1 //******************************************************************
3 // Copyright 2016 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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 #include <condition_variable>
24 #include "RemoteSceneList.h"
25 #include "UnitTestHelper.h"
26 #include "SceneCommons.h"
27 #include "SceneList.h"
28 #include "RCSRemoteResourceObject.h"
29 #include "OCPlatform.h"
30 #include "RCSDiscoveryManager.h"
31 #include "RCSAddress.h"
34 using namespace OIC::Service;
37 constexpr int DEFAULT_WAITTIME = 2000;
39 SceneList* g_sceneList = SceneList::getInstance();
40 RCSRemoteResourceObject::Ptr pListResource = nullptr;
41 RemoteSceneList::Ptr pSceneList = nullptr;
43 void discoverSceneListServer()
45 if(pListResource == nullptr)
47 std::vector< std::string > vecRT{ SCENE_LIST_RT };
48 std::vector< std::string > vecIF{ OC_RSRVD_INTERFACE_DEFAULT, OC::BATCH_INTERFACE };
50 pListResource = SceneUtils::createRCSResourceObject(
51 "coap://" + SceneUtils::getNetAddress() + SCENE_LIST_URI,
52 SCENE_CONNECTIVITY, vecRT, vecIF);
56 class RemoteSceneListTest : public TestWithMock
61 TestWithMock::SetUp();
62 g_sceneList->getName();
65 void waitForCallback(int waitingTime = DEFAULT_WAITTIME)
67 std::unique_lock< std::mutex > lock{ mutex };
68 cond.wait_for(lock, std::chrono::milliseconds{ waitingTime });
72 std::condition_variable cond;
75 void onRemoteSceneListCreated(RemoteSceneList::Ptr remoteSceneList, int)
77 pSceneList = std::move(remoteSceneList);
87 TEST_F(RemoteSceneListTest, createRemoteSceneListInstance)
89 discoverSceneListServer();
90 if(pSceneList == nullptr)
92 RemoteSceneList::createInstance(pListResource, std::bind(
93 &RemoteSceneListTest::onRemoteSceneListCreated, this,
94 placeholders::_1, placeholders::_2));
99 EXPECT_NE(nullptr, pSceneList);
102 TEST_F(RemoteSceneListTest, setAndGetRemoteSceneListName)
104 discoverSceneListServer();
105 if(pSceneList == nullptr)
107 RemoteSceneList::createInstance(pListResource, std::bind(
108 &RemoteSceneListTest::onRemoteSceneListCreated, this,
109 placeholders::_1, placeholders::_2));
114 pSceneList->setName("Test Scene List", std::bind(
115 &RemoteSceneListTest::onSetName, this, placeholders::_1));
119 EXPECT_EQ("Test Scene List", pSceneList->getName());