aboutsummaryrefslogtreecommitdiff
path: root/tests/tst_utils.cpp
diff options
context:
space:
mode:
authorRobert Tari <robert@tari.in>2021-06-14 23:08:17 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2021-06-16 08:26:44 +0200
commit9be11d94c663ea66cd41a9364a78531537ae405e (patch)
tree51f125b8c5b0560b1ed44668591f6cf3f7b7e5f0 /tests/tst_utils.cpp
parentdb18ded6c8a4ab9d4a0921a3f52e8f3507607238 (diff)
downloadlibayatana-common-9be11d94c663ea66cd41a9364a78531537ae405e.tar.gz
libayatana-common-9be11d94c663ea66cd41a9364a78531537ae405e.tar.bz2
libayatana-common-9be11d94c663ea66cd41a9364a78531537ae405e.zip
Add ability to ellipsize dynamic menu item lengths.
Plus making the maximum length of non-ellipsized strings configurable via GSettings. - data/org.ayatana.common.gschema.xml.in: Add file. - data/CMakeLists.txt: Add file. - CMakeLists.txt: Add gio-2.0 dependency + 'data' build folder. - src/utils.*: Add ayatana_common_utils_elipsize function + include glib-object.h and gio.h - tests/tst_utils.cpp: Add StringFunctionsTest. - tests/CMakeLists.txt: Add GLIB_LIBRARIES to target.
Diffstat (limited to 'tests/tst_utils.cpp')
-rw-r--r--tests/tst_utils.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/tst_utils.cpp b/tests/tst_utils.cpp
index c62bf43..25099fd 100644
--- a/tests/tst_utils.cpp
+++ b/tests/tst_utils.cpp
@@ -79,3 +79,55 @@ TEST_F(XdgCurrentDesktopUtilsTest, isBudgie)
setenv("XDG_CURRENT_DESKTOP", "Budgie:GNOME", 1);
EXPECT_TRUE(ayatana_common_utils_is_budgie());
}
+
+class StringFunctionsTest : public ::testing::Test
+{
+public:
+
+ StringFunctionsTest()
+ {
+ }
+
+ 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);
+ }
+ }
+ }
+
+ 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, "öüóőúéáűšđß");
+
+ gchar *sTest2 = g_strdup("123456789012345678901234567890123456789012345öüóőúéáűšđß");
+ ayatana_common_utils_elipsize((gchar*)sTest2);
+ EXPECT_STREQ(sTest2, "123456789012345678901234567890123456789012345öüóőú...");
+}