summaryrefslogtreecommitdiff
path: root/xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2017-07-27 14:53:20 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-07-27 20:16:52 +0000
commitdb1e8a500588abb98026bafac376b953f61813d2 (patch)
treef96181361d5acb18a11f60a09035f213264eaa75 /xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp
parent5b45c540a2bdfedd0711139e0f1256faaee2ef83 (diff)
downloadpdfium-db1e8a500588abb98026bafac376b953f61813d2.tar.xz
Move CXFA_FMParse to CFXA_FMParser
Minor nit I had with this code and want to fix. Bug: Change-Id: I2494667d580bf982a4359153123d9e8afb75e349 Reviewed-on: https://pdfium-review.googlesource.com/9370 Reviewed-by: Tom Sepez <tsepez@chromium.org> Reviewed-by: (OOO Jul 28 - Aug 8) dsinclair <dsinclair@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp')
-rw-r--r--xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp b/xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp
new file mode 100644
index 0000000000..9907890e83
--- /dev/null
+++ b/xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp
@@ -0,0 +1,109 @@
+// 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.
+
+#include "xfa/fxfa/fm2js/cxfa_fmparser.h"
+
+#include <vector>
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/test_support.h"
+#include "third_party/base/ptr_util.h"
+
+TEST(CXFA_FMParserTest, Empty) {
+ auto parser = pdfium::MakeUnique<CXFA_FMParser>(L"");
+ std::unique_ptr<CXFA_FMFunctionDefinition> ast = parser->Parse();
+ ASSERT(ast != nullptr);
+ EXPECT_FALSE(parser->HasError());
+
+ CFX_WideTextBuf buf;
+ EXPECT_TRUE(ast->ToJavaScript(buf));
+ // TODO(dsinclair): This is a little weird .....
+ EXPECT_EQ(L"// comments only", buf.AsStringC());
+}
+
+TEST(CXFA_FMParserTest, CommentOnlyIsError) {
+ auto parser = pdfium::MakeUnique<CXFA_FMParser>(L"; Just comment");
+ std::unique_ptr<CXFA_FMFunctionDefinition> ast = parser->Parse();
+ ASSERT(ast != nullptr);
+ // TODO(dsinclair): This isn't allowed per the spec.
+ EXPECT_FALSE(parser->HasError());
+ // EXPECT_TRUE(parser->HasError());
+
+ CFX_WideTextBuf buf;
+ EXPECT_TRUE(ast->ToJavaScript(buf));
+ EXPECT_EQ(L"// comments only", buf.AsStringC());
+}
+
+TEST(CXFA_FMParserTest, CommentThenValue) {
+ const wchar_t ret[] =
+ L"(\nfunction ()\n{\n"
+ L"var pfm_ret = null;\n"
+ L"pfm_ret = 12;\n"
+ L"return pfm_rt.get_val(pfm_ret);\n"
+ L"}\n).call(this);\n";
+
+ auto parser = pdfium::MakeUnique<CXFA_FMParser>(L"; Just comment\n12");
+ std::unique_ptr<CXFA_FMFunctionDefinition> ast = parser->Parse();
+ ASSERT(ast != nullptr);
+ EXPECT_FALSE(parser->HasError());
+
+ CFX_WideTextBuf buf;
+ EXPECT_TRUE(ast->ToJavaScript(buf));
+ EXPECT_EQ(ret, buf.AsStringC());
+}
+
+TEST(CXFA_FMParserTest, Parse) {
+ const wchar_t input[] =
+ L"$ = Avg (-3, 5, -6, 12, -13);\n"
+ L"$ = Avg (Table2..Row[*].Cell1);\n"
+ L"\n"
+ L"if ($ ne -1)then\n"
+ L" border.fill.color.value = \"255,64,64\";\n"
+ L"else\n"
+ L" border.fill.color.value = \"20,170,13\";\n"
+ L"endif\n"
+ L"\n"
+ L"$";
+
+ const wchar_t ret[] =
+ L"(\nfunction ()\n{\n"
+ L"var pfm_ret = null;\n"
+ L"if (pfm_rt.is_obj(this))\n{\n"
+ L"pfm_rt.asgn_val_op(this, pfm_rt.Avg(pfm_rt.neg_op(3), 5, "
+ L"pfm_rt.neg_op(6), 12, pfm_rt.neg_op(13)));\n"
+ L"}\n"
+ L"if (pfm_rt.is_obj(this))\n{\n"
+ L"pfm_rt.asgn_val_op(this, pfm_rt.Avg(pfm_rt.dot_acc(pfm_rt.dotdot_acc("
+ L"Table2, \"Table2\", \"Row\", 1), \"\", \"Cell1\", 0, 0)));\n"
+ L"}\n"
+ L"if (pfm_rt.get_val(pfm_rt.neq_op(this, pfm_rt.neg_op(1))))\n{\n"
+ L"if (pfm_rt.is_obj(pfm_rt.dot_acc(pfm_rt.dot_acc(pfm_rt.dot_acc("
+ L"border, \"border\", \"fill\", 0, 0), \"\", \"color\", 0, 0), \"\", "
+ L"\"value\", 0, 0)))\n{\n"
+ L"pfm_rt.asgn_val_op(pfm_rt.dot_acc(pfm_rt.dot_acc("
+ L"pfm_rt.dot_acc(border, \"border\", \"fill\", 0, 0), \"\", "
+ L"\"color\", 0, 0), \"\", \"value\", 0, 0), \"255,64,64\");\n"
+ L"}\n"
+ L"}\nelse\n{\n"
+ L"if (pfm_rt.is_obj(pfm_rt.dot_acc(pfm_rt.dot_acc(pfm_rt.dot_acc("
+ L"border, \"border\", \"fill\", 0, 0), \"\", \"color\", 0, 0), \"\", "
+ L"\"value\", 0, 0)))\n{\n"
+ L"pfm_rt.asgn_val_op(pfm_rt.dot_acc(pfm_rt.dot_acc("
+ L"pfm_rt.dot_acc(border, \"border\", \"fill\", 0, 0), \"\", "
+ L"\"color\", 0, 0), \"\", \"value\", 0, 0), \"20,170,13\");\n"
+ L"}\n"
+ L"}\n"
+ L"pfm_ret = this;\n"
+ L"return pfm_rt.get_val(pfm_ret);\n"
+ L"}\n).call(this);\n";
+
+ auto parser = pdfium::MakeUnique<CXFA_FMParser>(input);
+ std::unique_ptr<CXFA_FMFunctionDefinition> ast = parser->Parse();
+ ASSERT(ast != nullptr);
+ EXPECT_FALSE(parser->HasError());
+
+ CFX_WideTextBuf buf;
+ EXPECT_TRUE(ast->ToJavaScript(buf));
+ EXPECT_EQ(ret, buf.AsStringC());
+}