Unit Tests added for CoAP-HTTP Proxy module
[platform/upstream/iotivity.git] / service / coap-http-proxy / unittests / CoAPHttpUnitTest.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 "UnitTestHelper.h"
21
22 #include "CoapHttpHandler.h"
23
24 #include "oic_malloc.h"
25 #include "oic_string.h"
26 #include "logger.h"
27 #include "ocpayload.h"
28 #include "uarraylist.h"
29 #include "CoapHttpParser.h"
30 #include "CoapHttpMap.h"
31 #include "cJSON.h"
32
33 #include <signal.h>
34 #ifdef HAVE_UNISTD_H
35 #include <unistd.h>
36 #endif
37
38
39 typedef struct
40 {
41     OCMethod method;
42     OCRequestHandle requestHandle;
43 }CHPRequest_t; 
44
45 static int g_quitFlag = 0;
46 static int g_secureFlag = 0;
47
48 class CoApHttpTest: public TestWithMock
49 {
50 protected:
51     void SetUp()
52     {
53         TestWithMock::SetUp();
54     }
55 };
56
57 TEST_F(CoApHttpTest, OcInit)
58 {
59     EXPECT_EQ(OC_STACK_OK, OCInit(NULL, 0, OC_SERVER));
60 }
61
62 TEST_F(CoApHttpTest, CHPInitialize)
63 {
64
65     EXPECT_EQ(OC_STACK_OK, (CHPInitialize(g_secureFlag)));
66 }
67
68 TEST_F(CoApHttpTest, CHPIsInitialized)
69 {
70
71     EXPECT_EQ(true, (CHPIsInitialized()));
72 }
73
74
75 TEST_F(CoApHttpTest, CHPTerminate)
76 {
77
78     EXPECT_EQ(OC_STACK_OK, (CHPTerminate()));
79 }
80
81 TEST_F(CoApHttpTest, CHPGetOCCode)
82 {
83     CHPRequest_t context;
84     //enum HttpResponseResult_t httpCode = 200;
85     static OCResourceHandle g_proxyHandle = NULL;
86     OCEntityHandlerResponse response = { .requestHandle = context.requestHandle,
87                                          .resourceHandle = g_proxyHandle};
88     response.persistentBufferFlag = 0;
89
90     EXPECT_EQ(OC_STACK_OK, (CHPGetOCCode((const HttpResponseResult_t)200,(const OCMethod)context.method,&response.ehResult)));
91 }
92
93 TEST_F(CoApHttpTest, CHPGetOCOption)
94 {
95     int numOptions = 0;
96     OCHeaderOption *ret = NULL;
97     const HttpResponse_t *httpResponse = NULL;
98     HttpHeaderOption_t *httpOption = NULL;
99     EXPECT_NE(OC_STACK_OK, (CHPGetOCOption(httpOption,ret)));
100 }
101
102 TEST_F(CoApHttpTest, CHPGetOCContentType)
103 {
104     HttpResponse_t httpResponse;
105     //char *httpContentType = "OC_FORMAT_CBOR";
106     char *httpContentType = "CBOR_CONTENT_TYPE";
107     EXPECT_EQ(OC_FORMAT_CBOR, (CHPGetOCContentType(httpContentType)));
108 }
109
110 TEST_F(CoApHttpTest, CHPGetHttpMethod)
111 {
112     CHPRequest_t context;
113     HttpRequest_t httpRequest = { .httpMajor = 1,
114                                   .httpMinor = 1};
115
116     EXPECT_NE(OC_STACK_OK, (CHPGetHttpMethod((const OCMethod)context.method,&httpRequest.method)));
117 }
118
119 TEST_F(CoApHttpTest, CHPParserInitialize)
120 {
121     EXPECT_EQ(OC_STACK_OK, (CHPParserInitialize()));
122 }
123
124 TEST_F(CoApHttpTest, CHPParserTerminate)
125 {
126     EXPECT_EQ(OC_STACK_OK, (CHPParserTerminate()));
127 }
128