From 30f6ac91ec51a29dce17ffe62bb12db9c662bb7a Mon Sep 17 00:00:00 2001 From: Mykhailo Kotsiuruba Date: Fri, 18 Aug 2017 23:20:04 +0300 Subject: [PATCH] Test Coverage Increased Overall coverage rate: lines......: 64.2% (1624 of 2528 lines) functions..: 70.8% (364 of 514 functions) --- device_core/CMakeLists.txt | 2 +- device_core/iotivity_lib/inc/iotivity.h | 2 ++ device_core/iotivity_lib/src/iotivity.cpp | 2 ++ device_core/utest/test_IoT.cpp | 37 +++++++++++++++++++++++++++++ device_core/utest/test_commandhandler.cpp | 2 ++ device_core/utest/test_iot_dev_manager.cpp | 28 ++++++++++++++++------ device_core/utest/test_iot_notification.cpp | 1 + device_core/utest/test_mq.cpp | 7 ++---- device_core/utest/test_rest.cpp | 6 +++-- 9 files changed, 72 insertions(+), 15 deletions(-) diff --git a/device_core/CMakeLists.txt b/device_core/CMakeLists.txt index 96dca62..082887e 100644 --- a/device_core/CMakeLists.txt +++ b/device_core/CMakeLists.txt @@ -146,7 +146,7 @@ else() add_custom_target(coverage COMMAND mkdir -p ${COV_FOLDER} COMMAND lcov -t "result" -o ${COV_FOLDER}/utest.info -c -d .. --rc lcov_branch_coverage=1 -q - COMMAND lcov --remove ${COV_FOLDER}/utest.info '*utest/*' '*agent_lib/rmi*' '/usr/include/*' '*iotivity/*' '*main.cpp' --rc lcov_branch_coverage=1 -o ${COV_FOLDER}/utest_filtered.info -q + COMMAND lcov --remove ${COV_FOLDER}/utest.info '*utest/*' '$ENV{IOTIVITY_HOME}/*' '*agent_lib/rmi*' '/usr/include/*' '*iotivity/*' '*main.cpp' --rc lcov_branch_coverage=1 -o ${COV_FOLDER}/utest_filtered.info -q COMMAND genhtml -o ${COV_FOLDER} ${COV_FOLDER}/utest_filtered.info COMMAND echo "Coverage calculated." COMMENT "Coverage stat with LCOV.\n") diff --git a/device_core/iotivity_lib/inc/iotivity.h b/device_core/iotivity_lib/inc/iotivity.h index 4f830c9..859063f 100644 --- a/device_core/iotivity_lib/inc/iotivity.h +++ b/device_core/iotivity_lib/inc/iotivity.h @@ -229,11 +229,13 @@ private: */ void unsubscribeOwnedPresence(); + /* void devicePresenceHandle( const OC::HeaderOptions& hOptions, const OC::OCRepresentation& rep, const int eCode, const int seqN); + */ static void connectionChangedCallback(const std::string& url, int con_type, bool state); diff --git a/device_core/iotivity_lib/src/iotivity.cpp b/device_core/iotivity_lib/src/iotivity.cpp index 88f18a2..afc46bb 100644 --- a/device_core/iotivity_lib/src/iotivity.cpp +++ b/device_core/iotivity_lib/src/iotivity.cpp @@ -471,6 +471,7 @@ void IoTivity::deleteFromAccount() } } +/* void IoTivity::devicePresenceHandle( const HeaderOptions& hOptions, const OCRepresentation& rep, @@ -493,6 +494,7 @@ void IoTivity::devicePresenceHandle( } } } +*/ void IoTivity::setDevicePresenceHook(PresenceHook&& hook) { diff --git a/device_core/utest/test_IoT.cpp b/device_core/utest/test_IoT.cpp index 82c2603..7958676 100644 --- a/device_core/utest/test_IoT.cpp +++ b/device_core/utest/test_IoT.cpp @@ -42,8 +42,12 @@ class test_IoT_Fixture: public ::testing::Test public: void SetUp() override { + IoTivity::cleanUp(); ASSERT_EQ(EC_OK, NM_init(&ctx)); + sleep(1); + ASSERT_EQ(EC_OK, NM_signIn(ctx, TEST_ACCOUNT_LOGIN.c_str(), TEST_ACCOUNT_PASSWORD.c_str())); + sleep(1); iotivity = ctx->instance; ASSERT_TRUE(iotivity->isSignedIn()); } @@ -70,6 +74,19 @@ TEST_F(test_IoT_Fixture, signInCorrect) try { ASSERT_TRUE(iotivity->isSignedIn()); + ASSERT_FALSE(iotivity->host().empty()); + ASSERT_FALSE(iotivity->cloudId().empty()); + std::string host = iotivity->host(); + std::string uid = iotivity->getCloudAuthId(); + std::string access_token = iotivity->getCloudAccessToken(); + sleep(1); + + iotivity->signOut(); + sleep(1); + ASSERT_FALSE(iotivity->isSignedIn()); + iotivity->signIn(host, uid, access_token); + ASSERT_TRUE(iotivity->isSignedIn()); + sleep(1); iotivity->signOut(); ASSERT_FALSE(iotivity->isSignedIn()); } @@ -137,3 +154,23 @@ TEST_F(test_IoT_Fixture, findDevicesWork) ASSERT_NO_THROW(iotivity->findDevices(false, CT_DEFAULT, OC_RSRVD_WELL_KNOWN_URI)); } + +TEST_F(test_IoT_Fixture, publishResourcesWork) +{ + ResourceHandles rhandles; + ASSERT_NO_THROW(iotivity->publishResources(rhandles)); + ASSERT_NO_THROW(iotivity->unPublishResources(rhandles)); + ASSERT_NO_THROW(iotivity->unPublishAllResources()); +} + +TEST_F(test_IoT_Fixture, registerDeviceInfoWork) +{ + ASSERT_NO_THROW(iotivity->registerDeviceInfo("test_device", "test_device", "test_device")); +} + +/* +TEST_F(test_IoT_Fixture, registerDeviceInfoWork) +{ + ASSERT_NO_THROW(iotivity->registerDeviceInfo("test_device", "test_device", "test_device")); +} +*/ diff --git a/device_core/utest/test_commandhandler.cpp b/device_core/utest/test_commandhandler.cpp index 8cf26e6..6832c52 100644 --- a/device_core/utest/test_commandhandler.cpp +++ b/device_core/utest/test_commandhandler.cpp @@ -46,6 +46,7 @@ class test_commandhandler_fixture : public ::testing::Test public: void SetUp() { + IoTivity::cleanUp(); ASSERT_EQ(EC_OK, NM_init(&ctx)); ASSERT_EQ(EC_OK, NM_signIn(ctx, TEST_ACCOUNT_LOGIN.c_str(), TEST_ACCOUNT_PASSWORD.c_str())); } @@ -93,6 +94,7 @@ TEST_F(test_commandhandler_fixture, test_unOwnTask_standard) handler.process(rep); proxy->stop(); proxy->join(); + sleep(1); } catch (std::exception& e) { diff --git a/device_core/utest/test_iot_dev_manager.cpp b/device_core/utest/test_iot_dev_manager.cpp index ddb6fa4..718801f 100644 --- a/device_core/utest/test_iot_dev_manager.cpp +++ b/device_core/utest/test_iot_dev_manager.cpp @@ -29,6 +29,7 @@ class IoTDevManagerTest: public ::testing::Test public: void SetUp() override { + IoTivity::cleanUp(); ASSERT_EQ(EC_OK, NM_init(&ctx)); std::string login(TEST_ACCOUNT_LOGIN); @@ -72,6 +73,7 @@ public: { try { + IoTivity::cleanUp(); ASSERT_EQ(EC_OK, NM_init(&ctx)); std::string login(TEST_ACCOUNT_LOGIN); @@ -117,6 +119,7 @@ public: OC::OCRepresentation rep; rep.setValue("duid", device_id); + rep.setValue("action", std::string{"unregister"}); iotivity->getMqHandler()->publish("/srv/unreg", rep); } } @@ -141,6 +144,7 @@ class IoTDevManagerWithOwned: public ::testing::Test public: static void SetUpTestCase() { + IoTivity::cleanUp(); ASSERT_EQ(EC_OK, NM_init(&ctx)); std::string login(TEST_ACCOUNT_LOGIN); @@ -530,13 +534,22 @@ TEST_F(IoTDevManagerTestWithReg, reportTest) std::time_t current_time = std::time(nullptr); std::ostringstream os; std::string device_id = iotivity->getDeviceID(); - os << "{" - << "\"data\":{\"some_data\":\"report data\"}," - << "\"date\":\"" << std::ctime(¤t_time) << "\"," - << "\"did\":\"" << device_id.c_str() << "\"," - << "\"name\":\"sim\"," - << "\"result\":7" - << "}"; + char *c_Time = std::ctime(¤t_time); + c_Time[std::strlen(c_Time) - 1] = '\0'; + os << "{\"did\": \"" << device_id.c_str() <<"\",\"date\": \""<< c_Time <<"\"," + << "\"name\": \"smack\",\"result\": 0,\"data\": {\"log\":\"audit(1500281614." + << "841:722): lsm=SMACK fn=smack_inode_getattr action=denied mode=enforcing " + << "wait=no subject=User object=System requested=r d_inst=1 ppid=22847 " + << "ppid_comm=bash pid=23926 comm=bash path=/tmp/wm_start dev=tmpfs ino=18596" + << " user_bt=23926" + << "[23926][#0 0x429b5e3c in ___xstat64 () from /usr/lib/libc-2.24.so]" + << "[23926][#1 0x0006b439 in append_to_match () from /usr/bin/bash]" + << "[23926][#2 0x0006cda9 in rl_complete_internal () from /usr/bin/bash]" + << "[23926][#3 0x00067385 in _rl_dispatch_subseq () from /usr/bin/bash]" + << "[23926][#4 0x00067543 in readline_internal_char () from /usr/bin/bash]" + << "[23926][#5 0x000679f7 in readline () from /usr/bin/bash]" + << "[23926][#6 0x00026e1b in yy_readline_get () from /usr/bin/bash]" + << "[23926][#7 0x0002860d in shell_getc () from /usr/bin/bash]\"}}"; std::string new_report = os.str(); @@ -575,6 +588,7 @@ TEST_F(IoTDevManagerTestWithReg, reportTest) } catch (std::exception& e) { + std::cout << e.what() <instance; diff --git a/device_core/utest/test_mq.cpp b/device_core/utest/test_mq.cpp index e68c1c6..ebe0739 100644 --- a/device_core/utest/test_mq.cpp +++ b/device_core/utest/test_mq.cpp @@ -36,6 +36,7 @@ class TestIotMQ: public ::testing::Test public: void SetUp() override { + IoTivity::cleanUp(); ASSERT_EQ(EC_OK, NM_init(&ctx)); ASSERT_EQ(EC_OK, NM_signIn(ctx, TEST_ACCOUNT_LOGIN.c_str(), TEST_ACCOUNT_PASSWORD.c_str())); iot = ctx->instance; @@ -104,13 +105,9 @@ TEST_F(TestIotMQ, publishCorrect) std::mutex notificationMtx; std::unique_lock notificationLock(notificationMtx); - auto mqHandler = iot->getMqHandler(); - mqHandler->subscribe("/topic1/test2", &subscribeCB); - mqHandler->publish("/topic1/test2", rep); - notificationCV.wait_for( notificationLock, std::chrono::seconds(3) @@ -143,13 +140,13 @@ TEST_F(TestIotMQ, publishCorrect) TEST_F(TestIotMQ, loopPublish) { std::string stringToPublish("test"); - OCRepresentation rep; try { MqClient pubMqHandler(cloud_host); for (int i = 0; i <= 10; i++) { + OCRepresentation rep; rep["message"] = stringToPublish + std::to_string(i); pubMqHandler.publish("/loopPublish", rep); } diff --git a/device_core/utest/test_rest.cpp b/device_core/utest/test_rest.cpp index 42ab2df..9018bb9 100644 --- a/device_core/utest/test_rest.cpp +++ b/device_core/utest/test_rest.cpp @@ -116,7 +116,7 @@ TEST(test_REST, test_policyUseCase) std::string code = service.getAuthCode(TEST_ACCOUNT_LOGIN, TEST_ACCOUNT_PASSWORD); ASSERT_FALSE(code.empty()); std::cout << "Received code: " << code << std::endl; - + NetworkManager::IoTivity::cleanUp(); auto iotivity = NetworkManager::IoTivity::getInstance(); iotivity->signUp(cloud_host, NetworkManager::IoTivity::DEFAULT_PROVIDER, code); @@ -134,7 +134,7 @@ TEST(test_REST, test_policyUseCase) throw; } } - + std::this_thread::sleep_for(std::chrono::seconds(2)); auto devs = service.getOwnedDevices(user_id); if (devs.find(test_device.duid) == devs.end()) @@ -164,6 +164,8 @@ TEST(test_REST, test_policyUseCase) OC::OCRepresentation rep; rep.setValue("duid", test_device.duid); + std::string unreg = "unregister"; + rep.setValue("action", unreg); iotivity->getMqHandler()->publish("/srv/unreg", rep); } catch(std::exception& e) -- 2.7.4