diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/app_event_operators.cpp | 62 | ||||
-rw-r--r-- | tests/certs_.cpp | 4 | ||||
-rw-r--r-- | tests/certs_.h | 6 | ||||
-rw-r--r-- | tests/colour_log_formatter.cpp | 242 | ||||
-rw-r--r-- | tests/colour_log_formatter.h | 66 | ||||
-rw-r--r-- | tests/dbfixture.cpp | 24 | ||||
-rw-r--r-- | tests/dbfixture.h | 6 | ||||
-rw-r--r-- | tests/logic_.cpp | 138 | ||||
-rw-r--r-- | tests/logic_.h | 142 | ||||
-rw-r--r-- | tests/main.cpp | 11 | ||||
-rw-r--r-- | tests/popup_test.cpp | 40 | ||||
-rw-r--r-- | tests/queue_test_thread.cpp | 116 | ||||
-rw-r--r-- | tests/queue_test_thread.h | 24 | ||||
-rw-r--r-- | tests/stubs_.cpp | 55 | ||||
-rw-r--r-- | tests/test_app.cpp | 193 | ||||
-rw-r--r-- | tests/test_certs.cpp | 93 | ||||
-rw-r--r-- | tests/test_client.cpp | 5 | ||||
-rw-r--r-- | tests/test_db.cpp | 147 | ||||
-rw-r--r-- | tests/test_logic.cpp | 661 | ||||
-rw-r--r-- | tests/test_queue.cpp | 147 |
20 files changed, 1016 insertions, 1166 deletions
diff --git a/tests/app_event_operators.cpp b/tests/app_event_operators.cpp index 131e511..e0336e8 100644 --- a/tests/app_event_operators.cpp +++ b/tests/app_event_operators.cpp @@ -29,64 +29,66 @@ namespace CCHECKER { void sort_buffer(std::list<app_t> &buff) { - for (auto &iter : buff) { - sort(iter); - } + for (auto &iter : buff) { + sort(iter); + } - buff.sort(); + buff.sort(); } void sort(app_t &app) { - app.signatures.sort(); + app.signatures.sort(); } // Needed for sort() bool operator < (const app_t &app1, const app_t &app2) { - if (app1.app_id != app2.app_id) - return app1.app_id < app2.app_id; - if (app1.pkg_id != app2.pkg_id) - return app1.pkg_id < app2.pkg_id; - if (app1.uid != app2.uid) - return app1.uid < app2.uid; - - return app1.signatures < app2.signatures; + if (app1.app_id != app2.app_id) + return app1.app_id < app2.app_id; + + if (app1.pkg_id != app2.pkg_id) + return app1.pkg_id < app2.pkg_id; + + if (app1.uid != app2.uid) + return app1.uid < app2.uid; + + return app1.signatures < app2.signatures; } bool operator ==(const app_t &app1, const app_t &app2) { - if (app1.app_id != app2.app_id || - app1.pkg_id != app2.pkg_id || - app1.uid != app2.uid || - app1.signatures.size() != app2.signatures.size() || - app1.verified != app2.verified) { - LogDebug("app_t compare error: " << app1.str() << " is different than: " << app2.str()); - return false; - } - - return app1.signatures == app2.signatures; + if (app1.app_id != app2.app_id || + app1.pkg_id != app2.pkg_id || + app1.uid != app2.uid || + app1.signatures.size() != app2.signatures.size() || + app1.verified != app2.verified) { + LogDebug("app_t compare error: " << app1.str() << " is different than: " << app2.str()); + return false; + } + + return app1.signatures == app2.signatures; } bool operator !=(const app_t &app1, const app_t &app2) { - return !(app1 == app2); + return !(app1 == app2); } bool operator ==(const event_t &event1, const event_t &event2) { - if (event1.event_type != event2.event_type) - return false; + if (event1.event_type != event2.event_type) + return false; - if (event1.app != event2.app) - return false; + if (event1.app != event2.app) + return false; - return true; + return true; } bool operator !=(const event_t &event1, const event_t &event2) { - return !(event1 == event2); + return !(event1 == event2); } } // CHCHECKER diff --git a/tests/certs_.cpp b/tests/certs_.cpp index b63c48b..b20bace 100644 --- a/tests/certs_.cpp +++ b/tests/certs_.cpp @@ -27,7 +27,7 @@ using namespace CCHECKER; Certs_::~Certs_() {} -Certs_::ocsp_response_t Certs_::check_ocsp_chain_ (const chain_t &chain) +Certs_::ocsp_response_t Certs_::check_ocsp_chain_(const chain_t &chain) { - return this->check_ocsp_chain(chain); + return this->check_ocsp_chain(chain); } diff --git a/tests/certs_.h b/tests/certs_.h index 163d299..c5478ee 100644 --- a/tests/certs_.h +++ b/tests/certs_.h @@ -28,9 +28,9 @@ using namespace CCHECKER; class Certs_ : public Certs { - public: - virtual ~Certs_(); - ocsp_response_t check_ocsp_chain_ (const chain_t &chain); +public: + virtual ~Certs_(); + ocsp_response_t check_ocsp_chain_(const chain_t &chain); }; #endif //CCHECKER_DBFIXTURE_H diff --git a/tests/colour_log_formatter.cpp b/tests/colour_log_formatter.cpp index c873724..1d185bc 100644 --- a/tests/colour_log_formatter.cpp +++ b/tests/colour_log_formatter.cpp @@ -40,19 +40,21 @@ namespace { const_string test_phase_identifier() { - return framework::is_initialized() - ? const_string( framework::current_test_case().p_name.get() ) - : BOOST_TEST_L( "Test setup" ); + return framework::is_initialized() + ? const_string(framework::current_test_case().p_name.get()) + : BOOST_TEST_L("Test setup"); } const_string -get_basename(const const_string &file_name) { - return basename(file_name.begin()); +get_basename(const const_string &file_name) +{ + return basename(file_name.begin()); } std::string -get_basename(const std::string &file_name) { - return basename(file_name.c_str()); +get_basename(const std::string &file_name) +{ + return basename(file_name.c_str()); } } // local namespace @@ -61,185 +63,191 @@ get_basename(const std::string &file_name) { void colour_log_formatter::log_start( - std::ostream& output, - counter_t test_cases_amount ) + std::ostream &output, + counter_t test_cases_amount) { - if( test_cases_amount > 0 ) - output << "Running " << test_cases_amount << " test " - << (test_cases_amount > 1 ? "cases" : "case") << "...\n"; + if (test_cases_amount > 0) + output << "Running " << test_cases_amount << " test " + << (test_cases_amount > 1 ? "cases" : "case") << "...\n"; } //____________________________________________________________________________// void -colour_log_formatter::log_finish( std::ostream& ostr ) +colour_log_formatter::log_finish(std::ostream &ostr) { - ostr.flush(); + ostr.flush(); } //____________________________________________________________________________// void -colour_log_formatter::log_build_info( std::ostream& output ) +colour_log_formatter::log_build_info(std::ostream &output) { - output << "Platform: " << BOOST_PLATFORM << '\n' - << "Compiler: " << BOOST_COMPILER << '\n' - << "STL : " << BOOST_STDLIB << '\n' - << "Boost : " << BOOST_VERSION/100000 << "." - << BOOST_VERSION/100 % 1000 << "." - << BOOST_VERSION % 100 << std::endl; + output << "Platform: " << BOOST_PLATFORM << '\n' + << "Compiler: " << BOOST_COMPILER << '\n' + << "STL : " << BOOST_STDLIB << '\n' + << "Boost : " << BOOST_VERSION / 100000 << "." + << BOOST_VERSION / 100 % 1000 << "." + << BOOST_VERSION % 100 << std::endl; } //____________________________________________________________________________// void colour_log_formatter::test_unit_start( - std::ostream& output, - test_unit const& tu ) + std::ostream &output, + test_unit const &tu) { - if (tu.p_type_name->find(const_string("suite")) == 0) { - output << "Starting test " << tu.p_type_name << " \"" << tu.p_name << "\"" << std::endl; - } else { - output << "Running test " << tu.p_type_name << " \"" << tu.p_name << "\"" << std::endl; - } + if (tu.p_type_name->find(const_string("suite")) == 0) { + output << "Starting test " << tu.p_type_name << " \"" << tu.p_name << "\"" << std::endl; + } else { + output << "Running test " << tu.p_type_name << " \"" << tu.p_name << "\"" << std::endl; + } } //____________________________________________________________________________// void colour_log_formatter::test_unit_finish( - std::ostream& output, - test_unit const& tu, - unsigned long elapsed ) + std::ostream &output, + test_unit const &tu, + unsigned long elapsed) { - if (tu.p_type_name->find(const_string("suite")) == 0) { - output << "Finished test " << tu.p_type_name << " \"" << tu.p_name << "\""<< std::endl; - return; - } - std::string color = CCHECKER::Colors::Text::GREEN_BEGIN; - std::string status = "OK"; - if (m_isTestCaseFailed) { - color = CCHECKER::Colors::Text::RED_BEGIN; - status = "FAIL"; - } - output << "\t" << "[ " << color << status << CCHECKER::Colors::Text::COLOR_END << " ]"; - - - output << ", " << CCHECKER::Colors::Text::CYAN_BEGIN << "time: "; - if( elapsed > 0 ) { - if( elapsed % 1000 == 0 ) - output << elapsed/1000 << "ms"; - else - output << elapsed << "mks"; - } else { - output << "N/A"; - } - - output << CCHECKER::Colors::Text::COLOR_END << std::endl; - m_isTestCaseFailed = false; + if (tu.p_type_name->find(const_string("suite")) == 0) { + output << "Finished test " << tu.p_type_name << " \"" << tu.p_name << "\"" << std::endl; + return; + } + + std::string color = CCHECKER::Colors::Text::GREEN_BEGIN; + std::string status = "OK"; + + if (m_isTestCaseFailed) { + color = CCHECKER::Colors::Text::RED_BEGIN; + status = "FAIL"; + } + + output << "\t" << "[ " << color << status << CCHECKER::Colors::Text::COLOR_END << " ]"; + output << ", " << CCHECKER::Colors::Text::CYAN_BEGIN << "time: "; + + if (elapsed > 0) { + if (elapsed % 1000 == 0) + output << elapsed / 1000 << "ms"; + else + output << elapsed << "mks"; + } else { + output << "N/A"; + } + + output << CCHECKER::Colors::Text::COLOR_END << std::endl; + m_isTestCaseFailed = false; } //____________________________________________________________________________// void colour_log_formatter::test_unit_skipped( - std::ostream& output, - test_unit const& tu ) + std::ostream &output, + test_unit const &tu) { - output << "Test " << tu.p_type_name << " \"" << tu.p_name << "\"" << "is skipped" << std::endl; + output << "Test " << tu.p_type_name << " \"" << tu.p_name << "\"" << "is skipped" << std::endl; } //____________________________________________________________________________// void colour_log_formatter::log_exception( - std::ostream& output, - log_checkpoint_data const& checkpoint_data, - boost::execution_exception const& ex ) + std::ostream &output, + log_checkpoint_data const &checkpoint_data, + boost::execution_exception const &ex) { - boost::execution_exception::location const& loc = ex.where(); - output << '\t' << CCHECKER::Colors::Text::BOLD_YELLOW_BEGIN << get_basename(loc.m_file_name) - << '(' << loc.m_line_num << "), "; - - output << "fatal error in \"" - << (loc.m_function.is_empty() ? test_phase_identifier() : loc.m_function ) << "\": "; - - output << CCHECKER::Colors::Text::COLOR_END << ex.what(); - - if( !checkpoint_data.m_file_name.is_empty() ) { - output << '\n'; - output << "\tlast checkpoint : " << get_basename(checkpoint_data.m_file_name) - << '(' << checkpoint_data.m_line_num << ")"; - if( !checkpoint_data.m_message.empty() ) - output << ": " << checkpoint_data.m_message; - } - - output << std::endl; - m_isTestCaseFailed = true; + boost::execution_exception::location const &loc = ex.where(); + output << '\t' << CCHECKER::Colors::Text::BOLD_YELLOW_BEGIN << get_basename(loc.m_file_name) + << '(' << loc.m_line_num << "), "; + output << "fatal error in \"" + << (loc.m_function.is_empty() ? test_phase_identifier() : loc.m_function) << "\": "; + output << CCHECKER::Colors::Text::COLOR_END << ex.what(); + + if (!checkpoint_data.m_file_name.is_empty()) { + output << '\n'; + output << "\tlast checkpoint : " << get_basename(checkpoint_data.m_file_name) + << '(' << checkpoint_data.m_line_num << ")"; + + if (!checkpoint_data.m_message.empty()) + output << ": " << checkpoint_data.m_message; + } + + output << std::endl; + m_isTestCaseFailed = true; } //____________________________________________________________________________// void colour_log_formatter::log_entry_start( - std::ostream& output, - log_entry_data const& entry_data, - log_entry_types let ) + std::ostream &output, + log_entry_data const &entry_data, + log_entry_types let) { - switch( let ) { - case BOOST_UTL_ET_INFO: - output << '\t' << entry_data.m_file_name << '(' << entry_data.m_line_num << "), "; - output << "info: "; - break; - case BOOST_UTL_ET_MESSAGE: - break; - case BOOST_UTL_ET_WARNING: - output << '\t' << get_basename(entry_data.m_file_name) << '(' << entry_data.m_line_num << "), "; - output << "warning in \"" << test_phase_identifier() << "\": "; - break; - case BOOST_UTL_ET_ERROR: - output << '\t' << CCHECKER::Colors::Text::BOLD_YELLOW_BEGIN << get_basename(entry_data.m_file_name) - << '(' << entry_data.m_line_num << "), "; - output << "error in \"" << test_phase_identifier() << "\": "; - m_isTestCaseFailed = true; - break; - case BOOST_UTL_ET_FATAL_ERROR: - output << '\t' << CCHECKER::Colors::Text::BOLD_YELLOW_BEGIN << get_basename(entry_data.m_file_name) - << '(' << entry_data.m_line_num << "), "; - output << " fatal error in \"" << test_phase_identifier() << "\": "; - m_isTestCaseFailed = true; - break; - } - output << CCHECKER::Colors::Text::COLOR_END; + switch (let) { + case BOOST_UTL_ET_INFO: + output << '\t' << entry_data.m_file_name << '(' << entry_data.m_line_num << "), "; + output << "info: "; + break; + + case BOOST_UTL_ET_MESSAGE: + break; + + case BOOST_UTL_ET_WARNING: + output << '\t' << get_basename(entry_data.m_file_name) << '(' << entry_data.m_line_num << "), "; + output << "warning in \"" << test_phase_identifier() << "\": "; + break; + + case BOOST_UTL_ET_ERROR: + output << '\t' << CCHECKER::Colors::Text::BOLD_YELLOW_BEGIN << get_basename(entry_data.m_file_name) + << '(' << entry_data.m_line_num << "), "; + output << "error in \"" << test_phase_identifier() << "\": "; + m_isTestCaseFailed = true; + break; + + case BOOST_UTL_ET_FATAL_ERROR: + output << '\t' << CCHECKER::Colors::Text::BOLD_YELLOW_BEGIN << get_basename(entry_data.m_file_name) + << '(' << entry_data.m_line_num << "), "; + output << " fatal error in \"" << test_phase_identifier() << "\": "; + m_isTestCaseFailed = true; + break; + } + + output << CCHECKER::Colors::Text::COLOR_END; } //____________________________________________________________________________// void colour_log_formatter::log_entry_value( - std::ostream& output, - const_string value ) + std::ostream &output, + const_string value) { - output << value; + output << value; } //____________________________________________________________________________// void colour_log_formatter::log_entry_value( - std::ostream& output, - lazy_ostream const& value ) + std::ostream &output, + lazy_ostream const &value) { - output << value; + output << value; } //____________________________________________________________________________// void colour_log_formatter::log_entry_finish( - std::ostream& output ) + std::ostream &output) { - output << std::endl; + output << std::endl; } //____________________________________________________________________________// diff --git a/tests/colour_log_formatter.h b/tests/colour_log_formatter.h index 5e44c58..ac4b07f 100644 --- a/tests/colour_log_formatter.h +++ b/tests/colour_log_formatter.h @@ -20,43 +20,43 @@ namespace CCHECKER { class colour_log_formatter : public boost::unit_test::unit_test_log_formatter { public: - // Formatter interface - colour_log_formatter() : m_isTestCaseFailed(false) {} - void log_start( - std::ostream&, - boost::unit_test::counter_t test_cases_amount ); - void log_finish( std::ostream& ); - void log_build_info( std::ostream& ); + // Formatter interface + colour_log_formatter() : m_isTestCaseFailed(false) {} + void log_start( + std::ostream &, + boost::unit_test::counter_t test_cases_amount); + void log_finish(std::ostream &); + void log_build_info(std::ostream &); - void test_unit_start( - std::ostream&, - boost::unit_test::test_unit const& tu ); - void test_unit_finish( - std::ostream&, - boost::unit_test::test_unit const& tu, - unsigned long elapsed ); - void test_unit_skipped( - std::ostream&, - boost::unit_test::test_unit const& tu ); + void test_unit_start( + std::ostream &, + boost::unit_test::test_unit const &tu); + void test_unit_finish( + std::ostream &, + boost::unit_test::test_unit const &tu, + unsigned long elapsed); + void test_unit_skipped( + std::ostream &, + boost::unit_test::test_unit const &tu); - void log_exception( - std::ostream&, - boost::unit_test::log_checkpoint_data const&, - boost::execution_exception const& ex ); + void log_exception( + std::ostream &, + boost::unit_test::log_checkpoint_data const &, + boost::execution_exception const &ex); - void log_entry_start( - std::ostream&, - boost::unit_test::log_entry_data const&, - log_entry_types let ); - void log_entry_value( - std::ostream&, - boost::unit_test::const_string value ); - void log_entry_value( - std::ostream&, - boost::unit_test::lazy_ostream const& value ); - void log_entry_finish( std::ostream& ); + void log_entry_start( + std::ostream &, + boost::unit_test::log_entry_data const &, + log_entry_types let); + void log_entry_value( + std::ostream &, + boost::unit_test::const_string value); + void log_entry_value( + std::ostream &, + boost::unit_test::lazy_ostream const &value); + void log_entry_finish(std::ostream &); private: - bool m_isTestCaseFailed; + bool m_isTestCaseFailed; }; } // namespace CCHECKER diff --git a/tests/dbfixture.cpp b/tests/dbfixture.cpp index 4d604fe..bcbbb33 100644 --- a/tests/dbfixture.cpp +++ b/tests/dbfixture.cpp @@ -32,20 +32,18 @@ const char *TEST_DB_PATH_TEMP = DB_INSTALL_DIR"/.cert-checker-test-temp.db"; } // anonymus namespace DBFixture::DBFixture() : - DB::SqlQuery() + DB::SqlQuery() { - // Remove temporary databse - BOOST_CHECK(unlink(TEST_DB_PATH_TEMP) == 0 || errno == ENOENT); - - // Restore original database - std::ifstream f1(TEST_DB_PATH, std::fstream::binary); - std::ofstream f2(TEST_DB_PATH_TEMP, std::fstream::trunc|std::fstream::binary); - f2 << f1.rdbuf(); - f2.close(); - f1.close(); - - // Open temporary database - BOOST_REQUIRE(connect(TEST_DB_PATH_TEMP)); + // Remove temporary databse + BOOST_CHECK(unlink(TEST_DB_PATH_TEMP) == 0 || errno == ENOENT); + // Restore original database + std::ifstream f1(TEST_DB_PATH, std::fstream::binary); + std::ofstream f2(TEST_DB_PATH_TEMP, std::fstream::trunc | std::fstream::binary); + f2 << f1.rdbuf(); + f2.close(); + f1.close(); + // Open temporary database + BOOST_REQUIRE(connect(TEST_DB_PATH_TEMP)); }; DBFixture::~DBFixture() diff --git a/tests/dbfixture.h b/tests/dbfixture.h index 68c1450..d64450e 100644 --- a/tests/dbfixture.h +++ b/tests/dbfixture.h @@ -28,9 +28,9 @@ using namespace CCHECKER; class DBFixture : public DB::SqlQuery { - public: - DBFixture(); - virtual ~DBFixture(); +public: + DBFixture(); + virtual ~DBFixture(); }; #endif //CCHECKER_DBFIXTURE_H diff --git a/tests/logic_.cpp b/tests/logic_.cpp index 4384e4e..20e4a2c 100644 --- a/tests/logic_.cpp +++ b/tests/logic_.cpp @@ -35,118 +35,118 @@ namespace CCHECKER { Logic_::Logic_(void) : - Logic(), - m_installCnt(0), - m_uninstallCnt(0), - m_bufferCnt(0) + Logic(), + m_installCnt(0), + m_uninstallCnt(0), + m_bufferCnt(0) {} Logic_::~Logic_(void) { - clean(); + clean(); } void Logic_::clean(void) { - LogDebug("Cert-checker cleaning."); - - // wait and join processing thread - if (m_thread.joinable()) { - LogDebug("Waiting for join processing thread"); - { - std::lock_guard < std::mutex > lock(m_mutex_cv); - set_should_exit(); - m_to_process.notify_one(); - } - m_thread.join(); - LogDebug("Processing thread joined"); - } else - LogDebug("No thread to join"); + LogDebug("Cert-checker cleaning."); + + // wait and join processing thread + if (m_thread.joinable()) { + LogDebug("Waiting for join processing thread"); + { + std::lock_guard <std::mutex> lock(m_mutex_cv); + set_should_exit(); + m_to_process.notify_one(); + } + m_thread.join(); + LogDebug("Processing thread joined"); + } else { + LogDebug("No thread to join"); + } } void Logic_::job() { - LogDebug("Test timer job"); - m_installCnt++; - - _m_wait_for_process.notify_one(); + LogDebug("Test timer job"); + m_installCnt++; + _m_wait_for_process.notify_one(); } void Logic_::connman_callback_manual_(bool state) { - Logic::set_online(state); + Logic::set_online(state); } void Logic_::pkgmgr_install_manual_(const app_t &app) { - push_event(event_t(app, event_t::event_type_t::APP_INSTALL)); + push_event(event_t(app, event_t::event_type_t::APP_INSTALL)); } void Logic_::pkgmgr_uninstall_manual_(const app_t &app) { - push_event(event_t(app, event_t::event_type_t::APP_UNINSTALL)); + push_event(event_t(app, event_t::event_type_t::APP_UNINSTALL)); } void Logic_::process_event(const event_t &event) { - Logic::process_event(event); - - std::lock_guard<std::mutex> lock(_m_mutex_wait_cv); - switch(event.event_type) - { - case event_t::event_type_t::APP_INSTALL: - m_installCnt++; - LogDebug(m_installCnt << " " << m_uninstallCnt << " " << m_bufferCnt); - break; - case event_t::event_type_t::APP_UNINSTALL: - m_uninstallCnt++; - LogDebug(m_installCnt << " " << m_uninstallCnt << " " << m_bufferCnt); - break; - default: - return; - } - // notify caller - _m_wait_for_process.notify_one(); + Logic::process_event(event); + std::lock_guard<std::mutex> lock(_m_mutex_wait_cv); + + switch (event.event_type) { + case event_t::event_type_t::APP_INSTALL: + m_installCnt++; + LogDebug(m_installCnt << " " << m_uninstallCnt << " " << m_bufferCnt); + break; + + case event_t::event_type_t::APP_UNINSTALL: + m_uninstallCnt++; + LogDebug(m_installCnt << " " << m_uninstallCnt << " " << m_bufferCnt); + break; + + default: + return; + } + + // notify caller + _m_wait_for_process.notify_one(); } void Logic_::app_processed() { - std::lock_guard<std::mutex> lock(_m_mutex_wait_cv); - m_bufferCnt++; - LogDebug(m_installCnt << " " << m_uninstallCnt << " " << m_bufferCnt); - - // notify caller - _m_wait_for_process.notify_one(); + std::lock_guard<std::mutex> lock(_m_mutex_wait_cv); + m_bufferCnt++; + LogDebug(m_installCnt << " " << m_uninstallCnt << " " << m_bufferCnt); + // notify caller + _m_wait_for_process.notify_one(); } void Logic_::reset_cnt() { - m_installCnt = 0; - m_uninstallCnt = 0; - m_bufferCnt = 0; + m_installCnt = 0; + m_uninstallCnt = 0; + m_bufferCnt = 0; } void Logic_::wait_for_worker(int installCnt, int uninstallCnt, int bufferCnt) { - LogDebug("Wait for: " << installCnt << " " << uninstallCnt << " " << bufferCnt); - std::unique_lock<std::mutex> lock(_m_mutex_wait_cv); - bool timeout = !_m_wait_for_process.wait_for( - lock, - std::chrono::seconds(10), - [this, installCnt, uninstallCnt, bufferCnt]{ - return m_installCnt == installCnt && - m_uninstallCnt == uninstallCnt && - m_bufferCnt == bufferCnt; - } - ); - reset_cnt(); - _m_mutex_wait_cv.unlock(); - BOOST_REQUIRE(!timeout); + LogDebug("Wait for: " << installCnt << " " << uninstallCnt << " " << bufferCnt); + std::unique_lock<std::mutex> lock(_m_mutex_wait_cv); + bool timeout = !_m_wait_for_process.wait_for( + lock, + std::chrono::seconds(10), + [this, installCnt, uninstallCnt, bufferCnt] { + return m_installCnt == installCnt && + m_uninstallCnt == uninstallCnt && + m_bufferCnt == bufferCnt; + }); + reset_cnt(); + _m_mutex_wait_cv.unlock(); + BOOST_REQUIRE(!timeout); } -const std::list<app_t>& Logic_::get_buffer_() +const std::list<app_t> &Logic_::get_buffer_() { - return m_buffer; + return m_buffer; } } // CCHECKER diff --git a/tests/logic_.h b/tests/logic_.h index f8dcf95..e5e3934 100644 --- a/tests/logic_.h +++ b/tests/logic_.h @@ -34,72 +34,94 @@ namespace CCHECKER { class Logic_ : public Logic { - public: - Logic_(void); - virtual ~Logic_(void); - virtual void clean(void); - - // For tests only - void connman_callback_manual_(bool state); - void pkgmgr_install_manual_(const app_t &app); - void pkgmgr_uninstall_manual_(const app_t &app); - const std::list<app_t>& get_buffer_(); - - void reset_cnt(); - void wait_for_worker(int installCnt, int uninstallCnt, int bufferCnt); - - protected: - void job(void) override; - - private: - int m_installCnt; - int m_uninstallCnt; - int m_bufferCnt; - - void process_event(const event_t &event); - void app_processed() override; - std::condition_variable _m_wait_for_process; - std::mutex _m_mutex_wait_cv; +public: + Logic_(void); + virtual ~Logic_(void); + virtual void clean(void); + + // For tests only + void connman_callback_manual_(bool state); + void pkgmgr_install_manual_(const app_t &app); + void pkgmgr_uninstall_manual_(const app_t &app); + const std::list<app_t> &get_buffer_(); + + void reset_cnt(); + void wait_for_worker(int installCnt, int uninstallCnt, int bufferCnt); + +protected: + void job(void) override; + +private: + int m_installCnt; + int m_uninstallCnt; + int m_bufferCnt; + + void process_event(const event_t &event); + void app_processed() override; + std::condition_variable _m_wait_for_process; + std::mutex _m_mutex_wait_cv; }; class LogicWrapper { public: - LogicWrapper() {} - ~LogicWrapper() { m_logic.clean(); } - - error_t setup() { return m_logic.setup(); } - void clean() { m_logic.clean(); } - void connman_callback_manual_(bool state) { m_logic.connman_callback_manual_(state); } - void pkgmgr_install_manual_(const app_t &app) { m_logic.pkgmgr_install_manual_(app); } - void pkgmgr_uninstall_manual_(const app_t &app) { m_logic.pkgmgr_uninstall_manual_(app); } - const std::list<app_t>& get_buffer_() { return m_logic.get_buffer_(); } - - void wait_for_worker(int installCnt = 0, int uninstallCnt = 0, int bufferCnt = 0) { - m_logic.wait_for_worker(installCnt, uninstallCnt, bufferCnt); - } - - // timer operation - void timerStart(int interval) - { - m_logic.timerStart(interval); - } - void timerStop() - { - m_logic.timerStop(); - } - - // gio operation - void run(guint timeout) - { - m_logic.run(timeout); - } - bool is_running() - { - return m_logic.is_running(); - } + LogicWrapper() {} + ~LogicWrapper() + { + m_logic.clean(); + } + + error_t setup() + { + return m_logic.setup(); + } + void clean() + { + m_logic.clean(); + } + void connman_callback_manual_(bool state) + { + m_logic.connman_callback_manual_(state); + } + void pkgmgr_install_manual_(const app_t &app) + { + m_logic.pkgmgr_install_manual_(app); + } + void pkgmgr_uninstall_manual_(const app_t &app) + { + m_logic.pkgmgr_uninstall_manual_(app); + } + const std::list<app_t> &get_buffer_() + { + return m_logic.get_buffer_(); + } + + void wait_for_worker(int installCnt = 0, int uninstallCnt = 0, int bufferCnt = 0) + { + m_logic.wait_for_worker(installCnt, uninstallCnt, bufferCnt); + } + + // timer operation + void timerStart(int interval) + { + m_logic.timerStart(interval); + } + void timerStop() + { + m_logic.timerStop(); + } + + // gio operation + void run(guint timeout) + { + m_logic.run(timeout); + } + bool is_running() + { + return m_logic.is_running(); + } private: - Logic_ m_logic; + Logic_ m_logic; }; } // CCHECKER diff --git a/tests/main.cpp b/tests/main.cpp index 8fe6733..59e8df2 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -29,11 +29,12 @@ #include "common/log.h" struct TestConfig { - TestConfig() { - boost::unit_test::unit_test_log.set_threshold_level( boost::unit_test::log_test_units); - boost::unit_test::results_reporter::set_level(boost::unit_test::SHORT_REPORT); - boost::unit_test::unit_test_log.set_formatter(new CCHECKER::colour_log_formatter); - } + TestConfig() + { + boost::unit_test::unit_test_log.set_threshold_level(boost::unit_test::log_test_units); + boost::unit_test::results_reporter::set_level(boost::unit_test::SHORT_REPORT); + boost::unit_test::unit_test_log.set_formatter(new CCHECKER::colour_log_formatter); + } }; BOOST_GLOBAL_FIXTURE(TestConfig) diff --git a/tests/popup_test.cpp b/tests/popup_test.cpp index 3f6676d..8bdff76 100644 --- a/tests/popup_test.cpp +++ b/tests/popup_test.cpp @@ -26,27 +26,23 @@ using namespace CCHECKER; -int main(int argc, char** argv) +int main(int argc, char **argv) { - LogDebug("Cert-checker popup-test start!"); - - int timeout = 60; - if (argc > 1) { - timeout = atoi(argv[1]); - } - LogDebug("popup-test timeout: " << timeout); - - setlocale(LC_ALL, ""); - - UI::UIBackend ui(timeout); - - app_t app(std::string("test_APP_ID"), - std::string("test PKG ID"), - 5005, - {}); - - ui.call_popup(app); - - LogDebug("Cert-checker popup-test exit!"); - return 0; + LogDebug("Cert-checker popup-test start!"); + int timeout = 60; + + if (argc > 1) { + timeout = atoi(argv[1]); + } + + LogDebug("popup-test timeout: " << timeout); + setlocale(LC_ALL, ""); + UI::UIBackend ui(timeout); + app_t app(std::string("test_APP_ID"), + std::string("test PKG ID"), + 5005, + {}); + ui.call_popup(app); + LogDebug("Cert-checker popup-test exit!"); + return 0; } diff --git a/tests/queue_test_thread.cpp b/tests/queue_test_thread.cpp index b98ddc1..b20f10c 100644 --- a/tests/queue_test_thread.cpp +++ b/tests/queue_test_thread.cpp @@ -34,78 +34,80 @@ namespace CCHECKER { #define APPS_COUNT 10 app_t app[APPS_COUNT] = { - app_t ("app_id0", "###", 0, {}), - app_t ("app_id1", "pkg_id1", 1, {}), - app_t ("app_id2", "pkg_id2", 2, {}), - app_t ("app_id3", "###", 3, {}), - app_t ("app_id4", "###", 4, {}), - app_t ("app_id5", "###", 5, {}), - app_t ("app_id6", "###", 6, {}), - app_t ("app_id7", "###", 7, {}), - app_t ("app_id8", "###", 8, {}), - app_t ("app_id9", "###", 9, {}) + app_t("app_id0", "###", 0, {}), + app_t("app_id1", "pkg_id1", 1, {}), + app_t("app_id2", "pkg_id2", 2, {}), + app_t("app_id3", "###", 3, {}), + app_t("app_id4", "###", 4, {}), + app_t("app_id5", "###", 5, {}), + app_t("app_id6", "###", 6, {}), + app_t("app_id7", "###", 7, {}), + app_t("app_id8", "###", 8, {}), + app_t("app_id9", "###", 9, {}) }; void TestQueue::add_events_th(int number_of_threads) { - if (number_of_threads < 1) { - LogDebug("Too few threads, at least 1 should be used"); - number_of_threads = 1; - } + if (number_of_threads < 1) { + LogDebug("Too few threads, at least 1 should be used"); + number_of_threads = 1; + } - m_sent = 0; - m_max_events = number_of_threads * 2 * APPS_COUNT; + m_sent = 0; + m_max_events = number_of_threads * 2 * APPS_COUNT; + LogDebug("Running threads"); - LogDebug("Running threads"); - for (int i=0; i<number_of_threads; i++) - std::thread(&TestQueue::add_events, this).detach(); + for (int i = 0; i < number_of_threads; i++) + std::thread(&TestQueue::add_events, this).detach(); - LogDebug("Running threads done"); + LogDebug("Running threads done"); } void TestQueue::add_events() { - for (int i = 0; i < APPS_COUNT; i++) { - m_queue.push_event(event_t(app[i], event_t::event_type_t::APP_INSTALL)); - m_sent++; - LogDebug("Add event : " << i); - } - - for (int i = 0; i < APPS_COUNT; i++) { - m_queue.push_event(event_t(app[i], event_t::event_type_t::APP_UNINSTALL)); - m_sent++; - LogDebug("Add event : " << i); - } + for (int i = 0; i < APPS_COUNT; i++) { + m_queue.push_event(event_t(app[i], event_t::event_type_t::APP_INSTALL)); + m_sent++; + LogDebug("Add event : " << i); + } + + for (int i = 0; i < APPS_COUNT; i++) { + m_queue.push_event(event_t(app[i], event_t::event_type_t::APP_UNINSTALL)); + m_sent++; + LogDebug("Add event : " << i); + } } bool TestQueue::pop_events() { - int i_install = 0; - int i_uninstall = 0; - event_t ev; - - LogDebug("Looking events..."); - do { - while(m_queue.pop_event(ev)) { - if (ev.event_type == event_t::event_type_t::APP_INSTALL) - i_install++; - else if (ev.event_type == event_t::event_type_t::APP_UNINSTALL) - i_uninstall++; - } - } while (m_sent < m_max_events); - - // Read all events once again - just for case - while(m_queue.pop_event(ev)) { - if (ev.event_type == event_t::event_type_t::APP_INSTALL) - i_install++; - else if (ev.event_type == event_t::event_type_t::APP_UNINSTALL) - i_uninstall++; - } - LogDebug("Found " << i_install + i_uninstall << " events."); - - if (i_install != m_max_events/2 || i_uninstall != m_max_events/2) - return false; - return true; + int i_install = 0; + int i_uninstall = 0; + event_t ev; + LogDebug("Looking events..."); + + do { + while (m_queue.pop_event(ev)) { + if (ev.event_type == event_t::event_type_t::APP_INSTALL) + i_install++; + else if (ev.event_type == event_t::event_type_t::APP_UNINSTALL) + i_uninstall++; + } + } while (m_sent < m_max_events); + + // Read all events once again - just for case + while (m_queue.pop_event(ev)) { + if (ev.event_type == event_t::event_type_t::APP_INSTALL) + i_install++; + else if (ev.event_type == event_t::event_type_t::APP_UNINSTALL) + i_uninstall++; + } + + LogDebug("Found " << i_install + i_uninstall << " events."); + + if (i_install != m_max_events / 2 || i_uninstall != m_max_events / 2) + return false; + + return true; } } // CCHECKER diff --git a/tests/queue_test_thread.h b/tests/queue_test_thread.h index 2c2989e..329a29c 100644 --- a/tests/queue_test_thread.h +++ b/tests/queue_test_thread.h @@ -25,19 +25,19 @@ namespace CCHECKER { class TestQueue { - public: - TestQueue(): - m_sent(0), - m_max_events(0) - {}; - void add_events_th (int number_of_threads); - bool pop_events (); +public: + TestQueue(): + m_sent(0), + m_max_events(0) + {}; + void add_events_th(int number_of_threads); + bool pop_events(); - private: - Queue m_queue; - int m_sent; - int m_max_events; - void add_events(); +private: + Queue m_queue; + int m_sent; + int m_max_events; + void add_events(); }; } // CCHECKER diff --git a/tests/stubs_.cpp b/tests/stubs_.cpp index 1360986..2f46fb1 100644 --- a/tests/stubs_.cpp +++ b/tests/stubs_.cpp @@ -38,37 +38,38 @@ Certs::~Certs() void Certs::get_certificates(app_t &app) { - (void)app; + (void)app; } // Only the public functions need to be stubbed for testing all possibilities Certs::ocsp_response_t Certs::check_ocsp(const app_t &app) { - if (app.signatures.empty()) - return ocsp_response_t::OCSP_APP_OK; + if (app.signatures.empty()) + return ocsp_response_t::OCSP_APP_OK; - if (app.signatures.front().empty()) - return ocsp_response_t::OCSP_APP_OK; + if (app.signatures.front().empty()) + return ocsp_response_t::OCSP_APP_OK; - std::string ret = app.signatures.front().front(); + std::string ret = app.signatures.front().front(); - if ("OCSP_APP_REVOKED" == ret) - return ocsp_response_t::OCSP_APP_REVOKED; - if ("OCSP_CHECK_AGAIN" == ret) - return ocsp_response_t::OCSP_CHECK_AGAIN; - if ("OCSP_CERT_ERROR" == ret) - return ocsp_response_t::OCSP_CERT_ERROR; + if ("OCSP_APP_REVOKED" == ret) + return ocsp_response_t::OCSP_APP_REVOKED; - return ocsp_response_t::OCSP_APP_OK; + if ("OCSP_CHECK_AGAIN" == ret) + return ocsp_response_t::OCSP_CHECK_AGAIN; + + if ("OCSP_CERT_ERROR" == ret) + return ocsp_response_t::OCSP_CERT_ERROR; + + return ocsp_response_t::OCSP_APP_OK; } // DB DB::SqlQuery::SqlQuery(const std::string &path) { - m_connection = NULL; - m_inUserTransaction = false; - - (void)path; + m_connection = NULL; + m_inUserTransaction = false; + (void)path; } DB::SqlQuery::~SqlQuery() @@ -76,29 +77,29 @@ DB::SqlQuery::~SqlQuery() bool DB::SqlQuery::add_app_to_check_list(const app_t &app) { - (void)app; - return true; // Success + (void)app; + return true; // Success } void DB::SqlQuery::remove_app_from_check_list(const app_t &app) { - (void)app; + (void)app; } void DB::SqlQuery::mark_as_verified(const app_t &app, const app_t::verified_t &verified) { - (void)app; - (void)verified; + (void)app; + (void)verified; } void DB::SqlQuery::get_app_list(std::list<app_t> &apps_buffer) { - (void)apps_buffer; + (void)apps_buffer; } // UI UI::UIBackend::UIBackend(int timeout) : - m_responseTimeout(timeout) + m_responseTimeout(timeout) {} UI::UIBackend::~UIBackend() @@ -106,10 +107,10 @@ UI::UIBackend::~UIBackend() bool UI::UIBackend::call_popup(const app_t &app) { - if (app.uid > 5000) - return true; + if (app.uid > 5000) + return true; - return false; + return false; } } //CCHECKER diff --git a/tests/test_app.cpp b/tests/test_app.cpp index c32d571..8035dfa 100644 --- a/tests/test_app.cpp +++ b/tests/test_app.cpp @@ -30,111 +30,98 @@ using namespace CCHECKER; BOOST_FIXTURE_TEST_SUITE(APP_TEST, app_t) -BOOST_AUTO_TEST_CASE(App_positive) { - - app_t app1("app_1", "pkg_1", 5001, {{"aaaaaa"}}); - app_t app2("app_1", "pkg_1", 5001, {{"aaaaaa"}}); - - app_t app3("app_2", "pkg_1", 5002, {{"aaa", "bbbb"}, {"ccccc"}}); - app_t app4("app_2", "pkg_1", 5002, {{"ccccc"}, {"aaa", "bbbb"}}); - - chain_t chain411 = {"cert_4.1", "cert 4.2"}; - chain_t chain421 = {"cert_4.2.1", "cert 4.2.2", "cert 4.2.3"}; - chain_t chain43 = {"cert_4.3.1"}; - - app_t app5("app_3", "pkg_1", 5003, {chain411, chain421, chain43}); - app_t app6("app_3", "pkg_1", 5003, {chain421, chain411, chain43}); - app_t app7("app_3", "pkg_1", 5003, {chain411, chain43, chain421}); - app_t app8("app_3", "pkg_1", 5003, {chain421, chain43, chain411}); - app_t app9("app_3", "pkg_1", 5003, {chain43, chain411, chain421}); - app_t app10("app_3", "pkg_1", 5003, {chain43, chain421, chain411}); - - sort(app1); - sort(app2); - sort(app3); - sort(app4); - sort(app5); - sort(app6); - sort(app7); - sort(app8); - sort(app9); - sort(app10); - - BOOST_REQUIRE(app1 == app2); - - BOOST_REQUIRE(app3 == app4); - - BOOST_REQUIRE(app5 == app6); - BOOST_REQUIRE(app6 == app7); - BOOST_REQUIRE(app7 == app8); - BOOST_REQUIRE(app8 == app9); - BOOST_REQUIRE(app9 == app10); +BOOST_AUTO_TEST_CASE(App_positive) +{ + app_t app1("app_1", "pkg_1", 5001, {{"aaaaaa"}}); + app_t app2("app_1", "pkg_1", 5001, {{"aaaaaa"}}); + app_t app3("app_2", "pkg_1", 5002, {{"aaa", "bbbb"}, {"ccccc"}}); + app_t app4("app_2", "pkg_1", 5002, {{"ccccc"}, {"aaa", "bbbb"}}); + chain_t chain411 = {"cert_4.1", "cert 4.2"}; + chain_t chain421 = {"cert_4.2.1", "cert 4.2.2", "cert 4.2.3"}; + chain_t chain43 = {"cert_4.3.1"}; + app_t app5("app_3", "pkg_1", 5003, {chain411, chain421, chain43}); + app_t app6("app_3", "pkg_1", 5003, {chain421, chain411, chain43}); + app_t app7("app_3", "pkg_1", 5003, {chain411, chain43, chain421}); + app_t app8("app_3", "pkg_1", 5003, {chain421, chain43, chain411}); + app_t app9("app_3", "pkg_1", 5003, {chain43, chain411, chain421}); + app_t app10("app_3", "pkg_1", 5003, {chain43, chain421, chain411}); + sort(app1); + sort(app2); + sort(app3); + sort(app4); + sort(app5); + sort(app6); + sort(app7); + sort(app8); + sort(app9); + sort(app10); + BOOST_REQUIRE(app1 == app2); + BOOST_REQUIRE(app3 == app4); + BOOST_REQUIRE(app5 == app6); + BOOST_REQUIRE(app6 == app7); + BOOST_REQUIRE(app7 == app8); + BOOST_REQUIRE(app8 == app9); + BOOST_REQUIRE(app9 == app10); } -BOOST_AUTO_TEST_CASE(App_negative) { - - app_t app1("app_1", "pkg_1", 5001, {{"aaaaaa"}}); - app_t app2("app_2", "pkg_1", 5001, {{"aaaaaa"}}); - app_t app3("app_2", "pkg_2", 5001, {{"aaaaaa"}}); - app_t app4("app_2", "pkg_2", 5002, {{"aaaaaa"}}); - - chain_t chain411 = {"cert_4.1", "cert 4.2"}; - chain_t chain412 = {"cert 4.2", "cert_4.1"}; - - chain_t chain421 = {"cert_4.2.1", "cert 4.2.2", "cert 4.2.3"}; - chain_t chain422 = {"cert_4.2.1", "cert 4.2.3", "cert_4.2.2"}; - chain_t chain423 = {"cert_4.2.3", "cert 4.2.1", "cert_4.2.2"}; - chain_t chain424 = {"cert_4.2.3", "cert 4.2.2", "cert_4.2.1"}; - chain_t chain425 = {"cert_4.2.2", "cert 4.2.1", "cert_4.2.3"}; - chain_t chain426 = {"cert_4.2.2", "cert 4.2.3", "cert_4.2.1"}; - - chain_t chain427 = {"cert", "cert_4.2.1", "cert 4.2.2"}; - chain_t chain428 = {"cert_4.2.1", " ", "cert 4.2.2"}; - chain_t chain429 = {"cert 4.2.3", "cert 4.2.2"}; - chain_t chain420 = {"cert 4.2" , "cert_4.2" , "cert 4.2" }; - - chain_t chain43 = {"cert_4.3.1"}; - - app_t app5("app_3", "pkg_1", 5003, {chain411, chain421, chain43}); - app_t app6("app_3", "pkg_1", 5003, {chain411, chain422, chain43}); - app_t app7("app_3", "pkg_1", 5003, {chain411, chain423, chain43}); - app_t app8("app_3", "pkg_1", 5003, {chain411, chain424, chain43}); - app_t app9("app_3", "pkg_1", 5003, {chain411, chain425, chain43}); - app_t app10("app_3", "pkg_1", 5003, {chain411, chain426, chain43}); - app_t app11("app_3", "pkg_1", 5003, {chain412, chain421, chain43}); - app_t app12("app_3", "pkg_1", 5003, {chain412, chain422, chain43}); - app_t app13("app_3", "pkg_1", 5003, {chain412, chain423, chain43}); - app_t app14("app_3", "pkg_1", 5003, {chain412, chain424, chain43}); - app_t app15("app_3", "pkg_1", 5003, {chain412, chain425, chain43}); - app_t app16("app_3", "pkg_1", 5003, {chain412, chain426, chain43}); - - app_t app17("app_3", "pkg_1", 5003, {chain421}); - app_t app18("app_3", "pkg_1", 5003, {chain422}); - app_t app19("app_3", "pkg_1", 5003, {chain423}); - app_t app20("app_3", "pkg_1", 5003, {chain424}); - app_t app21("app_3", "pkg_1", 5003, {chain425}); - app_t app22("app_3", "pkg_1", 5003, {chain426}); - app_t app23("app_3", "pkg_1", 5003, {chain427}); - app_t app24("app_3", "pkg_1", 5003, {chain428}); - app_t app25("app_3", "pkg_1", 5003, {chain429}); - app_t app26("app_3", "pkg_1", 5003, {chain420}); - - app_t apps[26] = {app1, app2, app3, app4, app5, app6, app7, app8, - app9, app10, app11, app12, app13, app14, app15, app16, app17, - app18, app19, app20, app21, app22, app23, app24, app25, app26}; - - for (int i=0; i<26; i++) { - sort(apps[i]); - } - - for (int i=0; i<26; i++) { - for (int j=0; j<26; j++) { - if (i != j) - BOOST_REQUIRE(apps[i] != apps[j]); - else - BOOST_REQUIRE(apps[i] == apps[j]); - } - } +BOOST_AUTO_TEST_CASE(App_negative) +{ + app_t app1("app_1", "pkg_1", 5001, {{"aaaaaa"}}); + app_t app2("app_2", "pkg_1", 5001, {{"aaaaaa"}}); + app_t app3("app_2", "pkg_2", 5001, {{"aaaaaa"}}); + app_t app4("app_2", "pkg_2", 5002, {{"aaaaaa"}}); + chain_t chain411 = {"cert_4.1", "cert 4.2"}; + chain_t chain412 = {"cert 4.2", "cert_4.1"}; + chain_t chain421 = {"cert_4.2.1", "cert 4.2.2", "cert 4.2.3"}; + chain_t chain422 = {"cert_4.2.1", "cert 4.2.3", "cert_4.2.2"}; + chain_t chain423 = {"cert_4.2.3", "cert 4.2.1", "cert_4.2.2"}; + chain_t chain424 = {"cert_4.2.3", "cert 4.2.2", "cert_4.2.1"}; + chain_t chain425 = {"cert_4.2.2", "cert 4.2.1", "cert_4.2.3"}; + chain_t chain426 = {"cert_4.2.2", "cert 4.2.3", "cert_4.2.1"}; + chain_t chain427 = {"cert", "cert_4.2.1", "cert 4.2.2"}; + chain_t chain428 = {"cert_4.2.1", " ", "cert 4.2.2"}; + chain_t chain429 = {"cert 4.2.3", "cert 4.2.2"}; + chain_t chain420 = {"cert 4.2" , "cert_4.2" , "cert 4.2" }; + chain_t chain43 = {"cert_4.3.1"}; + app_t app5("app_3", "pkg_1", 5003, {chain411, chain421, chain43}); + app_t app6("app_3", "pkg_1", 5003, {chain411, chain422, chain43}); + app_t app7("app_3", "pkg_1", 5003, {chain411, chain423, chain43}); + app_t app8("app_3", "pkg_1", 5003, {chain411, chain424, chain43}); + app_t app9("app_3", "pkg_1", 5003, {chain411, chain425, chain43}); + app_t app10("app_3", "pkg_1", 5003, {chain411, chain426, chain43}); + app_t app11("app_3", "pkg_1", 5003, {chain412, chain421, chain43}); + app_t app12("app_3", "pkg_1", 5003, {chain412, chain422, chain43}); + app_t app13("app_3", "pkg_1", 5003, {chain412, chain423, chain43}); + app_t app14("app_3", "pkg_1", 5003, {chain412, chain424, chain43}); + app_t app15("app_3", "pkg_1", 5003, {chain412, chain425, chain43}); + app_t app16("app_3", "pkg_1", 5003, {chain412, chain426, chain43}); + app_t app17("app_3", "pkg_1", 5003, {chain421}); + app_t app18("app_3", "pkg_1", 5003, {chain422}); + app_t app19("app_3", "pkg_1", 5003, {chain423}); + app_t app20("app_3", "pkg_1", 5003, {chain424}); + app_t app21("app_3", "pkg_1", 5003, {chain425}); + app_t app22("app_3", "pkg_1", 5003, {chain426}); + app_t app23("app_3", "pkg_1", 5003, {chain427}); + app_t app24("app_3", "pkg_1", 5003, {chain428}); + app_t app25("app_3", "pkg_1", 5003, {chain429}); + app_t app26("app_3", "pkg_1", 5003, {chain420}); + app_t apps[26] = {app1, app2, app3, app4, app5, app6, app7, app8, + app9, app10, app11, app12, app13, app14, app15, app16, app17, + app18, app19, app20, app21, app22, app23, app24, app25, app26 + }; + + for (int i = 0; i < 26; i++) { + sort(apps[i]); + } + + for (int i = 0; i < 26; i++) { + for (int j = 0; j < 26; j++) { + if (i != j) + BOOST_REQUIRE(apps[i] != apps[j]); + else + BOOST_REQUIRE(apps[i] == apps[j]); + } + } } BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/test_certs.cpp b/tests/test_certs.cpp index e9f5b34..e51dbdd 100644 --- a/tests/test_certs.cpp +++ b/tests/test_certs.cpp @@ -32,11 +32,11 @@ using namespace CCHECKER; BOOST_FIXTURE_TEST_SUITE(CERT_TEST, Certs_) -BOOST_AUTO_TEST_CASE(Certs_OCSP_positive) { - - //*.wikipedia.com: - chain_t chain = { - "MIIH1jCCBr6gAwIBAgISESGXLjKl5bLinUct/tty1iduMA0GCSqGSIb3DQEBCwUA\ +BOOST_AUTO_TEST_CASE(Certs_OCSP_positive) +{ + //*.wikipedia.com: + chain_t chain = { + "MIIH1jCCBr6gAwIBAgISESGXLjKl5bLinUct/tty1iduMA0GCSqGSIb3DQEBCwUA\ MGYxCzAJBgNVBAYTAkJFMRkwFwYDVQQKExBHbG9iYWxTaWduIG52LXNhMTwwOgYD\ VQQDEzNHbG9iYWxTaWduIE9yZ2FuaXphdGlvbiBWYWxpZGF0aW9uIENBIC0gU0hB\ MjU2IC0gRzIwHhcNMTQxMjE2MjEyNDAzWhcNMTcwMjE5MTIwMDAwWjB5MQswCQYD\ @@ -79,7 +79,7 @@ gOk/sO6ilkOun/u5QBigxne1/P4g2SYkISqRqA0Z9FloEd6odDb6dbIHhhz270rH\ 4V9POUs5kH7d1OJs9d5Fv9y3t/Yt1pGaHyK/DTUbYVhMyn0EaLxd3FLJ9ABKpQJ+\ OUcTfe55U2Ox1H/87b6Ca04DDl3u2i87jPbhgshWSNwU8+llHCst0sbG", -"MIIEaTCCA1GgAwIBAgILBAAAAAABRE7wQkcwDQYJKoZIhvcNAQELBQAwVzELMAkG\ + "MIIEaTCCA1GgAwIBAgILBAAAAAABRE7wQkcwDQYJKoZIhvcNAQELBQAwVzELMAkG\ A1UEBhMCQkUxGTAXBgNVBAoTEEdsb2JhbFNpZ24gbnYtc2ExEDAOBgNVBAsTB1Jv\ b3QgQ0ExGzAZBgNVBAMTEkdsb2JhbFNpZ24gUm9vdCBDQTAeFw0xNDAyMjAxMDAw\ MDBaFw0yNDAyMjAxMDAwMDBaMGYxCzAJBgNVBAYTAkJFMRkwFwYDVQQKExBHbG9i\ @@ -104,7 +104,7 @@ XN0cvfNVlg/UBsD84iOKJHDTu/B5GqdhcIOKrwbFINihY9Bsrk8y1658GEV1BSl3\ SOlCdjSXVWkkDoPWoC209fN5ikkodBpBocLTJIg1MGCUF7ThBCIxPTsvFwayuJ2G\ K1pp74P1S8SqtCr4fKGxhZSM9AyHDPSsQPhZSZg=", -"MIIDdTCCAl2gAwIBAgILBAAAAAABFUtaw5QwDQYJKoZIhvcNAQEFBQAwVzELMAkG\ + "MIIDdTCCAl2gAwIBAgILBAAAAAABFUtaw5QwDQYJKoZIhvcNAQEFBQAwVzELMAkG\ A1UEBhMCQkUxGTAXBgNVBAoTEEdsb2JhbFNpZ24gbnYtc2ExEDAOBgNVBAsTB1Jv\ b3QgQ0ExGzAZBgNVBAMTEkdsb2JhbFNpZ24gUm9vdCBDQTAeFw05ODA5MDExMjAw\ MDBaFw0yODAxMjgxMjAwMDBaMFcxCzAJBgNVBAYTAkJFMRkwFwYDVQQKExBHbG9i\ @@ -122,19 +122,19 @@ yj1hTdNGCbM+w6DjY1Ub8rrvrTnhQ7k4o+YviiY776BQVvnGCv04zcQLcFGUl5gE\ 38NflNUVyRRBnMRddWQVDf9VMOyGj/8N7yy5Y0b2qvzfvGn9LhJIZJrglfCm7ymP\ AbEVtQwdpf5pLGkkeB6zpxxxYu7KyJesF12KwvhHhm4qxFYxldBniYUr+WymXUad\ DKqC5JlR3XC321Y9YeRq4VzW9v493kHMB65jUr9TU/Qr6cf9tveCX4XSQRjbgbME\ -HMUfpIBvFSDJ3gyICh3WZlXi/EjJKSZp4A=="}; - - Certs::ocsp_response_t resp = check_ocsp_chain_ (chain); - LogDebug("Certs_::check_ocsp_chain_ response : " << (int) resp); - BOOST_REQUIRE(resp == Certs::ocsp_response_t::OCSP_CHECK_AGAIN); +HMUfpIBvFSDJ3gyICh3WZlXi/EjJKSZp4A==" + }; + Certs::ocsp_response_t resp = check_ocsp_chain_(chain); + LogDebug("Certs_::check_ocsp_chain_ response : " << (int) resp); + BOOST_REQUIRE(resp == Certs::ocsp_response_t::OCSP_CHECK_AGAIN); } -BOOST_AUTO_TEST_CASE(Certs_OCSP_negative_1) { - // Broken chain of certificates - - //*.wikipedia.com: - chain_t chain = { - "MIIH1jCCBr6gAwIBAgISESGXLjKl5bLinUct/tty1iduMA0GCSqGSIb3DQEBCwUA\ +BOOST_AUTO_TEST_CASE(Certs_OCSP_negative_1) +{ + // Broken chain of certificates + //*.wikipedia.com: + chain_t chain = { + "MIIH1jCCBr6gAwIBAgISESGXLjKl5bLinUct/tty1iduMA0GCSqGSIb3DQEBCwUA\ MGYxCzAJBgNVBAYTAkJFMRkwFwYDVQQKExBHbG9iYWxTaWduIG52LXNhMTwwOgYD\ VQQDEzNHbG9iYWxTaWduIE9yZ2FuaXphdGlvbiBWYWxpZGF0aW9uIENBIC0gU0hB\ MjU2IC0gRzIwHhcNMTQxMjE2MjEyNDAzWhcNMTcwMjE5MTIwMDAwWjB5MQswCQYD\ @@ -175,18 +175,18 @@ gwBA5hp8MA0GCSqGSIb3DQEBCwUAA4IBAQC45+nGVISGOZctc9mxhil3EDmlBIzY\ gOk/sO6ilkOun/u5QBigxne1/P4g2SYkISqRqA0Z9FloEd6odDb6dbIHhhz270rH\ 3pjewMLq6OA09eklPav4f3NiBL/VcqG53TRTJW6eHxZuEsGAgBmwk6jKf8e+BjmZ\ 4V9POUs5kH7d1OJs9d5Fv9y3t/Yt1pGaHyK/DTUbYVhMyn0EaLxd3FLJ9ABKpQJ+\ -OUcTfe55U2Ox1H/87b6Ca04DDl3u2i87jPbhgshWSNwU8+llHCst0sbG"}; - - Certs::ocsp_response_t resp = check_ocsp_chain_ (chain); - LogDebug("Certs_::check_ocsp_chain_ response : " << (int) resp); - BOOST_REQUIRE(resp == Certs::ocsp_response_t::OCSP_CERT_ERROR); +OUcTfe55U2Ox1H/87b6Ca04DDl3u2i87jPbhgshWSNwU8+llHCst0sbG" + }; + Certs::ocsp_response_t resp = check_ocsp_chain_(chain); + LogDebug("Certs_::check_ocsp_chain_ response : " << (int) resp); + BOOST_REQUIRE(resp == Certs::ocsp_response_t::OCSP_CERT_ERROR); } -BOOST_AUTO_TEST_CASE(Certs_OCSP_negative_2) { - // Last Certificate is corrupted - - chain_t chain = { - "MIIH1jCCBr6gAwIBAgISESGXLjKl5bLinUct/tty1iduMA0GCSqGSIb3DQEBCwUA\ +BOOST_AUTO_TEST_CASE(Certs_OCSP_negative_2) +{ + // Last Certificate is corrupted + chain_t chain = { + "MIIH1jCCBr6gAwIBAgISESGXLjKl5bLinUct/tty1iduMA0GCSqGSIb3DQEBCwUA\ MGYxCzAJBgNVBAYTAkJFMRkwFwYDVQQKExBHbG9iYWxTaWduIG52LXNhMTwwOgYD\ VQQDEzNHbG9iYWxTaWduIE9yZ2FuaXphdGlvbiBWYWxpZGF0aW9uIENBIC0gU0hB\ MjU2IC0gRzIwHhcNMTQxMjE2MjEyNDAzWhcNMTcwMjE5MTIwMDAwWjB5MQswCQYD\ @@ -229,7 +229,7 @@ gOk/sO6ilkOun/u5QBigxne1/P4g2SYkISqRqA0Z9FloEd6odDb6dbIHhhz270rH\ 4V9POUs5kH7d1OJs9d5Fv9y3t/Yt1pGaHyK/DTUbYVhMyn0EaLxd3FLJ9ABKpQJ+\ OUcTfe55U2Ox1H/87b6Ca04DDl3u2i87jPbhgshWSNwU8+llHCst0sbG", -"MIIEaTCCA1GgAwIBAgILBAAAAAABRE7wQkcwDQYJKoZIhvcNAQELBQAwVzELMAkG\ + "MIIEaTCCA1GgAwIBAgILBAAAAAABRE7wQkcwDQYJKoZIhvcNAQELBQAwVzELMAkG\ A1UEBhMCQkUxGTAXBgNVBAoTEEdsb2JhbFNpZ24gbnYtc2ExEDAOBgNVBAsTB1Jv\ b3QgQ0ExGzAZBgNVBAMTEkdsb2JhbFNpZ24gUm9vdCBDQTAeFw0xNDAyMjAxMDAw\ MDBaFw0yNDAyMjAxMDAwMDBaMGYxCzAJBgNVBAYTAkJFMRkwFwYDVQQKExBHbG9i\ @@ -254,7 +254,7 @@ XN0cvfNVlg/UBsD84iOKJHDTu/B5GqdhcIOKrwbFINihY9Bsrk8y1658GEV1BSl3\ SOlCdjSXVWkkDoPWoC209fN5ikkodBpBocLTJIg1MGCUF7ThBCIxPTsvFwayuJ2G\ K1pp74P1S8SqtCr4fKGxhZSM9AyHDPSsQPhZSZg=", -"MIIDdTCCAl2gAwIBAgILBAAAAAABFUtaw5QwDQYJKoZIhvcNAQEFBQAwVzELMAkG\ + "MIIDdTCCAl2gAwIBAgILBAAAAAABFUtaw5QwDQYJKoZIhvcNAQEFBQAwVzELMAkG\ A1UEBhMCQkUxGTAXBgNVBAoTEEdsb2JhbFNpZ24gbnYtc2ExEDAOBgNVBAsTB1Jv\ b3QgQ0ExGzAZBgNVBAMTEkdsb2JhbFNpZ24gUm9vdCBDQTAeFw05ODA5MDExMjAw\ MDBaFw0yODAxMjgxMjAwMDBaMFcxCzAJBgNVBAYTAkJFMRkwFwYDVQQKExBHbG9i\ @@ -272,18 +272,18 @@ yj1hTdNGCbM+w6DjY1Ub8rrvrTnhQ7k4o+YviiY776BQVvnGCv04zcQLcFGUl5gE\ 38NflNUVyRRBnMRddWQVDf9VMOyGj/8N7yy5Y0b2qvzfvGn9LhJIZJrglfCm7ymP\ AbEVtQwdpf5pLGkkeB6zpxxxYu7KyJesF12KwvhHhm4qxFYxldBniYUr+WymXUad\ DKqC5JlR3XC321Y9YeRq4VzW9v493kHMB65jUr9TU/Qr6cf9tveCX4XSQRjbgbME\ -HMUfpIBvFSDJ3gyICh3WZlXi/EjJKSZp4"}; - - Certs::ocsp_response_t resp = check_ocsp_chain_ (chain); - LogDebug("Certs_::check_ocsp_chain_ response : " << (int) resp); - BOOST_REQUIRE(resp == Certs::ocsp_response_t::OCSP_CERT_ERROR); +HMUfpIBvFSDJ3gyICh3WZlXi/EjJKSZp4" + }; + Certs::ocsp_response_t resp = check_ocsp_chain_(chain); + LogDebug("Certs_::check_ocsp_chain_ response : " << (int) resp); + BOOST_REQUIRE(resp == Certs::ocsp_response_t::OCSP_CERT_ERROR); } -BOOST_AUTO_TEST_CASE(Certs_OCSP_positive_1) { - - chain_t chain = { - // MBANK, signed by SYMANTEC, expires 04 Feb 2016 - "MIIGXDCCBUSgAwIBAgIQKJK70TuBw91HAA0BqZSPETANBgkqhkiG9w0BAQsFADB3\ +BOOST_AUTO_TEST_CASE(Certs_OCSP_positive_1) +{ + chain_t chain = { + // MBANK, signed by SYMANTEC, expires 04 Feb 2016 + "MIIGXDCCBUSgAwIBAgIQKJK70TuBw91HAA0BqZSPETANBgkqhkiG9w0BAQsFADB3\ MQswCQYDVQQGEwJVUzEdMBsGA1UEChMUU3ltYW50ZWMgQ29ycG9yYXRpb24xHzAd\ BgNVBAsTFlN5bWFudGVjIFRydXN0IE5ldHdvcmsxKDAmBgNVBAMTH1N5bWFudGVj\ IENsYXNzIDMgRVYgU1NMIENBIC0gRzMwHhcNMTUwMTE1MDAwMDAwWhcNMTYwMjA0\ @@ -318,8 +318,8 @@ SReh+urkTFGUdSPCsD4mQk3zI1wNhE7Amb2mUTIaSLzabnN89hn9jlvQwLH2Wkf2\ aFmUlsB1C6YFMqVPRfHuxyPUb2zjw+ll7UStQxuSSTpwBmW1g/dIhtle9+o8i3z2\ WJAT38TP3mPw8SUWLbgGyih6bsB6eBxFEM5awP60XXjZfVAmoVLlj9oWYNQrZLwk", - // SYMANTEC, signed by VERISIGN, expires 30 Oct 2023 - "MIIFKzCCBBOgAwIBAgIQfuFKb2/v8tN/P61lTTratDANBgkqhkiG9w0BAQsFADCB\ + // SYMANTEC, signed by VERISIGN, expires 30 Oct 2023 + "MIIFKzCCBBOgAwIBAgIQfuFKb2/v8tN/P61lTTratDANBgkqhkiG9w0BAQsFADCB\ yjELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQL\ ExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJp\ U2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxW\ @@ -347,11 +347,10 @@ qLuSLRtzsMarNvSWbCAI7woeZiRFT2cAQMgHVHQzO6atuyOfZu2iRHA0+w7qAf3P\ eHTfp61Vt19N9tY/4IbOJMdCqRMURDVLtt/JYKwMf9mTIUvunORJApjTYHtcvNUw\ LwfORELEC5n+5p/8sHiGUW3RLJ3GlvuFgrsEL/digO9i2n/2DqyQuFa9eT/ygG6j\ 2bkPXToHHZGThkspTOHcteHgM52zyzaRS/6htO7w+Q==" - }; - - Certs::ocsp_response_t resp = check_ocsp_chain_ (chain); - LogDebug("Certs_::check_ocsp_chain_ response : " << (int) resp); - BOOST_REQUIRE(resp == Certs::ocsp_response_t::OCSP_APP_OK); + }; + Certs::ocsp_response_t resp = check_ocsp_chain_(chain); + LogDebug("Certs_::check_ocsp_chain_ response : " << (int) resp); + BOOST_REQUIRE(resp == Certs::ocsp_response_t::OCSP_APP_OK); } BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/test_client.cpp b/tests/test_client.cpp index a0fc0c2..83661f4 100644 --- a/tests/test_client.cpp +++ b/tests/test_client.cpp @@ -27,11 +27,10 @@ BOOST_AUTO_TEST_SUITE(CLIENT_TEST) -BOOST_AUTO_TEST_CASE(client_api) { - +BOOST_AUTO_TEST_CASE(client_api) +{ auto ret = cchecker_ocsp_request(); BOOST_REQUIRE(ret == 0); - } BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/test_db.cpp b/tests/test_db.cpp index 9649087..1f6541d 100644 --- a/tests/test_db.cpp +++ b/tests/test_db.cpp @@ -31,93 +31,70 @@ BOOST_FIXTURE_TEST_SUITE(DB_TEST, DBFixture) -BOOST_AUTO_TEST_CASE(DB_app_positive) { - - std::list<app_t> buffer; - app_t app1("app_1", "pkg_1", 5001, {}); - - chain_t chain2 = {"cert2"}; - app_t app2("app_2", "pkg 2", 5002, {chain2}); - - chain_t chain2r = {"cert2r"}; - app_t app2r("app_2_remove", "pkg 2", 5002, {chain2, chain2r}); - - chain_t chain31 = {"cert_3.1", "cert 3.2"}; - chain_t chain32 = {"cert_3.1"}; - app_t app3("app 3", "pkg 3", 5003, {chain31, chain32}); - - chain_t chain41 = {"cert_4.1", "cert 4.2"}; - chain_t chain42 = {"cert_4.2.1", "cert 4.2.2", "cert 4.2.3"}; - chain_t chain43 = {"cert_4.3.1"}; - - app_t app4("app 4", "pkg 4", 5004, {chain41, chain42, chain43}); - - BOOST_REQUIRE(add_app_to_check_list(app1)==true); - BOOST_REQUIRE(add_app_to_check_list(app2)==true); - BOOST_REQUIRE(add_app_to_check_list(app2r)==true); - BOOST_REQUIRE(add_app_to_check_list(app3)==true); - BOOST_REQUIRE(add_app_to_check_list(app4)==true); - - mark_as_verified(app2, app_t::verified_t::NO); - mark_as_verified(app3, app_t::verified_t::YES); - remove_app_from_check_list(app2r); - - app2.verified = app_t::verified_t::NO; - app3.verified = app_t::verified_t::YES; - - std::list<app_t> buffer_ok = {app1, app2, app3, app4}; - - get_app_list(buffer); - - // Need to sort buffer - sort_buffer(buffer); - sort_buffer(buffer_ok); - - BOOST_REQUIRE(buffer_ok == buffer); +BOOST_AUTO_TEST_CASE(DB_app_positive) +{ + std::list<app_t> buffer; + app_t app1("app_1", "pkg_1", 5001, {}); + chain_t chain2 = {"cert2"}; + app_t app2("app_2", "pkg 2", 5002, {chain2}); + chain_t chain2r = {"cert2r"}; + app_t app2r("app_2_remove", "pkg 2", 5002, {chain2, chain2r}); + chain_t chain31 = {"cert_3.1", "cert 3.2"}; + chain_t chain32 = {"cert_3.1"}; + app_t app3("app 3", "pkg 3", 5003, {chain31, chain32}); + chain_t chain41 = {"cert_4.1", "cert 4.2"}; + chain_t chain42 = {"cert_4.2.1", "cert 4.2.2", "cert 4.2.3"}; + chain_t chain43 = {"cert_4.3.1"}; + app_t app4("app 4", "pkg 4", 5004, {chain41, chain42, chain43}); + BOOST_REQUIRE(add_app_to_check_list(app1) == true); + BOOST_REQUIRE(add_app_to_check_list(app2) == true); + BOOST_REQUIRE(add_app_to_check_list(app2r) == true); + BOOST_REQUIRE(add_app_to_check_list(app3) == true); + BOOST_REQUIRE(add_app_to_check_list(app4) == true); + mark_as_verified(app2, app_t::verified_t::NO); + mark_as_verified(app3, app_t::verified_t::YES); + remove_app_from_check_list(app2r); + app2.verified = app_t::verified_t::NO; + app3.verified = app_t::verified_t::YES; + std::list<app_t> buffer_ok = {app1, app2, app3, app4}; + get_app_list(buffer); + // Need to sort buffer + sort_buffer(buffer); + sort_buffer(buffer_ok); + BOOST_REQUIRE(buffer_ok == buffer); } -BOOST_AUTO_TEST_CASE(DB_app_negative) { - - std::list<app_t> buffer; - app_t app1("app_1", "pkg_1", 5001, {}); - - chain_t chain2 = {"cert2"}; - app_t app2("app_2", "pkg 2", 5002, {chain2}); - - chain_t chain2r = {"cert2r"}; - app_t app2r("app_2_remove", "pkg 2", 5002, {chain2, chain2r}); - - chain_t chain31 = {"cert_3.1", "cert 3.2"}; - chain_t chain32 = {"cert_3.1"}; - app_t app3("app 3", "pkg 3", 5003, {chain31, chain32}); - - chain_t chain41 = {"cert_4.1", "cert 4.2"}; - chain_t chain42 = {"cert_4.2.1", "cert 4.2.2", "cert 4.2.3"}; - chain_t chain43 = {"cert_4.3.1"}; - - app_t app4("app 4", "pkg 4", 5004, {chain41, chain42, chain43}); - - BOOST_REQUIRE(add_app_to_check_list(app1)==true); - BOOST_REQUIRE(add_app_to_check_list(app2)==true); - BOOST_REQUIRE(add_app_to_check_list(app2r)==true); - // Skipp adding app3 to database - BOOST_REQUIRE(add_app_to_check_list(app4)==true); - - mark_as_verified(app2, app_t::verified_t::NO); - mark_as_verified(app3, app_t::verified_t::YES); - remove_app_from_check_list(app2r); - - app2.verified = app_t::verified_t::NO; - app3.verified = app_t::verified_t::YES; - - std::list<app_t> buffer_ok = {app1, app2, app3, app4}; - - get_app_list(buffer); - - // list has to be sorted before comparison. - sort_buffer(buffer); - sort_buffer(buffer_ok); - BOOST_REQUIRE(buffer_ok != buffer); +BOOST_AUTO_TEST_CASE(DB_app_negative) +{ + std::list<app_t> buffer; + app_t app1("app_1", "pkg_1", 5001, {}); + chain_t chain2 = {"cert2"}; + app_t app2("app_2", "pkg 2", 5002, {chain2}); + chain_t chain2r = {"cert2r"}; + app_t app2r("app_2_remove", "pkg 2", 5002, {chain2, chain2r}); + chain_t chain31 = {"cert_3.1", "cert 3.2"}; + chain_t chain32 = {"cert_3.1"}; + app_t app3("app 3", "pkg 3", 5003, {chain31, chain32}); + chain_t chain41 = {"cert_4.1", "cert 4.2"}; + chain_t chain42 = {"cert_4.2.1", "cert 4.2.2", "cert 4.2.3"}; + chain_t chain43 = {"cert_4.3.1"}; + app_t app4("app 4", "pkg 4", 5004, {chain41, chain42, chain43}); + BOOST_REQUIRE(add_app_to_check_list(app1) == true); + BOOST_REQUIRE(add_app_to_check_list(app2) == true); + BOOST_REQUIRE(add_app_to_check_list(app2r) == true); + // Skipp adding app3 to database + BOOST_REQUIRE(add_app_to_check_list(app4) == true); + mark_as_verified(app2, app_t::verified_t::NO); + mark_as_verified(app3, app_t::verified_t::YES); + remove_app_from_check_list(app2r); + app2.verified = app_t::verified_t::NO; + app3.verified = app_t::verified_t::YES; + std::list<app_t> buffer_ok = {app1, app2, app3, app4}; + get_app_list(buffer); + // list has to be sorted before comparison. + sort_buffer(buffer); + sort_buffer(buffer_ok); + BOOST_REQUIRE(buffer_ok != buffer); } BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/test_logic.cpp b/tests/test_logic.cpp index 56c8290..2b80aff 100644 --- a/tests/test_logic.cpp +++ b/tests/test_logic.cpp @@ -37,436 +37,315 @@ namespace { std::string log_apps(std::list<app_t> &apps, std::list<app_t> buff) { - std::string ret = "\nApps:\n"; + std::string ret = "\nApps:\n"; - for (const auto &iter : apps) { - ret += iter.str() + "\n"; - } + for (const auto &iter : apps) { + ret += iter.str() + "\n"; + } - ret += "Buff:\n"; - for (const auto &iter : buff) { - ret+= iter.str() + "\n"; - } + ret += "Buff:\n"; - return ret; + for (const auto &iter : buff) { + ret += iter.str() + "\n"; + } + + return ret; } } // anonymous namespace BOOST_FIXTURE_TEST_SUITE(LOGIC_TEST, LogicWrapper) -BOOST_AUTO_TEST_CASE(logic_setup) { - - BOOST_REQUIRE(setup() == NO_ERROR); - - // double setup - BOOST_REQUIRE(setup() == NO_ERROR); - - // double setup - BOOST_REQUIRE(setup() == NO_ERROR); +BOOST_AUTO_TEST_CASE(logic_setup) +{ + BOOST_REQUIRE(setup() == NO_ERROR); + // double setup + BOOST_REQUIRE(setup() == NO_ERROR); + // double setup + BOOST_REQUIRE(setup() == NO_ERROR); } -BOOST_AUTO_TEST_CASE(logic_workflow_mixed) { - BOOST_REQUIRE(setup() == NO_ERROR); - - wait_for_worker(); - - // turn off the network - connman_callback_manual_(false); - - // add applications: - app_t app1("app_1", "pkg_1", 5001, {}); - pkgmgr_install_manual_(app1); - - app_t app2("app_2", "pkg_1", 5001, {}); - pkgmgr_install_manual_(app2); - - app_t app3("app_2", "pkg_2", 5001, {}); - pkgmgr_install_manual_(app3); - - // remove app 2 - pkgmgr_uninstall_manual_(app2); - - wait_for_worker(3, 1); - - std::list<app_t> buff = get_buffer_(); - std::list<app_t> apps = {app1, app2, app3}; - BOOST_REQUIRE(buff != apps); - - apps = {app1, app3}; - BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); - - // Add other apps - pkgmgr_install_manual_(app2); - - // install the same app again - // it should never happen in real workflow - pkgmgr_install_manual_(app3); - - app_t app4("app_4", "pkg_4", 5002, {}); - pkgmgr_install_manual_(app4); - - wait_for_worker(3); - - buff = get_buffer_(); - BOOST_REQUIRE(buff != apps); - - apps = {app1, app3, app2, app4}; - - BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); - - // turn on the Internet - buffer should be processed - connman_callback_manual_(true); - - wait_for_worker(0, 0, 4); - buff = get_buffer_(); - BOOST_CHECK(buff.empty()); +BOOST_AUTO_TEST_CASE(logic_workflow_mixed) +{ + BOOST_REQUIRE(setup() == NO_ERROR); + wait_for_worker(); + // turn off the network + connman_callback_manual_(false); + // add applications: + app_t app1("app_1", "pkg_1", 5001, {}); + pkgmgr_install_manual_(app1); + app_t app2("app_2", "pkg_1", 5001, {}); + pkgmgr_install_manual_(app2); + app_t app3("app_2", "pkg_2", 5001, {}); + pkgmgr_install_manual_(app3); + // remove app 2 + pkgmgr_uninstall_manual_(app2); + wait_for_worker(3, 1); + std::list<app_t> buff = get_buffer_(); + std::list<app_t> apps = {app1, app2, app3}; + BOOST_REQUIRE(buff != apps); + apps = {app1, app3}; + BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); + // Add other apps + pkgmgr_install_manual_(app2); + // install the same app again + // it should never happen in real workflow + pkgmgr_install_manual_(app3); + app_t app4("app_4", "pkg_4", 5002, {}); + pkgmgr_install_manual_(app4); + wait_for_worker(3); + buff = get_buffer_(); + BOOST_REQUIRE(buff != apps); + apps = {app1, app3, app2, app4}; + BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); + // turn on the Internet - buffer should be processed + connman_callback_manual_(true); + wait_for_worker(0, 0, 4); + buff = get_buffer_(); + BOOST_CHECK(buff.empty()); } -BOOST_AUTO_TEST_CASE(logic_workflow_mixed_2) { - - BOOST_REQUIRE(setup() == NO_ERROR); - - wait_for_worker(); - - // turn off the network - connman_callback_manual_(false); - - // add applications: - app_t app1("app_1", "pkg_1", 5001, {}); - pkgmgr_install_manual_(app1); - - app_t app2("app_2", "pkg_2", 5002, {{"OCSP_CERT_ERROR"}}); - pkgmgr_install_manual_(app2); - - app_t app3("app_3", "pkg_3", 5003, {{"OCSP_CHECK_AGAIN"}}); - pkgmgr_install_manual_(app3); - - app_t app4("app_4", "pkg_4", 5004, {{"OCSP_APP_REVOKED"}}); // popup will succeed - pkgmgr_install_manual_(app4); - - app_t app5("app_5", "pkg_5", 100, {{"OCSP_APP_REVOKED"}}); // popup will fail - pkgmgr_install_manual_(app5); - - // turn on the Internet - buffer should be processed - connman_callback_manual_(true); - - wait_for_worker(5, 0, 5); - std::list<app_t> buff = get_buffer_(); +BOOST_AUTO_TEST_CASE(logic_workflow_mixed_2) +{ + BOOST_REQUIRE(setup() == NO_ERROR); + wait_for_worker(); + // turn off the network + connman_callback_manual_(false); + // add applications: + app_t app1("app_1", "pkg_1", 5001, {}); + pkgmgr_install_manual_(app1); + app_t app2("app_2", "pkg_2", 5002, {{"OCSP_CERT_ERROR"}}); + pkgmgr_install_manual_(app2); + app_t app3("app_3", "pkg_3", 5003, {{"OCSP_CHECK_AGAIN"}}); + pkgmgr_install_manual_(app3); + app_t app4("app_4", "pkg_4", 5004, {{"OCSP_APP_REVOKED"}}); // popup will succeed + pkgmgr_install_manual_(app4); + app_t app5("app_5", "pkg_5", 100, {{"OCSP_APP_REVOKED"}}); // popup will fail + pkgmgr_install_manual_(app5); + // turn on the Internet - buffer should be processed + connman_callback_manual_(true); + wait_for_worker(5, 0, 5); + std::list<app_t> buff = get_buffer_(); #if POPUP - std::list<app_t> apps = {app3, app5}; + std::list<app_t> apps = {app3, app5}; #else - std::list<app_t> apps = {app3}; // only if popup is disabled + std::list<app_t> apps = {app3}; // only if popup is disabled #endif - - BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); + BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); } -BOOST_AUTO_TEST_CASE(logic_workflow_mixed_3) { - - BOOST_REQUIRE(setup() == NO_ERROR); - - wait_for_worker(); - - // turn off the network - connman_callback_manual_(false); - - // add applications: - app_t app1("app_1", "pkg_1", 5001, {{"OCSP_CHECK_AGAIN"}}); - pkgmgr_install_manual_(app1); - - app_t app2("app_2", "pkg_2", 5002, {{"OCSP_CERT_ERROR"}}); - pkgmgr_install_manual_(app2); - - app_t app3("app_3", "pkg_3", 100, {{"OCSP_APP_REVOKED"}}); // popup will fail - pkgmgr_install_manual_(app3); - - app_t app4("app_4", "pkg_4", 5004, {{"OCSP_APP_REVOKED"}}); // popup will succeed - pkgmgr_install_manual_(app4); - - app_t app5("app_5", "pkg_5", 5005, {{"OCSP_CERT_ERROR"}}); - pkgmgr_install_manual_(app5); - - app_t app6("app_6", "pkg_6", 101, {{"OCSP_APP_REVOKED"}}); // popup will fail - pkgmgr_install_manual_(app6); - - wait_for_worker(6); - - std::list<app_t> buff = get_buffer_(); - std::list<app_t> apps = {app1, app2, app3, app4, app5, app6}; - - BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); - - connman_callback_manual_(true); - wait_for_worker(0, 0, 6); - buff = get_buffer_(); +BOOST_AUTO_TEST_CASE(logic_workflow_mixed_3) +{ + BOOST_REQUIRE(setup() == NO_ERROR); + wait_for_worker(); + // turn off the network + connman_callback_manual_(false); + // add applications: + app_t app1("app_1", "pkg_1", 5001, {{"OCSP_CHECK_AGAIN"}}); + pkgmgr_install_manual_(app1); + app_t app2("app_2", "pkg_2", 5002, {{"OCSP_CERT_ERROR"}}); + pkgmgr_install_manual_(app2); + app_t app3("app_3", "pkg_3", 100, {{"OCSP_APP_REVOKED"}}); // popup will fail + pkgmgr_install_manual_(app3); + app_t app4("app_4", "pkg_4", 5004, {{"OCSP_APP_REVOKED"}}); // popup will succeed + pkgmgr_install_manual_(app4); + app_t app5("app_5", "pkg_5", 5005, {{"OCSP_CERT_ERROR"}}); + pkgmgr_install_manual_(app5); + app_t app6("app_6", "pkg_6", 101, {{"OCSP_APP_REVOKED"}}); // popup will fail + pkgmgr_install_manual_(app6); + wait_for_worker(6); + std::list<app_t> buff = get_buffer_(); + std::list<app_t> apps = {app1, app2, app3, app4, app5, app6}; + BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); + connman_callback_manual_(true); + wait_for_worker(0, 0, 6); + buff = get_buffer_(); #if POPUP - apps = {app1, app3, app6}; + apps = {app1, app3, app6}; #else - apps = {app1}; // only if popup is disabled + apps = {app1}; // only if popup is disabled #endif - - BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); + BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); } -BOOST_AUTO_TEST_CASE(logic_workflow_mixed_4) { - - BOOST_REQUIRE(setup() == NO_ERROR); - - wait_for_worker(); - - // turn off the network - connman_callback_manual_(false); - - // add applications: - app_t app1("app_1", "pkg_1", 5001, {}); - pkgmgr_install_manual_(app1); - - wait_for_worker(1); - - std::list<app_t> apps = {app1}; - std::list<app_t> buff = get_buffer_(); - BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); - - app_t app2("app_2", "pkg_2", 5002, {{"OCSP_CERT_ERROR"}}); - pkgmgr_install_manual_(app2); - - wait_for_worker(1); - - apps = {app1, app2}; - buff = get_buffer_(); - BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); - - app_t app3("app_3", "pkg_3", 5003, {{"OCSP_CHECK_AGAIN"}}); - pkgmgr_install_manual_(app3); - - wait_for_worker(1); - - apps = {app1, app2, app3}; - buff = get_buffer_(); - BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); - - app_t app4("app_4", "pkg_4", 5004, {{"OCSP_APP_REVOKED"}}); // popup will succeed - pkgmgr_install_manual_(app4); - - wait_for_worker(1); - - apps = {app1, app2, app3, app4}; - buff = get_buffer_(); - BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); - - app_t app5("app_5", "pkg_5", 100, {{"OCSP_APP_REVOKED"}}); // popup will fail - pkgmgr_install_manual_(app5); - - wait_for_worker(1); - - apps = {app1, app2, app3, app4, app5}; - buff = get_buffer_(); - BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); +BOOST_AUTO_TEST_CASE(logic_workflow_mixed_4) +{ + BOOST_REQUIRE(setup() == NO_ERROR); + wait_for_worker(); + // turn off the network + connman_callback_manual_(false); + // add applications: + app_t app1("app_1", "pkg_1", 5001, {}); + pkgmgr_install_manual_(app1); + wait_for_worker(1); + std::list<app_t> apps = {app1}; + std::list<app_t> buff = get_buffer_(); + BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); + app_t app2("app_2", "pkg_2", 5002, {{"OCSP_CERT_ERROR"}}); + pkgmgr_install_manual_(app2); + wait_for_worker(1); + apps = {app1, app2}; + buff = get_buffer_(); + BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); + app_t app3("app_3", "pkg_3", 5003, {{"OCSP_CHECK_AGAIN"}}); + pkgmgr_install_manual_(app3); + wait_for_worker(1); + apps = {app1, app2, app3}; + buff = get_buffer_(); + BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); + app_t app4("app_4", "pkg_4", 5004, {{"OCSP_APP_REVOKED"}}); // popup will succeed + pkgmgr_install_manual_(app4); + wait_for_worker(1); + apps = {app1, app2, app3, app4}; + buff = get_buffer_(); + BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); + app_t app5("app_5", "pkg_5", 100, {{"OCSP_APP_REVOKED"}}); // popup will fail + pkgmgr_install_manual_(app5); + wait_for_worker(1); + apps = {app1, app2, app3, app4, app5}; + buff = get_buffer_(); + BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); } // OCSP_CHECK_AGAIN - apps should stay in buffer -BOOST_AUTO_TEST_CASE(logic_workflow_OCSP_CHECK_AGAIN) { - - BOOST_REQUIRE(setup() == NO_ERROR); - - wait_for_worker(); - - // turn off the network - connman_callback_manual_(false); - - // add applications: - app_t app1("app_1", "pkg_1", 5001, {{"OCSP_CHECK_AGAIN"}}); - pkgmgr_install_manual_(app1); - - app_t app2("app_2", "pkg_2", 5002, {{"OCSP_CHECK_AGAIN"}}); - pkgmgr_install_manual_(app2); - - app_t app3("app_3", "pkg_3", 100, {{"OCSP_CHECK_AGAIN"}}); - pkgmgr_install_manual_(app3); - - app_t app4("app_4", "pkg_4", 5004, {{"OCSP_CHECK_AGAIN"}}); - pkgmgr_install_manual_(app4); - - connman_callback_manual_(true); - - wait_for_worker(4, 0, 4); - - std::list<app_t> buff = get_buffer_(); - std::list<app_t> apps = {app1, app2, app3, app4}; - - BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); - - connman_callback_manual_(true); - - wait_for_worker(0, 0, 4); - - buff = get_buffer_(); - BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); +BOOST_AUTO_TEST_CASE(logic_workflow_OCSP_CHECK_AGAIN) +{ + BOOST_REQUIRE(setup() == NO_ERROR); + wait_for_worker(); + // turn off the network + connman_callback_manual_(false); + // add applications: + app_t app1("app_1", "pkg_1", 5001, {{"OCSP_CHECK_AGAIN"}}); + pkgmgr_install_manual_(app1); + app_t app2("app_2", "pkg_2", 5002, {{"OCSP_CHECK_AGAIN"}}); + pkgmgr_install_manual_(app2); + app_t app3("app_3", "pkg_3", 100, {{"OCSP_CHECK_AGAIN"}}); + pkgmgr_install_manual_(app3); + app_t app4("app_4", "pkg_4", 5004, {{"OCSP_CHECK_AGAIN"}}); + pkgmgr_install_manual_(app4); + connman_callback_manual_(true); + wait_for_worker(4, 0, 4); + std::list<app_t> buff = get_buffer_(); + std::list<app_t> apps = {app1, app2, app3, app4}; + BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); + connman_callback_manual_(true); + wait_for_worker(0, 0, 4); + buff = get_buffer_(); + BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); } // OCSP_CERT_ERROR - apps should be removed from buffer // OCSP_APP_OK should have the same effect -BOOST_AUTO_TEST_CASE(logic_workflow_OCSP_CERT_ERROR) { - - BOOST_REQUIRE(setup() == NO_ERROR); - - wait_for_worker(); - - // turn off the network - connman_callback_manual_(false); - - // add applications: - app_t app1("app_1", "pkg_1", 5001, {{"OCSP_CERT_ERROR"}}); - pkgmgr_install_manual_(app1); - - app_t app2("app_2", "pkg_2", 5002, {{"OCSP_CERT_ERROR"}}); - pkgmgr_install_manual_(app2); - - - app_t app3("app_3", "pkg_3", 100, {{"OCSP_CERT_ERROR"}}); - pkgmgr_install_manual_(app3); - - app_t app4("app_4", "pkg_4", 5004, {{"OCSP_CERT_ERROR"}}); - pkgmgr_install_manual_(app4); - - connman_callback_manual_(true); - wait_for_worker(4, 0, 4); - std::list<app_t> buff = get_buffer_(); - - BOOST_REQUIRE(buff.empty()); - - connman_callback_manual_(true); - - wait_for_worker(); - - buff = get_buffer_(); - BOOST_REQUIRE(buff.empty()); - - connman_callback_manual_(true); - - wait_for_worker(); - - buff = get_buffer_(); - BOOST_REQUIRE(buff.empty()); +BOOST_AUTO_TEST_CASE(logic_workflow_OCSP_CERT_ERROR) +{ + BOOST_REQUIRE(setup() == NO_ERROR); + wait_for_worker(); + // turn off the network + connman_callback_manual_(false); + // add applications: + app_t app1("app_1", "pkg_1", 5001, {{"OCSP_CERT_ERROR"}}); + pkgmgr_install_manual_(app1); + app_t app2("app_2", "pkg_2", 5002, {{"OCSP_CERT_ERROR"}}); + pkgmgr_install_manual_(app2); + app_t app3("app_3", "pkg_3", 100, {{"OCSP_CERT_ERROR"}}); + pkgmgr_install_manual_(app3); + app_t app4("app_4", "pkg_4", 5004, {{"OCSP_CERT_ERROR"}}); + pkgmgr_install_manual_(app4); + connman_callback_manual_(true); + wait_for_worker(4, 0, 4); + std::list<app_t> buff = get_buffer_(); + BOOST_REQUIRE(buff.empty()); + connman_callback_manual_(true); + wait_for_worker(); + buff = get_buffer_(); + BOOST_REQUIRE(buff.empty()); + connman_callback_manual_(true); + wait_for_worker(); + buff = get_buffer_(); + BOOST_REQUIRE(buff.empty()); } // OCSP_APP_REVOKED - popup OK - apps should be removed from buffer -BOOST_AUTO_TEST_CASE(logic_workflow_OCSP_APP_REVOKED) { - - BOOST_REQUIRE(setup() == NO_ERROR); - - wait_for_worker(); - - // turn off the network - connman_callback_manual_(false); - - // add applications: - app_t app1("app_1", "pkg_1", 5001, {{"OCSP_APP_REVOKED"}}); - pkgmgr_install_manual_(app1); - - app_t app2("app_2", "pkg_2", 5002, {{"OCSP_APP_REVOKED"}}); - pkgmgr_install_manual_(app2); - - app_t app3("app_3", "pkg_3", 5003, {{"OCSP_APP_REVOKED"}}); - pkgmgr_install_manual_(app3); - - app_t app4("app_4", "pkg_4", 5004, {{"OCSP_APP_REVOKED"}}); - pkgmgr_install_manual_(app4); - - connman_callback_manual_(true); - wait_for_worker(4, 0, 4); - - std::list<app_t> buff = get_buffer_(); - - BOOST_REQUIRE(buff.empty()); - - connman_callback_manual_(true); - - wait_for_worker(); - - buff = get_buffer_(); - BOOST_REQUIRE(buff.empty()); - - connman_callback_manual_(true); - - wait_for_worker(); - - buff = get_buffer_(); - BOOST_REQUIRE(buff.empty()); +BOOST_AUTO_TEST_CASE(logic_workflow_OCSP_APP_REVOKED) +{ + BOOST_REQUIRE(setup() == NO_ERROR); + wait_for_worker(); + // turn off the network + connman_callback_manual_(false); + // add applications: + app_t app1("app_1", "pkg_1", 5001, {{"OCSP_APP_REVOKED"}}); + pkgmgr_install_manual_(app1); + app_t app2("app_2", "pkg_2", 5002, {{"OCSP_APP_REVOKED"}}); + pkgmgr_install_manual_(app2); + app_t app3("app_3", "pkg_3", 5003, {{"OCSP_APP_REVOKED"}}); + pkgmgr_install_manual_(app3); + app_t app4("app_4", "pkg_4", 5004, {{"OCSP_APP_REVOKED"}}); + pkgmgr_install_manual_(app4); + connman_callback_manual_(true); + wait_for_worker(4, 0, 4); + std::list<app_t> buff = get_buffer_(); + BOOST_REQUIRE(buff.empty()); + connman_callback_manual_(true); + wait_for_worker(); + buff = get_buffer_(); + BOOST_REQUIRE(buff.empty()); + connman_callback_manual_(true); + wait_for_worker(); + buff = get_buffer_(); + BOOST_REQUIRE(buff.empty()); } // OCSP_APP_REVOKED - popup fail - apps should stay in buffer -BOOST_AUTO_TEST_CASE(logic_workflow_OCSP_APP_REVOKED_2) { - - BOOST_REQUIRE(setup() == NO_ERROR); - - wait_for_worker(); - - // turn off the network - connman_callback_manual_(false); - - // add applications: - app_t app1("app_1", "pkg_1", 1001, {{"OCSP_APP_REVOKED"}}); - pkgmgr_install_manual_(app1); - - app_t app2("app_2", "pkg_2", 1002, {{"OCSP_APP_REVOKED"}}); - pkgmgr_install_manual_(app2); - - app_t app3("app_3", "pkg_3", 1003, {{"OCSP_APP_REVOKED"}}); - pkgmgr_install_manual_(app3); - - app_t app4("app_4", "pkg_4", 1004, {{"OCSP_APP_REVOKED"}}); - pkgmgr_install_manual_(app4); - - connman_callback_manual_(true); - - wait_for_worker(4, 0, 4); - - std::list<app_t> buff = get_buffer_(); - std::list<app_t> apps = {app1, app2, app3, app4}; - - BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); - - connman_callback_manual_(true); - - wait_for_worker(0, 0, 4); - - buff = get_buffer_(); - BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); - - connman_callback_manual_(true); - - wait_for_worker(0, 0, 4); - - buff = get_buffer_(); - BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); +BOOST_AUTO_TEST_CASE(logic_workflow_OCSP_APP_REVOKED_2) +{ + BOOST_REQUIRE(setup() == NO_ERROR); + wait_for_worker(); + // turn off the network + connman_callback_manual_(false); + // add applications: + app_t app1("app_1", "pkg_1", 1001, {{"OCSP_APP_REVOKED"}}); + pkgmgr_install_manual_(app1); + app_t app2("app_2", "pkg_2", 1002, {{"OCSP_APP_REVOKED"}}); + pkgmgr_install_manual_(app2); + app_t app3("app_3", "pkg_3", 1003, {{"OCSP_APP_REVOKED"}}); + pkgmgr_install_manual_(app3); + app_t app4("app_4", "pkg_4", 1004, {{"OCSP_APP_REVOKED"}}); + pkgmgr_install_manual_(app4); + connman_callback_manual_(true); + wait_for_worker(4, 0, 4); + std::list<app_t> buff = get_buffer_(); + std::list<app_t> apps = {app1, app2, app3, app4}; + BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); + connman_callback_manual_(true); + wait_for_worker(0, 0, 4); + buff = get_buffer_(); + BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); + connman_callback_manual_(true); + wait_for_worker(0, 0, 4); + buff = get_buffer_(); + BOOST_CHECK_MESSAGE(buff == apps, log_apps(apps, buff)); } -BOOST_AUTO_TEST_CASE(logic_workflow_timer) { - - // Wait for setup. - BOOST_REQUIRE(setup() == NO_ERROR); - wait_for_worker(); - - // Job() will run. Install process. - timerStart(1); - wait_for_worker(5); - timerStop(); - - // If Timer is not work, wait_for_worker throw exception. - BOOST_REQUIRE(true); +BOOST_AUTO_TEST_CASE(logic_workflow_timer) +{ + // Wait for setup. + BOOST_REQUIRE(setup() == NO_ERROR); + wait_for_worker(); + // Job() will run. Install process. + timerStart(1); + wait_for_worker(5); + timerStop(); + // If Timer is not work, wait_for_worker throw exception. + BOOST_REQUIRE(true); } -BOOST_AUTO_TEST_CASE(logic_workflow_gio_timeout) { - - // Wait for setup. - BOOST_REQUIRE(setup() == NO_ERROR); - wait_for_worker(); - - // Run gmainloop. - run(3); - - BOOST_REQUIRE(is_running() == false); +BOOST_AUTO_TEST_CASE(logic_workflow_gio_timeout) +{ + // Wait for setup. + BOOST_REQUIRE(setup() == NO_ERROR); + wait_for_worker(); + // Run gmainloop. + run(3); + BOOST_REQUIRE(is_running() == false); } BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/test_queue.cpp b/tests/test_queue.cpp index dd1f51e..fbf7000 100644 --- a/tests/test_queue.cpp +++ b/tests/test_queue.cpp @@ -33,98 +33,77 @@ using namespace CCHECKER; BOOST_FIXTURE_TEST_SUITE(QUEUE_TEST, Queue) -BOOST_AUTO_TEST_CASE(Queue_operators) { - app_t app1("app_id1", "pkg_id1", 1, {}); - app_t app2("app_id2", "pkg_id2", 2, {}); - app_t app3("app_id@", "###", 3, {}); - - event_t ev1(app1, event_t::event_type_t::APP_INSTALL); - event_t ev2(app1, event_t::event_type_t::APP_UNINSTALL); - - BOOST_REQUIRE(ev1 == ev1); - BOOST_REQUIRE(ev1 != ev2); - BOOST_REQUIRE(ev2 != ev1); - BOOST_REQUIRE(ev2 == ev2); +BOOST_AUTO_TEST_CASE(Queue_operators) +{ + app_t app1("app_id1", "pkg_id1", 1, {}); + app_t app2("app_id2", "pkg_id2", 2, {}); + app_t app3("app_id@", "###", 3, {}); + event_t ev1(app1, event_t::event_type_t::APP_INSTALL); + event_t ev2(app1, event_t::event_type_t::APP_UNINSTALL); + BOOST_REQUIRE(ev1 == ev1); + BOOST_REQUIRE(ev1 != ev2); + BOOST_REQUIRE(ev2 != ev1); + BOOST_REQUIRE(ev2 == ev2); } -BOOST_AUTO_TEST_CASE(Queue) { - - app_t app1("app_id1", "pkg_id1", 1, {}); - app_t app2("app_id2", "pkg_id2", 2, {}); - app_t app3("app_id@", "###", 3, {}); - - event_t ev1(app1, event_t::event_type_t::APP_INSTALL); - event_t ev2(app1, event_t::event_type_t::APP_UNINSTALL); - - event_t ev3(app2, event_t::event_type_t::APP_INSTALL); - event_t ev4(app2, event_t::event_type_t::APP_UNINSTALL); - - event_t ev; - - BOOST_REQUIRE(empty() == true); - BOOST_REQUIRE(pop_event(ev) == false); - BOOST_REQUIRE(empty() == true); - push_event(ev1); - BOOST_REQUIRE(empty() == false); - - BOOST_REQUIRE(pop_event(ev) == true); - BOOST_REQUIRE(ev1 == ev); - - BOOST_REQUIRE(empty() == true); - - push_event(ev2); - push_event(ev3); - BOOST_REQUIRE(empty() == false); - - BOOST_REQUIRE(pop_event(ev) == true); - BOOST_REQUIRE(ev2 == ev); - - BOOST_REQUIRE(pop_event(ev) == true); - BOOST_REQUIRE(ev3 == ev); - - - BOOST_REQUIRE(empty() == true); - BOOST_REQUIRE(pop_event(ev) == false); - push_event(ev4); - BOOST_REQUIRE(empty() == false); - BOOST_REQUIRE(pop_event(ev) == true); - BOOST_REQUIRE(pop_event(ev) == false); - BOOST_REQUIRE(pop_event(ev) == false); - BOOST_REQUIRE(empty() == true); - - push_event(ev4); - - BOOST_REQUIRE(pop_event(ev) == true); - BOOST_REQUIRE(ev4 == ev); - - - BOOST_REQUIRE(pop_event(ev) == false); - BOOST_REQUIRE(empty() == true); +BOOST_AUTO_TEST_CASE(Queue) +{ + app_t app1("app_id1", "pkg_id1", 1, {}); + app_t app2("app_id2", "pkg_id2", 2, {}); + app_t app3("app_id@", "###", 3, {}); + event_t ev1(app1, event_t::event_type_t::APP_INSTALL); + event_t ev2(app1, event_t::event_type_t::APP_UNINSTALL); + event_t ev3(app2, event_t::event_type_t::APP_INSTALL); + event_t ev4(app2, event_t::event_type_t::APP_UNINSTALL); + event_t ev; + BOOST_REQUIRE(empty() == true); + BOOST_REQUIRE(pop_event(ev) == false); + BOOST_REQUIRE(empty() == true); + push_event(ev1); + BOOST_REQUIRE(empty() == false); + BOOST_REQUIRE(pop_event(ev) == true); + BOOST_REQUIRE(ev1 == ev); + BOOST_REQUIRE(empty() == true); + push_event(ev2); + push_event(ev3); + BOOST_REQUIRE(empty() == false); + BOOST_REQUIRE(pop_event(ev) == true); + BOOST_REQUIRE(ev2 == ev); + BOOST_REQUIRE(pop_event(ev) == true); + BOOST_REQUIRE(ev3 == ev); + BOOST_REQUIRE(empty() == true); + BOOST_REQUIRE(pop_event(ev) == false); + push_event(ev4); + BOOST_REQUIRE(empty() == false); + BOOST_REQUIRE(pop_event(ev) == true); + BOOST_REQUIRE(pop_event(ev) == false); + BOOST_REQUIRE(pop_event(ev) == false); + BOOST_REQUIRE(empty() == true); + push_event(ev4); + BOOST_REQUIRE(pop_event(ev) == true); + BOOST_REQUIRE(ev4 == ev); + BOOST_REQUIRE(pop_event(ev) == false); + BOOST_REQUIRE(empty() == true); } BOOST_AUTO_TEST_SUITE_END() BOOST_FIXTURE_TEST_SUITE(QUEUE_MULTI_THREAD_TEST, TestQueue) -BOOST_AUTO_TEST_CASE(TestQueue) { - - add_events_th (1); - BOOST_REQUIRE(pop_events() == true); - - add_events_th (2); - BOOST_REQUIRE(pop_events() == true); - - add_events_th (3); - BOOST_REQUIRE(pop_events() == true); - - add_events_th (5); - BOOST_REQUIRE(pop_events() == true); - - add_events_th (10); - BOOST_REQUIRE(pop_events() == true); - - add_events_th (20); - BOOST_REQUIRE(pop_events() == true); +BOOST_AUTO_TEST_CASE(TestQueue) +{ + add_events_th(1); + BOOST_REQUIRE(pop_events() == true); + add_events_th(2); + BOOST_REQUIRE(pop_events() == true); + add_events_th(3); + BOOST_REQUIRE(pop_events() == true); + add_events_th(5); + BOOST_REQUIRE(pop_events() == true); + add_events_th(10); + BOOST_REQUIRE(pop_events() == true); + add_events_th(20); + BOOST_REQUIRE(pop_events() == true); } BOOST_AUTO_TEST_SUITE_END() |