diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-05-16 15:14:02 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-05-17 03:08:06 +0000 |
commit | 2e9d47ac2c9a4ebf0821d10c766fafa85e6d3cb9 (patch) | |
tree | 212ca832851067eb5f40cf49c1dc2ffe81a24ada /xfa/fxfa/fm2js/cxfa_fmsimpleexpression_unittest.cpp | |
parent | 7876609b3540137663d48282ad94ba42a3749e73 (diff) | |
download | pdfium-2e9d47ac2c9a4ebf0821d10c766fafa85e6d3cb9.tar.xz |
Rename formcalc files to better match contents
Most files match the contents. The expression files are named to match
their base type even though they contain all the expression
subclasses.
Change-Id: I3b7705c7b206a9fa1afae8b677f765e8b788e84d
Reviewed-on: https://pdfium-review.googlesource.com/5492
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Nicolás Peña <npm@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa/fxfa/fm2js/cxfa_fmsimpleexpression_unittest.cpp')
-rw-r--r-- | xfa/fxfa/fm2js/cxfa_fmsimpleexpression_unittest.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/xfa/fxfa/fm2js/cxfa_fmsimpleexpression_unittest.cpp b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression_unittest.cpp new file mode 100644 index 0000000000..f11459b107 --- /dev/null +++ b/xfa/fxfa/fm2js/cxfa_fmsimpleexpression_unittest.cpp @@ -0,0 +1,76 @@ +// Copyright 2016 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_fmsimpleexpression.h" + +#include <memory> +#include <utility> + +#include "core/fxcrt/fx_string.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "testing/test_support.h" +#include "third_party/base/ptr_util.h" +#include "xfa/fxfa/fm2js/cxfa_fmlexer.h" + +TEST(FMCallExpressionTest, more_than_32_arguments) { + // Use sign as it has 3 object parameters at positions 0, 5, and 6. + auto exp = pdfium::MakeUnique<CXFA_FMIdentifierExpression>(0, L"sign"); + + std::vector<std::unique_ptr<CXFA_FMSimpleExpression>> args; + for (size_t i = 0; i < 50; i++) + args.push_back(pdfium::MakeUnique<CXFA_FMSimpleExpression>(0, TOKnan)); + + CXFA_FMCallExpression callExp(0, std::move(exp), std::move(args), true); + CFX_WideTextBuf js; + callExp.ToJavaScript(js); + + // Generate the result javascript string. + CFX_WideString result = L"sign("; + for (size_t i = 0; i < 50; i++) { + if (i > 0) + result += L", "; + + result += L"foxit_xfa_formcalc_runtime.get_fm_"; + // Object positions for sign() method. + if (i == 0 || i == 5 || i == 6) + result += L"jsobj()"; + else + result += L"value()"; + } + result += L")"; + + EXPECT_EQ(result.AsStringC(), js.AsStringC()); +} + +TEST(FMStringExpressionTest, Empty) { + CFX_WideTextBuf accumulator; + CXFA_FMStringExpression(1, CFX_WideStringC()).ToJavaScript(accumulator); + EXPECT_EQ(L"", accumulator.AsStringC()); +} + +TEST(FMStringExpressionTest, Short) { + CFX_WideTextBuf accumulator; + CXFA_FMStringExpression(1, L"a").ToJavaScript(accumulator); + EXPECT_EQ(L"a", accumulator.AsStringC()); +} + +TEST(FMStringExpressionTest, Medium) { + CFX_WideTextBuf accumulator; + CXFA_FMStringExpression(1, L".abcd.").ToJavaScript(accumulator); + EXPECT_EQ(L"\"abcd\"", accumulator.AsStringC()); +} + +TEST(FMStringExpressionTest, Long) { + CFX_WideTextBuf accumulator; + std::vector<CFX_WideStringC::UnsignedType> vec(140000, L'A'); + CXFA_FMStringExpression(1, CFX_WideStringC(vec)).ToJavaScript(accumulator); + EXPECT_EQ(140000, accumulator.GetLength()); +} + +TEST(FMStringExpressionTest, Quoted) { + CFX_WideTextBuf accumulator; + CXFA_FMStringExpression(1, L".Simon says \"\"run\"\".") + .ToJavaScript(accumulator); + EXPECT_EQ(L"\"Simon says \\\"run\\\"\"", accumulator.AsStringC()); +} |