diff options
author | Wu Xiaotian <[email protected]> | 2019-05-28 14:29:42 +0800 |
---|---|---|
committer | raveit65 <[email protected]> | 2019-06-11 16:06:41 +0200 |
commit | 451baa964b34accd93af19ab8c6aa93636bf79fd (patch) | |
tree | 864225e365b684f40d4cda42a20ec61462a59a16 | |
parent | d53d2be25eded44f81c126c9d904d21774f7ee42 (diff) | |
download | mate-desktop-451baa964b34accd93af19ab8c6aa93636bf79fd.tar.bz2 mate-desktop-451baa964b34accd93af19ab8c6aa93636bf79fd.tar.xz |
Add test code for mate-languages.
-rw-r--r-- | libmate-desktop/Makefile.am | 8 | ||||
-rw-r--r-- | libmate-desktop/mate-languages.h | 2 | ||||
-rw-r--r-- | libmate-desktop/meson.build | 18 | ||||
-rw-r--r-- | libmate-desktop/test-languages.c | 88 | ||||
-rw-r--r-- | meson.build | 1 |
5 files changed, 116 insertions, 1 deletions
diff --git a/libmate-desktop/Makefile.am b/libmate-desktop/Makefile.am index b6698e5..48d7378 100644 --- a/libmate-desktop/Makefile.am +++ b/libmate-desktop/Makefile.am @@ -31,7 +31,7 @@ AM_CPPFLAGS = \ AM_CFLAGS = $(WARN_CFLAGS) -noinst_PROGRAMS = test-ditem test +noinst_PROGRAMS = test-ditem test test-languages CLEANFILES = @@ -87,6 +87,12 @@ test_ditem_LDADD = \ $(XLIB_LIBS) \ $(MATE_DESKTOP_LIBS) +test_languages_SOURCES = test-languages.c + +test_languages_LDADD = \ + libmate-desktop-2.la \ + $(MATE_DESKTOP_LIBS) + pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = mate-desktop-2.0.pc diff --git a/libmate-desktop/mate-languages.h b/libmate-desktop/mate-languages.h index 2a800c4..6cd616b 100644 --- a/libmate-desktop/mate-languages.h +++ b/libmate-desktop/mate-languages.h @@ -27,6 +27,8 @@ #error This is unstable API. You must define MATE_DESKTOP_USE_UNSTABLE_API before including mate-languages.h #endif +#include <glib.h> + G_BEGIN_DECLS char * mate_get_language_from_locale (const char *locale, diff --git a/libmate-desktop/meson.build b/libmate-desktop/meson.build index 77007a6..576788a 100644 --- a/libmate-desktop/meson.build +++ b/libmate-desktop/meson.build @@ -143,3 +143,21 @@ if enable_gir install_dir_typelib: typelib_dir, ) endif + +test_ditem = executable('test-ditem', + sources : 'test-ditem.c', + dependencies : libmate_desktop_dep, + install : false, +) + +test_color_button = executable('test-color-button', + sources : 'test.c', + dependencies : libmate_desktop_dep, + install : false, +) + +test_languages = executable('test-languages', + sources : 'test-languages.c', + dependencies : libmate_desktop_dep, + install : false, +) diff --git a/libmate-desktop/test-languages.c b/libmate-desktop/test-languages.c new file mode 100644 index 0000000..0f975b2 --- /dev/null +++ b/libmate-desktop/test-languages.c @@ -0,0 +1,88 @@ +/* vi: set sw=4 ts=4 wrap ai: */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * */ + +#include <stdio.h> +#include <locale.h> +#define MATE_DESKTOP_USE_UNSTABLE_API +#include "mate-languages.h" + +void test_one_locale(const gchar *locale); +void test_locales(void); + +void test_one_locale(const gchar *locale) +{ + char *lang, *country, *norm_locale; + char *language_code, *country_code, *codeset, *modifier; + + lang = mate_get_language_from_locale (locale, locale); + country = mate_get_country_from_locale (locale, locale); + norm_locale = mate_normalize_locale (locale); + + printf("Current locale: %s\n", locale); + printf("[locale]:\t\tlang=%s, country=%s, locale=%s\n", lang, country, norm_locale); + g_free(lang); + g_free(country); + g_free(norm_locale); + + if (mate_parse_locale (locale, &language_code, &country_code, &codeset, &modifier)) { + lang = mate_get_language_from_code (language_code, locale); + country = mate_get_country_from_code (country_code, locale); + if (mate_language_has_translations(language_code)) { + printf("[mate_parse_locale]:\tlang_code=%s, country_code=%s, code=%s, modifier=%s\n" + "[code]:\t\t\tlang=%s, country=%s, Has translation\n", + language_code, country_code, codeset, modifier, + lang, country); + } else { + printf("[mate_parse_locale]:\tlang_code=%s, country_code=%s, code=%s, modifier=%s\n" + "[code]:\t\t\tlang=%s, country=%s\n", + language_code, country_code, codeset, modifier, + lang, country); + } + g_free(lang); + g_free(country); + } + putchar('\n'); + + g_free(language_code); + g_free(country_code); + g_free(codeset); + g_free(modifier); +} + +void test_locales(void) +{ + char **all; + guint i, len; + + all= mate_get_all_locales (); + len = g_strv_length (all); + + for (i =0; i < len; i++) { + test_one_locale(all[i]); + } + g_strfreev(all); +} + +int main(int argc, char **argv) +{ + if (argc == 2) { + test_one_locale(argv[1]); + } else { + test_locales(); + } + return 0; +} diff --git a/meson.build b/meson.build index defef4d..00da23c 100644 --- a/meson.build +++ b/meson.build @@ -62,6 +62,7 @@ config_h.set_quoted('LOCALEDIR', matedt_localedir) common_flags = [ '-DHAVE_CONFIG_H', + '-I' + meson.build_root(), '-DPACKAGE_VERSION="@0@"'.format(matedt_version), ] |