summaryrefslogtreecommitdiff
path: root/xfa/fde/css/cfde_cssvaluelistparser_unittest.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-02-07 11:47:24 -0500
committerChromium commit bot <commit-bot@chromium.org>2017-02-08 14:07:04 +0000
commit36c18c872addaa2d5cc36d1b218f8d2dc22a38be (patch)
tree6eaeb93a8566b8efca547600cb20d4b6253b7949 /xfa/fde/css/cfde_cssvaluelistparser_unittest.cpp
parent071d78690a4e2becffaeeb32fe210ee58ab3e532 (diff)
downloadpdfium-36c18c872addaa2d5cc36d1b218f8d2dc22a38be.tar.xz
Add CFDE_CSSValueListParser tests
This Cl adds some unit tests for the CFDE_CSSValueListParser prior to refactoring. Change-Id: I2b32775ea1e70b721f5902cd3d88d68a01166d5e Reviewed-on: https://pdfium-review.googlesource.com/2535 Reviewed-by: Tom Sepez <tsepez@chromium.org> Reviewed-by: Nicolás Peña <npm@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fde/css/cfde_cssvaluelistparser_unittest.cpp')
-rw-r--r--xfa/fde/css/cfde_cssvaluelistparser_unittest.cpp142
1 files changed, 142 insertions, 0 deletions
diff --git a/xfa/fde/css/cfde_cssvaluelistparser_unittest.cpp b/xfa/fde/css/cfde_cssvaluelistparser_unittest.cpp
new file mode 100644
index 0000000000..71bb807f3d
--- /dev/null
+++ b/xfa/fde/css/cfde_cssvaluelistparser_unittest.cpp
@@ -0,0 +1,142 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "xfa/fde/css/cfde_cssvaluelistparser.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/base/ptr_util.h"
+
+TEST(CFDE_CSSValueListParser, rgb_short) {
+ FDE_CSSPrimitiveType type;
+ const FX_WCHAR* start;
+ int32_t len;
+
+ auto parser = pdfium::MakeUnique<CFDE_CSSValueListParser>(L"#abc", 4, L' ');
+ EXPECT_TRUE(parser->NextValue(type, start, len));
+ EXPECT_EQ(FDE_CSSPrimitiveType::RGB, type);
+ EXPECT_EQ(L"#abc", CFX_WideString(start, len));
+ EXPECT_FALSE(parser->NextValue(type, start, len));
+
+ parser = pdfium::MakeUnique<CFDE_CSSValueListParser>(L"#abcdef", 7, L' ');
+ EXPECT_TRUE(parser->NextValue(type, start, len));
+ EXPECT_EQ(FDE_CSSPrimitiveType::RGB, type);
+ EXPECT_EQ(L"#abcdef", CFX_WideString(start, len));
+ EXPECT_FALSE(parser->NextValue(type, start, len));
+
+ parser =
+ pdfium::MakeUnique<CFDE_CSSValueListParser>(L"rgb(1, 255, 4)", 14, L' ');
+ EXPECT_TRUE(parser->NextValue(type, start, len));
+ EXPECT_EQ(FDE_CSSPrimitiveType::RGB, type);
+ EXPECT_EQ(L"rgb(1, 255, 4)", CFX_WideString(start, len));
+
+ parser =
+ pdfium::MakeUnique<CFDE_CSSValueListParser>(L"#abcdefghij", 11, L' ');
+ EXPECT_TRUE(parser->NextValue(type, start, len));
+ EXPECT_EQ(FDE_CSSPrimitiveType::Unknown, type);
+ EXPECT_EQ(L"#abcdefghij", CFX_WideString(start, len));
+ EXPECT_FALSE(parser->NextValue(type, start, len));
+}
+
+TEST(CFDE_CSSValueListParser, number_parsing) {
+ FDE_CSSPrimitiveType type;
+ const FX_WCHAR* start;
+ int32_t len;
+
+ auto parser = pdfium::MakeUnique<CFDE_CSSValueListParser>(L"1234", 4, L' ');
+ EXPECT_TRUE(parser->NextValue(type, start, len));
+ EXPECT_EQ(FDE_CSSPrimitiveType::Number, type);
+ EXPECT_EQ(L"1234", CFX_WideString(start, len));
+
+ parser = pdfium::MakeUnique<CFDE_CSSValueListParser>(L"-1234", 5, L' ');
+ EXPECT_TRUE(parser->NextValue(type, start, len));
+ EXPECT_EQ(FDE_CSSPrimitiveType::Number, type);
+ EXPECT_EQ(L"-1234", CFX_WideString(start, len));
+
+ parser = pdfium::MakeUnique<CFDE_CSSValueListParser>(L"+1234", 5, L' ');
+ EXPECT_TRUE(parser->NextValue(type, start, len));
+ EXPECT_EQ(FDE_CSSPrimitiveType::Number, type);
+ EXPECT_EQ(L"+1234", CFX_WideString(start, len));
+
+ parser = pdfium::MakeUnique<CFDE_CSSValueListParser>(L".1234", 5, L' ');
+ EXPECT_TRUE(parser->NextValue(type, start, len));
+ EXPECT_EQ(FDE_CSSPrimitiveType::Number, type);
+ EXPECT_EQ(L".1234", CFX_WideString(start, len));
+
+ parser = pdfium::MakeUnique<CFDE_CSSValueListParser>(L"4321.1234", 9, L' ');
+ EXPECT_TRUE(parser->NextValue(type, start, len));
+ EXPECT_EQ(FDE_CSSPrimitiveType::Number, type);
+ EXPECT_EQ(L"4321.1234", CFX_WideString(start, len));
+
+ // TODO(dsinclair): These should probably fail but currently don't.
+ parser = pdfium::MakeUnique<CFDE_CSSValueListParser>(L"4321.12.34", 10, L' ');
+ EXPECT_TRUE(parser->NextValue(type, start, len));
+ EXPECT_EQ(FDE_CSSPrimitiveType::Number, type);
+ EXPECT_EQ(L"4321.12.34", CFX_WideString(start, len));
+
+ parser = pdfium::MakeUnique<CFDE_CSSValueListParser>(L"43a1.12.34", 10, L' ');
+ EXPECT_TRUE(parser->NextValue(type, start, len));
+ EXPECT_EQ(FDE_CSSPrimitiveType::Number, type);
+ EXPECT_EQ(L"43a1.12.34", CFX_WideString(start, len));
+}
+
+TEST(CFDE_CSSValueListParser, string_parsing) {
+ FDE_CSSPrimitiveType type;
+ const FX_WCHAR* start;
+ int32_t len;
+
+ auto parser =
+ pdfium::MakeUnique<CFDE_CSSValueListParser>(L"'string'", 8, L' ');
+ EXPECT_TRUE(parser->NextValue(type, start, len));
+ EXPECT_EQ(FDE_CSSPrimitiveType::String, type);
+ EXPECT_EQ(L"string", CFX_WideString(start, len));
+
+ parser = pdfium::MakeUnique<CFDE_CSSValueListParser>(L"\"another string\"",
+ 16, L' ');
+ EXPECT_TRUE(parser->NextValue(type, start, len));
+ EXPECT_EQ(FDE_CSSPrimitiveType::String, type);
+ EXPECT_EQ(L"another string", CFX_WideString(start, len));
+
+ parser = pdfium::MakeUnique<CFDE_CSSValueListParser>(L"standalone", 10, L' ');
+ EXPECT_TRUE(parser->NextValue(type, start, len));
+ EXPECT_EQ(FDE_CSSPrimitiveType::String, type);
+ EXPECT_EQ(L"standalone", CFX_WideString(start, len));
+}
+
+TEST(CFDE_CSSValueListParser, multiparsing) {
+ FDE_CSSPrimitiveType type;
+ const FX_WCHAR* start;
+ int32_t len;
+
+ auto parser =
+ pdfium::MakeUnique<CFDE_CSSValueListParser>(L"1, 2, 3", 7, L',');
+ EXPECT_TRUE(parser->NextValue(type, start, len));
+ EXPECT_EQ(FDE_CSSPrimitiveType::Number, type);
+ EXPECT_EQ(L"1", CFX_WideString(start, len));
+
+ EXPECT_TRUE(parser->NextValue(type, start, len));
+ EXPECT_EQ(FDE_CSSPrimitiveType::Number, type);
+ EXPECT_EQ(L"2", CFX_WideString(start, len));
+
+ EXPECT_TRUE(parser->NextValue(type, start, len));
+ EXPECT_EQ(FDE_CSSPrimitiveType::Number, type);
+ EXPECT_EQ(L"3", CFX_WideString(start, len));
+
+ EXPECT_FALSE(parser->NextValue(type, start, len));
+
+ parser = pdfium::MakeUnique<CFDE_CSSValueListParser>(
+ L"'str', rgb(1, 2, 3), 4", 22, L',');
+ EXPECT_TRUE(parser->NextValue(type, start, len));
+ EXPECT_EQ(FDE_CSSPrimitiveType::String, type);
+ EXPECT_EQ(L"str", CFX_WideString(start, len));
+
+ EXPECT_TRUE(parser->NextValue(type, start, len));
+ EXPECT_EQ(FDE_CSSPrimitiveType::RGB, type);
+ EXPECT_EQ(L"rgb(1, 2, 3)", CFX_WideString(start, len));
+
+ EXPECT_TRUE(parser->NextValue(type, start, len));
+ EXPECT_EQ(FDE_CSSPrimitiveType::Number, type);
+ EXPECT_EQ(L"4", CFX_WideString(start, len));
+}