summaryrefslogtreecommitdiff
path: root/src/mongo/db/concurrency/fast_map_noalloc_test.cpp
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2015-06-20 00:22:50 -0400
committerMark Benvenuto <mark.benvenuto@mongodb.com>2015-06-20 10:56:02 -0400
commit9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 (patch)
tree3814f79c10d7b490948d8cb7b112ac1dd41ceff1 /src/mongo/db/concurrency/fast_map_noalloc_test.cpp
parent01965cf52bce6976637ecb8f4a622aeb05ab256a (diff)
downloadmongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/db/concurrency/fast_map_noalloc_test.cpp')
-rw-r--r--src/mongo/db/concurrency/fast_map_noalloc_test.cpp182
1 files changed, 90 insertions, 92 deletions
diff --git a/src/mongo/db/concurrency/fast_map_noalloc_test.cpp b/src/mongo/db/concurrency/fast_map_noalloc_test.cpp
index 70810cb6b5a..e9a013427df 100644
--- a/src/mongo/db/concurrency/fast_map_noalloc_test.cpp
+++ b/src/mongo/db/concurrency/fast_map_noalloc_test.cpp
@@ -36,127 +36,125 @@
namespace mongo {
- struct TestStruct {
-
- void initNew(int newId, const std::string& newValue) {
- id = newId;
- value = newValue;
- }
-
- int id;
- std::string value;
- };
+struct TestStruct {
+ void initNew(int newId, const std::string& newValue) {
+ id = newId;
+ value = newValue;
+ }
- typedef class FastMapNoAlloc<ResourceId, TestStruct, 6> TestFastMapNoAlloc;
+ int id;
+ std::string value;
+};
+typedef class FastMapNoAlloc<ResourceId, TestStruct, 6> TestFastMapNoAlloc;
- TEST(FastMapNoAlloc, Empty) {
- TestFastMapNoAlloc map;
- ASSERT(map.empty());
- TestFastMapNoAlloc::Iterator it = map.begin();
- ASSERT(it.finished());
- }
+TEST(FastMapNoAlloc, Empty) {
+ TestFastMapNoAlloc map;
+ ASSERT(map.empty());
- TEST(FastMapNoAlloc, NotEmpty) {
- TestFastMapNoAlloc map;
+ TestFastMapNoAlloc::Iterator it = map.begin();
+ ASSERT(it.finished());
+}
- map.insert(ResourceId(RESOURCE_COLLECTION, 1))->initNew(101, "Item101");
- map.insert(ResourceId(RESOURCE_COLLECTION, 2))->initNew(102, "Item102");
- ASSERT(!map.empty());
+TEST(FastMapNoAlloc, NotEmpty) {
+ TestFastMapNoAlloc map;
- TestFastMapNoAlloc::Iterator it = map.begin();
- ASSERT(!it.finished());
- ASSERT(!!it);
+ map.insert(ResourceId(RESOURCE_COLLECTION, 1))->initNew(101, "Item101");
+ map.insert(ResourceId(RESOURCE_COLLECTION, 2))->initNew(102, "Item102");
+ ASSERT(!map.empty());
- ASSERT(it->id == 101);
- ASSERT(it->value == "Item101");
+ TestFastMapNoAlloc::Iterator it = map.begin();
+ ASSERT(!it.finished());
+ ASSERT(!!it);
- it.next();
- ASSERT(!it.finished());
- ASSERT(!!it);
+ ASSERT(it->id == 101);
+ ASSERT(it->value == "Item101");
- ASSERT(it->id == 102);
- ASSERT(it->value == "Item102");
+ it.next();
+ ASSERT(!it.finished());
+ ASSERT(!!it);
- // We are at the last element
- it.next();
- ASSERT(it.finished());
- ASSERT(!it);
- }
+ ASSERT(it->id == 102);
+ ASSERT(it->value == "Item102");
- TEST(FastMapNoAlloc, FindNonExisting) {
- TestFastMapNoAlloc map;
+ // We are at the last element
+ it.next();
+ ASSERT(it.finished());
+ ASSERT(!it);
+}
- ASSERT(!map.find(ResourceId(RESOURCE_COLLECTION, 0)));
- }
+TEST(FastMapNoAlloc, FindNonExisting) {
+ TestFastMapNoAlloc map;
- TEST(FastMapNoAlloc, FindAndRemove) {
- TestFastMapNoAlloc map;
+ ASSERT(!map.find(ResourceId(RESOURCE_COLLECTION, 0)));
+}
- for (int i = 0; i < 6; i++) {
- map.insert(ResourceId(RESOURCE_COLLECTION, i))->initNew(
- i, "Item" + boost::lexical_cast<std::string>(i));
- }
+TEST(FastMapNoAlloc, FindAndRemove) {
+ TestFastMapNoAlloc map;
- for (int i = 0; i < 6; i++) {
- ASSERT(!map.find(ResourceId(RESOURCE_COLLECTION, i)).finished());
+ for (int i = 0; i < 6; i++) {
+ map.insert(ResourceId(RESOURCE_COLLECTION, i))
+ ->initNew(i, "Item" + boost::lexical_cast<std::string>(i));
+ }
- ASSERT_EQUALS(i, map.find(ResourceId(RESOURCE_COLLECTION, i))->id);
+ for (int i = 0; i < 6; i++) {
+ ASSERT(!map.find(ResourceId(RESOURCE_COLLECTION, i)).finished());
- ASSERT_EQUALS("Item" + boost::lexical_cast<std::string>(i),
- map.find(ResourceId(RESOURCE_COLLECTION, i))->value);
- }
+ ASSERT_EQUALS(i, map.find(ResourceId(RESOURCE_COLLECTION, i))->id);
- // Remove a middle entry
- map.find(ResourceId(RESOURCE_COLLECTION, 2)).remove();
- ASSERT(!map.find(ResourceId(RESOURCE_COLLECTION, 2)));
+ ASSERT_EQUALS("Item" + boost::lexical_cast<std::string>(i),
+ map.find(ResourceId(RESOURCE_COLLECTION, i))->value);
+ }
- // Remove entry after first
- map.find(ResourceId(RESOURCE_COLLECTION, 1)).remove();
- ASSERT(!map.find(ResourceId(RESOURCE_COLLECTION, 1)));
+ // Remove a middle entry
+ map.find(ResourceId(RESOURCE_COLLECTION, 2)).remove();
+ ASSERT(!map.find(ResourceId(RESOURCE_COLLECTION, 2)));
- // Remove entry before last
- map.find(ResourceId(RESOURCE_COLLECTION, 4)).remove();
- ASSERT(!map.find(ResourceId(RESOURCE_COLLECTION, 4)));
+ // Remove entry after first
+ map.find(ResourceId(RESOURCE_COLLECTION, 1)).remove();
+ ASSERT(!map.find(ResourceId(RESOURCE_COLLECTION, 1)));
- // Remove first entry
- map.find(ResourceId(RESOURCE_COLLECTION, 0)).remove();
- ASSERT(!map.find(ResourceId(RESOURCE_COLLECTION, 0)));
+ // Remove entry before last
+ map.find(ResourceId(RESOURCE_COLLECTION, 4)).remove();
+ ASSERT(!map.find(ResourceId(RESOURCE_COLLECTION, 4)));
- // Remove last entry
- map.find(ResourceId(RESOURCE_COLLECTION, 5)).remove();
- ASSERT(!map.find(ResourceId(RESOURCE_COLLECTION, 5)));
+ // Remove first entry
+ map.find(ResourceId(RESOURCE_COLLECTION, 0)).remove();
+ ASSERT(!map.find(ResourceId(RESOURCE_COLLECTION, 0)));
- // Remove final entry
- map.find(ResourceId(RESOURCE_COLLECTION, 3)).remove();
- ASSERT(!map.find(ResourceId(RESOURCE_COLLECTION, 3)));
- }
+ // Remove last entry
+ map.find(ResourceId(RESOURCE_COLLECTION, 5)).remove();
+ ASSERT(!map.find(ResourceId(RESOURCE_COLLECTION, 5)));
- TEST(FastMapNoAlloc, RemoveAll) {
- TestFastMapNoAlloc map;
- unordered_map<ResourceId, TestStruct> checkMap;
+ // Remove final entry
+ map.find(ResourceId(RESOURCE_COLLECTION, 3)).remove();
+ ASSERT(!map.find(ResourceId(RESOURCE_COLLECTION, 3)));
+}
- for (int i = 1; i <= 6; i++) {
- map.insert(ResourceId(RESOURCE_COLLECTION, i))->initNew(
- i, "Item" + boost::lexical_cast<std::string>(i));
+TEST(FastMapNoAlloc, RemoveAll) {
+ TestFastMapNoAlloc map;
+ unordered_map<ResourceId, TestStruct> checkMap;
- checkMap[ResourceId(RESOURCE_COLLECTION, i)].initNew(
- i, "Item" + boost::lexical_cast<std::string>(i));
- }
+ for (int i = 1; i <= 6; i++) {
+ map.insert(ResourceId(RESOURCE_COLLECTION, i))
+ ->initNew(i, "Item" + boost::lexical_cast<std::string>(i));
- TestFastMapNoAlloc::Iterator it = map.begin();
- while (!it.finished()) {
- ASSERT_EQUALS(it->id, checkMap[it.key()].id);
- ASSERT_EQUALS(
- "Item" + boost::lexical_cast<std::string>(it->id), checkMap[it.key()].value);
+ checkMap[ResourceId(RESOURCE_COLLECTION, i)].initNew(
+ i, "Item" + boost::lexical_cast<std::string>(i));
+ }
- checkMap.erase(it.key());
- it.remove();
- }
+ TestFastMapNoAlloc::Iterator it = map.begin();
+ while (!it.finished()) {
+ ASSERT_EQUALS(it->id, checkMap[it.key()].id);
+ ASSERT_EQUALS("Item" + boost::lexical_cast<std::string>(it->id), checkMap[it.key()].value);
- ASSERT(map.empty());
- ASSERT(checkMap.empty());
+ checkMap.erase(it.key());
+ it.remove();
}
-} // namespace mongo
+ ASSERT(map.empty());
+ ASSERT(checkMap.empty());
+}
+
+} // namespace mongo