1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
23 #include "gtest/gtest.h"
24 #include "HippoMocks/hippomocks.h"
26 #include "OCPlatform.h"
28 #include "DevicePresence.h"
29 #include "DeviceAssociation.h"
30 #include "ResourcePresence.h"
31 #include "PrimitiveResource.h"
32 #include "ResponseStatement.h"
33 #include "UnitTestHelper.h"
35 using namespace testing;
36 using namespace OIC::Service;
39 #define STRING_VALUE "10.242.34.235"
41 typedef OCStackResult (*subscribePresenceSig1)(OC::OCPlatform::OCPresenceHandle&,
42 const std::string&, OCConnectivityType, SubscribeCallback);
44 class DeviceAssociationTest : public TestWithMock
48 DeviceAssociation * instance;
49 DevicePresencePtr device;
50 PrimitiveResource::Ptr pResource;
55 mocks.OnCall(pResource.get(), PrimitiveResource::requestGet);
56 mocks.OnCall(pResource.get(), PrimitiveResource::getHost).Return(STRING_VALUE);
57 mocks.OnCallFuncOverload(static_cast< subscribePresenceSig1 >(OC::OCPlatform::subscribePresence)).Return(OC_STACK_OK);
60 void SetAssociationDevice()
63 device->initializeDevicePresence(pResource);
64 instance->addDevice(device);
69 TestWithMock::SetUp();
70 instance = DeviceAssociation::getInstance();
71 device = (DevicePresencePtr)new DevicePresence();
72 pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), [](PrimitiveResource*){});
77 TestWithMock::TearDown();
84 TEST_F(DeviceAssociationTest,findDevice_ReturnNormalValueIfNormalParam)
87 SetAssociationDevice();
88 ASSERT_NE(nullptr,instance->findDevice(pResource->getHost()));
93 TEST_F(DeviceAssociationTest,addDevice_NormalHandlingIfNormalParam)
96 SetAssociationDevice();
97 ASSERT_FALSE(instance->isEmptyDeviceList());
100 TEST_F(DeviceAssociationTest,removeDevice_NormalHandlingIfNormalParam)
103 SetAssociationDevice();
104 instance->removeDevice(device);
105 ASSERT_TRUE(instance->isEmptyDeviceList());