Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / resource / csdk / security / unittest / svcresourcetest.cpp
1 //******************************************************************
2 //
3 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #include "gtest/gtest.h"
22 #include <pwd.h>
23 #include <grp.h>
24 #include <linux/limits.h>
25 #include <sys/stat.h>
26 #include "ocstack.h"
27 #include "oic_malloc.h"
28 #include "cJSON.h"
29 #include "cainterface.h"
30 #include "secureresourcemanager.h"
31 #include "securevirtualresourcetypes.h"
32 #include "srmresourcestrings.h"
33 #include "svcresource.h"
34 #include "srmtestcommon.h"
35
36 using namespace std;
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 extern char * BinToSvcJSON(const OicSecSvc_t * svc);
42 extern OicSecSvc_t * JSONToSvcBin(const char * jsonStr);
43 extern void DeleteSVCList(OicSecSvc_t* svc);
44 #ifdef __cplusplus
45 }
46 #endif
47
48 static const char* JSON_FILE_NAME = "oic_unittest.json";
49
50 #define NUM_SVC_IN_JSON_DB (2)
51
52
53 // JSON Marshalling Tests
54 TEST(SVCResourceTest, JSONMarshallingTests)
55 {
56     char *jsonStr1 = ReadFile(JSON_FILE_NAME);
57     if (jsonStr1)
58     {
59         OicSecSvc_t * svc = JSONToSvcBin(jsonStr1);
60         EXPECT_TRUE(NULL != svc);
61
62         int cnt = 0;
63         OicSecSvc_t * tempSvc = svc;
64         while(tempSvc)
65         {
66
67             EXPECT_EQ(tempSvc->svct, ACCESS_MGMT_SERVICE);
68             cnt++;
69             tempSvc = tempSvc->next;
70         }
71         EXPECT_EQ(cnt, NUM_SVC_IN_JSON_DB);
72
73         char * jsonStr2 = BinToSvcJSON(svc);
74         EXPECT_TRUE(NULL != jsonStr2);
75
76         OICFree(jsonStr1);
77         OICFree(jsonStr2);
78         DeleteSVCList(svc);
79     }
80 }
81