X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tests%2Flibpspp%2Fstringi-map-test.c;h=eaf4102bb15341e6eb8c70c8bc961d4397027175;hb=8d33786b32ea7f1d709c33d5a7c2c442fbeaafff;hp=a8dd9dd6b7068049a377a8f56c23b4282262a58a;hpb=6562532a8aa0e0eaee444c6270d555a5d6a734cf;p=pspp diff --git a/tests/libpspp/stringi-map-test.c b/tests/libpspp/stringi-map-test.c index a8dd9dd6b7..eaf4102bb1 100644 --- a/tests/libpspp/stringi-map-test.c +++ b/tests/libpspp/stringi-map-test.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 2007, 2008, 2009, 2010, 2012, 2014 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 @@ -39,6 +39,7 @@ #include "libpspp/hash-functions.h" #include "libpspp/compiler.h" +#include "libpspp/i18n.h" #include "libpspp/str.h" #include "libpspp/string-set.h" #include "libpspp/stringi-set.h" @@ -68,58 +69,6 @@ check_func (bool ok, int line) terminates. */ #define check(EXPR) check_func ((EXPR), __LINE__) -/* Prints a message about memory exhaustion and exits with a - failure code. */ -static void -xalloc_die (void) -{ - printf ("virtual memory exhausted\n"); - exit (EXIT_FAILURE); -} - -static void *xmalloc (size_t n) MALLOC_LIKE; -static void *xnmalloc (size_t n, size_t m) MALLOC_LIKE; -static void *xmemdup (const void *p, size_t n) MALLOC_LIKE; - -/* Allocates and returns N bytes of memory. */ -static void * -xmalloc (size_t n) -{ - if (n != 0) - { - void *p = malloc (n); - if (p == NULL) - xalloc_die (); - - return p; - } - else - return NULL; -} - -static void * -xmemdup (const void *p, size_t n) -{ - void *q = xmalloc (n); - memcpy (q, p, n); - return q; -} - -/* Clone STRING. */ -static char * -xstrdup (const char *string) -{ - return xmemdup (string, strlen (string) + 1); -} - -/* Allocates and returns N * M bytes of memory. */ -static void * -xnmalloc (size_t n, size_t m) -{ - if ((size_t) -1 / m <= n) - xalloc_die (); - return xmalloc (n * m); -} /* Support routines. */ @@ -144,7 +93,7 @@ get_string (int idx) if (*s == NULL) { *s = xmalloc (16); - str_format_26adic (idx + 1, *s, 16); + str_format_26adic (idx + 1, true, *s, 16); } return *s; } @@ -274,9 +223,9 @@ check_map_contains (struct stringi_map *map, check (stringi_map_contains (map, key)); - node = stringi_map_find_node (map, key); + node = stringi_map_find_node (map, key, strlen (key)); check (node != NULL); - check (!strcasecmp (key, stringi_map_node_get_key (node))); + check (!utf8_strcasecmp (key, stringi_map_node_get_key (node))); check (!strcmp (value, stringi_map_node_get_value (node))); check (node == stringi_map_insert (map, key, "012")); @@ -322,7 +271,7 @@ check_stringi_map (struct stringi_map *map, const int data[], size_t cnt) check (!stringi_map_contains (map, "xxx")); check (stringi_map_find (map, "0") == NULL); - check (stringi_map_find_node (map, "") == NULL); + check (stringi_map_find_node (map, "", 0) == NULL); check (!stringi_map_delete (map, "xyz")); if (cnt == 0) @@ -740,11 +689,12 @@ node_swap_value_cb (struct stringi_map *map, int data[], int n) for (i = 0; i < n; i++) { + const char *key = make_key (data[i]); const char *value = make_value (data[i]); struct stringi_map_node *node; char *old_value; - node = stringi_map_find_node (map, make_key (data[i])); + node = stringi_map_find_node (map, key, strlen (key)); check (node != NULL); check (!strcmp (stringi_map_node_get_value (node), value)); data[i] = (data[i] & KEY_MASK) | random_value (i, 15);