]> git.ozlabs.org Git - ccan/blobdiff - ccan/intmap/test/run-order-smallsize.c
base64: fix for unsigned chars (e.g. ARM).
[ccan] / ccan / intmap / test / run-order-smallsize.c
index 3633180ea93880b337016582277aaf8af2f8ab85..8121f27697fcda19ad617112070758169ce7643e 100644 (file)
@@ -14,10 +14,20 @@ static bool check_umap(const umap *map)
 {
        /* This is a larger type than unsigned, and allows negative */
        int64_t prev;
-       intmap_index_t i;
+       intmap_index_t i, last_idx;
        uint8_t *v;
+       bool last = true;
 
        /* Must be in order, must contain value. */
+       prev = 256;
+       for (v = uintmap_last(map, &i); v; v = uintmap_before(map, &i)) {
+               if (i >= prev)
+                       return false;
+               if (*v != i)
+                       return false;
+               prev = i;
+       }
+
        prev = -1;
        for (v = uintmap_first(map, &i); v; v = uintmap_after(map, &i)) {
                if (i <= prev)
@@ -25,18 +35,29 @@ static bool check_umap(const umap *map)
                if (*v != i)
                        return false;
                prev = i;
+               last = (uintmap_last(map, &last_idx) == v);
        }
-       return true;
+       return last;
 }
 
 static bool check_smap(const smap *map)
 {
        /* This is a larger type than int, and allows negative */
        int64_t prev;
-       sintmap_index_t i;
+       sintmap_index_t i, last_idx;
        int8_t *v;
+       bool last = true;
 
        /* Must be in order, must contain value. */
+       prev = 0x80000000ULL;
+       for (v = sintmap_last(map, &i); v; v = sintmap_before(map, &i)) {
+               if (i >= prev)
+                       return false;
+               if (*v != i)
+                       return false;
+               prev = i;
+       }
+
        prev = -0x80000001ULL;
        for (v = sintmap_first(map, &i); v; v = sintmap_after(map, &i)) {
                if (i <= prev)
@@ -44,11 +65,12 @@ static bool check_smap(const smap *map)
                if (*v != i)
                        return false;
                prev = i;
+               last = (sintmap_last(map, &last_idx) == v);
        }
-       return true;
+       return last;
 }
 
-int main(void)
+int main(int argc, char *argv[])
 {
        umap umap;
        smap smap;
@@ -60,6 +82,9 @@ int main(void)
        uintmap_init(&umap);
        sintmap_init(&smap);
 
+       if (argc > 1)
+               srandom(atoi(argv[1]));
+
        for (i = 0; i < NUM; i++) {
                urandoms[i] = random();
                srandoms[i] = random();