OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 StringReader reader(test_string_one_); | 81 StringReader reader(test_string_one_); |
82 EXPECT_EQ(test_string_one_.substr(0, 6), reader.PeekString(6)); | 82 EXPECT_EQ(test_string_one_.substr(0, 6), reader.PeekString(6)); |
83 EXPECT_EQ(0U, reader.position()); | 83 EXPECT_EQ(0U, reader.position()); |
84 EXPECT_EQ(test_string_one_, reader.input()); | 84 EXPECT_EQ(test_string_one_, reader.input()); |
85 } | 85 } |
86 | 86 |
87 TEST_F(StringReaderTest, ReadsSingleCharacter) { | 87 TEST_F(StringReaderTest, ReadsSingleCharacter) { |
88 StringReader reader(test_string_one_); | 88 StringReader reader(test_string_one_); |
89 EXPECT_EQ(test_string_one_.substr(0, 1)[0], reader.ReadChar()); | 89 EXPECT_EQ(test_string_one_.substr(0, 1)[0], reader.ReadChar()); |
90 EXPECT_EQ(1U, reader.position()); | 90 EXPECT_EQ(1U, reader.position()); |
91 EXPECT_EQ(false, reader.IsAtEnd()); | 91 EXPECT_FALSE(reader.IsAtEnd()); |
92 EXPECT_EQ(test_string_one_.substr(1, 2), reader.PeekString(2)); | 92 EXPECT_EQ(test_string_one_.substr(1, 2), reader.PeekString(2)); |
93 EXPECT_EQ(1U, reader.position()); | 93 EXPECT_EQ(1U, reader.position()); |
94 } | 94 } |
95 | 95 |
96 TEST_F(StringReaderTest, ReadsMultipleCharacters) { | 96 TEST_F(StringReaderTest, ReadsMultipleCharacters) { |
97 StringReader reader(test_string_one_); | 97 StringReader reader(test_string_one_); |
98 EXPECT_EQ(test_string_one_.substr(0, 1)[0], reader.ReadChar()); | 98 EXPECT_EQ(test_string_one_.substr(0, 1)[0], reader.ReadChar()); |
99 EXPECT_EQ(test_string_one_.substr(1, 1)[0], reader.ReadChar()); | 99 EXPECT_EQ(test_string_one_.substr(1, 1)[0], reader.ReadChar()); |
100 EXPECT_EQ(2U, reader.position()); | 100 EXPECT_EQ(2U, reader.position()); |
101 EXPECT_EQ(false, reader.IsAtEnd()); | 101 EXPECT_FALSE(reader.IsAtEnd()); |
102 EXPECT_EQ(test_string_one_.substr(2, 2), reader.PeekString(2)); | 102 EXPECT_EQ(test_string_one_.substr(2, 2), reader.PeekString(2)); |
103 EXPECT_EQ(2U, reader.position()); | 103 EXPECT_EQ(2U, reader.position()); |
104 } | 104 } |
105 | 105 |
106 TEST_F(StringReaderTest, ReadsString) { | 106 TEST_F(StringReaderTest, ReadsString) { |
107 StringReader reader(test_string_one_); | 107 StringReader reader(test_string_one_); |
108 EXPECT_EQ(test_string_one_.substr(0, 7), reader.ReadString(7)); | 108 EXPECT_EQ(test_string_one_.substr(0, 7), reader.ReadString(7)); |
109 EXPECT_EQ(7U, reader.position()); | 109 EXPECT_EQ(7U, reader.position()); |
110 EXPECT_EQ(false, reader.IsAtEnd()); | 110 EXPECT_FALSE(reader.IsAtEnd()); |
111 EXPECT_EQ(test_string_one_.substr(7, 2), reader.PeekString(2)); | 111 EXPECT_EQ(test_string_one_.substr(7, 2), reader.PeekString(2)); |
112 EXPECT_EQ(7U, reader.position()); | 112 EXPECT_EQ(7U, reader.position()); |
113 } | 113 } |
114 | 114 |
115 TEST_F(StringReaderTest, ReadsToEnd) { | 115 TEST_F(StringReaderTest, ReadsToEnd) { |
116 StringReader reader(test_string_lf_); | 116 StringReader reader(test_string_lf_); |
117 EXPECT_EQ(test_string_lf_, reader.ReadToEnd()); | 117 EXPECT_EQ(test_string_lf_, reader.ReadToEnd()); |
118 EXPECT_EQ(test_string_lf_.size(), reader.position()); | 118 EXPECT_EQ(test_string_lf_.size(), reader.position()); |
119 EXPECT_EQ(true, reader.IsAtEnd()); | 119 EXPECT_TRUE(reader.IsAtEnd()); |
120 EXPECT_EQ("", reader.ReadString(1)); | 120 EXPECT_EQ("", reader.ReadString(1)); |
121 EXPECT_EQ(true, reader.IsAtEnd()); | 121 EXPECT_TRUE(reader.IsAtEnd()); |
122 EXPECT_EQ(test_string_lf_.size(), reader.position()); | 122 EXPECT_EQ(test_string_lf_.size(), reader.position()); |
123 } | 123 } |
124 | 124 |
125 | 125 |
126 TEST_F(StringReaderTest, ReadsLinefeedString) { | 126 TEST_F(StringReaderTest, ReadsLinefeedString) { |
127 StringReader reader(test_string_lf_); | 127 StringReader reader(test_string_lf_); |
128 std::string line = reader.ReadLine(); | 128 std::string line = reader.ReadLine(); |
129 EXPECT_EQ(test_string_one_, line); | 129 EXPECT_EQ(test_string_one_, line); |
130 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); | 130 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); |
131 EXPECT_EQ(false, reader.IsAtEnd()); | 131 EXPECT_FALSE(reader.IsAtEnd()); |
132 EXPECT_EQ(test_string_lf_.substr(test_string_one_.size() + 1, 2), | 132 EXPECT_EQ(test_string_lf_.substr(test_string_one_.size() + 1, 2), |
133 reader.PeekString(2)); | 133 reader.PeekString(2)); |
134 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); | 134 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); |
135 EXPECT_EQ(test_string_two_, reader.ReadLine()); | 135 EXPECT_EQ(test_string_two_, reader.ReadLine()); |
136 EXPECT_EQ(true, reader.IsAtEnd()); | 136 EXPECT_TRUE(reader.IsAtEnd()); |
137 EXPECT_EQ(test_string_lf_.size(), reader.position()); | 137 EXPECT_EQ(test_string_lf_.size(), reader.position()); |
138 } | 138 } |
139 | 139 |
140 TEST_F(StringReaderTest, ReadsCarriageReturnString) { | 140 TEST_F(StringReaderTest, ReadsCarriageReturnString) { |
141 StringReader reader(test_string_cr_); | 141 StringReader reader(test_string_cr_); |
142 EXPECT_EQ(test_string_one_, reader.ReadLine()); | 142 EXPECT_EQ(test_string_one_, reader.ReadLine()); |
143 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); | 143 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); |
144 EXPECT_EQ(false, reader.IsAtEnd()); | 144 EXPECT_FALSE(reader.IsAtEnd()); |
145 EXPECT_EQ(test_string_cr_.substr(test_string_one_.size() + 1, 2), | 145 EXPECT_EQ(test_string_cr_.substr(test_string_one_.size() + 1, 2), |
146 reader.PeekString(2)); | 146 reader.PeekString(2)); |
147 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); | 147 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); |
148 EXPECT_EQ(test_string_two_, reader.ReadLine()); | 148 EXPECT_EQ(test_string_two_, reader.ReadLine()); |
149 EXPECT_EQ(true, reader.IsAtEnd()); | 149 EXPECT_TRUE(reader.IsAtEnd()); |
150 EXPECT_EQ(test_string_cr_.size(), reader.position()); | 150 EXPECT_EQ(test_string_cr_.size(), reader.position()); |
151 } | 151 } |
152 | 152 |
153 | 153 |
154 TEST_F(StringReaderTest, ReadsCarriageReturnLinefeedString) { | 154 TEST_F(StringReaderTest, ReadsCarriageReturnLinefeedString) { |
155 StringReader reader(test_string_crlf_); | 155 StringReader reader(test_string_crlf_); |
156 EXPECT_EQ(test_string_one_, reader.ReadLine()); | 156 EXPECT_EQ(test_string_one_, reader.ReadLine()); |
157 EXPECT_EQ(test_string_one_.size() + 2, reader.position()); | 157 EXPECT_EQ(test_string_one_.size() + 2, reader.position()); |
158 EXPECT_EQ(false, reader.IsAtEnd()); | 158 EXPECT_FALSE(reader.IsAtEnd()); |
159 EXPECT_EQ(test_string_crlf_.substr(test_string_one_.size() + 2, 2), | 159 EXPECT_EQ(test_string_crlf_.substr(test_string_one_.size() + 2, 2), |
160 reader.PeekString(2)); | 160 reader.PeekString(2)); |
161 EXPECT_EQ(test_string_one_.size() + 2, reader.position()); | 161 EXPECT_EQ(test_string_one_.size() + 2, reader.position()); |
162 EXPECT_EQ(test_string_two_, reader.ReadLine()); | 162 EXPECT_EQ(test_string_two_, reader.ReadLine()); |
163 EXPECT_EQ(true, reader.IsAtEnd()); | 163 EXPECT_TRUE(reader.IsAtEnd()); |
164 EXPECT_EQ(test_string_crlf_.size(), reader.position()); | 164 EXPECT_EQ(test_string_crlf_.size(), reader.position()); |
165 } | 165 } |
166 | 166 |
167 TEST_F(StringReaderTest, ReadsLinefeedCarriageReturnString) { | 167 TEST_F(StringReaderTest, ReadsLinefeedCarriageReturnString) { |
168 StringReader reader(test_string_lfcr_); | 168 StringReader reader(test_string_lfcr_); |
169 EXPECT_EQ(test_string_one_, reader.ReadLine()); | 169 EXPECT_EQ(test_string_one_, reader.ReadLine()); |
170 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); | 170 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); |
171 EXPECT_EQ(false, reader.IsAtEnd()); | 171 EXPECT_FALSE(reader.IsAtEnd()); |
172 EXPECT_EQ(test_string_lfcr_.substr(test_string_one_.size() + 1, 2), | 172 EXPECT_EQ(test_string_lfcr_.substr(test_string_one_.size() + 1, 2), |
173 reader.PeekString(2)); | 173 reader.PeekString(2)); |
174 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); | 174 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); |
175 EXPECT_EQ("", reader.ReadLine()); | 175 EXPECT_EQ("", reader.ReadLine()); |
176 EXPECT_EQ(false, reader.IsAtEnd()); | 176 EXPECT_FALSE(reader.IsAtEnd()); |
177 EXPECT_EQ(test_string_two_, reader.ReadLine()); | 177 EXPECT_EQ(test_string_two_, reader.ReadLine()); |
178 EXPECT_EQ(false, reader.IsAtEnd()); | 178 EXPECT_FALSE(reader.IsAtEnd()); |
179 EXPECT_EQ("", reader.ReadLine()); | 179 EXPECT_EQ("", reader.ReadLine()); |
180 EXPECT_EQ(true, reader.IsAtEnd()); | 180 EXPECT_TRUE(reader.IsAtEnd()); |
181 EXPECT_EQ(test_string_lfcr_.size(), reader.position()); | 181 EXPECT_EQ(test_string_lfcr_.size(), reader.position()); |
182 } | 182 } |
183 | 183 |
184 TEST_F(StringReaderTest, ReadsLinefeedLinefeedString) { | 184 TEST_F(StringReaderTest, ReadsLinefeedLinefeedString) { |
185 StringReader reader(test_string_lflf_); | 185 StringReader reader(test_string_lflf_); |
186 EXPECT_EQ(test_string_one_, reader.ReadLine()); | 186 EXPECT_EQ(test_string_one_, reader.ReadLine()); |
187 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); | 187 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); |
188 EXPECT_EQ(false, reader.IsAtEnd()); | 188 EXPECT_FALSE(reader.IsAtEnd()); |
189 EXPECT_EQ(test_string_lflf_.substr(test_string_one_.size() + 1, 2), | 189 EXPECT_EQ(test_string_lflf_.substr(test_string_one_.size() + 1, 2), |
190 reader.PeekString(2)); | 190 reader.PeekString(2)); |
191 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); | 191 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); |
192 EXPECT_EQ("", reader.ReadLine()); | 192 EXPECT_EQ("", reader.ReadLine()); |
193 EXPECT_EQ(false, reader.IsAtEnd()); | 193 EXPECT_FALSE(reader.IsAtEnd()); |
194 EXPECT_EQ(test_string_two_, reader.ReadLine()); | 194 EXPECT_EQ(test_string_two_, reader.ReadLine()); |
195 EXPECT_EQ(false, reader.IsAtEnd()); | 195 EXPECT_FALSE(reader.IsAtEnd()); |
196 EXPECT_EQ("", reader.ReadLine()); | 196 EXPECT_EQ("", reader.ReadLine()); |
197 EXPECT_EQ(true, reader.IsAtEnd()); | 197 EXPECT_TRUE(reader.IsAtEnd()); |
198 EXPECT_EQ(test_string_lflf_.size(), reader.position()); | 198 EXPECT_EQ(test_string_lflf_.size(), reader.position()); |
199 } | 199 } |
200 } // namespace o3d | 200 } // namespace o3d |
OLD | NEW |