diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-01-17 16:55:25 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-01-17 17:44:48 -0800 |
| commit | eb3b131db73610274a41f04d8fd6b7cf879cc016 (patch) | |
| tree | 957ed45ef5fd8919bb2a65f9827b1bc8695b6f6c /tests | |
| parent | ac9236de0bc9ed3000947ef6eeeae1cd874d3071 (diff) | |
| download | nng-eb3b131db73610274a41f04d8fd6b7cf879cc016.tar.gz nng-eb3b131db73610274a41f04d8fd6b7cf879cc016.tar.bz2 nng-eb3b131db73610274a41f04d8fd6b7cf879cc016.zip | |
Added dynamic ID generation & management for idhash tables.
This will allow us to use idhash tables to manage id handles a bit more
flexibly. For example, sockets, pipe IDs, etc. can all be generated, and
we can use hash tables to ensure that values do not collide.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/idhash.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/tests/idhash.c b/tests/idhash.c index fb240078..b05b4b2f 100644 --- a/tests/idhash.c +++ b/tests/idhash.c @@ -7,9 +7,9 @@ // found online at https://opensource.org/licenses/MIT. // -#include "core/idhash.c" #include "convey.h" #include "stubs.h" +#include "core/idhash.c" Main({ Test("General ID Hash", { @@ -133,4 +133,37 @@ Main({ }) }) }) + + Test("Dynamic ID generation", { + Convey("Given a small ID hash", { + nni_idhash *h; + int expect[5]; + uint32_t id; + int i; + So(nni_idhash_create(&h) == 0); + Reset({ + nni_idhash_destroy(h); + }) + nni_idhash_set_limits(h, 10, 13, 10); + So(1); + Convey("We can fill the table", { + for (i = 0; i < 4; i++) { + So(nni_idhash_alloc(h, &id, &expect[i]) == 0); + So(id == (i + 10)); + } + Convey("Adding another fails", { + So(nni_idhash_alloc(h, &id, &expect[5]) == NNG_ENOMEM); + }) + Convey("Deleting one lets us reinsert", { + nni_idhash_remove(h, 11); + So(nni_idhash_alloc(h, &id, &expect[5]) == 0); + So(id == 11); + }) + }) + Convey("We cannot insert bogus values", { + So(nni_idhash_insert(h, 1, &expect[0]) == NNG_EINVAL); + So(nni_idhash_insert(h, 100, &expect[0]) == NNG_EINVAL); + }) + }) + }) }) |
