From 5e7f81c11b57b65bfd96af244b4319d8a9826ace Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Sat, 16 May 2015 02:36:45 +0300 Subject: [PATCH] Fixed Multiset tests --- libuavcan/test/util/multiset.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/libuavcan/test/util/multiset.cpp b/libuavcan/test/util/multiset.cpp index 21f74500cd..f89f61fd0a 100644 --- a/libuavcan/test/util/multiset.cpp +++ b/libuavcan/test/util/multiset.cpp @@ -156,15 +156,14 @@ TEST(Multiset, NoStatic) { using uavcan::Multiset; - uavcan::PoolAllocator<1024, 128> pool; // Large enough to keep everything + static const int POOL_BLOCKS = 3; + uavcan::PoolAllocator pool; uavcan::PoolManager<2> poolmgr; poolmgr.addPool(&pool); typedef Multiset MultisetType; std::auto_ptr mset(new MultisetType(poolmgr)); - ASSERT_LE(2, MultisetType::NumItemsPerDynamicChunk); - // Empty mset->removeFirst("foo"); ASSERT_EQ(0, pool.getNumUsedBlocks()); @@ -173,15 +172,17 @@ TEST(Multiset, NoStatic) // Insertion ASSERT_EQ("a", *mset->add("a")); ASSERT_EQ("b", *mset->add("b")); - ASSERT_EQ(1, pool.getNumUsedBlocks()); + ASSERT_LE(1, pool.getNumUsedBlocks()); ASSERT_EQ(0, mset->getNumStaticItems()); ASSERT_EQ(2, mset->getNumDynamicItems()); - // Ordering +#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11 + // Only C++11 because C++03 uses one entry per pool block which breaks ordering ASSERT_EQ("a", *mset->getByIndex(0)); ASSERT_EQ("b", *mset->getByIndex(1)); ASSERT_FALSE(mset->getByIndex(3)); ASSERT_FALSE(mset->getByIndex(1000)); +#endif } @@ -189,15 +190,14 @@ TEST(Multiset, PrimitiveKey) { using uavcan::Multiset; - uavcan::PoolAllocator<1024, 128> pool; // Large enough to keep everything + static const int POOL_BLOCKS = 3; + uavcan::PoolAllocator pool; uavcan::PoolManager<2> poolmgr; poolmgr.addPool(&pool); typedef Multiset MultisetType; std::auto_ptr mset(new MultisetType(poolmgr)); - ASSERT_LE(2, MultisetType::NumItemsPerDynamicChunk); - // Empty mset->removeFirst(8); ASSERT_EQ(0, pool.getNumUsedBlocks()); @@ -213,11 +213,13 @@ TEST(Multiset, PrimitiveKey) ASSERT_EQ(4, *mset->add(4)); ASSERT_EQ(4, mset->getSize()); - // Ordering +#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11 + // Only C++11 because C++03 uses one entry per pool block which breaks ordering ASSERT_EQ(1, *mset->getByIndex(0)); ASSERT_EQ(2, *mset->getByIndex(1)); ASSERT_EQ(3, *mset->getByIndex(2)); ASSERT_EQ(4, *mset->getByIndex(3)); ASSERT_FALSE(mset->getByIndex(5)); ASSERT_FALSE(mset->getByIndex(1000)); +#endif }