From 55c170c679230dc3d70630b14bed12026cf8b9a6 Mon Sep 17 00:00:00 2001 From: Lomtev Dmytro Date: Mon, 6 Nov 2017 12:10:03 +0200 Subject: [PATCH] SECIOTSRK-596 Added tests for nmlib API functions. --- device_core/ctrl_app_lib/src/securitycontext.cpp | 3 +- device_core/utest/test_hubclient.cpp | 26 ++-- device_core/utest/test_iotresourceclient.cpp | 60 ++++---- device_core/utest/test_nmlibapi.cpp | 180 ++++++++++++++++++++++- device_core/utest/test_policyhandlerres.cpp | 18 +-- device_core/utest/test_reporthandlerres.cpp | 18 +-- 6 files changed, 235 insertions(+), 70 deletions(-) diff --git a/device_core/ctrl_app_lib/src/securitycontext.cpp b/device_core/ctrl_app_lib/src/securitycontext.cpp index 98f539b..f5df334 100644 --- a/device_core/ctrl_app_lib/src/securitycontext.cpp +++ b/device_core/ctrl_app_lib/src/securitycontext.cpp @@ -304,6 +304,7 @@ void SecurityContext::unsubscribeNotifications() IMqClient* mq = iotivity->getMqHandler(); std::string user_notification_topic = "/" + iotivity->getCloudAuthId() + "/notification"; mq->unsubscribe(user_notification_topic); + subscribed = false; } //void SecurityContext::unsubscribeOwnedPresence() @@ -365,8 +366,6 @@ std::string SecurityContext::getPolicy(const std::string& uuid, const std::strin void SecurityContext::postPolicy(const std::string& uuid, const std::string& policy) { FN_VISIT - auto it = getIoTDevice(uuid); - OCRepresentation repr; repr.setValue("policy", policy); repr.setValue("duid", uuid); diff --git a/device_core/utest/test_hubclient.cpp b/device_core/utest/test_hubclient.cpp index b2dc5d4..076da36 100644 --- a/device_core/utest/test_hubclient.cpp +++ b/device_core/utest/test_hubclient.cpp @@ -13,9 +13,9 @@ using ::testing::StrEq; namespace { -const std::string RESOURCE_HOST{"coap://192.168.1.2:5000"}; -const std::string RESOURCE_URI{"/resource"}; -const std::string RESOURCE_TYPE{"oic.fake"}; +const std::string FAKE_RESOURCE_HOST{"coap://192.168.1.2:5000"}; +const std::string FAKE_RESOURCE_URI{"/resource"}; +const std::string FAKE_RESOURCE_TYPE{"oic.fake"}; const std::string OWNED_DEVICE_ID{"OWNED-PRIMITIVE-ID"}; const std::string UNOWNED_DEVICE_ID{"UNOWNED-PRIMITIVE-ID"}; const std::string DEVICE_NAME{"PRIMITIVE-NAME"}; @@ -49,11 +49,11 @@ public: TEST(Test_HubClient, construction) { OCResource::Ptr resource = OCPlatform::constructResourceObject( - RESOURCE_HOST, - RESOURCE_URI, + FAKE_RESOURCE_HOST, + FAKE_RESOURCE_URI, CT_DEFAULT, true, - {RESOURCE_TYPE}, + {FAKE_RESOURCE_TYPE}, {DEFAULT_INTERFACE}); HubClient hub_null(nullptr); @@ -64,7 +64,7 @@ TEST(Test_HubClient, construction) HubClient hub_copy(hub); EXPECT_FALSE(!hub_copy); - EXPECT_EQ(RESOURCE_HOST, hub.host()); + EXPECT_EQ(FAKE_RESOURCE_HOST, hub.host()); EXPECT_EQ("", hub.sid()); } @@ -78,11 +78,11 @@ TEST(Test_HubClient, getPrimitiveDevices) { const int DEVICE_STATE = 1; OCResource::Ptr resource = OCPlatform::constructResourceObject( - RESOURCE_HOST, - RESOURCE_URI, + FAKE_RESOURCE_HOST, + FAKE_RESOURCE_URI, CT_DEFAULT, true, - {RESOURCE_TYPE}, + {FAKE_RESOURCE_TYPE}, {DEFAULT_INTERFACE}); std::shared_ptr hub = std::make_shared(resource); @@ -165,11 +165,11 @@ TEST(Test_HubClient, getPrimitiveDevices) TEST(Test_HubClient, ownPrimitiveDevice) { OCResource::Ptr resource = OCPlatform::constructResourceObject( - RESOURCE_HOST, - RESOURCE_URI, + FAKE_RESOURCE_HOST, + FAKE_RESOURCE_URI, CT_DEFAULT, true, - {RESOURCE_TYPE}, + {FAKE_RESOURCE_TYPE}, {DEFAULT_INTERFACE}); std::shared_ptr hub = std::make_shared(resource); diff --git a/device_core/utest/test_iotresourceclient.cpp b/device_core/utest/test_iotresourceclient.cpp index 0eef698..31f1c5b 100644 --- a/device_core/utest/test_iotresourceclient.cpp +++ b/device_core/utest/test_iotresourceclient.cpp @@ -13,14 +13,14 @@ using ::testing::Matcher; namespace { const std::string RESOURCE_SID{"resource-sid"}; -const std::string RESOURCE_TYPE{"resource.type"}; -const std::string RESOURCE_HOST{"coap://192.168.1.2:5000"}; -const std::string RESOURCE_URI{"/a/link"}; +const std::string FAKE_RESOURCE_TYPE{"resource.type"}; +const std::string FAKE_RESOURCE_HOST{"coap://192.168.1.2:5000"}; +const std::string FAKE_RESOURCE_URI{"/a/link"}; } TEST(Test_IotResourceClient, findResource_no_iotivity) { - IotResourceClient with_no_iotivity(nullptr, RESOURCE_TYPE, RESOURCE_SID); + IotResourceClient with_no_iotivity(nullptr, FAKE_RESOURCE_TYPE, RESOURCE_SID); EXPECT_FALSE(with_no_iotivity.findResource()); } @@ -29,36 +29,36 @@ TEST(Test_IotResourceClient, findResource_with_resignIn) IoTivityMock iotivity; OC::OCResource::Ptr empty; auto resource_stub = OC::OCPlatform::constructResourceObject( - RESOURCE_HOST, - RESOURCE_URI, + FAKE_RESOURCE_HOST, + FAKE_RESOURCE_URI, CT_DEFAULT, true, - {RESOURCE_TYPE}, + {FAKE_RESOURCE_TYPE}, {OC::DEFAULT_INTERFACE}); - EXPECT_CALL(iotivity, host()).WillRepeatedly(ReturnRef(RESOURCE_HOST)); + EXPECT_CALL(iotivity, host()).WillRepeatedly(ReturnRef(FAKE_RESOURCE_HOST)); { ::testing::InSequence dummy; EXPECT_CALL(iotivity, findResource( - Matcher(StrEq(RESOURCE_HOST)), - StrEq(RESOURCE_TYPE), + Matcher(StrEq(FAKE_RESOURCE_HOST)), + StrEq(FAKE_RESOURCE_TYPE), StrEq(OC_RSRVD_WELL_KNOWN_URI), Matcher(StrEq(RESOURCE_SID)))) .WillOnce(Return(empty)); EXPECT_CALL(iotivity, isConnected()).WillOnce(Return(true)); EXPECT_CALL(iotivity, signIn()).Times(1); EXPECT_CALL(iotivity, findResource( - Matcher(StrEq(RESOURCE_HOST)), - StrEq(RESOURCE_TYPE), + Matcher(StrEq(FAKE_RESOURCE_HOST)), + StrEq(FAKE_RESOURCE_TYPE), StrEq(OC_RSRVD_WELL_KNOWN_URI), Matcher(Eq(RESOURCE_SID)))) .WillOnce(Return(resource_stub)); } - IotResourceClient res(&iotivity, RESOURCE_TYPE, RESOURCE_SID); + IotResourceClient res(&iotivity, FAKE_RESOURCE_TYPE, RESOURCE_SID); EXPECT_TRUE(res.findResource()); } @@ -68,18 +68,18 @@ TEST(Test_IotResourceClient, findResource_failures) IoTivityMock iotivity; OC::OCResource::Ptr empty; - EXPECT_CALL(iotivity, host()).WillRepeatedly(ReturnRef(RESOURCE_HOST)); + EXPECT_CALL(iotivity, host()).WillRepeatedly(ReturnRef(FAKE_RESOURCE_HOST)); { EXPECT_CALL(iotivity, findResource( Matcher(StrEq(std::string{})), - StrEq(RESOURCE_TYPE), + StrEq(FAKE_RESOURCE_TYPE), StrEq(OC_RSRVD_WELL_KNOWN_URI), Matcher(StrEq(RESOURCE_SID)))) .WillOnce(Return(empty)); EXPECT_CALL(iotivity, findResource( - Matcher(StrEq(RESOURCE_HOST)), - StrEq(RESOURCE_TYPE), + Matcher(StrEq(FAKE_RESOURCE_HOST)), + StrEq(FAKE_RESOURCE_TYPE), StrEq(OC_RSRVD_WELL_KNOWN_URI), Matcher(Eq(CT_DEFAULT)))) .Times(2) @@ -91,11 +91,11 @@ TEST(Test_IotResourceClient, findResource_failures) .WillOnce(Throw(std::logic_error("error"))); } - IotResourceClient res(&iotivity, RESOURCE_TYPE, RESOURCE_SID); + IotResourceClient res(&iotivity, FAKE_RESOURCE_TYPE, RESOURCE_SID); EXPECT_FALSE(res.findResource(false)); - IotResourceClient res2(&iotivity, RESOURCE_TYPE); + IotResourceClient res2(&iotivity, FAKE_RESOURCE_TYPE); EXPECT_FALSE(res2.findResource()); EXPECT_FALSE(res2.findResource()); } @@ -105,23 +105,23 @@ TEST(Test_IotResourceClient, findResource) IoTivityMock iotivity; OC::OCResource::Ptr empty; auto resource_stub = OC::OCPlatform::constructResourceObject( - RESOURCE_HOST, - RESOURCE_URI, + FAKE_RESOURCE_HOST, + FAKE_RESOURCE_URI, CT_DEFAULT, true, - {RESOURCE_TYPE}, + {FAKE_RESOURCE_TYPE}, {OC::DEFAULT_INTERFACE}); ::testing::InSequence dummy; - EXPECT_CALL(iotivity, host()).WillRepeatedly(ReturnRef(RESOURCE_HOST)); + EXPECT_CALL(iotivity, host()).WillRepeatedly(ReturnRef(FAKE_RESOURCE_HOST)); EXPECT_CALL(iotivity, findResource( - Matcher(StrEq(RESOURCE_HOST)), - StrEq(RESOURCE_TYPE), + Matcher(StrEq(FAKE_RESOURCE_HOST)), + StrEq(FAKE_RESOURCE_TYPE), StrEq(OC_RSRVD_WELL_KNOWN_URI), Matcher(Eq(CT_DEFAULT)))) .WillOnce(Return(resource_stub)); - IotResourceClient res(&iotivity, RESOURCE_TYPE); + IotResourceClient res(&iotivity, FAKE_RESOURCE_TYPE); EXPECT_TRUE(res.findResource()); @@ -134,11 +134,11 @@ TEST(Test_IotResourceClient, construct) { OC::OCResource::Ptr empty; auto resource_stub = OC::OCPlatform::constructResourceObject( - RESOURCE_HOST, - RESOURCE_URI, + FAKE_RESOURCE_HOST, + FAKE_RESOURCE_URI, CT_DEFAULT, true, - {RESOURCE_TYPE}, + {FAKE_RESOURCE_TYPE}, {OC::DEFAULT_INTERFACE}); ::testing::InSequence dummy; @@ -149,5 +149,5 @@ TEST(Test_IotResourceClient, construct) EXPECT_TRUE(cli.host().empty()); EXPECT_TRUE(cli.sid().empty()); EXPECT_NO_THROW(cli = resource_stub); - EXPECT_EQ(RESOURCE_HOST, cli.host()); + EXPECT_EQ(FAKE_RESOURCE_HOST, cli.host()); } diff --git a/device_core/utest/test_nmlibapi.cpp b/device_core/utest/test_nmlibapi.cpp index 9bc8fc2..f70bf73 100644 --- a/device_core/utest/test_nmlibapi.cpp +++ b/device_core/utest/test_nmlibapi.cpp @@ -17,6 +17,7 @@ #include "securitycontext.h" #include "iotivity_mock.h" +#include "mqclient_mock.h" #include "iot_resource_mock.h" #include "device_control.h" #include "device_commands.h" @@ -37,6 +38,22 @@ extern std::string cloud_host; extern std::string TEST_ACCOUNT_LOGIN; extern std::string TEST_ACCOUNT_PASSWORD; +namespace +{ +const std::string DEV_UUID = "11111111-1111-1111-1111-111111111111"; +const std::string DEV_PARENT_UUID = "11111111-1111-1111-1111-222222222222"; +const std::string DEV_UUID_UNKNOWN = "unknown"; +const std::string DEV_NAME = "device-name"; +const std::string DEV_MODEL = "device-model"; +const std::string DEV_TYPE = "device-type"; +const std::string DEV_PARENT = "device-parent"; +const std::string DEV_AGENT_ID = "aget-id"; +const std::string FAKE_RESOURCE_HOST{"coap://192.168.1.2:5000"}; +const std::string FAKE_RESOURCE_URI{"/resource"}; +const std::string FAKE_RESOURCE_TYPE{"oic.fake"}; +const std::string CLOUD_AUTH_ID{"iot-cloud-auth-id"}; +} + /** * Performs init, signin, sign out and cleanup */ @@ -261,13 +278,6 @@ TEST(Test_nmlibapi, NM_deviceListForEach) */ TEST(Test_nmlibapi, NM_getDeviceInfo) { - const std::string DEV_UUID = "11111111-1111-1111-1111-111111111111"; - const std::string DEV_UUID_UNKNOWN = "unknown"; - const std::string DEV_NAME = "device-name"; - const std::string DEV_MODEL = "device-model"; - const std::string DEV_TYPE = "device-type"; - const std::string DEV_PARENT = "device-parent"; - NM_DeviceInfo info; IoTDeviceMock dev; NM_DeviceList list; @@ -313,3 +323,159 @@ TEST(Test_nmlibapi, NM_getDeviceInfo) EXPECT_NO_THROW(NM_freeDeviceInfo(&info)); } + +/** + * @brief TEST for NM_getDevicePolicy function + * 1. Call with nullptr instead of device id + * 2. Call with nullptr instead of agent id + * 3. Call with nullptr instead of policy pointer + */ +TEST(Test_nmlibapi, NM_getDevicePolicy) +{ + IoTivityMock iot; + NM_Context ctx; + ctx.instance = &iot; + ctx.context = nullptr; + char* policy; + + EXPECT_EQ(EC_NULL_POINTER, NM_getDevicePolicy(&ctx, nullptr, DEV_AGENT_ID.c_str(), &policy)); + EXPECT_EQ(EC_NULL_POINTER, NM_getDevicePolicy(&ctx, DEV_UUID.c_str(), nullptr, &policy)); + EXPECT_EQ(EC_NULL_POINTER, NM_getDevicePolicy(&ctx, DEV_UUID.c_str(), DEV_AGENT_ID.c_str(), nullptr)); +} + +/** + * @brief TEST for NM_setDevicePolicy function + * 1. Call with nullptr instead of device id + * 2. Call with nullptr instead of policy + * 3. Call with good parameters + * 4. simulate std::exception throw + * 5. simulate NMexception throw + */ +TEST(Test_nmlibapi, NM_setDevicePolicy) +{ + NM_Context ctx; + IoTivityMock iot; + MqClientMock mqclient; + SecurityContext sec(&iot); + ctx.context = &sec; + ctx.instance = &iot; + const std::string policy{"{policy object}"}; + OC::OCRepresentation repr; + repr.setValue("policy", policy); + repr.setValue("duid", DEV_UUID); + + EXPECT_CALL(iot, getMqHandler()) + .WillOnce(Return(&mqclient)) + .WillOnce(Throw(std::runtime_error("exception"))) // simulate exception throw + .WillOnce(Throw(NMexception("exception", EC_NOT_INITIALIZED))); // simulate exception throw + EXPECT_CALL(mqclient, publish(StrEq("/srv/policy"), Eq(repr))) + .Times(1); + + EXPECT_EQ(EC_NULL_POINTER, NM_setDevicePolicy(&ctx, nullptr, policy.c_str())); + EXPECT_EQ(EC_NULL_POINTER, NM_setDevicePolicy(&ctx, DEV_UUID.c_str(), nullptr)); + EXPECT_EQ(EC_OK, NM_setDevicePolicy(&ctx, DEV_UUID.c_str(), policy.c_str())); + EXPECT_EQ(EC_INTERNAL_ERROR, NM_setDevicePolicy(&ctx, DEV_UUID.c_str(), policy.c_str())); + EXPECT_EQ(EC_NOT_INITIALIZED, NM_setDevicePolicy(&ctx, DEV_UUID.c_str(), policy.c_str())); +} + +/** + * @brief TEST for NM_shutdownDevice function + * 1. Call with nullptr instead of context + * 2. Call with nullptr instead of device uuid + * 3. Call with nullptr instead of parent device uuid + * 4. Call with good parameters + * 5. simulate NMexception throw + * 6. simulate std::exception throw + */ +TEST(Test_nmlibapi, NM_shutdownDevice) +{ + const char EMPTY_PARENT_UID[] = ""; + + OC::OCResource::Ptr resource = OC::OCPlatform::constructResourceObject( + FAKE_RESOURCE_HOST, + FAKE_RESOURCE_URI, + CT_DEFAULT, + true, + {FAKE_RESOURCE_TYPE}, + {OC::DEFAULT_INTERFACE}); + + NM_Context ctx; + IoTivityMock iot; + SecurityContext sec(&iot); + IotResourceClientMock dev_ctrl(resource); + shared_ptr ctrl_ptr{&dev_ctrl, [](IotResourceClient*){}}; + ctx.context = &sec; + ctx.instance = &iot; + OC::QueryParamsMap empty_query; + OC::OCRepresentation cmd_rep; + cmd_rep.setValue("command", int(DeviceCommands::SHUTDOWN)); + cmd_rep.setValue("duid", std::string{DEV_UUID}); + + EXPECT_CALL(iot, host()).WillRepeatedly(ReturnRef(FAKE_RESOURCE_HOST)); + EXPECT_CALL(iot, createResourceClient(StrEq(FAKE_RESOURCE_HOST), DeviceControl::CTRL_RESOURCE_TYPE, DEV_PARENT_UUID)) + .Times(2) + .WillRepeatedly(Return(ctrl_ptr)); + EXPECT_CALL(iot, createResourceClient(StrEq(FAKE_RESOURCE_HOST), DeviceControl::CTRL_RESOURCE_TYPE, DEV_UUID)) + .WillOnce(Return(ctrl_ptr)); + EXPECT_CALL(dev_ctrl, post(Eq(cmd_rep), Eq(empty_query))) + .WillOnce(Return(OC_STACK_OK)) + .WillOnce(Throw(NMexception("ex1", EC_UNAUTHORIZED))) + .WillOnce(Throw(std::logic_error("ex2"))); + + EXPECT_EQ(EC_NULL_POINTER, NM_shutdownDevice(nullptr, DEV_UUID.c_str(), DEV_PARENT_UUID.c_str())); + EXPECT_EQ(EC_NULL_POINTER, NM_shutdownDevice(&ctx, nullptr, DEV_PARENT_UUID.c_str())); + EXPECT_EQ(EC_NULL_POINTER, NM_shutdownDevice(&ctx, DEV_UUID.c_str(), nullptr)); + + EXPECT_EQ(EC_OK, NM_shutdownDevice(&ctx, DEV_UUID.c_str(), DEV_PARENT_UUID.c_str())); + EXPECT_EQ(EC_UNAUTHORIZED, NM_shutdownDevice(&ctx, DEV_UUID.c_str(), DEV_PARENT_UUID.c_str())); + EXPECT_EQ(EC_INTERNAL_ERROR, NM_shutdownDevice(&ctx, DEV_UUID.c_str(), "")); +} + +/** + * @brief Notification stub + * @param data [in] not used + * @param user_data [in] not used + */ +void NM_NotificationStub(NM_NotificationData data, void* user_data) +{ +} + +/** + * @brief TEST for NM_subscribeNotifications NM_unsubscribeNotifications function + * 1. simulate subscribe thows NMexception + * 2. simulate subscribe thows std::exception + * 3. Normal call + * 4. simulate unsubscribe thows NMexception + * 5. simulate unsubscribe thows std::exception + * 6. Normal call + */ +TEST(Test_nmlibapi, NM_unsubscribeNotifications) +{ + NM_Context ctx; + IoTivityMock iot; + SecurityContext sec(&iot); + MqClientMock mqclient; + ctx.context = &sec; + ctx.instance = &iot; + std::string topic = "/" + CLOUD_AUTH_ID + "/notification"; + + EXPECT_CALL(iot, getMqHandler()).WillRepeatedly(Return(&mqclient)); + EXPECT_CALL(iot, isSignedIn()).WillRepeatedly(Return(true)); + EXPECT_CALL(iot, getCloudAuthId()).WillRepeatedly(ReturnRef(CLOUD_AUTH_ID)); + EXPECT_CALL(mqclient, subscribe(Eq(topic), _)) + .WillOnce(Throw(NMexception("ex1", EC_UNAUTHORIZED))) + .WillOnce(Throw(std::logic_error("ex2"))) + .WillOnce(Return()); + EXPECT_CALL(mqclient, unsubscribe(Eq(topic))) + .WillOnce(Throw(NMexception("ex1", EC_UNAUTHORIZED))) + .WillOnce(Throw(std::logic_error("ex2"))) + .WillOnce(Return()); + + EXPECT_EQ(EC_UNAUTHORIZED, NM_subscribeNotifications(&ctx, NM_NotificationStub, nullptr)); + EXPECT_EQ(EC_INTERNAL_ERROR, NM_subscribeNotifications(&ctx, NM_NotificationStub, nullptr)); + EXPECT_EQ(EC_OK, NM_subscribeNotifications(&ctx, NM_NotificationStub, nullptr)); + + EXPECT_NO_THROW(NM_unsubscribeNotifications(&ctx)); + EXPECT_NO_THROW(NM_unsubscribeNotifications(&ctx)); + EXPECT_NO_THROW(NM_unsubscribeNotifications(&ctx)); +} diff --git a/device_core/utest/test_policyhandlerres.cpp b/device_core/utest/test_policyhandlerres.cpp index 2b295eb..f73b254 100644 --- a/device_core/utest/test_policyhandlerres.cpp +++ b/device_core/utest/test_policyhandlerres.cpp @@ -12,9 +12,9 @@ using ::testing::Matcher; namespace { -const std::string RESOURCE_HOST{"coap://192.168.1.2:5000"}; -const std::string RESOURCE_URI{"/resource"}; -const std::string RESOURCE_TYPE{"core.policy"}; +const std::string FAKE_RESOURCE_HOST{"coap://192.168.1.2:5000"}; +const std::string FAKE_RESOURCE_URI{"/resource"}; +const std::string FAKE_RESOURCE_TYPE{"core.policy"}; const std::string DEVICE_ID{"this-device-id"}; } @@ -38,18 +38,18 @@ TEST(Test_PolicyHandlerRes, pass) OC::QueryParamsMap test_params{{"param", "value"}}; auto resource_stub = OC::OCPlatform::constructResourceObject( - RESOURCE_HOST, - RESOURCE_URI, + FAKE_RESOURCE_HOST, + FAKE_RESOURCE_URI, CT_DEFAULT, true, - {RESOURCE_TYPE}, + {FAKE_RESOURCE_TYPE}, {OC::DEFAULT_INTERFACE}); - EXPECT_CALL(iotivity, host()).WillOnce(ReturnRef(RESOURCE_HOST)); + EXPECT_CALL(iotivity, host()).WillOnce(ReturnRef(FAKE_RESOURCE_HOST)); EXPECT_CALL(iotivity, getDeviceID()).WillOnce(ReturnRef(DEVICE_ID)); EXPECT_CALL(iotivity, findResource( - Matcher(StrEq(RESOURCE_HOST)), - Eq(RESOURCE_TYPE), + Matcher(StrEq(FAKE_RESOURCE_HOST)), + Eq(FAKE_RESOURCE_TYPE), Eq(OC_RSRVD_WELL_KNOWN_URI), Matcher(Eq(CT_DEFAULT)))) .WillOnce(Return(resource_stub)); diff --git a/device_core/utest/test_reporthandlerres.cpp b/device_core/utest/test_reporthandlerres.cpp index 59caac4..9f05fd5 100644 --- a/device_core/utest/test_reporthandlerres.cpp +++ b/device_core/utest/test_reporthandlerres.cpp @@ -12,9 +12,9 @@ using ::testing::Matcher; namespace { -const std::string RESOURCE_HOST{"coap://192.168.1.2:5000"}; -const std::string RESOURCE_URI{"/resource"}; -const std::string RESOURCE_TYPE{"core.security"}; +const std::string FAKE_RESOURCE_HOST{"coap://192.168.1.2:5000"}; +const std::string FAKE_RESOURCE_URI{"/resource"}; +const std::string FAKE_RESOURCE_TYPE{"core.security"}; } class ReportHandlerResMock: public ReportHandlerRes @@ -37,17 +37,17 @@ TEST(Test_ReportHandlerRes, pass) OC::QueryParamsMap test_params{{"param", "value"}}; auto resource_stub = OC::OCPlatform::constructResourceObject( - RESOURCE_HOST, - RESOURCE_URI, + FAKE_RESOURCE_HOST, + FAKE_RESOURCE_URI, CT_DEFAULT, true, - {RESOURCE_TYPE}, + {FAKE_RESOURCE_TYPE}, {OC::DEFAULT_INTERFACE}); - EXPECT_CALL(iotivity, host()).WillOnce(ReturnRef(RESOURCE_HOST)); + EXPECT_CALL(iotivity, host()).WillOnce(ReturnRef(FAKE_RESOURCE_HOST)); EXPECT_CALL(iotivity, findResource( - Matcher(StrEq(RESOURCE_HOST)), - Eq(RESOURCE_TYPE), + Matcher(StrEq(FAKE_RESOURCE_HOST)), + Eq(FAKE_RESOURCE_TYPE), Eq(OC_RSRVD_WELL_KNOWN_URI), Matcher(Eq(CT_DEFAULT)))) .WillOnce(Return(resource_stub)); -- 2.7.4