Skip to content

Commit ce48272

Browse files
committed
test/t_commands: add locale test
Test for #142
1 parent 5fff53b commit ce48272

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ conf.set_quoted('DEFAULT_HOST', get_option('default_host'))
2222
conf.set('DEFAULT_PORT', get_option('default_port'))
2323

2424
conf.set('HAVE_STRNDUP', cc.has_function('strndup', prefix: '#define _GNU_SOURCE\n#include <string.h>'))
25+
conf.set('HAVE_SETLOCALE', cc.has_function('setlocale', prefix: '#include <locale.h>'))
2526

2627
platform_deps = []
2728
if host_machine.system() == 'haiku'

test/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ test('t_iso8601', executable('t_iso8601',
1515
test('t_commands', executable('t_commands',
1616
't_commands.c',
1717
'capture.c',
18+
include_directories: inc,
1819
dependencies: [
1920
libmpdclient_dep,
2021
check_dep,

test/t_commands.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "capture.h"
2+
#include "config.h"
23
#include <mpd/connection.h>
34
#include <mpd/response.h>
45
#include <mpd/capabilities.h>
@@ -15,6 +16,10 @@
1516
#include <limits.h>
1617
#include <time.h>
1718

19+
#ifdef HAVE_SETLOCALE
20+
#include <locale.h>
21+
#endif
22+
1823
static void
1924
abort_command(struct test_capture *capture,
2025
struct mpd_connection *connection)
@@ -360,6 +365,31 @@ START_TEST(test_mount_commands)
360365
}
361366
END_TEST
362367

368+
#ifdef HAVE_SETLOCALE
369+
370+
START_TEST(test_locale)
371+
{
372+
/* choosing a locale that uses the comma instead of the dot as
373+
the decimal separator to see if this affects libmpdclient
374+
(it should not because MPD expects the dot) */
375+
setlocale(LC_ALL, "de_DE@UTF-8");
376+
377+
struct test_capture capture;
378+
struct mpd_connection *c = test_capture_init(&capture);
379+
380+
ck_assert(mpd_send_seek_current(c, -42.5, false));
381+
ck_assert_str_eq(test_capture_receive(&capture), "seekcur \"-42.500\"\n");
382+
abort_command(&capture, c);
383+
384+
mpd_connection_free(c);
385+
test_capture_deinit(&capture);
386+
387+
setlocale(LC_ALL, "C");
388+
}
389+
END_TEST
390+
391+
#endif // HAVE_SETLOCALE
392+
363393
static Suite *
364394
create_suite(void)
365395
{
@@ -396,6 +426,12 @@ create_suite(void)
396426
tcase_add_test(tc_mount, test_mount_commands);
397427
suite_add_tcase(s, tc_mount);
398428

429+
#ifdef HAVE_SETLOCALE
430+
TCase *tc_locale = tcase_create("locale");
431+
tcase_add_test(tc_locale, test_locale);
432+
suite_add_tcase(s, tc_locale);
433+
#endif // HAVE_SETLOCALE
434+
399435
return s;
400436
}
401437

0 commit comments

Comments
 (0)