aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRobert Tari <robert@tari.in>2021-06-16 22:54:43 +0200
committerRobert Tari <robert@tari.in>2021-06-21 02:33:06 +0200
commit33cd95e61dcb5947e7671a8eb21d67014376495e (patch)
tree8b8fc62297a95f6f5a8bbc465f003c8e51733125 /tests
parent4b6ef9d6039078d5ff24ed7e3dd642e2b6faa9fc (diff)
downloadlibayatana-common-33cd95e61dcb5947e7671a8eb21d67014376495e.tar.gz
libayatana-common-33cd95e61dcb5947e7671a8eb21d67014376495e.tar.bz2
libayatana-common-33cd95e61dcb5947e7671a8eb21d67014376495e.zip
Skip elipsizing if max characters are 0
- data/org.ayatana.common.gschema.xml.in: Set min value to 0 + update description - src/utils.c: Include hadling max allowed length of 0 - tests/CMakeLists.txt: Compile schema locally for testing - tests/tst_utils.cpp: Include handling max allowed length of 0 - po/ayatana-common.pot: Update translation strings - po/*.po: Update translation strings fixes https://github.com/AyatanaIndicators/libayatana-common/issues/29
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt22
-rw-r--r--tests/tst_utils.cpp50
2 files changed, 40 insertions, 32 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index d0d05c0..4fa6602 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -2,11 +2,28 @@ find_package(GMock)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -no-pie")
-include_directories(
- ${CMAKE_SOURCE_DIR}/src
+# gschemas.compiled
+
+set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "gschemas.compiled")
+set_source_files_properties("gschemas.compiled" GENERATED)
+execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} gio-2.0 --variable glib_compile_schemas OUTPUT_VARIABLE COMPILE_SCHEMA_EXECUTABLE OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+add_custom_command(
+ OUTPUT "gschemas.compiled"
+ DEPENDS "${CMAKE_BINARY_DIR}/data/org.ayatana.common.gschema.xml"
+ COMMAND cp -f "${CMAKE_BINARY_DIR}/data/org.ayatana.common.gschema.xml" "${CMAKE_CURRENT_BINARY_DIR}"
+ COMMAND ${COMPILE_SCHEMA_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}"
)
+add_custom_target("gschemas-compiled" ALL DEPENDS "gschemas.compiled")
+
+# tst_utils
+
add_executable(tst_utils tst_utils.cpp)
+target_compile_definitions(tst_utils PUBLIC SCHEMA_DIR="${CMAKE_CURRENT_BINARY_DIR}")
+add_dependencies(tst_utils "gschemas-compiled")
+target_include_directories(tst_utils PUBLIC "${CMAKE_SOURCE_DIR}/src")
+
target_link_libraries(tst_utils
ayatana-common
${GLIB_LIBRARIES}
@@ -14,4 +31,5 @@ target_link_libraries(tst_utils
${GTEST_BOTH_LIBRARIES}
${GMOCK_LIBRARIES}
)
+
add_test(TstUtils tst_utils)
diff --git a/tests/tst_utils.cpp b/tests/tst_utils.cpp
index 25099fd..99821ef 100644
--- a/tests/tst_utils.cpp
+++ b/tests/tst_utils.cpp
@@ -90,44 +90,34 @@ public:
void SetUp()
{
- GSettingsSchemaSource *pSource = g_settings_schema_source_get_default();
-
- if (pSource != NULL)
- {
- GSettingsSchema *pSchema = g_settings_schema_source_lookup(pSource, "org.ayatana.common", FALSE);
-
- if (pSchema != NULL)
- {
- g_settings_schema_unref(pSchema);
- this->pSettings = g_settings_new("org.ayatana.common");
- this->nMaxLetters = g_settings_get_uint(pSettings, "max-menu-text-length");
- g_settings_set_uint(this->pSettings, "max-menu-text-length", 50);
- }
- }
+ g_setenv("GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, TRUE);
+ g_setenv("GSETTINGS_BACKEND", "memory", TRUE);
}
void TearDown()
{
- if (this->pSettings != NULL)
- {
- g_settings_set_uint(pSettings, "max-menu-text-length", this->nMaxLetters);
- g_object_unref(this->pSettings);
- }
}
-
-private:
-
- GSettings *pSettings;
- guint nMaxLetters;
};
TEST_F(StringFunctionsTest, elipsize)
{
- gchar *sTest1 = g_strdup("öüóőúéáűšđß");
- ayatana_common_utils_elipsize((gchar*)sTest1);
- EXPECT_STREQ(sTest1, "öüóőúéáűšđß");
+ GSettings *pSettings = g_settings_new("org.ayatana.common");
+ gchar *sTest = g_strdup("123456789012345678901234567890123456789012345öüóőúéáűšđß");
+ g_settings_set_uint(pSettings, "max-menu-text-length", 0);
+ ayatana_common_utils_elipsize(sTest);
+
+ EXPECT_STREQ(sTest, "123456789012345678901234567890123456789012345öüóőúéáűšđß");
+
+ g_settings_set_uint(pSettings, "max-menu-text-length", 100);
+ ayatana_common_utils_elipsize(sTest);
+
+ EXPECT_STREQ(sTest, "123456789012345678901234567890123456789012345öüóőúéáűšđß");
+
+ g_settings_set_uint(pSettings, "max-menu-text-length", 50);
+ ayatana_common_utils_elipsize(sTest);
+
+ EXPECT_STREQ(sTest, "123456789012345678901234567890123456789012345öüóőú...");
- gchar *sTest2 = g_strdup("123456789012345678901234567890123456789012345öüóőúéáűšđß");
- ayatana_common_utils_elipsize((gchar*)sTest2);
- EXPECT_STREQ(sTest2, "123456789012345678901234567890123456789012345öüóőú...");
+ g_free(sTest);
+ g_object_unref(pSettings);
}