Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cfx_cssvaluelistparser_unittest.cpp
Go to the documentation of this file.
1// Copyright 2017 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "core/fxcrt/css/cfx_cssvaluelistparser.h"
8
9#include <memory>
10
11#include "core/fxcrt/widestring.h"
12#include "testing/gtest/include/gtest/gtest.h"
13
15 auto parser = std::make_unique<CFX_CSSValueListParser>(L"#abc", L' ');
16 auto maybe_next = parser->NextValue();
17 ASSERT_TRUE(maybe_next.has_value());
18 EXPECT_EQ(CFX_CSSValue::PrimitiveType::kRGB, maybe_next.value().type);
19 EXPECT_EQ(L"#abc", maybe_next.value().string_view);
20 EXPECT_FALSE(parser->NextValue());
21
22 parser = std::make_unique<CFX_CSSValueListParser>(L"#abcdef", L' ');
23 maybe_next = parser->NextValue();
24 ASSERT_TRUE(maybe_next.has_value());
25 EXPECT_EQ(CFX_CSSValue::PrimitiveType::kRGB, maybe_next.value().type);
26 EXPECT_EQ(L"#abcdef", maybe_next.value().string_view);
27
28 parser = std::make_unique<CFX_CSSValueListParser>(L"rgb(1, 255, 4)", L' ');
29 maybe_next = parser->NextValue();
30 ASSERT_TRUE(maybe_next.has_value());
31 EXPECT_EQ(CFX_CSSValue::PrimitiveType::kRGB, maybe_next.value().type);
32 EXPECT_EQ(L"rgb(1, 255, 4)", maybe_next.value().string_view);
33
34 parser = std::make_unique<CFX_CSSValueListParser>(L"#abcdefghij", L' ');
35 maybe_next = parser->NextValue();
36 ASSERT_TRUE(maybe_next.has_value());
37 EXPECT_EQ(CFX_CSSValue::PrimitiveType::kUnknown, maybe_next.value().type);
38 EXPECT_EQ(L"#abcdefghij", maybe_next.value().string_view);
39 EXPECT_FALSE(parser->NextValue());
40}
41
43 auto parser = std::make_unique<CFX_CSSValueListParser>(L"1234", L' ');
44 auto maybe_next = parser->NextValue();
45 ASSERT_TRUE(maybe_next.has_value());
46 EXPECT_EQ(CFX_CSSValue::PrimitiveType::kNumber, maybe_next.value().type);
47 EXPECT_EQ(L"1234", maybe_next.value().string_view);
48
49 parser = std::make_unique<CFX_CSSValueListParser>(L"-1234", L' ');
50 maybe_next = parser->NextValue();
51 ASSERT_TRUE(maybe_next.has_value());
52 EXPECT_EQ(CFX_CSSValue::PrimitiveType::kNumber, maybe_next.value().type);
53 EXPECT_EQ(L"-1234", maybe_next.value().string_view);
54
55 parser = std::make_unique<CFX_CSSValueListParser>(L"+1234", L' ');
56 maybe_next = parser->NextValue();
57 ASSERT_TRUE(maybe_next.has_value());
58 EXPECT_EQ(CFX_CSSValue::PrimitiveType::kNumber, maybe_next.value().type);
59 EXPECT_EQ(L"+1234", maybe_next.value().string_view);
60
61 parser = std::make_unique<CFX_CSSValueListParser>(L".1234", L' ');
62 maybe_next = parser->NextValue();
63 ASSERT_TRUE(maybe_next.has_value());
64 EXPECT_EQ(CFX_CSSValue::PrimitiveType::kNumber, maybe_next.value().type);
65 EXPECT_EQ(L".1234", maybe_next.value().string_view);
66
67 parser = std::make_unique<CFX_CSSValueListParser>(L"4321.1234", L' ');
68 maybe_next = parser->NextValue();
69 ASSERT_TRUE(maybe_next.has_value());
70 EXPECT_EQ(CFX_CSSValue::PrimitiveType::kNumber, maybe_next.value().type);
71 EXPECT_EQ(L"4321.1234", maybe_next.value().string_view);
72
73 // TODO(dsinclair): These should probably fail but currently don't.
74 parser = std::make_unique<CFX_CSSValueListParser>(L"4321.12.34", L' ');
75 maybe_next = parser->NextValue();
76 ASSERT_TRUE(maybe_next.has_value());
77 EXPECT_EQ(CFX_CSSValue::PrimitiveType::kNumber, maybe_next.value().type);
78 EXPECT_EQ(L"4321.12.34", maybe_next.value().string_view);
79
80 parser = std::make_unique<CFX_CSSValueListParser>(L"43a1.12.34", L' ');
81 maybe_next = parser->NextValue();
82 ASSERT_TRUE(maybe_next.has_value());
83 EXPECT_EQ(CFX_CSSValue::PrimitiveType::kNumber, maybe_next.value().type);
84 EXPECT_EQ(L"43a1.12.34", maybe_next.value().string_view);
85}
86
88 auto parser = std::make_unique<CFX_CSSValueListParser>(L"'string'", L' ');
89 auto maybe_next = parser->NextValue();
90 ASSERT_TRUE(maybe_next.has_value());
91 EXPECT_EQ(CFX_CSSValue::PrimitiveType::kString, maybe_next.value().type);
92 EXPECT_EQ(L"string", maybe_next.value().string_view);
93
94 parser =
95 std::make_unique<CFX_CSSValueListParser>(L"\"another string\"", L' ');
96 maybe_next = parser->NextValue();
97 ASSERT_TRUE(maybe_next.has_value());
98 EXPECT_EQ(CFX_CSSValue::PrimitiveType::kString, maybe_next.value().type);
99 EXPECT_EQ(L"another string", maybe_next.value().string_view);
100
101 parser = std::make_unique<CFX_CSSValueListParser>(L"standalone", L' ');
102 maybe_next = parser->NextValue();
103 ASSERT_TRUE(maybe_next.has_value());
104 EXPECT_EQ(CFX_CSSValue::PrimitiveType::kString, maybe_next.value().type);
105 EXPECT_EQ(L"standalone", maybe_next.value().string_view);
106}
107
109 auto parser = std::make_unique<CFX_CSSValueListParser>(L"1, 2, 3", L',');
110 auto maybe_next = parser->NextValue();
111 ASSERT_TRUE(maybe_next.has_value());
112 EXPECT_EQ(CFX_CSSValue::PrimitiveType::kNumber, maybe_next.value().type);
113 EXPECT_EQ(L"1", maybe_next.value().string_view);
114
115 maybe_next = parser->NextValue();
116 ASSERT_TRUE(maybe_next.has_value());
117 EXPECT_EQ(CFX_CSSValue::PrimitiveType::kNumber, maybe_next.value().type);
118 EXPECT_EQ(L"2", maybe_next.value().string_view);
119
120 maybe_next = parser->NextValue();
121 ASSERT_TRUE(maybe_next.has_value());
122 EXPECT_EQ(CFX_CSSValue::PrimitiveType::kNumber, maybe_next.value().type);
123 EXPECT_EQ(L"3", maybe_next.value().string_view);
124
125 EXPECT_FALSE(parser->NextValue());
126
127 parser =
128 std::make_unique<CFX_CSSValueListParser>(L"'str', rgb(1, 2, 3), 4", L',');
129 maybe_next = parser->NextValue();
130 ASSERT_TRUE(maybe_next.has_value());
131 EXPECT_EQ(CFX_CSSValue::PrimitiveType::kString, maybe_next.value().type);
132 EXPECT_EQ(L"str", maybe_next.value().string_view);
133
134 maybe_next = parser->NextValue();
135 ASSERT_TRUE(maybe_next.has_value());
136 EXPECT_EQ(CFX_CSSValue::PrimitiveType::kRGB, maybe_next.value().type);
137 EXPECT_EQ(L"rgb(1, 2, 3)", maybe_next.value().string_view);
138
139 maybe_next = parser->NextValue();
140 ASSERT_TRUE(maybe_next.has_value());
141 EXPECT_EQ(CFX_CSSValue::PrimitiveType::kNumber, maybe_next.value().type);
142 EXPECT_EQ(L"4", maybe_next.value().string_view);
143}
TEST(FXCRYPT, MD5GenerateEmtpyData)