Imported Upstream version 1.0.0
[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 **ppDevicesList, const char* addr,
32                                const uint16_t port, OCTransportAdapter adapter,
33                                OCConnectivityType connType, OicSecDoxm_t *doxm);
34 #ifdef __cplusplus
35 }
36 #endif
37
38 OCProvisionDev_t* gList = NULL;
39
40 // List add Tests
41 TEST(ProvisionListTest, Addition)
42 {
43     OCProvisionDev_t* el = NULL;
44     OCStackResult res = OC_STACK_ERROR;
45     OicSecDoxm_t* pDoxm = NULL;
46     int cnt =0;
47
48     // The first addition
49     res = AddDevice(&gList, "10.20.30.40", 5684, OC_DEFAULT_ADAPTER, CT_IP_USE_V4, pDoxm);
50     EXPECT_TRUE(OC_STACK_OK == res);
51     EXPECT_TRUE(NULL != gList);
52
53     LL_FOREACH(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, CT_IP_USE_V4, pDoxm);
58     EXPECT_TRUE(OC_STACK_OK == res);
59     EXPECT_TRUE(NULL != gList);
60
61     cnt = 0;
62     LL_FOREACH(gList,el){ ++cnt; };
63     EXPECT_TRUE(1 == cnt);
64
65     // Differnet node must be inserted
66     res = AddDevice(&gList, "110.120.130.140", 6789, OC_DEFAULT_ADAPTER, CT_IP_USE_V4, pDoxm);
67     EXPECT_TRUE(OC_STACK_OK == res);
68     EXPECT_TRUE(NULL != gList);
69
70     cnt = 0;
71     LL_FOREACH(gList,el){ ++cnt; };
72     EXPECT_TRUE(2 == cnt);
73 }
74
75 // List Delete Tests
76 TEST(ProvisionListTest, Deletion)
77 {
78     OCProvisionDev_t* el = NULL;
79     int cnt =0;
80
81     // Delete whole
82     PMDeleteDeviceList(gList);
83     gList = NULL;
84
85     LL_FOREACH(gList,el){ ++cnt; };
86     EXPECT_TRUE(0 == cnt);
87 }