replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / resource-encapsulation / unittests / ResourceClientTest.cpp
index 5236eab..78e443d 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "UnitTestHelper.h"
 
+#include "OCResource.h"
+
 #include "RCSRemoteResourceObject.h"
 #include "RCSDiscoveryManager.h"
 #include "RCSResourceObject.h"
@@ -45,7 +47,7 @@ void getRemoteAttributesCallback(const RCSResourceAttributes&, int) {}
 void setRemoteAttributesCallback(const RCSResourceAttributes&, int) {}
 void setRemoteRepresentationCallback(const HeaderOpts&, const RCSRepresentation&, int) {}
 void resourceStateChanged(ResourceState) { }
-void cacheUpdatedCallback(const RCSResourceAttributes&) {}
+void cacheUpdatedCallback(const RCSResourceAttributes&, int) {}
 
 class RemoteResourceObjectTest: public TestWithMock
 {
@@ -162,7 +164,7 @@ TEST_F(RemoteResourceObjectTest, SetRemoteAttributesSetsAttributesOfServer)
     object->setRemoteAttributes(newAttrs, setRemoteAttributesCallback);
     Wait();
 
-    ASSERT_EQ(newValue, server->getAttributeValue(ATTR_KEY));
+    ASSERT_EQ(newValue, server->getAttributeValue(ATTR_KEY).get<int>());
 }
 
 TEST_F(RemoteResourceObjectTest, SetRemoteRepresentationDoesNotAllowEmptyFunction)
@@ -188,7 +190,7 @@ TEST_F(RemoteResourceObjectTest, SetRemoteRepresentationSetsRepresentationOfServ
     object->set(queryParams, rcsRep, setRemoteRepresentationCallback);
     Wait();
 
-    ASSERT_EQ(newValue, server->getAttributeValue(ATTR_KEY));
+    ASSERT_EQ(newValue, server->getAttributeValue(ATTR_KEY).get<int>());
 }
 
 TEST_F(RemoteResourceObjectTest, QueryParamsForGetWillBePassedToBase)
@@ -292,7 +294,7 @@ TEST_F(RemoteResourceObjectTest, CacheStateIsUnreadyAfterStartCaching)
 TEST_F(RemoteResourceObjectTest, CacheStateIsReadyAfterCacheUpdated)
 {
     mocks.ExpectCallFunc(cacheUpdatedCallback).
-                Do([this](const RCSResourceAttributes&){ Proceed(); });
+                Do([this](const RCSResourceAttributes&, int){ Proceed(); });
 
     object->startCaching(cacheUpdatedCallback);
     Wait();
@@ -303,7 +305,7 @@ TEST_F(RemoteResourceObjectTest, CacheStateIsReadyAfterCacheUpdated)
 TEST_F(RemoteResourceObjectTest, IsCachedAvailableReturnsTrueWhenCacheIsReady)
 {
     mocks.ExpectCallFunc(cacheUpdatedCallback).
-                Do([this](const RCSResourceAttributes&){ Proceed(); });
+                Do([this](const RCSResourceAttributes&, int){ Proceed(); });
 
     object->startCaching(cacheUpdatedCallback);
     Wait();
@@ -314,12 +316,12 @@ TEST_F(RemoteResourceObjectTest, IsCachedAvailableReturnsTrueWhenCacheIsReady)
 TEST_F(RemoteResourceObjectTest, DISABLED_CacheUpdatedCallbackBeCalledWheneverCacheUpdated)
 {
     mocks.OnCallFunc(cacheUpdatedCallback).
-            Do([this](const RCSResourceAttributes&){ Proceed(); });
+            Do([this](const RCSResourceAttributes&, int){ Proceed(); });
     object->startCaching(cacheUpdatedCallback);
     Wait();
 
     mocks.ExpectCallFunc(cacheUpdatedCallback).
-            Do([this](const RCSResourceAttributes&){ Proceed(); });
+            Do([this](const RCSResourceAttributes&, int){ Proceed(); });
 
     server->setAttribute(ATTR_KEY, ATTR_VALUE + 1);
 
@@ -331,15 +333,15 @@ TEST_F(RemoteResourceObjectTest, DISABLED_CacheUpdatedCallbackBeCalledWithUpdate
     constexpr int newValue = ATTR_VALUE + 1;
 
     mocks.OnCallFunc(cacheUpdatedCallback).
-            Do([this](const RCSResourceAttributes&){ Proceed(); });
+            Do([this](const RCSResourceAttributes&, int){ Proceed(); });
     object->startCaching(cacheUpdatedCallback);
     Wait();
 
     mocks.ExpectCallFunc(cacheUpdatedCallback).
-            Match([this](const RCSResourceAttributes& attrs){
+            Match([this](const RCSResourceAttributes& attrs, int){
                 return attrs.at(ATTR_KEY) == newValue;
             }).
-            Do([this](const RCSResourceAttributes&){ Proceed(); });
+            Do([this](const RCSResourceAttributes&, int){ Proceed(); });
 
     server->setAttribute(ATTR_KEY, newValue);
 
@@ -354,7 +356,7 @@ TEST_F(RemoteResourceObjectTest, GetCachedAttributesThrowsIfCachingIsNotStarted)
 TEST_F(RemoteResourceObjectTest, CachedAttributesHasSameAttributesWithServer)
 {
     mocks.OnCallFunc(cacheUpdatedCallback).
-            Do([this](const RCSResourceAttributes&){ Proceed(); });
+            Do([this](const RCSResourceAttributes&, int){ Proceed(); });
     object->startCaching(cacheUpdatedCallback);
     Wait();
 
@@ -371,7 +373,7 @@ TEST_F(RemoteResourceObjectTest, GetCachedAttributeThrowsIfCachingIsNotStarted)
 TEST_F(RemoteResourceObjectTest, GetCachedAttributeThrowsIfKeyIsInvalid)
 {
     mocks.OnCallFunc(cacheUpdatedCallback).
-            Do([this](const RCSResourceAttributes&){ Proceed(); });
+            Do([this](const RCSResourceAttributes&, int){ Proceed(); });
     object->startCaching(cacheUpdatedCallback);
     Wait();
 
@@ -393,3 +395,12 @@ TEST_F(RemoteResourceObjectTest, HasSameInterfaceWithServer)
     EXPECT_EQ(RESOURCEINTERFACE, object->getInterfaces()[0]);
 }
 
+TEST_F(RemoteResourceObjectTest, GetValidOCResourceTest)
+{
+    std::shared_ptr<OC::OCResource> ocRes = RCSRemoteResourceObject::toOCResource(object);
+
+    EXPECT_NE(nullptr, ocRes);
+
+    EXPECT_EQ(RESOURCEURI, ocRes->uri());
+}
+