1 //******************************************************************
3 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "gtest/gtest.h"
23 #include "oic_malloc.h"
24 #include "cainterface.h"
25 #include "secureresourcemanager.h"
26 #include "securevirtualresourcetypes.h"
27 #include "srmresourcestrings.h"
28 #include "svcresource.h"
29 #include "srmtestcommon.h"
30 #include "security_internals.h"
34 #define NUM_SVC_IN_CBOR_DB (2)
36 TEST(SVCResourceTest, CBORConversionTests)
38 OicSecSvc_t *svc1 = (OicSecSvc_t *) OICCalloc(1, sizeof(*svc1));
39 ASSERT_TRUE(NULL != svc1);
40 uint8_t svcdid[] = {0x35, 0x35, 0x35, 0x35, 0x35, 0x35, 0x35, 0x35, 0x35,
41 0x35, 0x35, 0x35, 0x35, 0x35, 0x35, 0x35};
42 memcpy(svc1->svcdid.id, svcdid, sizeof(svcdid));
43 ASSERT_EQ(sizeof(svc1->svcdid.id), sizeof(svcdid));
45 svc1->svct = (OicSecSvcType_t) 1;
46 uint8_t owners[] = {0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39,
47 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39};
49 svc1->owners = (OicUuid_t *)OICCalloc(svc1->ownersLen, sizeof(*svc1->owners));
50 ASSERT_TRUE(NULL != svc1->owners);
51 memcpy(svc1->owners[0].id, owners, sizeof(owners));
52 ASSERT_EQ(sizeof(svc1->owners[0].id), sizeof(owners));
54 svc1->next = (OicSecSvc_t *) OICCalloc(1, sizeof(*svc1->next));
55 ASSERT_TRUE(svc1->next != NULL);
56 memcpy(svc1->next->svcdid.id, svcdid, sizeof(svcdid));
57 ASSERT_EQ(sizeof(svc1->next->svcdid.id), sizeof(svcdid));
58 svc1->next->svct = (OicSecSvcType_t) 1;
59 uint8_t owners1[] = {0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
60 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36};
61 svc1->next->ownersLen = 1;
62 svc1->next->owners = (OicUuid_t *)OICCalloc(svc1->next->ownersLen,
63 sizeof(*svc1->next->owners));
64 ASSERT_TRUE(NULL != svc1->next->owners);
65 memcpy(svc1->next->owners[0].id, owners1, sizeof(owners1));
66 svc1->next->next = NULL;
69 uint8_t *psStorage = NULL;
70 EXPECT_EQ(OC_STACK_OK, SVCToCBORPayload(svc1, &psStorage, &size));
71 ASSERT_TRUE(NULL != psStorage);
73 OicSecSvc_t *svc = NULL;
74 EXPECT_EQ(OC_STACK_OK, CBORPayloadToSVC(psStorage, size, &svc));
75 ASSERT_TRUE(NULL != svc);
78 OicSecSvc_t *tempSvc = svc;
81 EXPECT_EQ(ACCESS_MGMT_SERVICE, tempSvc->svct);
83 tempSvc = tempSvc->next;
85 EXPECT_EQ(NUM_SVC_IN_CBOR_DB, cnt);