Merge branch 'master' into resource-manipulation
[platform/upstream/iotivity.git] / resource / csdk / connectivity / test / ca_api_unittest.cpp
1 /* ****************************************************************
2  *
3  * Copyright 2014 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************/
20
21 #include "gtest/gtest.h"
22 #include "cainterface.h"
23 #include "cacommon.h"
24
25
26 class CATests : public testing::Test {
27     protected:
28     virtual void SetUp() {
29         CAInitialize();
30     }
31
32     virtual void TearDown()
33     {
34         CATerminate();
35     }
36 };
37
38 void request_handler(CARemoteEndpoint_t* object, CARequestInfo_t* requestInfo);
39 void response_handler(CARemoteEndpoint_t* object, CAResponseInfo_t* responseInfo);
40 void error_handler(const CARemoteEndpoint_t *object, const CAErrorInfo_t* errorInfo);
41
42 CAResult_t checkGetNetworkInfo();
43 CAResult_t checkSelectNetwork();
44
45
46
47 void request_handler(const CARemoteEndpoint_t *object, const CARequestInfo_t *requestInfo)
48 {
49
50 }
51
52 void response_handler(const CARemoteEndpoint_t *object, const CAResponseInfo_t *responseInfo)
53 {
54
55 }
56
57 void error_handler(const CARemoteEndpoint_t *object, const CAErrorInfo_t* errorInfo)
58 {
59     if(!object || !errorInfo)
60     {
61         return;
62     }
63
64     //error handling shall be added
65     return;
66 }
67
68 static char* uri = NULL;
69 static CARemoteEndpoint_t* tempRep = NULL;
70 static CARequestInfo_t requestInfo;
71 static CAInfo_t requestData;
72 static CAInfo_t responseData;
73 static CAResponseInfo_t responseInfo;
74 static CAToken_t tempToken = NULL;
75 static uint8_t tokenLength = CA_MAX_TOKEN_LEN;
76 static const char URI[] = "coap://10.11.12.13:4545/a/light";
77 static const char RESOURCE_URI[] = "/a/light";
78
79 static const char SECURE_INFO_DATA[] =
80                                     "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
81                                      "\"if\":[\"oic.if.baseline\"],\"obs\":1,\"sec\":1,\"port\":%d}}]}";
82 static const char NORMAL_INFO_DATA[] =
83                                     "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
84                                      "\"if\":[\"oic.if.baseline\"],\"obs\":1}}]}";
85
86 #ifdef __WITH_DTLS__
87
88 /**
89  * @def RS_IDENTITY
90  * @brief
91  */
92 #define IDENTITY     ("1111111111111111")
93 /* @def RS_CLIENT_PSK
94  * @brief
95  */
96 #define RS_CLIENT_PSK   ("AAAAAAAAAAAAAAAA")
97
98 static CADtlsPskCredsBlob_t *pskCredsBlob = NULL;
99
100 void clearDtlsCredentialInfo()
101 {
102     printf("clearDtlsCredentialInfo IN\n");
103     if (pskCredsBlob)
104     {
105         // Initialize sensitive data to zeroes before freeing.
106         memset(pskCredsBlob->creds, 0, sizeof(OCDtlsPskCreds) * (pskCredsBlob->num));
107         free(pskCredsBlob->creds);
108
109         memset(pskCredsBlob, 0, sizeof(CADtlsPskCredsBlob_t));
110         free(pskCredsBlob);
111         pskCredsBlob = NULL;
112     }
113     printf("clearDtlsCredentialInfo OUT\n");
114 }
115
116 // Internal API. Invoked by OC stack to retrieve credentials from this module
117 void CAGetDtlsPskCredentials(CADtlsPskCredsBlob_t **credInfo)
118 {
119     printf("CAGetDtlsPskCredentials IN\n");
120
121     if (pskCredsBlob != NULL)
122     {
123         *credInfo = pskCredsBlob;
124     }
125
126     printf("CAGetDtlsPskCredentials OUT\n");
127 }
128
129 int32_t SetCredentials()
130 {
131     printf("SetCredentials IN\n");
132     pskCredsBlob = (CADtlsPskCredsBlob_t *)malloc(sizeof(CADtlsPskCredsBlob_t));
133
134     memset(pskCredsBlob, 0x0, sizeof(CADtlsPskCredsBlob_t));
135     memcpy(pskCredsBlob->identity, IDENTITY, DTLS_PSK_ID_LEN);
136
137     pskCredsBlob->num = 1;
138
139     pskCredsBlob->creds = (OCDtlsPskCreds *)malloc(sizeof(OCDtlsPskCreds) * (pskCredsBlob->num));
140
141     memcpy(pskCredsBlob->creds[0].id, IDENTITY, DTLS_PSK_ID_LEN);
142     memcpy(pskCredsBlob->creds[0].psk, RS_CLIENT_PSK, DTLS_PSK_PSK_LEN);
143
144     printf("SetCredentials OUT\n");
145     return 1;
146 }
147 #endif
148
149 int main(int argc, char **argv)
150 {
151     testing::InitGoogleTest(&argc, argv);
152     return RUN_ALL_TESTS();
153 }
154
155 // CAInitialize TC
156 // check return value
157 TEST(InitializeTest, TC_01_Positive_01)
158 {
159     EXPECT_EQ(CA_STATUS_OK, CAInitialize());
160     CATerminate();
161 }
162
163 //CATerminate TC
164 TEST_F(CATests, TerminateTest)
165 {
166     CATerminate();
167
168     char* check = (char *) "terminate success";
169     EXPECT_STREQ(check, "terminate success");
170
171     CAInitialize();
172 }
173 // CAStartListeningServer TC
174 // check return value
175 TEST(StartListeningServerTest, DISABLED_TC_03_Positive_01)
176 {
177     CASelectNetwork(CA_IPV4);
178     EXPECT_EQ(CA_STATUS_OK, CAStartListeningServer());
179 }
180
181 // CAStartDiscoveryServer TC
182 // check return value
183 TEST(StartDiscoveryServerTest, DISABLED_TC_04_Positive_01)
184 {
185     EXPECT_EQ(CA_STATUS_OK, CAStartDiscoveryServer());
186 }
187
188 // CARegisterHandlerTest TC
189 // check return value
190 TEST_F(CATests, RegisterHandlerTest)
191 {
192     CARegisterHandler(request_handler, response_handler, error_handler);
193     char* check = (char *) "registerHandler success";
194     EXPECT_STREQ(check, "registerHandler success");
195 }
196
197 // CACreateRemoteEndpoint TC
198 // check return value
199 TEST_F(CATests, CreateRemoteEndpointTestGood)
200 {
201     uri = (char *) URI;
202
203     EXPECT_EQ(CA_STATUS_OK, CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep));
204
205     if (tempRep != NULL)
206     {
207         CADestroyRemoteEndpoint(tempRep);
208         tempRep = NULL;
209     }
210 }
211
212 // check remoteEndpoint and values of remoteEndpoint
213 TEST_F(CATests, CreateRemoteEndpointTestValues)
214 {
215     uri = (char *) URI;
216
217     CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep);
218
219     EXPECT_TRUE(tempRep != NULL);
220
221     if (tempRep != NULL)
222     {
223         EXPECT_STRNE(NULL, tempRep->resourceUri);
224     }
225
226     if (tempRep != NULL)
227     {
228         CADestroyRemoteEndpoint(tempRep);
229         tempRep = NULL;
230     }
231 }
232
233 // check return value when uri is NULL
234 TEST_F(CATests, CreateRemoteEndpointTestBad)
235 {
236     uri = NULL;
237
238     EXPECT_EQ(CA_STATUS_FAILED, CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep));
239
240     if (tempRep != NULL)
241     {
242         CADestroyRemoteEndpoint(tempRep);
243         tempRep = NULL;
244     }
245 }
246
247 // check values of remoteEndpoint when uri is NULL
248 TEST_F(CATests, CreateRemoteEndpointTestWithNullUri)
249 {
250     uri = NULL;
251     CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep);
252
253     if (tempRep != NULL)
254     {
255         EXPECT_STREQ(NULL, tempRep->resourceUri);
256
257     }
258
259     if (tempRep != NULL)
260     {
261         CADestroyRemoteEndpoint(tempRep);
262         tempRep = NULL;
263     }
264 }
265
266 // CADestroyRemoteEndpoint TC
267 // check destroyed remoteEndpoint
268 TEST_F(CATests, DestroyRemoteEndpointTest)
269 {
270     uri = (char *) URI;
271     CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep);
272
273     CADestroyRemoteEndpoint(tempRep);
274     tempRep = NULL;
275
276     char * check = (char *) "destroy success";
277     EXPECT_STREQ(check, "destroy success");
278 }
279
280 // CAGerateToken TC
281 // check return value
282 TEST_F(CATests, GenerateTokenTestGood)
283 {
284     EXPECT_EQ(CA_STATUS_OK, CAGenerateToken(&tempToken, tokenLength));
285
286     CADestroyToken(tempToken);
287 }
288
289 // check return value when CAGenerateToken is passed a NULL instead a valid pointer
290 TEST_F(CATests, GenerateTokenTestBad)
291 {
292     EXPECT_EQ(CA_STATUS_INVALID_PARAM, CAGenerateToken(NULL, tokenLength));
293 }
294
295 // CADestroyToken TC
296 // check destroyed token
297 TEST_F(CATests, DestroyTokenTest)
298 {
299     CAGenerateToken(&tempToken, tokenLength);
300     CADestroyToken(tempToken);
301
302     char * check = (char *) "destroy success";
303     EXPECT_STREQ(check, "destroy success");
304 }
305
306 // CAFindResource TC
307 // check return value
308 TEST(FindResourceTest, DISABLED_TC_14_Positive_01)
309 {
310     uri = (char *) RESOURCE_URI;
311
312     CAGenerateToken(&tempToken, tokenLength);
313     EXPECT_EQ(CA_STATUS_OK, CAFindResource(uri, tempToken, tokenLength));
314     CADestroyToken(tempToken);
315 }
316
317 // check return value when uri is NULL
318 TEST_F(CATests, FindResourceTest)
319 {
320     uri = NULL;
321     CAGenerateToken(&tempToken, tokenLength);
322     EXPECT_EQ(CA_STATUS_INVALID_PARAM, CAFindResource(uri, tempToken, tokenLength));
323     CADestroyToken(tempToken);
324 }
325
326 // CASendRequest TC
327 // check return value
328 TEST(SendRequestTest, DISABLED_TC_16_Positive_01)
329 {
330     uri = (char *) URI;
331     CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep);
332
333     memset(&requestData, 0, sizeof(CAInfo_t));
334     CAGenerateToken(&tempToken, tokenLength);
335     requestData.token = tempToken;
336     requestData.tokenLength = tokenLength;
337
338     int length = strlen(NORMAL_INFO_DATA) + strlen("a/light");
339     requestData.payload = (CAPayload_t) calloc(length, sizeof(char));
340
341     if(!requestData.payload)
342     {
343         CADestroyToken(tempToken);
344         FAIL() << "requestData.payload allocation failed";
345     }
346
347     snprintf(requestData.payload, length, NORMAL_INFO_DATA, "a/light");
348     requestData.type = CA_MSG_NONCONFIRM;
349
350     memset(&requestInfo, 0, sizeof(CARequestInfo_t));
351     requestInfo.method = CA_GET;
352     requestInfo.info = requestData;
353
354     EXPECT_EQ(CA_STATUS_OK, CASendRequest(tempRep, &requestInfo));
355
356     CADestroyToken(tempToken);
357
358     free(requestData.payload);
359
360     CADestroyRemoteEndpoint(tempRep);
361     tempRep = NULL;
362
363 }
364
365 // check return value when uri is NULL
366 TEST_F(CATests, SendRequestTestWithNullURI)
367 {
368     uri = NULL;
369     CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep);
370
371     memset(&requestData, 0, sizeof(CAInfo_t));
372     CAGenerateToken(&tempToken, tokenLength);
373     requestData.token = tempToken;
374     requestData.tokenLength = tokenLength;
375
376     int length = strlen(NORMAL_INFO_DATA) + strlen("a/light");
377     requestData.payload = (CAPayload_t) calloc(length, sizeof(char));
378
379     if(!requestData.payload)
380     {
381         CADestroyToken(tempToken);
382         FAIL() << "requestData.payload allocation failed";
383     }
384
385     snprintf(requestData.payload, length, NORMAL_INFO_DATA, "a/light");
386     requestData.type = CA_MSG_NONCONFIRM;
387
388     memset(&requestInfo, 0, sizeof(CARequestInfo_t));
389     requestInfo.method = CA_GET;
390     requestInfo.info = requestData;
391
392     EXPECT_EQ(CA_STATUS_INVALID_PARAM, CASendRequest(tempRep, &requestInfo));
393
394     CADestroyToken(tempToken);
395
396     free(requestData.payload);
397
398     if (tempRep != NULL)
399     {
400         CADestroyRemoteEndpoint(tempRep);
401         tempRep = NULL;
402     }
403 }
404
405 // check return value when a NULL is passed instead of a valid CARequestInfo_t address
406 TEST_F(CATests, SendRequestTestWithNullAddr)
407 {
408     uri = (char *) URI;
409     CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep);
410
411     EXPECT_EQ(CA_STATUS_INVALID_PARAM, CASendRequest(tempRep, NULL));
412
413     if (tempRep != NULL)
414     {
415         CADestroyRemoteEndpoint(tempRep);
416         tempRep = NULL;
417     }
418 }
419
420 // CASendResponse TC
421 // check return value
422 TEST(SendResponseTest, DISABLED_TC_19_Positive_01)
423 {
424     uri = (char *) URI;
425     CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep);
426
427     memset(&responseData, 0, sizeof(CAInfo_t));
428     responseData.type = CA_MSG_NONCONFIRM;
429     responseData.messageId = 1;
430     responseData.payload = (char *) "response payload";
431
432     CAGenerateToken(&tempToken, tokenLength);
433     requestData.token = tempToken;
434     requestData.tokenLength = tokenLength;
435
436     memset(&responseInfo, 0, sizeof(CAResponseInfo_t));
437     responseInfo.result = CA_SUCCESS;
438     responseInfo.info = responseData;
439
440     EXPECT_EQ(CA_STATUS_OK, CASendResponse(tempRep, &responseInfo));
441
442     CADestroyToken(tempToken);
443     CADestroyRemoteEndpoint(tempRep);
444     tempRep = NULL;
445 }
446
447 // check return value when uri is NULL
448 TEST(SendResponseTest, DISABLED_TC_20_Negative_01)
449 {
450     uri = NULL;
451     CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep);
452
453     memset(&responseData, 0, sizeof(CAInfo_t));
454     responseData.type = CA_MSG_NONCONFIRM;
455     responseData.messageId = 1;
456     responseData.payload = (char *) "response payload";
457
458     CAGenerateToken(&tempToken, tokenLength);
459     requestData.token = tempToken;
460     requestData.tokenLength = tokenLength;
461
462     memset(&responseInfo, 0, sizeof(CAResponseInfo_t));
463     responseInfo.result = CA_SUCCESS;
464     responseInfo.info = responseData;
465
466     EXPECT_EQ(CA_STATUS_INVALID_PARAM, CASendResponse(tempRep, &responseInfo));
467
468     CADestroyToken(tempToken);
469     if (tempRep != NULL)
470     {
471         CADestroyRemoteEndpoint(tempRep);
472         tempRep = NULL;
473     }
474 }
475
476 // check return value NULL is passed instead of a valid CAResponseInfo_t address
477 TEST_F(CATests, SendResponseTest)
478 {
479     uri = (char *) URI;
480     CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep);
481
482     EXPECT_EQ(CA_STATUS_INVALID_PARAM, CASendResponse(tempRep, NULL));
483
484     if (tempRep != NULL)
485     {
486         CADestroyRemoteEndpoint(tempRep);
487         tempRep = NULL;
488     }
489 }
490
491 // CASendNotification TC
492 // check return value
493 TEST(SendNotificationTest, DISABLED_TC_22_Positive_01)
494 {
495     uri = (char *) URI;
496     CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep);
497
498     memset(&responseData, 0, sizeof(CAInfo_t));
499     responseData.type = CA_MSG_NONCONFIRM;
500     responseData.payload = (char *) "Temp Notification Data";
501
502     CAGenerateToken(&tempToken, tokenLength);
503     requestData.token = tempToken;
504     requestData.tokenLength = tokenLength;
505
506     memset(&responseInfo, 0, sizeof(CAResponseInfo_t));
507     responseInfo.result = CA_SUCCESS;
508     responseInfo.info = responseData;
509
510     EXPECT_EQ(CA_STATUS_OK, CASendNotification(tempRep, &responseInfo));
511
512     CADestroyToken(tempToken);
513     if (tempRep != NULL)
514     {
515         CADestroyRemoteEndpoint(tempRep);
516         tempRep = NULL;
517     }
518 }
519
520 // check return value when uri is NULL
521 TEST_F(CATests, SendNotificationTest)
522 {
523     uri = NULL;
524     CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep);
525
526     memset(&responseData, 0, sizeof(CAInfo_t));
527     responseData.type = CA_MSG_NONCONFIRM;
528     responseData.payload = (char *) "Temp Notification Data";
529
530     CAGenerateToken(&tempToken, tokenLength);
531     requestData.token = tempToken;
532     requestData.tokenLength = tokenLength;
533
534     memset(&responseInfo, 0, sizeof(CAResponseInfo_t));
535     responseInfo.result = CA_SUCCESS;
536     responseInfo.info = responseData;
537
538     EXPECT_EQ(CA_STATUS_INVALID_PARAM, CASendNotification(tempRep, &responseInfo));
539
540     CADestroyToken(tempToken);
541     if (tempRep != NULL)
542     {
543         CADestroyRemoteEndpoint(tempRep);
544         tempRep = NULL;
545     }
546 }
547
548 // CAAdvertiseResource TC
549 // check return value
550 TEST(AdvertiseResourceTest, DISABLED_TC_24_Positive_01)
551 {
552     uri = (char *) RESOURCE_URI;
553     int optionNum = 2;
554
555     CAHeaderOption_t* headerOpt;
556     headerOpt = (CAHeaderOption_t *) calloc(1, optionNum * sizeof(CAHeaderOption_t));
557
558     if(!headerOpt)
559     {
560         FAIL() <<"Allocation for headerOpt failed";
561     }
562
563     char* tmpOptionData1 = (char *) "Hello";
564     size_t tmpOptionDataLen = (strlen(tmpOptionData1) < CA_MAX_HEADER_OPTION_DATA_LENGTH) ?
565             strlen(tmpOptionData1) : CA_MAX_HEADER_OPTION_DATA_LENGTH - 1;
566     headerOpt[0].optionID = 3000;
567     memcpy(headerOpt[0].optionData, tmpOptionData1, tmpOptionDataLen);
568     headerOpt[0].optionLength = (uint16_t) tmpOptionDataLen;
569
570     char* tmpOptionData2 = (char *) "World";
571     tmpOptionDataLen = (strlen(tmpOptionData2) < CA_MAX_HEADER_OPTION_DATA_LENGTH) ?
572                 strlen(tmpOptionData2) : CA_MAX_HEADER_OPTION_DATA_LENGTH - 1;
573     headerOpt[1].optionID = 3001;
574     memcpy(headerOpt[1].optionData, tmpOptionData2, tmpOptionDataLen);
575     headerOpt[1].optionLength = (uint16_t) tmpOptionDataLen;
576
577     CAGenerateToken(&tempToken, tokenLength);
578
579     EXPECT_EQ(CA_STATUS_OK, CAAdvertiseResource(uri, tempToken, tokenLength,
580                                                 headerOpt, (uint8_t )optionNum));
581
582     CADestroyToken(tempToken);
583
584     free(headerOpt);
585 }
586
587 // check return value when uri is NULL
588 TEST_F(CATests, AdvertiseResourceTest)
589 {
590     uri = NULL;
591     int optionNum = 2;
592
593     CAHeaderOption_t* headerOpt;
594     headerOpt = (CAHeaderOption_t *) calloc(1, optionNum * sizeof(CAHeaderOption_t));
595
596     if(!headerOpt)
597     {
598         FAIL() << "Allocation for headerOpt failed";
599     }
600
601     char* tmpOptionData1 = (char *) "Hello";
602     size_t tmpOptionDataLen = (strlen(tmpOptionData1) < CA_MAX_HEADER_OPTION_DATA_LENGTH) ?
603             strlen(tmpOptionData1) : CA_MAX_HEADER_OPTION_DATA_LENGTH - 1;
604     headerOpt[0].optionID = 3000;
605     memcpy(headerOpt[0].optionData, tmpOptionData1, tmpOptionDataLen);
606     headerOpt[0].optionLength = (uint16_t) tmpOptionDataLen;
607
608     char* tmpOptionData2 = (char *) "World";
609     tmpOptionDataLen = (strlen(tmpOptionData2) < CA_MAX_HEADER_OPTION_DATA_LENGTH) ?
610                 strlen(tmpOptionData2) : CA_MAX_HEADER_OPTION_DATA_LENGTH - 1;
611     headerOpt[1].optionID = 3001;
612     memcpy(headerOpt[1].optionData, tmpOptionData2, tmpOptionDataLen);
613     headerOpt[1].optionLength = (uint16_t) tmpOptionDataLen;
614
615     CAGenerateToken(&tempToken, tokenLength);
616
617     EXPECT_EQ(CA_STATUS_INVALID_PARAM, CAAdvertiseResource(uri, tempToken, tokenLength,
618                                                            headerOpt, (uint8_t )optionNum));
619
620     CADestroyToken(tempToken);
621
622     free(headerOpt);
623 }
624
625 // CASelectNewwork TC
626 // check return value
627 TEST_F(CATests, SelectNetworkTestGood)
628 {
629     CAResult_t res = checkSelectNetwork();
630     EXPECT_EQ(CA_STATUS_OK, res);
631 }
632
633 CAResult_t checkSelectNetwork()
634 {
635     CAResult_t res = CASelectNetwork(CA_IPV4);
636
637     if (CA_STATUS_OK == res)
638     {
639         EXPECT_EQ(CA_STATUS_OK, CAUnSelectNetwork(CA_IPV4));
640         return CA_STATUS_OK;
641     }
642     if (CA_NOT_SUPPORTED == res)
643     {
644         EXPECT_EQ(CA_STATUS_FAILED, CAUnSelectNetwork(CA_IPV4));
645         return CA_STATUS_OK;
646     }
647
648     return res;
649 }
650
651 // check return value when selected network is disable
652 TEST_F(CATests, SelectNetworkTestBad)
653 {
654     //Select disable network
655     EXPECT_EQ(CA_NOT_SUPPORTED, CASelectNetwork(1000));
656 }
657
658 // check return value when selected network is disable
659 TEST_F(CATests, UnSelectNetworkTest)
660 {
661     //UnSelect disable network
662     EXPECT_EQ(CA_STATUS_FAILED, CAUnSelectNetwork(1000));
663 }
664
665 // CAHandlerRequestResponse TC
666 // check return value
667 TEST_F(CATests, HandlerRequestResponseTest)
668 {
669     EXPECT_EQ(CA_STATUS_OK, CAHandleRequestResponse());
670 }
671
672 // CASendRequestToAll TC
673 // check return value
674 TEST(SendRequestToAllTest, DISABLED_TC_31_Positive_01)
675 {
676     CASelectNetwork(CA_IPV4);
677
678     uri = (char *) RESOURCE_URI;
679     CACreateRemoteEndpoint(uri, CA_IPV4, &tempRep);
680     CAGroupEndpoint_t *group = NULL;
681     group = (CAGroupEndpoint_t *) malloc(sizeof(CAGroupEndpoint_t));
682     if(!group)
683     {
684         FAIL() << "Allocation for group failed";
685     }
686
687     group->transportType = tempRep->transportType;
688     group->resourceUri = tempRep->resourceUri;
689
690     memset(&requestData, 0, sizeof(CAInfo_t));
691     CAGenerateToken(&tempToken, tokenLength);
692     requestData.token = tempToken;
693     requestData.tokenLength = tokenLength;
694
695     requestData.payload = (char *) "Temp Json Payload";
696     requestData.type = CA_MSG_NONCONFIRM;
697     memset(&requestInfo, 0, sizeof(CARequestInfo_t));
698     requestInfo.method = CA_GET;
699     requestInfo.info = requestData;
700
701     EXPECT_EQ(CA_STATUS_OK, CASendRequestToAll(group, &requestInfo));
702
703     CADestroyToken(tempToken);
704
705     CADestroyRemoteEndpoint(tempRep);
706     tempRep = NULL;
707
708     free(group);
709 }
710
711 // check return value when group->resourceUri is NULL
712 TEST(SendRequestToAllTest, DISABLED_TC_32_Negative_01)
713 {
714     uri = (char *) RESOURCE_URI;
715     CAGroupEndpoint_t *group = NULL;
716
717     memset(&requestData, 0, sizeof(CAInfo_t));
718     CAGenerateToken(&tempToken, tokenLength);
719     requestData.token = tempToken;
720     requestData.tokenLength = tokenLength;
721
722     requestData.payload = (char *) "Temp Json Payload";
723     requestData.type = CA_MSG_NONCONFIRM;
724     memset(&requestInfo, 0, sizeof(CARequestInfo_t));
725     requestInfo.method = CA_GET;
726     requestInfo.info = requestData;
727
728     EXPECT_EQ(CA_STATUS_INVALID_PARAM, CASendRequestToAll(group, &requestInfo));
729
730     CADestroyToken(tempToken);
731 }
732
733 // CAGetNetworkInformation TC
734 // check return value
735 TEST_F (CATests, GetNetworkInformationTestGood)
736 {
737     EXPECT_EQ(CA_STATUS_OK, checkGetNetworkInfo());
738 }
739
740 TEST_F(CATests, RegisterDTLSCredentialsHandlerTest)
741 {
742 #ifdef __WITH_DTLS__
743     if (SetCredentials() == 0)
744     {
745         printf("SetCredentials failed\n");
746     }
747
748     EXPECT_EQ(CA_STATUS_OK, CARegisterDTLSCredentialsHandler(CAGetDtlsPskCredentials));
749 #endif
750 }
751
752 CAResult_t checkGetNetworkInfo()
753 {
754     CALocalConnectivity_t *tempInfo = NULL;
755     uint32_t tempSize = 0;
756
757     CAResult_t res = CAGetNetworkInformation(&tempInfo, &tempSize);
758
759     free(tempInfo);
760
761     if (CA_STATUS_OK == res || CA_ADAPTER_NOT_ENABLED == res ||
762             CA_NOT_SUPPORTED == res)
763     {
764         return CA_STATUS_OK;
765     }
766     else
767     {
768         return CA_STATUS_FAILED;
769     }
770 }