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"
26 #include "UnitTestHelper.h"
27 #include "SceneCommons.h"
28 #include "SceneList.h"
29 #include "RCSResourceObject.h"
30 #include "RCSRemoteResourceObject.h"
31 #include "OCPlatform.h"
34 using namespace OIC::Service;
37 constexpr int DEFAULT_WAITTIME = 2000;
39 class RemoteSceneCollectionTest : public TestWithMock
44 TestWithMock::SetUp();
46 SceneList::getInstance()->getName();
49 RemoteSceneList::createInstance(pListResource, std::bind(
50 &RemoteSceneCollectionTest::onRemoteSceneListCreated, this,
51 placeholders::_1, placeholders::_2));
56 void createListServer()
58 std::vector< std::string > vecRT{ SCENE_LIST_RT };
59 std::vector< std::string > vecIF{ OC_RSRVD_INTERFACE_DEFAULT, OC::BATCH_INTERFACE };
61 pListResource = SceneUtils::createRCSResourceObject(
62 "coap://" + SceneUtils::getNetAddress() + SCENE_LIST_URI,
63 SCENE_CONNECTIVITY, vecRT, vecIF);
66 void waitForCallback(int waitingTime = DEFAULT_WAITTIME)
68 std::unique_lock< std::mutex > lock{ mutex };
69 cond.wait_for(lock, std::chrono::milliseconds{ waitingTime });
73 RCSRemoteResourceObject::Ptr pListResource;
74 RemoteSceneList::Ptr pSceneList;
75 RemoteSceneCollection::Ptr pSceneCollection;
76 std::condition_variable cond;
79 void onRemoteSceneListCreated(RemoteSceneList::Ptr remoteSceneList, int)
81 pSceneList = std::move(remoteSceneList);
85 void onRemoteSceneCollectionCreated(RemoteSceneCollection::Ptr remoteSceneCol, int)
87 pSceneCollection = remoteSceneCol;
91 void onRemoteSceneCreated(RemoteScene::Ptr, int)
102 TEST_F(RemoteSceneCollectionTest, addNewRemoteSceneCollection)
104 pSceneList->addNewSceneCollection(std::bind(
105 &RemoteSceneCollectionTest::onRemoteSceneCollectionCreated, this,
106 placeholders::_1, placeholders::_2));
110 pSceneCollection->addNewScene("Default", std::bind(
111 &RemoteSceneCollectionTest::onRemoteSceneCreated, this,
112 placeholders::_1, placeholders::_2));
116 EXPECT_NE(nullptr, pSceneCollection);
119 TEST_F(RemoteSceneCollectionTest, getRemoteSceneCollectionList)
121 std::vector< RemoteSceneCollection::Ptr > sceneCollections
122 = pSceneList->getRemoteSceneCollections();
124 bool getCollectionsOK = true;
126 if (!sceneCollections.empty())
128 for (const auto &it : sceneCollections)
130 if (it->getId() == "")
132 getCollectionsOK = false;
139 getCollectionsOK = false;
142 ASSERT_TRUE(getCollectionsOK);
145 TEST_F(RemoteSceneCollectionTest, setAndGetSceneCollectionName)
147 pSceneList->addNewSceneCollection(std::bind(
148 &RemoteSceneCollectionTest::onRemoteSceneCollectionCreated, this,
149 placeholders::_1, placeholders::_2));
153 pSceneCollection->addNewScene("Default", std::bind(
154 &RemoteSceneCollectionTest::onRemoteSceneCreated, this,
155 placeholders::_1, placeholders::_2));
159 pSceneCollection->setName("Kitchen", std::bind(
160 &RemoteSceneCollectionTest::onSetName, this, placeholders::_1));
164 EXPECT_EQ("Kitchen", pSceneCollection->getName());