[Simulator] Minor UI changes fixing the IOT-1087.
[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     OC_UNUSED(easySetupInfo);
58 }
59
60 /* Test cases for prov_adapter*/
61
62 //InitProvProcess
63 TEST_F(MediatorCSDKTest, testInitProvProcess)
64 {
65     OCStackResult result = InitProvProcess();
66     ASSERT_EQ(OC_STACK_OK, result);
67 }
68
69 //ResetProvProcess
70 TEST_F(MediatorCSDKTest, testResetProvProcess)
71 {
72     OCStackResult result = ResetProvProcess();
73     ASSERT_EQ(OC_STACK_OK, result);
74 }
75
76 //RegisterCallback [positive]
77 TEST_F(MediatorCSDKTest, testRegisterCallback)
78 {
79     OCStackResult result = RegisterCallback(&OCProvisioningStatusCallback);
80     ASSERT_EQ(OC_STACK_OK, result);
81 }
82
83 //RegisterCallback [Negative]
84 TEST_F(MediatorCSDKTest, testRegisterCallbackNegative)
85 {
86     OCStackResult result = RegisterCallback(NULL);
87     ASSERT_EQ(OC_STACK_ERROR, result);
88 }
89
90 //StartProvisioning [positive]
91 TEST_F(MediatorCSDKTest, testStartProvisioning)
92 {
93     ProvConfig provConfig;
94     WiFiOnboadingConnection onboardConn;
95
96     strncpy(onboardConn.ipAddress, "1.1.1.1", IPV4_ADDR_SIZE - 1);
97
98     strncpy(provConfig.provData.WIFI.ssid, "testAP", NET_WIFI_SSID_SIZE - 1);
99     strncpy(provConfig.provData.WIFI.pwd, "test@123", NET_WIFI_PWD_SIZE - 1);
100     provConfig.connType = CT_ADAPTER_IP;
101
102     //API Call
103     OCStackResult result =    StartProvisioning(&provConfig, &onboardConn);
104
105     ASSERT_EQ(OC_STACK_OK, result);
106 }
107
108 //StartProvisioning [Negative]
109 TEST_F(MediatorCSDKTest, testStartProvisioningNegative)
110 {
111     OCStackResult result = StartProvisioning(NULL, NULL);
112     ASSERT_EQ(OC_STACK_ERROR, result);
113 }
114
115 //StopProvisioning
116 TEST_F(MediatorCSDKTest, testStopProvisioning)
117 {
118     // This API always return success
119     OCStackResult result = StopProvisioning(CT_ADAPTER_IP);
120     ASSERT_EQ(OC_STACK_OK, result);
121 }
122
123