Merge test folder of test branch
[iotivity.git] / test / src / tc / sm / gtest / src / stc / SMRemoteSceneListIntegrationTest.cpp
1 /******************************************************************
2 *
3 * Copyright 2016 Samsung Electronics All Rights Reserved.
4 *
5 *
6 *
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
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
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.
18 *
19 ******************************************************************/
20
21 #include "SMRemoteHelper.h"
22
23 class SMRemoteSceneListIntegrationTest_stc: public ::testing::Test {
24 public:
25     SMRemoteHelper* m_pSMRemoteHelper;
26     std::shared_ptr<RemoteSceneList> m_pRemoteSceneList;
27     std::shared_ptr<RemoteSceneCollection> m_pRemoteSceneCollection;
28     bool m_IsCallback;
29
30     SMRemoteSceneListIntegrationTest_stc() {
31         m_pSMRemoteHelper = nullptr;
32         m_pRemoteSceneList = nullptr;
33         m_pRemoteSceneCollection = nullptr;
34         m_IsCallback = false;
35     }
36
37     virtual void SetUp() {
38         IOTIVITYTEST_LOG(INFO, "SetUp IN");
39
40         CommonTestUtil::runCommonTCSetUpPart();
41
42         CommonUtil::launchApp(SCENE_SERVER);
43         CommonUtil::waitInSecond(MAX_SLEEP_TIME);
44
45         m_pSMRemoteHelper = new SMRemoteHelper();
46         m_pSMRemoteHelper->discoverResource();
47         m_pSMRemoteHelper->stopDiscovery();
48
49         ASSERT_NE(NULL_PTR,m_pSMRemoteHelper->g_pFoundSceneList) << "Local scene List resource was not found in discovery";
50     }
51
52     virtual void TearDown() {
53         IOTIVITYTEST_LOG(INFO, "TearDown IN");
54
55         CommonTestUtil::runCommonTCTearDownPart();
56
57         CommonUtil::killApp(SCENE_SERVER);
58         CommonUtil::waitInSecond(MAX_SLEEP_TIME);
59
60         delete m_pSMRemoteHelper;
61         m_pSMRemoteHelper = nullptr;
62     }
63
64 public:
65     void onRemoteSceneListCreated(RemoteSceneList::Ptr remoteSceneList, int eCode) {
66         IOTIVITYTEST_LOG(INFO, "%s is called with error code: %d", __func__, eCode);
67
68         if (eCode == SCENE_RESULT_OK) {
69             m_pRemoteSceneList = std::move(remoteSceneList);
70             m_IsCallback = true;
71         } else {
72             IOTIVITYTEST_LOG(INFO, "Create Remote list failed.");
73         }
74     }
75
76     void onRemoteSceneCollectionCreated(
77             RemoteSceneCollection::Ptr remoteSceneCol, int eCode) {
78         IOTIVITYTEST_LOG(INFO, "%s is called with error code: %d", __func__, eCode);
79
80         if (eCode == SCENE_RESULT_OK) {
81             m_pRemoteSceneCollection = remoteSceneCol;
82             m_IsCallback = true;
83         } else {
84             IOTIVITYTEST_LOG(INFO, "Create Remote scene collection failed.");
85         }
86     }
87
88     void onSetName(int eCode) {
89         IOTIVITYTEST_LOG(INFO, "%s is called with error code: %d", __func__, eCode);
90         if (eCode == SCENE_RESULT_OK) {
91             m_IsCallback = true;
92         }
93     }
94 };
95
96 /**
97  * @since 2016-02-29
98  * @see void Configure(const PlatformConfig& config);
99  * @see DiscoveryTask::Ptr discoverResourceByTypes(const RCSAddress& address,
100  *                  const std::vector< std::string >& resourceTypes,
101  *                  ResourceDiscoveredCallback cb);
102  * @objective Test createInstance function positively for checking if callback is called
103  * @target static void createInstance(RCSRemoteResourceObject::Ptr sceneListResource,
104  *             CreateInstanceCallback cb);
105  * @test_data         1. RCSRemoteResourceObject::Ptr RCSRemoteResourceObject pointer of SceneList
106  *                     2. CreateInstanceCallback A callback to create instance
107  * @pre_condition     1. Start SceneList type resource using SCENE_SERVER simulator
108  *                     2. discover resource
109  * @procedure call createInstance
110  * @post_condition none
111  * @expected callback will be called with proper error code and no exceptions occur
112  */
113 #if defined(__LINUX__)
114 TEST_F(SMRemoteSceneListIntegrationTest_stc, RemoteSceneListCreateInstance_CV_P)
115 {
116     try
117     {
118         RemoteSceneList::createInstance(m_pSMRemoteHelper->g_pFoundSceneList,std::bind(
119                         &SMRemoteSceneListIntegrationTest_stc::onRemoteSceneListCreated, this, placeholders::_1, placeholders::_2));
120         CommonUtil::waitInSecond(CALLBACK_WAIT_MAX);
121     }
122     catch (exception& e)
123     {
124         SET_FAILURE("Unexpected Exception occurred inside createInstance: " + std::string(e.what()));
125         return;
126     }
127
128     if(m_IsCallback == false)
129     {
130         SET_FAILURE("CreateInstanceCallback is not called with proper error code");
131     }
132 }
133 #endif
134
135 /**
136  * @since 2016-02-29
137  * @see void Configure(const PlatformConfig& config);
138  * @see DiscoveryTask::Ptr discoverResourceByTypes(const RCSAddress& address,
139  *                  const std::vector< std::string >& resourceTypes,
140  *                  ResourceDiscoveredCallback cb);
141  * @see static void createInstance(RCSRemoteResourceObject::Ptr sceneListResource,
142  *             CreateInstanceCallback cb);
143  * @objective Test addNewSceneCollection function positively for checking if callback is called
144  * @target void addNewSceneCollection(AddNewSceneCollectionCallback cb);
145  * @test_data AddNewSceneCollectionCallback A callback function to create remote scene collection
146  * @pre_condition     1. Start SceneList type resource using SCENE_SERVER simulator
147  *                     2. discover resource
148  *                     3. call createInstance method
149  * @procedure call addNewSceneCollection
150  * @post_condition none
151  * @expected callback will be called with proper error code and no exceptions occur
152  */
153 #if defined(__LINUX__)
154 TEST_F(SMRemoteSceneListIntegrationTest_stc, RemoteAddNewSceneCollection_CV_P)
155 {
156     m_pRemoteSceneList = m_pSMRemoteHelper->createRemoteSceneListInstance();
157
158     if(m_pRemoteSceneList == NULL_PTR)
159     {
160         SET_FAILURE("did not find remote scene list instance");
161         return;
162     }
163
164     try
165     {
166         m_pRemoteSceneList->addNewSceneCollection(std::bind(
167                         &SMRemoteSceneListIntegrationTest_stc::onRemoteSceneCollectionCreated, this, placeholders::_1, placeholders::_2));
168         CommonUtil::waitInSecond(CALLBACK_WAIT_MAX);
169         ASSERT_NE(m_pRemoteSceneCollection,NULL_PTR) << "remote scene collection is not added";
170     }
171     catch (exception& e)
172     {
173         SET_FAILURE("Exception occurred inside addNewSceneCollection: " + std::string(e.what()));
174         return;
175     }
176
177     if(m_IsCallback == false)
178     {
179         SET_FAILURE("AddNewSceneCollectionCallback is not called with proper error code");
180     }
181 }
182 #endif
183
184 /**
185  * @since 2016-02-29
186  * @see void Configure(const PlatformConfig& config);
187  * @see DiscoveryTask::Ptr discoverResourceByTypes(const RCSAddress& address,
188  *                  const std::vector< std::string >& resourceTypes,
189  *                  ResourceDiscoveredCallback cb);
190  * @see static void createInstance(RCSRemoteResourceObject::Ptr sceneListResource,
191  *             CreateInstanceCallback cb);
192  * @objective Test addNewSceneCollection and getSceneCollections functions positively for getting added list of SceneCollections
193  * @target void addNewSceneCollection(AddNewSceneCollectionCallback cb);
194  * @target std::vector< RemoteSceneCollection::Ptr > getRemoteSceneCollections() const;
195  * @test_data AddNewSceneCollectionCallback A callback function to create remote scene collection
196  * @pre_condition     1. Start SceneList type resource using SCENE_SERVER simulator
197  *                     2. discover resource
198  *                     3. call createInstance method
199  * @procedure         1. call addNewSceneCollection
200  *                     2. call getSceneCollections
201  * @post_condition none
202  * @expected getSceneCollections will return added scene collections and no exceptions occur
203  */
204 #if defined(__LINUX__)
205 TEST_F(SMRemoteSceneListIntegrationTest_stc, RemoteAddAndGetSceneCollections_GSRV_P)
206 {
207     m_pRemoteSceneList = m_pSMRemoteHelper->createRemoteSceneListInstance();
208
209     if(m_pRemoteSceneList == NULL_PTR)
210     {
211         SET_FAILURE("did not find remote scene list instance");
212         return;
213     }
214
215     std::vector<RemoteSceneCollection::Ptr> remoteSceneCollections;
216
217     try
218     {
219         m_pRemoteSceneList->addNewSceneCollection(std::bind(
220                         &SMRemoteSceneListIntegrationTest_stc::onRemoteSceneCollectionCreated, this, placeholders::_1, placeholders::_2));
221         CommonUtil::waitInSecond(CALLBACK_WAIT_MAX);
222         ASSERT_NE(m_pRemoteSceneCollection,NULL_PTR) << "remote scene collection is not added";
223
224         remoteSceneCollections = m_pRemoteSceneList->getRemoteSceneCollections();
225
226         if(remoteSceneCollections.size() == INT_ZERO)
227         {
228             SET_FAILURE("list of remote scene collections is not found ");
229             return;
230         }
231
232         if(remoteSceneCollections.at(INT_ZERO) != m_pRemoteSceneCollection)
233         {
234             SET_FAILURE("set scene collection and received scene collection does not match");
235         }
236     }
237     catch (exception& e)
238     {
239         SET_FAILURE("Exception occurred: " + std::string(e.what()));
240     }
241 }
242 #endif
243
244 /**
245  * @since 2016-07-26
246  * @see void Configure(const PlatformConfig& config);
247  * @see DiscoveryTask::Ptr discoverResourceByTypes(const RCSAddress& address,
248  *                  const std::vector< std::string >& resourceTypes,
249  *                  ResourceDiscoveredCallback cb);
250  * @see static void createInstance(RCSRemoteResourceObject::Ptr sceneListResource,
251  *             CreateInstanceCallback cb);
252  * @objective Test getSceneCollections functions negatively without adding remote scene collections and check if no
253  *         remote scene collections is returned
254  * @target std::vector< RemoteSceneCollection::Ptr > getRemoteSceneCollections() const;
255  * @test_data none
256  * @pre_condition     1. Start SceneList type resource using SCENE_SERVER simulator
257  *                     2. discover resource
258  *                     3. call createInstance method
259  * @procedure call getSceneCollections
260  * @post_condition none
261  * @expected getSceneCollections will return empty list of scene collections and no exceptions occur
262  */
263 #if defined(__LINUX__)
264 TEST_F(SMRemoteSceneListIntegrationTest_stc, RemoteGetSceneCollectionsWithoutAddingRemoteSceneCollection_DSCC_N)
265 {
266     m_pRemoteSceneList = m_pSMRemoteHelper->createRemoteSceneListInstance();
267
268     if(m_pRemoteSceneList == NULL_PTR)
269     {
270         SET_FAILURE("did not find remote scene list instance");
271         return;
272     }
273
274     std::vector<RemoteSceneCollection::Ptr> remoteSceneCollections;
275
276     try
277     {
278         remoteSceneCollections = m_pRemoteSceneList->getRemoteSceneCollections();
279
280         if(remoteSceneCollections.size() != INT_ZERO)
281         {
282             SET_FAILURE("list of remote scene collections should be empty");
283             return;
284         }
285     }
286     catch (exception& e)
287     {
288         SET_FAILURE("Exception occurred inside getRemoteSceneCollections: " + std::string(e.what()));
289     }
290 }
291 #endif
292
293 /**
294  * @since 2016-02-29
295  * @see void Configure(const PlatformConfig& config);
296  * @see DiscoveryTask::Ptr discoverResourceByTypes(const RCSAddress& address,
297  *                  const std::vector< std::string >& resourceTypes,
298  *                  ResourceDiscoveredCallback cb);
299  * @see static void createInstance(RCSRemoteResourceObject::Ptr sceneListResource,
300  *             CreateInstanceCallback cb);
301  * @objective Test setName function positively for checking if callback is called
302  * @target void setName(const std::string &name, SetNameCallback cb);
303  * @test_data         1. name = "Home"
304  *                     2. SetNameCallback A callback to receive the response
305  * @pre_condition     1. Start SceneList type resource using SCENE_SERVER simulator
306  *                     2. discover resource
307  *                     3. call createInstance method
308  * @procedure call setName
309  * @post_condition none
310  * @expected callback will be called with proper error code and no exceptions occur
311  */
312 #if defined(__LINUX__)
313 TEST_F(SMRemoteSceneListIntegrationTest_stc, RemoteSceneListSetName_CV_P)
314 {
315     m_pRemoteSceneList = m_pSMRemoteHelper->createRemoteSceneListInstance();
316
317     if(m_pRemoteSceneList == NULL_PTR)
318     {
319         SET_FAILURE("did not find remote scene list instance");
320         return;
321     }
322
323     try
324     {
325         m_pRemoteSceneList->setName(REMOTE_SCENE_LIST_NAME,std::bind(&SMRemoteSceneListIntegrationTest_stc::onSetName, this, placeholders::_1));
326         CommonUtil::waitInSecond(CALLBACK_WAIT_MAX);
327     }
328     catch (exception& e)
329     {
330         SET_FAILURE("Exception occurred inside setName: " + std::string(e.what()));
331         return;
332     }
333
334     if(m_IsCallback == false)
335     {
336         SET_FAILURE("SetNameCallback is not called with proper error code");
337     }
338 }
339 #endif
340
341 /**
342  * @since 2016-02-29
343  * @see void Configure(const PlatformConfig& config);
344  * @see DiscoveryTask::Ptr discoverResourceByTypes(const RCSAddress& address,
345  *                  const std::vector< std::string >& resourceTypes,
346  *                  ResourceDiscoveredCallback cb);
347  * @see static void createInstance(RCSRemoteResourceObject::Ptr sceneListResource,
348  *             CreateInstanceCallback cb);
349  * @objective Test setName and getName function positively  to check if set name is received
350  * @target void setName(const std::string &name, SetNameCallback cb);
351  * @target std::string getName() const;
352  * @test_data         1. name = "Home"
353  *                     2. SetNameCallback A callback to receive the response
354  * @pre_condition     1. Start SceneList type resource using SCENE_SERVER simulator
355  *                     2. discover resource
356  *                     3. call createInstance method
357  * @procedure        1. call setName
358  *                     2. call getName
359  * @post_condition none
360  * @expected getName will return same as the setName and no exceptions occur
361  */
362 #if defined(__LINUX__)
363 TEST_F(SMRemoteSceneListIntegrationTest_stc, RemoteSceneListSetAndGetName_GSRV_P)
364 {
365     m_pRemoteSceneList = m_pSMRemoteHelper->createRemoteSceneListInstance();
366
367     if(m_pRemoteSceneList == NULL_PTR)
368     {
369         SET_FAILURE("did not find remote scene list instance");
370         return;
371     }
372
373     std::string receivedName="";
374
375     try
376     {
377         m_pRemoteSceneList->setName(REMOTE_SCENE_LIST_NAME,std::bind(&SMRemoteSceneListIntegrationTest_stc::onSetName, this, placeholders::_1));
378         CommonUtil::waitInSecond(CALLBACK_WAIT_MAX);
379         receivedName = m_pRemoteSceneList->getName();
380     }
381     catch (exception& e)
382     {
383         SET_FAILURE("Exception occurred: " + std::string(e.what()));
384         return;
385     }
386
387     if(receivedName != REMOTE_SCENE_LIST_NAME)
388     {
389         SET_FAILURE("setName and getName does not match");
390     }
391 }
392 #endif
393
394 /**
395  * @since 2016-07-27
396  * @see void Configure(const PlatformConfig& config);
397  * @see DiscoveryTask::Ptr discoverResourceByTypes(const RCSAddress& address,
398  *                  const std::vector< std::string >& resourceTypes,
399  *                  ResourceDiscoveredCallback cb);
400  * @see static void createInstance(RCSRemoteResourceObject::Ptr sceneListResource,
401  *             CreateInstanceCallback cb);
402  * @objective Test getName function negatively to check if getName returns default
403  *         remote scenelist name
404  * @target std::string getName() const;
405  * @test_data none
406  * @pre_condition     1. Start SceneList type resource using SCENE_SERVER simulator
407  *                     2. discover resource
408  *                     3. call createInstance method
409  * @procedure call getName
410  * @post_condition none
411  * @expected getName will return default remote scenelist name and no exceptions occur
412  */
413 #if defined(__LINUX__)
414 TEST_F(SMRemoteSceneListIntegrationTest_stc, RemoteSceneListGetNameWithoutSettingName_DSCC_N)
415 {
416     m_pRemoteSceneList = m_pSMRemoteHelper->createRemoteSceneListInstance();
417
418     if(m_pRemoteSceneList == NULL_PTR)
419     {
420         SET_FAILURE("did not find remote scene list instance");
421         return;
422     }
423
424     std::string receivedName="";
425
426     try
427     {
428         receivedName = m_pRemoteSceneList->getName();
429     }
430     catch (exception& e)
431     {
432         SET_FAILURE("Exception occurred inside getName: " + std::string(e.what()));
433         return;
434     }
435
436     const std::string defaultRemoteSceneListName = "Home";
437     if(receivedName != defaultRemoteSceneListName)
438     {
439         SET_FAILURE("getName does not return default remote scene list name");
440     }
441 }
442 #endif