Skip to content

Commit 5c764d9

Browse files
committed
Tests for Allocators copy by rvalue reference.
1 parent 683010b commit 5c764d9

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

test/unittest/allocatorstest.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616

1717
#include "rapidjson/allocators.h"
1818

19+
#include <map>
1920
#include <string>
20-
#include <cstring>
21+
#include <utility>
22+
#include <functional>
2123

2224
using namespace rapidjson;
2325

@@ -141,12 +143,34 @@ void TestStdAllocator(const Allocator& a) {
141143

142144
typedef StdAllocator<char, Allocator> CharAllocator;
143145
typedef std::basic_string<char, std::char_traits<char>, CharAllocator> String;
146+
#if RAPIDJSON_HAS_CXX11
147+
String s(CharAllocator{a});
148+
#else
144149
CharAllocator ca(a);
145150
String s(ca);
151+
#endif
146152
for (int i = 0; i < 26; i++) {
147153
s.push_back(static_cast<char>('A' + i));
148154
}
149155
EXPECT_TRUE(s == "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
156+
157+
typedef StdAllocator<std::pair<const int, bool>, Allocator> MapAllocator;
158+
typedef std::map<int, bool, std::less<int>, MapAllocator> Map;
159+
#if RAPIDJSON_HAS_CXX11
160+
Map map(std::less<int>(), MapAllocator{a});
161+
#else
162+
MapAllocator ma(a);
163+
Map map(std::less<int>(), ma);
164+
#endif
165+
for (int i = 0; i < 10; i++) {
166+
map.insert(std::make_pair(i, (i % 2) == 0));
167+
}
168+
EXPECT_TRUE(map.size() == 10);
169+
for (int i = 0; i < 10; i++) {
170+
typename Map::iterator it = map.find(i);
171+
EXPECT_TRUE(it != map.end());
172+
EXPECT_TRUE(it->second == ((i % 2) == 0));
173+
}
150174
}
151175

152176
TEST(Allocator, CrtAllocator) {

0 commit comments

Comments
 (0)