Fix logs in internal tests
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 28 Jan 2015 13:56:18 +0000 (14:56 +0100)
committerMaciej J. Karpiuk <m.karpiuk2@samsung.com>
Tue, 17 Feb 2015 11:09:37 +0000 (12:09 +0100)
[Issue#] N/A
[Feature/Bug] N/A
[Problem] No logs from internal tests
[Cause] LogSystem tag was not set
[Solution] Internal tests refactored and cleaned up. Proper tag set.

[Verification] Run internal tests and see if logs are visible

Change-Id: Ibb8517bad710d06a62ba9ba7fbc7b9b8ed7b7c21

tests/CMakeLists.txt
tests/main.cpp [new file with mode: 0644]
tests/test-key-provider.cpp
tests/test_common.h
tests/test_db_crypto.cpp
tests/test_descriptor-set.cpp
tests/test_safe-buffer.cpp

index 21478fa..9725e5a 100644 (file)
@@ -1,9 +1,3 @@
-PKG_CHECK_MODULES(KEY_MANAGER_TEST_DEP
-    dlog
-    openssl
-    REQUIRED
-    )
-
 ADD_DEFINITIONS( "-DBOOST_TEST_DYN_LINK" )
 
 SET(KEY_MANAGER_SRC_PATH ${PROJECT_SOURCE_DIR}/src)
@@ -26,6 +20,7 @@ INCLUDE_DIRECTORIES(
     )
 
 SET(TEST_MERGED_SOURCES
+    ${KEY_MANAGER_TEST_MERGED_SRC}/main.cpp
     ${KEY_MANAGER_TEST_MERGED_SRC}/test_common.cpp
     ${KEY_MANAGER_TEST_MERGED_SRC}/DBFixture.cpp
     ${KEY_MANAGER_TEST_MERGED_SRC}/colour_log_formatter.cpp
@@ -42,9 +37,6 @@ SET(TEST_MERGED_SOURCES
 ADD_EXECUTABLE(${TARGET_TEST_MERGED} ${TEST_MERGED_SOURCES})
 
 TARGET_LINK_LIBRARIES(${TARGET_TEST_MERGED}
-    ${KEY_MANAGER_CLIENT_DEP_LIBRARIES}
-    ${KEY_MANAGER_DEP_LIBRARIES}
-    ${TARGET_KEY_MANAGER_CLIENT}
     ${TARGET_KEY_MANAGER_COMMON}
     boost_unit_test_framework
     )
diff --git a/tests/main.cpp b/tests/main.cpp
new file mode 100644 (file)
index 0000000..737ae12
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ *  Copyright (c) 2000 - 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       main.cpp
+ * @author     Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
+ * @version    1.0
+ */
+
+#include <key-provider.h>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/unit_test_log.hpp>
+#include <boost/test/results_reporter.hpp>
+#include <colour_log_formatter.h>
+#include <dpl/log/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 CKM::colour_log_formatter);
+    }
+    ~TestConfig(){
+    }
+};
+
+bool isLibInitialized = false;
+
+struct KeyProviderLib {
+    KeyProviderLib() {
+        Try {
+            CKM::KeyProvider::initializeLibrary();
+            isLibInitialized = true;
+        }
+        Catch (CKM::Exception) {
+            std::cout << "Library initialization failed!" << std::endl;
+        }
+    }
+    ~KeyProviderLib() {
+        Try { CKM::KeyProvider::closeLibrary(); }
+        Catch (CKM::Exception) {
+            std::cout << "Library deinitialization failed!" << std::endl;
+        }
+    }
+};
+
+struct LogSetup {
+    LogSetup() {
+        CKM::Singleton<CKM::Log::LogSystem>::Instance().SetTag("CKM_INTERNAL_TESTS");
+    }
+    ~LogSetup() {}
+};
+
+BOOST_GLOBAL_FIXTURE(KeyProviderLib)
+BOOST_GLOBAL_FIXTURE(TestConfig)
+BOOST_GLOBAL_FIXTURE(LogSetup)
+
index f841ae3..433e8ec 100644 (file)
@@ -13,28 +13,7 @@ const std::string USERNAME_LONG = "SOFTWARE_CENTER_SYSTEM_SW_LAB_SECURITY_PART";
 const std::string SMACK_LABEL_1 = "SAMPLE_SMACK_LABEL_1";
 const std::string SMACK_LABEL_2 = "SAMPLE_SMACK_LABEL_2";
 
-static bool isLibInitialized = false;
-
-struct KeyProviderLib {
-    KeyProviderLib() {
-        Try {
-            CKM::KeyProvider::initializeLibrary();
-            isLibInitialized = true;
-        }
-        Catch (CKM::Exception) {
-            std::cout << "Library initialization failed!" << std::endl;
-        }
-    }
-    ~KeyProviderLib() {
-        Try { CKM::KeyProvider::closeLibrary(); }
-        Catch (CKM::Exception) {
-            std::cout << "Library deinitialization failed!" << std::endl;
-        }
-    }
-};
-
-BOOST_GLOBAL_FIXTURE(TestConfig)
-BOOST_GLOBAL_FIXTURE(KeyProviderLib)
+extern bool isLibInitialized;
 
 BOOST_AUTO_TEST_SUITE(KEY_PROVIDER_TEST)
 BOOST_AUTO_TEST_CASE(KeyDomainKEK){
index 5a6279c..04878f3 100644 (file)
@@ -1,20 +1,6 @@
 #pragma once
 #include <string>
 #include <ckm/ckm-type.h>
-#include <boost/test/unit_test_log.hpp>
-#include <boost/test/results_reporter.hpp>
-#include <colour_log_formatter.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 CKM::colour_log_formatter);
-    }
-    ~TestConfig(){
-    }
-private:
-};
 
 // mirrors the API-defined value
 #ifndef AES_GCM_TAG_SIZE
index 1256720..6539876 100644 (file)
@@ -1,5 +1,4 @@
 #include <boost/test/unit_test.hpp>
-#include <boost/test/results_reporter.hpp>
 #include <unistd.h>
 #include <db-crypto.h>
 #include <iostream>
@@ -9,8 +8,6 @@
 #include <test_common.h>
 #include <DBFixture.h>
 
-BOOST_GLOBAL_FIXTURE(TestConfig)
-
 using namespace CKM;
 
 namespace
@@ -22,8 +19,7 @@ const unsigned int c_test_retries = 1000;
 const unsigned int c_num_names = 500;
 const unsigned int c_num_names_add_test = 5000;
 const unsigned int c_names_per_label = 15;
-}
-
+} // namespace anonymous
 
 BOOST_FIXTURE_TEST_SUITE(DBCRYPTO_TEST, DBFixture)
 BOOST_AUTO_TEST_CASE(DBtestSimple) {
index a58a817..1cabe37 100644 (file)
@@ -34,8 +34,6 @@
 
 #include <descriptor-set.h>
 
-BOOST_GLOBAL_FIXTURE(TestConfig)
-
 using namespace CKM;
 
 namespace {
index 691f02c..b56e824 100644 (file)
@@ -5,8 +5,6 @@
 
 #include <ckm/ckm-raw-buffer.h>
 
-BOOST_GLOBAL_FIXTURE(TestConfig)
-
 using namespace CKM;
 
 namespace {