From 30e010226ca4fbabe421bbeb7c1e82f02325c515 Mon Sep 17 00:00:00 2001 From: keita Date: Fri, 5 Mar 2021 10:35:09 +0900 Subject: [PATCH] =?UTF-8?q?tweet=E3=83=A2=E3=83=87=E3=83=AB=E3=81=AB?= =?UTF-8?q?=E5=AF=BE=E3=81=99=E3=82=8B=E3=83=86=E3=82=B9=E3=83=88=E3=82=92?= =?UTF-8?q?=E6=9B=B8=E3=81=84=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 4 +- test/CMakeLists.txt | 1 + test/api/model/tweet.cc | 91 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 test/api/model/tweet.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 144585f..cc7f084 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,8 +108,8 @@ include_directories(${CURL_INCLUDE_DIRS}) include_directories( - ${PROJECT_SOURCE_DIR}/src - ${PROJECT_SOURCE_DIR}/third + ${CMAKE_SOURCE_DIR}/src + ${CMAKE_SOURCE_DIR}/third ) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index fe3c3f1..bdc6ab5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,5 @@ file(GLOB_RECURSE SOURCES ./*.cc) +include_directories(${CMAKE_SOURCE_DIR}/third) foreach(TEST_SOURCE_FILE ${SOURCES}) file(RELATIVE_PATH SRC_RELPATH ${CMAKE_CURRENT_LIST_DIR} ${TEST_SOURCE_FILE}) diff --git a/test/api/model/tweet.cc b/test/api/model/tweet.cc new file mode 100644 index 0000000..82ea605 --- /dev/null +++ b/test/api/model/tweet.cc @@ -0,0 +1,91 @@ +#define BOOST_TEST_DYN_LINK + +#include + +#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()