From 7d448be97ad45a32e1ef68dd3f1f472d01def082 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 1 Nov 2015 23:45:06 +0100 Subject: [PATCH] Rectify TypedCounter_test fixture -- Type-IDs are not stable Hehe... with GenNode, we started to use these global Type-IDs to generate unique Names for unnamed Children in a diff::Record. This means, when running in the test-suite, the TypeID for 'short' and 'long' are likely to be allready allocated, so our Test can not not observe the allocateion, nor is it sensible to assume fixed numbers for these Type-IDs. Instead, we create two local types right within the test function, to force generation of new unique type-IDs, which we can observe --- tests/basics/typed-counter-test.cpp | 42 +++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/tests/basics/typed-counter-test.cpp b/tests/basics/typed-counter-test.cpp index 72fd45f3e..b34231e5d 100644 --- a/tests/basics/typed-counter-test.cpp +++ b/tests/basics/typed-counter-test.cpp @@ -326,22 +326,42 @@ namespace test{ CHECK (0==myCounter.size()); CHECK (0 == myCounter.get()); - CHECK (1 == myCounter.size()); + CHECK (0 < myCounter.size()); + // probably greater than 1; + // other parts of the application allocate type-IDs as well - CHECK (0 == myCounter.get()); - CHECK (2 == myCounter.size()); + // now allocate a counter for a type not seen yet + struct X { }; + struct U { }; - CHECK (-1 == myCounter.dec()); - CHECK (-2 == myCounter.dec()); - CHECK (+1 == myCounter.inc()); + CHECK (0 == myCounter.get()); + size_t sX = myCounter.size(); - CHECK (-2 == myCounter.get()); - CHECK (+1 == myCounter.get()); + CHECK (0 == myCounter.get()); + CHECK (sX + 1 == myCounter.size()); + CHECK (0 == myCounter.get()); + CHECK (sX + 1 == myCounter.size()); + CHECK (-1 == myCounter.dec()); + CHECK (-2 == myCounter.dec()); + CHECK (+1 == myCounter.inc()); - CHECK (1 == TypedContext::ID::get()); - CHECK (2 == TypedContext::ID::get()); - CHECK (2 == myCounter.size()); + CHECK (-2 == myCounter.get()); + CHECK (+1 == myCounter.get()); + + // each new type has gotten a new "slot" (i.e. a distinct type-ID) + IxID typeID_short = TypedContext::ID::get(); + IxID typeID_X = TypedContext::ID::get(); + IxID typeID_U = TypedContext::ID::get(); + + CHECK (0 < typeID_short); + CHECK (0 < typeID_X); + CHECK (0 < typeID_U); + CHECK (typeID_short < typeID_X); + CHECK (typeID_X < typeID_U); + // type-IDs are allocated in the order of first usage + + CHECK (sX + 1 == myCounter.size()); }