aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMike Gabriel <mike.gabriel@das-netzwerkteam.de>2021-08-26 07:33:21 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2021-08-26 07:33:21 +0200
commitb32fac907b6e61f0f94d28d0e44d77bf0883c8e2 (patch)
treec32ed6a4be5b03d5e5bccd8f7c510cac278a8854 /tests
parent7f9519e1b54d4e864f2573583945419ef56f8a05 (diff)
parentc7320dab38cb2dda29226eab2c8705b5a132ac87 (diff)
downloadlibayatana-common-b32fac907b6e61f0f94d28d0e44d77bf0883c8e2.tar.gz
libayatana-common-b32fac907b6e61f0f94d28d0e44d77bf0883c8e2.tar.bz2
libayatana-common-b32fac907b6e61f0f94d28d0e44d77bf0883c8e2.zip
Merge branch 'tari01-pr/add-vala-bindings'
Attributes GH PR #35: https://github.com/AyatanaIndicators/libayatana-common/pull/35
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt30
-rw-r--r--tests/tst_utils.vala57
2 files changed, 87 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 0349ae6..61ce542 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -32,3 +32,33 @@ target_link_libraries(tst_utils
)
add_test(TstUtils tst_utils)
+
+# utils.h
+
+file(COPY "${CMAKE_SOURCE_DIR}/src/utils.h" DESTINATION "${CMAKE_BINARY_DIR}/src/ayatana/common")
+
+# tst_utils.c
+
+add_custom_command(
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/tst_utils.c"
+ DEPENDS "src"
+ DEPENDS "gschemas-compiled"
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ COMMAND
+ ${VALA_COMPILER}
+ --pkg AyatanaCommon
+ --pkg gio-2.0
+ --vapidir=${CMAKE_BINARY_DIR}/src
+ --ccode tst_utils.vala
+ --directory=${CMAKE_CURRENT_BINARY_DIR}
+)
+
+# tst_utils_vala
+
+add_executable("tst_utils_vala" "${CMAKE_CURRENT_BINARY_DIR}/tst_utils.c")
+target_include_directories("tst_utils_vala" PUBLIC "${GLIB_INCLUDE_DIRS};${CMAKE_BINARY_DIR}/src")
+target_link_libraries("tst_utils_vala" "${GLIB_LIBRARIES} -layatana-common -L${CMAKE_BINARY_DIR}/src")
+target_link_directories("tst_utils_vala" PUBLIC "${CMAKE_BINARY_DIR}/src")
+add_dependencies("tst_utils_vala" "src")
+
+add_test(NAME "TstUtilsVala" COMMAND "${CMAKE_CURRENT_BINARY_DIR}/tst_utils_vala" "${CMAKE_CURRENT_BINARY_DIR}")
diff --git a/tests/tst_utils.vala b/tests/tst_utils.vala
new file mode 100644
index 0000000..b46fb24
--- /dev/null
+++ b/tests/tst_utils.vala
@@ -0,0 +1,57 @@
+using AyatanaCommon;
+using Environment;
+
+static int main(string[] args)
+{
+ assert_true(args.length == 2);
+
+ unset_variable("XDG_CURRENT_DESKTOP");
+
+ assert_false(utils_is_lomiri());
+ set_variable("XDG_CURRENT_DESKTOP", "Lomiri", true);
+ assert_true(utils_is_lomiri());
+
+ assert_false(utils_is_gnome());
+ set_variable("XDG_CURRENT_DESKTOP", "GNOME", true);
+ assert_true(utils_is_gnome());
+
+ assert_false(utils_is_unity());
+ set_variable("XDG_CURRENT_DESKTOP", "Unity", true);
+ assert_true(utils_is_unity());
+
+ assert_false(utils_is_mate());
+ set_variable("XDG_CURRENT_DESKTOP", "MATE", true);
+ assert_true(utils_is_mate());
+
+ assert_false(utils_is_xfce());
+ set_variable("XDG_CURRENT_DESKTOP", "XFCE", true);
+ assert_true(utils_is_xfce());
+
+ assert_false(utils_is_pantheon());
+ set_variable("XDG_CURRENT_DESKTOP", "PANTHEON", true);
+ assert_true(utils_is_pantheon());
+
+ assert_false(utils_is_budgie());
+ set_variable("XDG_CURRENT_DESKTOP", "Budgie:GNOME", true);
+ assert_true(utils_is_budgie());
+
+ unset_variable("XDG_CURRENT_DESKTOP");
+ set_variable("GSETTINGS_SCHEMA_DIR", args[1], true);
+ set_variable("GSETTINGS_BACKEND", "memory", true);
+
+ Settings pSettings = new Settings("org.ayatana.common");
+ string sTest = "123456789012345678901234567890123456789012345öüóőúéáűšđß";
+ pSettings.set_uint("max-menu-text-length", 0);
+ utils_ellipsize(sTest);
+ assert_true(sTest == "123456789012345678901234567890123456789012345öüóőúéáűšđß");
+
+ pSettings.set_uint("max-menu-text-length", 100);
+ utils_ellipsize(sTest);
+ assert_true(sTest == "123456789012345678901234567890123456789012345öüóőúéáűšđß");
+
+ pSettings.set_uint("max-menu-text-length", 50);
+ utils_ellipsize(sTest);
+ assert_true(sTest == "123456789012345678901234567890123456789012345öüóőú...");
+
+ return 0;
+}