From 209547e8b6bc5e268dda72f896d951391bcc42db Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Mon, 23 Mar 2015 22:20:15 +0300 Subject: [PATCH] Map<>::KVPair constructor fix --- libuavcan/include/uavcan/util/map.hpp | 7 ++++- libuavcan/test/util/map.cpp | 38 +++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/libuavcan/include/uavcan/util/map.hpp b/libuavcan/include/uavcan/util/map.hpp index f387f51fbb..c011359667 100644 --- a/libuavcan/include/uavcan/util/map.hpp +++ b/libuavcan/include/uavcan/util/map.hpp @@ -41,7 +41,12 @@ public: { Key key; Value value; - KVPair() { } + + KVPair() + : key() + , value() + { } + KVPair(const Key& arg_key, const Value& arg_value) : key(arg_key) , value(arg_value) diff --git a/libuavcan/test/util/map.cpp b/libuavcan/test/util/map.cpp index 2a0eba20a4..3f8671ede9 100644 --- a/libuavcan/test/util/map.cpp +++ b/libuavcan/test/util/map.cpp @@ -233,3 +233,41 @@ TEST(Map, NoStatic) ASSERT_FALSE(map->getByIndex(3)); ASSERT_FALSE(map->getByIndex(1000)); } + + +TEST(Map, PrimitiveKey) +{ + using uavcan::Map; + + static const int POOL_BLOCKS = 3; + uavcan::PoolAllocator pool; + uavcan::PoolManager<2> poolmgr; + poolmgr.addPool(&pool); + + typedef Map MapType; + std::auto_ptr map(new MapType(poolmgr)); + + // Empty + ASSERT_FALSE(map->access(1)); + map->remove(8); + ASSERT_EQ(0, pool.getNumUsedBlocks()); + ASSERT_EQ(0, map->getSize()); + ASSERT_FALSE(map->getByIndex(0)); + + // Insertion + ASSERT_EQ(1, *map->insert(1, 1)); + ASSERT_EQ(1, map->getSize()); + ASSERT_EQ(2, *map->insert(2, 2)); + ASSERT_EQ(2, map->getSize()); + ASSERT_EQ(3, *map->insert(3, 3)); + ASSERT_EQ(4, *map->insert(4, 4)); + ASSERT_EQ(4, map->getSize()); + + // Ordering + ASSERT_TRUE(map->getByIndex(0)->match(1)); + ASSERT_TRUE(map->getByIndex(1)->match(2)); + ASSERT_TRUE(map->getByIndex(2)->match(3)); + ASSERT_TRUE(map->getByIndex(3)->match(4)); + ASSERT_FALSE(map->getByIndex(5)); + ASSERT_FALSE(map->getByIndex(1000)); +}