build: Add build dir to LIBPATH globally
[platform/upstream/iotivity.git] / resource / unittests / OCResourceTest.cpp
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH 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
22 #include <OCPlatform.h>
23 #include <OCApi.h>
24 #include <gtest/gtest.h>
25 #include <string>
26 #include <map>
27
28 static char gLongHostAddress[] = "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111:5000";
29
30 namespace OCResourceTest
31 {
32     using namespace OC;
33     // Callbacks
34     void onObserve(const HeaderOptions, const OCRepresentation&, const int&, const int&)
35     {
36     }
37
38     void onGetPut(const HeaderOptions&, const OCRepresentation& , const int eCode)
39     {
40         EXPECT_EQ(eCode, OC_STACK_OK);
41     }
42
43     void foundResource(std::shared_ptr<OCResource> )
44     {
45     }
46
47     void deleteResponse(const HeaderOptions&, const int)
48     {
49     }
50
51     //Helper method
52     OCResource::Ptr ConstructResourceObject(std::string host, std::string uri)
53     {
54         OCConnectivityType connectivityType = CT_DEFAULT;
55         std::vector<std::string> types = {"intel.rpost"};
56         std::vector<std::string> ifaces = {DEFAULT_INTERFACE};
57
58         auto ret = OCPlatform::constructResourceObject(host, uri,
59                 connectivityType, false, types, ifaces);
60
61         if(!ret)
62         {
63             ADD_FAILURE() << "ConstructResourceObject result was null";
64             throw std::runtime_error("ConstructResourceObject result was null");
65         }
66
67         return ret;
68     }
69
70     //ConstructResourceObject Test
71     TEST(ConstructResourceTest, ConstructResourceObjectWithValidHost)
72     {
73         EXPECT_NO_THROW(ConstructResourceObject("coap://192.168.1.2:5000", "/resource"));
74     }
75
76     TEST(ConstructResourceTest, ConstructResourceObjectWithValidHost2)
77     {
78         EXPECT_NO_THROW(ConstructResourceObject("coap://[ffff::ffff]:5000", "/resource"));
79     }
80
81     TEST(ConstructResourceTest, ConstructResourceObjectWithValidHost3)
82     {
83         EXPECT_NO_THROW(ConstructResourceObject("coap://[ffff::ffff%25eth0]:5000", "/resource"));
84     }
85
86     TEST(ConstructResourceTest, ConstructResourceObject)
87     {
88         EXPECT_ANY_THROW(ConstructResourceObject(std::string(""), std::string("")));
89     }
90
91     TEST(ConstructResourceTest, ConstructResourceObjectWithoutCoapScheme)
92     {
93         EXPECT_ANY_THROW(ConstructResourceObject("//192.168.1.2:5000", "/resource"));
94     }
95
96     TEST(ConstructResourceTest, ConstructResourceObjectWithoutPortNumber)
97     {
98         EXPECT_ANY_THROW(ConstructResourceObject("coap://192.168.1.2", "/resource"));
99     }
100
101     TEST(ConstructResourceTest, ConstructResourceObjectWithoutPortNumber2)
102     {
103         EXPECT_ANY_THROW(ConstructResourceObject("coap://192.168.1.2:", "/resource"));
104     }
105
106     TEST(ConstructResourceTest, ConstructResourceObjectWithLongHostAddress)
107     {
108         EXPECT_ANY_THROW(ConstructResourceObject(gLongHostAddress, "/resource"));
109     }
110
111     TEST(ConstructResourceTest, ConstructResourceObjectInvalidHost)
112     {
113         EXPECT_ANY_THROW(ConstructResourceObject("192.168.1.2:5000", "/resource"));
114     }
115
116     TEST(ConstructResourceTest, ConstructResourceObjectInvalidHost2)
117     {
118         EXPECT_ANY_THROW(ConstructResourceObject("coap://:5000", "/resource"));
119     }
120
121     TEST(ConstructResourceTest, ConstructResourceObjectInvalidHost3)
122     {
123         EXPECT_ANY_THROW(ConstructResourceObject("coap://[ffff:::ffff]:5000", "/resource"));
124     }
125
126     TEST(ConstructResourceTest, ConstructResourceObjectInvalidHost4)
127     {
128         EXPECT_ANY_THROW(ConstructResourceObject("coap://[ffff::ffff%eth0]:5000", "/resource"));
129     }
130
131     TEST(ConstructResourceTest, ConstructResourceObjectInvalidUri)
132     {
133         EXPECT_ANY_THROW(ConstructResourceObject("coap://192.168.1.2:5000", "/"));
134     }
135
136     TEST(ConstructResourceTest, ConstructResourceObjectInvalidUri2)
137     {
138         EXPECT_ANY_THROW(ConstructResourceObject("coap://192.168.1.2:5000", "resource"));
139     }
140
141     //Get Test
142     TEST(ResourceGetTest, DISABLED_ResourceGetForValidUri)
143     {
144         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
145         EXPECT_TRUE(resource != NULL);
146         EXPECT_EQ(OC_STACK_OK, resource->get(OC::QueryParamsMap(), &onGetPut));
147
148     }
149
150     TEST(ResourceGetTest, DISABLED_ResourceGetForBadUri)
151     {
152         OCResource::Ptr resource = ConstructResourceObject("", "coap://192.168.1.2:5000");
153         EXPECT_TRUE(resource != NULL);
154         EXPECT_THROW(resource->get(OC::QueryParamsMap(), &onGetPut), OC::OCException);
155     }
156
157     TEST(ResourceGetTest, DISABLED_ResourceGetWithHighQos)
158     {
159         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
160         EXPECT_TRUE(resource != NULL);
161         EXPECT_EQ(OC_STACK_OK,
162                 resource->get(OC::QueryParamsMap(), &onGetPut, QualityOfService::HighQos));
163     }
164
165     TEST(ResourceGetTest, DISABLED_ResourceGetWithLowQos)
166     {
167         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
168         EXPECT_TRUE(resource != NULL);
169         EXPECT_EQ(OC_STACK_OK,
170                 resource->get(OC::QueryParamsMap(), &onGetPut, QualityOfService::LowQos));
171     }
172
173     TEST(ResourceGetTest, DISABLED_ResourceGetWithMidQos)
174     {
175         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
176         EXPECT_TRUE(resource != NULL);
177         EXPECT_EQ(OC_STACK_OK,
178                 resource->get(OC::QueryParamsMap(), &onGetPut, QualityOfService::MidQos));
179     }
180
181     TEST(ResourceGetTest, DISABLED_ResourceGetWithNaQos)
182     {
183         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
184         EXPECT_TRUE(resource != NULL);
185         EXPECT_EQ(OC_STACK_OK,
186                 resource->get(OC::QueryParamsMap(), &onGetPut, QualityOfService::NaQos));
187     }
188
189     TEST(ResourceGetTest, DISABLED_ResourceGetWithRTIFNaQos)
190     {
191         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
192         EXPECT_TRUE(resource != NULL);
193         EXPECT_EQ(OC_STACK_OK,
194                 resource->get("", DEFAULT_INTERFACE, QueryParamsMap(), &onGetPut,
195                         QualityOfService::NaQos));
196     }
197
198     TEST(ResourceGetTest, DISABLED_ResourceGetWithNullResourceType)
199     {
200         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
201         EXPECT_TRUE(resource != NULL);
202         EXPECT_ANY_THROW(
203                 resource->get(nullptr, DEFAULT_INTERFACE, QueryParamsMap(), &onGetPut,
204                         QualityOfService::NaQos));
205     }
206
207
208     TEST(ResourceGetTest, DISABLED_ResourceGetWithNullResourceInterface)
209     {
210         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
211         EXPECT_TRUE(resource != NULL);
212         EXPECT_ANY_THROW(
213                 resource->get("", nullptr, QueryParamsMap(), &onGetPut, QualityOfService::NaQos));
214     }
215
216     TEST(ResourceGetTest, DISABLED_ResourceGetWithTypeAndInterface)
217     {
218         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
219         EXPECT_TRUE(resource != NULL);
220         EXPECT_EQ(OC_STACK_OK, resource->get("", DEFAULT_INTERFACE, QueryParamsMap(), &onGetPut));
221     }
222
223     //Post Test
224     TEST(ResourcePostTest, DISABLED_ResourcePostValidConfiguration)
225     {
226         OCRepresentation rep;
227         QueryParamsMap query = {};
228         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
229         EXPECT_TRUE(resource != NULL);
230         EXPECT_EQ(OC_STACK_OK, resource->post(rep, query, &onGetPut));
231     }
232
233     TEST(ResourcePostTest, DISABLED_ResourcePostWithNaQos)
234     {
235         OCRepresentation rep;
236         QueryParamsMap query = {};
237         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
238         EXPECT_TRUE(resource != NULL);
239         EXPECT_EQ(OC_STACK_OK, resource->post(rep, query, &onGetPut, QualityOfService::NaQos));
240     }
241
242     TEST(ResourcePostTest, DISABLED_ResourcePostWithMidQos)
243     {
244         OCRepresentation rep;
245         QueryParamsMap query = {};
246         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
247         EXPECT_TRUE(resource != NULL);
248         EXPECT_EQ(OC_STACK_OK, resource->post(rep, query, &onGetPut, QualityOfService::MidQos));
249     }
250
251     TEST(ResourcePostTest, DISABLED_ResourcePostWithLowQos)
252     {
253         OCRepresentation rep;
254         QueryParamsMap query = {};
255         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
256         EXPECT_TRUE(resource != NULL);
257         EXPECT_EQ(OC_STACK_OK, resource->post(rep, query, &onGetPut, QualityOfService::LowQos));
258     }
259
260     TEST(ResourcePostTest, DISABLED_ResourcePostWithHighQos)
261     {
262         OCRepresentation rep;
263         QueryParamsMap query = {};
264         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
265         EXPECT_TRUE(resource != NULL);
266         EXPECT_EQ(OC_STACK_OK, resource->post(rep, query, &onGetPut, QualityOfService::HighQos));
267     }
268
269     //Put Test
270     TEST(ResourcePutTest, DISABLED_ResourcePutForValid)
271     {
272         OCRepresentation rep;
273         QueryParamsMap query = {};
274         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
275         EXPECT_TRUE(resource != NULL);
276         EXPECT_EQ(OC_STACK_OK, resource->put(rep, query, &onGetPut));
277     }
278
279     TEST(ResourcePutTest, DISABLED_ResourcePutWithNaQos)
280     {
281         OCRepresentation rep;
282         QueryParamsMap query = {};
283         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
284         EXPECT_TRUE(resource != NULL);
285         EXPECT_EQ(OC_STACK_OK, resource->put(rep, query, &onGetPut, QualityOfService::NaQos));
286     }
287
288     TEST(ResourcePutTest, DISABLED_ResourcePutWithLowQos)
289     {
290         OCRepresentation rep;
291         QueryParamsMap query = {};
292         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
293         EXPECT_TRUE(resource != NULL);
294         EXPECT_EQ(OC_STACK_OK, resource->put(rep, query, &onGetPut, QualityOfService::LowQos));
295     }
296
297     TEST(ResourcePutTest, DISABLED_ResourcePutWithMidQos)
298     {
299         OCRepresentation rep;
300         QueryParamsMap query = {};
301         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
302         EXPECT_TRUE(resource != NULL);
303         EXPECT_EQ(OC_STACK_OK, resource->put(rep, query, &onGetPut, QualityOfService::MidQos));
304     }
305
306     TEST(ResourcePutTest, DISABLED_ResourcePutWithHighQos)
307     {
308         OCRepresentation rep;
309         QueryParamsMap query = {};
310         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
311         EXPECT_TRUE(resource != NULL);
312         EXPECT_EQ(OC_STACK_OK, resource->put(rep, query, &onGetPut, QualityOfService::HighQos));
313     }
314
315     TEST(ResourcePutTest, DISABLED_ResourcePutWithTypeAndInterface)
316     {
317         OCRepresentation rep;
318         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
319         EXPECT_TRUE(resource != NULL);
320         EXPECT_EQ(OC_STACK_OK,
321                 resource->put("", DEFAULT_INTERFACE, rep, QueryParamsMap(), &onGetPut));
322     }
323
324     TEST(ResourcePutTest, DISABLED_ResourcePutWithNullType)
325     {
326         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
327         EXPECT_TRUE(resource != NULL);
328         OCRepresentation rep;
329         EXPECT_ANY_THROW(
330                 resource->put(nullptr, DEFAULT_INTERFACE, rep, QueryParamsMap(), &onGetPut));
331         HeaderOptions headerOptions;
332         onGetPut(headerOptions, rep, OC_STACK_OK);
333     }
334
335     TEST(ResourcePutTest, DISABLED_ResourcePutWithNullInterface)
336     {
337         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
338         EXPECT_TRUE(resource != NULL);
339         OCRepresentation rep;
340         EXPECT_ANY_THROW(resource->put("", nullptr, rep, QueryParamsMap(), &onGetPut));
341     }
342
343     // Observer Test
344     TEST(ResourceObserveTest, DISABLED_ResourceObserveValidUri)
345     {
346         OCResource::Ptr resource =
347                 ConstructResourceObject("coap://192.168.1.2:5000", "/Observe");
348         EXPECT_TRUE(resource != NULL);
349         QueryParamsMap query = {};
350         EXPECT_EQ(OC_STACK_OK, resource->observe(ObserveType::ObserveAll, query, &onObserve));
351     }
352
353     TEST(ResourceObserveTest, DISABLED_ResourceObserveLoQos)
354     {
355         QueryParamsMap query = {};
356         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/Observe");
357         EXPECT_TRUE(resource != NULL);
358         EXPECT_EQ(OC_STACK_OK,
359                 resource->observe(ObserveType::ObserveAll, query, &onObserve,
360                         QualityOfService::LowQos));
361     }
362
363     TEST(ResourceObserveTest, DISABLED_ResourceObserveNaQos)
364     {
365         QueryParamsMap query = {};
366         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/Observe");
367         EXPECT_TRUE(resource != NULL);
368         EXPECT_EQ(OC_STACK_OK,
369                 resource->observe(ObserveType::ObserveAll, query, &onObserve,
370                         QualityOfService::NaQos));
371     }
372
373     TEST(ResourceObserveTest, DISABLED_ResourceObserveMidQos)
374     {
375         QueryParamsMap query = {};
376         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/Observe");
377         EXPECT_TRUE(resource != NULL);
378         EXPECT_EQ(OC_STACK_OK,
379                 resource->observe(ObserveType::ObserveAll, query, &onObserve,
380                         QualityOfService::MidQos));
381     }
382
383     TEST(ResourceObserveTest, DISABLED_ResourceObserveHighQos)
384     {
385         QueryParamsMap query = {};
386         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/Observe");
387         EXPECT_TRUE(resource != NULL);
388         EXPECT_EQ(OC_STACK_OK,
389                 resource->observe(ObserveType::ObserveAll, query, &onObserve,
390                         QualityOfService::HighQos));
391     }
392
393     TEST(ResourceObserveTest, DISABLED_ResourceCancelObserveValidUri)
394     {
395         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
396         EXPECT_TRUE(resource != NULL);
397         QueryParamsMap query = {};
398         EXPECT_EQ(OC_STACK_OK, resource->observe(ObserveType::ObserveAll, query, &onObserve));
399         EXPECT_EQ(OC_STACK_OK, resource->cancelObserve());
400     }
401
402     TEST(ResourceObserveTest, DISABLED_ResourceCancelObserveWithNaQos)
403     {
404         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
405         EXPECT_TRUE(resource != NULL);
406         QueryParamsMap query = {};
407         EXPECT_EQ(OC_STACK_OK,
408                 resource->observe(ObserveType::ObserveAll, query, &onObserve,
409                         QualityOfService::NaQos));
410         EXPECT_EQ(OC_STACK_OK, resource->cancelObserve(QualityOfService::NaQos));
411     }
412
413     TEST(ResourceObserveTest, DISABLED_ResourceCancelObserveWithLowQos)
414     {
415         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
416         EXPECT_TRUE(resource != NULL);
417         QueryParamsMap query = {};
418         EXPECT_EQ(OC_STACK_OK,
419                 resource->observe(ObserveType::ObserveAll, query, &onObserve,
420                         QualityOfService::LowQos));
421         EXPECT_EQ(OC_STACK_OK, resource->cancelObserve(QualityOfService::LowQos));
422     }
423
424     TEST(ResourceObserveTest, DISABLED_ResourceCancelObserveWithMidQos)
425     {
426         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
427         EXPECT_TRUE(resource != NULL);
428             QueryParamsMap query = {};
429         EXPECT_EQ(OC_STACK_OK,
430                 resource->observe(ObserveType::ObserveAll, query, &onObserve,
431                         QualityOfService::MidQos));
432         EXPECT_EQ(OC_STACK_OK, resource->cancelObserve(QualityOfService::MidQos));
433     }
434
435     TEST(ResourceObserveTest, DISABLED_ResourceCancelObserveWithHighQos)
436     {
437         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
438         EXPECT_TRUE(resource != NULL);
439             QueryParamsMap query = {};
440         EXPECT_EQ(OC_STACK_OK,
441                 resource->observe(ObserveType::ObserveAll, query, &onObserve,
442                         QualityOfService::HighQos));
443         EXPECT_EQ(OC_STACK_OK, resource->cancelObserve(QualityOfService::HighQos));
444     }
445
446     //DeleteResource
447     TEST(DeleteResourceTest, DISABLED_DeleteResourceValidUri)
448     {
449         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
450         EXPECT_TRUE(resource != NULL);
451         EXPECT_EQ(OC_STACK_OK, resource->deleteResource(&deleteResponse));
452     }
453
454     TEST(DeleteResourceTest, DISABLED_DeleteResourceWithLowQos)
455     {
456         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
457         EXPECT_TRUE(resource != NULL);
458         EXPECT_EQ(OC_STACK_OK,
459                 resource->deleteResource(&deleteResponse, QualityOfService::LowQos));
460     }
461
462     TEST(DeleteResourceTest, DISABLED_DeleteResourceWithMidQos)
463     {
464         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
465         EXPECT_TRUE(resource != NULL);
466         EXPECT_EQ(OC_STACK_OK,
467                 resource->deleteResource(&deleteResponse, QualityOfService::MidQos));
468     }
469
470     TEST(DeleteResourceTest, DISABLED_DeleteResourceWithHighQos)
471     {
472         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
473         EXPECT_TRUE(resource != NULL);
474         EXPECT_EQ(OC_STACK_OK,
475                 resource->deleteResource(&deleteResponse, QualityOfService::HighQos));
476     }
477     TEST(DeleteResourceTest, DISABLED_DeleteResourceWithNaQos)
478     {
479         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
480         EXPECT_TRUE(resource != NULL);
481         EXPECT_EQ(OC_STACK_OK, resource->deleteResource(&deleteResponse, QualityOfService::NaQos));
482     }
483
484     //GetResourceInterfaces Test
485     TEST(GetResourceInterfacesTest, GetResourceInterfaces)
486     {
487         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
488         EXPECT_TRUE(resource != NULL);
489         EXPECT_TRUE(resource->getResourceInterfaces().front() == DEFAULT_INTERFACE);
490     }
491
492     //GetResourceTypes Test
493     TEST(GetResourceTypesTest, GetResourceTypes)
494     {
495         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
496         EXPECT_TRUE(resource != NULL);
497         EXPECT_TRUE(resource->getResourceTypes().front() == "intel.rpost");
498     }
499
500     // Host Test
501     TEST(HostTest, Host)
502     {
503         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
504         EXPECT_TRUE(resource != NULL);
505         EXPECT_TRUE(resource->host() == "coap://192.168.1.2:5000");
506     }
507
508     TEST(HostTest, Host2)
509     {
510         OCResource::Ptr resource = ConstructResourceObject("coap://[ffff::ffff%25eth0]:5000", "/resource");
511         EXPECT_TRUE(resource != NULL);
512         EXPECT_TRUE(resource->host() == "coap://[ffff::ffff%25eth0]:5000");
513     }
514
515     // EmptyHosts Test
516     TEST(HostsTest, EmptyHosts)
517     {
518         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
519         EXPECT_TRUE(resource != NULL);
520         EXPECT_TRUE(resource->getAllHosts().empty());
521     }
522
523     // SetHost Test
524     TEST(SetHostTest, SetHost)
525     {
526         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
527         EXPECT_TRUE(resource != NULL);
528         EXPECT_TRUE(resource->host() == "coap://192.168.1.2:5000");
529         EXPECT_TRUE(resource->setHost("coap://192.168.1.1:5000") == "coap://192.168.1.1:5000");
530     }
531
532     // SetHost Test2
533     TEST(SetHostTest, SetHost2)
534     {
535         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
536         EXPECT_TRUE(resource != NULL);
537         EXPECT_TRUE(resource->host() == "coap://192.168.1.2:5000");
538         EXPECT_TRUE(resource->setHost("coap://[3731:54:65fe:2::a7]:32787") ==
539                                       "coap://[3731:54:65fe:2::a7]:32787");
540     }
541
542     // SetHost Test3
543     TEST(SetHostTest, SetHost3)
544     {
545         OCResource::Ptr resource = ConstructResourceObject("coap://[3731:54:65fe:2::a7]:32787", "/resource");
546         EXPECT_TRUE(resource != NULL);
547         EXPECT_TRUE(resource->host() == "coap://[3731:54:65fe:2::a7]:32787");
548         EXPECT_TRUE(resource->setHost("coap://192.168.1.2:5000") == "coap://192.168.1.2:5000");
549     }
550
551     //Uri Test
552     TEST(UriTest, Uri)
553     {
554         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
555         EXPECT_TRUE(resource != NULL);
556         EXPECT_TRUE(resource->uri() == "/resource");
557     }
558
559     //ConnectivityType Test
560     TEST(ConnectivityTypeTest, ConnectivityTypeIpv4)
561     {
562         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
563         EXPECT_TRUE(resource != NULL);
564         EXPECT_TRUE(resource->connectivityType() == (CT_ADAPTER_IP | CT_IP_USE_V4));
565     }
566
567     //ConnectivityType Test
568     TEST(ConnectivityTypeTest, ConnectivityTypeIpv6)
569     {
570         OCResource::Ptr resource = ConstructResourceObject("coap://[fe80::52b7:c3ff:fead:dc0d%25eth0]:5000", "/resource");
571         EXPECT_TRUE(resource != NULL);
572         EXPECT_TRUE(resource->connectivityType() == (CT_ADAPTER_IP | CT_IP_USE_V6));
573     }
574
575     //IsObservable Test
576     TEST(IsObservableTest, isObservable)
577     {
578         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
579         EXPECT_TRUE(resource != NULL);
580         EXPECT_FALSE(resource->isObservable());
581     }
582
583     //SID Test
584     TEST(SidTest, sid)
585     {
586         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
587         EXPECT_TRUE(resource != NULL);
588         EXPECT_TRUE(resource->sid() == "");
589     }
590
591     //UniqueIdentifier Test
592     TEST(UniqueIdentifierTest, uniqueIdentifier)
593     {
594         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
595         EXPECT_TRUE(resource != NULL);
596         std::ostringstream ss;
597         ss << resource->uniqueIdentifier();
598         EXPECT_TRUE(ss.str() == "/resource");
599     }
600
601     // HeaderOptions Test
602     TEST(HeaderOptionsTest, SetHeaderOptionsValidInput)
603     {
604         const uint16_t API_VERSION = 2048;
605         const uint16_t TOKEN = 3000;
606         HeaderOptions headerOptions;
607         HeaderOption::OCHeaderOption apiVersion(API_VERSION, "v.1.0");
608         HeaderOption::OCHeaderOption clientToken(TOKEN, "21ae43gf");
609         headerOptions.push_back(apiVersion);
610         headerOptions.push_back(clientToken);
611
612         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
613         EXPECT_TRUE(resource != NULL);
614         EXPECT_NO_THROW(resource->setHeaderOptions(headerOptions));
615         EXPECT_NO_THROW(resource->unsetHeaderOptions());
616     }
617
618     TEST(HeaderOptionsTest, SetHeaderOptionsEmptyInput)
619     {
620         OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
621         EXPECT_TRUE(resource != NULL);
622         HeaderOptions headerOptions;
623         EXPECT_NO_THROW(resource->setHeaderOptions(headerOptions));
624         EXPECT_NO_THROW(resource->unsetHeaderOptions());
625     }
626 }
627