MCPcopy Create free account
hub / github.com/Tencent/rapidjson / TestStringStream

Function TestStringStream

test/unittest/istreamwrappertest.cpp:32–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30
31template <typename StringStreamType>
32static void TestStringStream() {
33 typedef typename StringStreamType::char_type Ch;
34
35 {
36 StringStreamType iss;
37 BasicIStreamWrapper<StringStreamType> is(iss);
38 EXPECT_EQ(0, is.Tell());
39 if (sizeof(Ch) == 1) {
40 EXPECT_EQ(0, is.Peek4());
41 EXPECT_EQ(0, is.Tell());
42 }
43 EXPECT_EQ(0, is.Peek());
44 EXPECT_EQ(0, is.Take());
45 EXPECT_EQ(0, is.Tell());
46 }
47
48 {
49 Ch s[] = { 'A', 'B', 'C', '\0' };
50 StringStreamType iss(s);
51 BasicIStreamWrapper<StringStreamType> is(iss);
52 EXPECT_EQ(0, is.Tell());
53 if (sizeof(Ch) == 1) {
54 EXPECT_EQ(0, is.Peek4()); // less than 4 bytes
55 }
56 for (int i = 0; i < 3; i++) {
57 EXPECT_EQ(static_cast<size_t>(i), is.Tell());
58 EXPECT_EQ('A' + i, is.Peek());
59 EXPECT_EQ('A' + i, is.Peek());
60 EXPECT_EQ('A' + i, is.Take());
61 }
62 EXPECT_EQ(3, is.Tell());
63 EXPECT_EQ(0, is.Peek());
64 EXPECT_EQ(0, is.Take());
65 }
66
67 {
68 Ch s[] = { 'A', 'B', 'C', 'D', 'E', '\0' };
69 StringStreamType iss(s);
70 BasicIStreamWrapper<StringStreamType> is(iss);
71 if (sizeof(Ch) == 1) {
72 const Ch* c = is.Peek4();
73 for (int i = 0; i < 4; i++)
74 EXPECT_EQ('A' + i, c[i]);
75 EXPECT_EQ(0, is.Tell());
76 }
77 for (int i = 0; i < 5; i++) {
78 EXPECT_EQ(static_cast<size_t>(i), is.Tell());
79 EXPECT_EQ('A' + i, is.Peek());
80 EXPECT_EQ('A' + i, is.Peek());
81 EXPECT_EQ('A' + i, is.Take());
82 }
83 EXPECT_EQ(5, is.Tell());
84 EXPECT_EQ(0, is.Peek());
85 EXPECT_EQ(0, is.Take());
86 }
87}
88
89TEST(IStreamWrapper, istringstream) {

Callers

nothing calls this directly

Calls 3

TellMethod · 0.45
PeekMethod · 0.45
TakeMethod · 0.45

Tested by

no test coverage detected