Enable unit tests 32/260132/1
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 21 Jun 2021 04:47:55 +0000 (13:47 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 21 Jun 2021 04:47:55 +0000 (13:47 +0900)
Change-Id: I284aea62d547f8fd3a76a2e27cf3da55c0cea2af
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
test/unit_tests/CMakeLists.txt
test/unit_tests/mock/glib_mock.cc
test/unit_tests/mock/glib_mock.h

index 1c60896..3bbc0f5 100644 (file)
@@ -42,7 +42,7 @@ SET_TARGET_PROPERTIES(${TARGET_AUL_UNIT_TESTS} PROPERTIES LINK_FLAGS "-pie")
 INSTALL(TARGETS ${TARGET_AUL_UNIT_TESTS} DESTINATION bin)
 
 
-#ADD_TEST(
-#  NAME ${TARGET_AUL_UNIT_TESTS}
-#  COMMAND ${TARGET_AUL_UNIT_TESTS}
-#)
+ADD_TEST(
+  NAME ${TARGET_AUL_UNIT_TESTS}
+  COMMAND ${TARGET_AUL_UNIT_TESTS}
+)
index c662df8..d6c20f2 100644 (file)
  * limitations under the License.
  */
 
+#include <dlfcn.h>
+
 #include "mock/glib_mock.h"
 #include "mock/mock_hook.h"
 #include "mock/test_fixture.h"
 
 extern "C" GIOChannel* g_io_channel_unix_new(gint fd) {
-  return MOCK_HOOK_P1(GlibMock, g_io_channel_unix_new, fd);
-}
-
-extern "C" guint g_io_add_watch(GIOChannel* channel, GIOCondition condition,
-    GIOFunc func, gpointer user_data) {
-  return MOCK_HOOK_P4(GlibMock, g_io_add_watch, channel, condition, func,
-      user_data);
-}
-
-extern "C" void g_io_channel_set_close_on_unref(GIOChannel* channel,
-    gboolean do_close) {
-}
-
-extern "C" void g_io_channel_unref(GIOChannel* channel) {
-}
-
-extern "C" gint g_io_channel_unix_get_fd(GIOChannel* channel) {
-  return MOCK_HOOK_P1(GlibMock, g_io_channel_unix_get_fd, channel);
-}
-
-extern "C" guint g_idle_add_full(gint priority, GSourceFunc function,
-    gpointer data, GDestroyNotify notify) {
-  return MOCK_HOOK_P4(GlibMock, g_idle_add_full, priority, function, data,
-      notify);
-}
-
-extern "C" GSource* g_io_create_watch(GIOChannel* channel,
-    GIOCondition condition) {
-  return MOCK_HOOK_P2(GlibMock, g_io_create_watch, channel, condition);
-}
-
-extern "C" void g_source_unref(GSource* source) {
-}
-
-extern "C" void g_source_set_callback(GSource* source, GSourceFunc func,
-    gpointer data, GDestroyNotify notify) {
-  MOCK_HOOK_P4(GlibMock, g_source_set_callback, source, func, data, notify);
-}
-
-extern "C" void g_source_set_priority(GSource* source, gint priority) {
-  MOCK_HOOK_P2(GlibMock, g_source_set_priority, source, priority);
-}
-
-extern "C" guint g_source_attach (GSource* source, GMainContext* context) {
-  return MOCK_HOOK_P2(GlibMock, g_source_attach, source, context);
-}
-
-extern "C" GIOStatus g_io_channel_shutdown(GIOChannel* channel,
-    gboolean flush, GError** err) {
-  return MOCK_HOOK_P3(GlibMock, g_io_channel_shutdown, channel, flush, err);
-}
+  GIOChannel* (*g_io_channel_unix_new_func)(gint) =
+      reinterpret_cast<GIOChannel* (*)(gint)>(
+          dlsym(RTLD_NEXT, "g_io_channel_unix_new"));
+  if (g_io_channel_unix_new_func)
+    return g_io_channel_unix_new_func(1);
 
-extern "C" gboolean g_main_loop_is_running (GMainLoop *loop) {
-  return MOCK_HOOK_P1(GlibMock, g_main_loop_is_running, loop);
+  return nullptr;
 }
index fe695a1..8012e5f 100644 (file)
@@ -29,43 +29,9 @@ class GlibMock : public virtual ModuleMock {
     using ::testing::_;
     using ::testing::Return;
     using ::testing::Invoke;
-
-    static int dummy;
-    GIOChannel* ch = (GIOChannel*)&dummy;
-    GSource* source = (GSource*)&dummy;
-
-    ON_CALL(*this, g_io_channel_unix_new(_))
-        .WillByDefault(Return(ch));
-    ON_CALL(*this, g_io_add_watch(_, _, _, _))
-        .WillByDefault(Return(1));
-    ON_CALL(*this, g_io_channel_unix_get_fd(_))
-        .WillByDefault(Return(1));
-    ON_CALL(*this, g_idle_add_full(_, _, _, _))
-        .WillByDefault(Invoke([&](gint priority, GSourceFunc function,
-            gpointer data, GDestroyNotify notify) -> guint {
-          function(data);
-          return 1;
-        }));
-    ON_CALL(*this, g_io_create_watch(_, _))
-        .WillByDefault(Return(source));
-    ON_CALL(*this, g_main_loop_is_running(_))
-        .WillByDefault(Return(TRUE));
   }
 
   MOCK_METHOD1(g_io_channel_unix_new, GIOChannel* (gint));
-  MOCK_METHOD4(g_io_add_watch, guint (GIOChannel*, GIOCondition,
-      GIOFunc, gpointer));
-  MOCK_METHOD1(g_io_channel_unix_get_fd, gint (GIOChannel*));
-  MOCK_METHOD4(g_idle_add_full, guint (gint, GSourceFunc, gpointer,
-      GDestroyNotify));
-  MOCK_METHOD1(g_main_loop_is_running, gboolean (GMainLoop*));
-  MOCK_METHOD2(g_io_create_watch, GSource* (GIOChannel*, GIOCondition));
-  MOCK_METHOD4(g_source_set_callback, void (GSource*, GSourceFunc, gpointer,
-      GDestroyNotify));
-  MOCK_METHOD2(g_source_set_priority, void (GSource*, gint));
-  MOCK_METHOD2(g_source_attach, guint (GSource*, GMainContext*));
-  MOCK_METHOD3(g_io_channel_shutdown, GIOStatus (GIOChannel*, gboolean,
-      GError**));
 };
 
 #endif  // UNIT_TESTS_MOCK_GLIB_MOCK_H_