diff options
Diffstat (limited to 'gl/tests')
-rw-r--r-- | gl/tests/test-di-set.c | 31 | ||||
-rw-r--r-- | gl/tests/test-ino-map.c (renamed from gl/tests/test-dev-map.c) | 34 |
2 files changed, 22 insertions, 43 deletions
diff --git a/gl/tests/test-di-set.c b/gl/tests/test-di-set.c index 4d5823ed8..e5fb6cb21 100644 --- a/gl/tests/test-di-set.c +++ b/gl/tests/test-di-set.c @@ -1,4 +1,4 @@ -/* Test the dev-map module. +/* Test the di-set module. Copyright (C) 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -36,41 +36,21 @@ #include "di-set.h" -/* FIXME: ugly duplication of code from di-set.c */ -#define N_DEV_BITS_4 5 -#define N_INO_BITS_4 (32 - N_DEV_BITS_4 - 2 - 1) - -#define N_DEV_BITS_8 8 -#define N_INO_BITS_8 (64 - N_DEV_BITS_8 - 2 - 1) - int main (void) { /* set_program_name (argv[0]); placate overzealous "syntax-check" test. */ - size_t initial_size = 61; - /* "real" code might prefer to avoid the allocation here, simply - declaring "struct di_set_state dis;", do a global substitution, - s/\<dis\>/\&dis/, and remove the final free. */ - struct di_set_state *dis = malloc (sizeof *dis); + struct di_set *dis = di_set_alloc (); ASSERT (dis); - ASSERT (di_set_init (dis, initial_size) == 0); - - struct di_ent *di_ent; - ASSERT (di_ent_create (dis, 1, 1, &di_ent) == 0); - ASSERT (di_ent_create (dis, 1 << N_DEV_BITS_4, 1, &di_ent) == 0); - ASSERT (di_ent_create (dis, 1, 1 << N_INO_BITS_4, &di_ent) == 0); - ASSERT (di_ent_create (dis, 1, - (uint64_t) 1 << N_INO_BITS_8, &di_ent) == 0); - free (di_ent); ASSERT (di_set_insert (dis, 2, 5) == 1); /* first insertion succeeds */ ASSERT (di_set_insert (dis, 2, 5) == 0); /* duplicate fails */ ASSERT (di_set_insert (dis, 3, 5) == 1); /* diff dev, duplicate inode is ok */ ASSERT (di_set_insert (dis, 2, 8) == 1); /* same dev, different inode is ok */ - /* very large inode number */ - ASSERT (di_set_insert (dis, 5, (uint64_t) 1 << 63) == 1); - ASSERT (di_set_insert (dis, 5, (uint64_t) 1 << 63) == 0); /* dup */ + /* very large (or negative) inode number */ + ASSERT (di_set_insert (dis, 5, (ino_t) -1) == 1); + ASSERT (di_set_insert (dis, 5, (ino_t) -1) == 0); /* dup */ unsigned int i; for (i = 0; i < 3000; i++) @@ -79,7 +59,6 @@ main (void) ASSERT (di_set_insert (dis, 9, i) == 0); /* duplicate fails */ di_set_free (dis); - free (dis); return 0; } diff --git a/gl/tests/test-dev-map.c b/gl/tests/test-ino-map.c index 98ba6301b..2b44602e2 100644 --- a/gl/tests/test-dev-map.c +++ b/gl/tests/test-ino-map.c @@ -1,4 +1,4 @@ -/* Test the dev-map module. +/* Test the ino-map module. Copyright (C) 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -34,30 +34,30 @@ } \ while (0) -#include "dev-map.h" - -/* Risky: this is also defined in di-set.c; they should match. */ -#define N_DEV_BITS_4 5 +#include "ino-map.h" int main () { /* set_program_name (argv[0]); placate overzealous "syntax-check" test. */ - struct dev_map dev_map; - ASSERT (dev_map_init (&dev_map) == 0); - - ASSERT (dev_map_insert (&dev_map, 42) == 0); - ASSERT (dev_map_insert (&dev_map, 42) == 0); - ASSERT (dev_map_insert (&dev_map, 398) == 1); - ASSERT (dev_map_insert (&dev_map, 398) == 1); - - int32_t i; - for (i = 0; i < (1 << N_DEV_BITS_4); i++) + enum { INO_MAP_INIT = 123 }; + struct ino_map *ino_map = ino_map_alloc (INO_MAP_INIT); + ASSERT (ino_map != NULL); + + ASSERT (ino_map_insert (ino_map, 42) == INO_MAP_INIT); + ASSERT (ino_map_insert (ino_map, 42) == INO_MAP_INIT); + ASSERT (ino_map_insert (ino_map, 398) == INO_MAP_INIT + 1); + ASSERT (ino_map_insert (ino_map, 398) == INO_MAP_INIT + 1); + ASSERT (ino_map_insert (ino_map, 0) == INO_MAP_INIT + 2); + ASSERT (ino_map_insert (ino_map, 0) == INO_MAP_INIT + 2); + + int i; + for (i = 0; i < 100; i++) { - ASSERT (dev_map_insert (&dev_map, 10000+i) == 2+i); + ASSERT (ino_map_insert (ino_map, 10000 + i) == INO_MAP_INIT + 3 + i); } - dev_map_free (&dev_map); + ino_map_free (ino_map); return 0; } |