Adding unit test for connectivity-abstraction work.
authorJon A. Cruz <jonc@osg.samsung.com>
Fri, 13 Mar 2015 01:29:37 +0000 (18:29 -0700)
committerPatrick Lankswert <patrick.lankswert@intel.com>
Wed, 25 Mar 2015 16:01:00 +0000 (16:01 +0000)
Simple addition of unit test for adding cases related to the
connectivity-abstraction work. Utilized in subsequent commits.

Change-Id: Iee4d688ff78bcb358a4d403e32b81f5fdc3bd060
Signed-off-by: Jon A. Cruz <jonc@osg.samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/474
Reviewed-by: Joseph Morrow <joseph.l.morrow@intel.com>
Reviewed-by: Sakthivel Samidurai <sakthivel.samidurai@intel.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Erich Keane <erich.keane@intel.com>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
Reviewed-by: Patrick Lankswert <patrick.lankswert@intel.com>
resource/csdk/connectivity/test/SConscript [new file with mode: 0644]
resource/csdk/connectivity/test/catests.cpp [new file with mode: 0644]
resource/unit_tests.scons

diff --git a/resource/csdk/connectivity/test/SConscript b/resource/csdk/connectivity/test/SConscript
new file mode 100644 (file)
index 0000000..d19b5c4
--- /dev/null
@@ -0,0 +1,85 @@
+#******************************************************************
+#
+# 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.
+#
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+Import('env')
+import os
+import os.path
+catest_env = env.Clone()
+
+src_dir = catest_env.get('SRC_DIR')
+
+######################################################################
+# Build flags
+######################################################################
+catest_env.PrependUnique(CPPPATH = [
+                '../../ocsocket/include',
+                '../../logger/include',
+                '../../stack/include',
+                '../../ocmalloc/include',
+                '../../extlibs/cjson',
+                '../../../oc_logger/include',
+                '../../../../extlibs/gtest/gtest-1.7.0/include'
+                ])
+
+tmplist = catest_env['LINKFLAGS'][:]
+if '-lpthread' in tmplist:
+    tmplist.remove('-lpthread')
+    catest_env.Replace(LINKFLAGS = tmplist)
+
+catest_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
+catest_env.AppendUnique(LIBS = ['pthread'])
+catest_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+catest_env.AppendUnique(LIBPATH = [src_dir + '/extlibs/gtest/gtest-1.7.0/lib/.libs'])
+catest_env.PrependUnique(LIBS = ['m',
+                                    'octbstack',
+                                    'oc_logger',
+                                    'connectivity_abstraction',
+                                    'coap',
+                                    'gtest',
+                                    'gtest_main'])
+
+if env.get('SECURED') == '1':
+    catest_env.AppendUnique(LIBS = ['tinydtls'])
+catest_env.ParseConfig('pkg-config --libs glib-2.0');
+
+if not env.get('RELEASE'):
+        catest_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+
+######################################################################
+# Source files and Targets
+######################################################################
+catests = catest_env.Program('catests', ['catests.cpp',
+                                         'caprotocolmessagetest.cpp'])
+
+Alias("test", [catests])
+
+env.AppendTarget('test')
+if env.get('TEST') == '1':
+        target_os = env.get('TARGET_OS')
+        if target_os == 'linux':
+                out_dir = env.get('BUILD_DIR')
+                result_dir = env.get('BUILD_DIR') + '/test_out/'
+                if not os.path.isdir(result_dir):
+                        os.makedirs(result_dir)
+                catest_env.AppendENVPath('GTEST_OUTPUT', ['xml:'+ result_dir])
+                catest_env.AppendENVPath('LD_LIBRARY_PATH', [out_dir])
+                catest_env.AppendENVPath('LD_LIBRARY_PATH', ['./extlibs/gtest/gtest-1.7.0/lib/.libs'])
+                ut = catest_env.Command ('ut', None, out_dir + '/resource/csdk/connectivity/test/catests')
+                AlwaysBuild ('ut')
diff --git a/resource/csdk/connectivity/test/catests.cpp b/resource/csdk/connectivity/test/catests.cpp
new file mode 100644 (file)
index 0000000..b07eb6f
--- /dev/null
@@ -0,0 +1,56 @@
+//******************************************************************
+//
+// 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 "gtest/gtest.h"
+
+#include <pthread.h>
+
+/**
+ * Simple holder of work-arounds for link-time issues.
+ */
+void workaroundHook()
+{
+    pthread_key_t key = {0};
+    int ret = pthread_key_create(&key, NULL);
+    if (!ret)
+    {
+        void *ptr = pthread_getspecific(key); // should return NULL
+        ret = pthread_setspecific(key, &ptr);
+        if (ret)
+        {
+            // Something went wrong. Since this is a stub, we don't care.
+        }
+
+        pthread_key_delete(key);
+    }
+}
+
+
+TEST(BaseTest, WorldIsSane)
+{
+    workaroundHook();
+
+    EXPECT_EQ(1 + 1, 2);
+
+    int a = 1;
+    int b = 5;
+
+    EXPECT_GT(b, a);
+}
index 08e64e6..bea8c7e 100644 (file)
@@ -42,6 +42,8 @@ if target_os == 'linux':
        # Build C unit tests
        SConscript('csdk/stack/test/SConscript')
 
+       SConscript('csdk/connectivity/test/SConscript')
+
        # Build C++ unit tests
        SConscript('unittests/SConscript')