diff options
author | Manuel A. Fernandez Montecelo <manuel.montezelo@gmail.com> | 2016-05-27 14:35:40 +0100 |
---|---|---|
committer | Manuel A. Fernandez Montecelo <manuel.montezelo@gmail.com> | 2016-05-27 14:35:40 +0100 |
commit | b1de003dac299705a7f01c997d2b866bafe39926 (patch) | |
tree | 1cc16a3877e945116387a380f7f3023f81fa36e4 /tests/unistr | |
parent | 752fd7247bc223bcea35bd89cf56d1c08ead9ba6 (diff) | |
parent | 3590c846d4c2febbc05b4ad6b14a06edc549e453 (diff) |
Merge tag 'upstream/0.9.6+really0.9.6'
Upstream version 0.9.6+really0.9.6
Diffstat (limited to 'tests/unistr')
131 files changed, 1347 insertions, 139 deletions
diff --git a/tests/unistr/test-chr.h b/tests/unistr/test-chr.h index 5a021c2..cd5a45e 100644 --- a/tests/unistr/test-chr.h +++ b/tests/unistr/test-chr.h @@ -1,5 +1,5 @@ /* Test of uN_chr() functions. - Copyright (C) 2008-2010 Free Software Foundation, Inc. + Copyright (C) 2008-2015 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 @@ -19,32 +19,65 @@ int main (void) { - size_t n = 0x100000; - UNIT *input = (UNIT *) malloc (n * sizeof (UNIT)); + size_t size = 0x100000; + size_t i; + size_t length; + UNIT *input; + uint32_t *input32 = (uint32_t *) malloc (size * sizeof (uint32_t)); + ASSERT (input32); + + input32[0] = 'a'; + input32[1] = 'b'; + u32_set (input32 + 2, 'c', 1024); + for (i = 1026; i < size - 2; i += 63) + { + size_t last = i + 63 < size - 2 ? i + 63 : size - 2; + ucs4_t uc = 'd' | (i - 1026); + if (uc >= 0xd800 && uc <= 0xdfff) + uc |= 0x100000; + u32_set (input32 + i, uc, last - i); + } + + input32[size - 2] = 'e'; + input32[size - 1] = 'a'; + + input = U32_TO_U (input32, size, NULL, &length); ASSERT (input); - input[0] = 'a'; - input[1] = 'b'; - U_SET (input + 2, 'c', 1024); - U_SET (input + 1026, 'd', n - 1028); - input[n - 2] = 'e'; - input[n - 1] = 'a'; - /* Basic behavior tests. */ - ASSERT (U_CHR (input, n, 'a') == input); + ASSERT (U_CHR (input, length, 'a') == input); ASSERT (U_CHR (input, 0, 'a') == NULL); ASSERT (U_CHR (zerosize_ptr (), 0, 'a') == NULL); - ASSERT (U_CHR (input, n, 'b') == input + 1); - ASSERT (U_CHR (input, n, 'c') == input + 2); - ASSERT (U_CHR (input, n, 'd') == input + 1026); + ASSERT (U_CHR (input, length, 'b') == input + 1); + ASSERT (U_CHR (input, length, 'c') == input + 2); + ASSERT (U_CHR (input, length, 'd') == input + 1026); + + { + UNIT *exp = input + 1026; + UNIT *prev = input + 1; + for (i = 1026; i < size - 2; i += 63) + { + UNIT c[6]; + size_t n; + ucs4_t uc = 'd' | (i - 1026); + if (uc >= 0xd800 && uc <= 0xdfff) + uc |= 0x100000; + n = U_UCTOMB (c, uc, 6); + ASSERT (exp < input + length - 1); + ASSERT (U_CHR (prev, (length - 1) - (prev - input), uc) == exp); + ASSERT (memcmp (exp, c, n * sizeof (UNIT)) == 0); + prev = exp; + exp += n * 63; + } + } - ASSERT (U_CHR (input + 1, n - 1, 'a') == input + n - 1); - ASSERT (U_CHR (input + 1, n - 1, 'e') == input + n - 2); + ASSERT (U_CHR (input + 1, length - 1, 'a') == input + length - 1); + ASSERT (U_CHR (input + 1, length - 1, 'e') == input + length - 2); - ASSERT (U_CHR (input, n, 'f') == NULL); - ASSERT (U_CHR (input, n, '\0') == NULL); + ASSERT (U_CHR (input, length, 'f') == NULL); + ASSERT (U_CHR (input, length, '\0') == NULL); /* Check that a very long haystack is handled quickly if the byte is found near the beginning. */ @@ -52,7 +85,7 @@ main (void) size_t repeat = 10000; for (; repeat > 0; repeat--) { - ASSERT (U_CHR (input, n, 'c') == input + 2); + ASSERT (U_CHR (input, length, 'c') == input + 2); } } @@ -74,6 +107,7 @@ main (void) byte being searched. */ { char *page_boundary = (char *) zerosize_ptr (); + size_t n; if (page_boundary != NULL) { diff --git a/tests/unistr/test-cmp.h b/tests/unistr/test-cmp.h index e536f48..aece9b0 100644 --- a/tests/unistr/test-cmp.h +++ b/tests/unistr/test-cmp.h @@ -1,5 +1,5 @@ /* Test of uN_cmp() functions. - Copyright (C) 2008-2010 Free Software Foundation, Inc. + Copyright (C) 2008-2015 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 diff --git a/tests/unistr/test-cmp2.h b/tests/unistr/test-cmp2.h index 261fe36..c405099 100644 --- a/tests/unistr/test-cmp2.h +++ b/tests/unistr/test-cmp2.h @@ -1,5 +1,5 @@ /* Test of uN_cmp2() functions. - Copyright (C) 2008-2010 Free Software Foundation, Inc. + Copyright (C) 2008-2015 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 diff --git a/tests/unistr/test-cpy-alloc.h b/tests/unistr/test-cpy-alloc.h index 795e0b7..261a677 100644 --- a/tests/unistr/test-cpy-alloc.h +++ b/tests/unistr/test-cpy-alloc.h @@ -1,5 +1,5 @@ /* Test of uN_cpy_alloc() functions. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-cpy.h b/tests/unistr/test-cpy.h index b62fd14..bc8fe53 100644 --- a/tests/unistr/test-cpy.h +++ b/tests/unistr/test-cpy.h @@ -1,5 +1,5 @@ /* Test of uN_cpy() functions. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-move.h b/tests/unistr/test-move.h index 2462367..d2c3921 100644 --- a/tests/unistr/test-move.h +++ b/tests/unistr/test-move.h @@ -1,5 +1,5 @@ /* Test of uN_move() functions. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-set.h b/tests/unistr/test-set.h index 56924dc..8d36636 100644 --- a/tests/unistr/test-set.h +++ b/tests/unistr/test-set.h @@ -1,5 +1,5 @@ /* Test of uN_set() functions. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-stpcpy.h b/tests/unistr/test-stpcpy.h index 76065dc..a924853 100644 --- a/tests/unistr/test-stpcpy.h +++ b/tests/unistr/test-stpcpy.h @@ -1,5 +1,5 @@ /* Test of uN_stpcpy() functions. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-stpncpy.h b/tests/unistr/test-stpncpy.h index bb81ff0..3cb2958 100644 --- a/tests/unistr/test-stpncpy.h +++ b/tests/unistr/test-stpncpy.h @@ -1,5 +1,5 @@ /* Test of uN_stpncpy() functions. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-strcat.h b/tests/unistr/test-strcat.h index 6c1f90d..e454e93 100644 --- a/tests/unistr/test-strcat.h +++ b/tests/unistr/test-strcat.h @@ -1,5 +1,5 @@ /* Test of uN_strcat() functions. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-strchr.h b/tests/unistr/test-strchr.h new file mode 100644 index 0000000..191d74e --- /dev/null +++ b/tests/unistr/test-strchr.h @@ -0,0 +1,161 @@ +/* Test of uN_strchr() functions. + Copyright (C) 2008-2015 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* Written by Paolo Bonzini <bonzini@gnu.org>, 2010. + Based on test-chr.h, by Eric Blake and Bruno Haible. */ + +static void +test_strchr (void) +{ + size_t size = 0x100000; + size_t length; + size_t i; + UNIT *input; + uint32_t *input32 = (uint32_t *) malloc ((size + 1) * sizeof (uint32_t)); + ASSERT (input32); + + input32[0] = 'a'; + input32[1] = 'b'; + u32_set (input32 + 2, 'c', 1024); + for (i = 1026; i < size - 2; i += 63) + { + size_t last = i + 63 < size - 2 ? i + 63 : size - 2; + ucs4_t uc = 'd' | (i - 1026); + if (uc >= 0xd800 && uc <= 0xdfff) + uc |= 0x100000; + u32_set (input32 + i, uc, last - i); + } + input32[size - 2] = 'e'; + input32[size - 1] = 'a'; + input32[size] = 0; + + input = U32_TO_U (input32, size + 1, NULL, &length); + ASSERT (input); + + /* Basic behavior tests. */ + ASSERT (U_STRCHR (input, 'a') == input); + ASSERT (U_STRCHR (input, 'b') == input + 1); + ASSERT (U_STRCHR (input, 'c') == input + 2); + + { + UNIT *exp = input + 1026; + UNIT *prev = input + 2; + + for (i = 1026; i < size - 2; i += 63) + { + UNIT c[6]; + size_t n; + ucs4_t uc = 'd' | (i - 1026); + if (uc >= 0xd800 && uc <= 0xdfff) + uc |= 0x100000; + n = U_UCTOMB (c, uc, 6); + ASSERT (exp < input + length - 2); + ASSERT (U_STRCHR (prev, uc) == exp); + ASSERT (memcmp (exp, c, n * sizeof (UNIT)) == 0); + prev = exp; + exp += n * 63; + } + } + + ASSERT (U_STRCHR (input + 1, 'a') == input + length - 2); + ASSERT (U_STRCHR (input + 1, 'e') == input + length - 3); + + ASSERT (U_STRCHR (input, 'f') == NULL); + ASSERT (U_STRCHR (input, '\0') == input + length - 1); + + /* Check that a very long haystack is handled quickly if the byte is + found near the beginning. */ + { + size_t repeat = 10000; + for (; repeat > 0; repeat--) + { + ASSERT (U_STRCHR (input, 'c') == input + 2); + } + } + + /* Alignment tests. */ + { + int i, j; + for (i = 0; i < 32; i++) + { + for (j = 0; j < 127; j++) + input[i + j] = j + 1; + input[i + 128] = 0; + for (j = 0; j < 127; j++) + { + ASSERT (U_STRCHR (input + i, j + 1) == input + i + j); + } + } + } + + /* Check that uN_strchr() does not read past the end of the string. */ + { + char *page_boundary = (char *) zerosize_ptr (); + size_t n; + + if (page_boundary != NULL) + { + for (n = 2; n <= 500 / sizeof (UNIT); n++) + { + UNIT *mem = (UNIT *) (page_boundary - n * sizeof (UNIT)); + U_SET (mem, 'X', n - 2); + mem[n - 2] = 0; + ASSERT (U_STRCHR (mem, 'U') == NULL); + mem[n - 2] = 'X'; + mem[n - 1] = 0; + ASSERT (U_STRCHR (mem, 'U') == NULL); + } + } + } + +#if 0 + /* This check is disabled, because uN_strchr() is allowed to read past the + first occurrence of the byte being searched. In fact, u8_strchr() does + so, on i586 glibc systems: u8_strchr calls strchr, which in + glibc/sysdeps/i386/i586/strchr.S loads the second word before the + handling of the first word has been completed. */ + /* Check that uN_strchr() does not read past the first occurrence of the + byte being searched. */ + { + char *page_boundary = (char *) zerosize_ptr (); + size_t n; + + if (page_boundary != NULL) + { + for (n = 2; n <= 500 / sizeof (UNIT); n++) + { + UNIT *mem = (UNIT *) (page_boundary - n * sizeof (UNIT)); + U_SET (mem, 'X', n - 1); + mem[n - 1] = 0; + ASSERT (U_STRCHR (mem, 'U') == NULL); + + { + size_t i; + + for (i = 0; i < n; i++) + { + mem[i] = 'U'; + ASSERT (U_STRCHR (mem, 'U') == mem + i); + mem[i] = 'X'; + } + } + } + } + } +#endif + + free (input); +} diff --git a/tests/unistr/test-strcmp.h b/tests/unistr/test-strcmp.h index 485b6f9..d5fcbe9 100644 --- a/tests/unistr/test-strcmp.h +++ b/tests/unistr/test-strcmp.h @@ -1,5 +1,5 @@ /* Test of uN_strcmp() and uN_strcoll() functions. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-strcpy.h b/tests/unistr/test-strcpy.h index f8fe5ef..50d28e1 100644 --- a/tests/unistr/test-strcpy.h +++ b/tests/unistr/test-strcpy.h @@ -1,5 +1,5 @@ /* Test of uN_strcpy() functions. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-strdup.h b/tests/unistr/test-strdup.h index 1684b39..44246e5 100644 --- a/tests/unistr/test-strdup.h +++ b/tests/unistr/test-strdup.h @@ -1,5 +1,5 @@ /* Test of uN_strdup() functions. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-strncat.h b/tests/unistr/test-strncat.h index 0445b6d..fc4494e 100644 --- a/tests/unistr/test-strncat.h +++ b/tests/unistr/test-strncat.h @@ -1,5 +1,5 @@ /* Test of uN_strncat() functions. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-strncmp.h b/tests/unistr/test-strncmp.h index 628db94..3a28784 100644 --- a/tests/unistr/test-strncmp.h +++ b/tests/unistr/test-strncmp.h @@ -1,5 +1,5 @@ /* Test of uN_strncmp() functions. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-strncpy.h b/tests/unistr/test-strncpy.h index 6fa0d12..492e7b8 100644 --- a/tests/unistr/test-strncpy.h +++ b/tests/unistr/test-strncpy.h @@ -1,5 +1,5 @@ /* Test of uN_strncpy() functions. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-strnlen.h b/tests/unistr/test-strnlen.h index 1199126..0a5ce8b 100644 --- a/tests/unistr/test-strnlen.h +++ b/tests/unistr/test-strnlen.h @@ -1,5 +1,5 @@ /* Test of uN_strnlen() functions. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u-strstr.h b/tests/unistr/test-u-strstr.h new file mode 100644 index 0000000..417f8b3 --- /dev/null +++ b/tests/unistr/test-u-strstr.h @@ -0,0 +1,210 @@ +/* Test of uN_strstr() functions. + Copyright (C) 2004, 2007-2015 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +static void +test_u_strstr (void) +{ + { + const UNIT input[] = { 'f', 'o', 'o', 0 }; + const UNIT needle[] = { 0 }; + const UNIT *result = U_STRSTR (input, needle); + ASSERT (result == input); + } + + { + const UNIT input[] = { 'f', 'o', 'o', 0 }; + const UNIT needle[] = { 'o', 0 }; + const UNIT *result = U_STRSTR (input, needle); + ASSERT (result == input + 1); + } + + { + const UNIT input[] = + { 'A', 'B', 'C', ' ', 'A', 'B', 'C', 'D', 'A', 'B', ' ', 'A', 'B', 'C', + 'D', 'A', 'B', 'C', 'D', 'A', 'B', 'D', 'E', 0 + }; + const UNIT needle[] = { 'A', 'B', 'C', 'D', 'A', 'B', 'D', 0 }; + const UNIT *result = U_STRSTR (input, needle); + ASSERT (result == input + 15); + } + + { + const UNIT input[] = + { 'A', 'B', 'C', ' ', 'A', 'B', 'C', 'D', 'A', 'B', ' ', 'A', 'B', 'C', + 'D', 'A', 'B', 'C', 'D', 'A', 'B', 'D', 'E', 0 + }; + const UNIT needle[] = { 'A', 'B', 'C', 'D', 'A', 'B', 'E', 0 }; + const UNIT *result = U_STRSTR (input, needle); + ASSERT (result == NULL); + } + + { + const UNIT input[] = + { 'A', 'B', 'C', ' ', 'A', 'B', 'C', 'D', 'A', 'B', ' ', 'A', 'B', 'C', + 'D', 'A', 'B', 'C', 'D', 'A', 'B', 'D', 'E', 0 + }; + const UNIT needle[] = { 'A', 'B', 'C', 'D', 'A', 'B', 'C', 'D', 0 }; + const UNIT *result = U_STRSTR (input, needle); + ASSERT (result == input + 11); + } + + /* Check that a long periodic needle does not cause false positives. */ + { + const UNIT input[] = + { 'F', '_', 'B', 'D', '_', 'C', 'E', '_', 'B', 'D', '_', 'E', 'F', + '_', 'B', 'F', '_', 'B', 'D', '_', 'E', 'F', '_', 'B', 'F', + '_', 'B', 'D', '_', 'E', 'F', '_', 'B', 'F', '_', 'B', 'D', + '_', 'E', 'F', '_', 'B', 'F', '_', 'B', 'D', '_', 'C', '3', + '_', '8', '8', '_', '2', '0', '_', 'E', 'F', '_', 'B', 'F', + '_', 'B', 'D', '_', 'E', 'F', '_', 'B', 'F', '_', 'B', 'D', + '_', 'E', 'F', '_', 'B', 'F', '_', 'B', 'D', '_', 'C', '3', + '_', 'A', '7', '_', '2', '0', '_', 'E', 'F', '_', 'B', 'F', + '_', 'B', 'D', 0 + }; + const UNIT needle[] = + { '_', 'E', 'F', '_', 'B', 'F', '_', 'B', 'D', '_', 'E', 'F', + '_', 'B', 'F', '_', 'B', 'D', '_', 'E', 'F', '_', 'B', 'F', + '_', 'B', 'D', '_', 'E', 'F', '_', 'B', 'F', '_', 'B', 'D', + '_', 'E', 'F', '_', 'B', 'F', '_', 'B', 'D', 0 + }; + const UNIT *result = U_STRSTR (input, needle); + ASSERT (result == NULL); + } + { + const UNIT input[] = + { 'F', '_', 'B', 'D', '_', 'C', 'E', '_', 'B', 'D', '_', 'E', 'F', + '_', 'B', 'F', '_', 'B', 'D', '_', 'E', 'F', '_', 'B', 'F', + '_', 'B', 'D', '_', 'E', 'F', '_', 'B', 'F', '_', 'B', 'D', + '_', 'E', 'F', '_', 'B', 'F', '_', 'B', 'D', '_', 'C', '3', + '_', '8', '8', '_', '2', '0', '_', 'E', 'F', '_', 'B', 'F', + '_', 'B', 'D', '_', 'E', 'F', '_', 'B', 'F', '_', 'B', 'D', + '_', 'E', 'F', '_', 'B', 'F', '_', 'B', 'D', '_', 'C', '3', + '_', 'A', '7', '_', '2', '0', '_', 'E', 'F', '_', 'B', 'F', + '_', 'B', 'D', '_', 'D', 'A', '_', 'B', '5', '_', 'C', '2', + '_', 'A', '6', '_', '2', '0', '_', 'E', 'F', '_', 'B', 'F', + '_', 'B', 'D', '_', 'E', 'F', '_', 'B', 'F', '_', 'B', 'D', + '_', 'E', 'F', '_', 'B', 'F', '_', 'B', 'D', '_', 'E', 'F', + '_', 'B', 'F', '_', 'B', 'D', '_', 'E', 'F', '_', 'B', 'F', + '_', 'B', 'D', 0 + }; + const UNIT needle[] = + { '_', 'E', 'F', '_', 'B', 'F', '_', 'B', 'D', '_', 'E', 'F', + '_', 'B', 'F', '_', 'B', 'D', '_', 'E', 'F', '_', 'B', 'F', + '_', 'B', 'D', '_', 'E', 'F', '_', 'B', 'F', '_', 'B', 'D', + '_', 'E', 'F', '_', 'B', 'F', '_', 'B', 'D', 0 + }; + const UNIT *result = U_STRSTR (input, needle); + ASSERT (result == input + 115); + } + + /* Check that a very long haystack is handled quickly if the needle is + short and occurs near the beginning. */ + { + size_t repeat = 10000; + size_t m = 1000000; + const UNIT needle[] = + { 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', + 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', + 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', + 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', + 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', + 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', + 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', + 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', + 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', + 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 0 + }; + UNIT *haystack = (UNIT *) malloc ((m + 1) * sizeof (UNIT)); + if (haystack != NULL) + { + size_t i; + + haystack[0] = 'B'; + for (i = 1; i < m; i++) + haystack[i] = 'A'; + haystack[m] = '\0'; + + for (; repeat > 0; repeat--) + { + ASSERT (U_STRSTR (haystack, needle) == haystack + 1); + } + + free (haystack); + } + } + + /* Check that a very long needle is discarded quickly if the haystack is + short. */ + { + size_t repeat = 10000; + size_t m = 1000000; + const UNIT haystack[] = + { 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', + 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', + 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', + 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', + 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'B', + 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', + 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', + 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', + 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', + 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', 0 + }; + UNIT *needle = (UNIT *) malloc ((m + 1) * sizeof (UNIT)); + if (needle != NULL) + { + size_t i; + + for (i = 0; i < m; i++) + needle[i] = 'A'; + needle[m] = '\0'; + + for (; repeat > 0; repeat--) + { + ASSERT (U_STRSTR (haystack, needle) == NULL); + } + + free (needle); + } + } + + /* Check that the asymptotic worst-case complexity is not quadratic. */ + { + size_t m = 1000000; + UNIT *haystack = (UNIT *) malloc ((2 * m + 2) * sizeof (UNIT)); + UNIT *needle = (UNIT *) malloc ((m + 2) * sizeof (UNIT)); + if (haystack != NULL && needle != NULL) + { + size_t i; + const UNIT *result; + + for (i = 0; i < 2 * m; i++) + haystack[i] = 'A'; + haystack[2 * m] = 'B'; + haystack[2 * m + 1] = 0; + + for (i = 0; i < m; i++) + needle[i] = 'A'; + needle[m] = 'B'; + needle[m + 1] = 0; + + result = U_STRSTR (haystack, needle); + ASSERT (result == haystack + m); + } + free (needle); + free (haystack); + } +} diff --git a/tests/unistr/test-u-strtok.h b/tests/unistr/test-u-strtok.h new file mode 100644 index 0000000..6c12484 --- /dev/null +++ b/tests/unistr/test-u-strtok.h @@ -0,0 +1,88 @@ +/* Test of uN_strtok() functions. + Copyright (C) 2015 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +static void +test_u_strtok (void) +{ + { + UNIT input[] = { 'f', 'o', 'o', 0 }; + const UNIT delim[] = { 0 }; + UNIT *state; + const UNIT *result = U_STRTOK (input, delim, &state); + ASSERT (result == input); + } + + { + UNIT input[] = + { 'A', 'B', 'C', ' ', 'A', 'B', 'C', 'D', 'A', 'B', ' ', '\t', + 'A', 'B', 'C', 'D', 'A', 'B', 'C', 'D', 'A', 'B', 'D', 'E', 0 + }; + const UNIT delim[] = { ' ', '\t', 0 }; + UNIT *state; + const UNIT *result; + result = U_STRTOK (input, delim, &state); + ASSERT (result == input); + result = U_STRTOK (NULL, delim, &state); + ASSERT (result == input + 4); + result = U_STRTOK (NULL, delim, &state); + ASSERT (result == input + 12); + result = U_STRTOK (NULL, delim, &state); + ASSERT (result == NULL); + } + + /* Check for multibyte delimiters. */ + { + ucs4_t u_input[] = + { 'A', 'B', 'C', 0x3000, 'A', 'B', 'C', 'D', 'A', 'B', 0x3000, 0x3001, + 'A', 'B', 'C', 'D', 'A', 'B', 'C', 'D', 'A', 'B', 'D', 'E', 0 + }; + ucs4_t u_delim[] = { 0x3000, 0x3001, 0 }; + size_t input_len = 6 * SIZEOF (u_input); + UNIT *input = (UNIT *) malloc (input_len); + size_t delim_len = 6 * SIZEOF (u_delim); + UNIT *delim = (UNIT *) malloc (delim_len); + UNIT *state; + const UNIT *result; + UNIT *ptr, *first_ptr, *second_ptr; + size_t i; + for (i = 0, ptr = input; i < SIZEOF (u_input) && u_input[i] != 0; i++) + { + int ret = U_UCTOMB (ptr, u_input[i], input_len - (ptr - input)); + if (i == 4) + first_ptr = ptr; + if (i == 12) + second_ptr = ptr; + ptr += ret; + } + *ptr = 0; + for (i = 0, ptr = delim; i < SIZEOF (u_delim) && u_delim[i] != 0; i++) + { + int ret = U_UCTOMB (ptr, u_delim[i], delim_len - (ptr - delim)); + ptr += ret; + } + *ptr = 0; + result = U_STRTOK (input, delim, &state); + ASSERT (result == input); + result = U_STRTOK (NULL, delim, &state); + ASSERT (result == first_ptr); + result = U_STRTOK (NULL, delim, &state); + ASSERT (result == second_ptr); + result = U_STRTOK (NULL, delim, &state); + ASSERT (result == NULL); + free (input); + free (delim); + } +} diff --git a/tests/unistr/test-u16-check.c b/tests/unistr/test-u16-check.c index b7a9c10..23adffe 100644 --- a/tests/unistr/test-u16-check.c +++ b/tests/unistr/test-u16-check.c @@ -1,5 +1,5 @@ /* Test of u16_check() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-chr.c b/tests/unistr/test-u16-chr.c index d71755c..7ffeb57 100644 --- a/tests/unistr/test-u16-chr.c +++ b/tests/unistr/test-u16-chr.c @@ -1,5 +1,5 @@ /* Test of u16_chr() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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,11 +21,14 @@ #include "unistr.h" #include <stdlib.h> +#include <string.h> #include "zerosize-ptr.h" #include "macros.h" #define UNIT uint16_t +#define U_UCTOMB u16_uctomb +#define U32_TO_U u32_to_u16 #define U_CHR u16_chr #define U_SET u16_set #include "test-chr.h" diff --git a/tests/unistr/test-u16-cmp.c b/tests/unistr/test-u16-cmp.c index 1ab9019..ab2025b 100644 --- a/tests/unistr/test-u16-cmp.c +++ b/tests/unistr/test-u16-cmp.c @@ -1,5 +1,5 @@ /* Test of u16_cmp() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-cmp2.c b/tests/unistr/test-u16-cmp2.c index 3993dcd..1a7ce04 100644 --- a/tests/unistr/test-u16-cmp2.c +++ b/tests/unistr/test-u16-cmp2.c @@ -1,5 +1,5 @@ /* Test of u16_cmp2() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-cpy-alloc.c b/tests/unistr/test-u16-cpy-alloc.c index d1aa211..a62502f 100644 --- a/tests/unistr/test-u16-cpy-alloc.c +++ b/tests/unistr/test-u16-cpy-alloc.c @@ -1,5 +1,5 @@ /* Test of u16_cpy_alloc() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-cpy.c b/tests/unistr/test-u16-cpy.c index 168a459..b109514 100644 --- a/tests/unistr/test-u16-cpy.c +++ b/tests/unistr/test-u16-cpy.c @@ -1,5 +1,5 @@ /* Test of u16_cpy() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-mblen.c b/tests/unistr/test-u16-mblen.c index 13186f3..5cec88d 100644 --- a/tests/unistr/test-u16-mblen.c +++ b/tests/unistr/test-u16-mblen.c @@ -1,5 +1,5 @@ /* Test of u16_mblen() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-mbsnlen.c b/tests/unistr/test-u16-mbsnlen.c index a2d8b10..4e99b57 100644 --- a/tests/unistr/test-u16-mbsnlen.c +++ b/tests/unistr/test-u16-mbsnlen.c @@ -1,5 +1,5 @@ /* Test of u16_mbsnlen() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-mbtouc-unsafe.c b/tests/unistr/test-u16-mbtouc-unsafe.c index a1d1214..6811033 100644 --- a/tests/unistr/test-u16-mbtouc-unsafe.c +++ b/tests/unistr/test-u16-mbtouc-unsafe.c @@ -1,5 +1,5 @@ /* Test of u16_mbtouc_unsafe() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-mbtouc.c b/tests/unistr/test-u16-mbtouc.c index 4545add..f673ee8 100644 --- a/tests/unistr/test-u16-mbtouc.c +++ b/tests/unistr/test-u16-mbtouc.c @@ -1,5 +1,5 @@ /* Test of u16_mbtouc() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-mbtouc.h b/tests/unistr/test-u16-mbtouc.h index ef0fb68..7019b4a 100644 --- a/tests/unistr/test-u16-mbtouc.h +++ b/tests/unistr/test-u16-mbtouc.h @@ -1,5 +1,5 @@ /* Test of u16_mbtouc() and u16_mbtouc_unsafe() functions. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-mbtoucr.c b/tests/unistr/test-u16-mbtoucr.c index fb1264d..bf93b12 100644 --- a/tests/unistr/test-u16-mbtoucr.c +++ b/tests/unistr/test-u16-mbtoucr.c @@ -1,5 +1,5 @@ /* Test of u16_mbtoucr() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-move.c b/tests/unistr/test-u16-move.c index ff1e6e3..32588d5 100644 --- a/tests/unistr/test-u16-move.c +++ b/tests/unistr/test-u16-move.c @@ -1,5 +1,5 @@ /* Test of u16_move() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-next.c b/tests/unistr/test-u16-next.c index d9ac6e9..f338f76 100644 --- a/tests/unistr/test-u16-next.c +++ b/tests/unistr/test-u16-next.c @@ -1,5 +1,5 @@ /* Test of u16_next() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-prev.c b/tests/unistr/test-u16-prev.c index 90e8341..8dcf6c1 100644 --- a/tests/unistr/test-u16-prev.c +++ b/tests/unistr/test-u16-prev.c @@ -1,5 +1,5 @@ /* Test of u16_prev() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-set.c b/tests/unistr/test-u16-set.c index f3e6305..a545f29 100644 --- a/tests/unistr/test-u16-set.c +++ b/tests/unistr/test-u16-set.c @@ -1,5 +1,5 @@ /* Test of u16_set() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-stpcpy.c b/tests/unistr/test-u16-stpcpy.c index 6bf3ecb..9615999 100644 --- a/tests/unistr/test-u16-stpcpy.c +++ b/tests/unistr/test-u16-stpcpy.c @@ -1,5 +1,5 @@ /* Test of u16_stpcpy() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-stpncpy.c b/tests/unistr/test-u16-stpncpy.c index e53ce6b..5bebcfb 100644 --- a/tests/unistr/test-u16-stpncpy.c +++ b/tests/unistr/test-u16-stpncpy.c @@ -1,5 +1,5 @@ /* Test of u16_stpncpy() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-strcat.c b/tests/unistr/test-u16-strcat.c index 9d6032e..d381d0c 100644 --- a/tests/unistr/test-u16-strcat.c +++ b/tests/unistr/test-u16-strcat.c @@ -1,5 +1,5 @@ /* Test of u16_strcat() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-strchr.c b/tests/unistr/test-u16-strchr.c new file mode 100644 index 0000000..d33f740 --- /dev/null +++ b/tests/unistr/test-u16-strchr.c @@ -0,0 +1,42 @@ +/* Test of u16_strchr() function. + Copyright (C) 2010-2015 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* Written by Paolo Bonzini <bonzini@gnu.org>, 2010. */ + +#include <config.h> + +#include "unistr.h" + +#include <stdlib.h> +#include <string.h> + +#include "zerosize-ptr.h" +#include "macros.h" + +#define UNIT uint16_t +#define U_UCTOMB u16_uctomb +#define U32_TO_U u32_to_u16 +#define U_STRCHR u16_strchr +#define U_SET u16_set +#include "test-strchr.h" + +int +main (void) +{ + test_strchr (); + + return 0; +} diff --git a/tests/unistr/test-u16-strcmp.c b/tests/unistr/test-u16-strcmp.c index 5fc4777..9c97613 100644 --- a/tests/unistr/test-u16-strcmp.c +++ b/tests/unistr/test-u16-strcmp.c @@ -1,5 +1,5 @@ /* Test of u16_strcmp() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-strcmp.h b/tests/unistr/test-u16-strcmp.h index ad54a43..6a3d988 100644 --- a/tests/unistr/test-u16-strcmp.h +++ b/tests/unistr/test-u16-strcmp.h @@ -1,5 +1,5 @@ /* Test of u16_strcmp() and u16_strcoll() functions. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-strcoll.c b/tests/unistr/test-u16-strcoll.c index e24814a..ac32c5b 100644 --- a/tests/unistr/test-u16-strcoll.c +++ b/tests/unistr/test-u16-strcoll.c @@ -1,5 +1,5 @@ /* Test of u16_strcoll() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-strcpy.c b/tests/unistr/test-u16-strcpy.c index e017a11..e274d78 100644 --- a/tests/unistr/test-u16-strcpy.c +++ b/tests/unistr/test-u16-strcpy.c @@ -1,5 +1,5 @@ /* Test of u16_strcpy() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-strdup.c b/tests/unistr/test-u16-strdup.c index f0266d1..33d1d0b 100644 --- a/tests/unistr/test-u16-strdup.c +++ b/tests/unistr/test-u16-strdup.c @@ -1,5 +1,5 @@ /* Test of u16_strdup() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-strlen.c b/tests/unistr/test-u16-strlen.c index 7b8690b..40f6af3 100644 --- a/tests/unistr/test-u16-strlen.c +++ b/tests/unistr/test-u16-strlen.c @@ -1,5 +1,5 @@ /* Test of u16_strlen() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-strmblen.c b/tests/unistr/test-u16-strmblen.c index 80371b0..36103a2 100644 --- a/tests/unistr/test-u16-strmblen.c +++ b/tests/unistr/test-u16-strmblen.c @@ -1,5 +1,5 @@ /* Test of u16_strmblen() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-strmbtouc.c b/tests/unistr/test-u16-strmbtouc.c index ceeaf2c..fb6f08a 100644 --- a/tests/unistr/test-u16-strmbtouc.c +++ b/tests/unistr/test-u16-strmbtouc.c @@ -1,5 +1,5 @@ /* Test of u16_strmbtouc() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-strncat.c b/tests/unistr/test-u16-strncat.c index c875cfc..9a407f0 100644 --- a/tests/unistr/test-u16-strncat.c +++ b/tests/unistr/test-u16-strncat.c @@ -1,5 +1,5 @@ /* Test of u16_strncat() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-strncmp.c b/tests/unistr/test-u16-strncmp.c index b04431b..c6ed7c0 100644 --- a/tests/unistr/test-u16-strncmp.c +++ b/tests/unistr/test-u16-strncmp.c @@ -1,5 +1,5 @@ /* Test of u16_strncmp() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-strncpy.c b/tests/unistr/test-u16-strncpy.c index 102f653..21e302d 100644 --- a/tests/unistr/test-u16-strncpy.c +++ b/tests/unistr/test-u16-strncpy.c @@ -1,5 +1,5 @@ /* Test of u16_strncpy() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-strnlen.c b/tests/unistr/test-u16-strnlen.c index beeba64..85ff647 100644 --- a/tests/unistr/test-u16-strnlen.c +++ b/tests/unistr/test-u16-strnlen.c @@ -1,5 +1,5 @@ /* Test of u16_strnlen() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-strstr.c b/tests/unistr/test-u16-strstr.c new file mode 100644 index 0000000..8f0f4f1 --- /dev/null +++ b/tests/unistr/test-u16-strstr.c @@ -0,0 +1,47 @@ +/* Test of u16_strstr() function. + Copyright (C) 2011-2015 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* Written by Pádraig Brady <P@draigBrady.com>, 2011. */ + +#include <config.h> + +#include "unistr.h" + +#include <stdint.h> +#include <stdlib.h> +#include <signal.h> /* For signal. */ +#include <unistd.h> /* For alarm. */ + +#include "macros.h" + +#define UNIT uint16_t +#define U_STRSTR u16_strstr +#include "test-u-strstr.h" + +int +main (void) +{ +#if HAVE_DECL_ALARM + /* Declare failure if test takes too long, by using default abort + caused by SIGALRM. */ + signal (SIGALRM, SIG_DFL); + alarm (10); +#endif + + test_u_strstr (); + + return 0; +} diff --git a/tests/unistr/test-u16-strtok.c b/tests/unistr/test-u16-strtok.c new file mode 100644 index 0000000..cbd95ef --- /dev/null +++ b/tests/unistr/test-u16-strtok.c @@ -0,0 +1,37 @@ +/* Test of u16_strtok() function. + Copyright (C) 2015 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <config.h> + +#include "unistr.h" + +#include <stdint.h> +#include <stdlib.h> + +#include "macros.h" + +#define UNIT uint16_t +#define U_STRTOK u16_strtok +#define U_UCTOMB u16_uctomb +#include "test-u-strtok.h" + +int +main (void) +{ + test_u_strtok (); + + return 0; +} diff --git a/tests/unistr/test-u16-to-u32.c b/tests/unistr/test-u16-to-u32.c index 5b382b2..e095643 100644 --- a/tests/unistr/test-u16-to-u32.c +++ b/tests/unistr/test-u16-to-u32.c @@ -1,5 +1,5 @@ /* Test of u16_to_u32() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-to-u8.c b/tests/unistr/test-u16-to-u8.c index 4ef9b9b..f62c21e 100644 --- a/tests/unistr/test-u16-to-u8.c +++ b/tests/unistr/test-u16-to-u8.c @@ -1,5 +1,5 @@ /* Test of u16_to_u8() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u16-uctomb.c b/tests/unistr/test-u16-uctomb.c index ba50225..cfa2104 100644 --- a/tests/unistr/test-u16-uctomb.c +++ b/tests/unistr/test-u16-uctomb.c @@ -1,5 +1,5 @@ /* Test of u16_uctomb() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-check.c b/tests/unistr/test-u32-check.c index fdd64df..49099ec 100644 --- a/tests/unistr/test-u32-check.c +++ b/tests/unistr/test-u32-check.c @@ -1,5 +1,5 @@ /* Test of u32_check() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-chr.c b/tests/unistr/test-u32-chr.c index f23aa08..ae274f4 100644 --- a/tests/unistr/test-u32-chr.c +++ b/tests/unistr/test-u32-chr.c @@ -1,5 +1,5 @@ /* Test of u32_chr() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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,11 +21,14 @@ #include "unistr.h" #include <stdlib.h> +#include <string.h> #include "zerosize-ptr.h" #include "macros.h" #define UNIT uint32_t +#define U_UCTOMB(s, uc, n) (*(s) = (uc), 1) +#define U32_TO_U(s, n, result, length) (*(length) = (n), (s)) #define U_CHR u32_chr #define U_SET u32_set #include "test-chr.h" diff --git a/tests/unistr/test-u32-cmp.c b/tests/unistr/test-u32-cmp.c index ab41b31..20c0646 100644 --- a/tests/unistr/test-u32-cmp.c +++ b/tests/unistr/test-u32-cmp.c @@ -1,5 +1,5 @@ /* Test of u32_cmp() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-cmp2.c b/tests/unistr/test-u32-cmp2.c index 84450b5..376aa73 100644 --- a/tests/unistr/test-u32-cmp2.c +++ b/tests/unistr/test-u32-cmp2.c @@ -1,5 +1,5 @@ /* Test of u32_cmp2() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-cpy-alloc.c b/tests/unistr/test-u32-cpy-alloc.c index d3675dd..73a4b85 100644 --- a/tests/unistr/test-u32-cpy-alloc.c +++ b/tests/unistr/test-u32-cpy-alloc.c @@ -1,5 +1,5 @@ /* Test of u32_cpy_alloc() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-cpy.c b/tests/unistr/test-u32-cpy.c index 49fc995..cf11e6c 100644 --- a/tests/unistr/test-u32-cpy.c +++ b/tests/unistr/test-u32-cpy.c @@ -1,5 +1,5 @@ /* Test of u32_cpy() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-mblen.c b/tests/unistr/test-u32-mblen.c index 1ebd93e..1e038e1 100644 --- a/tests/unistr/test-u32-mblen.c +++ b/tests/unistr/test-u32-mblen.c @@ -1,5 +1,5 @@ /* Test of u32_mblen() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-mbsnlen.c b/tests/unistr/test-u32-mbsnlen.c index d9e066b..9a87634 100644 --- a/tests/unistr/test-u32-mbsnlen.c +++ b/tests/unistr/test-u32-mbsnlen.c @@ -1,5 +1,5 @@ /* Test of u32_mbsnlen() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-mbtouc-unsafe.c b/tests/unistr/test-u32-mbtouc-unsafe.c index cb3052c..d0ee0af 100644 --- a/tests/unistr/test-u32-mbtouc-unsafe.c +++ b/tests/unistr/test-u32-mbtouc-unsafe.c @@ -1,5 +1,5 @@ /* Test of u32_mbtouc_unsafe() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-mbtouc.c b/tests/unistr/test-u32-mbtouc.c index 7c981b5..e582979 100644 --- a/tests/unistr/test-u32-mbtouc.c +++ b/tests/unistr/test-u32-mbtouc.c @@ -1,5 +1,5 @@ /* Test of u32_mbtouc() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-mbtouc.h b/tests/unistr/test-u32-mbtouc.h index 7d70133..b0a7498 100644 --- a/tests/unistr/test-u32-mbtouc.h +++ b/tests/unistr/test-u32-mbtouc.h @@ -1,5 +1,5 @@ /* Test of u32_mbtouc() and u32_mbtouc_unsafe() functions. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-mbtoucr.c b/tests/unistr/test-u32-mbtoucr.c index 7b1034c..898baa2 100644 --- a/tests/unistr/test-u32-mbtoucr.c +++ b/tests/unistr/test-u32-mbtoucr.c @@ -1,5 +1,5 @@ /* Test of u32_mbtoucr() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-move.c b/tests/unistr/test-u32-move.c index 44f95c0..0dd9e30 100644 --- a/tests/unistr/test-u32-move.c +++ b/tests/unistr/test-u32-move.c @@ -1,5 +1,5 @@ /* Test of u32_move() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-next.c b/tests/unistr/test-u32-next.c index a5852e2..339ffb9 100644 --- a/tests/unistr/test-u32-next.c +++ b/tests/unistr/test-u32-next.c @@ -1,5 +1,5 @@ /* Test of u32_next() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-prev.c b/tests/unistr/test-u32-prev.c index 95187af..a49525d 100644 --- a/tests/unistr/test-u32-prev.c +++ b/tests/unistr/test-u32-prev.c @@ -1,5 +1,5 @@ /* Test of u32_prev() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-set.c b/tests/unistr/test-u32-set.c index 120804f..0051609 100644 --- a/tests/unistr/test-u32-set.c +++ b/tests/unistr/test-u32-set.c @@ -1,5 +1,5 @@ /* Test of u32_set() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-stpcpy.c b/tests/unistr/test-u32-stpcpy.c index 9c99c52..04a16a5 100644 --- a/tests/unistr/test-u32-stpcpy.c +++ b/tests/unistr/test-u32-stpcpy.c @@ -1,5 +1,5 @@ /* Test of u32_stpcpy() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-stpncpy.c b/tests/unistr/test-u32-stpncpy.c index e29683b..4b99666 100644 --- a/tests/unistr/test-u32-stpncpy.c +++ b/tests/unistr/test-u32-stpncpy.c @@ -1,5 +1,5 @@ /* Test of u32_stpncpy() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-strcat.c b/tests/unistr/test-u32-strcat.c index 66e7c85..02f9615 100644 --- a/tests/unistr/test-u32-strcat.c +++ b/tests/unistr/test-u32-strcat.c @@ -1,5 +1,5 @@ /* Test of u32_strcat() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-strchr.c b/tests/unistr/test-u32-strchr.c new file mode 100644 index 0000000..054b996 --- /dev/null +++ b/tests/unistr/test-u32-strchr.c @@ -0,0 +1,42 @@ +/* Test of u32_strchr() function. + Copyright (C) 2010-2015 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* Written by Paolo Bonzini <bonzini@gnu.org>, 2010. */ + +#include <config.h> + +#include "unistr.h" + +#include <stdlib.h> +#include <string.h> + +#include "zerosize-ptr.h" +#include "macros.h" + +#define UNIT uint32_t +#define U_UCTOMB(s, uc, n) (*(s) = (uc), 1) +#define U32_TO_U(s, n, result, length) (*(length) = (n), (s)) +#define U_STRCHR u32_strchr +#define U_SET u32_set +#include "test-strchr.h" + +int +main (void) +{ + test_strchr (); + + return 0; +} diff --git a/tests/unistr/test-u32-strcmp.c b/tests/unistr/test-u32-strcmp.c index 8364a41..8b420cf 100644 --- a/tests/unistr/test-u32-strcmp.c +++ b/tests/unistr/test-u32-strcmp.c @@ -1,5 +1,5 @@ /* Test of u32_strcmp() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-strcmp.h b/tests/unistr/test-u32-strcmp.h index 6d24132..4b1fdd0 100644 --- a/tests/unistr/test-u32-strcmp.h +++ b/tests/unistr/test-u32-strcmp.h @@ -1,5 +1,5 @@ /* Test of u32_strcmp() and u32_strcoll() functions. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-strcoll.c b/tests/unistr/test-u32-strcoll.c index 36954e7..f718a82 100644 --- a/tests/unistr/test-u32-strcoll.c +++ b/tests/unistr/test-u32-strcoll.c @@ -1,5 +1,5 @@ /* Test of u32_strcoll() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-strcpy.c b/tests/unistr/test-u32-strcpy.c index 2e22aad..b388890 100644 --- a/tests/unistr/test-u32-strcpy.c +++ b/tests/unistr/test-u32-strcpy.c @@ -1,5 +1,5 @@ /* Test of u32_strcpy() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-strdup.c b/tests/unistr/test-u32-strdup.c index ede8e54..c200e65 100644 --- a/tests/unistr/test-u32-strdup.c +++ b/tests/unistr/test-u32-strdup.c @@ -1,5 +1,5 @@ /* Test of u32_strdup() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-strlen.c b/tests/unistr/test-u32-strlen.c index a349be7..a797398 100644 --- a/tests/unistr/test-u32-strlen.c +++ b/tests/unistr/test-u32-strlen.c @@ -1,5 +1,5 @@ /* Test of u32_strlen() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-strmblen.c b/tests/unistr/test-u32-strmblen.c index 733f8fc..0b74531 100644 --- a/tests/unistr/test-u32-strmblen.c +++ b/tests/unistr/test-u32-strmblen.c @@ -1,5 +1,5 @@ /* Test of u32_strmblen() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-strmbtouc.c b/tests/unistr/test-u32-strmbtouc.c index 79c222e..39451f7 100644 --- a/tests/unistr/test-u32-strmbtouc.c +++ b/tests/unistr/test-u32-strmbtouc.c @@ -1,5 +1,5 @@ /* Test of u32_strmbtouc() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-strncat.c b/tests/unistr/test-u32-strncat.c index 346bafb..2c78c8f 100644 --- a/tests/unistr/test-u32-strncat.c +++ b/tests/unistr/test-u32-strncat.c @@ -1,5 +1,5 @@ /* Test of u32_strncat() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-strncmp.c b/tests/unistr/test-u32-strncmp.c index d69913d..f1cad81 100644 --- a/tests/unistr/test-u32-strncmp.c +++ b/tests/unistr/test-u32-strncmp.c @@ -1,5 +1,5 @@ /* Test of u32_strncmp() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-strncpy.c b/tests/unistr/test-u32-strncpy.c index 9309c0e..ebe0add 100644 --- a/tests/unistr/test-u32-strncpy.c +++ b/tests/unistr/test-u32-strncpy.c @@ -1,5 +1,5 @@ /* Test of u32_strncpy() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-strnlen.c b/tests/unistr/test-u32-strnlen.c index 6929914..7941ab3 100644 --- a/tests/unistr/test-u32-strnlen.c +++ b/tests/unistr/test-u32-strnlen.c @@ -1,5 +1,5 @@ /* Test of u32_strnlen() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-strstr.c b/tests/unistr/test-u32-strstr.c new file mode 100644 index 0000000..c291b3c --- /dev/null +++ b/tests/unistr/test-u32-strstr.c @@ -0,0 +1,47 @@ +/* Test of u32_strstr() function. + Copyright (C) 2011-2015 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* Written by Pádraig Brady <P@draigBrady.com>, 2011. */ + +#include <config.h> + +#include "unistr.h" + +#include <stdint.h> +#include <stdlib.h> +#include <signal.h> /* For signal. */ +#include <unistd.h> /* For alarm. */ + +#include "macros.h" + +#define UNIT uint32_t +#define U_STRSTR u32_strstr +#include "test-u-strstr.h" + +int +main (void) +{ +#if HAVE_DECL_ALARM + /* Declare failure if test takes too long, by using default abort + caused by SIGALRM. */ + signal (SIGALRM, SIG_DFL); + alarm (10); +#endif + + test_u_strstr (); + + return 0; +} diff --git a/tests/unistr/test-u32-strtok.c b/tests/unistr/test-u32-strtok.c new file mode 100644 index 0000000..04cded7 --- /dev/null +++ b/tests/unistr/test-u32-strtok.c @@ -0,0 +1,37 @@ +/* Test of u32_strtok() function. + Copyright (C) 2015 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <config.h> + +#include "unistr.h" + +#include <stdint.h> +#include <stdlib.h> + +#include "macros.h" + +#define UNIT uint32_t +#define U_STRTOK u32_strtok +#define U_UCTOMB u32_uctomb +#include "test-u-strtok.h" + +int +main (void) +{ + test_u_strtok (); + + return 0; +} diff --git a/tests/unistr/test-u32-to-u16.c b/tests/unistr/test-u32-to-u16.c index 6faf537..65e1985 100644 --- a/tests/unistr/test-u32-to-u16.c +++ b/tests/unistr/test-u32-to-u16.c @@ -1,5 +1,5 @@ /* Test of u32_to_u16() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-to-u8.c b/tests/unistr/test-u32-to-u8.c index 933fba0..deb4560 100644 --- a/tests/unistr/test-u32-to-u8.c +++ b/tests/unistr/test-u32-to-u8.c @@ -1,5 +1,5 @@ /* Test of u32_to_u8() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u32-uctomb.c b/tests/unistr/test-u32-uctomb.c index 0a25177..acc4c73 100644 --- a/tests/unistr/test-u32-uctomb.c +++ b/tests/unistr/test-u32-uctomb.c @@ -1,5 +1,5 @@ /* Test of u32_uctomb() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-check.c b/tests/unistr/test-u8-check.c index a32d385..fcf678c 100644 --- a/tests/unistr/test-u8-check.c +++ b/tests/unistr/test-u8-check.c @@ -1,5 +1,5 @@ /* Test of u8_check() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-chr.c b/tests/unistr/test-u8-chr.c index 7c4b999..2d28f9e 100644 --- a/tests/unistr/test-u8-chr.c +++ b/tests/unistr/test-u8-chr.c @@ -1,5 +1,5 @@ /* Test of u8_chr() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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,11 +21,14 @@ #include "unistr.h" #include <stdlib.h> +#include <string.h> #include "zerosize-ptr.h" #include "macros.h" #define UNIT uint8_t +#define U_UCTOMB u8_uctomb +#define U32_TO_U u32_to_u8 #define U_CHR u8_chr #define U_SET u8_set #include "test-chr.h" diff --git a/tests/unistr/test-u8-cmp.c b/tests/unistr/test-u8-cmp.c index 73778c7..5606f0a 100644 --- a/tests/unistr/test-u8-cmp.c +++ b/tests/unistr/test-u8-cmp.c @@ -1,5 +1,5 @@ /* Test of u8_cmp() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-cmp2.c b/tests/unistr/test-u8-cmp2.c index 8a7848e..07b52d9 100644 --- a/tests/unistr/test-u8-cmp2.c +++ b/tests/unistr/test-u8-cmp2.c @@ -1,5 +1,5 @@ /* Test of u8_cmp2() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-cpy-alloc.c b/tests/unistr/test-u8-cpy-alloc.c index 2d35b8f..ff89813 100644 --- a/tests/unistr/test-u8-cpy-alloc.c +++ b/tests/unistr/test-u8-cpy-alloc.c @@ -1,5 +1,5 @@ /* Test of u8_cpy_alloc() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-cpy.c b/tests/unistr/test-u8-cpy.c index 8d1152d..2e2c06f 100644 --- a/tests/unistr/test-u8-cpy.c +++ b/tests/unistr/test-u8-cpy.c @@ -1,5 +1,5 @@ /* Test of u8_cpy() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-mblen.c b/tests/unistr/test-u8-mblen.c index 75e92d6..3e68b66 100644 --- a/tests/unistr/test-u8-mblen.c +++ b/tests/unistr/test-u8-mblen.c @@ -1,5 +1,5 @@ /* Test of u8_mblen() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-mbsnlen.c b/tests/unistr/test-u8-mbsnlen.c index 8e68550..e57e3ea 100644 --- a/tests/unistr/test-u8-mbsnlen.c +++ b/tests/unistr/test-u8-mbsnlen.c @@ -1,5 +1,5 @@ /* Test of u8_mbsnlen() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 @@ -57,5 +57,64 @@ main () } } + /* Test behaviour required by ISO 10646-1, sections R.7 and 2.3c, namely, + that a "malformed sequence" is interpreted in the same way as + "a character that is outside the adopted subset". + Reference: + Markus Kuhn: UTF-8 decoder capability and stress test + <http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt> + <http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html> + */ + /* 3.1. Test that each unexpected continuation byte is signalled as a + malformed sequence of its own. */ + { + static const uint8_t input[] = { '"', 0x80, 0xBF, 0x80, 0xBF, '"' }; + ASSERT (u8_mbsnlen (input, 6) == 6); + } + /* 3.2. Lonely start characters. */ + { + ucs4_t c; + uint8_t input[2]; + + for (c = 0xC0; c <= 0xFF; c++) + { + input[0] = c; + input[1] = ' '; + + ASSERT (u8_mbsnlen (input, 2) == 2); + } + } + /* 3.3. Sequences with last continuation byte missing. */ + /* 3.3.1. 2-byte sequence with last byte missing. */ + { + static const uint8_t input[] = { '"', 0xC0, '"' }; + ASSERT (u8_mbsnlen (input, 3) == 3); + } + /* 3.3.6. 2-byte sequence with last byte missing. */ + { + static const uint8_t input[] = { '"', 0xDF, '"' }; + ASSERT (u8_mbsnlen (input, 3) == 3); + } + /* 3.3.2. 3-byte sequence with last byte missing. */ + { + static const uint8_t input[] = { '"', 0xE0, 0x80, '"' }; + ASSERT (u8_mbsnlen (input, 4) == 3); + } + /* 3.3.7. 3-byte sequence with last byte missing. */ + { + static const uint8_t input[] = { '"', 0xEF, 0xBF, '"' }; + ASSERT (u8_mbsnlen (input, 4) == 3); + } + /* 3.3.3. 4-byte sequence with last byte missing. */ + { + static const uint8_t input[] = { '"', 0xF0, 0x80, 0x80, '"' }; + ASSERT (u8_mbsnlen (input, 5) == 3); + } + /* 3.3.8. 4-byte sequence with last byte missing. */ + { + static const uint8_t input[] = { '"', 0xF7, 0xBF, 0xBF, '"' }; + ASSERT (u8_mbsnlen (input, 5) == 3); + } + return 0; } diff --git a/tests/unistr/test-u8-mbtouc-unsafe.c b/tests/unistr/test-u8-mbtouc-unsafe.c index b093aa8..cf9ba19 100644 --- a/tests/unistr/test-u8-mbtouc-unsafe.c +++ b/tests/unistr/test-u8-mbtouc-unsafe.c @@ -1,5 +1,5 @@ /* Test of u8_mbtouc_unsafe() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-mbtouc.c b/tests/unistr/test-u8-mbtouc.c index f6960a6..9e3b960 100644 --- a/tests/unistr/test-u8-mbtouc.c +++ b/tests/unistr/test-u8-mbtouc.c @@ -1,5 +1,5 @@ /* Test of u8_mbtouc() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 @@ -24,10 +24,169 @@ #include "test-u8-mbtouc.h" +static void +test_safe_function (int (*my_u8_mbtouc) (ucs4_t *, const uint8_t *, size_t)) +{ + ucs4_t uc; + int ret; + + /* Test behaviour required by ISO 10646-1, sections R.7 and 2.3c, namely, + that a "malformed sequence" is interpreted in the same way as + "a character that is outside the adopted subset". + Reference: + Markus Kuhn: UTF-8 decoder capability and stress test + <http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt> + <http://www.w3.org/2001/06/utf-8-wrong/UTF-8-test.html> + */ + /* 3.1. Test that each unexpected continuation byte is signalled as a + malformed sequence of its own. */ + { + static const uint8_t input[] = { '"', 0x80, 0xBF, 0x80, 0xBF, '"' }; + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input, 6); + ASSERT (ret == 1); + ASSERT (uc == 0x0022); + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input + 1, 5); + ASSERT (ret == 1); + ASSERT (uc == 0xFFFD); + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input + 2, 4); + ASSERT (ret == 1); + ASSERT (uc == 0xFFFD); + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input + 3, 3); + ASSERT (ret == 1); + ASSERT (uc == 0xFFFD); + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input + 4, 2); + ASSERT (ret == 1); + ASSERT (uc == 0xFFFD); + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input + 5, 1); + ASSERT (ret == 1); + ASSERT (uc == 0x0022); + } + /* 3.2. Lonely start characters. */ + { + ucs4_t c; + uint8_t input[2]; + + for (c = 0xC0; c <= 0xFF; c++) + { + input[0] = c; + input[1] = ' '; + + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input, 2); + ASSERT (ret == 1); + ASSERT (uc == 0xFFFD); + } + } + /* 3.3. Sequences with last continuation byte missing. */ + /* 3.3.1. 2-byte sequence with last byte missing. */ + { + static const uint8_t input[] = { '"', 0xC0, '"' }; + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input, 3); + ASSERT (ret == 1); + ASSERT (uc == 0x0022); + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input + 1, 2); + ASSERT (ret == 1); + ASSERT (uc == 0xFFFD); + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input + 2, 1); + ASSERT (ret == 1); + ASSERT (uc == 0x0022); + } + /* 3.3.6. 2-byte sequence with last byte missing. */ + { + static const uint8_t input[] = { '"', 0xDF, '"' }; + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input, 3); + ASSERT (ret == 1); + ASSERT (uc == 0x0022); + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input + 1, 2); + ASSERT (ret == 1); + ASSERT (uc == 0xFFFD); + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input + 2, 1); + ASSERT (ret == 1); + ASSERT (uc == 0x0022); + } + /* 3.3.2. 3-byte sequence with last byte missing. */ + { + static const uint8_t input[] = { '"', 0xE0, 0x80, '"' }; + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input, 4); + ASSERT (ret == 1); + ASSERT (uc == 0x0022); + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input + 1, 3); + ASSERT (ret == 2); + ASSERT (uc == 0xFFFD); + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input + 3, 1); + ASSERT (ret == 1); + ASSERT (uc == 0x0022); + } + /* 3.3.7. 3-byte sequence with last byte missing. */ + { + static const uint8_t input[] = { '"', 0xEF, 0xBF, '"' }; + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input, 4); + ASSERT (ret == 1); + ASSERT (uc == 0x0022); + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input + 1, 3); + ASSERT (ret == 2); + ASSERT (uc == 0xFFFD); + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input + 3, 1); + ASSERT (ret == 1); + ASSERT (uc == 0x0022); + } + /* 3.3.3. 4-byte sequence with last byte missing. */ + { + static const uint8_t input[] = { '"', 0xF0, 0x80, 0x80, '"' }; + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input, 5); + ASSERT (ret == 1); + ASSERT (uc == 0x0022); + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input + 1, 4); + ASSERT (ret == 3); + ASSERT (uc == 0xFFFD); + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input + 4, 1); + ASSERT (ret == 1); + ASSERT (uc == 0x0022); + } + /* 3.3.8. 4-byte sequence with last byte missing. */ + { + static const uint8_t input[] = { '"', 0xF7, 0xBF, 0xBF, '"' }; + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input, 5); + ASSERT (ret == 1); + ASSERT (uc == 0x0022); + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input + 1, 4); + ASSERT (ret == 3); + ASSERT (uc == 0xFFFD); + uc = 0xBADFACE; + ret = my_u8_mbtouc (&uc, input + 4, 1); + ASSERT (ret == 1); + ASSERT (uc == 0x0022); + } +} + int main () { test_function (u8_mbtouc); + test_safe_function (u8_mbtouc); return 0; } diff --git a/tests/unistr/test-u8-mbtouc.h b/tests/unistr/test-u8-mbtouc.h index bcafb05..295160d 100644 --- a/tests/unistr/test-u8-mbtouc.h +++ b/tests/unistr/test-u8-mbtouc.h @@ -1,5 +1,5 @@ /* Test of u8_mbtouc() and u8_mbtouc_unsafe() functions. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 @@ -166,14 +166,14 @@ test_function (int (*my_u8_mbtouc) (ucs4_t *, const uint8_t *, size_t)) static const uint8_t input[] = { 0xF3, 0xD0, 0xBF }; uc = 0xBADFACE; ret = my_u8_mbtouc (&uc, input, 3); - ASSERT (ret == 1 || ret == 3); + ASSERT (ret == 1); ASSERT (uc == 0xFFFD); } { static const uint8_t input[] = { 0xF3, 0x8F, 0xD0 }; uc = 0xBADFACE; ret = my_u8_mbtouc (&uc, input, 3); - ASSERT (ret == 1 || ret == 3); + ASSERT (ret == 2); ASSERT (uc == 0xFFFD); } } diff --git a/tests/unistr/test-u8-mbtoucr.c b/tests/unistr/test-u8-mbtoucr.c index 88e08d3..7f02e8b 100644 --- a/tests/unistr/test-u8-mbtoucr.c +++ b/tests/unistr/test-u8-mbtoucr.c @@ -1,5 +1,5 @@ /* Test of u8_mbtoucr() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-move.c b/tests/unistr/test-u8-move.c index d18d8dd..eed72b4 100644 --- a/tests/unistr/test-u8-move.c +++ b/tests/unistr/test-u8-move.c @@ -1,5 +1,5 @@ /* Test of u8_move() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-next.c b/tests/unistr/test-u8-next.c index c4e06b5..4c509aa 100644 --- a/tests/unistr/test-u8-next.c +++ b/tests/unistr/test-u8-next.c @@ -1,5 +1,5 @@ /* Test of u8_next() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-prev.c b/tests/unistr/test-u8-prev.c index 61f47ef..9e2a9ba 100644 --- a/tests/unistr/test-u8-prev.c +++ b/tests/unistr/test-u8-prev.c @@ -1,5 +1,5 @@ /* Test of u8_prev() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-set.c b/tests/unistr/test-u8-set.c index e778fed..de2f281 100644 --- a/tests/unistr/test-u8-set.c +++ b/tests/unistr/test-u8-set.c @@ -1,5 +1,5 @@ /* Test of u8_set() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-stpcpy.c b/tests/unistr/test-u8-stpcpy.c index 94c0471..d7403e8 100644 --- a/tests/unistr/test-u8-stpcpy.c +++ b/tests/unistr/test-u8-stpcpy.c @@ -1,5 +1,5 @@ /* Test of u8_stpcpy() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-stpncpy.c b/tests/unistr/test-u8-stpncpy.c index 4809626..18f11df 100644 --- a/tests/unistr/test-u8-stpncpy.c +++ b/tests/unistr/test-u8-stpncpy.c @@ -1,5 +1,5 @@ /* Test of u8_stpncpy() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-strcat.c b/tests/unistr/test-u8-strcat.c index 7fa9e84..7f4a095 100644 --- a/tests/unistr/test-u8-strcat.c +++ b/tests/unistr/test-u8-strcat.c @@ -1,5 +1,5 @@ /* Test of u8_strcat() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-strchr.c b/tests/unistr/test-u8-strchr.c new file mode 100644 index 0000000..ff7abe6 --- /dev/null +++ b/tests/unistr/test-u8-strchr.c @@ -0,0 +1,149 @@ +/* Test of u8_strchr() function. + Copyright (C) 2010-2015 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* Written by Paolo Bonzini <bonzini@gnu.org>, 2010. */ + +#include <config.h> + +#include "unistr.h" + +#include <stdlib.h> +#include <string.h> + +#include "zerosize-ptr.h" +#include "macros.h" + +#define UNIT uint8_t +#define U_UCTOMB u8_uctomb +#define U32_TO_U u32_to_u8 +#define U_STRCHR u8_strchr +#define U_SET u8_set +#include "test-strchr.h" + +int +main (void) +{ + test_strchr (); + + /* Check that u8_strchr() does not read past the end of the string. */ + { + char *page_boundary = (char *) zerosize_ptr (); + + if (page_boundary != NULL) + { + UNIT *mem; + + mem = (UNIT *) (page_boundary - 1 * sizeof (UNIT)); + mem[0] = 0; + ASSERT (u8_strchr (mem, 0x55) == NULL); + ASSERT (u8_strchr (mem, 0x123) == NULL); + ASSERT (u8_strchr (mem, 0x3456) == NULL); + ASSERT (u8_strchr (mem, 0x23456) == NULL); + + mem = (UNIT *) (page_boundary - 2 * sizeof (UNIT)); + mem[0] = 0x50; + mem[1] = 0; + ASSERT (u8_strchr (mem, 0x55) == NULL); + ASSERT (u8_strchr (mem, 0x123) == NULL); + ASSERT (u8_strchr (mem, 0x3456) == NULL); + ASSERT (u8_strchr (mem, 0x23456) == NULL); + + mem = (UNIT *) (page_boundary - 3 * sizeof (UNIT)); + mem[0] = 0x50; + mem[1] = 0x50; + mem[2] = 0; + ASSERT (u8_strchr (mem, 0x55) == NULL); + ASSERT (u8_strchr (mem, 0x123) == NULL); + ASSERT (u8_strchr (mem, 0x3456) == NULL); + ASSERT (u8_strchr (mem, 0x23456) == NULL); + + mem = (UNIT *) (page_boundary - 3 * sizeof (UNIT)); + mem[0] = 0xC4; mem[1] = 0xA0; /* U+0120 */ + mem[2] = 0; + ASSERT (u8_strchr (mem, 0x55) == NULL); + ASSERT (u8_strchr (mem, 0x123) == NULL); + ASSERT (u8_strchr (mem, 0x3456) == NULL); + ASSERT (u8_strchr (mem, 0x23456) == NULL); + + mem = (UNIT *) (page_boundary - 3 * sizeof (UNIT)); + mem[0] = 0xC5; mem[1] = 0xA3; /* U+0163 */ + mem[2] = 0; + ASSERT (u8_strchr (mem, 0x55) == NULL); + ASSERT (u8_strchr (mem, 0x123) == NULL); + ASSERT (u8_strchr (mem, 0x3456) == NULL); + ASSERT (u8_strchr (mem, 0x23456) == NULL); + + mem = (UNIT *) (page_boundary - 4 * sizeof (UNIT)); + mem[0] = 0x50; + mem[1] = 0x50; + mem[2] = 0x50; + mem[3] = 0; + ASSERT (u8_strchr (mem, 0x55) == NULL); + ASSERT (u8_strchr (mem, 0x123) == NULL); + ASSERT (u8_strchr (mem, 0x3456) == NULL); + ASSERT (u8_strchr (mem, 0x23456) == NULL); + + mem = (UNIT *) (page_boundary - 4 * sizeof (UNIT)); + mem[0] = 0x50; + mem[1] = 0xC5; mem[2] = 0xA3; /* U+0163 */ + mem[3] = 0; + ASSERT (u8_strchr (mem, 0x55) == NULL); + ASSERT (u8_strchr (mem, 0x123) == NULL); + ASSERT (u8_strchr (mem, 0x3456) == NULL); + ASSERT (u8_strchr (mem, 0x23456) == NULL); + ASSERT (u8_strchr (mem, 0x163) == mem + 1); + + mem = (UNIT *) (page_boundary - 4 * sizeof (UNIT)); + mem[0] = 0xE3; mem[1] = 0x91; mem[2] = 0x00; /* U+3450 */ + mem[3] = 0; + ASSERT (u8_strchr (mem, 0x55) == NULL); + ASSERT (u8_strchr (mem, 0x123) == NULL); + ASSERT (u8_strchr (mem, 0x3456) == NULL); + ASSERT (u8_strchr (mem, 0x23456) == NULL); + + mem = (UNIT *) (page_boundary - 4 * sizeof (UNIT)); + mem[0] = 0xE3; mem[1] = 0x92; mem[2] = 0x96; /* U+3496 */ + mem[3] = 0; + ASSERT (u8_strchr (mem, 0x55) == NULL); + ASSERT (u8_strchr (mem, 0x123) == NULL); + ASSERT (u8_strchr (mem, 0x3456) == NULL); + ASSERT (u8_strchr (mem, 0x23456) == NULL); + + mem = (UNIT *) (page_boundary - 5 * sizeof (UNIT)); + mem[0] = 0x50; + mem[1] = 0x50; + mem[2] = 0x50; + mem[3] = 0x50; + mem[4] = 0; + ASSERT (u8_strchr (mem, 0x55) == NULL); + ASSERT (u8_strchr (mem, 0x123) == NULL); + ASSERT (u8_strchr (mem, 0x3456) == NULL); + ASSERT (u8_strchr (mem, 0x23456) == NULL); + + mem = (UNIT *) (page_boundary - 5 * sizeof (UNIT)); + mem[0] = 0x50; + mem[1] = 0xE3; mem[2] = 0x92; mem[3] = 0x96; /* U+3496 */ + mem[4] = 0; + ASSERT (u8_strchr (mem, 0x55) == NULL); + ASSERT (u8_strchr (mem, 0x123) == NULL); + ASSERT (u8_strchr (mem, 0x3456) == NULL); + ASSERT (u8_strchr (mem, 0x23456) == NULL); + ASSERT (u8_strchr (mem, 0x3496) == mem + 1); + } + } + + return 0; +} diff --git a/tests/unistr/test-u8-strcmp.c b/tests/unistr/test-u8-strcmp.c index 313cd11..51a90db 100644 --- a/tests/unistr/test-u8-strcmp.c +++ b/tests/unistr/test-u8-strcmp.c @@ -1,5 +1,5 @@ /* Test of u8_strcmp() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-strcmp.h b/tests/unistr/test-u8-strcmp.h index 9c25dac..66dec74 100644 --- a/tests/unistr/test-u8-strcmp.h +++ b/tests/unistr/test-u8-strcmp.h @@ -1,5 +1,5 @@ /* Test of u8_strcmp() and u8_strcoll() functions. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-strcoll.c b/tests/unistr/test-u8-strcoll.c index ae5c9a4..73f42dd 100644 --- a/tests/unistr/test-u8-strcoll.c +++ b/tests/unistr/test-u8-strcoll.c @@ -1,5 +1,5 @@ /* Test of u8_strcoll() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-strcpy.c b/tests/unistr/test-u8-strcpy.c index 810f975..2dd0201 100644 --- a/tests/unistr/test-u8-strcpy.c +++ b/tests/unistr/test-u8-strcpy.c @@ -1,5 +1,5 @@ /* Test of u8_strcpy() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-strdup.c b/tests/unistr/test-u8-strdup.c index 6da2151..c72b3d2 100644 --- a/tests/unistr/test-u8-strdup.c +++ b/tests/unistr/test-u8-strdup.c @@ -1,5 +1,5 @@ /* Test of u8_strdup() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-strlen.c b/tests/unistr/test-u8-strlen.c index 3dfa1b0..d4b3224 100644 --- a/tests/unistr/test-u8-strlen.c +++ b/tests/unistr/test-u8-strlen.c @@ -1,5 +1,5 @@ /* Test of u8_strlen() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-strmblen.c b/tests/unistr/test-u8-strmblen.c index bde3000..46bee92 100644 --- a/tests/unistr/test-u8-strmblen.c +++ b/tests/unistr/test-u8-strmblen.c @@ -1,5 +1,5 @@ /* Test of u8_strmblen() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-strmbtouc.c b/tests/unistr/test-u8-strmbtouc.c index 5591357..1239f40 100644 --- a/tests/unistr/test-u8-strmbtouc.c +++ b/tests/unistr/test-u8-strmbtouc.c @@ -1,5 +1,5 @@ /* Test of u8_strmbtouc() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-strncat.c b/tests/unistr/test-u8-strncat.c index bb90041..b7d248b 100644 --- a/tests/unistr/test-u8-strncat.c +++ b/tests/unistr/test-u8-strncat.c @@ -1,5 +1,5 @@ /* Test of u8_strncat() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-strncmp.c b/tests/unistr/test-u8-strncmp.c index f63cdaa..5bd7b5e 100644 --- a/tests/unistr/test-u8-strncmp.c +++ b/tests/unistr/test-u8-strncmp.c @@ -1,5 +1,5 @@ /* Test of u8_strncmp() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-strncpy.c b/tests/unistr/test-u8-strncpy.c index 64cabdc..5e20beb 100644 --- a/tests/unistr/test-u8-strncpy.c +++ b/tests/unistr/test-u8-strncpy.c @@ -1,5 +1,5 @@ /* Test of u8_strncpy() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-strnlen.c b/tests/unistr/test-u8-strnlen.c index 98de797..c59d7b1 100644 --- a/tests/unistr/test-u8-strnlen.c +++ b/tests/unistr/test-u8-strnlen.c @@ -1,5 +1,5 @@ /* Test of u8_strnlen() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-strstr.c b/tests/unistr/test-u8-strstr.c new file mode 100644 index 0000000..3d7be9c --- /dev/null +++ b/tests/unistr/test-u8-strstr.c @@ -0,0 +1,50 @@ +/* Test of u8_strstr() function. + Copyright (C) 2011-2015 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* Written by Pádraig Brady <P@draigBrady.com>, 2011. */ + +#include <config.h> + +#include "unistr.h" + +#include <stdint.h> +#include <stdlib.h> +#include <signal.h> /* For signal. */ +#include <unistd.h> /* For alarm. */ + +#include "macros.h" + +#define UNIT uint8_t +#define U_STRSTR u8_strstr +#include "test-u-strstr.h" + +int +main (void) +{ +#if HAVE_DECL_ALARM + /* Declare failure if test takes too long, by using default abort + caused by SIGALRM. Note since we defer to strstr() in this + case, we're assuming that we're running this test on the + same system that we did the check to ensure it has linear + performance characteristics. */ + signal (SIGALRM, SIG_DFL); + alarm (5); +#endif + + test_u_strstr (); + + return 0; +} diff --git a/tests/unistr/test-u8-strtok.c b/tests/unistr/test-u8-strtok.c new file mode 100644 index 0000000..6745ea8 --- /dev/null +++ b/tests/unistr/test-u8-strtok.c @@ -0,0 +1,37 @@ +/* Test of u8_strtok() function. + Copyright (C) 2015 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <config.h> + +#include "unistr.h" + +#include <stdint.h> +#include <stdlib.h> + +#include "macros.h" + +#define UNIT uint8_t +#define U_STRTOK u8_strtok +#define U_UCTOMB u8_uctomb +#include "test-u-strtok.h" + +int +main (void) +{ + test_u_strtok (); + + return 0; +} diff --git a/tests/unistr/test-u8-to-u16.c b/tests/unistr/test-u8-to-u16.c index 02ef44f..5f3ddad 100644 --- a/tests/unistr/test-u8-to-u16.c +++ b/tests/unistr/test-u8-to-u16.c @@ -1,5 +1,5 @@ /* Test of u8_to_u16() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-to-u32.c b/tests/unistr/test-u8-to-u32.c index d148e62..26ff002 100644 --- a/tests/unistr/test-u8-to-u32.c +++ b/tests/unistr/test-u8-to-u32.c @@ -1,5 +1,5 @@ /* Test of u8_to_u32() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 diff --git a/tests/unistr/test-u8-uctomb.c b/tests/unistr/test-u8-uctomb.c index 8fbdc42..f586f04 100644 --- a/tests/unistr/test-u8-uctomb.c +++ b/tests/unistr/test-u8-uctomb.c @@ -1,5 +1,5 @@ /* Test of u8_uctomb() function. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010-2015 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 |