summaryrefslogtreecommitdiff
path: root/tests/uninorm/test-u32-normalize-big.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/uninorm/test-u32-normalize-big.c')
-rw-r--r--tests/uninorm/test-u32-normalize-big.c273
1 files changed, 131 insertions, 142 deletions
diff --git a/tests/uninorm/test-u32-normalize-big.c b/tests/uninorm/test-u32-normalize-big.c
index 96781ab0..6c637862 100644
--- a/tests/uninorm/test-u32-normalize-big.c
+++ b/tests/uninorm/test-u32-normalize-big.c
@@ -1,5 +1,5 @@
/* Test of Unicode compliance of normalization of UTF-32 strings.
- Copyright (C) 2009 Free Software Foundation, Inc.
+ Copyright (C) 2009, 2010 Free Software Foundation, Inc.
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
@@ -21,37 +21,26 @@
/* Specification. */
#include "test-u32-normalize-big.h"
-#if GNULIB_UNINORM_U32_NORMALIZE
+#if GNULIB_TEST_UNINORM_U32_NORMALIZE
#include <stdio.h>
#include <stdlib.h>
#include "xalloc.h"
#include "unistr.h"
-
-#define ASSERT(expr) \
- do \
- { \
- if (!(expr)) \
- { \
- fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
- fflush (stderr); \
- abort (); \
- } \
- } \
- while (0)
+#include "macros.h"
#define ASSERT_WITH_LINE(expr, file, line) \
- do \
- { \
- if (!(expr)) \
- { \
- fprintf (stderr, "%s:%d: assertion failed for %s:%u\n", \
- __FILE__, __LINE__, file, line); \
- fflush (stderr); \
- abort (); \
- } \
- } \
+ do \
+ { \
+ if (!(expr)) \
+ { \
+ fprintf (stderr, "%s:%d: assertion failed for %s:%u\n", \
+ __FILE__, __LINE__, file, line); \
+ fflush (stderr); \
+ abort (); \
+ } \
+ } \
while (0)
static int
@@ -64,7 +53,7 @@ cmp_ucs4_t (const void *a, const void *b)
void
read_normalization_test_file (const char *filename,
- struct normalization_test_file *file)
+ struct normalization_test_file *file)
{
FILE *stream;
unsigned int lineno;
@@ -106,103 +95,103 @@ read_normalization_test_file (const char *filename,
/* Read a line. */
ptr = buf;
do
- {
- c = getc (stream);
- if (c == EOF || c == '\n')
- break;
- *ptr++ = c;
- }
+ {
+ c = getc (stream);
+ if (c == EOF || c == '\n')
+ break;
+ *ptr++ = c;
+ }
while (ptr < buf + 1000);
*ptr = '\0';
if (c == EOF)
- break;
+ break;
/* Ignore empty lines and comment lines. */
if (buf[0] == '\0' || buf[0] == '#')
- continue;
+ continue;
/* Handle lines that introduce a new part. */
if (buf[0] == '@')
- {
- /* Switch to the next part. */
- if (part_index >= 0)
- {
- lines =
- (struct normalization_test_line *)
- xnrealloc (lines, lines_length, sizeof (struct normalization_test_line));
- file->parts[part_index].lines = lines;
- file->parts[part_index].lines_length = lines_length;
- }
- part_index++;
- lines = NULL;
- lines_length = 0;
- lines_allocated = 0;
- continue;
- }
+ {
+ /* Switch to the next part. */
+ if (part_index >= 0)
+ {
+ lines =
+ (struct normalization_test_line *)
+ xnrealloc (lines, lines_length, sizeof (struct normalization_test_line));
+ file->parts[part_index].lines = lines;
+ file->parts[part_index].lines_length = lines_length;
+ }
+ part_index++;
+ lines = NULL;
+ lines_length = 0;
+ lines_allocated = 0;
+ continue;
+ }
/* It's a line containing 5 sequences of Unicode characters.
- Parse it and append it to the current part. */
+ Parse it and append it to the current part. */
if (!(part_index >= 0 && part_index < 4))
- {
- fprintf (stderr, "unexpected structure of '%s'\n", filename);
- exit (1);
- }
+ {
+ fprintf (stderr, "unexpected structure of '%s'\n", filename);
+ exit (1);
+ }
ptr = buf;
line.lineno = lineno;
for (sequence_index = 0; sequence_index < 5; sequence_index++)
- line.sequences[sequence_index] = NULL;
+ line.sequences[sequence_index] = NULL;
for (sequence_index = 0; sequence_index < 5; sequence_index++)
- {
- uint32_t *sequence = XNMALLOC (1, uint32_t);
- size_t sequence_length = 0;
-
- for (;;)
- {
- char *endptr;
- unsigned int uc;
-
- uc = strtoul (ptr, &endptr, 16);
- if (endptr == ptr)
- break;
- ptr = endptr;
-
- /* Append uc to the sequence. */
- sequence =
- (uint32_t *)
- xnrealloc (sequence, sequence_length + 2, sizeof (uint32_t));
- sequence[sequence_length] = uc;
- sequence_length++;
-
- if (*ptr == ' ')
- ptr++;
- }
- if (sequence_length == 0)
- {
- fprintf (stderr, "empty character sequence in '%s'\n", filename);
- exit (1);
- }
- sequence[sequence_length] = 0; /* terminator */
-
- line.sequences[sequence_index] = sequence;
-
- if (*ptr != ';')
- {
- fprintf (stderr, "error parsing '%s'\n", filename);
- exit (1);
- }
- ptr++;
- }
+ {
+ uint32_t *sequence = XNMALLOC (1, uint32_t);
+ size_t sequence_length = 0;
+
+ for (;;)
+ {
+ char *endptr;
+ unsigned int uc;
+
+ uc = strtoul (ptr, &endptr, 16);
+ if (endptr == ptr)
+ break;
+ ptr = endptr;
+
+ /* Append uc to the sequence. */
+ sequence =
+ (uint32_t *)
+ xnrealloc (sequence, sequence_length + 2, sizeof (uint32_t));
+ sequence[sequence_length] = uc;
+ sequence_length++;
+
+ if (*ptr == ' ')
+ ptr++;
+ }
+ if (sequence_length == 0)
+ {
+ fprintf (stderr, "empty character sequence in '%s'\n", filename);
+ exit (1);
+ }
+ sequence[sequence_length] = 0; /* terminator */
+
+ line.sequences[sequence_index] = sequence;
+
+ if (*ptr != ';')
+ {
+ fprintf (stderr, "error parsing '%s'\n", filename);
+ exit (1);
+ }
+ ptr++;
+ }
/* Append the line to the current part. */
if (lines_length == lines_allocated)
- {
- lines_allocated = 2 * lines_allocated;
- if (lines_allocated < 7)
- lines_allocated = 7;
- lines =
- (struct normalization_test_line *)
- xnrealloc (lines, lines_allocated, sizeof (struct normalization_test_line));
- }
+ {
+ lines_allocated = 2 * lines_allocated;
+ if (lines_allocated < 7)
+ lines_allocated = 7;
+ lines =
+ (struct normalization_test_line *)
+ xnrealloc (lines, lines_allocated, sizeof (struct normalization_test_line));
+ }
lines[lines_length] = line;
lines_length++;
}
@@ -210,8 +199,8 @@ read_normalization_test_file (const char *filename,
if (part_index >= 0)
{
lines =
- (struct normalization_test_line *)
- xnrealloc (lines, lines_length, sizeof (struct normalization_test_line));
+ (struct normalization_test_line *)
+ xnrealloc (lines, lines_length, sizeof (struct normalization_test_line));
file->parts[part_index].lines = lines;
file->parts[part_index].lines_length = lines_length;
}
@@ -224,11 +213,11 @@ read_normalization_test_file (const char *filename,
for (line_index = 0; line_index < p->lines_length; line_index++)
{
- const uint32_t *sequence = p->lines[line_index].sequences[0];
- /* In part 1, every sequences[0] consists of a single character. */
- if (!(sequence[0] != 0 && sequence[1] == 0))
- abort ();
- c1_array[line_index] = sequence[0];
+ const uint32_t *sequence = p->lines[line_index].sequences[0];
+ /* In part 1, every sequences[0] consists of a single character. */
+ if (!(sequence[0] != 0 && sequence[1] == 0))
+ abort ();
+ c1_array[line_index] = sequence[0];
}
/* Sort this array. */
@@ -251,11 +240,11 @@ read_normalization_test_file (const char *filename,
void
test_specific (const struct normalization_test_file *file,
- int (*check) (const uint32_t *c1, size_t c1_length,
- const uint32_t *c2, size_t c2_length,
- const uint32_t *c3, size_t c3_length,
- const uint32_t *c4, size_t c4_length,
- const uint32_t *c5, size_t c5_length))
+ int (*check) (const uint32_t *c1, size_t c1_length,
+ const uint32_t *c2, size_t c2_length,
+ const uint32_t *c3, size_t c3_length,
+ const uint32_t *c4, size_t c4_length,
+ const uint32_t *c5, size_t c5_length))
{
size_t part_index;
@@ -265,17 +254,17 @@ test_specific (const struct normalization_test_file *file,
size_t line_index;
for (line_index = 0; line_index < p->lines_length; line_index++)
- {
- const struct normalization_test_line *l = &p->lines[line_index];
-
- ASSERT_WITH_LINE (check (l->sequences[0], u32_strlen (l->sequences[0]),
- l->sequences[1], u32_strlen (l->sequences[1]),
- l->sequences[2], u32_strlen (l->sequences[2]),
- l->sequences[3], u32_strlen (l->sequences[3]),
- l->sequences[4], u32_strlen (l->sequences[4]))
- == 0,
- file->filename, l->lineno);
- }
+ {
+ const struct normalization_test_line *l = &p->lines[line_index];
+
+ ASSERT_WITH_LINE (check (l->sequences[0], u32_strlen (l->sequences[0]),
+ l->sequences[1], u32_strlen (l->sequences[1]),
+ l->sequences[2], u32_strlen (l->sequences[2]),
+ l->sequences[3], u32_strlen (l->sequences[3]),
+ l->sequences[4], u32_strlen (l->sequences[4]))
+ == 0,
+ file->filename, l->lineno);
+ }
}
}
@@ -291,24 +280,24 @@ test_other (const struct normalization_test_file *file, uninorm_t nf)
for (uc = 0; uc < 0x110000; uc++)
{
if (uc >= 0xD800 && uc < 0xE000)
- {
- /* A surrogate, not a character. Skip uc. */
- }
+ {
+ /* A surrogate, not a character. Skip uc. */
+ }
else if (uc == *p)
- {
- /* Skip uc. */
- p++;
- }
+ {
+ /* Skip uc. */
+ p++;
+ }
else
- {
- uint32_t input[1];
- size_t length;
- uint32_t *result;
-
- input[0] = uc;
- result = u32_normalize (nf, input, 1, NULL, &length);
- ASSERT (result != NULL && length == 1 && result[0] == uc);
- }
+ {
+ uint32_t input[1];
+ size_t length;
+ uint32_t *result;
+
+ input[0] = uc;
+ result = u32_normalize (nf, input, 1, NULL, &length);
+ ASSERT (result != NULL && length == 1 && result[0] == uc);
+ }
}
}