Initial merge-commit of the OIC code. Should successfully do discovery for single...
[platform/upstream/iotivity.git] / csdk / stack / test / stacktests.cpp
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
5
6
7 extern "C" {
8     #include "ocstack.h"
9     #include "ocstackinternal.h"
10     #include "logger.h"
11 }
12
13 #include "gtest/gtest.h"
14 #include <sys/types.h>
15 #include <sys/stat.h>
16 #include <errno.h>
17 #include <fcntl.h>
18 #include <unistd.h>
19 #include <stdlib.h>
20
21 //-----------------------------------------------------------------------------
22 // Includes
23 //-----------------------------------------------------------------------------
24 #include <stdio.h>
25 #include <string.h>
26
27 #include <iostream>
28 #include <stdint.h>
29 using namespace std;
30
31 #define CTX_VAL 0x99
32 //-----------------------------------------------------------------------------
33 // Private variables
34 //-----------------------------------------------------------------------------
35 static const char TAG[] = "TestHarness";
36 static const char *SERVICE_URI = "coap://127.0.0.1:5683/";
37
38 //-----------------------------------------------------------------------------
39 // Callback functions
40 //-----------------------------------------------------------------------------
41 extern "C"  OCStackApplicationResult asyncDoResourcesCallback(void *ctx, OCClientResponse * clientResponse) {
42     OC_LOG(INFO, TAG, "Entering asyncDoResourcesCallback");
43
44     EXPECT_EQ(OC_STACK_OK, clientResponse->result);
45
46     if(ctx == (void*)CTX_VAL) {
47         OC_LOG_V(INFO, TAG, "Callback Context recvd successfully");
48     }
49     OC_LOG_V(INFO, TAG, "result = %d", clientResponse->result);
50 }
51
52 //-----------------------------------------------------------------------------
53 // Resource creation stuff
54 //-----------------------------------------------------------------------------
55 // TODO - remove, temporarily kept for reference purposes
56 #if 0
57 const char *LEDrep[] = { "state;b", "power;i", (char *)NULL};
58 CREATE_RESOURCE_TYPE(LED, "core.led", LEDrep);
59
60 // Create the state and power attributes
61 char stateValue[] = "0";
62 CREATE_RESOURCE_ATTRIBUTE(stateAttr, "state", stateValue);
63
64 char powerValue[] = "5";
65 CREATE_RESOURCE_ATTRIBUTE(powerAttr, "power", powerValue);
66
67 // Define the interface
68 CREATE_RESOURCE_INTERFACE(LED, "core.rw", OC_REST_GET|OC_REST_PUT);
69
70 // Define the resource; the space is allocated;  but the resource has not been fully initialized
71 CREATE_RESOURCE(LED, "/a/led", &LED_resourcetype, &LED_resourceinterface) ;
72
73
74 // Define the entity handler for the resource
75 void LED_ehandler(OCEntityHandlerFlag flag, const char *request, char *reponse, OCResourceHandle resource) {
76     /* Add code for entity handler */
77 }
78 #endif
79
80 //-----------------------------------------------------------------------------
81 //  Tests
82 //-----------------------------------------------------------------------------
83 TEST(StackTest, StackInitNullAddr) {
84     EXPECT_EQ(OC_STACK_OK, OCInit(0, 5683, OC_SERVER));
85 }
86
87 TEST(StackTest, StackInitNullPort) {
88     EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 0, OC_SERVER));
89 }
90
91 TEST(StackTest, StackInitNullAddrAndPort) {
92     EXPECT_EQ(OC_STACK_OK, OCInit(0, 0, OC_SERVER));
93 }
94
95 TEST(StackTest, StackInitInvalidMode) {
96     EXPECT_EQ(OC_STACK_ERROR, OCInit(0, 0, (OCMode)10));
97 }
98
99 TEST(StackTest, StackStartSuccessClient) {
100     EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT));
101 }
102
103 TEST(StackTest, StackStartSuccessServer) {
104     EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_SERVER));
105 }
106
107 TEST(StackTest, StackStartSuccessClientServer) {
108     EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT_SERVER));
109 }
110
111 TEST(StackTest, StackStartSuccessiveInits) {
112     EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_SERVER));
113     EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.2", 5683, OC_SERVER));
114 }
115
116 TEST(StackTest, DoResourceDeviceDiscovery) {
117     uint8_t addr[20];
118     uint16_t port = USE_RANDOM_PORT;
119     uint8_t ifname[] = "eth0";
120     OCCallbackData cbData;
121
122     /*Get Ip address on defined interface and initialize coap on it with random port number
123      * this port number will be used as a source port in all coap communications*/
124     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
125     OC_LOG_V(INFO, TAG, "Starting DoResourceDeviceDiscovery test on address %s",addr);
126
127     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_CLIENT));
128     /* Start a discovery query*/
129     char szQueryUri[64] = { 0 };
130     strcpy(szQueryUri, OC_WELL_KNOWN_QUERY);
131     cbData.cb = asyncDoResourcesCallback;
132     cbData.context = (void*)CTX_VAL;
133     EXPECT_EQ(OC_STACK_OK, OCDoResource(OC_REST_GET, szQueryUri, 0, 0, OC_NON_CONFIRMABLE, &cbData));
134     //EXPECT_EQ(OC_STACK_OK, OCUpdateResources(SERVICE_URI));
135     EXPECT_EQ(OC_STACK_OK, OCStop());
136 }
137
138 TEST(StackTest, StackStopWithoutInit) {
139     EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT));
140     EXPECT_EQ(OC_STACK_OK, OCStop());
141     EXPECT_EQ(OC_STACK_ERROR, OCStop());
142 }
143
144 TEST(StackTest, UpdateResourceNullURI) {
145     uint8_t addr[20];
146     uint16_t port = USE_RANDOM_PORT;
147     uint8_t ifname[] = "eth0";
148     OCCallbackData cbData;
149
150     /*Get Ip address on defined interface and initialize coap on it with random port number
151      * this port number will be used as a source port in all coap communications*/
152     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
153     OC_LOG_V(INFO, TAG, "Starting UpdateResourceNullURI test on address %s",addr);
154
155     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_CLIENT));
156     /* Start a discovery query*/
157     char szQueryUri[64] = { 0 };
158     strcpy(szQueryUri, OC_WELL_KNOWN_QUERY);
159     cbData.cb = asyncDoResourcesCallback;
160     cbData.context = (void*)CTX_VAL;
161     EXPECT_EQ(OC_STACK_OK, OCDoResource(OC_REST_GET, szQueryUri, 0, 0, OC_NON_CONFIRMABLE, &cbData));
162     //EXPECT_EQ(OC_STACK_INVALID_URI, OCUpdateResources(0));
163     EXPECT_EQ(OC_STACK_OK, OCStop());
164 }
165
166 TEST(StackTest, CreateResourceBadParams) {
167     uint8_t addr[20];
168     uint16_t port = USE_RANDOM_PORT;
169     uint8_t ifname[] = "eth0";
170
171     /*Get Ip address on defined interface and initialize coap on it with random port number
172      * this port number will be used as a source port in all coap communications*/
173     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
174
175     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
176     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
177
178     OCResourceHandle handle;
179     EXPECT_EQ(OC_STACK_ERROR, OCCreateResource(NULL, //&handle,
180                                             "core.led",
181                                             "state:oc.bt.b;power:oc.bt.i",
182                                             "core.rw",
183                                             OC_REST_GET|OC_REST_PUT,
184                                             "/a/led",
185                                             0,
186                                             OC_DISCOVERABLE|OC_OBSERVABLE));
187
188     EXPECT_EQ(OC_STACK_ERROR, OCCreateResource(&handle,
189                                             NULL, //"core.led",
190                                             "state:oc.bt.b;power:oc.bt.i",
191                                             "core.rw",
192                                             OC_REST_GET|OC_REST_PUT,
193                                             "/a/led",
194                                             0,
195                                             OC_DISCOVERABLE|OC_OBSERVABLE));
196
197     // Method bitmask out of range
198     EXPECT_EQ(OC_STACK_ERROR, OCCreateResource(&handle,
199                                             "core.led",
200                                             "state:oc.bt.b;power:oc.bt.i",
201                                             "core.rw",
202                                             32, //OC_REST_GET|OC_REST_PUT,
203                                             "/a/led",
204                                             0,
205                                             OC_DISCOVERABLE|OC_OBSERVABLE));
206     // OC_REST_NOMETHOD
207     EXPECT_EQ(OC_STACK_ERROR, OCCreateResource(&handle,
208                                             "core.led",
209                                             "state:oc.bt.b;power:oc.bt.i",
210                                             "core.rw",
211                                             OC_REST_NOMETHOD, //OC_REST_GET|OC_REST_PUT,
212                                             "/a/led",
213                                             0,
214                                             OC_DISCOVERABLE|OC_OBSERVABLE));
215     // Property bitmask out of range
216     EXPECT_EQ(OC_STACK_ERROR, OCCreateResource(&handle,
217                                             "core.led",
218                                             "state:oc.bt.b;power:oc.bt.i",
219                                             "core.rw",
220                                             OC_REST_GET|OC_REST_PUT,
221                                             "/a/led",
222                                             0,
223                                             16));//OC_DISCOVERABLE|OC_OBSERVABLE));
224 }
225
226 TEST(StackTest, CreateResourceSuccess) {
227     uint8_t addr[20];
228     uint16_t port = USE_RANDOM_PORT;
229     uint8_t ifname[] = "eth0";
230
231     /*Get Ip address on defined interface and initialize coap on it with random port number
232      * this port number will be used as a source port in all coap communications*/
233     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
234
235     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
236     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
237
238     OCResourceHandle handle;
239     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
240                                             "core.led",
241                                             "state:oc.bt.b;power:oc.bt.i",
242                                             "core.rw",
243                                             OC_REST_GET|OC_REST_PUT,
244                                             "/a/led",
245                                             0,
246                                             OC_DISCOVERABLE|OC_OBSERVABLE));
247     const char *url = OCGetResourceUri(handle);
248     EXPECT_STREQ("/a/led", url);
249 }
250
251 TEST(StackTest, CreateResourceFailDuplicateUri) {
252     uint8_t addr[20];
253     uint16_t port = USE_RANDOM_PORT;
254     uint8_t ifname[] = "eth0";
255
256     /*Get Ip address on defined interface and initialize coap on it with random port number
257      * this port number will be used as a source port in all coap communications*/
258     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
259
260     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
261     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
262
263     OCResourceHandle handle;
264     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
265                                             "core.led",
266                                             "state:oc.bt.b;power:oc.bt.i",
267                                             "core.rw",
268                                             OC_REST_GET|OC_REST_PUT,
269                                             "/a/led",
270                                             0,
271                                             OC_DISCOVERABLE|OC_OBSERVABLE));
272     const char *url = OCGetResourceUri(handle);
273     EXPECT_STREQ("/a/led", url);
274
275     EXPECT_EQ(OC_STACK_ERROR, OCCreateResource(&handle,
276                                             "core.led",
277                                             "state:oc.bt.b;power:oc.bt.i",
278                                             "core.rw",
279                                             OC_REST_GET|OC_REST_PUT,
280                                             "/a/led",
281                                             0,
282                                             OC_DISCOVERABLE|OC_OBSERVABLE));
283 }
284
285 TEST(StackTest, CreateResourceMultipleResources) {
286     uint8_t addr[20];
287     uint16_t port = USE_RANDOM_PORT;
288     uint8_t ifname[] = "eth0";
289
290     /*Get Ip address on defined interface and initialize coap on it with random port number
291      * this port number will be used as a source port in all coap communications*/
292     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
293
294     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
295     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
296
297     OCResourceHandle handle1;
298     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle1,
299                                             "core.led",
300                                             "state:oc.bt.b;power:oc.bt.i",
301                                             "core.rw",
302                                             OC_REST_GET|OC_REST_PUT,
303                                             "/a/led1",
304                                             0,
305                                             OC_DISCOVERABLE|OC_OBSERVABLE));
306
307     OCResourceHandle handle2;
308     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle2,
309                                             "core.led",
310                                             "state:oc.bt.b;power:oc.bt.i",
311                                             "core.rw",
312                                             OC_REST_GET|OC_REST_PUT,
313                                             "/a/led2",
314                                             0,
315                                             OC_DISCOVERABLE|OC_OBSERVABLE));
316     OCResourceHandle handle3;
317     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle3,
318                                             "core.led",
319                                             "state:oc.bt.b;power:oc.bt.i",
320                                             "core.rw",
321                                             OC_REST_GET|OC_REST_PUT,
322                                             "/a/led3",
323                                             0,
324                                             OC_DISCOVERABLE|OC_OBSERVABLE));
325
326     const char *url = OCGetResourceUri(handle1);
327     EXPECT_STREQ("/a/led1", url);
328
329     url = OCGetResourceUri(handle2);
330     EXPECT_STREQ("/a/led2", url);
331
332     url = OCGetResourceUri(handle3);
333     EXPECT_STREQ("/a/led3", url);
334
335 }
336
337 TEST(StackTest, CreateResourceBadResoureType) {
338     uint8_t addr[20];
339     uint16_t port = USE_RANDOM_PORT;
340     uint8_t ifname[] = "eth0";
341
342     /*Get Ip address on defined interface and initialize coap on it with random port number
343      * this port number will be used as a source port in all coap communications*/
344     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
345
346     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
347     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
348
349     OCResourceHandle handle;
350     EXPECT_EQ(OC_STACK_ERROR, OCCreateResource(&handle,
351                                             NULL, //"core.led",
352                                             "state:oc.bt.b;power:oc.bt.i",
353                                             "core.rw",
354                                             OC_REST_GET|OC_REST_PUT,
355                                             "/a/led",
356                                             0,
357                                             OC_DISCOVERABLE|OC_OBSERVABLE));
358 }
359
360 TEST(StackTest, CreateResourceGoodResourceType) {
361     uint8_t addr[20];
362     uint16_t port = USE_RANDOM_PORT;
363     uint8_t ifname[] = "eth0";
364
365     /*Get Ip address on defined interface and initialize coap on it with random port number
366      * this port number will be used as a source port in all coap communications*/
367     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
368
369     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
370     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
371
372     OCResourceHandle handle;
373     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
374                                             "core.led",
375                                             "state:oc.bt.b;power:oc.bt.i",
376                                             "core.rw",
377                                             OC_REST_GET|OC_REST_PUT,
378                                             "/a/led",
379                                             0,
380                                             OC_DISCOVERABLE|OC_OBSERVABLE));
381
382 }
383
384 TEST(StackTest, ResourceTypeName) {
385     uint8_t addr[20];
386     uint16_t port = USE_RANDOM_PORT;
387     uint8_t ifname[] = "eth0";
388
389     /*Get Ip address on defined interface and initialize coap on it with random port number
390      * this port number will be used as a source port in all coap communications*/
391     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
392
393     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
394     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
395
396     OCResourceHandle handle;
397     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
398                                             "core.led",
399                                             "state:oc.bt.b;power:oc.bt.i",
400                                             "core.rw",
401                                             OC_REST_GET|OC_REST_PUT,
402                                             "/a/led",
403                                             0,
404                                             OC_DISCOVERABLE|OC_OBSERVABLE));
405
406     uint8_t numResourceTypes;
407     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceTypes(handle, &numResourceTypes));
408     EXPECT_EQ(1, numResourceTypes);
409     const char *resourceTypeName = OCGetResourceTypeName(handle, 0);
410     EXPECT_STREQ("core.led", resourceTypeName);
411
412     // try getting resource type names with an invalid index
413     resourceTypeName = OCGetResourceTypeName(handle, 1);
414     EXPECT_STREQ(NULL, resourceTypeName);
415     // try getting resource type names with an invalid index
416     resourceTypeName = OCGetResourceTypeName(handle, 10);
417     EXPECT_STREQ(NULL, resourceTypeName);
418 }
419
420 TEST(StackTest, BindResourceTypeNameBad) {
421     uint8_t addr[20];
422     uint16_t port = USE_RANDOM_PORT;
423     uint8_t ifname[] = "eth0";
424
425     /*Get Ip address on defined interface and initialize coap on it with random port number
426      * this port number will be used as a source port in all coap communications*/
427     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
428
429     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
430     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
431
432     OCResourceHandle handle;
433     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
434                                             "core.led",
435                                             "state:oc.bt.b;power:oc.bt.i",
436                                             "core.rw",
437                                             OC_REST_GET|OC_REST_PUT,
438                                             "/a/led",
439                                             0,
440                                             OC_DISCOVERABLE|OC_OBSERVABLE));
441
442     uint8_t numResourceTypes;
443     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceTypes(handle, &numResourceTypes));
444     EXPECT_EQ(1, numResourceTypes);
445     const char *resourceTypeName = OCGetResourceTypeName(handle, 0);
446     EXPECT_STREQ("core.led", resourceTypeName);
447
448     EXPECT_EQ(OC_STACK_ERROR, OCBindResourceTypeToResource(handle, NULL, "state:oc.bt.b;power:oc.bt.i"));
449 }
450
451 TEST(StackTest, BindResourceTypeNameGood) {
452     uint8_t addr[20];
453     uint16_t port = USE_RANDOM_PORT;
454     uint8_t ifname[] = "eth0";
455
456     /*Get Ip address on defined interface and initialize coap on it with random port number
457      * this port number will be used as a source port in all coap communications*/
458     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
459
460     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
461     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
462
463     OCResourceHandle handle;
464     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
465                                             "core.led",
466                                             "state:oc.bt.b;power:oc.bt.i",
467                                             "core.rw",
468                                             OC_REST_GET|OC_REST_PUT,
469                                             "/a/led",
470                                             0,
471                                             OC_DISCOVERABLE|OC_OBSERVABLE));
472
473     uint8_t numResourceTypes;
474     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceTypes(handle, &numResourceTypes));
475     EXPECT_EQ(1, numResourceTypes);
476     const char *resourceTypeName = OCGetResourceTypeName(handle, 0);
477     EXPECT_STREQ("core.led", resourceTypeName);
478
479     EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle, "core.brightled", "state:oc.bt.b;power:oc.bt.i"));
480     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceTypes(handle, &numResourceTypes));
481     EXPECT_EQ(2, numResourceTypes);
482     resourceTypeName = OCGetResourceTypeName(handle, 1);
483     EXPECT_STREQ("core.brightled", resourceTypeName);
484
485     EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle, "core.reallybrightled", "state:oc.bt.b;power:oc.bt.i"));
486     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceTypes(handle, &numResourceTypes));
487     EXPECT_EQ(3, numResourceTypes);
488     resourceTypeName = OCGetResourceTypeName(handle, 2);
489     EXPECT_STREQ("core.reallybrightled", resourceTypeName);
490
491 }
492
493 TEST(StackTest, ResourceTypeAttrRepresentation) {
494     uint8_t addr[20];
495     uint16_t port = USE_RANDOM_PORT;
496     uint8_t ifname[] = "eth0";
497
498     /*Get Ip address on defined interface and initialize coap on it with random port number
499      * this port number will be used as a source port in all coap communications*/
500     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
501
502     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
503     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
504
505     OCResourceHandle handle;
506     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
507                                             "core.led",
508                                             "state:oc.bt.b;power:oc.bt.i",
509                                             "core.rw",
510                                             OC_REST_GET|OC_REST_PUT,
511                                             "/a/led",
512                                             0,
513                                             OC_DISCOVERABLE|OC_OBSERVABLE));
514
515     uint8_t numResourceTypes;
516     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceTypes(handle, &numResourceTypes));
517     EXPECT_EQ(1, numResourceTypes);
518     const char *resourceTypeAttrRepresentation = OCGetResourceAttributeRepresentation(handle, 0);
519     EXPECT_STREQ("state:oc.bt.b;power:oc.bt.i", resourceTypeAttrRepresentation);
520
521     // try getting resource type attribute representations with an invalid index
522     resourceTypeAttrRepresentation = OCGetResourceAttributeRepresentation(handle, 1);
523     EXPECT_STREQ(NULL, resourceTypeAttrRepresentation);
524     // try getting resource type names with an invalid index
525     resourceTypeAttrRepresentation = OCGetResourceAttributeRepresentation(handle, 10);
526     EXPECT_STREQ(NULL, resourceTypeAttrRepresentation);
527 }
528
529 TEST(StackTest, BindResourceTypeAttribRepGood) {
530     uint8_t addr[20];
531     uint16_t port = USE_RANDOM_PORT;
532     uint8_t ifname[] = "eth0";
533
534     /*Get Ip address on defined interface and initialize coap on it with random port number
535      * this port number will be used as a source port in all coap communications*/
536     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
537
538     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
539     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
540
541     OCResourceHandle handle;
542     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
543                                             "core.led",
544                                             "state:oc.bt.b",
545                                             "core.rw",
546                                             OC_REST_GET|OC_REST_PUT,
547                                             "/a/led",
548                                             0,
549                                             OC_DISCOVERABLE|OC_OBSERVABLE));
550
551     uint8_t numResourceTypes;
552     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceTypes(handle, &numResourceTypes));
553     EXPECT_EQ(1, numResourceTypes);
554     const char *resourceTypeAttrRepresentation = OCGetResourceAttributeRepresentation(handle, 0);
555     EXPECT_STREQ("state:oc.bt.b", resourceTypeAttrRepresentation);
556
557     EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle, "core.brightled", "state:oc.bt.b;power:oc.bt.i"));
558     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceTypes(handle, &numResourceTypes));
559     EXPECT_EQ(2, numResourceTypes);
560     resourceTypeAttrRepresentation = OCGetResourceAttributeRepresentation(handle, 1);
561     EXPECT_STREQ("state:oc.bt.b;power:oc.bt.i", resourceTypeAttrRepresentation);
562
563     EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle, "core.reallybrightled", "state:oc.bt.b;power:oc.bt.i;temp:oc.bt.i"));
564     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceTypes(handle, &numResourceTypes));
565     EXPECT_EQ(3, numResourceTypes);
566     resourceTypeAttrRepresentation = OCGetResourceAttributeRepresentation(handle, 2);
567     EXPECT_STREQ("state:oc.bt.b;power:oc.bt.i;temp:oc.bt.i", resourceTypeAttrRepresentation);
568 }
569
570 TEST(StackTest, ResourceTypeInterface) {
571     uint8_t addr[20];
572     uint16_t port = USE_RANDOM_PORT;
573     uint8_t ifname[] = "eth0";
574
575     /*Get Ip address on defined interface and initialize coap on it with random port number
576      * this port number will be used as a source port in all coap communications*/
577     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
578
579     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
580     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
581
582     OCResourceHandle handle;
583     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
584                                             "core.led",
585                                             "state:oc.bt.b;power:oc.bt.i",
586                                             "core.rw",
587                                             OC_REST_GET|OC_REST_PUT,
588                                             "/a/led",
589                                             0,
590                                             OC_DISCOVERABLE|OC_OBSERVABLE));
591
592     uint8_t numResourceInterfaces;
593     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
594     EXPECT_EQ(1, numResourceInterfaces);
595     const char *resourceInterfaceName = OCGetResourceInterfaceName(handle, 0);
596     EXPECT_STREQ("core.rw", resourceInterfaceName);
597
598     // try getting resource interface names with an invalid index
599     resourceInterfaceName = OCGetResourceInterfaceName(handle, 1);
600     EXPECT_STREQ(NULL, resourceInterfaceName);
601     // try getting resource interface names with an invalid index
602     resourceInterfaceName = OCGetResourceInterfaceName(handle, 10);
603     EXPECT_STREQ(NULL, resourceInterfaceName);
604 }
605
606 TEST(StackTest, BindResourceInterfaceNameBad) {
607     uint8_t addr[20];
608     uint16_t port = USE_RANDOM_PORT;
609     uint8_t ifname[] = "eth0";
610
611     /*Get Ip address on defined interface and initialize coap on it with random port number
612      * this port number will be used as a source port in all coap communications*/
613     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
614
615     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
616     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
617
618     OCResourceHandle handle;
619     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
620                                             "core.led",
621                                             "state:oc.bt.b;power:oc.bt.i",
622                                             "core.rw",
623                                             OC_REST_GET|OC_REST_PUT,
624                                             "/a/led",
625                                             0,
626                                             OC_DISCOVERABLE|OC_OBSERVABLE));
627
628     uint8_t numResourceInterfaces;
629     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
630     EXPECT_EQ(1, numResourceInterfaces);
631     const char *resourceInterfaceName = OCGetResourceInterfaceName(handle, 0);
632     EXPECT_STREQ("core.rw", resourceInterfaceName);
633
634     EXPECT_EQ(OC_STACK_ERROR, OCBindResourceInterfaceToResource(handle, NULL, OC_REST_GET|OC_REST_PUT));
635 }
636
637 TEST(StackTest, BindResourceInterfaceNameGood) {
638     uint8_t addr[20];
639     uint16_t port = USE_RANDOM_PORT;
640     uint8_t ifname[] = "eth0";
641
642     /*Get Ip address on defined interface and initialize coap on it with random port number
643      * this port number will be used as a source port in all coap communications*/
644     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
645
646     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
647     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
648
649     OCResourceHandle handle;
650     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
651                                             "core.led",
652                                             "state:oc.bt.b;power:oc.bt.i",
653                                             "core.rw",
654                                             OC_REST_GET|OC_REST_PUT,
655                                             "/a/led",
656                                             0,
657                                             OC_DISCOVERABLE|OC_OBSERVABLE));
658
659     uint8_t numResourceInterfaces;
660     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
661     EXPECT_EQ(1, numResourceInterfaces);
662     const char *resourceInterfaceName = OCGetResourceInterfaceName(handle, 0);
663     EXPECT_STREQ("core.rw", resourceInterfaceName);
664
665     EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle, "core.r", OC_REST_GET|OC_REST_PUT));
666
667     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
668     EXPECT_EQ(2, numResourceInterfaces);
669     resourceInterfaceName = OCGetResourceInterfaceName(handle, 1);
670     EXPECT_STREQ("core.r", resourceInterfaceName);
671 }
672
673 TEST(StackTest, ResourceTypeInterfaceMethods) {
674     uint8_t addr[20];
675     uint16_t port = USE_RANDOM_PORT;
676     uint8_t ifname[] = "eth0";
677
678     /*Get Ip address on defined interface and initialize coap on it with random port number
679      * this port number will be used as a source port in all coap communications*/
680     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
681
682     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
683     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
684
685     OCResourceHandle handle;
686     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
687                                             "core.led",
688                                             "state:oc.bt.b;power:oc.bt.i",
689                                             "core.rw",
690                                             OC_REST_GET|OC_REST_PUT,
691                                             "/a/led",
692                                             0,
693                                             OC_DISCOVERABLE|OC_OBSERVABLE));
694
695     uint8_t numResourceInterfaces;
696     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
697     EXPECT_EQ(1, numResourceInterfaces);
698     uint8_t resourceInterfaceMethods = OCGetResourceInterfaceAllowedMethods(handle, 0);
699     EXPECT_EQ(OC_REST_GET|OC_REST_PUT, resourceInterfaceMethods);
700
701     // try getting resource interface methods with an invalid index
702     resourceInterfaceMethods = OCGetResourceInterfaceAllowedMethods(handle, 1);
703     EXPECT_EQ(0, resourceInterfaceMethods);
704     // try getting resource interface methods with an invalid index
705     resourceInterfaceMethods = OCGetResourceInterfaceAllowedMethods(handle, 10);
706     EXPECT_EQ(0, resourceInterfaceMethods);
707 }
708
709 TEST(StackTest, BindResourceInterfaceMethodsBad) {
710     uint8_t addr[20];
711     uint16_t port = USE_RANDOM_PORT;
712     uint8_t ifname[] = "eth0";
713
714     /*Get Ip address on defined interface and initialize coap on it with random port number
715      * this port number will be used as a source port in all coap communications*/
716     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
717
718     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
719     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
720
721     OCResourceHandle handle;
722     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
723                                             "core.led",
724                                             "state:oc.bt.b;power:oc.bt.i",
725                                             "core.rw",
726                                             OC_REST_GET|OC_REST_PUT,
727                                             "/a/led",
728                                             0,
729                                             OC_DISCOVERABLE|OC_OBSERVABLE));
730
731     uint8_t numResourceInterfaces;
732     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
733     EXPECT_EQ(1, numResourceInterfaces);
734     uint8_t resourceInterfaceMethods = OCGetResourceInterfaceAllowedMethods(handle, 0);
735     EXPECT_EQ(OC_REST_GET|OC_REST_PUT, resourceInterfaceMethods);
736
737     EXPECT_EQ(OC_STACK_ERROR, OCBindResourceInterfaceToResource(handle, "core.rw", OC_REST_NOMETHOD));
738 }
739
740 TEST(StackTest, BindResourceInterfaceMethodsGood) {
741     uint8_t addr[20];
742     uint16_t port = USE_RANDOM_PORT;
743     uint8_t ifname[] = "eth0";
744
745     /*Get Ip address on defined interface and initialize coap on it with random port number
746      * this port number will be used as a source port in all coap communications*/
747     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
748
749     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
750     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
751
752     OCResourceHandle handle;
753     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
754                                             "core.led",
755                                             "state:oc.bt.b;power:oc.bt.i",
756                                             "core.rw",
757                                             OC_REST_GET|OC_REST_PUT,
758                                             "/a/led",
759                                             0,
760                                             OC_DISCOVERABLE|OC_OBSERVABLE));
761
762     uint8_t numResourceInterfaces;
763     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
764     EXPECT_EQ(1, numResourceInterfaces);
765     uint8_t resourceInterfaceMethods = OCGetResourceInterfaceAllowedMethods(handle, 0);
766     EXPECT_EQ(OC_REST_GET|OC_REST_PUT, resourceInterfaceMethods);
767
768     EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle, "core.r", OC_REST_PUT));
769
770     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
771     EXPECT_EQ(2, numResourceInterfaces);
772     resourceInterfaceMethods = OCGetResourceInterfaceAllowedMethods(handle, 1);
773     EXPECT_EQ(OC_REST_PUT, resourceInterfaceMethods);
774 }
775
776 TEST(StackTest, BindContainedResourceBad) {
777     uint8_t addr[20];
778     uint16_t port = USE_RANDOM_PORT;
779     uint8_t ifname[] = "eth0";
780
781     /*Get Ip address on defined interface and initialize coap on it with random port number
782      * this port number will be used as a source port in all coap communications*/
783     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
784
785     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
786     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
787
788     OCResourceHandle containerHandle;
789     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&containerHandle,
790                                             "core.led",
791                                             "state:oc.bt.b;power:oc.bt.i",
792                                             "core.rw",
793                                             OC_REST_GET|OC_REST_PUT,
794                                             "/a/kitchen",
795                                             0,
796                                             OC_DISCOVERABLE|OC_OBSERVABLE));
797
798     OCResourceHandle handle0;
799     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle0,
800                                             "core.led",
801                                             "state:oc.bt.b;power:oc.bt.i",
802                                             "core.rw",
803                                             OC_REST_GET|OC_REST_PUT,
804                                             "/a/led",
805                                             0,
806                                             OC_DISCOVERABLE|OC_OBSERVABLE));
807
808     EXPECT_EQ(OC_STACK_ERROR, OCBindContainedResourceToResource(containerHandle, containerHandle));
809
810     OCResourceHandle handle1;
811     EXPECT_EQ(OC_STACK_ERROR, OCBindContainedResourceToResource(handle1, handle0));
812 }
813
814 TEST(StackTest, BindContainedResourceGood) {
815     uint8_t addr[20];
816     uint16_t port = USE_RANDOM_PORT;
817     uint8_t ifname[] = "eth0";
818
819     /*Get Ip address on defined interface and initialize coap on it with random port number
820      * this port number will be used as a source port in all coap communications*/
821     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
822
823     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
824     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
825
826     uint8_t numResources = 0;
827     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
828     EXPECT_EQ(0, numResources);
829
830     OCResourceHandle containerHandle;
831     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&containerHandle,
832                                             "core.led",
833                                             "state:oc.bt.b;power:oc.bt.i",
834                                             "core.rw",
835                                             OC_REST_GET|OC_REST_PUT,
836                                             "/a/kitchen",
837                                             0,
838                                             OC_DISCOVERABLE|OC_OBSERVABLE));
839     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
840     EXPECT_EQ(1, numResources);
841
842     OCResourceHandle handle0;
843     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle0,
844                                             "core.led",
845                                             "state:oc.bt.b;power:oc.bt.i",
846                                             "core.rw",
847                                             OC_REST_GET|OC_REST_PUT,
848                                             "/a/led0",
849                                             0,
850                                             OC_DISCOVERABLE|OC_OBSERVABLE));
851     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
852     EXPECT_EQ(2, numResources);
853
854     OCResourceHandle handle1;
855     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle1,
856                                             "core.led",
857                                             "state:oc.bt.b;power:oc.bt.i",
858                                             "core.rw",
859                                             OC_REST_GET|OC_REST_PUT,
860                                             "/a/led1",
861                                             0,
862                                             OC_DISCOVERABLE|OC_OBSERVABLE));
863     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
864     EXPECT_EQ(3, numResources);
865
866     OCResourceHandle handle2;
867     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle2,
868                                             "core.led",
869                                             "state:oc.bt.b;power:oc.bt.i",
870                                             "core.rw",
871                                             OC_REST_GET|OC_REST_PUT,
872                                             "/a/led2",
873                                             0,
874                                             OC_DISCOVERABLE|OC_OBSERVABLE));
875     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
876     EXPECT_EQ(4, numResources);
877
878     OCResourceHandle handle3;
879     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle3,
880                                             "core.led",
881                                             "state:oc.bt.b;power:oc.bt.i",
882                                             "core.rw",
883                                             OC_REST_GET|OC_REST_PUT,
884                                             "/a/led3",
885                                             0,
886                                             OC_DISCOVERABLE|OC_OBSERVABLE));
887     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
888     EXPECT_EQ(5, numResources);
889
890     OCResourceHandle handle4;
891     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle4,
892                                             "core.led",
893                                             "state:oc.bt.b;power:oc.bt.i",
894                                             "core.rw",
895                                             OC_REST_GET|OC_REST_PUT,
896                                             "/a/led4",
897                                             0,
898                                             OC_DISCOVERABLE|OC_OBSERVABLE));
899     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
900     EXPECT_EQ(6, numResources);
901
902     OCResourceHandle handle5;
903     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle5,
904                                             "core.led",
905                                             "state:oc.bt.b;power:oc.bt.i",
906                                             "core.rw",
907                                             OC_REST_GET|OC_REST_PUT,
908                                             "/a/led5",
909                                             0,
910                                             OC_DISCOVERABLE|OC_OBSERVABLE));
911     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
912     EXPECT_EQ(7, numResources);
913
914
915     EXPECT_EQ(OC_STACK_OK, OCBindContainedResourceToResource(containerHandle, handle0));
916     EXPECT_EQ(OC_STACK_OK, OCBindContainedResourceToResource(containerHandle, handle1));
917     EXPECT_EQ(OC_STACK_OK, OCBindContainedResourceToResource(containerHandle, handle2));
918     EXPECT_EQ(OC_STACK_OK, OCBindContainedResourceToResource(containerHandle, handle3));
919     EXPECT_EQ(OC_STACK_OK, OCBindContainedResourceToResource(containerHandle, handle4));
920     EXPECT_EQ(OC_STACK_ERROR, OCBindContainedResourceToResource(containerHandle, handle5));
921
922     EXPECT_EQ(handle0, OCGetContainedResourceHandle(containerHandle, 0));
923     EXPECT_EQ(handle1, OCGetContainedResourceHandle(containerHandle, 1));
924     EXPECT_EQ(handle2, OCGetContainedResourceHandle(containerHandle, 2));
925     EXPECT_EQ(handle3, OCGetContainedResourceHandle(containerHandle, 3));
926     EXPECT_EQ(handle4, OCGetContainedResourceHandle(containerHandle, 4));
927
928     EXPECT_EQ(NULL, OCGetContainedResourceHandle(containerHandle, 5));
929 }
930
931 TEST(StackTest, GetResourceByIndex) {
932     uint8_t addr[20];
933     uint16_t port = USE_RANDOM_PORT;
934     uint8_t ifname[] = "eth0";
935
936     /*Get Ip address on defined interface and initialize coap on it with random port number
937      * this port number will be used as a source port in all coap communications*/
938     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
939
940     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
941     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
942
943     uint8_t numResources = 0;
944     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
945     EXPECT_EQ(0, numResources);
946
947     OCResourceHandle containerHandle;
948     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&containerHandle,
949                                             "core.led",
950                                             "state:oc.bt.b;power:oc.bt.i",
951                                             "core.rw",
952                                             OC_REST_GET|OC_REST_PUT,
953                                             "/a/kitchen",
954                                             0,
955                                             OC_DISCOVERABLE|OC_OBSERVABLE));
956     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
957     EXPECT_EQ(1, numResources);
958
959     OCResourceHandle handle0;
960     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle0,
961                                             "core.led",
962                                             "state:oc.bt.b;power:oc.bt.i",
963                                             "core.rw",
964                                             OC_REST_GET|OC_REST_PUT,
965                                             "/a/led0",
966                                             0,
967                                             OC_DISCOVERABLE|OC_OBSERVABLE));
968     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
969     EXPECT_EQ(2, numResources);
970
971     OCResourceHandle handle1;
972     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle1,
973                                             "core.led",
974                                             "state:oc.bt.b;power:oc.bt.i",
975                                             "core.rw",
976                                             OC_REST_GET|OC_REST_PUT,
977                                             "/a/led1",
978                                             0,
979                                             OC_DISCOVERABLE|OC_OBSERVABLE));
980     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
981     EXPECT_EQ(3, numResources);
982
983     OCResourceHandle handle2;
984     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle2,
985                                             "core.led",
986                                             "state:oc.bt.b;power:oc.bt.i",
987                                             "core.rw",
988                                             OC_REST_GET|OC_REST_PUT,
989                                             "/a/led2",
990                                             0,
991                                             OC_DISCOVERABLE|OC_OBSERVABLE));
992     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
993     EXPECT_EQ(4, numResources);
994
995     OCResourceHandle handle3;
996     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle3,
997                                             "core.led",
998                                             "state:oc.bt.b;power:oc.bt.i",
999                                             "core.rw",
1000                                             OC_REST_GET|OC_REST_PUT,
1001                                             "/a/led3",
1002                                             0,
1003                                             OC_DISCOVERABLE|OC_OBSERVABLE));
1004     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1005     EXPECT_EQ(5, numResources);
1006
1007     OCResourceHandle handle4;
1008     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle4,
1009                                             "core.led",
1010                                             "state:oc.bt.b;power:oc.bt.i",
1011                                             "core.rw",
1012                                             OC_REST_GET|OC_REST_PUT,
1013                                             "/a/led4",
1014                                             0,
1015                                             OC_DISCOVERABLE|OC_OBSERVABLE));
1016     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1017     EXPECT_EQ(6, numResources);
1018
1019     OCResourceHandle handle5;
1020     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle5,
1021                                             "core.led",
1022                                             "state:oc.bt.b;power:oc.bt.i",
1023                                             "core.rw",
1024                                             OC_REST_GET|OC_REST_PUT,
1025                                             "/a/led5",
1026                                             0,
1027                                             OC_DISCOVERABLE|OC_OBSERVABLE));
1028     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1029     EXPECT_EQ(7, numResources);
1030
1031     EXPECT_EQ(containerHandle, OCGetResourceHandle(0));
1032     EXPECT_EQ(handle0, OCGetResourceHandle(1));
1033     EXPECT_EQ(handle1, OCGetResourceHandle(2));
1034     EXPECT_EQ(handle2, OCGetResourceHandle(3));
1035     EXPECT_EQ(handle3, OCGetResourceHandle(4));
1036     EXPECT_EQ(handle4, OCGetResourceHandle(5));
1037     EXPECT_EQ(handle5, OCGetResourceHandle(6));
1038
1039 }
1040
1041 TEST(StackTest, BindEntityHandlerBad) {
1042     uint8_t addr[20];
1043     uint16_t port = USE_RANDOM_PORT;
1044     uint8_t ifname[] = "eth0";
1045
1046     /*Get Ip address on defined interface and initialize coap on it with random port number
1047      * this port number will be used as a source port in all coap communications*/
1048     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
1049
1050     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
1051     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
1052
1053     OCResourceHandle handle;
1054     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
1055                                             "core.led",
1056                                             "state:oc.bt.b;power:oc.bt.i",
1057                                             "core.rw",
1058                                             OC_REST_GET|OC_REST_PUT,
1059                                             "/a/led",
1060                                             0,
1061                                             OC_DISCOVERABLE|OC_OBSERVABLE));
1062
1063     EXPECT_EQ(OC_STACK_ERROR, OCBindResourceHandler(handle, NULL));
1064     EXPECT_EQ(OC_STACK_ERROR, OCBindResourceHandler(NULL, NULL));
1065 }
1066
1067
1068 void entityHandler(OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest) {
1069     OC_LOG(INFO, TAG, "Entering entityHandler");
1070 }
1071
1072 TEST(StackTest, BindEntityHandlerGood) {
1073     uint8_t addr[20];
1074     uint16_t port = USE_RANDOM_PORT;
1075     uint8_t ifname[] = "eth0";
1076
1077     /*Get Ip address on defined interface and initialize coap on it with random port number
1078      * this port number will be used as a source port in all coap communications*/
1079     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
1080
1081     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
1082     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
1083
1084     OCResourceHandle handle;
1085     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
1086                                             "core.led",
1087                                             "state:oc.bt.b;power:oc.bt.i",
1088                                             "core.rw",
1089                                             OC_REST_GET|OC_REST_PUT,
1090                                             "/a/led",
1091                                             0,
1092                                             OC_DISCOVERABLE|OC_OBSERVABLE));
1093
1094     OCEntityHandler myHandler = entityHandler;
1095
1096     EXPECT_EQ(OC_STACK_OK, OCBindResourceHandler(handle, myHandler));
1097
1098     EXPECT_EQ(myHandler, OCGetResourceHandler(handle));
1099 }
1100
1101 TEST(StackTest, DeleteHeadResource) {
1102     uint8_t addr[20];
1103     uint16_t port = USE_RANDOM_PORT;
1104     uint8_t ifname[] = "eth0";
1105
1106     /*Get Ip address on defined interface and initialize coap on it with random port number
1107      * this port number will be used as a source port in all coap communications*/
1108     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
1109
1110     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
1111     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
1112
1113     uint8_t numResources = 0;
1114     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1115     EXPECT_EQ(0, numResources);
1116
1117     OCResourceHandle handle0;
1118     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle0,
1119                                             "core.led",
1120                                             "state:oc.bt.b;power:oc.bt.i",
1121                                             "core.rw",
1122                                             OC_REST_GET|OC_REST_PUT,
1123                                             "/a/led0",
1124                                             0,
1125                                             OC_DISCOVERABLE|OC_OBSERVABLE));
1126     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1127     EXPECT_EQ(1, numResources);
1128
1129     EXPECT_EQ(OC_STACK_OK, OCDeleteResource(handle0));
1130     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1131     EXPECT_EQ(0, numResources);
1132 }
1133
1134 TEST(StackTest, DeleteHeadResource2) {
1135     uint8_t addr[20];
1136     uint16_t port = USE_RANDOM_PORT;
1137     uint8_t ifname[] = "eth0";
1138
1139     /*Get Ip address on defined interface and initialize coap on it with random port number
1140      * this port number will be used as a source port in all coap communications*/
1141     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
1142
1143     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
1144     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
1145
1146     uint8_t numResources = 0;
1147     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1148     EXPECT_EQ(0, numResources);
1149
1150     OCResourceHandle handle0;
1151     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle0,
1152                                             "core.led",
1153                                             "state:oc.bt.b;power:oc.bt.i",
1154                                             "core.rw",
1155                                             OC_REST_GET|OC_REST_PUT,
1156                                             "/a/led0",
1157                                             0,
1158                                             OC_DISCOVERABLE|OC_OBSERVABLE));
1159     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1160     EXPECT_EQ(1, numResources);
1161
1162     OCResourceHandle handle1;
1163     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle1,
1164                                             "core.led",
1165                                             "state:oc.bt.b;power:oc.bt.i",
1166                                             "core.rw",
1167                                             OC_REST_GET|OC_REST_PUT,
1168                                             "/a/led1",
1169                                             0,
1170                                             OC_DISCOVERABLE|OC_OBSERVABLE));
1171     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1172     EXPECT_EQ(2, numResources);
1173
1174     EXPECT_EQ(OC_STACK_OK, OCDeleteResource(handle0));
1175     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1176     EXPECT_EQ(1, numResources);
1177
1178     EXPECT_EQ(handle1, OCGetResourceHandle(0));
1179 }
1180
1181
1182 TEST(StackTest, DeleteLastResource) {
1183     uint8_t addr[20];
1184     uint16_t port = USE_RANDOM_PORT;
1185     uint8_t ifname[] = "eth0";
1186
1187     /*Get Ip address on defined interface and initialize coap on it with random port number
1188      * this port number will be used as a source port in all coap communications*/
1189     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
1190
1191     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
1192     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
1193
1194     uint8_t numResources = 0;
1195     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1196     EXPECT_EQ(0, numResources);
1197
1198     OCResourceHandle handle0;
1199     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle0,
1200                                             "core.led",
1201                                             "state:oc.bt.b;power:oc.bt.i",
1202                                             "core.rw",
1203                                             OC_REST_GET|OC_REST_PUT,
1204                                             "/a/led0",
1205                                             0,
1206                                             OC_DISCOVERABLE|OC_OBSERVABLE));
1207     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1208     EXPECT_EQ(1, numResources);
1209
1210     OCResourceHandle handle1;
1211     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle1,
1212                                             "core.led",
1213                                             "state:oc.bt.b;power:oc.bt.i",
1214                                             "core.rw",
1215                                             OC_REST_GET|OC_REST_PUT,
1216                                             "/a/led1",
1217                                             0,
1218                                             OC_DISCOVERABLE|OC_OBSERVABLE));
1219     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1220     EXPECT_EQ(2, numResources);
1221
1222     EXPECT_EQ(OC_STACK_OK, OCDeleteResource(handle1));
1223     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1224     EXPECT_EQ(1, numResources);
1225
1226     EXPECT_EQ(handle0, OCGetResourceHandle(0));
1227
1228     OCResourceHandle handle2;
1229     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle2,
1230                                             "core.led",
1231                                             "state:oc.bt.b;power:oc.bt.i",
1232                                             "core.rw",
1233                                             OC_REST_GET|OC_REST_PUT,
1234                                             "/a/led2",
1235                                             0,
1236                                             OC_DISCOVERABLE|OC_OBSERVABLE));
1237     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1238     EXPECT_EQ(2, numResources);
1239 }
1240
1241 TEST(StackTest, DeleteMiddleResource) {
1242     uint8_t addr[20];
1243     uint16_t port = USE_RANDOM_PORT;
1244     uint8_t ifname[] = "eth0";
1245
1246     /*Get Ip address on defined interface and initialize coap on it with random port number
1247      * this port number will be used as a source port in all coap communications*/
1248     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
1249
1250     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
1251     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
1252
1253     uint8_t numResources = 0;
1254     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1255     EXPECT_EQ(0, numResources);
1256
1257     OCResourceHandle handle0;
1258     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle0,
1259                                             "core.led",
1260                                             "state:oc.bt.b;power:oc.bt.i",
1261                                             "core.rw",
1262                                             OC_REST_GET|OC_REST_PUT,
1263                                             "/a/led0",
1264                                             0,
1265                                             OC_DISCOVERABLE|OC_OBSERVABLE));
1266     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1267     EXPECT_EQ(1, numResources);
1268
1269     OCResourceHandle handle1;
1270     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle1,
1271                                             "core.led",
1272                                             "state:oc.bt.b;power:oc.bt.i",
1273                                             "core.rw",
1274                                             OC_REST_GET|OC_REST_PUT,
1275                                             "/a/led1",
1276                                             0,
1277                                             OC_DISCOVERABLE|OC_OBSERVABLE));
1278     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1279     EXPECT_EQ(2, numResources);
1280
1281     OCResourceHandle handle2;
1282     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle2,
1283                                             "core.led",
1284                                             "state:oc.bt.b;power:oc.bt.i",
1285                                             "core.rw",
1286                                             OC_REST_GET|OC_REST_PUT,
1287                                             "/a/led2",
1288                                             0,
1289                                             OC_DISCOVERABLE|OC_OBSERVABLE));
1290     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1291     EXPECT_EQ(3, numResources);
1292
1293     EXPECT_EQ(OC_STACK_OK, OCDeleteResource(handle1));
1294     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1295     EXPECT_EQ(2, numResources);
1296
1297     EXPECT_EQ(handle0, OCGetResourceHandle(0));
1298     EXPECT_EQ(handle2, OCGetResourceHandle(1));
1299
1300     // Make sure the resource elements are still correct
1301     uint8_t numResourceInterfaces;
1302     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle2, &numResourceInterfaces));
1303     EXPECT_EQ(1, numResourceInterfaces);
1304     const char *resourceInterfaceName = OCGetResourceInterfaceName(handle2, 0);
1305     EXPECT_STREQ("core.rw", resourceInterfaceName);
1306 }
1307
1308 TEST(StackTest, GetResourceProperties) {
1309     uint8_t addr[20];
1310     uint16_t port = USE_RANDOM_PORT;
1311     uint8_t ifname[] = "eth0";
1312
1313     /*Get Ip address on defined interface and initialize coap on it with random port number
1314      * this port number will be used as a source port in all coap communications*/
1315     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
1316
1317     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
1318     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
1319
1320     OCResourceHandle handle;
1321     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
1322                                             "core.led",
1323                                             "state:oc.bt.b;power:oc.bt.i",
1324                                             "core.rw",
1325                                             OC_REST_GET|OC_REST_PUT,
1326                                             "/a/led",
1327                                             0,
1328                                             OC_DISCOVERABLE|OC_OBSERVABLE));
1329
1330     EXPECT_EQ(OC_ACTIVE|OC_DISCOVERABLE|OC_OBSERVABLE, OCGetResourceProperties(handle));
1331     EXPECT_EQ(OC_STACK_OK, OCDeleteResource(handle));
1332 }
1333
1334 TEST(StackTest, StackTestResourceDiscoverOneResourceBad) {
1335     // Setting URI to null which is an error
1336     char uri[] = "";
1337     char query[] = "";
1338     char req[1024] = {};
1339     char rsp[1024] = {};
1340     //OCServerRequestResult res;
1341
1342     OCResourceHandle handle;
1343     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
1344                                             "core.led",
1345                                             "state:oc.bt.b;power:oc.bt.i",
1346                                             "core.rw",
1347                                             OC_REST_GET|OC_REST_PUT,
1348                                             "/a1/led",
1349                                             0,
1350                                             OC_DISCOVERABLE|OC_OBSERVABLE));
1351     const char *url = OCGetResourceUri(handle);
1352     EXPECT_STREQ("/a1/led", url);
1353
1354     //EXPECT_EQ(OC_STACK_INVALID_URI, OCHandleServerRequest(&res, uri, query, req, rsp));
1355     EXPECT_EQ(OC_STACK_OK, OCDeleteResource(handle));
1356     uint8_t numResources = 0;
1357     EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
1358     EXPECT_EQ(0, numResources);
1359
1360 }
1361
1362 TEST(StackTest, StackTestResourceDiscoverOneResource) {
1363     char uri[] = "/oc/core";
1364     char query[] = "";
1365     char req[1024] = {};
1366     char rsp[1024] = {};
1367     //OCServerRequestResult res;
1368
1369     OCResourceHandle handle;
1370     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
1371                                             "core.led",
1372                                             "state:oc.bt.b;power:oc.bt.i",
1373                                             "core.rw",
1374                                             OC_REST_GET|OC_REST_PUT,
1375                                             "/a/led",
1376                                             0,
1377                                             OC_DISCOVERABLE|OC_OBSERVABLE));
1378     const char *url = OCGetResourceUri(handle);
1379     EXPECT_STREQ("/a/led", url);
1380
1381     //EXPECT_EQ(OC_STACK_OK, OCHandleServerRequest(&res, uri, query, req, rsp));
1382     EXPECT_EQ(OC_STACK_OK, OCDeleteResource(handle));
1383 }
1384
1385 TEST(StackTest, StackTestResourceDiscoverManyResources) {
1386     uint8_t addr[20];
1387     uint16_t port = USE_RANDOM_PORT;
1388     uint8_t ifname[] = "eth0";
1389     char uri[] = "/oc/core";
1390     char query[] = "";
1391     char req[1024] = {};
1392     char rsp[1024] = {};
1393     //OCServerRequestResult res;
1394
1395     /*Get Ip address on defined interface and initialize coap on it with random port number
1396      * this port number will be used as a source port in all coap communications*/
1397     OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
1398
1399     OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
1400     EXPECT_EQ(OC_STACK_OK, OCInit((char *) addr, port, OC_SERVER));
1401
1402     OCResourceHandle handle1;
1403     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle1,
1404                                             "core.led",
1405                                             "state:oc.bt.b;power:oc.bt.i",
1406                                             "core.rw",
1407                                             OC_REST_GET|OC_REST_PUT,
1408                                             "/a/led1",
1409                                             0,
1410                                             OC_DISCOVERABLE));
1411     const char *url = OCGetResourceUri(handle1);
1412     EXPECT_STREQ("/a/led1", url);
1413
1414     OCResourceHandle handle2;
1415     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle2,
1416                                             "core.led",
1417                                             "state:oc.bt.b;power:oc.bt.i",
1418                                             "core.rw",
1419                                             OC_REST_GET|OC_REST_PUT,
1420                                             "/a/led2",
1421                                             0,
1422                                             OC_DISCOVERABLE|OC_OBSERVABLE));
1423     url = OCGetResourceUri(handle2);
1424     EXPECT_STREQ("/a/led2", url);
1425
1426     EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle2, "core.brightled",
1427                                                         "state:oc.bt.b;power:oc.bt.i"));
1428     EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle2, "core.colorled",
1429                                                         "state:oc.bt.b;power:oc.bt.i"));
1430
1431     OCResourceHandle handle3;
1432     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle3,
1433                                             "core.led",
1434                                             "state:oc.bt.b;power:oc.bt.i",
1435                                             "core.rw",
1436                                             OC_REST_GET|OC_REST_PUT,
1437                                             "/a/led3",
1438                                             0,
1439                                             OC_DISCOVERABLE|OC_OBSERVABLE));
1440     url = OCGetResourceUri(handle3);
1441     EXPECT_STREQ("/a/led3", url);
1442
1443     EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle3, "oc.mi.ll",
1444                                                              OC_REST_GET|OC_REST_PUT));
1445     EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle3, "oc.mi.b",
1446                                                              OC_REST_GET|OC_REST_PUT));
1447
1448     OCResourceHandle handle4;
1449     EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle4,
1450                                             "core.led",
1451                                             "state:oc.bt.b;power:oc.bt.i",
1452                                             "core.rw",
1453                                             OC_REST_GET|OC_REST_PUT,
1454                                             "/a/led4",
1455                                             0,
1456                                             OC_DISCOVERABLE));
1457     url = OCGetResourceUri(handle4);
1458     EXPECT_STREQ("/a/led4", url);
1459
1460     EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle4, "core.brightled",
1461                                                         "state:oc.bt.b;power:oc.bt.i"));
1462     EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle4, "oc.mi.ll",
1463                                                              OC_REST_GET|OC_REST_PUT));
1464     EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle4, "oc.mi.b",
1465                                                              OC_REST_GET|OC_REST_PUT));
1466
1467     //EXPECT_EQ(OC_STACK_OK, OCHandleServerRequest(&res, uri, query, req, rsp));
1468 }
1469
1470 TEST(StackTest, StackTestResourceDiscoverIfFilteringBad) {
1471     uint8_t addr[20];
1472     uint16_t port = USE_RANDOM_PORT;
1473     uint8_t ifname[] = "eth0";
1474     char uri[] = "/oc/core";
1475     char query[] = "if";
1476     char req[1024] = {};
1477     char rsp[1024] = {};
1478     //OCServerRequestResult res;
1479
1480     //EXPECT_EQ(OC_STACK_INVALID_QUERY, OCHandleServerRequest(&res, uri, query, req, rsp));
1481 }
1482
1483 TEST(StackTest, StackTestResourceDiscoverRtFilteringBad) {
1484     uint8_t addr[20];
1485     uint16_t port = USE_RANDOM_PORT;
1486     uint8_t ifname[] = "eth0";
1487     char uri[] = "/oc/core";
1488     char query[] = "rt";
1489     char req[1024] = {};
1490     char rsp[1024] = {};
1491     //OCServerRequestResult res;
1492
1493     //EXPECT_EQ(OC_STACK_INVALID_QUERY, OCHandleServerRequest(&res, uri, query, req, rsp));
1494 }
1495 TEST(StackTest, StackTestResourceDiscoverIfFiltering) {
1496     uint8_t addr[20];
1497     uint16_t port = USE_RANDOM_PORT;
1498     uint8_t ifname[] = "eth0";
1499     char uri[] = "/oc/core";
1500     char query[] = "if=oc.mi.ll";
1501     char req[1024] = {};
1502     char rsp[1024] = {};
1503     //OCServerRequestResult res;
1504
1505     //EXPECT_EQ(OC_STACK_OK, OCHandleServerRequest(&res, uri, query, req, rsp));
1506 }
1507
1508 TEST(StackTest, StackTestResourceDiscoverRtFiltering) {
1509     uint8_t addr[20];
1510     uint16_t port = USE_RANDOM_PORT;
1511     uint8_t ifname[] = "eth0";
1512     char uri[] = "/oc/core";
1513     char query[] = "rt=core.brightled";
1514     char req[1024] = {};
1515     char rsp[1024] = {};
1516     //OCServerRequestResult res;
1517
1518     //EXPECT_EQ(OC_STACK_OK, OCHandleServerRequest(&res, uri, query, req, rsp));
1519 }