File: test-utils.c

package info (click to toggle)
amtk 5.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,232 kB
  • sloc: sh: 4,840; ansic: 2,867; makefile: 232; sed: 16
file content (59 lines) | stat: -rw-r--r-- 1,797 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * This file is part of Amtk - Actions, Menus and Toolbars Kit
 *
 * Copyright 2017 - Sébastien Wilmet <swilmet@gnome.org>
 *
 * Amtk is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version.
 *
 * Amtk 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 Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, see <http://www.gnu.org/licenses/>.
 */

#include <amtk/amtk.h>

static void
check_remove_mnemonic (const gchar *str_with_mnemonic,
		       const gchar *expected_str_without_mnemonic)
{
	gchar *str_without_mnemonic;

	str_without_mnemonic = amtk_utils_remove_mnemonic (str_with_mnemonic);
	g_assert_cmpstr (str_without_mnemonic, ==, expected_str_without_mnemonic);
	g_free (str_without_mnemonic);
}

static void
test_remove_mnemonic (void)
{
	check_remove_mnemonic ("", "");
	check_remove_mnemonic ("a", "a");
	check_remove_mnemonic ("_a", "a");
	check_remove_mnemonic ("__a", "_a");
	check_remove_mnemonic ("___a", "_a");
	check_remove_mnemonic ("S_maller Text", "Smaller Text");

	/* With multi-byte UTF-8 chars. */
	check_remove_mnemonic ("___ß_é__c____d", "_ßé_c__d");

	/* Not valid mnemonic, but the function must not crash. */
	check_remove_mnemonic ("a_", "a");
}

int
main (int    argc,
      char **argv)
{
	g_test_init (&argc, &argv, NULL);

	g_test_add_func ("/utils/remove-mnemonic", test_remove_mnemonic);

	return g_test_run ();
}