mailing list of musl libc
 help / color / mirror / code / Atom feed
* uncommitted libc-test additions (?)
@ 2017-06-22 23:14 Rich Felker
  2017-06-22 23:40 ` Szabolcs Nagy
  0 siblings, 1 reply; 2+ messages in thread
From: Rich Felker @ 2017-06-22 23:14 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 630 bytes --]

I found these in my local libc-test checkout. Some of them might have
been duplicated or superseded by other tests or committed at different
locations, but likely they were just overlooked:

src/common/utf8.c
src/functional/clocale_mbfuncs.c
src/regression/iconv-roundtrips.c
src/regression/uselocale-0.c

I also have a file called src/regression/malloc-brk-fail-under.c, but
it looks like work I started on a test related to malloc-brk-fail.c
and never finished.

utf8.c doesn't actually seem to be used by anything, and I don't
remember where it came from, but it should be useful for testing utf-8
related functionality.

Rich

[-- Attachment #2: utf8.c --]
[-- Type: text/plain, Size: 508 bytes --]

#include <locale.h>
#include <string.h>
#include <langinfo.h>
#include "test.h"

int t_setutf8()
{
	(void)(
	setlocale(LC_CTYPE, "C.UTF-8") ||
	setlocale(LC_CTYPE, "POSIX.UTF-8") ||
	setlocale(LC_CTYPE, "en_US.UTF-8") ||
	setlocale(LC_CTYPE, "en_GB.UTF-8") ||
	setlocale(LC_CTYPE, "en.UTF-8") ||
	setlocale(LC_CTYPE, "UTF-8") ||
	setlocale(LC_CTYPE, "") );
	
	if (strcmp(nl_langinfo(CODESET), "UTF-8"))
		return t_error("cannot set UTF-8 locale for test (codeset=%s)\n", nl_langinfo(CODESET));

	return 0;
}

[-- Attachment #3: clocale_mbfuncs.c --]
[-- Type: text/plain, Size: 3034 bytes --]

#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include <wctype.h>
#include <stdlib.h>
#include <locale.h>
#include <langinfo.h>
#include <limits.h>
#include "test.h"

int main(void)
{
	int i, j;
	mbstate_t st, st2;
	wchar_t wc, map[257], wtmp[257];
	char s[MB_LEN_MAX*256];
	size_t rv;
	int c;
	int ni_errors=0;

	setlocale(LC_CTYPE, "C");

	if (MB_CUR_MAX != 1) t_error("MB_CUR_MAX = %d, expected 1\n", (int)MB_CUR_MAX);

	for (i=0; i<256; i++) {
		st = (mbstate_t){0};
		if (mbrtowc(&wc, &(char){i}, 1, &st) != !!i)
			t_error("mbrtowc failed to convert byte %.2x to wchar_t\n", i);
		if ((map[i]=btowc(i)) == WEOF) {
			t_error("btowc failed to convert byte %.2x to wchar_t\n", i);
			continue;
		}
		for (j=0; j<i; j++) {
			if (map[j]==map[i])
				t_error("bytes %.2x and %.2x map to same wchar_t %.4x\n", j, i, (unsigned)map[i]);
		}
	}

	for (i=0; i<256; i++) {
		if (map[i]==WEOF) continue;
		if (wctob(map[i]) != i)
			t_error("wctob failed to convert wchar_t %.4x back to byte %.2x\n", (unsigned)map[i], i);
	}

	/* covering whole 32-bit range would be too slow... maybe add random high tests? */
	for (i=0; i<0x110000; i++) {
		if (wcschr(map+1, i)) continue;
		if ((c=wctob(i)) != WEOF && ni_errors++ < 50)
			t_error("wctob accepted non-image wchar_t %.4x as byte %.2x\n", i, c);
		st = (mbstate_t){0};
		if (wcrtomb(s, i, &st) != -1  && ni_errors++ < 50)
			t_error("wcrtomb accepted non-image wchar_t %.4x\n", i);
	}
	if (ni_errors > 50)
		t_error("additional %d non-image errors (not printed)\n", ni_errors);

	map[256] = 0;
	st = (mbstate_t){0};
	if ((rv=wcsrtombs(s, &(const wchar_t *){map+1}, sizeof s, &st)) != 255)
		t_error("wcsrtombs returned %zd, expected 255\n", rv);
	if ((rv=mbsrtowcs(wtmp, &(const char *){s}, 256, &st)) != 255)
		t_error("mbsrtowcs returned %zd, expected 255\n", rv);
	if (memcmp(map+1, wtmp, 256*sizeof(*map)))
		t_error("wcsrtombs/mbsrtowcs round trip failed\n");

	for (i=128; i<256; i++) {
		if (iswalnum(map[i])) t_error("iswalnum returned true for %.4x (%.2x)\n", map[i], i);
		if (iswalpha(map[i])) t_error("iswalpha returned true for %.4x (%.2x)\n", map[i], i);
		if (iswblank(map[i])) t_error("iswblank returned true for %.4x (%.2x)\n", map[i], i);
		if (iswcntrl(map[i])) t_error("iswcntrl returned true for %.4x (%.2x)\n", map[i], i);
		if (iswdigit(map[i])) t_error("iswdigit returned true for %.4x (%.2x)\n", map[i], i);
		if (iswgraph(map[i])) t_error("iswgraph returned true for %.4x (%.2x)\n", map[i], i);
		if (iswlower(map[i])) t_error("iswlower returned true for %.4x (%.2x)\n", map[i], i);
		if (iswprint(map[i])) t_error("iswprint returned true for %.4x (%.2x)\n", map[i], i);
		if (iswpunct(map[i])) t_error("iswpunct returned true for %.4x (%.2x)\n", map[i], i);
		if (iswspace(map[i])) t_error("iswspace returned true for %.4x (%.2x)\n", map[i], i);
		if (iswupper(map[i])) t_error("iswupper returned true for %.4x (%.2x)\n", map[i], i);
		if (iswxdigit(map[i])) t_error("iswxdigit returned true for %.4x (%.2x)\n", map[i], i);
	}

	return t_status;
}

[-- Attachment #4: iconv-roundtrips.c --]
[-- Type: text/plain, Size: 1409 bytes --]

// commit: b7bfb5c3a8330002250f304cb5deb522fa054eae
// fix iconv conversions for iso88592-iso885916
#include <iconv.h>
#include <string.h>
#include "test.h"

int main(void)
{
	static char *test_charsets[] = {
		"iso-8859-1",
		"iso-8859-2",
		"iso-8859-4",
		"iso-8859-5",
		"iso-8859-9",
		"iso-8859-10",
		"iso-8859-13",
		"iso-8859-14",
		"iso-8859-15",
		"iso-8859-16",
		0
	};
	char all_codepoints[256];
	int i;

	for (i=0; i<256; i++)
		all_codepoints[i] = 255-i;

	for (i=0; test_charsets[i]; i++) {
		iconv_t there = iconv_open("UTF-8", test_charsets[i]);
		if (there == (iconv_t)-1) continue;
		iconv_t andback = iconv_open(test_charsets[i], "UTF-8");
		if (andback == (iconv_t)-1) {
			iconv_close(there);
			continue;
		}
		char u8buf[1024];
		char buf[256];
		size_t u8rem = sizeof u8buf;
		int r1 = iconv(there,
			&(char *){all_codepoints}, &(size_t){sizeof all_codepoints},
			&(char *){u8buf}, &u8rem);
		size_t u8len = sizeof u8buf - u8rem;
		int r2 = iconv(andback,
			&(char *){u8buf}, &(size_t){u8len},
			&(char *){buf}, &(size_t){sizeof buf});

		if (r1) t_error("got %d converting from %s\n", r1, test_charsets[i]);
		if (r2) t_error("got %d converting back to %s\n", r2, test_charsets[i]);

		if (memcmp(all_codepoints, buf, sizeof buf)) {
			t_error("round trip corrupted %s characters\n", test_charsets[i]);
		}

		iconv_close(there);
		iconv_close(andback);
	}

	return t_status;
}

[-- Attachment #5: uselocale-0.c --]
[-- Type: text/plain, Size: 607 bytes --]

// commit: 63f4b9f18f3674124d8bcb119739fec85e6da005
// uselocale(0) should not change the current locale
#include <locale.h>
#include "test.h"

int main(void)
{
	locale_t c = newlocale(LC_ALL_MASK, "C", 0);

	if (!c) {
		t_error("newlocale failed\n");
		return t_status;
	}

	if (!uselocale(c))
		t_error("uselocale(c) failed\n");

	locale_t l1 = uselocale(0);
	if (l1 != c)
		t_error("uselocale failed to set locale: "
			"%p != %p\n", (void*)l1, (void*)c);

	locale_t l2 = uselocale(0);
	if (l2 != l1)
		t_error("uselocale(0) changed locale: "
			"%p != %p\n", (void*)l2, (void*)l1);

	return t_status;
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: uncommitted libc-test additions (?)
  2017-06-22 23:14 uncommitted libc-test additions (?) Rich Felker
@ 2017-06-22 23:40 ` Szabolcs Nagy
  0 siblings, 0 replies; 2+ messages in thread
From: Szabolcs Nagy @ 2017-06-22 23:40 UTC (permalink / raw)
  To: musl

* Rich Felker <dalias@libc.org> [2017-06-22 19:14:58 -0400]:
> I found these in my local libc-test checkout. Some of them might have
> been duplicated or superseded by other tests or committed at different
> locations, but likely they were just overlooked:
> 
> src/common/utf8.c
> src/functional/clocale_mbfuncs.c
> src/regression/iconv-roundtrips.c
> src/regression/uselocale-0.c
> 
> I also have a file called src/regression/malloc-brk-fail-under.c, but
> it looks like work I started on a test related to malloc-brk-fail.c
> and never finished.
> 
> utf8.c doesn't actually seem to be used by anything, and I don't
> remember where it came from, but it should be useful for testing utf-8
> related functionality.

ok i added all of them to libc-test


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-06-22 23:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-22 23:14 uncommitted libc-test additions (?) Rich Felker
2017-06-22 23:40 ` Szabolcs Nagy

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).