TEST(StringBuffer, Clear) { StringBuffer buffer; buffer.Put('A'); buffer.Put('B'); buffer.Put('C'); buffer.Clear(); EXPECT_EQ(0u, buffer.GetSize()); EXPECT_STREQ("", buffer.GetString()); }
TEST(StringBuffer, Pop) { StringBuffer buffer; buffer.Put('A'); buffer.Put('B'); buffer.Put('C'); buffer.Put('D'); buffer.Put('E'); buffer.Pop(3); EXPECT_EQ(2u, buffer.GetSize()); EXPECT_STREQ("AB", buffer.GetString()); }
TEST(StringBuffer, Put) { StringBuffer buffer; buffer.Put('A'); EXPECT_EQ(1u, buffer.GetSize()); EXPECT_STREQ("A", buffer.GetString()); }
TEST(StringBuffer, MoveAssignment) { StringBuffer x; x.Put('A'); x.Put('B'); x.Put('C'); x.Put('D'); EXPECT_EQ(4u, x.GetSize()); EXPECT_STREQ("ABCD", x.GetString()); StringBuffer y; // y = x; // does not compile (!is_copy_assignable) y = std::move(x); EXPECT_EQ(0u, x.GetSize()); EXPECT_EQ(4u, y.GetSize()); EXPECT_STREQ("ABCD", y.GetString()); }
TEST(StringBuffer, MoveConstructor) { StringBuffer x; x.Put('A'); x.Put('B'); x.Put('C'); x.Put('D'); EXPECT_EQ(4u, x.GetSize()); EXPECT_STREQ("ABCD", x.GetString()); // StringBuffer y(x); // does not compile (!is_copy_constructible) StringBuffer y(std::move(x)); EXPECT_EQ(0u, x.GetSize()); EXPECT_EQ(4u, y.GetSize()); EXPECT_STREQ("ABCD", y.GetString()); // StringBuffer z = y; // does not compile (!is_copy_assignable) StringBuffer z = std::move(y); EXPECT_EQ(0u, y.GetSize()); EXPECT_EQ(4u, z.GetSize()); EXPECT_STREQ("ABCD", z.GetString()); }
StringBuffer* OpflexMessage::serialize() { StringBuffer* sb = new StringBuffer(); Writer<StringBuffer> writer(*sb); writer.StartObject(); switch (type) { case REQUEST: writer.String("method"); writer.String(method.c_str()); writer.String("params"); serializePayload(writer); break; case RESPONSE: writer.String("result"); serializePayload(writer); writer.String("error"); writer.Null(); break; case ERROR_RESPONSE: writer.String("result"); writer.Null(); writer.String("error"); serializePayload(writer); break; } writer.String("id"); if (id == NULL) writer.String(method.c_str()); else id->Accept(writer); writer.EndObject(); // we delimit our frames with a nul byte sb->Put('\0'); return sb; }
TEST_F(RapidJson, StringBuffer) { StringBuffer sb; for (int i = 0; i < 32 * 1024 * 1024; i++) sb.Put(i & 0x7f); }