From eaa75b70e31aed8ba2823c7b37ff92230dd8c451 Mon Sep 17 00:00:00 2001 From: Thomas Fitzsimmons Date: Wed, 24 Apr 2002 20:53:30 +0000 Subject: * Makefile.am (check-DEJAGNU): New target. (site.exp): Likewise. * acinclude.m4 (NEWLIB_CONFIGURE): Replace AC_CANONICAL_HOST with AC_CANONICAL_SYSTEM. Remove AC_CANONICAL_BUILD. * libc/locale/locale.c (_setlocale_r): Add UTF-8 support. * libc/stdlib/mbtowc_r.c (_mbtowc_r): Likewise. * libc/stdlib/wctomb_r.c (_wctomb_r): Likewise. * testsuite: New directory. * testsuite/config: Likewise. * testsuite/lib: Likewise. * testsuite/newlib.locale: Likewise. * testsuite/newlib.string: Likewise. * testsuite/config/default.exp: New file. * testsuite/lib/checkoutput.exp: New file. * testsuite/lib/newlib.exp: New file. * testsuite/lib/passfail.exp: New file. * testsuite/newlib.locale/UTF-8.c: New file. * testsuite/newlib.locale/UTF-8.exp: New file. * testsuite/newlib.locale/locale.exp: New file. * testsuite/newlib.string/string.exp: New file. * testsuite/newlib.string/tstring.c: New file. --- newlib/testsuite/config/default.exp | 7 + newlib/testsuite/lib/checkoutput.exp | 40 +++ newlib/testsuite/lib/newlib.exp | 110 +++++++++ newlib/testsuite/lib/passfail.exp | 39 +++ newlib/testsuite/newlib.locale/UTF-8.c | 397 ++++++++++++++++++++++++++++++ newlib/testsuite/newlib.locale/UTF-8.exp | 88 +++++++ newlib/testsuite/newlib.locale/locale.exp | 13 + newlib/testsuite/newlib.string/string.exp | 12 + newlib/testsuite/newlib.string/tstring.c | 349 ++++++++++++++++++++++++++ 9 files changed, 1055 insertions(+) create mode 100644 newlib/testsuite/config/default.exp create mode 100644 newlib/testsuite/lib/checkoutput.exp create mode 100644 newlib/testsuite/lib/newlib.exp create mode 100644 newlib/testsuite/lib/passfail.exp create mode 100644 newlib/testsuite/newlib.locale/UTF-8.c create mode 100644 newlib/testsuite/newlib.locale/UTF-8.exp create mode 100644 newlib/testsuite/newlib.locale/locale.exp create mode 100644 newlib/testsuite/newlib.string/string.exp create mode 100644 newlib/testsuite/newlib.string/tstring.c (limited to 'newlib/testsuite') diff --git a/newlib/testsuite/config/default.exp b/newlib/testsuite/config/default.exp new file mode 100644 index 0000000..4742182 --- /dev/null +++ b/newlib/testsuite/config/default.exp @@ -0,0 +1,7 @@ +# Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. +# +# Permission to use, copy, modify, and distribute this software +# is freely granted, provided that this notice is preserved. +# + +load_lib standard.exp diff --git a/newlib/testsuite/lib/checkoutput.exp b/newlib/testsuite/lib/checkoutput.exp new file mode 100644 index 0000000..5793868 --- /dev/null +++ b/newlib/testsuite/lib/checkoutput.exp @@ -0,0 +1,40 @@ +# Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. +# +# Permission to use, copy, modify, and distribute this software +# is freely granted, provided that this notice is preserved. +# + +# newlib_check_output takes the basename of the test source file, and +# a list of pairs of the form "testname" "expectedoutput" +# "testname" "expectedoutput"... It assumes one line of output +# per test. + +proc newlib_check_output { srcfile expectlist } { + global objdir subdir srcdir + + set srcfullname "$srcdir/$subdir/$srcfile" + set test_driver "$objdir/testsuite/[file tail [file rootname $srcfullname].x]" + + set comp_output [newlib_target_compile "$srcfullname" "$test_driver" "executable" ""] + + if { $comp_output != "" } { + fail "Failed to compile $srcfile.\n" + } else { + pass "Compiled $srcfile.\n" + } + + set result [newlib_load $test_driver ""] + set status [lindex $result 0] + set output [lindex $result 1] + + set output_lines [split $output "\n"] + + foreach { testname expectedval } $expectlist { + if [string match "$expectedval" "[lindex $output_lines 0]"] then { + pass $testname + } else { + fail $testname + } + set output_lines [lrange $output_lines 1 end] + } +} diff --git a/newlib/testsuite/lib/newlib.exp b/newlib/testsuite/lib/newlib.exp new file mode 100644 index 0000000..e94534f --- /dev/null +++ b/newlib/testsuite/lib/newlib.exp @@ -0,0 +1,110 @@ +# Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. +# +# Permission to use, copy, modify, and distribute this software +# is freely granted, provided that this notice is preserved. +# + +proc newlib_version { } { + global tool_version + + verbose "In newlib version...\n" + + return $tool_version +} + +set newlib_initialized 0 + +proc newlib_init { args } { + global gluefile wrap_flags + global newlib_initialized + global target_info + global CFLAGS_FOR_TARGET + # These values are initialized in the local site.exp file + global srcdir objdir + global build_triplet host_triplet + # newlib_cflags comes from acinclude.m4, through the site.exp file + global newlib_cflags + global old_ld_library_path + + verbose "In newlib_init...\n" + + if { $newlib_initialized == 1 } { return; } + + set CFLAGS_FOR_TARGET $newlib_cflags + + set_currtarget_info "wrap_compile_flags" "$newlib_cflags" + + if {[target_info needs_status_wrapper] != "" && \ + [target_info needs_status_wrapper] != "0" && \ + ![info exists gluefile]} { + set gluefile ${objdir}/testglue.o; + set result [build_wrapper $gluefile]; + if { $result != "" } { + set gluefile [lindex $result 0]; + set wrap_flags [lindex $result 1]; + } else { + unset gluefile + } + } + + if [string match $build_triplet $host_triplet] then { + if [string match "i686-pc-linux-gnu" $build_triplet] then { + set old_ld_library_path [getenv LD_LIBRARY_PATH] + setenv LD_LIBRARY_PATH "$objdir/.libs" + } + } +} + +proc newlib_target_compile { source dest type options } { + global gluefile wrap_flags + global srcdir objdir + global build_triplet + global host_triplet + + verbose "In newlib_target_compile...\n" + + if {[target_info needs_status_wrapper] != "" && \ + [target_info needs_status_wrapper] != "0" && \ + [info exists gluefile] } { + lappend options "libs=$gluefile" + # This method of finding libgloss_target_dir may not work for some targets + set libgloss_target_dir [lindex [split $host_triplet "-"] 0] + lappend options "ldflags=$wrap_flags -B$objdir/../libgloss/$libgloss_target_dir \ + -L$objdir/../libgloss/$libgloss_target_dir \ + -L$srcdir/../../libgloss/$libgloss_target_dir \ + -L$objdir" + } + + if [string match $build_triplet $host_triplet] then { + if [string match "i686-pc-linux-gnu" $build_triplet] then { + lappend options "libs=$objdir/crt0.o -lc" + lappend options "ldflags=-nostdlib -L$objdir/.libs -lgcc" + } + } + + return [target_compile $source $dest $type $options] +} + +proc newlib_finish { } { + global old_ld_library_path + global build_triplet host_triplet + + verbose "In newlib_finish...\n" + + if [string match $build_triplet $host_triplet] then { + if [string match "i686-pc-linux-gnu" $build_triplet] then { + setenv LD_LIBRARY_PATH "$old_ld_library_path" + } + } +} + +proc newlib_exit { } { + global gluefile; + + verbose "In newlib_exit...\n" + + if [info exists gluefile] { + file_on_build delete $gluefile; + unset gluefile; + } +} diff --git a/newlib/testsuite/lib/passfail.exp b/newlib/testsuite/lib/passfail.exp new file mode 100644 index 0000000..8a44d27 --- /dev/null +++ b/newlib/testsuite/lib/passfail.exp @@ -0,0 +1,39 @@ +# Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. +# +# Permission to use, copy, modify, and distribute this software +# is freely granted, provided that this notice is preserved. +# + +# newlib_pass_fail compiles and runs all the source files in the test +# directory that are not included in the check_output_tests list. +# check_output_tests lists the sources' basenames. + +proc newlib_pass_fail { check_output_tests } { + global srcdir objdir subdir runtests + + foreach testcase [glob -nocomplain $srcdir/$subdir/*.c] { + # If we're only testing specific files and this isn't one of them, skip it. + if ![runtest_file_p $runtests $testcase] then { + continue + } + + # Exclude tests which require their output to be checked + if {[lsearch $check_output_tests "[file tail $testcase]"] != -1} then { + continue + } + + set test_driver "$objdir/testsuite/[file tail [file rootname $testcase].x]" + + set comp_output [newlib_target_compile "$testcase" "$test_driver" "executable" ""] + + if { $comp_output != "" } { + fail "Failed to compile $testcase.\n" + fail "$testcase" + } else { + pass "Compiled $testcase.\n" + set result [newlib_load $test_driver ""] + set status [lindex $result 0] + $status "$testcase" + } + } +} diff --git a/newlib/testsuite/newlib.locale/UTF-8.c b/newlib/testsuite/newlib.locale/UTF-8.c new file mode 100644 index 0000000..5b1510d --- /dev/null +++ b/newlib/testsuite/newlib.locale/UTF-8.c @@ -0,0 +1,397 @@ +/* + * Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. + * + * Permission to use, copy, modify, and distribute this software + * is freely granted, provided that this notice is preserved. + * + * Tests gleaned from Markus Kuhn's UTF-8 and Unicode FAQ, + * and specifically, his UTF-8-test.txt decoder stress test file. + */ + +#include +#include +#include + +#define MAX_BYTES 65 + +int num_invalid(const char *s, int len); + +char first[6][6] = { + {0x0}, /* U-00000000 */ + {0xc2, 0x80}, /* U-00000080 */ + {0xe0, 0xa0, 0x80}, /* U-00000800 */ + {0xf0, 0x90, 0x80, 0x80}, /* U-00010000 */ + {0xf8, 0x88, 0x80, 0x80, 0x80}, /* U-00200000 */ + {0xfc, 0x84, 0x80, 0x80, 0x80, 0x80} /* U-04000000 */ +}; + +char last[6][6] = { + {0x7f}, /* U-0000007F */ + {0xdf, 0xbf}, /* U-000007FF */ + {0xef, 0xbf, 0xbf}, /* U-0000FFFF */ + {0xf7, 0xbf, 0xbf, 0xbf}, /* U-001FFFFF */ + {0xfb, 0xbf, 0xbf, 0xbf, 0xbf}, /* U-03FFFFFF */ + {0xfd, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf} /* U-7FFFFFFF */ +}; + +char boundary[5][6] = { + {0xed, 0x9f, 0xbf}, /* U-0000D7FF */ + {0xee, 0x80, 0x80}, /* U-0000E000 */ + {0xef, 0xbf, 0xbd}, /* U-0000FFFD */ + {0xf4, 0x8f, 0xbf, 0xbf}, /* U-0010FFFF */ + {0xf4, 0x90, 0x80, 0x80} /* U-00110000 */ +}; + +char continuation_bytes[8][7] = { + {0x80}, + {0xbf}, + {0x80, 0xbf}, + {0x80, 0xbf, 0x80}, + {0x80, 0xbf, 0x80, 0xbf}, + {0x80, 0xbf, 0x80, 0xbf, 0x80}, + {0x80, 0xbf, 0x80, 0xbf, 0x80, 0xbf}, + {0x80, 0xbf, 0x80, 0xbf, 0x80, 0xbf, 0x80} +}; + +char all_continuation_bytes[64]; + + +char all_two_byte_seq[32]; +char all_three_byte_seq[16]; +char all_four_byte_seq[8]; +char all_five_byte_seq[4]; +char all_six_byte_seq[2]; + +char incomplete_seq[10][6] = { + {0xc2}, /* U-00000080 */ + {0xe0, 0x80}, /* U-00000800 */ + {0xf0, 0x80, 0x80}, /* U-00010000 */ + {0xf8, 0x80, 0x80, 0x80}, /* U-00200000 */ + {0xfc, 0x80, 0x80, 0x80, 0x80}, /* U-04000000 */ + {0xdf}, /* U-000007FF */ + {0xef, 0xbf}, /* U-0000FFFF */ + {0xf7, 0xbf, 0xbf}, /* U-001FFFFF */ + {0xfb, 0xbf, 0xbf, 0xbf}, /* U-03FFFFFF */ + {0xfd, 0xbf, 0xbf, 0xbf, 0xbf} /* U-7FFFFFFF */ +}; + +char incomplete_seq_concat[30]; + +char impossible_bytes[3][4] = { + {0xfe}, + {0xff}, + {0xfe, 0xfe, 0xff, 0xff} +}; + +char overlong[5][6] = { + {0xc0, 0xaf}, + {0xe0, 0x80, 0xaf}, + {0xf0, 0x80, 0x80, 0xaf}, + {0xf8, 0x80, 0x80, 0x80, 0xaf}, + {0xfc, 0x80, 0x80, 0x80, 0x80, 0xaf} +}; + +char overlong_max[5][6] = { + {0xc1, 0xbf}, + {0xe0, 0x9f, 0xbf}, + {0xf0, 0x8f, 0xbf, 0xbf}, + {0xf8, 0x87, 0xbf, 0xbf, 0xbf}, + {0xfc, 0x83, 0xbf, 0xbf, 0xbf, 0xbf} +}; + +char overlong_nul[5][6] = { + {0xc0, 0x80}, + {0xe0, 0x80, 0x80}, + {0xf0, 0x80, 0x80, 0x80}, + {0xf8, 0x80, 0x80, 0x80, 0x80}, + {0xfc, 0x80, 0x80, 0x80, 0x80, 0x80} +}; + +char single_surrogates[7][3] = { + {0xed, 0xa0, 0x80}, + {0xed, 0xad, 0xbf}, + {0xed, 0xae, 0x80}, + {0xed, 0xaf, 0xbf}, + {0xed, 0xb0, 0x80}, + {0xed, 0xbe, 0x80}, + {0xed, 0xbf, 0xbf} +}; + +char paired_surrogates[8][6] = { + {0xed, 0xa0, 0x80, 0xed, 0xb0, 0x80}, + {0xed, 0xa0, 0x80, 0xed, 0xbf, 0xbf}, + {0xed, 0xad, 0xbf, 0xed, 0xb0, 0x80}, + {0xed, 0xad, 0xbf, 0xed, 0xbf, 0xbf}, + {0xed, 0xae, 0x80, 0xed, 0xb0, 0x80}, + {0xed, 0xae, 0x80, 0xed, 0xbf, 0xbf}, + {0xed, 0xaf, 0xbf, 0xed, 0xb0, 0x80}, + {0xed, 0xaf, 0xbf, 0xed, 0xbf, 0xbf} +}; + +char illegal_pos[2][3] = { + {0xff, 0xfe}, + {0xff, 0xff} +}; + +int main() + { + wchar_t wchar; + int retval; + int i; + + if (!setlocale(LC_CTYPE, "UTF-8")) + { + fprintf(stderr, "Failed to set UTF-8 locale.\n"); + return 1; + } + else + fprintf(stderr, "Set UTF-8 locale.\n"); + + /* 2 Boundary condition test cases */ + /* 2.1 First possible sequence of a certain length */ + retval = mbtowc(&wchar, first[0], MAX_BYTES); + if (retval == 0) + printf("2.1.1: U-%08d \n", wchar); + else + printf("2.1.1: Invalid \n"); + + for (i = 2; i < 7; i++) + { + retval = mbtowc (&wchar, first[i-1], MAX_BYTES); + if (retval == i) + printf("2.1.%d: U-%08x \n", i, wchar); + else + printf("2.1.%d: Invalid \n", i); + } + + /* 2.2 Last possible sequence of a certain length */ + for (i = 1; i < 7; i++) + { + retval = mbtowc (&wchar, last[i-1], MAX_BYTES); + if (retval == i) + printf("2.2.%d: U-%08x \n", i, wchar); + else + printf("2.2.%d: Invalid \n", i); + } + + /* 2.3 Other boundary conditions */ + for (i = 1; i < 6; i++) + { + retval = mbtowc (&wchar, boundary[i-1], MAX_BYTES); + if ((i < 4 && retval == 3) || (i > 3 && retval == 4)) + printf("2.3.%d: U-%08x \n", i, wchar); + else + printf("2.3.%d: Invalid \n", i); + } + + /* 3 Malformed sequences */ + /* 3.1 Unexpected continuation bytes */ + retval = mbtowc (&wchar, continuation_bytes[0], MAX_BYTES); + if (retval == 1) + printf("3.1.1: U-%08x \n", wchar); + else + printf("3.1.1: 1 Invalid \n"); + + retval = mbtowc (&wchar, continuation_bytes[1], MAX_BYTES); + if (retval == 1) + printf("3.1.2: U-%08x \n", wchar); + else + printf("3.1.2: 1 Invalid \n"); + + for(i=2; i< 8; i++) + { + retval = num_invalid(continuation_bytes[i], i); + if (retval == -1) + printf("3.1.%d: Valid Character Found\n", i+1); + else + printf("3.1.%d: %d Invalid \n", i+1, retval); + } + + for(i = 0x80; i < 0xc0; i++) + all_continuation_bytes[i-0x80] = i; + + retval = num_invalid(all_continuation_bytes, 0xc0 - 0x80); + if (retval == -1) + printf("3.1.9: Valid Character Found\n"); + else + printf("3.1.9: %d Invalid \n", retval); + + /* 3.2 Lonely start characters */ + for(i = 0xc0; i < 0xe0; i++) + all_two_byte_seq[i-0xc0] = i; + + retval = num_invalid(all_two_byte_seq, 0xe0 - 0xc0); + if (retval == -1) + printf("3.2.1: Valid Character Found\n"); + else + printf("3.2.1: %d Invalid \n", retval); + + for(i = 0xe0; i < 0xf0; i++) + all_three_byte_seq[i-0xe0] = i; + + retval = num_invalid(all_three_byte_seq, 0xf0 - 0xe0); + if (retval == -1) + printf("3.2.2: Valid Character Found\n"); + else + printf("3.2.2: %d Invalid \n", retval); + + for(i = 0xf0; i < 0xf8; i++) + all_four_byte_seq[i-0xf0] = i; + + retval = num_invalid(all_four_byte_seq, 0xf8 - 0xf0); + if (retval == -1) + printf("3.2.3: Valid Character Found\n"); + else + printf("3.2.3: %d Invalid \n", retval); + + for(i = 0xf8; i < 0xfc; i++) + all_five_byte_seq[i-0xf8] = i; + + retval = num_invalid(all_five_byte_seq, 0xfc - 0xf8); + if (retval == -1) + printf("3.2.4: Valid Character Found\n"); + else + printf("3.2.4: %d Invalid \n", retval); + + for(i = 0xfc; i < 0xfe; i++) + all_six_byte_seq[i-0xfc] = i; + + retval = num_invalid(all_six_byte_seq, 0xfe - 0xfc); + if (retval == -1) + printf("3.2.5: Valid Character Found\n"); + else + printf("3.2.5: %d Invalid \n", retval); + + /* 3.3 Sequences with last continuation byte missing */ + for(i = 1; i < 6; i++) + { + retval = mbtowc(&wchar, incomplete_seq[i-1], i); + if(retval == -1) + printf("3.3.%d: 1 Invalid \n", i); + else + printf("3.3.%d: Valid Character Found\n", i); + } + + for(i = 6; i < 11; i++) + { + retval = mbtowc(&wchar, incomplete_seq[i-1], i - 5); + if(retval == -1) + printf("3.3.%d: 1 Invalid \n", i); + else + printf("3.3.%d: Valid Character Found\n", i); + } + + /* 3.4 Concatenation of incomplete sequences */ + /* This test is excluded because the mbtowc function does not return the + number of bytes read in an invalid multi-byte sequence. */ + + /* 3.5 Impossible bytes */ + retval = mbtowc(&wchar, impossible_bytes[0], 1); + if(retval == -1) + printf("3.5.1: 1 Invalid \n"); + else + printf("3.5.1: Valid Character Found\n"); + + retval = mbtowc(&wchar, impossible_bytes[1], 1); + if(retval == -1) + printf("3.5.2: 1 Invalid \n"); + else + printf("3.5.2: Valid Character Found\n"); + + retval = mbtowc(&wchar, impossible_bytes[2], 4); + if(retval == -1) + printf("3.5.3: 1 Invalid \n"); + else + printf("3.5.3: Valid Character Found\n"); + + /* 4 Overlong sequences */ + /* 4.1 Examples of an overlong ASCII character */ + for(i = 2; i < 7; i++) + { + retval = mbtowc(&wchar, overlong[i-2], i); + if(retval == -1) + printf("4.1.%d: 1 Invalid \n", i-1); + else + printf("4.1.%d: Valid Character Found\n", i-1); + } + + /* 4.2 Maximum overlong sequences */ + for(i = 2; i < 7; i++) + { + retval = mbtowc(&wchar, overlong_max[i-2], i); + if(retval == -1) + printf("4.2.%d: 1 Invalid \n", i-1); + else + printf("4.2.%d: Valid Character Found\n", i-1); + } + + /* 4.3 Overlong representation of the NUL character */ + for(i = 2; i < 7; i++) + { + retval = mbtowc(&wchar, overlong_nul[i-2], i); + if(retval == -1) + printf("4.3.%d: 1 Invalid \n", i-1); + else + printf("4.3.%d: Valid Character Found\n", i-1); + } + + /* 5 Illegal code positions */ + /* 5.1 Single UTF-16 surrogates */ + for (i = 1; i < 8; i++) + { + retval = mbtowc(&wchar, single_surrogates[i-1], 3); + if(retval == -1) + printf("5.1.%d: 1 Invalid \n", i); + else + printf("5.1.%d: Valid Character Found\n", i); + } + + /* 5.2 Paired UTF-16 surrogates */ + for (i = 1; i < 8; i++) + { + retval = mbtowc(&wchar, paired_surrogates[i-1], 6); + if(retval == -1) + printf("5.2.%d: 1 Invalid \n", i); + else + printf("5.2.%d: Valid Character Found\n", i); + } + + /* 5.3 Other illegal code positions */ + retval = mbtowc(&wchar, illegal_pos[0], 3); + if(retval == -1) + printf("5.3.1: 1 Invalid \n"); + else + printf("5.3.1: Valid Character Found\n"); + + retval = mbtowc(&wchar, illegal_pos[1], 3); + if(retval == -1) + printf("5.3.2: 1 Invalid \n"); + else + printf("5.3.2: Valid Character Found\n"); + + return 0; + } + +/* return number of invalid characters in string, + returns -1 if a valid character is found */ +int +num_invalid(const char *s, int len) +{ + int retval = 0; + int i = 0; + int num_inv = 0; + wchar_t wchar; + const char *t; + + t = s; + + for(i=0; i +#include +#include + +#ifndef MAX_1 +#define MAX_1 66000 +#endif + +#define MAX_2 (2 * MAX_1 + MAX_1 / 10) + +void eprintf (int line, char *result, char *expected, int size) +{ + if (size != 0) + printf ("Failure at line %d, result is <%.*s>, should be <%s> of size %d\n", + line, size, result, expected, size); + else + printf ("Failure at line %d, result is <%s>, should be <%s>\n", + line, result, expected); +} + +void mycopy (char *target, char *source, int size) +{ + int i; + + for (i = 0; i < size; ++i) + { + target[i] = source[i]; + } +} + +void myset (char *target, char ch, int size) +{ + int i; + + for (i = 0; i < size; ++i) + { + target[i] = ch; + } +} + +int main() +{ + char target[MAX_1] = "A"; + char first_char; + char second_char; + char array[] = "abcdefghijklmnopqrstuvwxz"; + char array2[] = "0123456789!@#$%^&*("; + char buffer2[MAX_1]; + char buffer3[MAX_1]; + char buffer4[MAX_1]; + char buffer5[MAX_2]; + char buffer6[MAX_2]; + char buffer7[MAX_2]; + char expected[MAX_1]; + char *tmp1, *tmp2, *tmp3, *tmp4, *tmp5, *tmp6, *tmp7; + int i, j, k, x, z, align_test_iterations; + + int test_failed = 0; + + tmp1 = target; + tmp2 = buffer2; + tmp3 = buffer3; + tmp4 = buffer4; + tmp5 = buffer5; + tmp6 = buffer6; + tmp7 = buffer7; + + tmp2[0] = 'Z'; + tmp2[1] = '\0'; + + if (memset (target, 'X', 0) != target || + memcpy (target, "Y", 0) != target || + memmove (target, "K", 0) != target || + strncpy (tmp2, "4", 0) != tmp2 || + strncat (tmp2, "123", 0) != tmp2 || + strcat (target, "") != target) + { + eprintf (__LINE__, target, "A", 0); + test_failed = 1; + } + + if (strcmp (target, "A") || strlen(target) != 1 || memchr (target, 'A', 0) != NULL + || memcmp (target, "J", 0) || strncmp (target, "A", 1) || strncmp (target, "J", 0) || + tmp2[0] != 'Z' || tmp2[1] != '\0') + { + eprintf (__LINE__, target, "A", 0); + test_failed = 1; + } + + tmp2[2] = 'A'; + if (strcpy (target, "") != target || + strncpy (tmp2, "", 4) != tmp2 || + strcat (target, "") != target) + { + eprintf (__LINE__, target, "", 0); + test_failed = 1; + } + + if (target[0] != '\0' || strncmp (target, "", 1) || + memcmp (tmp2, "\0\0\0\0", 4)) + { + eprintf (__LINE__, target, "", 0); + test_failed = 1; + } + + tmp2[2] = 'A'; + if (strncat (tmp2, "1", 3) != tmp2 || + memcmp (tmp2, "1\0A", 3)) + { + eprintf (__LINE__, tmp2, "1\0A", 3); + test_failed = 1; + } + + if (strcpy (tmp3, target) != tmp3 || + strcat (tmp3, "X") != tmp3 || + strncpy (tmp2, "X", 2) != tmp2 || + memset (target, tmp2[0], 1) != target) + { + eprintf (__LINE__, target, "X", 0); + test_failed = 1; + } + + if (strcmp (target, "X") || strlen (target) != 1 || + memchr (target, 'X', 2) != target || + strchr (target, 'X') != target || + memchr (target, 'Y', 2) != NULL || + strchr (target, 'Y') != NULL || + strcmp (tmp3, target) || + strncmp (tmp3, target, 2) || + memcmp (target, "K", 0) || + strncmp (target, tmp3, 3)) + { + eprintf (__LINE__, target, "X", 0); + test_failed = 1; + } + + if (strcpy (tmp3, "Y") != tmp3 || + strcat (tmp3, "Y") != tmp3 || + memset (target, 'Y', 2) != target) + { + eprintf (__LINE__, target, "Y", 0); + test_failed = 1; + } + + target[2] = '\0'; + if (memcmp (target, "YY", 2) || strcmp (target, "YY") || + strlen (target) != 2 || memchr (target, 'Y', 2) != target || + strcmp (tmp3, target) || + strncmp (target, tmp3, 3) || + strncmp (target, tmp3, 4) || + strncmp (target, tmp3, 2) || + strchr (target, 'Y') != target) + { + eprintf (__LINE__, target, "YY", 2); + test_failed = 1; + } + + strcpy (target, "WW"); + if (memcmp (target, "WW", 2) || strcmp (target, "WW") || + strlen (target) != 2 || memchr (target, 'W', 2) != target || + strchr (target, 'W') != target) + { + eprintf (__LINE__, target, "WW", 2); + test_failed = 1; + } + + if (strncpy (target, "XX", 16) != target || + memcmp (target, "XX\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16)) + { + eprintf (__LINE__, target, "XX\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16); + test_failed = 1; + } + + if (strcpy (tmp3, "ZZ") != tmp3 || + strcat (tmp3, "Z") != tmp3 || + memcpy (tmp4, "Z", 2) != tmp4 || + strcat (tmp4, "ZZ") != tmp4 || + memset (target, 'Z', 3) != target) + { + eprintf (__LINE__, target, "ZZZ", 3); + test_failed = 1; + } + + target[3] = '\0'; + tmp5[0] = '\0'; + strncat (tmp5, "123", 2); + if (memcmp (target, "ZZZ", 3) || strcmp (target, "ZZZ") || + strcmp (tmp3, target) || strcmp (tmp4, target) || + strncmp (target, "ZZZ", 4) || strncmp (target, "ZZY", 3) <= 0 || + strncmp ("ZZY", target, 4) >= 0 || + memcmp (tmp5, "12", 3) || + strlen (target) != 3) + { + eprintf (__LINE__, target, "ZZZ", 3); + test_failed = 1; + } + + target[2] = 'K'; + if (memcmp (target, "ZZZ", 2) || strcmp (target, "ZZZ") >= 0 || + memcmp (target, "ZZZ", 3) >= 0 || strlen (target) != 3 || + memchr (target, 'K', 3) != target + 2 || + strncmp (target, "ZZZ", 2) || strncmp (target, "ZZZ", 4) >= 0 || + strchr (target, 'K') != target + 2) + { + eprintf (__LINE__, target, "ZZK", 3); + test_failed = 1; + } + + strcpy (target, "AAA"); + if (memcmp (target, "AAA", 3) || strcmp (target, "AAA") || + strncmp (target, "AAA", 3) || + strlen (target) != 3) + { + eprintf (__LINE__, target, "AAA", 3); + test_failed = 1; + } + + j = 5; + while (j < MAX_1) + { + for (i = j-1; i <= j+1; ++i) + { + /* don't bother checking unaligned data in the larger + sizes since it will waste time without performing additional testing */ + if (i <= 16 * sizeof(long)) + { + align_test_iterations = 2*sizeof(long); + if (i <= 2 * sizeof(long) + 1) + z = 2; + else + z = 2 * sizeof(long); + } + else + { + align_test_iterations = 1; + } + + for (x = 0; x < align_test_iterations; ++x) + { + tmp1 = target + x; + tmp2 = buffer2 + x; + tmp3 = buffer3 + x; + tmp4 = buffer4 + x; + tmp5 = buffer5 + x; + tmp6 = buffer6 + x; + + first_char = array[i % (sizeof(array) - 1)]; + second_char = array2[i % (sizeof(array2) - 1)]; + memset (tmp1, first_char, i); + mycopy (tmp2, tmp1, i); + myset (tmp2 + z, second_char, i - z - 1); + if (memcpy (tmp1 + z, tmp2 + z, i - z - 1) != tmp1 + z) + { + printf ("error at line %d\n", __LINE__); + test_failed = 1; + } + + tmp1[i] = '\0'; + tmp2[i] = '\0'; + if (strcpy (expected, tmp2) != expected) + { + printf ("error at line %d\n", __LINE__); + test_failed = 1; + } + tmp2[i-z] = first_char + 1; + if (memmove (tmp2 + z + 1, tmp2 + z, i - z - 1) != tmp2 + z + 1 || + memset (tmp3, first_char, i) != tmp3) + { + printf ("error at line %d\n", __LINE__); + test_failed = 1; + } + + myset (tmp4, first_char, i); + tmp5[0] = '\0'; + if (strncpy (tmp5, tmp1, i+1) != tmp5 || + strcat (tmp5, tmp1) != tmp5) + { + printf ("error at line %d\n", __LINE__); + test_failed = 1; + } + mycopy (tmp6, tmp1, i); + mycopy (tmp6 + i, tmp1, i + 1); + + tmp7[2*i+z] = second_char; + strcpy (tmp7, tmp1); + + strchr (tmp1, second_char); + + if (memcmp (tmp1, expected, i) || strcmp (tmp1, expected) || + strncmp (tmp1, expected, i) || + strncmp (tmp1, expected, i+1) || + strcmp (tmp1, tmp2) >= 0 || memcmp (tmp1, tmp2, i) >= 0 || + strncmp (tmp1, tmp2, i+1) >= 0 || + strlen (tmp1) != i || memchr (tmp1, first_char, i) != tmp1 || + strchr (tmp1, first_char) != tmp1 || + memchr (tmp1, second_char, i) != tmp1 + z || + strchr (tmp1, second_char) != tmp1 + z || + strcmp (tmp5, tmp6) || + strncat (tmp7, tmp1, i+2) != tmp7 || + strcmp (tmp7, tmp6) || + tmp7[2*i+z] != second_char) + { + eprintf (__LINE__, tmp1, expected, 0); + printf ("x is %d\n",x); + printf ("i is %d\n", i); + printf ("tmp1 is <%p>\n", tmp1); + printf ("tmp5 is <%p> <%s>\n", tmp5, tmp5); + printf ("tmp6 is <%p> <%s>\n", tmp6, tmp6); + test_failed = 1; + } + + for (k = 1; k <= align_test_iterations && k <= i; ++k) + { + if (memcmp (tmp3, tmp4, i - k + 1) != 0 || + strncmp (tmp3, tmp4, i - k + 1) != 0) + { + printf ("Failure at line %d, comparing %.*s with %.*s\n", + __LINE__, i, tmp3, i, tmp4); + test_failed = 1; + } + tmp4[i-k] = first_char + 1; + if (memcmp (tmp3, tmp4, i) >= 0 || + strncmp (tmp3, tmp4, i) >= 0 || + memcmp (tmp4, tmp3, i) <= 0 || + strncmp (tmp4, tmp3, i) <= 0) + { + printf ("Failure at line %d, comparing %.*s with %.*s\n", + __LINE__, i, tmp3, i, tmp4); + test_failed = 1; + } + tmp4[i-k] = first_char; + } + } + } + j = ((2 * j) >> 2) << 2; + } + + if (test_failed) + abort(); + else + exit(0); +} -- cgit v1.1