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"
31 #if defined (__TIZENRT__)
32 #include <apps/netutils/cJSON.h>
46 OCRequestHandle requestHandle;
49 static int g_quitFlag = 0;
50 static int g_secureFlag = 0;
52 class CoApHttpTest: public TestWithMock
57 TestWithMock::SetUp();
61 TEST_F(CoApHttpTest, OcInit)
63 EXPECT_EQ(OC_STACK_OK, OCInit(NULL, 0, OC_SERVER));
66 TEST_F(CoApHttpTest, CHPInitialize)
69 EXPECT_EQ(OC_STACK_OK, (CHPInitialize(g_secureFlag)));
72 TEST_F(CoApHttpTest, CHPIsInitialized)
75 EXPECT_EQ(true, (CHPIsInitialized()));
79 TEST_F(CoApHttpTest, CHPTerminate)
82 EXPECT_EQ(OC_STACK_OK, (CHPTerminate()));
85 TEST_F(CoApHttpTest, CHPGetOCCode)
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;
94 EXPECT_EQ(OC_STACK_OK, (CHPGetOCCode((const HttpResponseResult_t)200,(const OCMethod)context.method,&response.ehResult)));
97 TEST_F(CoApHttpTest, CHPGetOCOption)
100 OCHeaderOption *ret = NULL;
101 const HttpResponse_t *httpResponse = NULL;
102 HttpHeaderOption_t *httpOption = NULL;
103 EXPECT_NE(OC_STACK_OK, (CHPGetOCOption(httpOption,ret)));
106 TEST_F(CoApHttpTest, CHPGetOCContentType)
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)));
115 TEST_F(CoApHttpTest, CHPGetHttpMethod)
117 CHPRequest_t context;
118 HttpRequest_t httpRequest = { .httpMajor = 1,
121 EXPECT_NE(OC_STACK_OK, (CHPGetHttpMethod((const OCMethod)context.method,&httpRequest.method)));
124 TEST_F(CoApHttpTest, CHPParserInitialize)
126 EXPECT_EQ(OC_STACK_OK, (CHPParserInitialize()));
129 TEST_F(CoApHttpTest, CHPParserTerminate)
131 EXPECT_EQ(OC_STACK_OK, (CHPParserTerminate()));