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 "OCResourceRequest.h"
25 #include "RequestObject.h"
26 #include "RCSRequest.h"
28 using namespace testing;
29 using namespace OIC::Service;
34 const RCSResourceAttributes &, int,
35 const RCSRequest &, RequestObject::Ptr) { }
38 class RequestObjectTest : public TestWithMock
41 ResourceEncapsulationTestSimulator::Ptr testObject;
42 RCSResourceObject::Ptr server;
43 RCSRemoteResourceObject::Ptr remoteObject;
45 RCSResourceAttributes attr;
47 std::mutex mutexForCondition;
48 std::condition_variable responseCon;
54 TestWithMock::SetUp();
56 testObject = std::make_shared<ResourceEncapsulationTestSimulator>();
57 testObject->defaultRunSimulator();
58 remoteObject = testObject->getRemoteResource();
63 TestWithMock::TearDown();
66 if(remoteObject->isCaching())
68 remoteObject->stopCaching();
70 if(remoteObject->isMonitoring())
72 remoteObject->stopMonitoring();
75 testObject->destroy();
79 void waitForCondition(int waitingTime = 1000)
81 std::unique_lock< std::mutex > lock{ mutexForCondition };
82 responseCon.wait_for(lock, std::chrono::milliseconds{ waitingTime });
85 void notifyCondition()
87 responseCon.notify_all();
91 TEST_F(RequestObjectTest, invokeRequestExpectCallwithSetter)
93 bool isCalled = false;
95 mocks.ExpectCallFunc(setRequestCB).Do(
96 [this, &isCalled](const RCSResourceAttributes &, int,
97 const RCSRequest &, RequestObject::Ptr)
103 RCSResourceAttributes att;
104 std::shared_ptr<OC::OCResourceRequest> request;
105 RequestObject::invokeRequest(remoteObject, RCSRequest(testObject->getResourceServer(), request),
106 RequestObject::RequestMethod::Set, att, setRequestCB);
110 ASSERT_TRUE(isCalled);