1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20 #include "UnitTestHelper.h"
22 #include "CoapHttpHandler.h"
24 #include "oic_malloc.h"
25 #include "oic_string.h"
27 #include "ocpayload.h"
28 #include "uarraylist.h"
29 #include "CoapHttpParser.h"
30 #include "CoapHttpMap.h"
42 OCRequestHandle requestHandle;
45 static int g_quitFlag = 0;
46 static int g_secureFlag = 0;
48 class CoApHttpTest: public TestWithMock
53 TestWithMock::SetUp();
57 TEST_F(CoApHttpTest, OcInit)
59 EXPECT_EQ(OC_STACK_OK, OCInit(NULL, 0, OC_SERVER));
62 TEST_F(CoApHttpTest, CHPInitialize)
65 EXPECT_EQ(OC_STACK_OK, (CHPInitialize(g_secureFlag)));
68 TEST_F(CoApHttpTest, CHPIsInitialized)
71 EXPECT_EQ(true, (CHPIsInitialized()));
75 TEST_F(CoApHttpTest, CHPTerminate)
78 EXPECT_EQ(OC_STACK_OK, (CHPTerminate()));
81 TEST_F(CoApHttpTest, CHPGetOCCode)
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;
90 EXPECT_EQ(OC_STACK_OK, (CHPGetOCCode((const HttpResponseResult_t)200,(const OCMethod)context.method,&response.ehResult)));
93 TEST_F(CoApHttpTest, CHPGetOCOption)
96 OCHeaderOption *ret = NULL;
97 const HttpResponse_t *httpResponse = NULL;
98 HttpHeaderOption_t *httpOption = NULL;
99 EXPECT_NE(OC_STACK_OK, (CHPGetOCOption(httpOption,ret)));
102 TEST_F(CoApHttpTest, CHPGetOCContentType)
104 HttpResponse_t httpResponse;
105 //char *httpContentType = "OC_FORMAT_CBOR";
106 char httpContentType[64];
107 strcpy(httpContentType, "application/cbor");
108 EXPECT_EQ(OC_FORMAT_CBOR, (CHPGetOCContentType(httpContentType)));
111 TEST_F(CoApHttpTest, CHPGetHttpMethod)
113 CHPRequest_t context;
114 HttpRequest_t httpRequest = { .httpMajor = 1,
117 EXPECT_NE(OC_STACK_OK, (CHPGetHttpMethod((const OCMethod)context.method,&httpRequest.method)));
120 TEST_F(CoApHttpTest, CHPParserInitialize)
122 EXPECT_EQ(OC_STACK_OK, (CHPParserInitialize()));
125 TEST_F(CoApHttpTest, CHPParserTerminate)
127 EXPECT_EQ(OC_STACK_OK, (CHPParserTerminate()));