TYPED_TEST(DocumentMove, MoveAssignment) { typedef TypeParam Allocator; typedef GenericDocument<UTF8<>, Allocator> Document; Allocator allocator; Document a(&allocator); a.Parse("[\"one\", \"two\", \"three\"]"); EXPECT_FALSE(a.HasParseError()); EXPECT_TRUE(a.IsArray()); EXPECT_EQ(3u, a.Size()); EXPECT_EQ(&a.GetAllocator(), &allocator); // Document b; b = a; // does not compile (!is_copy_assignable) Document b; b = std::move(a); EXPECT_TRUE(a.IsNull()); EXPECT_TRUE(b.IsArray()); EXPECT_EQ(3u, b.Size()); EXPECT_EQ(&a.GetAllocator(), (void*)0); EXPECT_EQ(&b.GetAllocator(), &allocator); b.Parse("{\"Foo\": \"Bar\", \"Baz\": 42}"); EXPECT_FALSE(b.HasParseError()); EXPECT_TRUE(b.IsObject()); EXPECT_EQ(2u, b.MemberCount()); // Document c; c = a; // does not compile (see static_assert) Document c; c = std::move(b); EXPECT_TRUE(b.IsNull()); EXPECT_TRUE(c.IsObject()); EXPECT_EQ(2u, c.MemberCount()); EXPECT_EQ(&b.GetAllocator(), (void*)0); EXPECT_EQ(&c.GetAllocator(), &allocator); }
TYPED_TEST(DocumentMove, MoveConstructor) { typedef TypeParam Allocator; typedef GenericDocument<UTF8<>, Allocator> Document; Allocator allocator; Document a(&allocator); a.Parse("[\"one\", \"two\", \"three\"]"); EXPECT_FALSE(a.HasParseError()); EXPECT_TRUE(a.IsArray()); EXPECT_EQ(3u, a.Size()); EXPECT_EQ(&a.GetAllocator(), &allocator); // Document b(a); // does not compile (!is_copy_constructible) Document b(std::move(a)); EXPECT_TRUE(a.IsNull()); EXPECT_TRUE(b.IsArray()); EXPECT_EQ(3u, b.Size()); EXPECT_THROW(a.GetAllocator(), AssertException); EXPECT_EQ(&b.GetAllocator(), &allocator); b.Parse("{\"Foo\": \"Bar\", \"Baz\": 42}"); EXPECT_FALSE(b.HasParseError()); EXPECT_TRUE(b.IsObject()); EXPECT_EQ(2u, b.MemberCount()); // Document c = a; // does not compile (!is_copy_constructible) Document c = std::move(b); EXPECT_TRUE(b.IsNull()); EXPECT_TRUE(c.IsObject()); EXPECT_EQ(2u, c.MemberCount()); EXPECT_THROW(b.GetAllocator(), AssertException); EXPECT_EQ(&c.GetAllocator(), &allocator); }
TEST(IStreamWrapper, fstream) { fstream fs; ASSERT_TRUE(Open(fs, "utf8bom.json")); IStreamWrapper isw(fs); EncodedInputStream<UTF8<>, IStreamWrapper> eis(isw); Document d; EXPECT_TRUE(!d.ParseStream(eis).HasParseError()); EXPECT_TRUE(d.IsObject()); EXPECT_EQ(5, d.MemberCount()); }
TEST(Document, UnchangedOnParseError) { Document doc; doc.SetArray().PushBack(0, doc.GetAllocator()); ParseResult err = doc.Parse("{]"); EXPECT_TRUE(doc.HasParseError()); EXPECT_EQ(err.Code(), doc.GetParseError()); EXPECT_EQ(err.Offset(), doc.GetErrorOffset()); EXPECT_TRUE(doc.IsArray()); EXPECT_EQ(doc.Size(), 1u); err = doc.Parse("{}"); EXPECT_FALSE(doc.HasParseError()); EXPECT_FALSE(err.IsError()); EXPECT_EQ(err.Code(), doc.GetParseError()); EXPECT_EQ(err.Offset(), doc.GetErrorOffset()); EXPECT_TRUE(doc.IsObject()); EXPECT_EQ(doc.MemberCount(), 0u); }