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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "UnitTestHelper.h"
23 #include "ResourceEncapsulationTestSimulator.h"
24 #include "RequestObject.h"
26 using namespace testing;
27 using namespace OIC::Service;
31 void setRequestCB(const RCSResourceAttributes &, RCSResourceAttributes &) { }
34 class RequestObjectTest : public TestWithMock
37 ResourceEncapsulationTestSimulator::Ptr testObject;
38 RCSResourceObject::Ptr server;
39 RCSRemoteResourceObject::Ptr remoteObject;
41 RCSResourceAttributes attr;
43 std::mutex mutexForCondition;
44 std::condition_variable responseCon;
50 TestWithMock::SetUp();
52 testObject = std::make_shared<ResourceEncapsulationTestSimulator>();
53 testObject->defaultRunSimulator();
54 remoteObject = testObject->getRemoteResource();
59 TestWithMock::TearDown();
62 if(remoteObject->isCaching())
64 remoteObject->stopCaching();
66 if(remoteObject->isMonitoring())
68 remoteObject->stopMonitoring();
71 testObject->destroy();
75 void waitForCondition(int waitingTime = 1000)
77 std::unique_lock< std::mutex > lock{ mutexForCondition };
78 responseCon.wait_for(lock, std::chrono::milliseconds{ waitingTime });
81 void notifyCondition()
83 responseCon.notify_all();
87 TEST_F(RequestObjectTest, invokeRequestExpectCallwithSetter)
89 bool isCalled = false;
90 RequestObject::Ptr instance = std::make_shared<RequestObject>(setRequestCB);
92 mocks.ExpectCallFunc(setRequestCB).Do(
93 [this, &isCalled](const RCSResourceAttributes &, RCSResourceAttributes &)
99 RCSResourceAttributes att;
100 instance->invokeRequest(remoteObject, RequestObject::RequestMethod::Setter, att);
104 ASSERT_TRUE(isCalled);