tweetモデルに対するテストを書いた
This commit is contained in:
+2
-2
@@ -108,8 +108,8 @@ include_directories(${CURL_INCLUDE_DIRS})
|
|||||||
|
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
${PROJECT_SOURCE_DIR}/src
|
${CMAKE_SOURCE_DIR}/src
|
||||||
${PROJECT_SOURCE_DIR}/third
|
${CMAKE_SOURCE_DIR}/third
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
file(GLOB_RECURSE SOURCES ./*.cc)
|
file(GLOB_RECURSE SOURCES ./*.cc)
|
||||||
|
include_directories(${CMAKE_SOURCE_DIR}/third)
|
||||||
|
|
||||||
foreach(TEST_SOURCE_FILE ${SOURCES})
|
foreach(TEST_SOURCE_FILE ${SOURCES})
|
||||||
file(RELATIVE_PATH SRC_RELPATH ${CMAKE_CURRENT_LIST_DIR} ${TEST_SOURCE_FILE})
|
file(RELATIVE_PATH SRC_RELPATH ${CMAKE_CURRENT_LIST_DIR} ${TEST_SOURCE_FILE})
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
#define BOOST_TEST_DYN_LINK
|
||||||
|
|
||||||
|
#include <boost/test/included/unit_test.hpp>
|
||||||
|
|
||||||
|
#include "nlohmann/json.hpp"
|
||||||
|
#include "cocoatweet/api/model/tweet.h"
|
||||||
|
#include "cocoatweet/exception/authenticateException.h"
|
||||||
|
#include "cocoatweet/exception/rateLimitException.h"
|
||||||
|
#include "cocoatweet/exception/tweetTooLongException.h"
|
||||||
|
#include "cocoatweet/exception/tweetDuplicateException.h"
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE(tweet_object)
|
||||||
|
BOOST_AUTO_TEST_CASE(test01) {
|
||||||
|
CocoaTweet::API::Model::Tweet tweet;
|
||||||
|
|
||||||
|
BOOST_TEST(tweet.id() == "");
|
||||||
|
BOOST_TEST(tweet.createdAt() == "");
|
||||||
|
BOOST_TEST(tweet.text() == "");
|
||||||
|
BOOST_TEST(tweet.source() == "");
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(test02) {
|
||||||
|
std::string json = R"({
|
||||||
|
"id_str" : "1234567890",
|
||||||
|
"created_at" : "Thu Mar 04 00:00:00 +0000 2021",
|
||||||
|
"text" : "tweet",
|
||||||
|
"source" : "Twitter for Android"
|
||||||
|
})";
|
||||||
|
|
||||||
|
CocoaTweet::API::Model::Tweet tweet(200, json);
|
||||||
|
BOOST_TEST(tweet.id() == "1234567890");
|
||||||
|
BOOST_TEST(tweet.createdAt() == "Thu Mar 04 00:00:00 +0000 2021");
|
||||||
|
BOOST_TEST(tweet.text() == "tweet");
|
||||||
|
BOOST_TEST(tweet.source() == "Twitter for Android");
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(test03) {
|
||||||
|
std::string json = R"({
|
||||||
|
"errors" : [{
|
||||||
|
"code" : 32,
|
||||||
|
"message" : "Could not authenticate you."
|
||||||
|
}]
|
||||||
|
})";
|
||||||
|
|
||||||
|
BOOST_CHECK_THROW(CocoaTweet::API::Model::Tweet(401, json), CocoaTweet::Exception::AuthenticateException);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(test04) {
|
||||||
|
std::string json = R"({
|
||||||
|
"errors" : [{
|
||||||
|
"code" : 88,
|
||||||
|
"message" : "Rate limit exceeded."
|
||||||
|
}]
|
||||||
|
})";
|
||||||
|
|
||||||
|
BOOST_CHECK_THROW(CocoaTweet::API::Model::Tweet(429, json), CocoaTweet::Exception::RateLimitException);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(test05) {
|
||||||
|
std::string json = R"({
|
||||||
|
"errors" : [{
|
||||||
|
"code" : 185,
|
||||||
|
"message" : "User is over daily status update limit."
|
||||||
|
}]
|
||||||
|
})";
|
||||||
|
|
||||||
|
BOOST_CHECK_THROW(CocoaTweet::API::Model::Tweet(403, json), CocoaTweet::Exception::RateLimitException);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(test06) {
|
||||||
|
std::string json = R"({
|
||||||
|
"errors" : [{
|
||||||
|
"code" : 186,
|
||||||
|
"message" : "Tweet needs to be a bit shorter."
|
||||||
|
}]
|
||||||
|
})";
|
||||||
|
|
||||||
|
BOOST_CHECK_THROW(CocoaTweet::API::Model::Tweet(403, json), CocoaTweet::Exception::TweetTooLongException);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(test07) {
|
||||||
|
std::string json = R"({
|
||||||
|
"errors" : [{
|
||||||
|
"code" : 187,
|
||||||
|
"message" : "Status is a duplicate."
|
||||||
|
}]
|
||||||
|
})";
|
||||||
|
|
||||||
|
BOOST_CHECK_THROW(CocoaTweet::API::Model::Tweet(403, json), CocoaTweet::Exception::TweetDuplicateException);
|
||||||
|
}
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
Reference in New Issue
Block a user