Merge test folder of test branch
[iotivity.git] / test / src / tc / ns / gtest / cpp / src / stc / NSCppScenarioTest.cpp
1 //******************************************************************\r
2 //\r
3 // Copyright 2018 Samsung Electronics All Rights Reserved.\r
4 //\r
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
6 //\r
7 // Licensed under the Apache License, Version 2.0 (the "License");\r
8 // you may not use this file except in compliance with the License.\r
9 // You may obtain a copy of the License at\r
10 //\r
11 //      http://www.apache.org/licenses/LICENSE-2.0\r
12 //\r
13 // Unless required by applicable law or agreed to in writing, software\r
14 // distributed under the License is distributed on an "AS IS" BASIS,\r
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16 // See the License for the specific language governing permissions and\r
17 // limitations under the License.\r
18 //\r
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
20 \r
21 #include "NSCppHelper.h"\r
22 #include "NSCppUtility.h"\r
23 using namespace std;\r
24 \r
25 class NSCppTest_stc: public ::testing::Test\r
26 {\r
27 protected:\r
28 \r
29     NSCppHelper* m_pNSHelper;\r
30     string m_testAppLog;\r
31 \r
32     virtual void SetUp()\r
33     {\r
34         CommonTestUtil::runCommonTCSetUpPart();\r
35 \r
36         m_pNSHelper = NSCppHelper::getInstance();\r
37         m_pNSHelper->preConfigure();\r
38 \r
39         m_testAppLog = "";\r
40     }\r
41 \r
42     virtual void TearDown()\r
43     {\r
44         m_pNSHelper->stopServices();\r
45     }\r
46 };\r
47 \r
48 /**\r
49  * @since 2017-03-16\r
50  * @see int start(OnConsumerSubscribedListener subscribedListener,\r
51  *      OnMessageSynchronizedListener messageSynchronized, boolean\r
52  *      subControllability, String userInfo, boolean resourceSecurity)\r
53  * @see int stop()\r
54  * @see OIC::Service::NSMessage createMessage()\r
55  * @see int registerTopic(String topicName)\r
56  * @see int setTopic(String topicName)\r
57  * @see void start(OnProviderDiscoveredListener onProviderDiscoveredListener)\r
58  * @objective Test Provider State Changed Listener callback\r
59  * @target OnProviderDiscoveredListener onProviderDiscoveredListener\r
60  * @test_data None\r
61  * @pre_condition 1. Get Provider Service Instance\r
62  *                2. Start Provider with Provider acceptor\r
63  *                3. Get Consumer Service Instance\r
64  *                4. Start Consumer Service\r
65  *                5. Wait for OnConsumerSubscribedListener\r
66  *                6. Get shared_ptr<OIC::Service::NSConsumer> object from callback\r
67  *                7. Accept Subscription\r
68  * @procedure 1. Stop Provider Service\r
69  *            2. Check the callback for state provider change\r
70  * @post_condition Stop shared_ptr<OIC::Service::NSConsumer> Service\r
71  * @expected Should get the STOPPED state.\r
72  */\r
73 #if defined(__LINUX__) || defined(__TIZEN__)\r
74 TEST_F(NSCppTest_stc, ProviderStateChanged_SRC_P)\r
75 {\r
76     shared_ptr< OIC::Service::NSConsumer > consumer = m_pNSHelper->getLocalConsumer(true, false);\r
77 \r
78     ASSERT_NE(nullptr, consumer.get())<< "Consumer should not be null";\r
79 \r
80     try\r
81     {\r
82         consumer->acceptSubscription(true);\r
83     }\r
84     catch (OIC::Service::NSException &e)\r
85     {\r
86         FAIL()<< "Can't accept subscription";\r
87     }\r
88 \r
89     CommonUtil::waitInSecond(WAIT_TIME_DEFAULT);\r
90 \r
91     ASSERT_EQ(true, m_pNSHelper->stopProviderService())<< "Should stop provider service successfully";\r
92 \r
93     CommonUtil::waitInSecond(WAIT_TIME_MIN);\r
94 \r
95     OIC::Service::NSProviderState state = m_pNSHelper->getProviderState();\r
96     ASSERT_EQ(OIC::Service::NSProviderState::STOPPED, state)<< "Provider State should be stopped";\r
97 \r
98 }\r
99 #endif\r
100 \r
101 /**\r
102  * @since 2017-03-21\r
103  * @see int start(OnConsumerSubscribedListener subscribedListener,\r
104  *      OnMessageSynchronizedListener messageSynchronized, boolean\r
105  *      subControllability, String userInfo, boolean resourceSecurity)\r
106  * @see int stop()\r
107  * @see OIC::Service::NSMessage createMessage()\r
108  * @see int registerTopic(String topicName)\r
109  * @see int setTopic(String topicName)\r
110  * @see void start(OnProviderDiscoveredListener onProviderDiscoveredListener)\r
111  * @objective Test scenario based 'sendMessage' API functionality\r
112  * @target int sendMessage(OIC::Service::NSMessage message)\r
113  * @test_data OIC::Service::NSMessage\r
114  * @pre_condition 1. Get Provider Service Instance\r
115  *                2. Start Provider with Provider acceptor\r
116  *                3. Get shared_ptr<OIC::Service::NSConsumer> Service Instance\r
117  *                4. Start shared_ptr<OIC::Service::NSConsumer> Service\r
118  *                5. Wait for OnConsumerSubscribedListener\r
119  *                6. Get shared_ptr<OIC::Service::NSConsumer> object from callback\r
120  *                7. Accept Subscription\r
121  * @procedure 1. Register Topic\r
122  *            2. Set Same topic which is registered\r
123  *            3. Get OIC::Service::NSMessage instance with createMessage()\r
124  *            4. Set OIC::Service::NSMessage Title, Body, SourceName and the TopicName\r
125  *               and also the mediaContents\r
126  *            5. Perform sendMessage() API\r
127  *            6. Wait for onMessageReceived Listener\r
128  * @post_condition 1. Stop Provider Service\r
129  *                 2. Stop shared_ptr<OIC::Service::NSConsumer> Service\r
130  * @expected 1. No exception occurs\r
131  *           2. Should get the Notification in consumer side\r
132  */\r
133 #if defined(__LINUX__) || defined(__TIZEN__)\r
134 TEST_F(NSCppTest_stc, SendMessage_SRC_P)\r
135 {\r
136     shared_ptr< OIC::Service::NSConsumer > consumer = m_pNSHelper->getLocalConsumer(true, false);\r
137 \r
138     ASSERT_NE(nullptr, consumer.get())<< "Consumer should not be null";\r
139 \r
140     try\r
141     {\r
142         consumer->acceptSubscription(true);\r
143     }\r
144     catch (OIC::Service::NSException &e)\r
145     {\r
146         FAIL()<< "Can't accept subscription";\r
147     }\r
148 \r
149     CommonUtil::waitInSecond(WAIT_TIME_MIN);\r
150 \r
151     ASSERT_EQ(true, m_pNSHelper->sendNotification())<< "Can't send notification";\r
152 \r
153     CommonUtil::waitInSecond(WAIT_TIME_DEFAULT);\r
154 \r
155     ASSERT_NE("", m_pNSHelper->getNotification().getContentText())<< "Doesn't get any notification";\r
156 }\r
157 #endif\r
158 \r
159 /**\r
160  * @since 2017-03-21\r
161  * @see int start(OnConsumerSubscribedListener subscribedListener,\r
162  *      OnMessageSynchronizedListener messageSynchronized, boolean\r
163  *      subControllability, String userInfo, boolean resourceSecurity)\r
164  * @see int stop()\r
165  * @see OIC::Service::NSMessage createMessage()\r
166  * @see int registerTopic(String topicName)\r
167  * @see int setTopic(String topicName)\r
168  * @see void start(OnProviderDiscoveredListener onProviderDiscoveredListener)\r
169  * @objective Test scenario based 'sendMessage' API functionality\r
170  * @target int sendMessage(OIC::Service::NSMessage message)\r
171  * @test_data OIC::Service::NSMessage\r
172  * @pre_condition 1. Get Provider Service Instance\r
173  *                2. Start Provider with Provider acceptor\r
174  *                3. Get shared_ptr<OIC::Service::NSConsumer> Service Instance\r
175  *                4. Start shared_ptr<OIC::Service::NSConsumer> Service\r
176  *                5. Wait for OnConsumerSubscribedListener\r
177  *                6. Get shared_ptr<OIC::Service::NSConsumer> object from callback\r
178  *                7. Accept Subscription\r
179  * @procedure 1. Register Topic\r
180  *            2. Set Same topic which is registered\r
181  *            3. Get OIC::Service::NSMessage instance with createMessage()\r
182  *            4. Set OIC::Service::NSMessage Title, Body, SourceName and the TopicName and also the mediaContents\r
183  *            5. Perform sendMessage() API\r
184  *            6. Wait for onMessageReceived Listener\r
185  * @post_condition 1. Stop Provider Service\r
186  *                 2. Stop shared_ptr<OIC::Service::NSConsumer> Service\r
187  * @expected 1. No exception occurs\r
188  *           2. Should get the Notification in consumer side\r
189  *           3. Title, ContentText, SourceName and Topic should be same\r
190  */\r
191 #if defined(__LINUX__) || defined(__TIZEN__)\r
192 TEST_F(NSCppTest_stc, SendMessageAndVerifyMessage_SRC_P)\r
193 {\r
194     shared_ptr< OIC::Service::NSConsumer > consumer = m_pNSHelper->getLocalConsumer(true, false);\r
195 \r
196     ASSERT_NE(nullptr, consumer.get())<< "Consumer should not be null";\r
197 \r
198     try\r
199     {\r
200         consumer->acceptSubscription(true);\r
201     }\r
202     catch (OIC::Service::NSException &e)\r
203     {\r
204         FAIL()<< "Can't accept subscription";\r
205     }\r
206 \r
207     CommonUtil::waitInSecond(WAIT_TIME_MIN);\r
208 \r
209     ASSERT_EQ(true, m_pNSHelper->sendNotification())<< "Can't send notification";\r
210 \r
211     CommonUtil::waitInSecond(WAIT_TIME_DEFAULT);\r
212 \r
213     OIC::Service::NSMessage msg = m_pNSHelper->getNotification();\r
214 \r
215     ASSERT_NE("", msg.getContentText())<< "Doesn't get any notification";\r
216 \r
217     ASSERT_EQ(TITLE_TO_SET, msg.getTitle());\r
218     ASSERT_EQ(CONTENTTEXT_TO_SET, msg.getContentText());\r
219     ASSERT_EQ(SOURCE_NAME, msg.getSourceName());\r
220     ASSERT_EQ(TEST_TOPIC_1, msg.getTopic());\r
221 }\r
222 #endif\r
223 \r
224 /**\r
225  * @since 2017-03-21\r
226  * @see int start(OnConsumerSubscribedListener subscribedListener,\r
227  *      OnMessageSynchronizedListener messageSynchronized, boolean\r
228  *      subControllability, String userInfo, boolean resourceSecurity)\r
229  * @see int stop()\r
230  * @see OIC::Service::NSMessage createMessage()\r
231  * @see int registerTopic(String topicName)\r
232  * @see int setTopic(String topicName)\r
233  * @see void start(OnProviderDiscoveredListener onProviderDiscoveredListener)\r
234  * @objective Test scenario based 'sendMessage' API functionality\r
235  * @target int sendMessage(OIC::Service::NSMessage message)\r
236  * @test_data OIC::Service::NSSyncInfo::NSSyncType = READ\r
237  * @pre_condition 1. Get Provider Service Instance\r
238  *                2. Start Provider with Provider acceptor\r
239  *                3. Get shared_ptr<OIC::Service::NSConsumer> Service Instance\r
240  *                4. Start shared_ptr<OIC::Service::NSConsumer> Service\r
241  *                5. Wait for OnConsumerSubscribedListener\r
242  *                6. Get shared_ptr<OIC::Service::NSConsumer> object from callback\r
243  *                7. Accept Subscription\r
244  * @procedure 1. Register Topic\r
245  *            2. Set Same topic which is registered\r
246  *            3. Get OIC::Service::NSMessage instance with createMessage()\r
247  *            4. Set OIC::Service::NSMessage Title, Body, SourceName and the TopicName and also the mediaContents\r
248  *            5. Perform sendMessage() API\r
249  *            6. Wait for onMessageReceived Listener\r
250  *            7. Send OIC::Service::NSSyncInfo to Provider Service\r
251  *            8. Check the callback data\r
252  * @post_condition 1. Stop Provider Service\r
253  *                 2. Stop shared_ptr<OIC::Service::NSConsumer> Service\r
254  * @expected 1. No exception occurs\r
255  *           2. Should get the Notification in consumer side\r
256  *           3. Should get syncInfo in Provider side\r
257  */\r
258 #if defined(__LINUX__) || defined(__TIZEN__)\r
259 TEST_F(NSCppTest_stc, ConsumerServiceSendSyncInfoAsRead_SRC_P)\r
260 {\r
261     shared_ptr< OIC::Service::NSConsumer > consumer = m_pNSHelper->getLocalConsumer(true, false);\r
262 \r
263     ASSERT_NE(nullptr, consumer.get())<< "Consumer should not be null";\r
264 \r
265     try\r
266     {\r
267         consumer->acceptSubscription(true);\r
268     }\r
269     catch (OIC::Service::NSException &e)\r
270     {\r
271         FAIL()<< "Can't accept subscription";\r
272     }\r
273 \r
274     CommonUtil::waitInSecond(WAIT_TIME_MIN);\r
275 \r
276     ASSERT_EQ(true, m_pNSHelper->sendNotification())<< "Can't send notification";\r
277 \r
278     CommonUtil::waitInSecond(WAIT_TIME_DEFAULT);\r
279 \r
280     OIC::Service::NSMessage msg = m_pNSHelper->getNotification();\r
281 \r
282     ASSERT_NE("", msg.getContentText())<< "Doesn't get any notification";\r
283 \r
284     ASSERT_EQ(true, m_pNSHelper->sendSyncInfo(false,\r
285             OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ))<< "Send OIC::Service::NSSyncInfo failed";\r
286 \r
287     CommonUtil::waitInSecond(WAIT_TIME_DEFAULT);\r
288 \r
289     OIC::Service::NSSyncInfo syncInfo = m_pNSHelper->getSyncInfo(false);\r
290 \r
291     ASSERT_NE("" , syncInfo.getProviderId())<< "SyncInfo should not be null";\r
292     ASSERT_EQ(OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ,\r
293             syncInfo.getState())<< "Syc state must be READ";\r
294 }\r
295 #endif\r
296 \r
297 /**\r
298  * @since 2017-03-21\r
299  * @see int start(OnConsumerSubscribedListener subscribedListener,\r
300  *      OnMessageSynchronizedListener messageSynchronized, boolean\r
301  *      subControllability, String userInfo, boolean resourceSecurity)\r
302  * @see int stop()\r
303  * @see OIC::Service::NSMessage createMessage()\r
304  * @see int registerTopic(String topicName)\r
305  * @see int setTopic(String topicName)\r
306  * @see void start(OnProviderDiscoveredListener onProviderDiscoveredListener)\r
307  * @objective Test scenario based 'sendMessage' API functionality\r
308  * @target int sendMessage(OIC::Service::NSMessage message)\r
309  * @test_data OIC::Service::NSSyncInfo::NSSyncType = DELETED\r
310  * @pre_condition 1. Get Provider Service Instance\r
311  *                2. Start Provider with Provider acceptor\r
312  *                3. Get shared_ptr<OIC::Service::NSConsumer> Service Instance\r
313  *                4. Start shared_ptr<OIC::Service::NSConsumer> Service\r
314  *                5. Wait for OnConsumerSubscribedListener\r
315  *                6. Get shared_ptr<OIC::Service::NSConsumer> object from callback\r
316  *                7. Accept Subscription\r
317  * @procedure 1. Register Topic\r
318  *            2. Set Same topic which is registered\r
319  *            3. Get OIC::Service::NSMessage instance with createMessage()\r
320  *            4. Set OIC::Service::NSMessage Title, Body, SourceName and the TopicName and also the mediaContents\r
321  *            5. Perform sendMessage() API\r
322  *            6. Wait for onMessageReceived Listener\r
323  *            7. Send OIC::Service::NSSyncInfo to Provider Service\r
324  *            8. Check the callback data\r
325  * @post_condition 1. Stop Provider Service\r
326  *                 2. Stop shared_ptr<OIC::Service::NSConsumer> Service\r
327  * @expected 1. No exception occurs\r
328  *           2. Should get the Notification in consumer side\r
329  *           3. Should get syncInfo in Provider side\r
330  */\r
331 #if defined(__LINUX__) || defined(__TIZEN__)\r
332 TEST_F(NSCppTest_stc, ConsumerServiceSendSyncInfoAsDeleted_SRC_P)\r
333 {\r
334     shared_ptr< OIC::Service::NSConsumer > consumer = m_pNSHelper->getLocalConsumer(true, false);\r
335 \r
336     ASSERT_NE(nullptr, consumer.get())<< "Consumer should not be null";\r
337 \r
338     try\r
339     {\r
340         consumer->acceptSubscription(true);\r
341     }\r
342     catch (OIC::Service::NSException &e)\r
343     {\r
344         FAIL()<< "Can't accept subscription";\r
345     }\r
346 \r
347     CommonUtil::waitInSecond(WAIT_TIME_MIN);\r
348 \r
349     ASSERT_EQ(true, m_pNSHelper->sendNotification())<< "Can't send notification";\r
350 \r
351     CommonUtil::waitInSecond(WAIT_TIME_DEFAULT);\r
352 \r
353     OIC::Service::NSMessage msg = m_pNSHelper->getNotification();\r
354 \r
355     ASSERT_NE("", msg.getContentText())<< "Doesn't get any notification";\r
356 \r
357     ASSERT_EQ(true, m_pNSHelper->sendSyncInfo(false,\r
358                     OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED))<< "Send OIC::Service::NSSyncInfo failed";\r
359 \r
360     CommonUtil::waitInSecond(WAIT_TIME_DEFAULT);\r
361 \r
362     OIC::Service::NSSyncInfo syncInfo = m_pNSHelper->getSyncInfo(false);\r
363 \r
364     ASSERT_NE("" , syncInfo.getProviderId())<< "SyncInfo should not be null";\r
365     ASSERT_EQ(OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED,\r
366             syncInfo.getState())<< "Sync state must be DELETED";\r
367 }\r
368 #endif\r
369 \r
370 /**\r
371  * @since 2017-03-21\r
372  * @see int start(OnConsumerSubscribedListener subscribedListener,\r
373  *      OnMessageSynchronizedListener messageSynchronized, boolean\r
374  *      subControllability, String userInfo, boolean resourceSecurity)\r
375  * @see int stop()\r
376  * @see OIC::Service::NSMessage createMessage()\r
377  * @see int registerTopic(String topicName)\r
378  * @see int setTopic(String topicName)\r
379  * @see void start(OnProviderDiscoveredListener onProviderDiscoveredListener)\r
380  * @objective Test scenario based 'sendMessage' API functionality\r
381  * @target int sendMessage(OIC::Service::NSMessage message)\r
382  * @test_data OIC::Service::NSSyncInfo::NSSyncType = UNREAD\r
383  * @pre_condition 1. Get Provider Service Instance\r
384  *                2. Start Provider with Provider acceptor\r
385  *                3. Get shared_ptr<OIC::Service::NSConsumer> Service Instance\r
386  *                4. Start shared_ptr<OIC::Service::NSConsumer> Service\r
387  *                5. Wait for OnConsumerSubscribedListener\r
388  *                6. Get shared_ptr<OIC::Service::NSConsumer> object from callback\r
389  *                7. Accept Subscription\r
390  * @procedure 1. Register Topic\r
391  *            2. Set Same topic which is registered\r
392  *            3. Get OIC::Service::NSMessage instance with createMessage()\r
393  *            4. Set OIC::Service::NSMessage Title, Body, SourceName and the TopicName and also the mediaContents\r
394  *            5. Perform sendMessage() API\r
395  *            6. Wait for onMessageReceived Listener\r
396  *            7. Send OIC::Service::NSSyncInfo to Provider Service\r
397  *            8. Check the callback data\r
398  * @post_condition 1. Stop Provider Service\r
399  *                 2. Stop shared_ptr<OIC::Service::NSConsumer> Service\r
400  * @expected 1. No exception occurs\r
401  *           2. Should get the Notification in consumer side\r
402  *           3. Should get syncInfo in Provider side\r
403  */\r
404 #if defined(__LINUX__) || defined(__TIZEN__)\r
405 TEST_F(NSCppTest_stc, ConsumerServiceSendSyncInfoAsUnread_SRC_P)\r
406 {\r
407     shared_ptr< OIC::Service::NSConsumer > consumer = m_pNSHelper->getLocalConsumer(true, false);\r
408 \r
409     ASSERT_NE(nullptr, consumer.get())<< "Consumer should not be null";\r
410 \r
411     try\r
412     {\r
413         consumer->acceptSubscription(true);\r
414     }\r
415     catch (OIC::Service::NSException &e)\r
416     {\r
417         FAIL()<< "Can't accept subscription";\r
418     }\r
419 \r
420     CommonUtil::waitInSecond(WAIT_TIME_MIN);\r
421 \r
422     ASSERT_EQ(true, m_pNSHelper->sendNotification())<< "Can't send notification";\r
423 \r
424     CommonUtil::waitInSecond(WAIT_TIME_DEFAULT);\r
425 \r
426     OIC::Service::NSMessage msg = m_pNSHelper->getNotification();\r
427 \r
428     ASSERT_NE("", msg.getTopic())<< "Doesn't get any notification";\r
429 \r
430     ASSERT_EQ(true, m_pNSHelper->sendSyncInfo(true,\r
431             OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_UNREAD))<< "Send OIC::Service::NSSyncInfo failed";\r
432 \r
433     CommonUtil::waitInSecond(WAIT_TIME_DEFAULT);\r
434 \r
435     OIC::Service::NSSyncInfo syncInfo = m_pNSHelper->getSyncInfo(true);\r
436 \r
437     ASSERT_EQ(OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_UNREAD,\r
438             syncInfo.getState())<< "Syanc state must be UNREAD";\r
439 }\r
440 #endif\r
441 \r
442 /**\r
443  * @since 2017-03-21\r
444  * @see int start(OnConsumerSubscribedListener subscribedListener,\r
445  *      OnMessageSynchronizedListener messageSynchronized, boolean\r
446  *      subControllability, String userInfo, boolean resourceSecurity)\r
447  * @see int stop()\r
448  * @see OIC::Service::NSMessage createMessage()\r
449  * @see int registerTopic(String topicName)\r
450  * @see int setTopic(String topicName)\r
451  * @see void start(OnProviderDiscoveredListener onProviderDiscoveredListener)\r
452  * @objective Test scenario based 'sendMessage' API functionality\r
453  * @target int sendMessage(OIC::Service::NSMessage message)\r
454  * @test_data OIC::Service::NSSyncInfo::NSSyncType = READ\r
455  * @pre_condition 1. Get Provider Service Instance\r
456  *                2. Start Provider with Provider acceptor\r
457  *                3. Get shared_ptr<OIC::Service::NSConsumer> Service Instance\r
458  *                4. Start shared_ptr<OIC::Service::NSConsumer> Service\r
459  *                5. Wait for OnConsumerSubscribedListener\r
460  *                6. Get shared_ptr<OIC::Service::NSConsumer> object from callback\r
461  *                7. Accept Subscription\r
462  * @procedure 1. Register Topic\r
463  *            2. Set Same topic which is registered\r
464  *            3. Get OIC::Service::NSMessage instance with createMessage()\r
465  *            4. Set OIC::Service::NSMessage Title, Body, SourceName and the TopicName and also the mediaContents\r
466  *            5. Perform sendMessage() API\r
467  *            6. Wait for onMessageReceived Listener\r
468  *            7. Send OIC::Service::NSSyncInfo to shared_ptr<OIC::Service::NSConsumer> Service\r
469  *            8. Check the callback data\r
470  * @post_condition 1. Stop Provider Service\r
471  *                 2. Stop shared_ptr<OIC::Service::NSConsumer> Service\r
472  * @expected 1. No exception occurs\r
473  *           2. Should get the Notification in consumer side\r
474  *           3. Should get syncInfo in shared_ptr<OIC::Service::NSConsumer> side\r
475  */\r
476 #if defined(__LINUX__) || defined(__TIZEN__)\r
477 TEST_F(NSCppTest_stc, ProviderServiceSendSyncInfoAsREAD_SRC_P)\r
478 {\r
479     shared_ptr< OIC::Service::NSConsumer > consumer = m_pNSHelper->getLocalConsumer(true, false);\r
480 \r
481     ASSERT_NE(nullptr, consumer.get())<< "Consumer should not be null";\r
482 \r
483     try\r
484     {\r
485         consumer->acceptSubscription(true);\r
486     }\r
487     catch (OIC::Service::NSException &e)\r
488     {\r
489         FAIL()<< "Can't accept subscription";\r
490     }\r
491 \r
492     CommonUtil::waitInSecond(WAIT_TIME_MIN);\r
493 \r
494     ASSERT_EQ(true, m_pNSHelper->sendNotification())<< "Can't send notification";\r
495 \r
496     CommonUtil::waitInSecond(WAIT_TIME_DEFAULT);\r
497 \r
498     OIC::Service::NSMessage msg = m_pNSHelper->getNotification();\r
499 \r
500     ASSERT_NE("", msg.getContentText())<< "Doesn't get any notification";\r
501 \r
502     ASSERT_EQ(true, m_pNSHelper->sendSyncInfo(false,\r
503             OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ))<< "Send OIC::Service::NSSyncInfo failed";\r
504 \r
505     CommonUtil::waitInSecond(WAIT_TIME_DEFAULT);\r
506 \r
507     OIC::Service::NSSyncInfo syncInfo = m_pNSHelper->getSyncInfo(true);\r
508 \r
509     ASSERT_NE("" , syncInfo.getProviderId())<< "SyncInfo should not be null";\r
510     ASSERT_EQ(OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ, syncInfo.getState());\r
511 }\r
512 #endif\r
513 \r
514 /**\r
515  * @since 2017-03-21\r
516  * @see int start(OnConsumerSubscribedListener subscribedListener,\r
517  *      OnMessageSynchronizedListener messageSynchronized, boolean\r
518  *      subControllability, String userInfo, boolean resourceSecurity)\r
519  * @see int stop()\r
520  * @see OIC::Service::NSMessage createMessage()\r
521  * @see int registerTopic(String topicName)\r
522  * @see int setTopic(String topicName)\r
523  * @see void start(OnProviderDiscoveredListener onProviderDiscoveredListener)\r
524  * @objective Test scenario based 'sendMessage' API functionality\r
525  * @target int sendMessage(OIC::Service::NSMessage message)\r
526  * @test_data OIC::Service::NSSyncInfo::NSSyncType = UNREAD\r
527  * @pre_condition 1. Get Provider Service Instance\r
528  *                2. Start Provider with Provider acceptor\r
529  *                3. Get shared_ptr<OIC::Service::NSConsumer> Service Instance\r
530  *                4. Start shared_ptr<OIC::Service::NSConsumer> Service\r
531  *                5. Wait for OnConsumerSubscribedListener\r
532  *                6. Get shared_ptr<OIC::Service::NSConsumer> object from callback\r
533  *                7. Accept Subscription\r
534  * @procedure 1. Register Topic\r
535  *            2. Set Same topic which is registered\r
536  *            3. Get OIC::Service::NSMessage instance with createMessage()\r
537  *            4. Set OIC::Service::NSMessage Title, Body, SourceName and the TopicName and also the mediaContents\r
538  *            5. Perform sendMessage() API\r
539  *            6. Wait for onMessageReceived Listener\r
540  *            7. Send OIC::Service::NSSyncInfo to shared_ptr<OIC::Service::NSConsumer> Service\r
541  *            8. Check the callback data\r
542  * @post_condition 1. Stop Provider Service\r
543  *                 2. Stop shared_ptr<OIC::Service::NSConsumer> Service\r
544  * @expected 1. No exception occurs\r
545  *           2. Should get the Notification in consumer side\r
546  *           3. Should not get syncInfo in shared_ptr<OIC::Service::NSConsumer> side\r
547  */\r
548 #if defined(__LINUX__) || defined(__TIZEN__)\r
549 TEST_F(NSCppTest_stc, ProviderServiceSendSyncInfoAsUNREAD_SRC_P)\r
550 {\r
551     shared_ptr< OIC::Service::NSConsumer > consumer = m_pNSHelper->getLocalConsumer(true, false);\r
552 \r
553     ASSERT_NE(nullptr, consumer.get())<< "Consumer should not be null";\r
554 \r
555     try\r
556     {\r
557         consumer->acceptSubscription(true);\r
558     }\r
559     catch (OIC::Service::NSException &e)\r
560     {\r
561         FAIL()<< "Can't accept subscription";\r
562     }\r
563 \r
564     CommonUtil::waitInSecond(WAIT_TIME_MIN);\r
565 \r
566     ASSERT_EQ(true, m_pNSHelper->sendNotification())<< "Can't send notification";\r
567 \r
568     CommonUtil::waitInSecond(WAIT_TIME_DEFAULT);\r
569 \r
570     OIC::Service::NSMessage msg = m_pNSHelper->getNotification();\r
571 \r
572     ASSERT_NE("", msg.getContentText())<< "Doesn't get any notification";\r
573 \r
574     ASSERT_EQ(true, m_pNSHelper->sendSyncInfo(false,\r
575             OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_UNREAD))<< "Send SyncInfo failed";\r
576 \r
577     CommonUtil::waitInSecond(WAIT_TIME_DEFAULT);\r
578 \r
579     OIC::Service::NSSyncInfo syncInfo = m_pNSHelper->getSyncInfo(true);\r
580 \r
581     ASSERT_NE("" , syncInfo.getProviderId())<< "SyncInfo should not be null";\r
582 }\r
583 #endif\r
584 \r
585 /**\r
586  * @since 2017-03-21\r
587  * @see int start(OnConsumerSubscribedListener subscribedListener,\r
588  *      OnMessageSynchronizedListener messageSynchronized, boolean\r
589  *      subControllability, String userInfo, boolean resourceSecurity)\r
590  * @see int stop()\r
591  * @see OIC::Service::NSMessage createMessage()\r
592  * @see int registerTopic(String topicName)\r
593  * @see int setTopic(String topicName)\r
594  * @see void start(OnProviderDiscoveredListener onProviderDiscoveredListener)\r
595  * @objective Test scenario based 'sendMessage' API functionality\r
596  * @target int sendMessage(OIC::Service::NSMessage message)\r
597  * @test_data OIC::Service::NSSyncInfo::NSSyncType = DELETED\r
598  * @pre_condition 1. Get Provider Service Instance\r
599  *                2. Start Provider with Provider acceptor\r
600  *                3. Get shared_ptr<OIC::Service::NSConsumer> Service Instance\r
601  *                4. Start shared_ptr<OIC::Service::NSConsumer> Service\r
602  *                5. Wait for OnConsumerSubscribedListener\r
603  *                6. Get shared_ptr<OIC::Service::NSConsumer> object from callback\r
604  *                7. Accept Subscription\r
605  * @procedure 1. Register Topic\r
606  *            2. Set Same topic which is registered\r
607  *            3. Get OIC::Service::NSMessage instance with createMessage()\r
608  *            4. Set OIC::Service::NSMessage Title, Body, SourceName and the TopicName and also the mediaContents\r
609  *            5. Perform sendMessage() API\r
610  *            6. Wait for onMessageReceived Listener\r
611  *            7. Send OIC::Service::NSSyncInfo to shared_ptr<OIC::Service::NSConsumer> Service\r
612  *            8. Check the callback data\r
613  * @post_condition 1. Stop Provider Service\r
614  *                 2. Stop shared_ptr<OIC::Service::NSConsumer> Service\r
615  * @expected 1. No exception occurs\r
616  *           2. Should get the Notification in consumer side\r
617  *           3. Should get syncInfo in shared_ptr<OIC::Service::NSConsumer> side\r
618  */\r
619 #if defined(__LINUX__) || defined(__TIZEN__)\r
620 TEST_F(NSCppTest_stc, ProviderServiceSendSyncInfoAsDELETED_SRC_P)\r
621 {\r
622     shared_ptr< OIC::Service::NSConsumer > consumer = m_pNSHelper->getLocalConsumer(true, false);\r
623 \r
624     ASSERT_NE(nullptr, consumer.get())<< "Consumer should not be null";\r
625 \r
626     try\r
627     {\r
628         consumer->acceptSubscription(true);\r
629     }\r
630     catch (OIC::Service::NSException &e)\r
631     {\r
632         FAIL()<< "Can't accept subscription";\r
633     }\r
634 \r
635     CommonUtil::waitInSecond(WAIT_TIME_MIN);\r
636 \r
637     ASSERT_EQ(true, m_pNSHelper->sendNotification())<< "Can't send notification";\r
638 \r
639     CommonUtil::waitInSecond(WAIT_TIME_DEFAULT);\r
640 \r
641     OIC::Service::NSMessage msg = m_pNSHelper->getNotification();\r
642 \r
643     ASSERT_NE("", msg.getContentText())<< "Doesn't get any notification";\r
644 \r
645     ASSERT_EQ(true, m_pNSHelper->sendSyncInfo(true,\r
646             OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED))<< "Send OIC::Service::NSSyncInfo failed";\r
647 \r
648     CommonUtil::waitInSecond(WAIT_TIME_DEFAULT);\r
649 \r
650     OIC::Service::NSSyncInfo syncInfo = m_pNSHelper->getSyncInfo(false);\r
651 \r
652     ASSERT_NE("" , syncInfo.getProviderId())<< "SyncInfo should not be null";\r
653     ASSERT_EQ(OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED, syncInfo.getState());\r
654 }\r
655 #endif\r
656 \r
657 /**\r
658  * @since 2016-10-20\r
659  * @see int start(OnConsumerSubscribedListener subscribedListener,\r
660  *      OnMessageSynchronizedListener messageSynchronized, boolean\r
661  *      subControllability, String userInfo, boolean resourceSecurity)\r
662  * @see int stop()\r
663  * @see OIC::Service::NSMessage createMessage()\r
664  * @see int registerTopic(String topicName)\r
665  * @see void start(OnProviderDiscoveredListener onProviderDiscoveredListener)\r
666  * @objective Test scenario based 'sendMessage' API functionality\r
667  * @target int sendMessage(OIC::Service::NSMessage message)\r
668  * @test_data None\r
669  * @pre_condition 1. Get Provider Service Instance\r
670  *                2. Start Provider with Provider acceptor\r
671  *                3. Register Topic with topicName = "OCF_TestTopic"\r
672  *                4. Get shared_ptr<OIC::Service::NSConsumer> Service Instance\r
673  *                5. Start shared_ptr<OIC::Service::NSConsumer> Service\r
674  *                6. Wait for OnConsumerSubscribedListener\r
675  *                7. Get shared_ptr<OIC::Service::NSConsumer> object from callback\r
676  *                8. Accept Subscription\r
677  * @procedure 1. Get the topic list\r
678  *            2. Check the topic state\r
679  * @post_condition 1. Stop Provider Service\r
680  *                 2. Stop shared_ptr<OIC::Service::NSConsumer> Service\r
681  * @expected 1. No exception occurs\r
682  *           2. Topic state should be UNSUBSCRIBED at initial stage\r
683  */\r
684 #if defined(__LINUX__) || defined(__TIZEN__)\r
685 TEST_F(NSCppTest_stc, TopicState_SRC_P)\r
686 {\r
687     shared_ptr< OIC::Service::NSConsumer > consumer = m_pNSHelper->getLocalConsumer(true, true);\r
688 \r
689     ASSERT_NE(nullptr, consumer.get())<< "Consumer should not be null";\r
690 \r
691     try\r
692     {\r
693         consumer->acceptSubscription(true);\r
694     }\r
695     catch (OIC::Service::NSException &e)\r
696     {\r
697         FAIL()<< "Can't accept subscription";\r
698     }\r
699 \r
700     CommonUtil::waitInSecond(WAIT_TIME_MIN);\r
701 \r
702     try\r
703     {\r
704         list< OIC::Service::NSTopic > topics = consumer->getConsumerTopicList()->getTopicsList();\r
705         OIC::Service::NSTopic topic = topics.front();\r
706         ASSERT_EQ(OIC::Service::NSTopic::NSTopicState::UNSUBSCRIBED,\r
707                 topic.getState())<< "Topic should be UNSUBSCRIBED state after unsetTopic()";\r
708     }\r
709     catch (OIC::Service::NSException &e)\r
710     {\r
711         FAIL() << "Can't get consumerTopicList. Exception: " << e.what();\r
712     }\r
713 }\r
714 #endif\r
715 \r
716 /**\r
717  * @since 2016-10-20\r
718  * @see int start(OnConsumerSubscribedListener subscribedListener,\r
719  *      OnMessageSynchronizedListener messageSynchronized, boolean\r
720  *      subControllability, String userInfo, boolean resourceSecurity)\r
721  * @see int stop()\r
722  * @see OIC::Service::NSMessage createMessage()\r
723  * @see int registerTopic(String topicName)\r
724  * @see void start(OnProviderDiscoveredListener onProviderDiscoveredListener)\r
725  * @objective Test scenario based 'sendMessage' API functionality\r
726  * @target int sendMessage(OIC::Service::NSMessage message)\r
727  * @test_data None\r
728  * @pre_condition 1. Get Provider Service Instance\r
729  *                2. Start Provider with Provider acceptor\r
730  *                3. Register Topic with topicName = "OCF_TestTopic"\r
731  *                4. Get shared_ptr<OIC::Service::NSConsumer> Service Instance\r
732  *                5. Start shared_ptr<OIC::Service::NSConsumer> Service\r
733  *                6. Wait for OnConsumerSubscribedListener\r
734  *                7. Get shared_ptr<OIC::Service::NSConsumer> object from callback\r
735  *                8. Accept Subscription\r
736  * @procedure 1. SetTopic for the topicName = "OCF_TestTopic"\r
737  *            2. Get the topic list\r
738  *            3. Check the topic state\r
739  *            4. Unset the topic\r
740  *            5. Get and check the topic state\r
741  * @post_condition 1. Stop Provider Service\r
742  *                 2. Stop shared_ptr<OIC::Service::NSConsumer> Service\r
743  * @expected 1. No exception occurs\r
744  *           2. Topic state should be SUBSCRIBED state after set\r
745  *           3. Topic state should be UNSUBSCRIBED state after unset\r
746  */\r
747 #if defined(__LINUX__) || defined(__TIZEN__)\r
748 TEST_F(NSCppTest_stc, SetUnsetTopic_SQV_P)\r
749 {\r
750     shared_ptr< OIC::Service::NSConsumer > consumer = m_pNSHelper->getLocalConsumer(true, true);\r
751 \r
752     ASSERT_NE(nullptr, consumer.get())<< "Consumer should not be null";\r
753 \r
754     try\r
755     {\r
756         consumer->acceptSubscription(true);\r
757     }\r
758     catch (OIC::Service::NSException &e)\r
759     {\r
760         FAIL()<< "Exception occurred while accept subscription : " << e.what();\r
761     }\r
762 \r
763     CommonUtil::waitInSecond(WAIT_TIME_MIN + WAIT_TIME_MIN );\r
764 \r
765     try\r
766     {\r
767         OIC::Service::NSTopic topic = NSCppUtility::getDesiredTopic(consumer->getConsumerTopicList(), TEST_TOPIC_1);\r
768         ASSERT_EQ((int) OIC::Service::NSTopic::NSTopicState::UNSUBSCRIBED,\r
769                 (int) topic.getState())<< "Topic should be UNSUBSCRIBED state before setTopic()";\r
770 \r
771         consumer->setTopic(TEST_TOPIC_1);\r
772         topic = NSCppUtility::getDesiredTopic(consumer->getConsumerTopicList(), TEST_TOPIC_1);\r
773         ASSERT_EQ((int) OIC::Service::NSTopic::NSTopicState::SUBSCRIBED,\r
774                 (int) topic.getState())<< "Topic should be SUBSCRIBED state after setTopic()";\r
775 \r
776         consumer->unsetTopic(TEST_TOPIC_1);\r
777         topic = NSCppUtility::getDesiredTopic(consumer->getConsumerTopicList(), TEST_TOPIC_1);\r
778         ASSERT_EQ(OIC::Service::NSTopic::NSTopicState::UNSUBSCRIBED,\r
779                 topic.getState())<< "Topic should be UNSUBSCRIBED state after unsetTopic()";\r
780     }\r
781     catch (OIC::Service::NSException &e)\r
782     {\r
783         FAIL() << "Can't get consumerTopicList. Exception: " << e.what();\r
784     }\r
785 }\r
786 #endif\r