diff --git a/Dockerfile b/Dockerfile index 4121475..c40894f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ doxygen \ git \ graphviz \ libboost-dev \ +libboost-test-dev \ libcurl4-openssl-dev \ libssl-dev \ ninja-build \ diff --git a/Jenkinsfile b/Jenkinsfile index 371f55b..4cfbc77 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,56 +3,59 @@ pipeline { dockerfile true } - stages{ - stage("parallel execution"){ - parallel{ - stage("doxygen"){ - steps{ - sh 'doxygen' - } - } + stages{ + stage("parallel execution"){ + parallel{ + stage("doxygen"){ + steps{ + sh 'doxygen' + } + } - stage("validation"){ - steps{ - sh 'tools/validate/includeGuard.sh' - } - } - stage("build and test"){ - stages{ - stage("prepare"){ - steps{ - sh ''' - mkdir -p build - cd build - cmake .. -G Ninja - ''' - } - } + stage("validation"){ + steps{ + sh 'tools/validate/includeGuard.sh' + } + } + stage("build and test"){ + stages{ + stage("prepare"){ + steps{ + sh ''' + mkdir -p build + cd build + cmake .. -G Ninja + ''' + } + } - stage("build"){ - steps{ - sh ''' - cd build - ninja - ''' - } - } + stage("build"){ + steps{ + sh ''' + cd build + ninja + ''' + } + } - stage("test"){ - steps{ - echo "test" - } - } - } - } - } - } + stage("test"){ + steps{ + sh ''' + cd build + ctest --output_on_failure + ''' + } + } + } + } + } + } - stage("upload artifact"){ - steps{ - archiveArtifacts allowEmptyArchive: true, artifacts: 'help/**/*.*', onlyIfSuccessful: true - } - } + stage("upload artifact"){ + steps{ + archiveArtifacts allowEmptyArchive: true, artifacts: 'help/**/*.*', onlyIfSuccessful: true + } + } - } + } } diff --git a/src/cocoatweet/oauth/key.h b/src/cocoatweet/oauth/key.h index 3b4b29f..07aba49 100644 --- a/src/cocoatweet/oauth/key.h +++ b/src/cocoatweet/oauth/key.h @@ -11,7 +11,11 @@ class Key { const std::string accessTokenSecret_; public: - Key() = default; + Key() + : consumerKey_(""), + consumerSecret_(""), + accessToken_(""), + accessTokenSecret_("") {} Key(const std::string& _consumerKey, const std::string& _consumerSecret, const std::string& _accessToken, const std::string& _accessTokenSecret) : consumerKey_(_consumerKey), diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..fe3c3f1 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,15 @@ +file(GLOB_RECURSE SOURCES ./*.cc) + +foreach(TEST_SOURCE_FILE ${SOURCES}) + file(RELATIVE_PATH SRC_RELPATH ${CMAKE_CURRENT_LIST_DIR} ${TEST_SOURCE_FILE}) + string(REGEX REPLACE "\.cc$" "" TEST_MODULE_NAME "test/${SRC_RELPATH}") + string(REPLACE "/" "_" TEST_EXECUTABLE_NAME ${TEST_MODULE_NAME}) + + add_executable(${TEST_EXECUTABLE_NAME} ${TEST_SOURCE_FILE}) + target_compile_definitions(${TEST_EXECUTABLE_NAME} PRIVATE BOOST_TEST_MODULE=${TEST_MODULE_NAME}) + target_link_libraries(${TEST_EXECUTABLE_NAME} + lib-cocoatweet + Boost::unit_test_framework + ) + add_test(${TEST_MODULE_NAME} ${EXECUTABLE_OUTPUT_PATH}/${TEST_EXECUTABLE_NAME}) +endforeach() diff --git a/test/oauth/key.cc b/test/oauth/key.cc new file mode 100644 index 0000000..c5bd0c7 --- /dev/null +++ b/test/oauth/key.cc @@ -0,0 +1,35 @@ +#define BOOST_TEST_DYN_LINK + +#include + +#include "cocoatweet/oauth/key.h" + +BOOST_AUTO_TEST_SUITE(oauth_key) +BOOST_AUTO_TEST_CASE(test01) { + CocoaTweet::OAuth::Key key; + + BOOST_TEST(key.consumerKey() == ""); + BOOST_TEST(key.consumerSecret() == ""); + BOOST_TEST(key.accessToken() == ""); + BOOST_TEST(key.accessTokenSecret() == ""); +} + +BOOST_AUTO_TEST_CASE(test02) { + CocoaTweet::OAuth::Key key("consumerKey", "consumerSecret", "accessToken", "accessTokenSecret"); + + BOOST_TEST(key.consumerKey() == "consumerKey"); + BOOST_TEST(key.consumerSecret() == "consumerSecret"); + BOOST_TEST(key.accessToken() == "accessToken"); + BOOST_TEST(key.accessTokenSecret() == "accessTokenSecret"); + + auto noSecret = key.noSecret(); + BOOST_TEST(noSecret.at("oauth_consumer_key") == "consumerKey"); + BOOST_TEST(noSecret.at("oauth_token") == "accessToken"); + + auto secret = key.secret(); + BOOST_TEST(secret.at("oauth_consumer_key") == "consumerSecret"); + BOOST_TEST(secret.at("oauth_token") == "accessTokenSecret"); +} + + +BOOST_AUTO_TEST_SUITE_END()