diff --git a/CMakeLists.txt b/CMakeLists.txt index 06b9a0b..52a04f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,11 +6,8 @@ set(CMAKE_CXX_STANDARD 14) include_directories(include/) include_directories(utils/) -find_package(sqlite3 REQUIRED) -find_package(Boost COMPONENTS - program_options REQUIRED) +find_package(Boost REQUIRED) find_package(SQLiteCpp REQUIRED) -find_package(gtest REQUIRED) find_package(OpenSSL REQUIRED) message(STATUS SSL ${OPENSSL_LIBRARIES}) @@ -26,27 +23,14 @@ link_directories(${GTEST_LIB}) aux_source_directory(src SOURCE_ALL) +add_executable(NetTest test/test_main.cpp) -# add_executable(Net ${SOURCE} src/rsacpp.cpp include/rsacpp.h src/init.cpp include/init.h) -add_executable(NetRSATest test/rsa_test.cpp) - -gtest_add_tests(TARGET NetRSATest +gtest_add_tests(TARGET NetTest TEST_SUFFIX .noArgs TEST_LIST noArgsTests) -add_executable(NetOptsPceTest test/opts_processor_test.cpp) - -gtest_add_tests(TARGET NetOptsPceTest - TEST_SUFFIX .noArgs - TEST_LIST noArgsTests) - add_library(m_error STATIC src/error.cpp) add_library(m_rsa STATIC src/rsa_cpp_binding.cpp) -add_library(test_main STATIC test/test_main.cpp) - - -target_link_libraries(NetRSATest test_main m_rsa m_error ${GTEST_LIBS} ${OPENSSL_LIBS}) -target_link_libraries(NetOptsPceTest test_main m_error Boost::program_options) -set_tests_properties(${noArgsTests} PROPERTIES TIMEOUT 10) -# target_link_libraries(Net SQLiteCpp sqlite3 gtest ${Boost_LIBRARIES} pthread dl ssl ) \ No newline at end of file +target_link_libraries(NetTest m_rsa m_error ${GTEST_LIBS} ssl crypto boost_program_options) +set_tests_properties(${noArgsTests} PROPERTIES TIMEOUT 10) \ No newline at end of file diff --git a/include/opts_processor.h b/include/opts_processor.h index e7390c5..3ba1b2c 100644 --- a/include/opts_processor.h +++ b/include/opts_processor.h @@ -13,7 +13,7 @@ namespace po = boost::program_options; class OptsProcessor { public: - OptsProcessor(){ + OptsProcessor(int argc, char *argv[]){ desc.add_options() ("help", "help list") ("init", "set up the environment") @@ -23,7 +23,7 @@ public: ("client", "start a client daemon") ("set", "change an option"); po::variables_map vm; - po::store(po::parse_command_line(ac, av, desc), vm); + po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); if (vm.count("help")) { @@ -40,7 +40,6 @@ public: } private: po::options_description desc("General Net Tools (0.0.1) By Saturn&Eric"); - }; diff --git a/include/rsa_cpp_binding.h b/include/rsa_cpp_binding.h index a62fafb..97a179f 100644 --- a/include/rsa_cpp_binding.h +++ b/include/rsa_cpp_binding.h @@ -6,12 +6,14 @@ #define NET_RSA_CPP_BINDING_H #include "error.h" -#include "bignumber.cpp" +#include "../src/bignumber.cpp" #include #include #include + #include +#include using namespace std; diff --git a/include/type.h b/include/type.h index 15ca8cb..4f95d2f 100644 --- a/include/type.h +++ b/include/type.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include diff --git a/include/bignumber.cpp b/src/bignumber.cpp similarity index 100% rename from include/bignumber.cpp rename to src/bignumber.cpp diff --git a/src/rsa_cpp_binding.cpp b/src/rsa_cpp_binding.cpp index 2850aa3..6a9b774 100644 --- a/src/rsa_cpp_binding.cpp +++ b/src/rsa_cpp_binding.cpp @@ -19,7 +19,6 @@ void Net::RSAKeyChain::generateKeyPair() { void Net::RSAKeyChain::privateKeyDecrypt(string &data, const string &encrypted_data) { if(!this->if_prv_key) throw runtime_error("illegal call of privateKeyDecrypt"); if(this->key_pair == nullptr) throw runtime_error("key pair is invalid"); - assert(buffer_size > 0); if(encrypted_data.size() != buffer_size) throw runtime_error("encrypt data's size is abnormal"); // 使用私钥解密 int decrypted_size = -1; diff --git a/test/rsa_test.cpp b/test/rsa_test.cpp index c0d1b63..1ae60bd 100644 --- a/test/rsa_test.cpp +++ b/test/rsa_test.cpp @@ -10,7 +10,7 @@ using namespace Net; using namespace std; -GlobalTestEnv *_env; +extern GlobalTestEnv *_env; TEST(RSATest, init_test_1) { diff --git a/test/test_main.cpp b/test/test_main.cpp index 65e6b26..39098e8 100644 --- a/test/test_main.cpp +++ b/test/test_main.cpp @@ -4,9 +4,11 @@ #include +#include "rsa_test.cpp" + #include "env.h" -extern GlobalTestEnv *_env; +GlobalTestEnv *_env; int main(int argc, char *argv[]){ ::testing::InitGoogleTest(&argc, argv);