diff options
author | 2016-05-18 13:18:31 +0300 | |
---|---|---|
committer | 2016-05-18 13:42:15 +0300 | |
commit | 437fd90c0250dee670290f9b714253671a990160 (patch) | |
tree | b871786c360704244a07411c69fb58da9ead4a06 /qemu/roms/ipxe/src/tests/string_test.c | |
parent | 5bbd6fe9b8bab2a93e548c5a53b032d1939eec05 (diff) |
These changes are the raw update to qemu-2.6.
Collission happened in the following patches:
migration: do cleanup operation after completion(738df5b9)
Bug fix.(1750c932f86)
kvmclock: add a new function to update env->tsc.(b52baab2)
The code provided by the patches was already in the upstreamed
version.
Change-Id: I3cc11841a6a76ae20887b2e245710199e1ea7f9a
Signed-off-by: José Pekkarinen <jose.pekkarinen@nokia.com>
Diffstat (limited to 'qemu/roms/ipxe/src/tests/string_test.c')
-rw-r--r-- | qemu/roms/ipxe/src/tests/string_test.c | 142 |
1 files changed, 141 insertions, 1 deletions
diff --git a/qemu/roms/ipxe/src/tests/string_test.c b/qemu/roms/ipxe/src/tests/string_test.c index 3b48d9f3d..4693b5f65 100644 --- a/qemu/roms/ipxe/src/tests/string_test.c +++ b/qemu/roms/ipxe/src/tests/string_test.c @@ -15,9 +15,13 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. + * + * You can also choose to distribute this program under the terms of + * the Unmodified Binary Distribution Licence (as given in the file + * COPYING.UBDL), provided that you have satisfied its requirements. */ -FILE_LICENCE ( GPL2_OR_LATER ); +FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); /** @file * @@ -31,7 +35,10 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include <stdint.h> #include <stdlib.h> +#include <stdio.h> #include <string.h> +#include <strings.h> +#include <ipxe/string.h> #include <ipxe/test.h> /** @@ -63,6 +70,18 @@ static void string_test_exec ( void ) { ok ( *(strchr ( "Testing", 'g' )) == 'g' ); ok ( strchr ( "Testing", 'x' ) == NULL ); + /* Test strrchr() */ + ok ( strrchr ( "", 'a' ) == NULL ); + ok ( *(strrchr ( "Haystack", 'a' )) == 'a' ); + ok ( *(strrchr ( "Haystack", 'k' )) == 'k' ); + ok ( strrchr ( "Haystack", 'x' ) == NULL ); + + /* Test memchr() */ + ok ( memchr ( "", '\0', 0 ) == NULL ); + ok ( *((uint8_t *)memchr ( "post\0null", 'l', 9 )) == 'l' ); + ok ( *((uint8_t *)memchr ( "post\0null", '\0', 9 )) == '\0' ); + ok ( memchr ( "thingy", 'z', 6 ) == NULL ); + /* Test strcmp() */ ok ( strcmp ( "", "" ) == 0 ); ok ( strcmp ( "Hello", "Hello" ) == 0 ); @@ -78,11 +97,31 @@ static void string_test_exec ( void ) { ok ( strncmp ( "Goodbye", "Goodbye world", 32 ) != 0 ); ok ( strncmp ( "Goodbye", "Goodbye world", 7 ) == 0 ); + /* Test strcasecmp() */ + ok ( strcasecmp ( "", "" ) == 0 ); + ok ( strcasecmp ( "Uncle Jack", "Uncle jack" ) == 0 ); + ok ( strcasecmp ( "Uncle Jack", "Uncle" ) != 0 ); + ok ( strcasecmp ( "Uncle", "Uncle Jack" ) != 0 ); + ok ( strcasecmp ( "not", "equal" ) != 0 ); + /* Test memcmp() */ ok ( memcmp ( "", "", 0 ) == 0 ); ok ( memcmp ( "Foo", "Foo", 3 ) == 0 ); ok ( memcmp ( "Foo", "Bar", 3 ) != 0 ); + /* Test strstr() */ + { + const char haystack[] = "find me!"; + char *found; + + found = strstr ( haystack, "find" ); + ok ( found == &haystack[0] ); + found = strstr ( haystack, "me" ); + ok ( found == &haystack[5] ); + found = strstr ( haystack, "me." ); + ok ( found == NULL ); + } + /* Test memset() */ { static uint8_t test[7] = { '>', 1, 1, 1, 1, 1, '<' }; @@ -154,6 +193,107 @@ static void string_test_exec ( void ) { ok ( strcmp ( dup, "hello" ) == 0 ); free ( dup ); } + + /* Test strcpy() */ + { + const char longer[7] = "copyme"; + const char shorter[3] = "hi"; + char dest[7]; + char *copy; + + copy = strcpy ( dest, longer ); + ok ( copy == dest ); + ok ( memcmp ( dest, longer, 7 ) == 0 ); + copy = strcpy ( dest, shorter ); + ok ( copy == dest ); + ok ( memcmp ( dest, shorter, 3 ) == 0 ); + ok ( memcmp ( ( dest + 3 ), ( longer + 3 ), 4 ) == 0 ); + } + + /* Test strncpy() */ + { + const char src[5] = "copy"; + const char orig[8] = { 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' }; + const char zero[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; + char dest[8]; + char *copy; + + memcpy ( dest, orig, sizeof ( dest ) ); + copy = strncpy ( dest, src, 5 ); + ok ( copy == dest ); + ok ( memcmp ( dest, src, 5 ) == 0 ); + ok ( memcmp ( dest + 5, orig + 5, 3 ) == 0 ); + memcpy ( dest, orig, sizeof ( dest ) ); + copy = strncpy ( dest, src, 4 ); + ok ( copy == dest ); + ok ( memcmp ( dest, src, 4 ) == 0 ); + ok ( memcmp ( dest + 4, orig + 4, 4 ) == 0 ); + memcpy ( dest, orig, sizeof ( dest ) ); + copy = strncpy ( dest, src, 8 ); + ok ( copy == dest ); + ok ( memcmp ( dest, src, 5 ) == 0 ); + ok ( memcmp ( dest + 5, zero + 5, 3 ) == 0 ); + memcpy ( dest, orig, sizeof ( dest ) ); + copy = strncpy ( dest, "", 8 ); + ok ( copy == dest ); + ok ( memcmp ( dest, zero, 8 ) == 0 ); + } + + /* Test strcat() */ + { + char buf[16] = "append"; + char *dest; + + dest = strcat ( buf, " this" ); + ok ( dest == buf ); + ok ( strcmp ( buf, "append this" ) == 0 ); + } + + /* Test digit_value() */ + { + unsigned int i; + char buf[2]; + for ( i = 0 ; i < 16 ; i++ ) { + snprintf ( buf, sizeof ( buf ), "%x", i ); + ok ( digit_value ( buf[0] ) == i ); + snprintf ( buf, sizeof ( buf ), "%X", i ); + ok ( digit_value ( buf[0] ) == i ); + } + ok ( digit_value ( 0 ) >= 16 ); + ok ( digit_value ( 9 ) >= 16 ); + ok ( digit_value ( '0' - 1 ) >= 16 ); + ok ( digit_value ( '9' + 1 ) >= 16 ); + ok ( digit_value ( 'A' - 1 ) >= 16 ); + ok ( digit_value ( 'F' + 1 ) >= 16 ); + ok ( digit_value ( 'a' - 1 ) >= 16 ); + ok ( digit_value ( 'f' + 1 ) >= 16 ); + } + + /* Test strtoul() */ + ok ( strtoul ( "12345", NULL, 0 ) == 12345UL ); + ok ( strtoul ( " 741", NULL, 10 ) == 741UL ); + ok ( strtoul ( " 555a", NULL, 0 ) == 555UL ); + ok ( strtoul ( " 555a", NULL, 16 ) == 0x555aUL ); + ok ( strtoul ( "-12", NULL, 0 ) == -12UL ); + ok ( strtoul ( "+3", NULL, 0 ) == 3UL ); + ok ( strtoul ( "721", NULL, 0 ) == 721UL ); + ok ( strtoul ( "721", NULL, 8 ) == 0721UL ); + ok ( strtoul ( "0721", NULL, 0 ) == 0721UL ); + ok ( strtoul ( "", NULL, 0 ) == 0UL ); + ok ( strtoul ( "\t0xcAfe", NULL, 0 ) == 0xcafeUL ); + ok ( strtoul ( "0xffffffff", NULL, 0 ) == 0xffffffffUL ); + { + static const char string[] = "123aHa.world"; + char *endp; + ok ( strtoul ( string, &endp, 0 ) == 123UL ); + ok ( endp == &string[3] ); + ok ( strtoul ( string, &endp, 16 ) == 0x123aUL ); + ok ( endp == &string[4] ); + ok ( strtoul ( string, &endp, 26 ) == + ( ( ( ( ( 1 * 26 + 2 ) * 26 + 3 ) * 26 + 10 ) * 26 + + 17 ) * 26 + 10 ) ); + ok ( endp == &string[6] ); + } } /** String self-test */ |