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
cxfa_fmexpression_unittest.cpp
Go to the documentation of this file.
1// Copyright 2018 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#include "xfa/fxfa/formcalc/cxfa_fmexpression.h"
6
7#include <utility>
8
9#include "core/fxcrt/fx_string.h"
10#include "core/fxcrt/widetext_buffer.h"
11#include "testing/fxgc_unittest.h"
12#include "testing/gtest/include/gtest/gtest.h"
13#include "v8/include/cppgc/heap.h"
14#include "xfa/fxfa/formcalc/cxfa_fmlexer.h"
15#include "xfa/fxfa/formcalc/cxfa_fmtojavascriptdepth.h"
16
20
22 // Use sign as it has 3 object parameters at positions 0, 5, and 6.
23 auto* exp = cppgc::MakeGarbageCollected<CXFA_FMIdentifierExpression>(
24 heap()->GetAllocationHandle(), L"sign");
25
26 std::vector<cppgc::Member<CXFA_FMSimpleExpression>> args;
27 for (size_t i = 0; i < 50; i++) {
28 args.push_back(cppgc::MakeGarbageCollected<CXFA_FMNullExpression>(
29 heap()->GetAllocationHandle()));
30 }
32 auto* callExp = cppgc::MakeGarbageCollected<CXFA_FMCallExpression>(
33 heap()->GetAllocationHandle(), exp, std::move(args), true);
34
35 WideTextBuffer js;
36 callExp->ToJavaScript(&js, CXFA_FMAssignExpression::ReturnType::kInferred);
37
38 // Generate the result javascript string.
39 WideString result = L"sign(";
40 for (size_t i = 0; i < 50; i++) {
41 if (i > 0)
42 result += L", ";
43
44 result += L"pfm_rt.get_";
45 // Object positions for sign() method.
46 if (i == 0 || i == 5 || i == 6)
47 result += L"jsobj(null)";
48 else
49 result += L"val(null)";
50 }
51 result += L")";
52
53 EXPECT_EQ(result.AsStringView(), js.AsStringView());
54}
55
58 WideTextBuffer accumulator;
59 auto* exp = cppgc::MakeGarbageCollected<CXFA_FMStringExpression>(
60 heap()->GetAllocationHandle(), L"");
61 exp->ToJavaScript(&accumulator,
62 CXFA_FMAssignExpression::ReturnType::kInferred);
63 EXPECT_EQ(L"", accumulator.AsStringView());
64}
65
68 WideTextBuffer accumulator;
69 auto* exp = cppgc::MakeGarbageCollected<CXFA_FMStringExpression>(
70 heap()->GetAllocationHandle(), L"a");
71 exp->ToJavaScript(&accumulator,
72 CXFA_FMAssignExpression::ReturnType::kInferred);
73 EXPECT_EQ(L"a", accumulator.AsStringView());
74}
75
78 WideTextBuffer accumulator;
79 auto* exp = cppgc::MakeGarbageCollected<CXFA_FMStringExpression>(
80 heap()->GetAllocationHandle(), L".abcd.");
81 exp->ToJavaScript(&accumulator,
82 CXFA_FMAssignExpression::ReturnType::kInferred);
83 EXPECT_EQ(L"\"abcd\"", accumulator.AsStringView());
84}
85
88 WideTextBuffer accumulator;
89 std::vector<WideStringView::UnsignedType> vec(140000, L'A');
90 auto* exp = cppgc::MakeGarbageCollected<CXFA_FMStringExpression>(
91 heap()->GetAllocationHandle(), WideString(WideStringView(vec)));
92 exp->ToJavaScript(&accumulator,
93 CXFA_FMAssignExpression::ReturnType::kInferred);
94 EXPECT_EQ(140000u, accumulator.GetLength());
95}
96
99 WideTextBuffer accumulator;
100 auto* exp = cppgc::MakeGarbageCollected<CXFA_FMStringExpression>(
101 heap()->GetAllocationHandle(), L".Simon says \"\"run\"\".");
102 exp->ToJavaScript(&accumulator,
103 CXFA_FMAssignExpression::ReturnType::kInferred);
104 EXPECT_EQ(L"\"Simon says \\\"run\\\"\"", accumulator.AsStringView());
105}
106
109 WideTextBuffer accumulator;
110
111 auto* expr = cppgc::MakeGarbageCollected<CXFA_FMVarExpression>(
112 heap()->GetAllocationHandle(), L"s", nullptr);
113 expr->ToJavaScript(&accumulator,
114 CXFA_FMAssignExpression::ReturnType::kInferred);
115 EXPECT_STREQ(
116 LR"***(var s = "";
117)***",
118 accumulator.MakeString().c_str());
119}
120
123 WideTextBuffer accumulator;
124
125 auto* init = cppgc::MakeGarbageCollected<CXFA_FMStringExpression>(
126 heap()->GetAllocationHandle(), LR"("")");
127 auto* expr = cppgc::MakeGarbageCollected<CXFA_FMVarExpression>(
128 heap()->GetAllocationHandle(), L"s", init);
129 expr->ToJavaScript(&accumulator,
130 CXFA_FMAssignExpression::ReturnType::kInferred);
131 EXPECT_STREQ(
132 LR"***(var s = "";
133s = pfm_rt.var_filter(s);
134)***",
135 accumulator.MakeString().c_str());
136}
137
140 WideTextBuffer accumulator;
141
142 auto* init = cppgc::MakeGarbageCollected<CXFA_FMStringExpression>(
143 heap()->GetAllocationHandle(), LR"("foo")");
144 auto* expr = cppgc::MakeGarbageCollected<CXFA_FMVarExpression>(
145 heap()->GetAllocationHandle(), L"s", init);
146 expr->ToJavaScript(&accumulator,
147 CXFA_FMAssignExpression::ReturnType::kInferred);
148 EXPECT_STREQ(
149 LR"***(var s = "foo";
150s = pfm_rt.var_filter(s);
151)***",
152 accumulator.MakeString().c_str());
153}
154
157 WideTextBuffer accumulator;
158
159 auto* init = cppgc::MakeGarbageCollected<CXFA_FMNumberExpression>(
160 heap()->GetAllocationHandle(), L"112");
161 auto* expr = cppgc::MakeGarbageCollected<CXFA_FMVarExpression>(
162 heap()->GetAllocationHandle(), L"s", init);
163 expr->ToJavaScript(&accumulator,
164 CXFA_FMAssignExpression::ReturnType::kInferred);
165 EXPECT_STREQ(
166 LR"***(var s = 112;
167s = pfm_rt.var_filter(s);
168)***",
169 accumulator.MakeString().c_str());
170}
WideString & operator+=(const wchar_t *str)
const wchar_t * c_str() const
Definition widestring.h:81
WideString MakeString() const
WideStringView AsStringView() const
TEST_F(FMExpressionTest, VarExpressionInitNull)
TEST_F(FMCallExpressionTest, more_than_32_arguments)
TEST_F(FMStringExpressionTest, Empty)