apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject svn commit: r591165 - /apr/apr/branches/1.2.x/test/testhash.c
Date Thu, 01 Nov 2007 23:02:28 GMT
Author: wrowe
Date: Thu Nov  1 16:02:27 2007
New Revision: 591165

URL: http://svn.apache.org/viewvc?rev=591165&view=rev
Log:
Broken on EBCDIC platforms at a minimum, perhaps others.

Previous testhash.c comments indicate an underlying problem:

  "I don't know why these are out of order, but they are. I would probably
  consider this a bug, but others should comment."

The hash iterator functions do not promise/attempt any ordering.
Alphabetically qsort all the dumped hashes using strcmp to provide
a testable result set. 

(wrowe adds; I thought everyone knew better than to use try to
get ordered results out of hashes ;-)

Submitted by: David Jones <oscaremma gmail.com>
Backports: 591164

Modified:
    apr/apr/branches/1.2.x/test/testhash.c

Modified: apr/apr/branches/1.2.x/test/testhash.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.2.x/test/testhash.c?rev=591165&r1=591164&r2=591165&view=diff
==============================================================================
--- apr/apr/branches/1.2.x/test/testhash.c (original)
+++ apr/apr/branches/1.2.x/test/testhash.c Thu Nov  1 16:02:27 2007
@@ -21,22 +21,40 @@
 #include "apr_pools.h"
 #include "apr_hash.h"
 
-static void dump_hash(apr_pool_t *p, apr_hash_t *h, char *str) 
+#define MAX_LTH 256
+#define MAX_DEPTH 11
+
+static int comp_string(const void *str1, const void *str2)
+{
+    return strcmp(str1,str2);
+}
+
+static void dump_hash(apr_pool_t *p, apr_hash_t *h, char str[][MAX_LTH]) 
 {
     apr_hash_index_t *hi;
     char *val, *key;
     apr_ssize_t len;
     int i = 0;
 
-    str[0] = '\0';
-
     for (hi = apr_hash_first(p, h); hi; hi = apr_hash_next(hi)) {
         apr_hash_this(hi,(void*) &key, &len, (void*) &val);
-        apr_snprintf(str, 8196, "%sKey %s (%" APR_SSIZE_T_FMT ") Value %s\n", 
-                     str, key, len, val);
+        str[i][0]='\0';
+        apr_snprintf(str[i], MAX_LTH, "%sKey %s (%" APR_SSIZE_T_FMT ") Value %s\n",
+                 str[i], key, len, val);
         i++;
     }
-    apr_snprintf(str, 8196, "%s#entries %d\n", str, i);
+    str[i][0]='\0';
+    apr_snprintf(str[i], MAX_LTH, "%s#entries %d\n", str[i], i);
+
+    /* Sort the result strings so that they can be checked for expected results easily,
+     * without having to worry about platform quirks
+     */
+    qsort(
+        str, /* Pointer to elements */
+        i,   /* number of elements */
+        MAX_LTH, /* size of one element */
+        comp_string /* Pointer to comparison routine */
+    );
 }
 
 static void sum_hash(apr_pool_t *p, apr_hash_t *h, int *pcount, int *keySum, int *valSum)

@@ -159,7 +177,7 @@
 static void hash_traverse(abts_case *tc, void *data)
 {
     apr_hash_t *h;
-    char str[8196];
+    char StrArray[MAX_DEPTH][MAX_LTH];
 
     h = apr_hash_make(p);
     ABTS_PTR_NOTNULL(tc, h);
@@ -174,15 +192,16 @@
     apr_hash_set(h, "SAME2", APR_HASH_KEY_STRING, "same");
     apr_hash_set(h, "OVERWRITE", APR_HASH_KEY_STRING, "Overwrite key");
 
-    dump_hash(p, h, str);
-    ABTS_STR_EQUAL(tc, "Key FOO1 (4) Value bar1\n"
-                          "Key FOO2 (4) Value bar2\n"
-                          "Key OVERWRITE (9) Value Overwrite key\n"
-                          "Key FOO3 (4) Value bar3\n"
-                          "Key SAME1 (5) Value same\n"
-                          "Key FOO4 (4) Value bar4\n"
-                          "Key SAME2 (5) Value same\n"
-                          "#entries 7\n", str);
+    dump_hash(p, h, StrArray);
+
+    ABTS_STR_EQUAL(tc, "Key FOO1 (4) Value bar1\n", StrArray[0]);
+    ABTS_STR_EQUAL(tc, "Key FOO2 (4) Value bar2\n", StrArray[1]);
+    ABTS_STR_EQUAL(tc, "Key FOO3 (4) Value bar3\n", StrArray[2]);
+    ABTS_STR_EQUAL(tc, "Key FOO4 (4) Value bar4\n", StrArray[3]);
+    ABTS_STR_EQUAL(tc, "Key OVERWRITE (9) Value Overwrite key\n", StrArray[4]);
+    ABTS_STR_EQUAL(tc, "Key SAME1 (5) Value same\n", StrArray[5]);
+    ABTS_STR_EQUAL(tc, "Key SAME2 (5) Value same\n", StrArray[6]);
+    ABTS_STR_EQUAL(tc, "#entries 7\n", StrArray[7]);
 }
 
 /* This is kind of a hack, but I am just keeping an existing test.  This is
@@ -296,7 +315,7 @@
     apr_hash_t *overlay = NULL;
     apr_hash_t *result = NULL;
     int count;
-    char str[8196];
+    char StrArray[MAX_DEPTH][MAX_LTH];
 
     base = apr_hash_make(p);
     overlay = apr_hash_make(p);
@@ -314,13 +333,14 @@
     count = apr_hash_count(result);
     ABTS_INT_EQUAL(tc, 5, count);
 
-    dump_hash(p, result, str);
-    ABTS_STR_EQUAL(tc, "Key key1 (4) Value value1\n"
-                          "Key key2 (4) Value value2\n"
-                          "Key key3 (4) Value value3\n"
-                          "Key key4 (4) Value value4\n"
-                          "Key key5 (4) Value value5\n"
-                          "#entries 5\n", str);
+    dump_hash(p, result, StrArray);
+
+    ABTS_STR_EQUAL(tc, "Key key1 (4) Value value1\n", StrArray[0]);
+    ABTS_STR_EQUAL(tc, "Key key2 (4) Value value2\n", StrArray[1]);
+    ABTS_STR_EQUAL(tc, "Key key3 (4) Value value3\n", StrArray[2]);
+    ABTS_STR_EQUAL(tc, "Key key4 (4) Value value4\n", StrArray[3]);
+    ABTS_STR_EQUAL(tc, "Key key5 (4) Value value5\n", StrArray[4]);
+    ABTS_STR_EQUAL(tc, "#entries 5\n", StrArray[5]);
 }
 
 static void overlay_2unique(abts_case *tc, void *data)
@@ -329,7 +349,7 @@
     apr_hash_t *overlay = NULL;
     apr_hash_t *result = NULL;
     int count;
-    char str[8196];
+    char StrArray[MAX_DEPTH][MAX_LTH];
 
     base = apr_hash_make(p);
     overlay = apr_hash_make(p);
@@ -353,21 +373,19 @@
     count = apr_hash_count(result);
     ABTS_INT_EQUAL(tc, 10, count);
 
-    dump_hash(p, result, str);
-    /* I don't know why these are out of order, but they are.  I would probably
-     * consider this a bug, but others should comment.
-     */
-    ABTS_STR_EQUAL(tc, "Key base5 (5) Value value5\n"
-                          "Key overlay1 (8) Value value1\n"
-                          "Key overlay2 (8) Value value2\n"
-                          "Key overlay3 (8) Value value3\n"
-                          "Key overlay4 (8) Value value4\n"
-                          "Key overlay5 (8) Value value5\n"
-                          "Key base1 (5) Value value1\n"
-                          "Key base2 (5) Value value2\n"
-                          "Key base3 (5) Value value3\n"
-                          "Key base4 (5) Value value4\n"
-                          "#entries 10\n", str);
+    dump_hash(p, result, StrArray);
+
+    ABTS_STR_EQUAL(tc, "Key base1 (5) Value value1\n", StrArray[0]);
+    ABTS_STR_EQUAL(tc, "Key base2 (5) Value value2\n", StrArray[1]);
+    ABTS_STR_EQUAL(tc, "Key base3 (5) Value value3\n", StrArray[2]);
+    ABTS_STR_EQUAL(tc, "Key base4 (5) Value value4\n", StrArray[3]);
+    ABTS_STR_EQUAL(tc, "Key base5 (5) Value value5\n", StrArray[4]);
+    ABTS_STR_EQUAL(tc, "Key overlay1 (8) Value value1\n", StrArray[5]);
+    ABTS_STR_EQUAL(tc, "Key overlay2 (8) Value value2\n", StrArray[6]);
+    ABTS_STR_EQUAL(tc, "Key overlay3 (8) Value value3\n", StrArray[7]);
+    ABTS_STR_EQUAL(tc, "Key overlay4 (8) Value value4\n", StrArray[8]);
+    ABTS_STR_EQUAL(tc, "Key overlay5 (8) Value value5\n", StrArray[9]);
+    ABTS_STR_EQUAL(tc, "#entries 10\n", StrArray[10]);
 }
 
 static void overlay_same(abts_case *tc, void *data)
@@ -375,7 +393,7 @@
     apr_hash_t *base = NULL;
     apr_hash_t *result = NULL;
     int count;
-    char str[8196];
+    char StrArray[MAX_DEPTH][MAX_LTH];
 
     base = apr_hash_make(p);
     ABTS_PTR_NOTNULL(tc, base);
@@ -391,16 +409,14 @@
     count = apr_hash_count(result);
     ABTS_INT_EQUAL(tc, 5, count);
 
-    dump_hash(p, result, str);
-    /* I don't know why these are out of order, but they are.  I would probably
-     * consider this a bug, but others should comment.
-     */
-    ABTS_STR_EQUAL(tc, "Key base5 (5) Value value5\n"
-                          "Key base1 (5) Value value1\n"
-                          "Key base2 (5) Value value2\n"
-                          "Key base3 (5) Value value3\n"
-                          "Key base4 (5) Value value4\n"
-                          "#entries 5\n", str);
+    dump_hash(p, result, StrArray);
+
+    ABTS_STR_EQUAL(tc, "Key base1 (5) Value value1\n", StrArray[0]);
+    ABTS_STR_EQUAL(tc, "Key base2 (5) Value value2\n", StrArray[1]);
+    ABTS_STR_EQUAL(tc, "Key base3 (5) Value value3\n", StrArray[2]);
+    ABTS_STR_EQUAL(tc, "Key base4 (5) Value value4\n", StrArray[3]);
+    ABTS_STR_EQUAL(tc, "Key base5 (5) Value value5\n", StrArray[4]);
+    ABTS_STR_EQUAL(tc, "#entries 5\n", StrArray[5]);
 }
 
 abts_suite *testhash(abts_suite *suite)



Mime
View raw message