]> git.ozlabs.org Git - ccan/blobdiff - ccan/intmap/test/run-order.c
base64: fix for unsigned chars (e.g. ARM).
[ccan] / ccan / intmap / test / run-order.c
index 0f8168d7fde54b3a0c3ec64cf790a162dadb148d..d945a4a86f5a6e35e5a6e5ad3c29956a9935b3fa 100644 (file)
@@ -7,6 +7,16 @@
 typedef UINTMAP(unsigned int *) umap;
 typedef SINTMAP(int *) smap;
 
+static bool uint_iterate_check(intmap_index_t i, unsigned int *v, int64_t *prev)
+{
+       if ((int64_t)i <= *prev)
+               return false;
+       if (*v != i)
+               return false;
+       *prev = i;
+       return true;
+}
+
 static bool check_umap(const umap *map)
 {
        /* This is a larger type than unsigned, and allows negative */
@@ -25,7 +35,35 @@ static bool check_umap(const umap *map)
                prev = i;
                last = (uintmap_last(map, &last_idx) == v);
        }
-       return last;
+
+       if (!last)
+               return false;
+
+       prev = INT_MAX;
+       for (v = uintmap_last(map, &i); v; v = uintmap_before(map, &i)) {
+               if ((int64_t)i >= prev)
+                       return false;
+               if (*v != i)
+                       return false;
+               prev = i;
+               last = (uintmap_first(map, &last_idx) == v);
+       }
+
+       if (!last)
+               return false;
+
+       prev = -1;
+       return uintmap_iterate(map, uint_iterate_check, &prev);
+}
+
+static bool sint_iterate_check(sintmap_index_t i, int *v, int64_t *prev)
+{
+       if (i <= *prev)
+               return false;
+       if (*v != i)
+               return false;
+       *prev = i;
+       return true;
 }
 
 static bool check_smap(const smap *map)
@@ -45,7 +83,24 @@ static bool check_smap(const smap *map)
                last = (sintmap_last(map, &last_idx) == v);
                prev = i;
        }
-       return last;
+
+       if (!last)
+               return false;
+
+       prev = 0x80000001ULL;
+       for (v = sintmap_last(map, &i); v; v = sintmap_before(map, &i)) {
+               if (i >= prev)
+                       return false;
+               if (*v != i)
+                       return false;
+               prev = i;
+               last = (sintmap_first(map, &last_idx) == v);
+       }
+       if (!last)
+               return false;
+
+       prev = -1;
+       return sintmap_iterate(map, sint_iterate_check, &prev);
 }
 
 int main(void)