OAuth::Keyのテストを書いた(#58)

This commit is contained in:
keita
2021-02-27 19:27:09 +09:00
parent cf77f7d611
commit 605b991d60
5 changed files with 106 additions and 48 deletions
+1
View File
@@ -9,6 +9,7 @@ doxygen \
git \ git \
graphviz \ graphviz \
libboost-dev \ libboost-dev \
libboost-test-dev \
libcurl4-openssl-dev \ libcurl4-openssl-dev \
libssl-dev \ libssl-dev \
ninja-build \ ninja-build \
Vendored
+50 -47
View File
@@ -3,56 +3,59 @@ pipeline {
dockerfile true dockerfile true
} }
stages{ stages{
stage("parallel execution"){ stage("parallel execution"){
parallel{ parallel{
stage("doxygen"){ stage("doxygen"){
steps{ steps{
sh 'doxygen' sh 'doxygen'
} }
} }
stage("validation"){ stage("validation"){
steps{ steps{
sh 'tools/validate/includeGuard.sh' sh 'tools/validate/includeGuard.sh'
} }
} }
stage("build and test"){ stage("build and test"){
stages{ stages{
stage("prepare"){ stage("prepare"){
steps{ steps{
sh ''' sh '''
mkdir -p build mkdir -p build
cd build cd build
cmake .. -G Ninja cmake .. -G Ninja
''' '''
} }
} }
stage("build"){ stage("build"){
steps{ steps{
sh ''' sh '''
cd build cd build
ninja ninja
''' '''
} }
} }
stage("test"){ stage("test"){
steps{ steps{
echo "test" sh '''
} cd build
} ctest --output_on_failure
} '''
} }
} }
} }
}
}
}
stage("upload artifact"){ stage("upload artifact"){
steps{ steps{
archiveArtifacts allowEmptyArchive: true, artifacts: 'help/**/*.*', onlyIfSuccessful: true archiveArtifacts allowEmptyArchive: true, artifacts: 'help/**/*.*', onlyIfSuccessful: true
} }
} }
} }
} }
+5 -1
View File
@@ -11,7 +11,11 @@ class Key {
const std::string accessTokenSecret_; const std::string accessTokenSecret_;
public: public:
Key() = default; Key()
: consumerKey_(""),
consumerSecret_(""),
accessToken_(""),
accessTokenSecret_("") {}
Key(const std::string& _consumerKey, const std::string& _consumerSecret, Key(const std::string& _consumerKey, const std::string& _consumerSecret,
const std::string& _accessToken, const std::string& _accessTokenSecret) const std::string& _accessToken, const std::string& _accessTokenSecret)
: consumerKey_(_consumerKey), : consumerKey_(_consumerKey),
+15
View File
@@ -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()
+35
View File
@@ -0,0 +1,35 @@
#define BOOST_TEST_DYN_LINK
#include <boost/test/included/unit_test.hpp>
#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()