From 338861eb27c91de0734d4499ec1100b4e50d39ad Mon Sep 17 00:00:00 2001 From: Wook Song Date: Tue, 2 May 2023 13:17:32 +0900 Subject: [PATCH] Tests: Add test cases for gdbus-util This patch adds unit test cases for the helper functions in the gdbus-util.c file. Signed-off-by: Wook Song --- packaging/machine-learning-api.spec | 1 + tests/daemon/meson.build | 10 ++++++ tests/daemon/unittest_gdbus_util.cc | 68 +++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 tests/daemon/unittest_gdbus_util.cc diff --git a/packaging/machine-learning-api.spec b/packaging/machine-learning-api.spec index 1eaf703..f11970d 100644 --- a/packaging/machine-learning-api.spec +++ b/packaging/machine-learning-api.spec @@ -391,6 +391,7 @@ bash %{test_script} ./tests/capi/unittest_capi_datatype_consistency %if 0%{?enable_ml_service} bash %{test_script} ./tests/daemon/unittest_ml_agent bash %{test_script} ./tests/daemon/unittest_service_db +bash %{test_script} ./tests/daemon/unittest_gdbus_util bash %{test_script} ./tests/capi/unittest_capi_service_agent_client %endif diff --git a/tests/daemon/meson.build b/tests/daemon/meson.build index a125a36..3e3fa4f 100644 --- a/tests/daemon/meson.build +++ b/tests/daemon/meson.build @@ -16,3 +16,13 @@ unittest_service_db = executable('unittest_service_db', include_directories: [nns_capi_include, ml_agentd_incs], ) test('unittest_service_db', unittest_service_db, env: testenv, timeout: 100) + +unittest_gdbus_util = executable('unittest_gdbus_util', + 'unittest_gdbus_util.cc', + dependencies: [unittest_common_dep], + link_with: ml_agentd_lib, + install: get_option('install-test'), + install_dir: unittest_install_dir, + include_directories: [ml_agentd_incs], +) +test('unittest_gdbus_util', unittest_gdbus_util, env: testenv, timeout: 100) diff --git a/tests/daemon/unittest_gdbus_util.cc b/tests/daemon/unittest_gdbus_util.cc new file mode 100644 index 0000000..522dee0 --- /dev/null +++ b/tests/daemon/unittest_gdbus_util.cc @@ -0,0 +1,68 @@ +/** + * @file unittest_gdbus_util.cc + * @date 2 May 2023 + * @brief Unit test for GDBus Utility functions + * @see https://github.com/nnstreamer/api + * @author Wook Song + * @bug No known bugs + */ + +#include + +#include "dbus-interface.h" +#include "gdbus-util.h" + +/** + * @brief Negative test for the gdbus helper function, gdbus_export_interface + */ +TEST (gdbusInstanceNotInitialized, export_interface_n) +{ + int ret; + + ret = gdbus_export_interface (nullptr, DBUS_PIPELINE_PATH); + EXPECT_EQ (-ENOSYS, ret); + + ret = gdbus_export_interface (nullptr, DBUS_MODEL_PATH); + EXPECT_EQ (-ENOSYS, ret); + + ret = gdbus_get_name (DBUS_ML_BUS_NAME); + EXPECT_EQ (-ENOSYS, ret); +} + +/** + * @brief Negative test for the gdbus helper function, get_system_connection + */ +TEST (gdbusInstanceNotInitialized, get_system_connection_n) +{ + gboolean is_session = true; + int ret; + + ret = gdbus_get_system_connection(is_session); + EXPECT_EQ (-ENOSYS, ret); + + ret = gdbus_get_system_connection(!is_session); + EXPECT_EQ (-ENOSYS, ret); +} + +/** + * @brief Main gtest + */ +int +main (int argc, char **argv) +{ + int result = -1; + + try { + testing::InitGoogleTest (&argc, argv); + } catch (...) { + g_warning ("catch 'testing::internal::::ClassUniqueToAlwaysTrue'"); + } + + try { + result = RUN_ALL_TESTS (); + } catch (...) { + g_warning ("catch `testing::internal::GoogleTestFailureException`"); + } + + return result; +} -- 2.7.4