SECIOTSRK-596 Test coverage increased.
authorLomtev Dmytro <d.lomtev@samsung.com>
Thu, 5 Oct 2017 07:57:04 +0000 (10:57 +0300)
committerLomtev Dmytro <d.lomtev@samsung.com>
Thu, 5 Oct 2017 07:57:04 +0000 (10:57 +0300)
16 files changed:
device_core/mock/sd-daemon-mock.h [new file with mode: 0644]
device_core/mock/sd-daemon-stub.cpp
device_core/mock/sd-daemon.h
device_core/nmdaemon/reporthandlermq.h
device_core/nmdaemon/thread_base.cpp
device_core/nmdaemon/thread_base.h
device_core/utest/test_all.cpp
device_core/utest/test_commandhandler.cpp
device_core/utest/test_dpm_api_mapper.cpp
device_core/utest/test_hub_policy_resource.cpp
device_core/utest/test_iot_common_enforce.cpp [new file with mode: 0644]
device_core/utest/test_iot_dev_manager.cpp
device_core/utest/test_iot_policy_enforce.cpp
device_core/utest/test_policyhandlerfactory.cpp [new file with mode: 0644]
device_core/utest/test_reporthandlerfactory.cpp [new file with mode: 0644]
device_core/utest/test_systemdwrapper.cpp [new file with mode: 0644]

diff --git a/device_core/mock/sd-daemon-mock.h b/device_core/mock/sd-daemon-mock.h
new file mode 100644 (file)
index 0000000..0ec5563
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef SDDAEMONMOCK_H
+#define SDDAEMONMOCK_H
+
+#include <gmock/gmock.h>
+#include "sd-daemon.h"
+
+class SDDaemonMock: public SDDaemonIf
+{
+public:
+    SDDaemonMock()
+    {
+        sd_daemon_set_impl(this);
+    }
+
+    ~SDDaemonMock()
+    {
+        sd_daemon_unset_impl();
+    }
+
+    MOCK_METHOD2(sd_notify, int(int unset_environment, const char *state));
+};
+
+#endif // SDDAEMONMOCK_H
index f2fc7e2..d6f413c 100644 (file)
@@ -1,7 +1,23 @@
 
 #include "mock/sd-daemon.h"
 
-int sd_notify(int /*unset_environment*/, const char* /*state*/)
+static SDDaemonIf* g_sd_daemon_impl = nullptr;
+
+void sd_daemon_set_impl(SDDaemonIf* impl)
+{
+    g_sd_daemon_impl = impl;
+}
+
+void sd_daemon_unset_impl()
 {
+    g_sd_daemon_impl = nullptr;
+}
+
+int sd_notify(int unset_environment, const char* state)
+{
+    if (nullptr != g_sd_daemon_impl) {
+        return g_sd_daemon_impl->sd_notify(unset_environment, state);
+    }
+
     return 0;
 }
index eabbdff..5492e53 100644 (file)
@@ -1,6 +1,19 @@
 #ifndef SDDAEMON_H
 #define SDDAEMON_H
 
+class SDDaemonIf
+{
+public:
+    virtual ~SDDaemonIf()
+    {
+    }
+
+    virtual int sd_notify(int unset_environment, const char *state) = 0;
+};
+
+void sd_daemon_set_impl(SDDaemonIf* impl);
+void sd_daemon_unset_impl();
+
 extern "C" int sd_notify(int unset_environment, const char *state);
 
 #endif // SDDAEMON_H
index 93f490f..a43f3b1 100644 (file)
@@ -13,8 +13,6 @@ public:
 
 private:
 
-    void findResource();
-
     OC::OCResource::Ptr resource;
     NetworkManager::IoTivity* iotivity;
     std::string server_id;
index bb6acb0..a0d9a14 100644 (file)
@@ -32,10 +32,6 @@ void ThreadBase::stop()
     m_running = false;\r
 }\r
 \r
-void ThreadBase::routine()\r
-{\r
-}\r
-\r
 void ThreadBase::join()\r
 {\r
     if (m_thread.joinable()) {\r
index ea1f8fa..b4dd0fc 100644 (file)
@@ -31,7 +31,7 @@ public:
 \r
     virtual void stop();\r
 \r
-    virtual void routine();\r
+    virtual void routine() = 0;\r
 \r
     void join();\r
 \r
index a49c3ae..8de4a9a 100644 (file)
@@ -24,6 +24,62 @@ static std::string getNextArg(int &pos, int argc, char** argv)
     return argv[pos];
 }
 
+class TestEventListener : public ::testing::EmptyTestEventListener
+{
+    // Fired before the test case starts and before SetUpTestCase() is invoked.
+    virtual void OnTestCaseStart(const ::testing::TestCase& test_case) override
+    {
+        firstTestInTestCase = true;
+        testCaseHadFailure = false;
+    }
+
+    // Fired before each individual test starts: before the test fixture is constructed
+    // and SetUp() is invoked.
+    virtual void OnTestStart(const ::testing::TestInfo& info) override
+    {
+        if (firstTestInTestCase) {
+            size_t numFailures = numFatalFailures();
+
+            if (numFailures > previousNumFatalFailures) {
+                testCaseHadFailure = true;
+                previousNumFatalFailures = numFailures;
+            }
+
+            firstTestInTestCase = false;
+        }
+
+        if (testCaseHadFailure) {
+            // this will avoid running the test fixture's SetUp() and
+            // TearDown() and TEST()/TEST_F(), but the test fixtures
+            // constructor is still invoked (that's unavoidable)
+            FAIL() << "The test case's SetUpTestCase() or executable had a fatal failure";
+        }
+    }
+
+    // gets the number of fatal failures in the UnitTest's ad_hoc_test_result,
+    // which is the number of fatal failures other than those inside of test
+    // cases; fatal failures in SetUpTestCase() also count in this, but those
+    // in SetUp(), TearDown(), and TEST()/TEST_F() do not.
+    size_t numFatalFailures()
+    {
+        const auto& result = ::testing::UnitTest::GetInstance()->ad_hoc_test_result();
+        const int numParts = result.total_part_count();
+        size_t failures = 0;
+
+        for (int i=0; i < numParts; ++i) {
+            if (result.GetTestPartResult(i).fatally_failed()) {
+                ++failures;
+            }
+        }
+
+        return failures;
+    }
+
+    bool   firstTestInTestCase{true};
+    bool   testCaseHadFailure{false};
+    size_t previousNumFatalFailures{0};
+};
+
 }
 
 int main(int argc, char** argv)
@@ -45,7 +101,12 @@ int main(int argc, char** argv)
                 setINIFilePath("");
             }
         }
+
         ::testing::InitGoogleTest(&argc, argv);
+        // Gets hold of the event listener list
+        ::testing::TestEventListeners& listeners = ::testing::UnitTest::GetInstance()->listeners();
+        // Adds a listener to the end.  Google Test takes the ownership.
+        listeners.Append(new TestEventListener);
         return RUN_ALL_TESTS();
     } catch (std::exception& e) {
         std::cout << "Exception: " << e.what() << std::endl;
index 8bbc644..48ccfbf 100644 (file)
@@ -54,10 +54,11 @@ public:
 
 }
 
-class MainThreadMock : public ThreadBase
+class ThreadBaseMock : public ThreadBase
 {
 public:
     MOCK_METHOD0(stop, void());
+    MOCK_METHOD0(routine, void());
 };
 
 /**
@@ -65,7 +66,7 @@ public:
  */
 TEST(Test_commandhandler, test_unOwnTask_standard)
 {
-    MainThreadMock main_thread;
+    ThreadBaseMock main_thread;
     IoTivityMock iot;
     MqClientMock mqclient;
     OC::OCRepresentation unreg_repr;
@@ -114,7 +115,7 @@ TEST(Test_commandhandler, test_uninstallTask)
         std::shared_ptr<HubResource> hub  = std::make_shared<HubResource>(&iot, proxy.get(), std::string{""});
         std::shared_ptr<ReportHandler> rh = std::make_shared<ReportHandlerStub>();
         std::shared_ptr<PolicyHandler> ph = std::make_shared<PolicyHandlerStub>();
-        ThreadBase mt;
+        ThreadBaseMock mt;
 
         CommandHandler handler(&iot, hub, rh, ph, proxy, WorkingMode::Standard, &mt);
 
@@ -139,7 +140,7 @@ TEST(Test_commandhandler, test_uninstall_wrong_params)
         std::shared_ptr<HubResource> hub  = std::make_shared<HubResource>(&iot, proxy.get(), std::string{""});
         std::shared_ptr<ReportHandler> rh = std::make_shared<ReportHandlerStub>();
         std::shared_ptr<PolicyHandler> ph = std::make_shared<PolicyHandlerStub>();
-        ThreadBase mt;
+        ThreadBaseMock mt;
 
         CommandHandler handler(&iot, hub, rh, ph, proxy, WorkingMode::Standard, &mt);
 
@@ -170,7 +171,7 @@ TEST(Test_commandhandler, test_uninstallTask_dpm_failure)
         std::shared_ptr<HubResource> hub  = std::make_shared<HubResource>(&iot, proxy.get(), std::string{""});
         std::shared_ptr<ReportHandler> rh = std::make_shared<ReportHandlerStub>();
         std::shared_ptr<PolicyHandler> ph = std::make_shared<PolicyHandlerStub>();
-        ThreadBase mt;
+        ThreadBaseMock mt;
 
         CommandHandler handler(&iot, hub, rh, ph, proxy, WorkingMode::Standard, &mt);
 
@@ -193,7 +194,7 @@ TEST(Test_commandhandler, test_unsupported_command)
         std::shared_ptr<HubResource> hub  = std::make_shared<HubResource>(&iot, proxy.get(), std::string{""});
         std::shared_ptr<ReportHandler> rh = std::make_shared<ReportHandlerStub>();
         std::shared_ptr<PolicyHandler> ph = std::make_shared<PolicyHandlerStub>();
-        ThreadBase mt;
+        ThreadBaseMock mt;
 
         CommandHandler handler(&iot, hub, rh, ph, proxy, WorkingMode::Standard, &mt);
 
index 4ed9091..c39d5cb 100644 (file)
@@ -29,7 +29,6 @@ TEST(Test_DPM_API, MapperTesting)
     ASSERT_EQ(mapper.apply(std::string("eoritueioteuior"), 1, v), dpm_api::NAME_NOT_FOUND);
     ASSERT_EQ(mapper.apply(std::string("iptables"), 1, v), dpm_api::SUCCESS);
     ASSERT_EQ(mapper.apply(std::string("iptables"), 0, v), dpm_api::SUCCESS);
-    ASSERT_EQ(mapper.apply(std::string("device_power_off"), 0, v), dpm_api::UNKNOWN);
 }
 
 dpm_api::error_code convert_err(int err);
index b3a12b3..d63f048 100644 (file)
@@ -1,4 +1,7 @@
 #include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <fstream>
+#include <boost/archive/text_oarchive.hpp>
 #include "hub_policy_resource.h"
 
 using ::testing::Eq;
@@ -80,12 +83,11 @@ TEST(Test_PolicyResource, postHandler)
 }
 
 /**
- * @brief TEST for ReportResource::postHandler method normal call
+ * @brief TEST for ReportResource::getHandler method normal call
  * 1. Create objects and mocks
  * 2. Set expectations
  * 3. Call method
  * 4. Check the result
- * 5. Check that ReportHandlerMock::pass called
  */
 TEST(Test_PolicyResource, getHandler)
 {
@@ -148,3 +150,111 @@ TEST(Test_PolicyResource, getHandler)
     executor.join();
 }
 
+class Test_PolicyResourceFix: public ::testing::Test
+{
+public:
+    static const std::string OWNED_DEVICE_UUID;
+    static const std::string UNOWNED_DEVICE_UUID;
+    static const std::string DEVICE_NAME;
+    static const std::string DEVICE_MODEL;
+    static const std::string DEVICE_TYPE;
+    static const std::string test_hub_devices_file;
+
+    static void SetUpTestCase()
+    {
+        std::ofstream file{test_hub_devices_file};
+
+        do {
+            boost::archive::text_oarchive oa{file};
+            const int DEVICES_COUNT = 1;
+            oa << DEVICES_COUNT
+               << OWNED_DEVICE_UUID
+               << DEVICE_NAME
+               << DEVICE_MODEL
+               << DEVICE_TYPE;
+        } while (0);
+
+        file.close();
+    }
+
+    static void TearDownTestCase()
+    {
+        ::remove(test_hub_devices_file.c_str());
+    }
+};
+
+const std::string Test_PolicyResourceFix::OWNED_DEVICE_UUID   = "11111111-1111-1111-1111-111111111111";
+const std::string Test_PolicyResourceFix::UNOWNED_DEVICE_UUID = "22222222-2222-2222-2222-222222222222";
+const std::string Test_PolicyResourceFix::DEVICE_NAME  = "device#1";
+const std::string Test_PolicyResourceFix::DEVICE_MODEL = "model#1";
+const std::string Test_PolicyResourceFix::DEVICE_TYPE  = "type#1";
+const std::string Test_PolicyResourceFix::test_hub_devices_file = "/tmp/test_policy_resource_hub_devices_file.dat";
+
+/**
+ * @brief TEST for ReportResource::observeHandler method normal call
+ * 1. Create objects and mocks
+ * 2. Set expectations
+ * 3. Call method
+ * 4. Check the result
+ */
+TEST_F(Test_PolicyResourceFix, observeHandler)
+{
+    const std::string THIS_DEVICE_ID{"this-device-id"};
+    const std::string PRIMITIVE_DEVICE_ID{"primitive-device-id"};
+    const std::string AGENT_ID{"microsoft agent"};
+    const std::string OBSERVER_ADDRESS{"coap://192.168.1.2"};
+    OC::OCRepresentation not_used;
+    const OCObservationId OBS_ID = 5;
+    uint16_t OBS_PORT = 8081;
+
+    OC::ObservationInfo obs_info_register = {
+        ObserveAction::ObserveRegister,
+        OBS_ID,
+        CT_ADAPTER_IP,
+        OBSERVER_ADDRESS,
+        OBS_PORT
+    };
+
+    OC::ObservationInfo obs_info_unregister = {
+        ObserveAction::ObserveUnregister,
+        OBS_ID,
+        CT_ADAPTER_IP,
+        OBSERVER_ADDRESS,
+        OBS_PORT
+    };
+
+    OC::QueryParamsMap wrong_params{};
+    OC::QueryParamsMap owned_params{{"did", OWNED_DEVICE_UUID}};
+    OC::QueryParamsMap unowned_params{{"did", UNOWNED_DEVICE_UUID}};
+
+    PolicyHandlerMock policyHandler;
+    ProxyThread executor;
+    HubResource hub(NetworkManager::IoTivity::getInstance(), &executor, test_hub_devices_file);
+    ::testing::InSequence dummy;
+
+    EXPECT_CALL(policyHandler, setObserver(_)).Times(1);
+    EXPECT_CALL(policyHandler, clearObserver()).Times(1);
+    try {
+        // Test PolicyResource object creation
+        PolicyResource policyResource(
+                    &policyHandler,
+                    THIS_DEVICE_ID,
+                    std::shared_ptr<HubResource>(&hub, [](HubResource*){}),
+                    std::shared_ptr<ProxyThread>(&executor, [](ProxyThread*){}));
+
+        OC::OCRepresentation response;
+        // Call with query parameters that does not contain "did" property results in BAD_REQ error
+        EXPECT_EQ(OC_EH_BAD_REQ, policyResource.observHandler(not_used, wrong_params, obs_info_register));
+
+        // Call observe register with good query parameters
+        EXPECT_EQ(OC_EH_OK, policyResource.observHandler(not_used, owned_params, obs_info_register));
+        // Call observe unregister with good query parameters
+        EXPECT_EQ(OC_EH_OK, policyResource.observHandler(not_used, owned_params, obs_info_unregister));
+        // Duplicated unregister calls doesn't cause errors
+        EXPECT_EQ(OC_EH_OK, policyResource.observHandler(not_used, owned_params, obs_info_unregister));
+        // Call observe register with good query parameters but for unowned device
+        EXPECT_EQ(OC_EH_RESOURCE_NOT_FOUND, policyResource.observHandler(not_used, unowned_params, obs_info_register));
+    } catch (std::exception& e) {
+        FAIL() << "Exception: " << e.what();
+    }
+}
diff --git a/device_core/utest/test_iot_common_enforce.cpp b/device_core/utest/test_iot_common_enforce.cpp
new file mode 100644 (file)
index 0000000..1a960a7
--- /dev/null
@@ -0,0 +1,39 @@
+#include "device-policy-manager-mock.h"
+#include "iot_common_enforce.h"
+#include <jsoncpp/json/reader.h>
+
+using namespace iot::core;
+using ::testing::_;
+using ::testing::Return;
+
+namespace
+{
+const std::string policy = R"-([{"name":"sound","state":1,"items":[]},
+                           {"name":"camera","state":0,"items":[]},
+                           {"name":"iptables","state":1,"items":["127.0.0.0/24|UDP|10-1024","1.1.1.1|TCP|80,443","8.8.8.8"]}])-";
+}
+
+TEST(test_CommonPolicyEnforce, test_ParseGroup)
+{
+    DPMMock dpm;
+    dpm_set_custom_implementation(&dpm);
+
+    CommonPolicyEnforce comm_pe(PolicyEnforce::GetInstance());
+
+    EXPECT_CALL(dpm, dpm_manager_create()).WillOnce(Return(&dpm));
+
+    EXPECT_CALL(dpm, dpm_restriction_set_sound_state(1)).WillOnce(Return(0));
+
+    EXPECT_CALL(dpm, dpm_restriction_set_camera_state(0)).WillOnce(Return(0));
+    EXPECT_CALL(dpm, dpm_manager_destroy()).Times(1);
+    EXPECT_CALL(dpm, dpm_firewall_flush_deny_rules()).WillOnce(Return(0));
+    EXPECT_CALL(dpm, dpm_firewall_apply_deny_rules(_)).Times(3).WillRepeatedly(Return(0));
+
+    EXPECT_TRUE(comm_pe.Init());
+    Json::Value root;
+    Json::Reader reader;
+    ASSERT_TRUE(reader.parse(policy, root));
+    EXPECT_TRUE(comm_pe.ParseGroup(root));
+
+    EXPECT_NO_THROW(comm_pe.Deinit());
+}
index 3e90912..6626598 100644 (file)
@@ -127,49 +127,6 @@ protected:
 NM_hContext IoTDevManagerTestWithReg::ctx;
 bool IoTDevManagerTestWithReg::registered;
 
-class IoTDevManagerWithOwned: public ::testing::Test
-{
-public:
-    static void SetUpTestCase() {
-        IoTivity::getInstance()->signOut();
-        ASSERT_EQ(EC_OK, NM_init(&ctx));
-
-        std::string login(TEST_ACCOUNT_LOGIN);
-        std::string password(TEST_ACCOUNT_PASSWORD);
-        ASSERT_EQ(EC_OK, NM_signIn(ctx, login.c_str(), password.c_str()));
-        ASSERT_EQ(EC_OK, NM_getOwnedDevices(ctx, &dev_list));
-        ASSERT_NE(0, NM_getListSize(dev_list)) << "No owned devices registered. Test is impossible.";
-        uid = nullptr;
-        const char* nd_uid;
-        while ((nd_uid = NM_deviceListEnum(dev_list)) != nullptr) {
-            NM_DeviceInfo info;
-            ASSERT_EQ(EC_OK, NM_getDeviceInfo(dev_list, nd_uid, &info));
-            if (info.type == std::string{"tv"}) {
-                uid = nd_uid;
-                break;
-            }
-            NM_freeDeviceInfo(&info);
-        }
-    }
-
-    static void TearDownTestCase() {
-        NM_freeDeviceList(&dev_list);
-        ASSERT_NO_THROW(NM_signOut(ctx));
-        ASSERT_NO_THROW(NM_cleanup(&ctx));
-    }
-
-protected:
-    static NM_hContext ctx;
-    static const char* uid;
-    static NM_hDeviceList dev_list;
-};
-
-NM_hContext IoTDevManagerWithOwned::ctx;
-const char* IoTDevManagerWithOwned::uid;
-NM_hDeviceList IoTDevManagerWithOwned::dev_list;
-
-#define TAG "Tests"
-
 void each_callback(NM_hDeviceList list, const char* uid, void* param)
 {
     NM_DeviceInfo info;
@@ -433,53 +390,6 @@ TEST_F(IoTDevManagerTestWithReg, reportTest)
 }
 
 /**
- * Test checks policy features
- * 1. Post policy
- * 2. Get policy and compare with posted
- * 3. Free memory
- */
-TEST_F(IoTDevManagerWithOwned, DISABLED_policyTest)
-{
-    std::string policy = R"-([
-    {
-        "group": "tv-extension",
-        "policies":
-        [
-            {
-                "name": "bluetooth",
-                "state": 1,
-                "items":
-                [
-                ]
-            },
-            {
-                "name": "iptables",
-                "state": 0,
-                "items":
-                [
-                    "127.0.0.0/24|UDP|10-1024",
-                    "1.1.1.1|TCP|80,443",
-                    "8.8.8.8"
-                ]
-            }
-        ]
-    }
-])-";
-
-    ASSERT_EQ(EC_OK, NM_setDevicePolicy(ctx, uid, policy.c_str()));
-    ASSERT_EQ(EC_NULL_POINTER, NM_setDevicePolicy(ctx, nullptr, policy.c_str()));
-
-    char* policy_recv = nullptr;
-
-    ASSERT_EQ(EC_OK, NM_getDevicePolicy(ctx, uid, "", &policy_recv));
-    ASSERT_EQ(EC_NULL_POINTER, NM_getDevicePolicy(ctx, IoTivity::getInstance()->getDeviceID().c_str(), "", nullptr));
-
-    ASSERT_NE(nullptr, policy_recv);
-    EXPECT_EQ(policy, policy_recv);
-    ASSERT_NO_THROW(NM_freeCharBuffer(policy_recv));
-}
-
-/**
  * Test checks device discovery use case
  * 1. Get device report for wrong did
  * 2. Check that return value is NULL
@@ -501,13 +411,20 @@ TEST_F(IoTDevManagerTest, reportTestWrongDid)
  * 2. Check it's not empty
  * 3. Check JSON format is correct
  */
-TEST_F(IoTDevManagerWithOwned, agentsListTest)
+TEST_F(IoTDevManagerTestWithReg, agentsListTest)
 {
     char* agents = nullptr;
-    ASSERT_EQ(EC_NULL_POINTER, NM_getDeviceAgents(ctx, nullptr, &agents));
-    if (uid == nullptr) {
+    char** uuids;
+
+    ASSERT_EQ(EC_OK, NM_getOwnedDevicesUUIDs(ctx, &uuids));
+    const char* uid;
+
+    if (uuids == nullptr || (uid  = uuids[0]) == nullptr) {
+        FAIL() << "No devices";
         return;
     }
+
+    ASSERT_EQ(EC_NULL_POINTER, NM_getDeviceAgents(ctx, nullptr, &agents));
     ASSERT_EQ(EC_OK, NM_getDeviceAgents(ctx, uid, &agents));
     ASSERT_NE(nullptr, agents);
 
@@ -519,6 +436,8 @@ TEST_F(IoTDevManagerWithOwned, agentsListTest)
     Json::Value root;
     Json::Reader reader;
     ASSERT_TRUE(reader.parse(agents_list, root));
+
+    ASSERT_NO_THROW(NM_freeDeviceArray(&uuids));
 }
 
 #include "iotutils.h"
index 2f803dd..b7b3ffe 100644 (file)
@@ -63,71 +63,3 @@ TEST(Test_PolicyEnforce, ParsePolicy_throw)
     // Simulate throwing exception on parsing
     EXPECT_EQ(PolicyEnforce::Result::ERROR_PARSING, pe.ParsePolicy(MOCK_POLICY_JSON));
 }
-
-//27           1 : PolicyEnforce::PolicyEnforce()
-//28           1 :     : m_policyGroups()
-//29             : {
-//30           1 : }
-//31             :
-//32             : PolicyEnforce::Result
-//33           1 : PolicyEnforce::ParsePolicy(const std::string& jsonString)
-//34             : {
-//35           1 :     LOG_D(TAG, "PolicyEnforce::ParsePolicy");
-//36           1 :     Result result = Result::SUCCESS;
-//37             :
-//38             :     try {
-//39           1 :         if (jsonString.empty()) {
-//40           0 :             return Result::ERROR_PARSING; //TODO
-//41             :         }
-//42             :
-//43           2 :         Json::Value policyGroupList;
-//44           2 :         Json::Reader reader;
-//45             :
-//46           1 :         bool parsingSuccessful = reader.parse(jsonString.c_str(), policyGroupList);
-//47             :
-//48           1 :         if (!parsingSuccessful || policyGroupList.empty()) {
-//49           0 :             return Result::ERROR_PARSING; //TODO
-//50             :         }
-//51             :
-//52           2 :         for (auto& node : policyGroupList) {
-//53           2 :             std::string groupName = node.get("group", "").asString();
-//54             :
-//55           1 :             if (groupName.empty()) {
-//56           0 :                 LOG_E(TAG, "No group node in class");
-//57           0 :                 return Result::ERROR_PARSING;
-//58             :             }
-//59             :
-//60           1 :             PolicyGroupMap::iterator it = m_policyGroups.find(groupName);
-//61             :
-//62           1 :             if (it == m_policyGroups.end()) {
-//63             :                 //FIXME Set error if error was occured
-//64           0 :                 continue; //TODO
-//65             :             }
-//66             :
-//67           1 :             IPolicyGroupEnforce& groupEnforce = *(it->second);
-//68             :
-//69           1 :             if (!groupEnforce.Init(/*m_context*/)) {
-//70           0 :                 result = Result::ERROR_GROUP;
-//71           0 :                 continue; //TODO
-//72             :             }
-//73             :
-//74           2 :             Json::Value policiesList = node.get("policies", "");
-//75             :
-//76           1 :             if (policiesList.empty()) {
-//77           0 :                 LOG_E(TAG, "No group node in class");
-//78           0 :                 return Result::ERROR_PARSING;
-//79             :             }
-//80             :
-//81           1 :             if (!groupEnforce.ParseGroup(policiesList)) {
-//82           0 :                 LOG_E(TAG, "Failed to apply policy group: %s", groupName.c_str());
-//83           0 :                 result = Result::ERROR_GROUP;
-//84             :             }
-//85             :
-//86           1 :             groupEnforce.Deinit();
-//87             :         }
-//88           0 :     } catch (std::exception& e) {
-//89           0 :         LOG_E(TAG, "Failed to apply policy, exception: %s", e.what());
-//90           0 :         LOG_E(TAG, "Policy which caused this exception: %s", jsonString.c_str());
-//91           0 :         result = Result::ERROR_PARSING;
-//92             :     }
-//93             :
diff --git a/device_core/utest/test_policyhandlerfactory.cpp b/device_core/utest/test_policyhandlerfactory.cpp
new file mode 100644 (file)
index 0000000..93f7bcc
--- /dev/null
@@ -0,0 +1,29 @@
+#include "iotivity_mock.h"
+#include "policyhandlerfactory.h"
+
+namespace
+{
+const std::string REPORTHANDLER_SID = "report-handler-server-id";
+}
+
+TEST(Test_PolicyHandlerFactory, createWithResource)
+{
+    IoTivityMock iot;
+    try {
+        auto ph = PolicyHandlerFactory::createWithResource(&iot, REPORTHANDLER_SID);
+        ASSERT_TRUE(bool(ph));
+    } catch (std::exception& e) {
+        FAIL() << "Exception: " << e.what();
+    }
+}
+
+TEST(Test_PolicyHandlerFactory, createWithMQ)
+{
+    IoTivityMock iot;
+    try {
+        auto ph = PolicyHandlerFactory::createWithMQ(&iot);
+        ASSERT_TRUE(bool(ph));
+    } catch (std::exception& e) {
+        FAIL() << "Exception: " << e.what();
+    }
+}
diff --git a/device_core/utest/test_reporthandlerfactory.cpp b/device_core/utest/test_reporthandlerfactory.cpp
new file mode 100644 (file)
index 0000000..7c6920e
--- /dev/null
@@ -0,0 +1,29 @@
+#include "iotivity_mock.h"
+#include "reporthandlerfactory.h"
+
+namespace
+{
+const std::string REPORTHANDLER_SID = "report-handler-server-id";
+}
+
+TEST(Test_ReportHandlerFactory, createWithResource)
+{
+    IoTivityMock iot;
+    try {
+        auto rh = ReportHandlerFactory::createWithResource(&iot, REPORTHANDLER_SID);
+        ASSERT_TRUE(bool(rh));
+    } catch (std::exception& e) {
+        FAIL() << "Exception: " << e.what();
+    }
+}
+
+TEST(Test_ReportHandlerFactory, createWithMQ)
+{
+    IoTivityMock iot;
+    try {
+        auto rh = ReportHandlerFactory::createWithMQ(&iot);
+        ASSERT_TRUE(bool(rh));
+    } catch (std::exception& e) {
+        FAIL() << "Exception: " << e.what();
+    }
+}
diff --git a/device_core/utest/test_systemdwrapper.cpp b/device_core/utest/test_systemdwrapper.cpp
new file mode 100644 (file)
index 0000000..742e350
--- /dev/null
@@ -0,0 +1,28 @@
+#include "mock/sd-daemon-mock.h"
+#include "systemdwrapper.h"
+
+using ::testing::Eq;
+using ::testing::StrEq;
+using ::testing::Return;
+
+namespace
+{
+const char READY_STR[] = "READY=1";
+const char WATCHDOG_STR[] = "WATCHDOG=1";
+}
+
+TEST(Test_SystemdWrapper, notifyReady)
+{
+    SDDaemonMock daemon;
+
+    EXPECT_CALL(daemon, sd_notify(Eq(0), StrEq(READY_STR))).WillOnce(Return(-1));
+    SystemdWrapper::notifyReady();
+}
+
+TEST(Test_SystemdWrapper, notifyWatchDog)
+{
+    SDDaemonMock daemon;
+
+    EXPECT_CALL(daemon, sd_notify(Eq(0), StrEq(WATCHDOG_STR))).WillOnce(Return(0));
+    SystemdWrapper::notifyWatchDog();
+}