replace : iotivity -> iotivity-sec
[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 #if defined (__TIZENRT__)
32 #include <apps/netutils/cJSON.h>
33 #else
34 #include "cJSON.h"
35 #endif
36
37 #include <signal.h>
38 #ifdef HAVE_UNISTD_H
39 #include <unistd.h>
40 #endif
41
42
43 typedef struct
44 {
45     OCMethod method;
46     OCRequestHandle requestHandle;
47 }CHPRequest_t; 
48
49 static int g_quitFlag = 0;
50 static int g_secureFlag = 0;
51
52 class CoApHttpTest: public TestWithMock
53 {
54 protected:
55     void SetUp()
56     {
57         TestWithMock::SetUp();
58     }
59 };
60
61 TEST_F(CoApHttpTest, OcInit)
62 {
63     EXPECT_EQ(OC_STACK_OK, OCInit(NULL, 0, OC_SERVER));
64 }
65
66 TEST_F(CoApHttpTest, CHPInitialize)
67 {
68
69     EXPECT_EQ(OC_STACK_OK, (CHPInitialize(g_secureFlag)));
70 }
71
72 TEST_F(CoApHttpTest, CHPIsInitialized)
73 {
74
75     EXPECT_EQ(true, (CHPIsInitialized()));
76 }
77
78
79 TEST_F(CoApHttpTest, CHPTerminate)
80 {
81
82     EXPECT_EQ(OC_STACK_OK, (CHPTerminate()));
83 }
84
85 TEST_F(CoApHttpTest, CHPGetOCCode)
86 {
87     CHPRequest_t context;
88     //enum HttpResponseResult_t httpCode = 200;
89     static OCResourceHandle g_proxyHandle = NULL;
90     OCEntityHandlerResponse response = { .requestHandle = context.requestHandle,
91                                          .resourceHandle = g_proxyHandle};
92     response.persistentBufferFlag = 0;
93
94     EXPECT_EQ(OC_STACK_OK, (CHPGetOCCode((const HttpResponseResult_t)200,(const OCMethod)context.method,&response.ehResult)));
95 }
96
97 TEST_F(CoApHttpTest, CHPGetOCOption)
98 {
99     int numOptions = 0;
100     OCHeaderOption *ret = NULL;
101     const HttpResponse_t *httpResponse = NULL;
102     HttpHeaderOption_t *httpOption = NULL;
103     EXPECT_NE(OC_STACK_OK, (CHPGetOCOption(httpOption,ret)));
104 }
105
106 TEST_F(CoApHttpTest, CHPGetOCContentType)
107 {
108     HttpResponse_t httpResponse;
109     //char *httpContentType = "OC_FORMAT_CBOR";
110     char httpContentType[64];
111     strcpy(httpContentType, "application/cbor");
112     EXPECT_EQ(OC_FORMAT_CBOR, (CHPGetOCContentType(httpContentType)));
113 }
114
115 TEST_F(CoApHttpTest, CHPGetHttpMethod)
116 {
117     CHPRequest_t context;
118     HttpRequest_t httpRequest = { .httpMajor = 1,
119                                   .httpMinor = 1};
120
121     EXPECT_NE(OC_STACK_OK, (CHPGetHttpMethod((const OCMethod)context.method,&httpRequest.method)));
122 }
123
124 TEST_F(CoApHttpTest, CHPParserInitialize)
125 {
126     EXPECT_EQ(OC_STACK_OK, (CHPParserInitialize()));
127 }
128
129 TEST_F(CoApHttpTest, CHPParserTerminate)
130 {
131     EXPECT_EQ(OC_STACK_OK, (CHPParserTerminate()));
132 }
133