| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013, Opera Software ASA. All rights reserved. | 2 * Copyright (c) 2013, Opera Software ASA. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 27 * OF THE POSSIBILITY OF SUCH DAMAGE. | 27 * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 */ | 28 */ |
| 29 | 29 |
| 30 #include "config.h" | 30 #include "config.h" |
| 31 #include "core/html/track/vtt/VTTScanner.h" | 31 #include "core/html/track/vtt/VTTScanner.h" |
| 32 | 32 |
| 33 #include "wtf/text/WTFString.h" | 33 #include "wtf/text/WTFString.h" |
| 34 | |
| 35 #include <gtest/gtest.h> | 34 #include <gtest/gtest.h> |
| 36 | 35 |
| 37 using blink::VTTScanner; | 36 namespace blink { |
| 38 | 37 |
| 39 namespace { | 38 TEST(VTTScannerTest, Constructor) |
| 40 | |
| 41 TEST(VTTScanner, Constructor) | |
| 42 { | 39 { |
| 43 String data8("foo"); | 40 String data8("foo"); |
| 44 EXPECT_TRUE(data8.is8Bit()); | 41 EXPECT_TRUE(data8.is8Bit()); |
| 45 VTTScanner scanner8(data8); | 42 VTTScanner scanner8(data8); |
| 46 EXPECT_FALSE(scanner8.isAtEnd()); | 43 EXPECT_FALSE(scanner8.isAtEnd()); |
| 47 | 44 |
| 48 String data16(data8); | 45 String data16(data8); |
| 49 data16.ensure16Bit(); | 46 data16.ensure16Bit(); |
| 50 EXPECT_FALSE(data16.is8Bit()); | 47 EXPECT_FALSE(data16.is8Bit()); |
| 51 VTTScanner scanner16(data16); | 48 VTTScanner scanner16(data16); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 82 TESTFUNC(data8); \ | 79 TESTFUNC(data8); \ |
| 83 \ | 80 \ |
| 84 String data16(data8); \ | 81 String data16(data8); \ |
| 85 data16.ensure16Bit(); \ | 82 data16.ensure16Bit(); \ |
| 86 EXPECT_FALSE(data16.is8Bit()); \ | 83 EXPECT_FALSE(data16.is8Bit()); \ |
| 87 TESTFUNC(data16); \ | 84 TESTFUNC(data16); \ |
| 88 } while (false) | 85 } while (false) |
| 89 | 86 |
| 90 | 87 |
| 91 // Exercises match(c) and scan(c). | 88 // Exercises match(c) and scan(c). |
| 92 TEST(VTTScanner, BasicOperations1) | 89 TEST(VTTScannerTest, BasicOperations1) |
| 93 { | 90 { |
| 94 TEST_WITH(scanSequenceHelper1, "foe"); | 91 TEST_WITH(scanSequenceHelper1, "foe"); |
| 95 } | 92 } |
| 96 | 93 |
| 97 void scanSequenceHelper2(const String& input) | 94 void scanSequenceHelper2(const String& input) |
| 98 { | 95 { |
| 99 VTTScanner scanner(input); | 96 VTTScanner scanner(input); |
| 100 EXPECT_FALSE(scanner.isAtEnd()); | 97 EXPECT_FALSE(scanner.isAtEnd()); |
| 101 EXPECT_FALSE(scanner.scan("fe")); | 98 EXPECT_FALSE(scanner.scan("fe")); |
| 102 | 99 |
| 103 EXPECT_TRUE(scanner.scan("fo")); | 100 EXPECT_TRUE(scanner.scan("fo")); |
| 104 EXPECT_FALSE(scanner.isAtEnd()); | 101 EXPECT_FALSE(scanner.isAtEnd()); |
| 105 | 102 |
| 106 EXPECT_FALSE(scanner.scan("ee")); | 103 EXPECT_FALSE(scanner.scan("ee")); |
| 107 | 104 |
| 108 EXPECT_TRUE(scanner.scan('e')); | 105 EXPECT_TRUE(scanner.scan('e')); |
| 109 EXPECT_TRUE(scanner.isAtEnd()); | 106 EXPECT_TRUE(scanner.isAtEnd()); |
| 110 } | 107 } |
| 111 | 108 |
| 112 // Exercises scan(<literal>[, length]). | 109 // Exercises scan(<literal>[, length]). |
| 113 TEST(VTTScanner, BasicOperations2) | 110 TEST(VTTScannerTest, BasicOperations2) |
| 114 { | 111 { |
| 115 TEST_WITH(scanSequenceHelper2, "foe"); | 112 TEST_WITH(scanSequenceHelper2, "foe"); |
| 116 } | 113 } |
| 117 | 114 |
| 118 bool lowerCaseAlpha(UChar c) | 115 bool lowerCaseAlpha(UChar c) |
| 119 { | 116 { |
| 120 return c >= 'a' && c <= 'z'; | 117 return c >= 'a' && c <= 'z'; |
| 121 } | 118 } |
| 122 | 119 |
| 123 void scanWithPredicate(const String& input) | 120 void scanWithPredicate(const String& input) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 140 lcRun = scanner.collectWhile<lowerCaseAlpha>(); | 137 lcRun = scanner.collectWhile<lowerCaseAlpha>(); |
| 141 // collectWhile doesn't move the scan position. | 138 // collectWhile doesn't move the scan position. |
| 142 EXPECT_FALSE(scanner.isAtEnd()); | 139 EXPECT_FALSE(scanner.isAtEnd()); |
| 143 // Consume "bing". | 140 // Consume "bing". |
| 144 scanner.skipWhile<lowerCaseAlpha>(); | 141 scanner.skipWhile<lowerCaseAlpha>(); |
| 145 EXPECT_TRUE(scanner.isAt(lcRun.end())); | 142 EXPECT_TRUE(scanner.isAt(lcRun.end())); |
| 146 EXPECT_TRUE(scanner.isAtEnd()); | 143 EXPECT_TRUE(scanner.isAtEnd()); |
| 147 } | 144 } |
| 148 | 145 |
| 149 // Tests skipWhile() and collectWhile(). | 146 // Tests skipWhile() and collectWhile(). |
| 150 TEST(VTTScanner, PredicateScanning) | 147 TEST(VTTScannerTest, PredicateScanning) |
| 151 { | 148 { |
| 152 TEST_WITH(scanWithPredicate, "badAbing"); | 149 TEST_WITH(scanWithPredicate, "badAbing"); |
| 153 } | 150 } |
| 154 | 151 |
| 155 void scanWithInvPredicate(const String& input) | 152 void scanWithInvPredicate(const String& input) |
| 156 { | 153 { |
| 157 VTTScanner scanner(input); | 154 VTTScanner scanner(input); |
| 158 EXPECT_FALSE(scanner.isAtEnd()); | 155 EXPECT_FALSE(scanner.isAtEnd()); |
| 159 // Collect "BAD". | 156 // Collect "BAD". |
| 160 VTTScanner::Run ucRun = scanner.collectUntil<lowerCaseAlpha>(); | 157 VTTScanner::Run ucRun = scanner.collectUntil<lowerCaseAlpha>(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 172 ucRun = scanner.collectUntil<lowerCaseAlpha>(); | 169 ucRun = scanner.collectUntil<lowerCaseAlpha>(); |
| 173 // collectUntil doesn't move the scan position. | 170 // collectUntil doesn't move the scan position. |
| 174 EXPECT_FALSE(scanner.isAtEnd()); | 171 EXPECT_FALSE(scanner.isAtEnd()); |
| 175 // Consume "BING". | 172 // Consume "BING". |
| 176 scanner.skipUntil<lowerCaseAlpha>(); | 173 scanner.skipUntil<lowerCaseAlpha>(); |
| 177 EXPECT_TRUE(scanner.isAt(ucRun.end())); | 174 EXPECT_TRUE(scanner.isAt(ucRun.end())); |
| 178 EXPECT_TRUE(scanner.isAtEnd()); | 175 EXPECT_TRUE(scanner.isAtEnd()); |
| 179 } | 176 } |
| 180 | 177 |
| 181 // Tests skipUntil() and collectUntil(). | 178 // Tests skipUntil() and collectUntil(). |
| 182 TEST(VTTScanner, InversePredicateScanning) | 179 TEST(VTTScannerTest, InversePredicateScanning) |
| 183 { | 180 { |
| 184 TEST_WITH(scanWithInvPredicate, "BADaBING"); | 181 TEST_WITH(scanWithInvPredicate, "BADaBING"); |
| 185 } | 182 } |
| 186 | 183 |
| 187 void scanRuns(const String& input) | 184 void scanRuns(const String& input) |
| 188 { | 185 { |
| 189 String fooString("foo"); | 186 String fooString("foo"); |
| 190 String barString("bar"); | 187 String barString("bar"); |
| 191 VTTScanner scanner(input); | 188 VTTScanner scanner(input); |
| 192 EXPECT_FALSE(scanner.isAtEnd()); | 189 EXPECT_FALSE(scanner.isAtEnd()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 203 EXPECT_TRUE(scanner.match(':')); | 200 EXPECT_TRUE(scanner.match(':')); |
| 204 EXPECT_TRUE(scanner.scan(':')); | 201 EXPECT_TRUE(scanner.scan(':')); |
| 205 | 202 |
| 206 word = scanner.collectWhile<lowerCaseAlpha>(); | 203 word = scanner.collectWhile<lowerCaseAlpha>(); |
| 207 EXPECT_FALSE(scanner.scanRun(word, fooString)); | 204 EXPECT_FALSE(scanner.scanRun(word, fooString)); |
| 208 EXPECT_TRUE(scanner.scanRun(word, barString)); | 205 EXPECT_TRUE(scanner.scanRun(word, barString)); |
| 209 EXPECT_TRUE(scanner.isAtEnd()); | 206 EXPECT_TRUE(scanner.isAtEnd()); |
| 210 } | 207 } |
| 211 | 208 |
| 212 // Tests scanRun/skipRun. | 209 // Tests scanRun/skipRun. |
| 213 TEST(VTTScanner, RunScanning) | 210 TEST(VTTScannerTest, RunScanning) |
| 214 { | 211 { |
| 215 TEST_WITH(scanRuns, "foo:baz:bar"); | 212 TEST_WITH(scanRuns, "foo:baz:bar"); |
| 216 } | 213 } |
| 217 | 214 |
| 218 void scanRunsToStrings(const String& input) | 215 void scanRunsToStrings(const String& input) |
| 219 { | 216 { |
| 220 VTTScanner scanner(input); | 217 VTTScanner scanner(input); |
| 221 EXPECT_FALSE(scanner.isAtEnd()); | 218 EXPECT_FALSE(scanner.isAtEnd()); |
| 222 VTTScanner::Run word = scanner.collectWhile<lowerCaseAlpha>(); | 219 VTTScanner::Run word = scanner.collectWhile<lowerCaseAlpha>(); |
| 223 String fooString = scanner.extractString(word); | 220 String fooString = scanner.extractString(word); |
| 224 EXPECT_EQ(fooString, "foo"); | 221 EXPECT_EQ(fooString, "foo"); |
| 225 EXPECT_TRUE(scanner.isAt(word.end())); | 222 EXPECT_TRUE(scanner.isAt(word.end())); |
| 226 | 223 |
| 227 EXPECT_TRUE(scanner.match(':')); | 224 EXPECT_TRUE(scanner.match(':')); |
| 228 EXPECT_TRUE(scanner.scan(':')); | 225 EXPECT_TRUE(scanner.scan(':')); |
| 229 | 226 |
| 230 word = scanner.collectWhile<lowerCaseAlpha>(); | 227 word = scanner.collectWhile<lowerCaseAlpha>(); |
| 231 String barString = scanner.extractString(word); | 228 String barString = scanner.extractString(word); |
| 232 EXPECT_EQ(barString, "bar"); | 229 EXPECT_EQ(barString, "bar"); |
| 233 EXPECT_TRUE(scanner.isAt(word.end())); | 230 EXPECT_TRUE(scanner.isAt(word.end())); |
| 234 EXPECT_TRUE(scanner.isAtEnd()); | 231 EXPECT_TRUE(scanner.isAtEnd()); |
| 235 } | 232 } |
| 236 | 233 |
| 237 // Tests extractString. | 234 // Tests extractString. |
| 238 TEST(VTTScanner, ExtractString) | 235 TEST(VTTScannerTest, ExtractString) |
| 239 { | 236 { |
| 240 TEST_WITH(scanRunsToStrings, "foo:bar"); | 237 TEST_WITH(scanRunsToStrings, "foo:bar"); |
| 241 } | 238 } |
| 242 | 239 |
| 243 void tailStringExtract(const String& input) | 240 void tailStringExtract(const String& input) |
| 244 { | 241 { |
| 245 VTTScanner scanner(input); | 242 VTTScanner scanner(input); |
| 246 EXPECT_TRUE(scanner.scan("foo")); | 243 EXPECT_TRUE(scanner.scan("foo")); |
| 247 EXPECT_TRUE(scanner.scan(':')); | 244 EXPECT_TRUE(scanner.scan(':')); |
| 248 String barSuffix = scanner.restOfInputAsString(); | 245 String barSuffix = scanner.restOfInputAsString(); |
| 249 EXPECT_EQ(barSuffix, "bar"); | 246 EXPECT_EQ(barSuffix, "bar"); |
| 250 | 247 |
| 251 EXPECT_TRUE(scanner.isAtEnd()); | 248 EXPECT_TRUE(scanner.isAtEnd()); |
| 252 } | 249 } |
| 253 | 250 |
| 254 // Tests restOfInputAsString(). | 251 // Tests restOfInputAsString(). |
| 255 TEST(VTTScanner, ExtractRestAsString) | 252 TEST(VTTScannerTest, ExtractRestAsString) |
| 256 { | 253 { |
| 257 TEST_WITH(tailStringExtract, "foo:bar"); | 254 TEST_WITH(tailStringExtract, "foo:bar"); |
| 258 } | 255 } |
| 259 | 256 |
| 260 void scanDigits1(const String& input) | 257 void scanDigits1(const String& input) |
| 261 { | 258 { |
| 262 VTTScanner scanner(input); | 259 VTTScanner scanner(input); |
| 263 EXPECT_TRUE(scanner.scan("foo")); | 260 EXPECT_TRUE(scanner.scan("foo")); |
| 264 int number; | 261 int number; |
| 265 EXPECT_EQ(scanner.scanDigits(number), 0u); | 262 EXPECT_EQ(scanner.scanDigits(number), 0u); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 291 | 288 |
| 292 EXPECT_TRUE(scanner.scan(' ')); | 289 EXPECT_TRUE(scanner.scan(' ')); |
| 293 | 290 |
| 294 EXPECT_EQ(scanner.scanDigits(number), 19u); | 291 EXPECT_EQ(scanner.scanDigits(number), 19u); |
| 295 EXPECT_EQ(number, std::numeric_limits<int>::max()); | 292 EXPECT_EQ(number, std::numeric_limits<int>::max()); |
| 296 | 293 |
| 297 EXPECT_TRUE(scanner.isAtEnd()); | 294 EXPECT_TRUE(scanner.isAtEnd()); |
| 298 } | 295 } |
| 299 | 296 |
| 300 // Tests scanDigits(). | 297 // Tests scanDigits(). |
| 301 TEST(VTTScanner, ScanDigits) | 298 TEST(VTTScannerTest, ScanDigits) |
| 302 { | 299 { |
| 303 TEST_WITH(scanDigits1, "foo 123 bar 45678"); | 300 TEST_WITH(scanDigits1, "foo 123 bar 45678"); |
| 304 TEST_WITH(scanDigits2, "-654 1000000000000000000"); | 301 TEST_WITH(scanDigits2, "-654 1000000000000000000"); |
| 305 } | 302 } |
| 306 | 303 |
| 307 void scanFloatValue(const String& input) | 304 void scanFloatValue(const String& input) |
| 308 { | 305 { |
| 309 VTTScanner scanner(input); | 306 VTTScanner scanner(input); |
| 310 float value; | 307 float value; |
| 311 // "1." | 308 // "1." |
| (...skipping 23 matching lines...) Expand all Loading... |
| 335 EXPECT_TRUE(scanner.scan(' ')); | 332 EXPECT_TRUE(scanner.scan(' ')); |
| 336 | 333 |
| 337 // "01.000" | 334 // "01.000" |
| 338 EXPECT_TRUE(scanner.scanFloat(value)); | 335 EXPECT_TRUE(scanner.scanFloat(value)); |
| 339 EXPECT_EQ(value, 1.0f); | 336 EXPECT_EQ(value, 1.0f); |
| 340 | 337 |
| 341 EXPECT_TRUE(scanner.isAtEnd()); | 338 EXPECT_TRUE(scanner.isAtEnd()); |
| 342 } | 339 } |
| 343 | 340 |
| 344 // Tests scanFloat(). | 341 // Tests scanFloat(). |
| 345 TEST(VTTScanner, ScanFloat) | 342 TEST(VTTScannerTest, ScanFloat) |
| 346 { | 343 { |
| 347 TEST_WITH(scanFloatValue, "1. 1.0 .0 . 1.0000 01.000"); | 344 TEST_WITH(scanFloatValue, "1. 1.0 .0 . 1.0000 01.000"); |
| 348 } | 345 } |
| 349 | 346 |
| 350 #undef TEST_WITH | 347 #undef TEST_WITH |
| 351 | 348 |
| 352 } // namespace | 349 } // namespace blink |
| OLD | NEW |