Tests actualized. Some SRK SVACE warnings fixed.
authorLomtev Dmytro <d.lomtev@samsung.com>
Fri, 22 Sep 2017 09:23:04 +0000 (12:23 +0300)
committerLomtev Dmytro <d.lomtev@samsung.com>
Mon, 2 Oct 2017 11:57:48 +0000 (14:57 +0300)
12 files changed:
device_core/ctrl_app_lib/inc/rest_request.h
device_core/ctrl_app_lib/src/ctrl_app_support.cpp
device_core/iotivity_lib/src/iot_resource_server.cpp
device_core/nmdaemon/hub_report_resource.cpp
device_core/utest/test_IoT.cpp
device_core/utest/test_commandhandler.cpp
device_core/utest/test_emo.cpp
device_core/utest/test_iot_dev_manager.cpp
device_core/utest/test_mq.cpp
device_core/utest/test_mq_topic.cpp
device_core/utest/test_nmd_utils.cpp
device_core/utest/test_rest.cpp

index 70b1b1c..186ca82 100644 (file)
@@ -52,6 +52,17 @@ public:
     RestRequest(const std::string& host);
 
     /**
+     * @brief Not copy constructible
+     */
+    RestRequest(const RestRequest&) = delete;
+
+    /**
+     * @brief Can not be assined
+     * @return
+     */
+    RestRequest& operator=(const RestRequest&) = delete;
+
+    /**
      * @brief Destructor
      */
     ~RestRequest();
index 67f0630..a96ba4c 100644 (file)
 #include <boost/property_tree/ptree.hpp>
 #include <boost/property_tree/ini_parser.hpp>
 
-#if !defined(__TIZEN__) && defined(INSTALL_DIR)
-#   define INSTALL_PREFIX(x) MAKE_STRING(x)
-#   define MAKE_STRING(x) #x
-#   define CONF_PREFIX INSTALL_PREFIX(INSTALL_DIR)
-#else
-#   define CONF_PREFIX
+#define STRINGIFY(x) MAKE_STRING(x)
+#define MAKE_STRING(x) #x
+
+#if !defined(NWMANAGER_CONFIG_FILE)
+#   error "NWMANAGER_CONFIG_FILE must be defined"
 #endif
 
+#define CONFIG_FILE STRINGIFY(NWMANAGER_CONFIG_FILE)
+
 using namespace NetworkManager;
 
 #define TAG "NetworkManager"
@@ -42,7 +43,7 @@ namespace
 // nmdaemon configuration path
 const std::string INI_FILE_PATH
 {
-    CONF_PREFIX "/etc/nmdaemon/nmdaemon.conf"
+    CONFIG_FILE
 };
 // default iotcloud IP (local SRK server)
 const std::string DEFAULT_CLOUD_IP
@@ -227,9 +228,12 @@ void NM_cleanup(NM_hContext* ctx)
 {
     FN_VISIT
     if (ctx != nullptr && *ctx != nullptr) {
-        if ((*ctx)->context != nullptr) {
-            delete(*ctx)->context;
+        SecurityContext* sec_context = (*ctx)->context;
+
+        if (sec_context != nullptr) {
+            delete sec_context;
         }
+
         delete *ctx;
         *ctx = nullptr;
     }
index 6b67483..f38ef68 100644 (file)
@@ -11,10 +11,7 @@ namespace NetworkManager
 {
 
 IotResourceServer::IotResourceServer(const std::string& uri, const std::string& type)
-    : IotResourceServer(uri, type,
-{
-    OC::DEFAULT_INTERFACE
-})
+    : IotResourceServer(uri, type, {OC::DEFAULT_INTERFACE})
 {
 }
 
index 452949c..fccd9ce 100644 (file)
@@ -84,7 +84,11 @@ OCEntityHandlerResult ReportResource::entityHandler(std::shared_ptr<OCResourceRe
 
             pResponse->setResponseResult(ehResult);
             pResponse->setResourceRepresentation(OCRepresentation{});
-            OCPlatform::sendResponse(pResponse);
+            OCStackResult sendResult = OCPlatform::sendResponse(pResponse);
+
+            if (OC_STACK_OK != sendResult) {
+                LOG_E(TAG, "Send response error: %d", sendResult);
+            }
         }
     } else {
         LOG_E(TAG, "Invalid request");
index 3c3e9ab..9acec1a 100644 (file)
@@ -37,7 +37,7 @@ extern std::string cloud_host;
 extern std::string TEST_ACCOUNT_LOGIN;
 extern std::string TEST_ACCOUNT_PASSWORD;
 
-class test_IoT_Fixture: public ::testing::Test
+class Test_IoT_Fixture: public ::testing::Test
 {
 public:
     void SetUp() override {
@@ -67,7 +67,7 @@ protected:
  * 3. Sign out
  * 4. Check signedIn flag is false
  */
-TEST_F(test_IoT_Fixture, signInCorrect)
+TEST_F(Test_IoT_Fixture, signInCorrect)
 {
     try {
         ASSERT_TRUE(iotivity->isSignedIn());
@@ -130,7 +130,7 @@ TEST(test_IoT, test_IOT_ReportFormat)
     ASSERT_FALSE(NMD::makeReport("1", "sim", 0, "report data").empty());
 }
 
-TEST_F(test_IoT_Fixture, findResourceWork)
+TEST_F(Test_IoT_Fixture, findResourceWork)
 {
     ASSERT_NO_THROW(iotivity->findResource(false, "", OC_RSRVD_WELL_KNOWN_URI, CT_DEFAULT));
     ASSERT_NO_THROW(iotivity->findResourceList(false, "", OC_RSRVD_WELL_KNOWN_URI, CT_DEFAULT));
@@ -141,14 +141,14 @@ TEST_F(test_IoT_Fixture, findResourceWork)
 
 }
 
-TEST_F(test_IoT_Fixture, findDevicesWork)
+TEST_F(Test_IoT_Fixture, findDevicesWork)
 {
     ASSERT_NO_THROW(iotivity->findDevices(true, CT_DEFAULT, OC_RSRVD_WELL_KNOWN_URI));
 
     ASSERT_NO_THROW(iotivity->findDevices(false, CT_DEFAULT, OC_RSRVD_WELL_KNOWN_URI));
 }
 
-TEST_F(test_IoT_Fixture, publishResourcesWork)
+TEST_F(Test_IoT_Fixture, publishResourcesWork)
 {
     ResourceHandles rhandles;
     ASSERT_NO_THROW(iotivity->publishResources(rhandles));
@@ -156,13 +156,13 @@ TEST_F(test_IoT_Fixture, publishResourcesWork)
     ASSERT_NO_THROW(iotivity->unPublishAllResources());
 }
 
-TEST_F(test_IoT_Fixture, registerDeviceInfoWork)
+TEST_F(Test_IoT_Fixture, registerDeviceInfoWork)
 {
     ASSERT_NO_THROW(iotivity->registerDeviceInfo("test_device", "test_device", "test_device"));
 }
 
 /*
-TEST_F(test_IoT_Fixture, registerDeviceInfoWork)
+TEST_F(Test_IoT_Fixture, registerDeviceInfoWork)
 {
     ASSERT_NO_THROW(iotivity->registerDeviceInfo("test_device", "test_device", "test_device"));
 }
index 86f444e..58378e9 100644 (file)
@@ -38,7 +38,7 @@ public:
     }
 };
 
-class test_commandhandler_fixture : public ::testing::Test
+class Test_commandhandler_fixture : public ::testing::Test
 {
 public:
     void SetUp() {
@@ -64,7 +64,7 @@ public:
 /**
  * Test CommandHandler class UNOWN command for standard working mode
  */
-TEST_F(test_commandhandler_fixture, test_unOwnTask_standard)
+TEST_F(Test_commandhandler_fixture, test_unOwnTask_standard)
 {
     MainThreadMock main_thread;
 
@@ -97,7 +97,7 @@ TEST_F(test_commandhandler_fixture, test_unOwnTask_standard)
 /**
  * Test CommandHandler class UNOWN command for primitive working mode
  */
-TEST_F(test_commandhandler_fixture, test_unOwnTask_primitive)
+TEST_F(Test_commandhandler_fixture, test_unOwnTask_primitive)
 {
     MainThreadMock main_thread;
 
@@ -128,7 +128,7 @@ TEST_F(test_commandhandler_fixture, test_unOwnTask_primitive)
 /**
  * Test CommandHandler class UNOWN command for hub working mode
  */
-TEST_F(test_commandhandler_fixture, test_unOwnTask_hub)
+TEST_F(Test_commandhandler_fixture, test_unOwnTask_hub)
 {
     MainThreadMock main_thread;
 
@@ -164,7 +164,7 @@ const std::string test_rpm_query_stub_path{"/tmp/test_rpm_query_stub.txt"};
 const std::string test_executable_package_name = test_executable + ".1.2.3.4.rpm";
 }
 
-TEST(test_commandhandler, test_uninstallTask)
+TEST(Test_commandhandler, test_uninstallTask)
 {
     try {
         IoTivity::cleanUp();
index 022dd98..70529eb 100644 (file)
@@ -274,7 +274,7 @@ static FILE* client_open(const char* path, const char* mode)
 /**
  * Test check report sender functional
  */
-TEST(test_emo, DISABLED_server)
+TEST(Test_emo, DISABLED_server)
 {
     OCPersistentStorage ps{client_open, fread, fwrite, fclose, unlink};
     PlatformConfig cfg{ServiceType::InProc, ModeType::Both, "0.0.0.0", 0, QualityOfService::HighQos, &ps};
@@ -326,7 +326,7 @@ void foundResource(std::shared_ptr<OCResource> resource)
 /**
  * Test check report sender functional
  */
-TEST(test_emo, DISABLED_client)
+TEST(Test_emo, DISABLED_client)
 {
     OCPersistentStorage ps{client_open, fread, fwrite, fclose, unlink};
     PlatformConfig cfg{ServiceType::InProc, ModeType::Both, "0.0.0.0", 0, QualityOfService::HighQos, &ps};
index 2d769ab..f4488fe 100644 (file)
@@ -436,7 +436,9 @@ TEST_F(IoTDevManagerTest, DISABLED_unown_device)
         ASSERT_NO_THROW(NM_resetDeviceList(dev_list));
         const char* uid = nullptr;
         while (nullptr != (uid = NM_deviceListEnum(dev_list))) {
-            if (uid != std::string{"2e19d28f-2ba1-9a3a-e157-7e50d9d4f022"}) continue;
+
+            if (uid != std::string{"1c3356cf-a8b2-ed03-1357-8604a8079653"}) continue;
+//            if (uid != std::string{"2e19d28f-2ba1-9a3a-e157-7e50d9d4f022"}) continue;
             NM_DeviceInfo info;
             ASSERT_EQ(EC_OK, NM_getDeviceInfo(dev_list, uid, &info));
             if (strcmp(info.name, "unknown") != 0) {
@@ -526,20 +528,9 @@ TEST_F(IoTDevManagerTestWithReg, reportTest)
         EXPECT_TRUE(reader.parse(received, received_json));
         EXPECT_NE(0u, received_json.size()) << "Empty reports received";
 
-        int i = 0;
-        for (; (unsigned)i < received_json.size(); i++) {
-            Json::Value recv = received_json[i];
-
-            if (recv["name"].asString() == sent_json["name"].asString()) {
-                EXPECT_EQ(sent_json["data"]["some_data"].asString(), recv["data"]["some_data"].asString());
-                EXPECT_EQ(sent_json["date"].asString(), recv["date"].asString());
-                EXPECT_EQ(sent_json["did"].asString(), recv["did"].asString());
-                EXPECT_EQ(sent_json["result"].asInt(), recv["result"].asInt());
-                break;
-            }
-        }
-
-        EXPECT_NE(i, received_json.size());
+        EXPECT_EQ(Json::arrayValue, received_json["dac"].type());
+        EXPECT_EQ(Json::arrayValue, received_json["smack"].type());
+        EXPECT_EQ(Json::arrayValue, received_json["syscall"].type());
     } catch (std::exception& e) {
         std::cout << e.what() << std::endl;
         EXPECT_TRUE(false) << "Exception: " << e.what();
@@ -589,7 +580,7 @@ TEST_F(IoTDevManagerWithOwned, DISABLED_policyTest)
     ASSERT_EQ(EC_NULL_POINTER, NM_getDevicePolicy(ctx, IoTivity::getInstance()->getDeviceID().c_str(), "", nullptr));
 
     ASSERT_NE(nullptr, policy_recv);
-    ASSERT_EQ(policy, policy_recv);
+    EXPECT_EQ(policy, policy_recv);
     ASSERT_NO_THROW(NM_freeCharBuffer(policy_recv));
 }
 
index 3512057..a8f5df8 100644 (file)
@@ -130,11 +130,11 @@ TEST_F(TestIotMQ, loopPublish)
     std::string stringToPublish("test");
 
     try {
-        MqClient pubMqHandler(cloud_host);
+        auto pubMqHandler = iot->getMqHandler();
         for (int i = 0; i <= 10; i++) {
             OCRepresentation rep;
             rep["message"] = stringToPublish + std::to_string(i);
-            pubMqHandler.publish("/loopPublish", rep);
+            pubMqHandler->publish("/loopPublish", rep);
         }
     } catch (NMexception& e) {
         ADD_FAILURE() << e.what() << " " << e.errorCode();
index 6cbc7ad..071afaa 100644 (file)
@@ -4,7 +4,7 @@
 using namespace NetworkManager;
 
 
-TEST(test_MqTopic, test_constructor_string)
+TEST(Test_MqTopic, test_constructor_string)
 {
     const std::string name{"/parent/topic_mid/topic_top"};
 
@@ -12,7 +12,7 @@ TEST(test_MqTopic, test_constructor_string)
     ASSERT_EQ(MqTopic::DEFAULT_MQ_BROKER_URI_ROOT + name, topic.getName());
 }
 
-TEST(test_MqTopic, test_constructor_iterator)
+TEST(Test_MqTopic, test_constructor_iterator)
 {
     const std::string t1 = "/parent";
     const std::string t2 = "/mid";
@@ -45,7 +45,7 @@ TEST(test_MqTopic, test_constructor_iterator)
     ASSERT_EQ(t1 + t2 + t3 + t4, topic4.getSubName());
 }
 
-TEST(test_MqTopic, test_split)
+TEST(Test_MqTopic, test_split)
 {
     const std::string t1 = "/parent";
     const std::string t2 = "/mid";
index 7066301..85bbb16 100644 (file)
@@ -22,7 +22,7 @@ bool fexists(const std::string& fname)
     return res == 0 && (info.st_mode & S_IFMT) == S_IFREG;
 }
 
-TEST(test_nmd_utils, config_cycle_write_read_delete)
+TEST(Test_nmd_utils, config_cycle_write_read_delete)
 {
     cfg_file_path_name = current_path() + testFileName;
 
@@ -55,7 +55,7 @@ TEST(test_nmd_utils, config_cycle_write_read_delete)
     ASSERT_NE(0, std::remove(cfg_file_path_name.c_str()));
 }
 
-TEST(test_nmd_utils, read_config_not_config_file)
+TEST(Test_nmd_utils, read_config_not_config_file)
 {
     cfg_file_path_name = current_path() + testFileName;
     ofstream out(cfg_file_path_name);
@@ -69,7 +69,7 @@ TEST(test_nmd_utils, read_config_not_config_file)
     remove(cfg_file_path_name.c_str());
 }
 
-TEST(test_nmd_utils, delete_config_with_file_that_does_not_exist)
+TEST(Test_nmd_utils, delete_config_with_file_that_does_not_exist)
 {
     cfg_file_path_name = current_path() + testFileName;
 
@@ -78,7 +78,7 @@ TEST(test_nmd_utils, delete_config_with_file_that_does_not_exist)
     ASSERT_NO_THROW(delete_config());
 }
 
-TEST(test_nmd_utils, write_log)
+TEST(Test_nmd_utils, write_log)
 {
     /* Set log filepath */
     log_file_path_name = current_path() + testFileName;
@@ -95,7 +95,7 @@ TEST(test_nmd_utils, write_log)
     remove(log_file_path_name.c_str());
 }
 
-TEST(test_nmd_utils, test_clear_hub_cache)
+TEST(Test_nmd_utils, test_clear_hub_cache)
 {
     hub_file_path_name = "/tmp/test_hub_file_path_name.dat";
     ofstream out(hub_file_path_name);
@@ -108,7 +108,7 @@ TEST(test_nmd_utils, test_clear_hub_cache)
     ASSERT_FALSE(fexists(hub_file_path_name)) << "Test file exists but must not";
 }
 
-TEST(test_nmd_utils, test_clear_hub_cache_file_not_exists)
+TEST(Test_nmd_utils, test_clear_hub_cache_file_not_exists)
 {
     ASSERT_FALSE(fexists(hub_file_path_name)) << "Test file exists but must not";
     ASSERT_NO_THROW(clear_hub_cache());
index d8dc1ed..6f0c84d 100644 (file)
@@ -26,7 +26,7 @@ const std::string TEST_DSM_SERVER_URL = "http://106.125.46.139:8080/dsm/restapi/
  * 3. Search for owned devices
  * 4. Iterate thoughout the list and print devices info
  */
-TEST(test_REST, test_get)
+TEST(Test_REST, test_get)
 {
     try {
         RestRequest request("http://example.com");
@@ -44,7 +44,7 @@ TEST(test_REST, test_get)
 /**
  * @brief TEST RestService::getAuthCode
  */
-TEST(test_REST, test_getAuthCode)
+TEST(Test_REST, test_getAuthCode)
 {
     try {
         RestService service(TEST_DSM_SERVER_URL);
@@ -60,7 +60,7 @@ TEST(test_REST, test_getAuthCode)
 /**
  * @brief TEST RestRequest with not existing HTTP address
  */
-TEST(test_REST, test_get_wrong_address)
+TEST(Test_REST, test_get_wrong_address)
 {
     RestRequest request("sdfgkadg.adg.ag.asdg.afg");
     RestRequest::QueryParameters params = {{"user", "anon"}, {"id", "3"}};
@@ -69,7 +69,7 @@ TEST(test_REST, test_get_wrong_address)
     ASSERT_THROW(request.get(params, "/", response), NMexception);
 }
 
-TEST(test_REST, test_RestRequest_addHeader_empty)
+TEST(Test_REST, test_RestRequest_addHeader_empty)
 {
     RestRequest request("http://example.com");
     ASSERT_THROW(request.addHeader("", "sdfvsdf"), std::runtime_error);
@@ -99,7 +99,7 @@ const std::string microsoft_agent_id{"3574462a-7efa-9449-4d9f-488734c79c0a"};
 /**
  * @brief TEST RestService::policyUseCase
  */
-TEST(test_REST, test_policyUseCase)
+TEST(Test_REST, test_policyUseCase)
 {
     try {
         RestService service(TEST_DSM_SERVER_URL);