From 8538a37db574bce767e566cf02e066d8705976a3 Mon Sep 17 00:00:00 2001 From: keita Date: Thu, 25 Feb 2021 23:08:05 +0900 Subject: [PATCH 1/7] =?UTF-8?q?=E3=82=B3=E3=83=BC=E3=83=89=E5=89=B2?= =?UTF-8?q?=E5=90=88=E3=81=AE=E3=82=A2=E3=83=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitattributes | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..859898f --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +third/* linguist-vendored +help/* linguist-documentation \ No newline at end of file From cf77f7d611eb46205ecca96f06c5c4693c56570e Mon Sep 17 00:00:00 2001 From: keita Date: Sat, 27 Feb 2021 19:26:15 +0900 Subject: [PATCH 2/7] =?UTF-8?q?boost=5Funit=5Ftest=5Fflamework=E3=81=AB?= =?UTF-8?q?=E5=AF=BE=E5=BF=9C(#58)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 10 +++++----- src/CMakeLists.txt | 7 +------ src/cocoatweet/CMakeLists.txt | 7 +++++++ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e62cbf..3a83174 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,7 @@ if(ENABLE_CODE_COVERAGE) endif() # Required libraries +find_package(Boost 1.71.0 COMPONENTS unit_test_framework REQUIRED) find_package(PkgConfig REQUIRED) find_package(OpenSSL REQUIRED) if(NOT OPENSSL_FOUND) @@ -63,14 +64,13 @@ if(NOT CURL_FOUND) endif() include_directories(${CURL_INCLUDE_DIRS}) -find_library(cpprest REQUIRED) -include_directories(${CPP_REST_INCLUDE_DIR}) - - include_directories( ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/third ) +# Enable CTest +enable_testing() + add_subdirectory(src) -#add_subdirectory(test) +add_subdirectory(test) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 663f71f..4f96f35 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,9 +2,4 @@ add_subdirectory(cocoatweet) set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}) add_executable(${PROJECT_NAME} main.cc) -target_link_libraries(${PROJECT_NAME} - lib-cocoatweet - OpenSSL::SSL - OpenSSL::Crypto - ${CURL_LIBRARIES} -) +target_link_libraries(${PROJECT_NAME} lib-cocoatweet) \ No newline at end of file diff --git a/src/cocoatweet/CMakeLists.txt b/src/cocoatweet/CMakeLists.txt index c5bb89d..ef17d9c 100644 --- a/src/cocoatweet/CMakeLists.txt +++ b/src/cocoatweet/CMakeLists.txt @@ -1,4 +1,11 @@ file(GLOB_RECURSE SOURCES ./*.cc) add_library(lib-cocoatweet ${SOURCES}) +target_link_libraries(lib-cocoatweet PUBLIC + Boost::boost + OpenSSL::SSL + OpenSSL::Crypto + ${CURL_LIBRARIES} +) + target_include_directories(lib-cocoatweet PUBLIC ${PROJECT_SOURCE_DIR}/src) set_target_properties(lib-cocoatweet PROPERTIES OUTPUT_NAME cocoatweet) From 605b991d60093a651ac29bc4284d503a98f0c6e1 Mon Sep 17 00:00:00 2001 From: keita Date: Sat, 27 Feb 2021 19:27:09 +0900 Subject: [PATCH 3/7] =?UTF-8?q?OAuth::Key=E3=81=AE=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=82=92=E6=9B=B8=E3=81=84=E3=81=9F(#58)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 1 + Jenkinsfile | 97 ++++++++++++++++++++------------------ src/cocoatweet/oauth/key.h | 6 ++- test/CMakeLists.txt | 15 ++++++ test/oauth/key.cc | 35 ++++++++++++++ 5 files changed, 106 insertions(+), 48 deletions(-) create mode 100644 test/CMakeLists.txt create mode 100644 test/oauth/key.cc 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() From 73dc8ab4bb24fe84d2e6c66e26ca1bd1be1d55d0 Mon Sep 17 00:00:00 2001 From: keita Date: Sat, 27 Feb 2021 19:27:32 +0900 Subject: [PATCH 4/7] =?UTF-8?q?=E3=83=8F=E3=83=BC=E3=83=89=E3=82=BF?= =?UTF-8?q?=E3=83=96=E3=81=8C=E6=B7=B7=E3=81=98=E3=81=A3=E3=81=A6=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/validate/includeGuard.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/validate/includeGuard.sh b/tools/validate/includeGuard.sh index a66b80f..cfb7657 100755 --- a/tools/validate/includeGuard.sh +++ b/tools/validate/includeGuard.sh @@ -8,7 +8,7 @@ for f in $(git ls-files | grep -E '^src\/.*\.h$'); do # ファイルパスから正しいインクルードガードの文字列を生成する s1="$(echo "$f" | sed -r 's/^src\///; s/[\/\.-]+/_/g; s/^.*$/\U&/')_" - # ファイルからインクルードガードを読み込む + # ファイルからインクルードガードを読み込む s2=$(grep -Pzo '#ifndef\s+\K\b(\w+)\b(?=\s+#define\s+\b\1\b)' "$f" | tr '\0' '\n') if [ -z "$s2" ]; then From 8b03ff5fd63b26283d44d7f73bd6f3efef18f431 Mon Sep 17 00:00:00 2001 From: keita Date: Mon, 1 Mar 2021 11:36:33 +0900 Subject: [PATCH 5/7] add badge --- Jenkinsfile | 18 ++++++++++++++---- README.md | 5 +++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4cfbc77..4a16b3e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,3 +1,5 @@ +def unittestBadge = addEmbeddableBadgeConfiguration(id: "unittest", subject: "unit test") + pipeline { agent { dockerfile true @@ -40,10 +42,18 @@ pipeline { stage("test"){ steps{ - sh ''' - cd build - ctest --output_on_failure - ''' + script{ + unittestBadge.setStatus('running') + try{ + sh ''' + cd build + ctest --output_on_failure + ''' + }catch(Exception error){ + unittestBadge.setStatus('failed') + error 'unittest failed' + } + } } } } diff --git a/README.md b/README.md index c7dc836..b2c432c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +![https://jenkins.milkcocoa.info/job/CocoaTweet/job/master](https://jenkins.milkcocoa.info/job/CocoaTweet/job/master/badge/icon?style=plastic) +![](https://img.shields.io/badge/libcurl-libcurl4--openssl-blue) +![](https://img.shields.io/badge/libssl-1.1.1f-blue) +![](http://jenkins.milkcocoa.info/job/CocoaTweet/job/master/badge/icon?style=plastic&config=unittest) + # CocoaTweet This is a library for using Twitter API from C++ From f1b5fb541c99361664543370b9c4a4feab347946 Mon Sep 17 00:00:00 2001 From: keita Date: Mon, 1 Mar 2021 11:40:14 +0900 Subject: [PATCH 6/7] add badge --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 4a16b3e..b7f1729 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -49,6 +49,7 @@ pipeline { cd build ctest --output_on_failure ''' + unittestBadge.setStatus('passing') }catch(Exception error){ unittestBadge.setStatus('failed') error 'unittest failed' From b4894023fb1ee7a346a801fc73dae693c6680b67 Mon Sep 17 00:00:00 2001 From: keita Date: Mon, 1 Mar 2021 11:44:32 +0900 Subject: [PATCH 7/7] manage README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b2c432c..5c06c11 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ![https://jenkins.milkcocoa.info/job/CocoaTweet/job/master](https://jenkins.milkcocoa.info/job/CocoaTweet/job/master/badge/icon?style=plastic) +![](http://jenkins.milkcocoa.info/job/CocoaTweet/job/master/badge/icon?style=plastic&config=unittest) ![](https://img.shields.io/badge/libcurl-libcurl4--openssl-blue) ![](https://img.shields.io/badge/libssl-1.1.1f-blue) -![](http://jenkins.milkcocoa.info/job/CocoaTweet/job/master/badge/icon?style=plastic&config=unittest) # CocoaTweet This is a library for using Twitter API from C++