[Unit tests] for FileLocker class 87/89687/6
authorRadoslaw Bartosiak <r.bartosiak@samsung.com>
Mon, 19 Sep 2016 12:49:29 +0000 (14:49 +0200)
committerRadoslaw Bartosiak <r.bartosiak@samsung.com>
Mon, 17 Oct 2016 08:28:19 +0000 (10:28 +0200)
1) Add test directory for unit test using Boost.Test
2) Add tests for common/include/file-lock.h

Change-Id: Ic0151fa228045d53d6c202416e5f718f1f843b42
Signed-off-by: Radoslaw Bartosiak <r.bartosiak@samsung.com>
CMakeLists.txt
packaging/security-manager-tests.manifest [new file with mode: 0644]
packaging/security-manager.spec
src/CMakeLists.txt
src/dpl/core/include/dpl/colors.h
src/dpl/core/src/colors.cpp
test/CMakeLists.txt [new file with mode: 0644]
test/colour_log_formatter.cpp [new file with mode: 0644]
test/colour_log_formatter.h [new file with mode: 0644]
test/security-manager-tests.cpp [new file with mode: 0644]
test/test_file-lock.cpp [new file with mode: 0644]

index 82c73cabc03a48a5cc7522c1a0c40d4bbdc35a4a..7f1d523327e77316ff0a2fb29ceea2aec876dde5 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2011 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
+# Copyright (c) 2011 - 2016 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.
@@ -100,9 +100,25 @@ IF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
     ADD_DEFINITIONS("-DBUILD_TYPE_DEBUG")
 ENDIF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
 
+SET(INCLUDE_PATH ${PROJECT_SOURCE_DIR}/src/include)
+SET(COMMON_PATH  ${PROJECT_SOURCE_DIR}/src/common)
+SET(CLIENT_PATH  ${PROJECT_SOURCE_DIR}/src/client)
+SET(SERVER_PATH  ${PROJECT_SOURCE_DIR}/src/server)
+SET(DPL_PATH     ${PROJECT_SOURCE_DIR}/src/dpl)
+SET(CMD_PATH     ${PROJECT_SOURCE_DIR}/src/cmd)
+SET(NSS_PATH     ${PROJECT_SOURCE_DIR}/src/nss)
+
+SET(TARGET_SERVER "security-manager")
+SET(TARGET_CLIENT "security-manager-client")
+SET(TARGET_COMMON "security-manager-commons")
+SET(TARGET_CMD    "security-manager-cmd")
+SET(TARGET_CLEANUP "security-manager-cleanup")
+SET(TARGET_NSS     "security-manager-nss")
+
 ADD_SUBDIRECTORY(src)
 ADD_SUBDIRECTORY(pc)
 ADD_SUBDIRECTORY(systemd)
 ADD_SUBDIRECTORY(db)
 ADD_SUBDIRECTORY(policy)
 ADD_SUBDIRECTORY(migration)
+ADD_SUBDIRECTORY(test)
diff --git a/packaging/security-manager-tests.manifest b/packaging/security-manager-tests.manifest
new file mode 100644 (file)
index 0000000..017d22d
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+ <request>
+    <domain name="_"/>
+ </request>
+</manifest>
index 56535d7f2bc8ca460f869f066e7607532bdd2a2d..1a9d51d442628e104c4e82f7b24a823e90224c1f 100644 (file)
@@ -8,6 +8,7 @@ Source0:    %{name}-%{version}.tar.gz
 Source1:    security-manager.manifest
 Source3:    libsecurity-manager-client.manifest
 Source4:    libnss-security-manager.manifest
+Source5:    security-manager-tests.manifest
 Requires: security-manager-policy
 Requires: nether
 Requires(post): sqlite3
@@ -73,11 +74,20 @@ Requires(post): tizen-platform-config-tools
 %description policy
 Set of security rules that constitute security policy in the system
 
+%package -n security-manager-tests
+Summary:    Security manager unit test binaries
+Group:      Security/Development
+Requires:   boost-test
+
+%description -n security-manager-tests
+Internal test for security manager implementation.
+
 %prep
 %setup -q
 cp %{SOURCE1} .
 cp %{SOURCE3} .
 cp %{SOURCE4} .
+cp %{SOURCE5} .
 
 %build
 %if 0%{?sec_build_binary_debug_enable}
@@ -236,3 +246,8 @@ fi
 %{_datadir}/security-manager/policy
 %attr(755,root,root) %{_bindir}/security-manager-policy-reload
 %attr(755,root,root) %{_sysconfdir}/opt/upgrade/241.security-manager.policy-update.sh
+
+%files -n security-manager-tests
+%manifest %{name}.manifest
+%attr(755,root,root) %{_bindir}/security-manager-unit-tests
+
index f0fa9e0db377eceeabad245d60dcdb79e9123d52..7ad16fe05a2c7ce0e99e8e7e42408a5d77e18e60 100644 (file)
@@ -1,18 +1,3 @@
-SET(INCLUDE_PATH ${PROJECT_SOURCE_DIR}/src/include)
-SET(COMMON_PATH  ${PROJECT_SOURCE_DIR}/src/common)
-SET(CLIENT_PATH  ${PROJECT_SOURCE_DIR}/src/client)
-SET(SERVER_PATH  ${PROJECT_SOURCE_DIR}/src/server)
-SET(DPL_PATH     ${PROJECT_SOURCE_DIR}/src/dpl)
-SET(CMD_PATH     ${PROJECT_SOURCE_DIR}/src/cmd)
-SET(NSS_PATH     ${PROJECT_SOURCE_DIR}/src/nss)
-
-SET(TARGET_SERVER "security-manager")
-SET(TARGET_CLIENT "security-manager-client")
-SET(TARGET_COMMON "security-manager-commons")
-SET(TARGET_CMD    "security-manager-cmd")
-SET(TARGET_CLEANUP "security-manager-cleanup")
-SET(TARGET_NSS     "security-manager-nss")
-
 ADD_SUBDIRECTORY(include)
 ADD_SUBDIRECTORY(common)
 ADD_SUBDIRECTORY(client)
index d10f973be4c9d7571f1dc830f9fbb4c37409a7ff..371c539d3b2342dc81d39e7bfb371ba5ea5586dc 100644 (file)
@@ -45,6 +45,7 @@ extern const char* BOLD_GOLD_BEGIN;
 extern const char* BOLD_GOLD_END;
 extern const char* BOLD_WHITE_BEGIN;
 extern const char* BOLD_WHITE_END;
+extern const char* COLOR_END;
 } //namespace Text
 
 namespace Html {
index 3682668d9e1f46d65f021294fbbb15f3dd58919d..8541235a805146447411d8ae09d743235397aa74 100644 (file)
@@ -44,6 +44,7 @@ const char* BOLD_GOLD_BEGIN = "\033[0;33m";
 const char* BOLD_GOLD_END = "\033[m";
 const char* BOLD_WHITE_BEGIN = "\033[1;37m";
 const char* BOLD_WHITE_END = "\033[m";
+const char* COLOR_END = "\033[m";
 } //namespace Text
 
 namespace Html {
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..35fea60
--- /dev/null
@@ -0,0 +1,91 @@
+# Copyright (c) 2016 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        CMakeLists.txt
+# @author      Radoslaw Bartosiak <r.bartosiak@samsung.com>
+# @brief       Cmake for internal security manager tests
+#
+
+PKG_CHECK_MODULES(COMMON_DEP
+    REQUIRED
+    libtzplatform-config
+    )
+
+IF(DPL_WITH_DLOG)
+    PKG_CHECK_MODULES(DLOG_DEP REQUIRED dlog)
+ENDIF(DPL_WITH_DLOG)
+
+ADD_DEFINITIONS( "-DBOOST_TEST_DYN_LINK" )
+
+################################################################################
+
+SET(DPL_PATH     ${PROJECT_SOURCE_DIR}/src/dpl)
+SET(SM_TEST_SRC  ${PROJECT_SOURCE_DIR}/test)
+
+################################################################################
+
+SET(TARGET_SM_TESTS "security-manager-unit-tests")
+
+SET(SM_TESTS_SOURCES
+    ${SM_TEST_SRC}/colour_log_formatter.cpp
+    ${SM_TEST_SRC}/security-manager-tests.cpp
+    ${SM_TEST_SRC}/test_file-lock.cpp
+    ${DPL_PATH}/core/src/assert.cpp
+    ${DPL_PATH}/core/src/colors.cpp
+    ${DPL_PATH}/core/src/errno_string.cpp
+    ${DPL_PATH}/core/src/exception.cpp
+    ${DPL_PATH}/core/src/noncopyable.cpp
+    ${DPL_PATH}/log/src/abstract_log_provider.cpp
+    ${DPL_PATH}/log/src/log.cpp
+    ${DPL_PATH}/log/src/old_style_log_provider.cpp
+    ${PROJECT_SOURCE_DIR}/src/common/file-lock.cpp
+    ${PROJECT_SOURCE_DIR}/src/common/tzplatform-config.cpp
+)
+
+IF(DPL_WITH_DLOG)
+    SET(SM_TESTS_SOURCES
+        ${SM_TESTS_SOURCES}
+        ${DPL_PATH}/log/src/dlog_log_provider.cpp)
+ENDIF(DPL_WITH_DLOG)
+
+IF(DPL_WITH_SYSTEMD_JOURNAL)
+    SET(SM_TESTS_SOURCES
+        ${SM_TESTS_SOURCES}
+        ${DPL_PATH}/log/src/sd_journal_provider.cpp)
+ENDIF(DPL_WITH_SYSTEMD_JOURNAL)
+
+INCLUDE_DIRECTORIES(
+    ${COMMON_DEP_INCLUDE_DIRS}
+    ${DLOG_DEP_INCLUDE_DIRS}
+    ${SM_TEST_SRC}
+    ${PROJECT_SOURCE_DIR}/src/include
+    ${PROJECT_SOURCE_DIR}/src/client/include
+    ${PROJECT_SOURCE_DIR}/src/common/include
+    ${PROJECT_SOURCE_DIR}/src/server/main/include
+    ${PROJECT_SOURCE_DIR}/src/dpl/core/include
+    ${PROJECT_SOURCE_DIR}/src/dpl/log/include
+    ${PROJECT_SOURCE_DIR}/src/dpl/log/include/dpl/log
+    ${PROJECT_SOURCE_DIR}/src/dpl/log
+)
+
+ADD_EXECUTABLE(${TARGET_SM_TESTS} ${SM_TESTS_SOURCES})
+
+TARGET_LINK_LIBRARIES(${TARGET_SM_TESTS}
+    ${COMMON_DEP_LIBRARIES}
+    ${DLOG_DEP_LIBRARIES}
+    boost_unit_test_framework
+    -ldl
+)
+
+INSTALL(TARGETS ${TARGET_SM_TESTS} DESTINATION ${BIN_INSTALL_DIR})
\ No newline at end of file
diff --git a/test/colour_log_formatter.cpp b/test/colour_log_formatter.cpp
new file mode 100644 (file)
index 0000000..69ae6f0
--- /dev/null
@@ -0,0 +1,275 @@
+/*
+ *  (C) Copyright Gennadiy Rozental 2005-2008.
+ *  Distributed under the Boost Software License, Version 1.0.
+ *  (See accompanying file LICENSE_1_0.txt or copy at
+ *  http://www.boost.org/LICENSE_1_0.txt)
+ *
+ *  See http://www.boost.org/libs/test for the library home page.
+ */
+/*
+ * @file        colour_log_formatter.cpp
+ * @author      Zofia Abramowska (z.abramowska@samsung.com)
+ * @version
+ * @brief
+ */
+// Boost.Test
+#include <colour_log_formatter.h>
+#include <boost/test/unit_test_suite_impl.hpp>
+#include <boost/test/framework.hpp>
+#include <boost/test/utils/basic_cstring/io.hpp>
+#include <boost/test/utils/lazy_ostream.hpp>
+
+// Boost
+#include <boost/version.hpp>
+
+// STL
+#include <iostream>
+#include <string>
+
+#include <dpl/colors.h>
+
+// ************************************************************************** //
+// **************            colour_log_formatter            ************** //
+// ************************************************************************** //
+
+using namespace boost::unit_test;
+namespace SecurityManager {
+
+namespace {
+
+const_string
+test_phase_identifier()
+{
+    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());
+}
+
+std::string
+get_basename(const std::string &file_name)
+{
+    return basename(file_name.c_str());
+}
+
+} // local namespace
+
+//____________________________________________________________________________//
+
+void
+colour_log_formatter::log_start(
+    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";
+}
+
+//____________________________________________________________________________//
+
+void
+colour_log_formatter::log_finish(std::ostream &ostr)
+{
+    ostr.flush();
+}
+
+//____________________________________________________________________________//
+
+void
+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;
+}
+
+//____________________________________________________________________________//
+
+void
+colour_log_formatter::test_unit_start(
+    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;
+    }
+}
+
+//____________________________________________________________________________//
+
+void
+colour_log_formatter::test_unit_finish(
+    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 = SecurityManager::Colors::Text::GREEN_BEGIN;
+    std::string status = "OK";
+
+    if (m_isTestCaseFailed) {
+        color = SecurityManager::Colors::Text::RED_BEGIN;
+        status = "FAIL";
+    }
+
+    output << "\t" << "[   " << color << status << SecurityManager::Colors::Text::COLOR_END <<
+           "   ]";
+
+
+    output << ", " << SecurityManager::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 << SecurityManager::Colors::Text::COLOR_END << std::endl;
+    m_isTestCaseFailed = false;
+}
+
+//____________________________________________________________________________//
+
+void
+colour_log_formatter::test_unit_skipped(
+    std::ostream &output,
+    test_unit const &tu)
+{
+    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)
+{
+    boost::execution_exception::location const &loc = ex.where();
+    output << '\t' << SecurityManager::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 << SecurityManager::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)
+{
+    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' << SecurityManager::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' << SecurityManager::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 << SecurityManager::Colors::Text::COLOR_END;
+}
+
+//____________________________________________________________________________//
+
+void
+colour_log_formatter::log_entry_value(
+    std::ostream &output,
+    const_string value)
+{
+    output << value;
+}
+
+//____________________________________________________________________________//
+
+void
+colour_log_formatter::log_entry_value(
+    std::ostream &output,
+    lazy_ostream const &value)
+{
+    output << value;
+}
+
+//____________________________________________________________________________//
+
+void
+colour_log_formatter::log_entry_finish(
+    std::ostream &output)
+{
+    output << std::endl;
+}
+
+//____________________________________________________________________________//
+
+//____________________________________________________________________________//
+
+} // namespace SecurityManager
+
+//____________________________________________________________________________//
+
diff --git a/test/colour_log_formatter.h b/test/colour_log_formatter.h
new file mode 100644 (file)
index 0000000..f245713
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ *  (C) Copyright Gennadiy Rozental 2005-2008.
+ *  Distributed under the Boost Software License, Version 1.0.
+ *  (See accompanying file LICENSE_1_0.txt or copy at
+ *  http://www.boost.org/LICENSE_1_0.txt)
+ *
+ *  See http://www.boost.org/libs/test for the library home page.
+ */
+/*
+ * @file        colour_log_formatter.h
+ * @author      Zofia Abramowska (z.abramowska@samsung.com)
+ * @version
+ * @brief
+ */
+#pragma once
+#include <boost/test/unit_test_log_formatter.hpp>
+
+namespace SecurityManager {
+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 &);
+
+    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_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;
+};
+} // namespace SecurityManager
diff --git a/test/security-manager-tests.cpp b/test/security-manager-tests.cpp
new file mode 100644 (file)
index 0000000..2f160c5
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2016 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/security-manager-tests.cpp
+ * @author      Radoslaw Bartosiak <r.bartosiak@samsung.com>
+ * @version     1.0
+ * @brief       Security manager tests
+ */
+
+#include <iostream>
+#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 SecurityManager::colour_log_formatter);
+    }
+    ~TestConfig()
+    {
+    }
+};
+
+
+struct LogSetup {
+    LogSetup()
+    {
+        SecurityManager::Singleton<SecurityManager::Log::LogSystem>::Instance().SetTag("SECURITY_MANAGER_TESTS");
+    }
+    ~LogSetup() {}
+};
+
+BOOST_GLOBAL_FIXTURE(TestConfig)
+BOOST_GLOBAL_FIXTURE(LogSetup)
diff --git a/test/test_file-lock.cpp b/test/test_file-lock.cpp
new file mode 100644 (file)
index 0000000..bea5be0
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ *  Copyright (c) 2016 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_file-lock.cpp
+ * @author     Radoslaw Bartosiak (r.bartosiak@samsung.com)
+ * @version    1.0
+ */
+#define BOOST_TEST_MODULE SecurityManagerTest
+#include <boost/test/unit_test.hpp>
+#include <boost/test/results_reporter.hpp>
+
+#include <cstdio>
+#include <string>
+
+#include <dpl/errno_string.h>
+#include <dpl/log/log.h>
+#include <file-lock.h>
+
+using namespace SecurityManager;
+
+struct FileLockFixture
+{
+    FileLockFixture()
+    {
+        FILE *f;
+        f= fopen(existingLockFile.c_str(), "w");
+        if (f != NULL)
+            fclose(f);
+        else
+            LogError("Failed to open file " << existingLockFile << " : " << GetErrnoString());
+        remove(noExistingLockFile.c_str());
+
+    }
+
+    ~FileLockFixture()
+    {
+        if (remove(existingLockFile.c_str()))
+            LogWarning("Failed to remove file " << existingLockFile << " : " << GetErrnoString());
+        remove(noExistingLockFile.c_str());
+    }
+
+    const static std::string existingLockFile;
+    const static std::string noExistingLockFile;
+};
+
+const std::string FileLockFixture::existingLockFile = "/tmp/SecurityManagerUTFileLockExisting";
+const std::string FileLockFixture::noExistingLockFile = "/tmp/SecurityManagerUTFileLockNoExisting";
+
+
+BOOST_AUTO_TEST_SUITE(FILE_LOCK_TEST)
+
+BOOST_FIXTURE_TEST_CASE(T010_empty_file_name, FileLockFixture)
+{
+    BOOST_REQUIRE_THROW(FileLocker fl(""), FileLocker::Exception::LockFailed);
+}
+
+BOOST_FIXTURE_TEST_CASE(T020_existing_file_name, FileLockFixture)
+{
+    BOOST_REQUIRE_NO_THROW(FileLocker fl(FileLockFixture::existingLockFile));
+}
+
+BOOST_FIXTURE_TEST_CASE(T030_no_existing_file_name, FileLockFixture)
+{
+    BOOST_REQUIRE_NO_THROW(FileLocker fl(FileLockFixture::noExistingLockFile));
+}
+
+BOOST_FIXTURE_TEST_CASE(T040_new_lock_file_is_locked, FileLockFixture)
+{
+    FileLocker fl(std::string(FileLockFixture::existingLockFile), false);
+    BOOST_REQUIRE_MESSAGE(fl.Locked(), "New lock file is not locked");
+}
+
+BOOST_FIXTURE_TEST_CASE(T050_after_unlock_file_is_unlocked, FileLockFixture)
+{
+    FileLocker fl(FileLockFixture::noExistingLockFile, false);
+    fl.Unlock();
+    BOOST_REQUIRE_MESSAGE(not(fl.Locked()), "File is locked after Unlock()");
+}
+
+BOOST_FIXTURE_TEST_CASE(T060_after_lock_file_is_locked_again, FileLockFixture)
+{
+    FileLocker fl(FileLockFixture::existingLockFile, false);
+    fl.Unlock();
+    fl.Lock();
+    BOOST_REQUIRE_MESSAGE(fl.Locked(), "File is locked after Unlock()");
+}
+
+BOOST_AUTO_TEST_SUITE_END()