merge master code to build iotivity
[platform/upstream/iotivity.git] / resource / csdk / security / provisioning / unittest / pmutilitytest.cpp
1 /* *****************************************************************
2  *
3  * Copyright 2015 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 #include "gtest/gtest.h"
21 #include "pmutility.h"
22 #include "ocstack.h"
23 #include "utlist.h"
24
25 using namespace std;
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 extern OCStackResult AddDevice(OCProvisionDev_t **ppList, const char* addr, const uint16_t port,
32                                OCTransportAdapter adapter, OicSecDoxm_t *doxm);
33 #ifdef __cplusplus
34 }
35 #endif
36
37 OCProvisionDev_t* gList = NULL;
38
39 // List add Tests
40 TEST(ProvisionListTest, Addition)
41 {
42     OCProvisionDev_t* el = NULL;
43     OCStackResult res = OC_STACK_ERROR;
44     OicSecDoxm_t* pDoxm = NULL;
45     int cnt =0;
46
47     // The first addition
48     res = AddDevice(&gList, "10.20.30.40", 5684, OC_DEFAULT_ADAPTER, pDoxm);
49     EXPECT_TRUE(OC_STACK_OK == res);
50     EXPECT_TRUE(NULL != gList);
51
52     LL_FOREACH(gList,el){ ++cnt; };
53     //LL_COUNT(gList, el, cnt);
54     EXPECT_TRUE(1 == cnt);
55
56     // Same node must not be inserted
57     res = AddDevice(&gList, "10.20.30.40", 5684, OC_ADAPTER_IP, pDoxm);
58     EXPECT_TRUE(OC_STACK_OK == res);
59     EXPECT_TRUE(NULL != gList);
60
61     cnt = 0;
62     LL_FOREACH(gList,el){ ++cnt; };
63     //LL_COUNT(gList, el, cnt);
64     EXPECT_TRUE(1 == cnt);
65
66     // Differnet node must be inserted
67     res = AddDevice(&gList, "110.120.130.140", 6789, OC_DEFAULT_ADAPTER, pDoxm);
68     EXPECT_TRUE(OC_STACK_OK == res);
69     EXPECT_TRUE(NULL != gList);
70
71     cnt = 0;
72     LL_FOREACH(gList,el){ ++cnt; };
73     //LL_COUNT(gList, el, cnt);
74     EXPECT_TRUE(2 == cnt);
75 }
76
77 // List Delete Tests
78 TEST(ProvisionListTest, Deletion)
79 {
80     OCProvisionDev_t* el = NULL;
81     int cnt =0;
82
83     // Delete whole
84     DeleteDeviceList(&gList);
85     gList = NULL;
86
87     LL_FOREACH(gList,el){ ++cnt; };
88     //LL_COUNT(gList, el, cnt);
89     EXPECT_TRUE(0 == cnt);
90 }