Unit Tests added for CoAP-HTTP Proxy module
authorRajendra S <raje_ndra.s@samsung.com>
Fri, 30 Sep 2016 11:06:36 +0000 (16:36 +0530)
committerUze Choi <uzchoi@samsung.com>
Thu, 13 Oct 2016 00:46:00 +0000 (00:46 +0000)
Change-Id: I8554cd9010bbd27ef29f1615a53f62cda4e41d30
Signed-off-by: Rajendra <raje_ndra.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/12615
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
service/coap-http-proxy/SConscript
service/coap-http-proxy/unittests/CoAPHttpUnitTest.cpp [new file with mode: 0644]
service/coap-http-proxy/unittests/SConscript [new file with mode: 0644]

index 4d9c5e6..a44d0c1 100644 (file)
@@ -84,3 +84,6 @@ local_env.UserInstallTargetHeader('include/CoapHttpHandler.h', 'service/coap-htt
 ######################################################################
 if target_os in ['linux', 'tizen']:
     SConscript('samples/SConscript')
+
+if target_os in ['linux']:
+    SConscript('unittests/SConscript')
diff --git a/service/coap-http-proxy/unittests/CoAPHttpUnitTest.cpp b/service/coap-http-proxy/unittests/CoAPHttpUnitTest.cpp
new file mode 100644 (file)
index 0000000..d59d7ce
--- /dev/null
@@ -0,0 +1,128 @@
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#include "UnitTestHelper.h"
+
+#include "CoapHttpHandler.h"
+
+#include "oic_malloc.h"
+#include "oic_string.h"
+#include "logger.h"
+#include "ocpayload.h"
+#include "uarraylist.h"
+#include "CoapHttpParser.h"
+#include "CoapHttpMap.h"
+#include "cJSON.h"
+
+#include <signal.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+
+typedef struct
+{
+    OCMethod method;
+    OCRequestHandle requestHandle;
+}CHPRequest_t; 
+
+static int g_quitFlag = 0;
+static int g_secureFlag = 0;
+
+class CoApHttpTest: public TestWithMock
+{
+protected:
+    void SetUp()
+    {
+        TestWithMock::SetUp();
+    }
+};
+
+TEST_F(CoApHttpTest, OcInit)
+{
+    EXPECT_EQ(OC_STACK_OK, OCInit(NULL, 0, OC_SERVER));
+}
+
+TEST_F(CoApHttpTest, CHPInitialize)
+{
+
+    EXPECT_EQ(OC_STACK_OK, (CHPInitialize(g_secureFlag)));
+}
+
+TEST_F(CoApHttpTest, CHPIsInitialized)
+{
+
+    EXPECT_EQ(true, (CHPIsInitialized()));
+}
+
+
+TEST_F(CoApHttpTest, CHPTerminate)
+{
+
+    EXPECT_EQ(OC_STACK_OK, (CHPTerminate()));
+}
+
+TEST_F(CoApHttpTest, CHPGetOCCode)
+{
+    CHPRequest_t context;
+    //enum HttpResponseResult_t httpCode = 200;
+    static OCResourceHandle g_proxyHandle = NULL;
+    OCEntityHandlerResponse response = { .requestHandle = context.requestHandle,
+                                         .resourceHandle = g_proxyHandle};
+    response.persistentBufferFlag = 0;
+
+    EXPECT_EQ(OC_STACK_OK, (CHPGetOCCode((const HttpResponseResult_t)200,(const OCMethod)context.method,&response.ehResult)));
+}
+
+TEST_F(CoApHttpTest, CHPGetOCOption)
+{
+    int numOptions = 0;
+    OCHeaderOption *ret = NULL;
+    const HttpResponse_t *httpResponse = NULL;
+    HttpHeaderOption_t *httpOption = NULL;
+    EXPECT_NE(OC_STACK_OK, (CHPGetOCOption(httpOption,ret)));
+}
+
+TEST_F(CoApHttpTest, CHPGetOCContentType)
+{
+    HttpResponse_t httpResponse;
+    //char *httpContentType = "OC_FORMAT_CBOR";
+    char *httpContentType = "CBOR_CONTENT_TYPE";
+    EXPECT_EQ(OC_FORMAT_CBOR, (CHPGetOCContentType(httpContentType)));
+}
+
+TEST_F(CoApHttpTest, CHPGetHttpMethod)
+{
+    CHPRequest_t context;
+    HttpRequest_t httpRequest = { .httpMajor = 1,
+                                  .httpMinor = 1};
+
+    EXPECT_NE(OC_STACK_OK, (CHPGetHttpMethod((const OCMethod)context.method,&httpRequest.method)));
+}
+
+TEST_F(CoApHttpTest, CHPParserInitialize)
+{
+    EXPECT_EQ(OC_STACK_OK, (CHPParserInitialize()));
+}
+
+TEST_F(CoApHttpTest, CHPParserTerminate)
+{
+    EXPECT_EQ(OC_STACK_OK, (CHPParserTerminate()));
+}
+
diff --git a/service/coap-http-proxy/unittests/SConscript b/service/coap-http-proxy/unittests/SConscript
new file mode 100644 (file)
index 0000000..e5677bc
--- /dev/null
@@ -0,0 +1,94 @@
+#******************************************************************
+#
+# Copyright 2016 Samsung Electronics All Rights Reserved.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+import os
+import os.path
+
+##
+# CoAP-HTTP Proxy Unit Test build script
+##
+# SConscript file for Local PKI google tests
+gtest_env = SConscript('#extlibs/gtest/SConscript')
+lib_env = gtest_env.Clone()
+
+if lib_env.get('RELEASE'):
+    lib_env.AppendUnique(CCFLAGS = ['-Os'])
+    lib_env.AppendUnique(CPPDEFINES = ['NDEBUG'])
+else:
+    lib_env.AppendUnique(CCFLAGS = ['-g'])
+
+if lib_env.get('LOGGING'):
+    lib_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+
+SConscript('#service/third_party_libs.scons', 'lib_env')
+
+######################################################################
+#unit test setting
+######################################################################
+src_dir = lib_env.get('SRC_DIR')
+
+CoAP_test_env = lib_env.Clone()
+target_os = CoAP_test_env.get('TARGET_OS')
+
+######################################################################
+# Build flags
+######################################################################
+
+CoAP_test_env.AppendUnique(LIBPATH = [lib_env.get('BUILD_DIR')])
+CoAP_test_env.AppendUnique(LIBS = [
+    'coap_http_proxy','oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'coap'])
+
+if target_os not in ['windows']:
+    CoAP_test_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0'])
+
+if not CoAP_test_env.get('RELEASE'):
+    CoAP_test_env.PrependUnique(LIBS = ['gcov'])
+    CoAP_test_env.AppendUnique(CXXFLAGS = ['--coverage'])
+
+CoAP_test_env.AppendUnique(CPPPATH = [src_dir + '/extlibs/hippomocks-master',
+                        '../include',
+                        os.path.join(src_dir, 'resource/csdk/stack/include'),
+                        os.path.join(src_dir, 'resource/csdk/connectivity/common/inc/'),
+                        os.path.join(src_dir, 'resource/csdk/connectivity/lib/libcoap-4.1.1'),
+                        os.path.join(src_dir, 'extlibs/cjson'),
+                ])
+
+CoAP_test_env.AppendUnique(CPPPATH = ['../../resource-encapsulation/include'])
+CoAP_test_env.AppendUnique(CPPPATH = ['../../resource-encapsulation/src/common/primitiveResource/include'])
+CoAP_test_env.AppendUnique(CPPPATH = ['../../resource-encapsulation/src/common/utils/include'])
+
+
+if target_os in ['linux']:
+    CoAP_test_env.AppendUnique(LIBS = ['pthread', 'curl'])
+
+
+if CoAP_test_env.get('SECURED') == '1':
+       if CoAP_test_env.get('WITH_TCP') == True:
+               CoAP_test_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509', 'mbedcrypto','tinydtls'])
+######################################################################
+# Build Test
+######################################################################
+
+CoAP_unit_test_src = CoAP_test_env.Glob('./CoAPHttpUnitTest.cpp')
+CoAP_unit_test = CoAP_test_env.Program('CoAP_unit_test', CoAP_unit_test_src)
+Alias("CoAP_unit_test", CoAP_unit_test)
+CoAP_test_env.AppendTarget('CoAP_unit_test')
+CoAP_test_env.InstallTarget(CoAP_unit_test, 'CoAP_unit_test')
+