summaryrefslogtreecommitdiff
path: root/usr/src/test/libc-tests/tests/printf-9511.c
blob: 98823f0d10429ae0a029f895f8e2a81bafccf266 (plain)
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
60
61
62
63
64
65
66
67
68
69
70
/*
 * This file and its contents are supplied under the terms of the
 * Common Development and Distribution License ("CDDL"), version 1.0.
 * You may only use this file in accordance with the terms of version
 * 1.0 of the CDDL.
 *
 * A full copy of the text of the CDDL should have accompanied this
 * source.  A copy of the CDDL is also available via the Internet at
 * http://www.illumos.org/license/CDDL.
 */

/*
 * Copyright 2018 Nexenta Systems, Inc.
 */

/*
 * Note that this file is easiest edited with a UTF-8 capable editor,
 * as there are embedded UTF-8 symbols in some of the strings.
 */

#include <err.h>
#include <locale.h>
#include <stdio.h>
#include <string.h>

struct {
	const char *locale;
	const char *convspec;
	const float fp;
	const char *expected;
} fpconv[] = {
	"C", "%a", 3.2, "0x1.99999a0000000p+1",
	"C", "%e", 3.2, "3.200000e+00",
	"C", "%f", 3.2, "3.200000",
	"C", "%g", 3.2, "3.2",
	"ar_AE.UTF-8", "%a", 3.2, "0x1٫99999a0000000p+1",
	"ar_AE.UTF-8", "%e", 3.2, "3٫200000e+00",
	"ar_AE.UTF-8", "%f", 3.2, "3٫200000",
	"ar_AE.UTF-8", "%g", 3.2, "3٫2",
	"en_US.UTF-8", "%a", 3.2, "0x1.99999a0000000p+1",
	"en_US.UTF-8", "%e", 3.2, "3.200000e+00",
	"en_US.UTF-8", "%f", 3.2, "3.200000",
	"en_US.UTF-8", "%g", 3.2, "3.2",
	"ru_RU.UTF-8", "%a", 3.2, "0x1,99999a0000000p+1",
	"ru_RU.UTF-8", "%e", 3.2, "3,200000e+00",
	"ru_RU.UTF-8", "%f", 3.2, "3,200000",
	"ru_RU.UTF-8", "%g", 3.2, "3,2",
	NULL, NULL, 0, NULL
};

int
main(void)
{
	char buf[100];
	int i;

	for (i = 0; fpconv[i].locale != NULL; i++) {
		if (setlocale(LC_ALL, fpconv[i].locale) == NULL)
			err(1, "failed to set locale to %s", fpconv[i].locale);

		(void) sprintf(buf, fpconv[i].convspec, fpconv[i].fp);
		if (strcmp(fpconv[i].expected, buf) != 0) {
			errx(1, "locale=%s, convspec=%s, expected=%s, got=%s",
			    fpconv[i].locale, fpconv[i].convspec,
			    fpconv[i].expected, buf);
		}
	}

	return (0);
}