summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt2
-rw-r--r--tests/app_event_operators.cpp86
-rw-r--r--tests/app_event_operators.h41
-rw-r--r--tests/test_app.cpp159
-rw-r--r--tests/test_db.cpp98
-rw-r--r--tests/test_queue.cpp50
6 files changed, 383 insertions, 53 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index a1c88db..bff89b6 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -23,6 +23,8 @@ SET(CERT_CHECKER_TESTS_SOURCES
${CERT_CHECKER_TESTS_SRC_PATH}/main.cpp
${CERT_CHECKER_TESTS_SRC_PATH}/dbfixture.cpp
${CERT_CHECKER_TESTS_SRC_PATH}/colour_log_formatter.cpp
+ ${CERT_CHECKER_TESTS_SRC_PATH}/app_event_operators.cpp
+ ${CERT_CHECKER_TESTS_SRC_PATH}/test_app.cpp
${CERT_CHECKER_TESTS_SRC_PATH}/test_db.cpp
${CERT_CHECKER_TESTS_SRC_PATH}/test_queue.cpp
${CERT_CHECKER_TESTS_SRC_PATH}/queue_test_thread.cpp
diff --git a/tests/app_event_operators.cpp b/tests/app_event_operators.cpp
new file mode 100644
index 0000000..1d26d60
--- /dev/null
+++ b/tests/app_event_operators.cpp
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file app_test_class.cpp
+ * @author Janusz Kozerski (j.kozerski@samsung.com)
+ * @version 1.0
+ * @brief Implementation of app_test class (from app_t)
+ */
+
+#include <cchecker/log.h>
+#include <app_event_operators.h>
+
+//using namespace CCHECKER;
+
+namespace CCHECKER {
+
+void sort(app_t &app)
+{
+ for (auto &iter : app.signatures) {
+ iter.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;
+}
+
+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;
+}
+
+bool operator !=(const app_t &app1, const app_t &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.app != event2.app)
+ return false;
+
+ return true;
+}
+
+bool operator !=(const event_t &event1, const event_t &event2)
+{
+ return !(event1 == event2);
+}
+
+} // CHCHECKER
diff --git a/tests/app_event_operators.h b/tests/app_event_operators.h
new file mode 100644
index 0000000..3e96d28
--- /dev/null
+++ b/tests/app_event_operators.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file app_test_class.h
+ * @author Janusz Kozerski (j.kozerski@samsung.com)
+ * @version 1.0
+ * @brief Implementation of app_test class (from app_t)
+ */
+
+#include <cchecker/app.h>
+#include <cchecker/queue.h>
+
+#ifndef CCHECKER_APP_TEST_CLASS_H
+#define CCHECKER_APP_TEST_CLASS_H
+
+namespace CCHECKER {
+
+void sort(app_t &app);
+bool operator ==(const app_t &app1, const app_t &app2);
+bool operator !=(const app_t &app1, const app_t &app2);
+bool operator < (const app_t &app1, const app_t &app2);
+
+bool operator ==(const event_t &event1, const event_t &event2);
+bool operator !=(const event_t &event1, const event_t &event2);
+
+} // CCHECKER
+
+#endif //CCHECKER_APP_TEST_CLASS_H
diff --git a/tests/test_app.cpp b/tests/test_app.cpp
new file mode 100644
index 0000000..20bf905
--- /dev/null
+++ b/tests/test_app.cpp
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file test_app.cpp
+ * @author Janusz Kozerski (j.kozerski@samsung.com)
+ * @version 1.0
+ * @brief App structure tests
+ */
+
+#include <boost/test/unit_test.hpp>
+#include <string>
+
+#include <cchecker/log.h>
+#include <app_event_operators.h>
+
+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"}});
+ app_t app4("app_2", "pkg_1", 5002, {{"bbbb", "aaa"}});
+
+ 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.2", "cert 4.2.3", "cert_4.2.1"};
+ chain_t chain423 = {"cert 4.2.3", "cert_4.2.1", "cert 4.2.2"};
+ chain_t chain424 = {"cert_4.2.1", "cert 4.2.3", "cert 4.2.2"};
+ chain_t chain425 = {"cert 4.2.3", "cert 4.2.2", "cert_4.2.1"};
+ chain_t chain426 = {"cert 4.2.2", "cert_4.2.1", "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, {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});
+
+ sort(app1);
+ sort(app2);
+ sort(app3);
+ sort(app4);
+ sort(app5);
+ sort(app6);
+ sort(app7);
+ sort(app8);
+ sort(app9);
+ sort(app10);
+ sort(app11);
+ sort(app12);
+ sort(app13);
+ sort(app14);
+ sort(app15);
+ sort(app16);
+
+ 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_REQUIRE(app10 == app11);
+ BOOST_REQUIRE(app11 == app12);
+ BOOST_REQUIRE(app12 == app13);
+ BOOST_REQUIRE(app13 == app14);
+ BOOST_REQUIRE(app14 == app15);
+ BOOST_REQUIRE(app15 == app16);
+ BOOST_REQUIRE(app16 == app5);
+}
+
+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.1"};
+
+ chain_t chain421 = {"cert_4.2.1", "cert 4.2.2", "cert 4.2.3"};
+ chain_t chain422 = {"" "cert 4.2.3", "cert_4.2.1"};
+ chain_t chain423 = {"cert", "cert_4.2.1", "cert 4.2.2"};
+ chain_t chain424 = {"cert_4.2.1", " ", "cert 4.2.2"};
+ chain_t chain425 = {"cert 4.2.3", "cert 4.2.2"};
+ chain_t chain426 = {"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 apps[12] = {app5, app6, app7, app8, app9, app10, app11, app12, app13, app14, app15, app16};
+
+ sort(app1);
+ sort(app2);
+ sort(app3);
+ sort(app4);
+
+ for (int i=0; i<12; i++) {
+ sort(apps[i]);
+ }
+
+ BOOST_REQUIRE(app1 != app2);
+ BOOST_REQUIRE(app1 != app3);
+ BOOST_REQUIRE(app1 != app4);
+ BOOST_REQUIRE(app2 != app3);
+ BOOST_REQUIRE(app2 != app4);
+ BOOST_REQUIRE(app3 != app4);
+
+ for (int i=0; i<12; i++) {
+ for (int j=0; j<12; 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_db.cpp b/tests/test_db.cpp
index dd5a962..e9685a8 100644
--- a/tests/test_db.cpp
+++ b/tests/test_db.cpp
@@ -24,9 +24,9 @@
#include <boost/test/unit_test.hpp>
#include <string>
-#include <cchecker/app.h>
#include <cchecker/log.h>
#include <dbfixture.h>
+#include <app_event_operators.h>
BOOST_FIXTURE_TEST_SUITE(DB_TEST, DBFixture)
@@ -96,15 +96,27 @@ BOOST_AUTO_TEST_CASE(DB_url) {
BOOST_REQUIRE(url==url_org2);
}
-BOOST_AUTO_TEST_CASE(DB_app) {
+BOOST_AUTO_TEST_CASE(DB_app_positive) {
clear_database();
std::list<app_t> buffer;
app_t app1("app_1", "pkg_1", 5001, {});
- app_t app2("app_2", "pkg 2", 5002, {"cert_2"});
- app_t app2r("app_2_remove", "pkg 2", 5002, {"cert_2"});
- app_t app3("app 3", "pkg 3", 5003, {"cert_3.1", "cert 3.2"});
- app_t app4("app 4", "pkg 4", 5004, {"cert_4.1", "cert 4.2", "cert 4.3"});
+
+ 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);
@@ -118,29 +130,65 @@ BOOST_AUTO_TEST_CASE(DB_app) {
app2.verified = app_t::verified_t::NO;
app3.verified = app_t::verified_t::YES;
+ sort(app1);
+ sort(app2);
+ sort(app3);
+ sort(app4);
+ std::list<app_t> buffer_ok = {app1, app2, app3, app4};
+
+ get_app_list(buffer);
+
+ buffer.sort();
+ buffer_ok.sort();
+ BOOST_REQUIRE(buffer_ok == buffer);
+}
+
+BOOST_AUTO_TEST_CASE(DB_app_negative) {
+ clear_database();
+
+ 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;
+ sort(app1);
+ sort(app2);
+ sort(app3);
+ sort(app4);
std::list<app_t> buffer_ok = {app1, app2, app3, app4};
get_app_list(buffer);
- std::list<app_t>::iterator iter = buffer.begin();
- std::list<app_t>::iterator iter_ok = buffer_ok.begin();
- for (; iter!=buffer.end(); iter++) {
- bool is_ok = false;
- for (iter_ok = buffer_ok.begin(); iter_ok!=buffer_ok.end(); iter_ok++) {
- if (iter->app_id == iter_ok->app_id &&
- iter->pkg_id == iter_ok->pkg_id &&
- iter->uid == iter_ok->uid &&
- iter->certificates == iter_ok->certificates &&
- iter->verified == iter_ok->verified) {
- // check_id field is created by database and can be ignored
- LogDebug(iter->str() << " has been found");
- is_ok = true;
- buffer_ok.erase(iter_ok);
- break;
- }
- }
- BOOST_REQUIRE(is_ok == true);
- }
+ // list has to be sorted before comparison.
+ buffer.sort();
+ buffer_ok.sort();
+ BOOST_REQUIRE(buffer_ok != buffer);
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/test_queue.cpp b/tests/test_queue.cpp
index 2fe7f3e..384d6e4 100644
--- a/tests/test_queue.cpp
+++ b/tests/test_queue.cpp
@@ -24,16 +24,28 @@
#include <string>
#include <thread>
-#include <cchecker/app.h>
#include <cchecker/log.h>
-#include <cchecker/queue.h>
-
#include <queue_test_thread.h>
+#include <app_event_operators.h>
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) {
app_t app1("app_id1", "pkg_id1", 1, {});
@@ -55,12 +67,8 @@ BOOST_AUTO_TEST_CASE(Queue) {
BOOST_REQUIRE(empty() == false);
BOOST_REQUIRE(pop_event(ev) == true);
- BOOST_REQUIRE(ev1.app.app_id == ev.app.app_id);
- BOOST_REQUIRE(ev1.app.pkg_id == ev.app.pkg_id);
- BOOST_REQUIRE(ev1.app.uid == ev.app.uid);
- // Certs and verified flag aren't used in queue, but can be tested
- BOOST_REQUIRE(ev1.app.certificates == ev.app.certificates);
- BOOST_REQUIRE(ev1.app.verified == ev.app.verified);
+ BOOST_REQUIRE(ev1 == ev);
+
BOOST_REQUIRE(empty() == true);
push_event(ev2);
@@ -68,21 +76,11 @@ BOOST_AUTO_TEST_CASE(Queue) {
BOOST_REQUIRE(empty() == false);
BOOST_REQUIRE(pop_event(ev) == true);
- BOOST_REQUIRE(ev2.app.app_id == ev.app.app_id);
- BOOST_REQUIRE(ev2.app.pkg_id == ev.app.pkg_id);
- BOOST_REQUIRE(ev2.app.uid == ev.app.uid);
- // Certs and verified flag aren't used in queue, but can be tested
- BOOST_REQUIRE(ev2.app.certificates == ev.app.certificates);
- BOOST_REQUIRE(ev2.app.verified == ev.app.verified);
-
+ BOOST_REQUIRE(ev2 == ev);
BOOST_REQUIRE(pop_event(ev) == true);
- BOOST_REQUIRE(ev3.app.app_id == ev.app.app_id);
- BOOST_REQUIRE(ev3.app.pkg_id == ev.app.pkg_id);
- BOOST_REQUIRE(ev3.app.uid == ev.app.uid);
- // Certs and verified flag aren't used in queue, but can be tested
- BOOST_REQUIRE(ev3.app.certificates == ev.app.certificates);
- BOOST_REQUIRE(ev3.app.verified == ev.app.verified);
+ BOOST_REQUIRE(ev3 == ev);
+
BOOST_REQUIRE(empty() == true);
BOOST_REQUIRE(pop_event(ev) == false);
@@ -96,12 +94,8 @@ BOOST_AUTO_TEST_CASE(Queue) {
push_event(ev4);
BOOST_REQUIRE(pop_event(ev) == true);
- BOOST_REQUIRE(ev4.app.app_id == ev.app.app_id);
- BOOST_REQUIRE(ev4.app.pkg_id == ev.app.pkg_id);
- BOOST_REQUIRE(ev4.app.uid == ev.app.uid);
- // Certs and verified flag aren't used in queue, but can be tested
- BOOST_REQUIRE(ev4.app.certificates == ev.app.certificates);
- BOOST_REQUIRE(ev4.app.verified == ev.app.verified);
+ BOOST_REQUIRE(ev4 == ev);
+
BOOST_REQUIRE(pop_event(ev) == false);
BOOST_REQUIRE(empty() == true);