OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 #include "core/css/parser/SizesCalcParser.h" | |
7 | |
8 #include "core/css/MediaValuesCached.h" | |
9 #include "core/css/parser/MediaQueryTokenizer.h" | |
10 | |
11 #include <gtest/gtest.h> | |
12 | |
13 namespace WebCore { | |
14 | |
15 typedef struct { | |
16 const char* input; | |
17 const unsigned output; | |
18 const bool valid; | |
19 } TestCase; | |
alancutter (OOO until 2018)
2014/04/30 04:02:17
struct TestCase {}; notation would be preferred.
| |
20 | |
21 TEST(SizesCalcParserTest, Basic) | |
22 { | |
23 // The first string represents the input string. | |
24 // The second string represents the output string, if present. | |
25 // Otherwise, the output string is identical to the first string. | |
alancutter (OOO until 2018)
2014/04/30 04:02:17
This comment doesn't seem to match the struct. The
| |
26 TestCase testCases[] = { | |
27 {"calc(500px + 10em)", 660, true}, | |
28 {"calc(500px + 2 * 10em)", 820, true}, | |
29 {"calc(500px + 2*10em)", 820, true}, | |
30 {"calc(500px + 0.5*10em)", 580, true}, | |
31 {"calc(500px + (0.5*10em + 13px))", 593, true}, | |
32 {"calc(100vw + (0.5*10em + 13px))", 593, true}, | |
33 {"calc(100vh + (0.5*10em + 13px))", 736, true}, | |
34 {"calc(100vh + calc(0.5*10em + 13px))", 736, true}, | |
35 {"calc(100vh + (50%*10em + 13px))", 0, false}, | |
36 {"calc(50em+13px)", 0, false}, | |
37 {"calc(50em-13px)", 0, false}, | |
38 {"calc(500px + 10)", 0, false}, | |
39 {"calc(500 + 10)", 0, false}, | |
40 {"calc(500px + 10s)", 0, false}, | |
41 {"calc(500px + 1cm)", 537, true}, | |
42 {"calc(500px - 10s)", 0, false}, | |
43 {"calc(500px - 1cm)", 463, true}, | |
44 {"calc(50px*10)", 500, true}, | |
45 {"calc(50px*10px)", 0, false}, | |
46 {"calc(50px/10px)", 0, false}, | |
47 {"calc(500px/10)", 50, true}, | |
48 {"calc(500/10)", 0, false}, | |
49 {"calc(500px/0.5)", 1000, true}, | |
50 {"calc(500px/.5)", 1000, true}, | |
51 {"calc(500/0)", 0, false}, | |
52 {"calc(500px/0)", 0, false}, | |
53 {"calc(-500px/10)", 0, true}, | |
54 {0, 0, true} // Do not remove the terminator line. | |
alancutter (OOO until 2018)
2014/04/30 04:02:17
It would be good to see more invalid inputs tested
| |
55 }; | |
56 | |
57 | |
58 MediaValuesCached::MediaValuesCachedData data; | |
59 data.viewportWidth = 500; | |
60 data.viewportHeight = 643; | |
61 data.deviceWidth = 500; | |
62 data.deviceHeight = 643; | |
63 data.devicePixelRatio = 2.0; | |
64 data.colorBitsPerComponent = 24; | |
65 data.monochromeBitsPerComponent = 0; | |
66 data.pointer = MediaValues::MousePointer; | |
67 data.defaultFontSize = 16; | |
68 data.threeDEnabled = true; | |
69 data.scanMediaType = false; | |
70 data.screenMediaType = true; | |
71 data.printMediaType = false; | |
72 data.strictMode = true; | |
73 RefPtr<MediaValues> mediaValues = MediaValuesCached::create(data); | |
74 | |
75 for (unsigned i = 0; testCases[i].input; ++i) { | |
76 Vector<MediaQueryToken> tokens; | |
77 MediaQueryTokenizer::tokenize(testCases[i].input, tokens); | |
78 unsigned output; | |
79 bool valid = SizesCalcParser::parse(tokens.begin(), tokens.end(), mediaV alues, output); | |
80 ASSERT_EQ(testCases[i].valid, valid); | |
81 if (valid) | |
82 ASSERT_EQ(testCases[i].output, output); | |
83 } | |
84 } | |
85 | |
86 } // namespace | |
OLD | NEW |