Resolved tizen build issue regarding ip network
[platform/upstream/iotivity.git] / service / easy-setup / mediator / csdk / unittests / MediatorCSDKTest.cpp
1 //******************************************************************
2 //
3 // Copyright 2016 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 "UnitTestHelper.h"
22
23 #include "ocstack.h"
24 #include "OCPlatform.h"
25 #include "OCApi.h"
26 #include "oic_string.h"
27 #include "logger.h"
28
29 #include "provisioningapi.h"
30 #include "provisioning.h"
31 #include "escommon.h"
32
33 #include <iostream>
34 #include <string.h>
35 #include <functional>
36 #include <pthread.h>
37 #include <condition_variable>
38
39 class MediatorCSDKTest: public TestWithMock
40 {
41
42     protected:
43         void SetUp()
44         {
45             TestWithMock::SetUp();
46         }
47
48         void TearDown()
49         {
50             TestWithMock::TearDown();
51         }
52
53 };
54
55 //callbacks
56 void OCProvisioningStatusCallback(EasySetupInfo  *easySetupInfo)
57 {
58     (void) easySetupInfo;
59 }
60
61 /* Test cases for prov_adapter*/
62
63 //InitProvProcess
64 TEST_F(MediatorCSDKTest, testInitProvProcess)
65 {
66     OCStackResult result = InitProvProcess();
67     ASSERT_EQ(OC_STACK_OK, result);
68 }
69
70 //ResetProvProcess
71 TEST_F(MediatorCSDKTest, testResetProvProcess)
72 {
73     OCStackResult result = ResetProvProcess();
74     ASSERT_EQ(OC_STACK_OK, result);
75 }
76
77 //RegisterCallback [positive]
78 TEST_F(MediatorCSDKTest, testRegisterCallback)
79 {
80     OCStackResult result = RegisterCallback(&OCProvisioningStatusCallback);
81     ASSERT_EQ(OC_STACK_OK, result);
82 }
83
84 //RegisterCallback [Negative]
85 TEST_F(MediatorCSDKTest, testRegisterCallbackNegative)
86 {
87     OCStackResult result = RegisterCallback(NULL);
88     ASSERT_EQ(OC_STACK_ERROR, result);
89 }
90
91 //StartProvisioning [positive]
92 TEST_F(MediatorCSDKTest, testStartProvisioning)
93 {
94     ProvConfig provConfig;
95     WiFiOnboadingConnection onboardConn;
96
97     strncpy(onboardConn.ipAddress, "1.1.1.1", IPV4_ADDR_SIZE - 1);
98
99     strncpy(provConfig.provData.WIFI.ssid, "testAP", NET_WIFI_SSID_SIZE - 1);
100     strncpy(provConfig.provData.WIFI.pwd, "test@123", NET_WIFI_PWD_SIZE - 1);
101     provConfig.connType = CT_ADAPTER_IP;
102
103     //API Call
104     OCStackResult result =    StartProvisioning(&provConfig, &onboardConn);
105
106     ASSERT_EQ(OC_STACK_OK, result);
107 }
108
109 //StartProvisioning [Negative]
110 TEST_F(MediatorCSDKTest, testStartProvisioningNegative)
111 {
112     OCStackResult result = StartProvisioning(NULL, NULL);
113     ASSERT_EQ(OC_STACK_ERROR, result);
114 }
115
116 //StopProvisioning
117 TEST_F(MediatorCSDKTest, testStopProvisioning)
118 {
119     // This API always return success
120     OCStackResult result = StopProvisioning(CT_ADAPTER_IP);
121     ASSERT_EQ(OC_STACK_OK, result);
122 }
123
124