Added MemoryPoolAllocator to GenericDocument moveunit tests. Added comment in GenericDocument move assignment operator explaining why the static_cast is needed to move the base class.

This commit is contained in:
ecorm 2014-10-24 14:05:32 -03:00
parent cb33f910c3
commit fd12dcb3db
2 changed files with 33 additions and 18 deletions

View File

@ -1652,6 +1652,8 @@ public:
//! Move assignment in C++11 //! Move assignment in C++11
GenericDocument& operator=(GenericDocument&& rhs) RAPIDJSON_NOEXCEPT GenericDocument& operator=(GenericDocument&& rhs) RAPIDJSON_NOEXCEPT
{ {
// The static cast is necessary here, because otherwise it would
// attempt to call GenericValue's templated assignment operator.
ValueType::operator=(std::move(static_cast<ValueType&&>(rhs))); ValueType::operator=(std::move(static_cast<ValueType&&>(rhs)));
// Calling the destructor here would prematurely call stack_'s destructor // Calling the destructor here would prematurely call stack_'s destructor

View File

@ -229,9 +229,17 @@ TEST(Document, UTF16_Document) {
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
TEST(Document, MoveConstructor) { template <typename Allocator>
typedef GenericDocument<UTF8<>, CrtAllocator> Document; struct DocumentMove: public ::testing::Test {
Document::AllocatorType allocator; };
typedef ::testing::Types< CrtAllocator, MemoryPoolAllocator<> > MoveAllocatorTypes;
TYPED_TEST_CASE(DocumentMove, MoveAllocatorTypes);
TYPED_TEST(DocumentMove, MoveConstructor) {
typedef TypeParam Allocator;
typedef GenericDocument<UTF8<>, Allocator> Document;
Allocator allocator;
Document a(&allocator); Document a(&allocator);
a.Parse("[\"one\", \"two\", \"three\"]"); a.Parse("[\"one\", \"two\", \"three\"]");
@ -262,8 +270,9 @@ TEST(Document, MoveConstructor) {
EXPECT_EQ(&c.GetAllocator(), &allocator); EXPECT_EQ(&c.GetAllocator(), &allocator);
} }
TEST(Document, MoveConstructorParseError) { TYPED_TEST(DocumentMove, MoveConstructorParseError) {
typedef GenericDocument<UTF8<>, CrtAllocator> Document; typedef TypeParam Allocator;
typedef GenericDocument<UTF8<>, Allocator> Document;
ParseResult noError; ParseResult noError;
Document a; Document a;
@ -290,18 +299,19 @@ TEST(Document, MoveConstructorParseError) {
EXPECT_EQ(c.GetErrorOffset(), error.Offset()); EXPECT_EQ(c.GetErrorOffset(), error.Offset());
} }
TEST(Document, MoveConstructorStack) { TYPED_TEST(DocumentMove, MoveConstructorStack) {
typedef TypeParam Allocator;
typedef UTF8<> Encoding; typedef UTF8<> Encoding;
typedef GenericDocument<Encoding, CrtAllocator> Document; typedef GenericDocument<Encoding, Allocator> Document;
Document a; Document a;
size_t defaultCapacity = a.GetStackCapacity(); size_t defaultCapacity = a.GetStackCapacity();
// Trick Document into getting GetStackCapacity() to return non-zero // Trick Document into getting GetStackCapacity() to return non-zero
typedef GenericReader<Encoding, Encoding, Document::AllocatorType> Reader; typedef GenericReader<Encoding, Encoding, Allocator> Reader;
Reader reader(&a.GetAllocator()); Reader reader(&a.GetAllocator());
GenericStringStream<Encoding> is("[\"one\", \"two\", \"three\"]"); GenericStringStream<Encoding> is("[\"one\", \"two\", \"three\"]");
reader.Parse<kParseDefaultFlags>(is, a); reader.template Parse<kParseDefaultFlags>(is, a);
size_t capacity = a.GetStackCapacity(); size_t capacity = a.GetStackCapacity();
EXPECT_GT(capacity, 0); EXPECT_GT(capacity, 0);
@ -314,9 +324,10 @@ TEST(Document, MoveConstructorStack) {
EXPECT_EQ(c.GetStackCapacity(), capacity); EXPECT_EQ(c.GetStackCapacity(), capacity);
} }
TEST(Document, MoveAssignment) { TYPED_TEST(DocumentMove, MoveAssignment) {
typedef GenericDocument<UTF8<>, CrtAllocator> Document; typedef TypeParam Allocator;
Document::AllocatorType allocator; typedef GenericDocument<UTF8<>, Allocator> Document;
Allocator allocator;
Document a(&allocator); Document a(&allocator);
a.Parse("[\"one\", \"two\", \"three\"]"); a.Parse("[\"one\", \"two\", \"three\"]");
@ -349,8 +360,9 @@ TEST(Document, MoveAssignment) {
EXPECT_EQ(&c.GetAllocator(), &allocator); EXPECT_EQ(&c.GetAllocator(), &allocator);
} }
TEST(Document, MoveAssignmentParseError) { TYPED_TEST(DocumentMove, MoveAssignmentParseError) {
typedef GenericDocument<UTF8<>, CrtAllocator> Document; typedef TypeParam Allocator;
typedef GenericDocument<UTF8<>, Allocator> Document;
ParseResult noError; ParseResult noError;
Document a; Document a;
@ -379,18 +391,19 @@ TEST(Document, MoveAssignmentParseError) {
EXPECT_EQ(c.GetErrorOffset(), error.Offset()); EXPECT_EQ(c.GetErrorOffset(), error.Offset());
} }
TEST(Document, MoveAssignmentStack) { TYPED_TEST(DocumentMove, MoveAssignmentStack) {
typedef TypeParam Allocator;
typedef UTF8<> Encoding; typedef UTF8<> Encoding;
typedef GenericDocument<Encoding, CrtAllocator> Document; typedef GenericDocument<Encoding, Allocator> Document;
Document a; Document a;
size_t defaultCapacity = a.GetStackCapacity(); size_t defaultCapacity = a.GetStackCapacity();
// Trick Document into getting GetStackCapacity() to return non-zero // Trick Document into getting GetStackCapacity() to return non-zero
typedef GenericReader<Encoding, Encoding, Document::AllocatorType> Reader; typedef GenericReader<Encoding, Encoding, Allocator> Reader;
Reader reader(&a.GetAllocator()); Reader reader(&a.GetAllocator());
GenericStringStream<Encoding> is("[\"one\", \"two\", \"three\"]"); GenericStringStream<Encoding> is("[\"one\", \"two\", \"three\"]");
reader.Parse<kParseDefaultFlags>(is, a); reader.template Parse<kParseDefaultFlags>(is, a);
size_t capacity = a.GetStackCapacity(); size_t capacity = a.GetStackCapacity();
EXPECT_GT(capacity, 0); EXPECT_GT(capacity, 0);