8#include "fxjs/xfa/cfxjse_engine.h"
9#include "fxjs/xfa/cfxjse_isolatetracker.h"
10#include "fxjs/xfa/cfxjse_value.h"
11#include "testing/gtest/include/gtest/gtest.h"
12#include "testing/scoped_set_tz.h"
13#include "testing/xfa_js_embedder_test.h"
14#include "xfa/fxfa/cxfa_eventparam.h"
27 EXPECT_FALSE(
Execute(input
)) <<
"Program: " << input;
31 EXPECT_TRUE(
Execute(input
)) <<
"Program: " << input;
34 EXPECT_TRUE(fxv8::IsNull(GetValue())) <<
"Program: " << input;
38 EXPECT_TRUE(
Execute(input
)) <<
"Program: " << input;
41 v8::Local<v8::Value> value = GetValue();
44 EXPECT_TRUE(fxv8::IsBoolean(value) || fxv8::IsInteger(value))
45 <<
"Program: " << input;
46 EXPECT_EQ(expected, fxv8::ReentrantToBooleanHelper(isolate(), value))
47 <<
"Program: " << input;
51 EXPECT_TRUE(
Execute(input
)) <<
"Program: " << input;
54 v8::Local<v8::Value> value = GetValue();
55 EXPECT_TRUE(fxv8::IsInteger(value)) <<
"Program: " << input;
56 EXPECT_EQ(expected, fxv8::ReentrantToInt32Helper(isolate(), value))
57 <<
"Program: " << input;
61 EXPECT_TRUE(
Execute(input
)) <<
"Program: " << input;
64 v8::Local<v8::Value> value = GetValue();
65 EXPECT_TRUE(fxv8::IsNumber(value));
66 EXPECT_FLOAT_EQ(expected, fxv8::ReentrantToFloatHelper(isolate(), value))
67 <<
"Program: " << input;
71 constexpr float kPrecision = 0.000001f;
73 EXPECT_TRUE(
Execute(input
)) <<
"Program: " << input;
76 v8::Local<v8::Value> value = GetValue();
77 EXPECT_TRUE(fxv8::IsNumber(value));
78 EXPECT_NEAR(expected, fxv8::ReentrantToFloatHelper(isolate(), value),
80 <<
"Program: " << input;
84 EXPECT_TRUE(
Execute(input
)) <<
"Program: " << input;
87 v8::Local<v8::Value> value = GetValue();
88 EXPECT_TRUE(fxv8::IsNumber(value));
89 EXPECT_TRUE(isnan(fxv8::ReentrantToDoubleHelper(isolate(), value)));
93 EXPECT_TRUE(
Execute(input
)) <<
"Program: " << input;
96 v8::Local<v8::Value> value = GetValue();
97 EXPECT_TRUE(fxv8::IsString(value));
98 EXPECT_STREQ(expected,
99 fxv8::ReentrantToByteStringHelper(isolate(), value).c_str())
100 <<
"Program: " << input;
107 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
109 const char input[] =
"";
110 EXPECT_TRUE(Execute(input));
116 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
117 ExecuteExpectInt32(
"123", 123);
121 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
123 ExecuteExpectInt32(
"123 + 456", 579);
124 ExecuteExpectInt32(
"2 - 3 * 10 / 2 + 7", -6);
125 ExecuteExpectInt32(
"10 * 3 + 5 * 4", 50);
126 ExecuteExpectInt32(
"(5 - \"abc\") * 3", 15);
127 ExecuteExpectInt32(
"\"100\" / 10e1", 1);
128 ExecuteExpectInt32(
"5 + null + 3", 8);
132 "if (\"abc\") then\n"
138 ExecuteExpectInt32(
"3 / 0 + 1", 0);
140 ExecuteExpectInt32(
"-(17)", -17);
141 ExecuteExpectInt32(
"-(-17)", 17);
142 ExecuteExpectInt32(
"+(17)", 17);
143 ExecuteExpectInt32(
"+(-17)", -17);
144 ExecuteExpectInt32(
"if (1 < 2) then\n1\nendif", 1);
146 "if (\"abc\" > \"def\") then\n"
155 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
157 ExecuteExpectString(
"\"abc\"",
"abc");
159 "concat(\"The total is \", 2, \" dollars and \", 57, \" cents.\")",
160 "The total is 2 dollars and 57 cents.");
164 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
166 ExecuteExpectBool(
"0 and 1 or 2 > 1",
true);
167 ExecuteExpectBool(
"2 < 3 not 1 == 1",
false);
168 ExecuteExpectBool(
"\"abc\" | 2",
true);
169 ExecuteExpectBool(
"1 or 0",
true);
170 ExecuteExpectBool(
"0 | 0",
false);
171 ExecuteExpectBool(
"0 or 1 | 0 or 0",
true);
172 ExecuteExpectBool(
"1 and 0",
false);
173 ExecuteExpectBool(
"0 and 1 & 0 and 0",
false);
174 ExecuteExpectBool(
"not(\"true\")",
true);
175 ExecuteExpectBool(
"not(1)",
false);
176 ExecuteExpectBool(
"3 == 3",
true);
177 ExecuteExpectBool(
"3 <> 4",
true);
178 ExecuteExpectBool(
"\"abc\" eq \"def\"",
false);
179 ExecuteExpectBool(
"\"def\" ne \"abc\"",
true);
180 ExecuteExpectBool(
"5 + 5 == 10",
true);
181 ExecuteExpectBool(
"5 + 5 <> \"10\"",
false);
182 ExecuteExpectBool(
"3 < 3",
false);
183 ExecuteExpectBool(
"3 > 4",
false);
184 ExecuteExpectBool(
"\"abc\" <= \"def\"",
true);
185 ExecuteExpectBool(
"\"def\" > \"abc\"",
true);
186 ExecuteExpectBool(
"12 >= 12",
true);
187 ExecuteExpectBool(
"\"true\" < \"false\"",
false);
191 ExecuteExpectBool(
"0 & 0",
true);
196 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
198 ExecuteExpectFloat(
"Abs(1.03)", 1.03f);
199 ExecuteExpectFloat(
"Abs(-1.03)", 1.03f);
200 ExecuteExpectFloat(
"Abs(0)", 0.0f);
204 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
206 ExecuteExpectFloat(
"Avg(0, 32, 16)", 16.0f);
207 ExecuteExpectFloat(
"Avg(2.5, 17, null)", 9.75f);
211 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
213 ExecuteExpectInt32(
"Ceil(2.5875)", 3);
214 ExecuteExpectInt32(
"Ceil(-5.9)", -5);
215 ExecuteExpectInt32(
"Ceil(\"abc\")", 0);
219 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
221 ExecuteExpectInt32(
"Count(\"Tony\", \"Blue\", 41)", 3);
225 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
227 ExecuteExpectInt32(
"Floor(21.3409873)", 21);
228 ExecuteExpectInt32(
"Floor(5.999965342)", 5);
229 ExecuteExpectInt32(
"Floor(3.2 * 15)", 48);
233 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
235 ExecuteExpectInt32(
"Max(234, 15, 107)", 234);
236 ExecuteExpectInt32(
"Max(\"abc\", 15, \"Tony Blue\")", 15);
237 ExecuteExpectInt32(
"Max(\"abc\")", 0);
241 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
243 ExecuteExpectInt32(
"Min(234, 15, 107)", 15);
247 ExecuteExpectInt32(
"Min(\"abc\", 15, \"Tony Blue\")", 15);
249 ExecuteExpectInt32(
"Min(\"abc\")", 0);
253 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
255 ExecuteExpectInt32(
"Mod(64, -3)", 1);
256 ExecuteExpectInt32(
"Mod(-13, 3)", -1);
257 ExecuteExpectInt32(
"Mod(\"abc\", 2)", 0);
259 ExecuteExpectNaN(
"Mod(10, NaN)");
260 ExecuteExpectNaN(
"Mod(10, Infinity)");
264 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
266 ExecuteExpectFloat(
"Round(12.389764537, 4)", 12.3898f);
267 ExecuteExpectFloat(
"Round(20/3, 2)", 6.67f);
268 ExecuteExpectFloat(
"Round(8.9897, \"abc\")", 9.0f);
269 ExecuteExpectFloat(
"Round(FV(400, 0.10/12, 30*12), 2)", 904195.17f);
273 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
275 ExecuteExpectInt32(
"Sum(2, 4, 6, 8)", 20);
276 ExecuteExpectInt32(
"Sum(-2, 4, -6, 8)", 4);
277 ExecuteExpectInt32(
"Sum(4, 16, \"abc\", 19)", 39);
295 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
297 ExecuteExpectInt32(
"Date2Num(\"1/1/1900\", \"D/M/YYYY\")", 1);
298 ExecuteExpectInt32(
"Date2Num(\"03/15/96\", \"MM/DD/YY\")", 35138);
299 ExecuteExpectInt32(
"Date2Num(\"96-08-20\", \"YY-MM-DD\", \"fr_FR\")", 35296);
301 "Date2Num(\"1/3/00\", \"D/M/YY\") - Date2Num(\"1/2/00\", \"D/M/YY\")",
305 ExecuteExpectInt32(
"Date2Num(\"Mar 15, 1996\")", 35138);
306 ExecuteExpectInt32(
"Date2Num(\"Aug 1, 1996\", \"MMM D, YYYY\")", 35277);
311 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
313 ExecuteExpectString(
"DateFmt(3, \"de_DE\")",
"D. MMMM YYYY");
316 ExecuteExpectString(
"DateFmt(1)",
"M/D/YY");
317 ExecuteExpectString(
"DateFmt(2, \"fr_CA\")",
"YY-MM-DD");
318 ExecuteExpectString(
"DateFmt(4, \"fr_FR\")",
"EEE D' MMMM YYYY");
323 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
325 ExecuteExpectInt32(
"IsoDate2Num(\"1900\")", 1);
326 ExecuteExpectInt32(
"IsoDate2Num(\"1900-01\")", 1);
327 ExecuteExpectInt32(
"IsoDate2Num(\"1900-01-01\")", 1);
328 ExecuteExpectInt32(
"IsoDate2Num(\"19960315T20:20:20\")", 35138);
329 ExecuteExpectInt32(
"IsoDate2Num(\"2000-03-01\") - IsoDate2Num(\"20000201\")",
334 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
336 ExecuteExpectInt32(
"IsoTime2Num(\"00:00:00Z\")", 1);
340 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
342 ExecuteExpectString(
"LocalDateFmt(3, \"de_CH\")",
"t. MMMM jjjj");
343 ExecuteExpectString(
"LocalDateFmt(4, \"fr_FR\")",
"EEEE j MMMM aaaa");
346 ExecuteExpectString(
"LocalDateFmt(1, \"de_DE\")",
"tt.MM.uu");
347 ExecuteExpectString(
"LocalDateFmt(2, \"fr_CA\")",
"aa-MM-jj");
352 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
354 ExecuteExpectString(
"LocalTimeFmt(1, \"de_DE\")",
"HH:mm");
355 ExecuteExpectString(
"LocalTimeFmt(2, \"fr_CA\")",
"HH:mm::ss");
356 ExecuteExpectString(
"LocalTimeFmt(3, \"de_CH\")",
"HH:mm:ss z");
357 ExecuteExpectString(
"LocalTimeFmt(4, \"fr_FR\")",
"HH' h 'mm z");
361 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
363 ExecuteExpectString(
"Num2Date(1, \"DD/MM/YYYY\")",
"01/01/1900");
364 ExecuteExpectString(
"Num2Date(35139, \"DD-MMM-YYYY\", \"de_DE\")",
369 "Num2Date(Date2Num(\"Mar 15, 2000\") - Date2Num(\"98-03-15\", "
370 "\"YY-MM-DD\", \"fr_CA\"))",
376 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
379 ExecuteExpectString(
"Num2GMTime(1, \"HH:MM:SS\")",
"00:00:00");
381 ExecuteExpectString(
"Num2GMTime(65593001, \"HH:MM:SS Z\")",
"18:13:13 GMT");
382 ExecuteExpectString(
"Num2GMTime(43993001, TimeFmt(4, \"de_DE\"), \"de_DE\")",
388 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
390 ExecuteExpectString(
"Num2Time(1, \"HH:MM:SS\")",
"00:00:00");
408 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
410 ExecuteExpectInt32(
"Time2Num(\"00:00:00 GMT\", \"HH:MM:SS Z\")", 1);
411 ExecuteExpectInt32(
"Time2Num(\"00:00:01 GMT\", \"HH:MM:SS Z\")", 1001);
412 ExecuteExpectInt32(
"Time2Num(\"00:01:00 GMT\", \"HH:MM:SS Z\")", 60001);
413 ExecuteExpectInt32(
"Time2Num(\"01:00:00 GMT\", \"HH:MM:SS Z\")", 3600001);
414 ExecuteExpectInt32(
"Time2Num(\"23:59:59 GMT\", \"HH:MM:SS Z\")", 86399001);
416 ExecuteExpectInt32(
"Time2Num(\"\", \"\", 1)", 0);
417 ExecuteExpectInt32(
"Time2Num(\"13:13:13 GMT\", \"HH:MM:SS Z\", \"fr_FR\")",
422 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
424 static constexpr const char* kTimeZones[] = {
425 "UTC+14",
"UTC-14",
"UTC+9:30",
"UTC-0:30",
426 "UTC+0:30",
"UTC-0:01",
"UTC+0:01"};
427 for (
const char* tz : kTimeZones) {
429 ExecuteExpectInt32(
"Time2Num(\"00:00:00 GMT\", \"HH:MM:SS Z\")", 1);
430 ExecuteExpectInt32(
"Time2Num(\"11:59:59 GMT\", \"HH:MM:SS Z\")", 43199001);
431 ExecuteExpectInt32(
"Time2Num(\"12:00:00 GMT\", \"HH:MM:SS Z\")", 43200001);
432 ExecuteExpectInt32(
"Time2Num(\"23:59:59 GMT\", \"HH:MM:SS Z\")", 86399001);
436 ExecuteExpectInt32(
"Time2Num(\"1:13:13 PM\")", 36793001);
438 "Time2Num(\"13:13:13 GMT\", \"HH:MM:SS Z\") - "
439 "Time2Num(\"13:13:13\", \"HH:MM:SS\")",
445 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
447 ExecuteExpectString(
"TimeFmt(2, \"fr_CA\")",
"HH:MM:SS");
448 ExecuteExpectString(
"TimeFmt(3, \"fr_FR\")",
"HH:MM:SS Z");
451 ExecuteExpectString(
"TimeFmt(1)",
"h::MM A");
452 ExecuteExpectString(
"TimeFmt(4, \"de_DE\")",
"H.MM' Uhr 'Z");
457 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
459 ExecuteExpectFloatNear(
"Apr(35000, 269.50, 360)", 0.08515404566f);
460 ExecuteExpectFloatNear(
"Apr(210000 * 0.75, 850 + 110, 25 * 26)",
463 ExecuteExpectError(
"Apr(2, 2, 2147483648)");
467 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
469 ExecuteExpectFloat(
"CTerm(0.10, 500000, 12000)", 39.13224648502f);
472 ExecuteExpectFloat(
"CTerm(0.02, 1000, 100)", 116.2767474515f);
473 ExecuteExpectFloat(
"CTerm(0.0275 + 0.0025, 1000000, 55000 * 0.10)",
479 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
481 ExecuteExpectFloat(
"FV(400, 0.10 / 12, 30 * 12)", 904195.16991842445f);
482 ExecuteExpectFloat(
"FV(1000, 0.075 / 4, 10 * 4)", 58791.96145535981f);
484 ExecuteExpectError(
"FV(2, 2, 2147483648)");
488 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
490 ExecuteExpectFloat(
"IPmt(30000, 0.085, 295.50, 7, 3)", 624.8839283142f);
491 ExecuteExpectFloat(
"IPmt(160000, 0.0475, 980, 24, 12)", 7103.80833569485f);
492 ExecuteExpectFloat(
"IPmt(15000, 0.065, 65.50, 15, 1)", 0.0f);
496 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
498 ExecuteExpectFloat(
"NPV(0.065, 5000)", 4694.83568075117f);
499 ExecuteExpectFloat(
"NPV(0.10, 500, 1500, 4000, 10000)", 11529.60863329007f);
500 ExecuteExpectFloat(
"NPV(0.0275 / 12, 50, 60, 40, 100, 25)", 273.14193838457f);
504 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
506 ExecuteExpectFloat(
"Pmt(25000, 0.085, 12)", 3403.82145169876f);
507 ExecuteExpectFloat(
"Pmt(5000, 0.01, 1)", 5050);
508 ExecuteExpectFloat(
"Pmt(5000, 0.01, 1.5)", 5050);
509 ExecuteExpectFloat(
"Pmt(30000.00, .085 / 12, 12 * 12)", 333.01666929435f);
510 ExecuteExpectFloat(
"Pmt(10000, .08 / 12, 10)", 1037.03208935916f);
511 ExecuteExpectFloat(
"Pmt(150000, 0.0475 / 12, 25 * 12)", 855.17604207164f);
514 ExecuteExpectError(
"Pmt(2, 2, 99999997952)");
518 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
520 ExecuteExpectFloat(
"PPmt(30000, 0.085, 295.50, 7, 3)", 261.6160716858f);
521 ExecuteExpectFloat(
"PPmt(160000, 0.0475, 980, 24, 12)", 4656.19166430515f);
524 ExecuteExpectFloat(
"PPmt(15000, 0.065, 65.50, 15, 1)", 0.0f);
529 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
531 ExecuteExpectFloat(
"PV(400, 0.10 / 12, 30 * 12)", 45580.32799074439f);
532 ExecuteExpectFloat(
"PV(1000, 0.075 / 4, 10 * 4)", 27964.88770467326f);
535 ExecuteExpectError(
"PV(2, 2, 2147483648)");
539 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
541 ExecuteExpectFloatNear(
"Rate(12000, 8000, 5)", 0.0844717712f);
542 ExecuteExpectFloatNear(
"Rate(10000, 0.25 * 5000, 4 * 12)", 0.04427378243f);
544 ExecuteExpectError(
"Rate(2, 2, 2147483648)");
548 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
550 ExecuteExpectFloat(
"Term(2500, 0.0275 + 0.0025, 5000)", 1.97128786369f);
553 ExecuteExpectFloat(
"Term(475, .05, 1500)", 3.00477517728f);
558 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
560 ExecuteExpectString(
"Choose(3, \"Taxes\", \"Price\", \"Person\", \"Teller\")",
562 ExecuteExpectString(
"Choose(2, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)",
"9");
564 "Choose(20/3, \"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\")",
569 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
570 ExecuteExpectBool(
"Exists(\"hello world\")",
false);
574 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
576 ExecuteExpectBool(
"HasValue(2)",
true);
577 ExecuteExpectBool(
"HasValue(\" \")",
false);
581 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
583 ExecuteExpectBool(
"Oneof(3, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)",
true);
585 "Oneof(\"John\", \"Bill\", \"Gary\", \"Joan\", \"John\", \"Lisa\")",
587 ExecuteExpectBool(
"Oneof(3, 1, 25)",
false);
588 ExecuteExpectBool(
"Oneof(3, 3, null)",
true);
589 ExecuteExpectBool(
"Oneof(3, null, null)",
false);
593 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
595 ExecuteExpectBool(
"Within(\"C\", \"A\", \"D\")",
true);
596 ExecuteExpectBool(
"Within(1.5, 0, 2)",
true);
597 ExecuteExpectBool(
"Within(-1, 0, 2)",
false);
601 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
603 ExecuteExpectInt32(
"eval(\"10*3+5*4\")", 50);
607 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
609 ExecuteExpectString(
"Null()",
"null");
610 ExecuteExpectString(
"Concat(\"ABC\", Null(), \"DEF\")",
"ABCDEF");
611 ExecuteExpectInt32(
"Null() + 5", 5);
615 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
617 ExecuteExpectString(
"Ref(\"10*3+5*4\")",
"10*3+5*4");
618 ExecuteExpectString(
"Ref(\"hello\")",
"hello");
622 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
624 ExecuteExpectString(
"UnitType(\"36 in\")",
"in");
625 ExecuteExpectString(
"UnitType(\"2.54centimeters\")",
"cm");
626 ExecuteExpectString(
"UnitType(\"picas\")",
"pt");
627 ExecuteExpectString(
"UnitType(\"2.cm\")",
"cm");
628 ExecuteExpectString(
"UnitType(\"2.zero cm\")",
"in");
629 ExecuteExpectString(
"UnitType(\"kilometers\")",
"in");
633 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
635 ExecuteExpectFloat(
"UnitValue(\"2in\")", 2.0f);
636 ExecuteExpectFloat(
"UnitValue(\"2in\", \"cm\")", 5.08f);
640 ExecuteExpectFloat(
"UnitValue(\"6\", \"pt\")", 432f);
641 ExecuteExpectFloat(
"UnitType(\"A\", \"cm\")", 0.0f);
642 ExecuteExpectFloat(
"UnitType(\"5.08cm\", \"kilograms\")", 2.0f);
647 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
649 ExecuteExpectInt32(
"At(\"ABCDEFGH\", \"AB\")", 1);
650 ExecuteExpectInt32(
"At(\"ABCDEFGH\", \"F\")", 6);
651 ExecuteExpectInt32(
"At(23412931298471, 29)", 5);
655 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
657 ExecuteExpectString(
"Concat(\"ABC\", \"DEF\")",
"ABCDEF");
658 ExecuteExpectString(
"Concat(\"Tony\", Space(1), \"Blue\")",
"Tony Blue");
659 ExecuteExpectString(
"Concat(\"You owe \", WordNum(1154.67, 2), \".\")",
660 "You owe One Thousand One Hundred Fifty-four Dollars And "
661 "Sixty-seven Cents.");
665 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
668 ExecuteExpectString(R"(Decode("", "html"))",
"");
669 ExecuteExpectString(R"(Decode("abcÂxyz", "html"))",
"abc\xC3\x82xyz");
670 ExecuteExpectString(R"(Decode("abc&NoneSuchButVeryLongIndeed;", "html"))",
672 ExecuteExpectString(R"(Decode("AÆÁ", "html"))",
673 "A\xC3\x86\xC3\x81");
674 ExecuteExpectString(R"(Decode("xyz&#", "html"))",
"xyz");
675 ExecuteExpectString(R"(Decode("|&zzzzzz;|", "html"))",
"||");
678 ExecuteExpectString(R"(Decode("", "xml"))",
"");
679 ExecuteExpectString(R"(Decode("~!@#$%%^&*()_+|`", "xml"))",
681 ExecuteExpectString(R"(Decode("abc&nonesuchbutverylongindeed;", "xml"))",
683 ExecuteExpectString(R"(Decode(""E<>[].'", "xml"))",
685 ExecuteExpectString(R"(Decode("xyz&#", "xml"))",
"xyz");
686 ExecuteExpectString(R"(Decode("|&zzzzzz;|", "xml"))",
"||");
689 ExecuteExpectString(R"(Decode("", "url"))",
"");
690 ExecuteExpectString(R"(Decode("~%26^&*()_+|`{", "url"))",
"~&^&*()_+|`{");
691 ExecuteExpectString(R"(Decode("~%26^&*()_+|`{", "mbogo"))",
"~&^&*()_+|`{");
692 ExecuteExpectString(R"(Decode("~%26^&*()_+|`{"))",
"~&^&*()_+|`{");
693 ExecuteExpectString(R"(Decode("~%~~"))",
"");
694 ExecuteExpectString(R"(Decode("?%~"))",
"");
695 ExecuteExpectString(R"(Decode("?%"))",
"?");
699 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
701 ExecuteExpectString(
"Encode(\"X/~&^*<=>?|\")",
702 "X%2f%7e%26%5e*%3c%3d%3e%3f%7c");
703 ExecuteExpectString(
"Encode(\"X/~&^*<=>?|\", \"mbogo\")",
704 "X%2f%7e%26%5e*%3c%3d%3e%3f%7c");
705 ExecuteExpectString(
"Encode(\"X/~&^*<=>?|\", \"url\")",
706 "X%2f%7e%26%5e*%3c%3d%3e%3f%7c");
707 ExecuteExpectString(
"Encode(\"X/~&^*<=>?|\", \"xml\")",
708 "X/~&^*<=>?|");
709 ExecuteExpectString(
"Encode(\"X/~&^*<=>?|\", \"html\")",
710 "X/~&^*<=>?|");
712 ExecuteExpectString(
"Encode(\"\\u0022\\u00f5\\ufed0\", \"url\")",
714 ExecuteExpectString(
"Encode(\"\\u0022\\u00f4\\ufed0\", \"xml\")",
715 ""ôﻐ");
716 ExecuteExpectString(
"Encode(\"\\u0022\\u00f5\\ufed0\", \"html\")",
717 ""õﻐ");
719 ExecuteExpectString(
"Encode(\"\\uD83D\\uDCA9\", \"url\")",
"%01%f4%a9");
720 ExecuteExpectString(
"Encode(\"\\uD83D\\uDCA9\", \"xml\")",
"");
721 ExecuteExpectString(
"Encode(\"\\uD83D\\uDCA9\", \"html\")",
"");
725 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
727 ExecuteExpectString(
"Format(\"MMM D, YYYY\", \"20020901\")",
"Sep 1, 2002");
728 ExecuteExpectString(
"Format(\"$9,999,999.99\", 1234567.89)",
"$1,234,567.89");
732 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
734 ExecuteExpectString(
"Left(\"ABCDEFGH\", 3)",
"ABC");
735 ExecuteExpectString(
"Left(\"Tony Blue\", 5)",
"Tony ");
739 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
741 ExecuteExpectInt32(
"Len(\"ABCDEFGH\")", 8);
742 ExecuteExpectInt32(
"Len(4)", 1);
743 ExecuteExpectInt32(
"Len(Str(4.532, 6, 4))", 6);
747 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
749 ExecuteExpectString(
"Lower(\"ABC\")",
"abc");
750 ExecuteExpectString(
"Lower(\"21 Main St.\")",
"21 main st.");
751 ExecuteExpectString(
"Lower(15)",
"15");
756 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
758 const uint8_t test_string[] = {
759 0x4c, 0x6f, 0x77, 0x65, 0x72, 0x28, 0x22, 0xc3,
760 0x85, 0xc3, 0x85, 0xc3, 0x85, 0x22, 0x29};
761 Execute(ByteString(test_string,
sizeof(test_string)).AsStringView());
765 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
767 ExecuteExpectString(
"Ltrim(\" ABCD\")",
"ABCD");
768 ExecuteExpectString(
"Ltrim(Rtrim(\" Tony Blue \"))",
"Tony Blue");
772 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
774 ExecuteExpectString(
"Parse(\"MMM D, YYYY\", \"Sep 1, 2002\")",
"2002-09-01");
775 ExecuteExpectFloat(
"Parse(\"$9,999,999.99\", \"$1,234,567.89\")",
780 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
782 ExecuteExpectString(
"Replace(\"Tony Blue\", \"Tony\", \"Chris\")",
784 ExecuteExpectString(
"Replace(\"ABCDEFGH\", \"D\")",
"ABCEFGH");
785 ExecuteExpectString(
"Replace(\"ABCDEFGH\", \"d\")",
"ABCDEFGH");
789 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
791 ExecuteExpectString(
"Right(\"ABCDEFGH\", 3)",
"FGH");
792 ExecuteExpectString(
"Right(\"Tony Blue\", 5)",
" Blue");
796 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
798 ExecuteExpectString(
"Rtrim(\"ABCD \")",
"ABCD");
799 ExecuteExpectString(
"Rtrim(\"Tony Blue \t\")",
"Tony Blue");
803 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
805 ExecuteExpectString(
"Space(5)",
" ");
806 ExecuteExpectString(
"Concat(\"Tony\", Space(1), \"Blue\")",
"Tony Blue");
809 ExecuteExpectError(
"Space(15654909)");
810 ExecuteExpectError(
"Space(99999999)");
811 ExecuteExpectError(
"Space()");
812 ExecuteExpectError(
"Space(1, 2)");
813 ExecuteExpectNull(
"Space( $)");
817 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
819 ExecuteExpectString(
"Str(2.456)",
" 2");
820 ExecuteExpectString(
"Str(4.532, 6, 4)",
"4.5320");
821 ExecuteExpectString(
"Str(234.458, 4)",
" 234");
822 ExecuteExpectString(
"Str(31.2345, 4, 2)",
"****");
825 ExecuteExpectString(
"Str(-765, 19, 14)",
"-765.00000000000000");
826 ExecuteExpectString(
"Str(-765, 20, 15)",
"-765.000000000000000");
827 ExecuteExpectString(
"Str(-765, 21, 16)",
" -765.000000000000000");
830 ExecuteExpectError(
"Str()");
831 ExecuteExpectError(
"Str(1, 2, 3, 4)");
832 ExecuteExpectError(
"Str(42, 15654909)");
833 ExecuteExpectNull(
"Str( $)");
837 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
840 ExecuteExpectError(
"Stuff(1, 2)");
841 ExecuteExpectError(
"Stuff(1, 2, 3, 4, 5)");
844 ExecuteExpectNull(
"Stuff(null, 0, 4)");
845 ExecuteExpectNull(
"Stuff(\"ABCDEFG\", null, 4)");
846 ExecuteExpectNull(
"Stuff(\"ABCDEFG\", 0, null)");
849 ExecuteExpectString(
"Stuff(\"\", 0, 0, \"clams\")",
"clams");
850 ExecuteExpectString(
"Stuff(\"TonyBlue\", 5, 0, \" \")",
"Tony Blue");
853 ExecuteExpectString(
"Stuff(\"A\", 1, 0)",
"A");
854 ExecuteExpectString(
"Stuff(\"A\", 1, 1)",
"");
855 ExecuteExpectString(
"Stuff(\"ABCDEFGH\", 4, 2)",
"ABCFGH");
856 ExecuteExpectString(
"Stuff(\"ABCDEFGH\", 7, 2)",
"ABCDEF");
859 ExecuteExpectString(
"Stuff(\"ABCDEFGH\", -400, 400)",
"");
866 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678900"
867 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678900"
868 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678900"
869 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678900"
870 "\", 133, 2147483520)",
871 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678900"
872 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678900"
877 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
880 ExecuteExpectError(
"Substr()");
881 ExecuteExpectError(
"Substr(1)");
882 ExecuteExpectError(
"Substr(1, 2)");
883 ExecuteExpectError(
"Substr(1, 2, 3, 4)");
886 ExecuteExpectNull(
"Substr(null, 0, 4)");
887 ExecuteExpectNull(
"Substr(\"ABCDEFG\", null, 4)");
888 ExecuteExpectNull(
"Substr(\"ABCDEFG\", 0, null)");
889 ExecuteExpectNull(
"Substr(null, null, 4)");
890 ExecuteExpectNull(
"Substr(null, 0, null)");
891 ExecuteExpectNull(
"Substr(\"ABCDEFG\", null, null)");
892 ExecuteExpectNull(
"Substr(null, null, null)");
894 ExecuteExpectString(
"Substr(\"ABCDEFG\", -1, 4)",
"ABCD");
895 ExecuteExpectString(
"Substr(\"ABCDEFG\", 0, 4)",
"ABCD");
896 ExecuteExpectString(
"Substr(\"ABCDEFG\", 3, 4)",
"CDEF");
897 ExecuteExpectString(
"Substr(\"ABCDEFG\", 4, 4)",
"DEFG");
898 ExecuteExpectString(
"Substr(\"ABCDEFG\", 5, 4)",
"EFG");
899 ExecuteExpectString(
"Substr(\"ABCDEFG\", 6, 4)",
"FG");
900 ExecuteExpectString(
"Substr(\"ABCDEFG\", 7, 4)",
"G");
901 ExecuteExpectString(
"Substr(\"ABCDEFG\", 8, 4)",
"");
902 ExecuteExpectString(
"Substr(\"ABCDEFG\", 5, -1)",
"");
903 ExecuteExpectString(
"Substr(\"ABCDEFG\", 5, 0)",
"");
904 ExecuteExpectString(
"Substr(\"ABCDEFG\", 5, 1)",
"E");
905 ExecuteExpectString(
"Substr(\"abcdefghi\", 5, 3)",
"efg");
906 ExecuteExpectString(
"Substr(3214, 2, 1)",
"2");
907 ExecuteExpectString(
"Substr(\"21 Waterloo St.\", 4, 5)",
"Water");
911 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
912 EXPECT_TRUE(Execute(
"Uuid()"));
915 v8::Local<v8::Value> value = GetValue();
916 EXPECT_TRUE(fxv8::IsString(value));
920 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
922 ExecuteExpectString(
"Upper(\"abc\")",
"ABC");
923 ExecuteExpectString(
"Upper(\"21 Main St.\")",
"21 MAIN ST.");
924 ExecuteExpectString(
"Upper(15)",
"15");
928 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
931 ExecuteExpectError(
"WordNum()");
932 ExecuteExpectError(
"WordNum(1, 2, 3, 4)");
935 ExecuteExpectString(
"WordNum(123.45)",
"One Hundred Twenty-three");
936 ExecuteExpectString(
"WordNum(123.45, 0)",
"One Hundred Twenty-three");
937 ExecuteExpectString(
"WordNum(123.45, 1)",
"One Hundred Twenty-three Dollars");
938 ExecuteExpectString(
"WordNum(123.45, 2)",
939 "One Hundred Twenty-three Dollars And Forty-five Cents");
942 ExecuteExpectString(
"WordNum(123.45, -1)",
"");
943 ExecuteExpectString(
"WordNum(123.45, 3)",
"");
946 ExecuteExpectString(
"WordNum(123.45, 0, \"zh_CN\")",
947 "One Hundred Twenty-three");
950 ExecuteExpectString(
"WordNum(0, 0)",
"Zero");
951 ExecuteExpectString(
"WordNum(0, 1)",
"Zero Dollars");
952 ExecuteExpectString(
"WordNum(0, 2)",
"Zero Dollars And Zero Cents");
953 ExecuteExpectString(
"WordNum(0.12, 0)",
"Zero");
954 ExecuteExpectString(
"WordNum(0.12, 1)",
"Zero Dollars");
955 ExecuteExpectString(
"WordNum(0.12, 2)",
"Zero Dollars And Twelve Cents");
958 ExecuteExpectString(
"WordNum(-1, 0)",
"*");
959 ExecuteExpectString(
"WordNum(-1, 1)",
"*");
960 ExecuteExpectString(
"WordNum(-1, 2)",
"*");
964 ExecuteExpectString(
"WordNum(1.234e+6)",
965 "One Million Two Hundred Thirty-four Thousand Zero");
970 "One Billion Two Hundred Thirty-four Million Zero Thousand Zero");
974 "WordNum(1.234e+12)",
975 "One Trillion Two Hundred Thirty-four Billion Zero Million Nineteen "
976 "Thousand Four Hundred Fifty-six");
979 "WordNum(1.234e+15)",
980 "One Thousand Two Hundred Thirty-three Trillion Nine Hundred Ninety-nine "
981 "Billion Nine Hundred Thirty-eight Million Seven Hundred Fifteen "
983 "Six Hundred Forty-eight");
986 ExecuteExpectString(
"WordNum(1.234e+18)",
"*");
987 ExecuteExpectString(
"WordNum(1.234e+21)",
"*");
988 ExecuteExpectString(
"WordNum(1.234e+24)",
"*");
989 ExecuteExpectString(
"WordNum(1.234e+30)",
"*");
993 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
994 ExecuteExpectString(
"Get(\"https://example.com\")",
"<body>secrets</body>");
998 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
1000 "Post(\"http://example.com\", \"secret stuff\", \"text/plain\")",
1005 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
1006 ExecuteExpectString(
"Put(\"http://example.com\", \"secret stuff\")",
"");
1010 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
1012 EXPECT_FALSE(ExecuteSilenceFailure(
"F()"));
1013 EXPECT_FALSE(ExecuteSilenceFailure(
"()"));
1014 EXPECT_FALSE(ExecuteSilenceFailure(
"()()()"));
1015 EXPECT_FALSE(ExecuteSilenceFailure(
"Round(2.0)()"));
1019 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
1021 const char test[] = {
"$form.form1.TextField11.getAttribute(\"h\")"};
1022 ExecuteExpectString(test,
"12.7mm");
1026 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
1029 params.m_wsChange = L"changed";
1034 const char test[] = {
"xfa.event.change"};
1035 ExecuteExpectString(test,
"changed");
1039 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
1045 const char test[] = {
"xfa.event.change = \"changed\""};
1046 EXPECT_TRUE(Execute(test));
1047 EXPECT_EQ(L"changed", params.m_wsChange);
1051 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
1054 params.m_wsFullText = L"Original Full Text";
1059 const char test[] = {
"xfa.event.fullText = \"Changed Full Text\""};
1060 EXPECT_TRUE(Execute(test));
1061 EXPECT_EQ(L"Original Full Text", params.m_wsFullText);
1065 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
1068 params.m_wsPrevText = L"1234";
1076 EXPECT_TRUE(Execute(
"xfa.event.selEnd = \"1\""));
1081 EXPECT_TRUE(Execute(
"xfa.event.selEnd = \"0\""));
1086 EXPECT_TRUE(Execute(
"xfa.event.selEnd = \"-1\""));
1091 EXPECT_TRUE(Execute(
"xfa.event.selStart = \"-1\""));
1098 EXPECT_TRUE(Execute(
"xfa.event.selStart = \"1\""));
1103 EXPECT_TRUE(Execute(
"xfa.event.selStart = \"2\""));
1108 EXPECT_TRUE(Execute(
"xfa.event.selEnd = \"20\""));
1113 EXPECT_TRUE(Execute(
"xfa.event.selStart = \"20\""));
1119 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
1126 ExecuteExpectBool(
"xfa.event.cancelAction",
false);
1127 EXPECT_TRUE(Execute(
"xfa.event.cancelAction = \"true\""));
1132 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
1135 params.m_wsChange = L"g";
1136 params.m_wsPrevText = L"abcd";
1143 EXPECT_EQ(L"abcd", params.m_wsPrevText);
1145 EXPECT_EQ(L"g", params.m_wsChange);
1149 const char change_event[] = {
"xfa.event.change = \"xyz\""};
1150 EXPECT_TRUE(Execute(change_event));
1152 EXPECT_EQ(L"abcd", params.m_wsPrevText);
1153 EXPECT_EQ(L"xyz", params.m_wsChange);
1158 const char sel_event[] = {
"xfa.event.selEnd = \"1\""};
1159 EXPECT_TRUE(Execute(sel_event));
1161 EXPECT_EQ(L"abcd", params.m_wsPrevText);
1162 EXPECT_EQ(L"xyz", params.m_wsChange);
1170 ASSERT_TRUE(OpenDocument(
"simple_xfa.pdf"));
1171 EXPECT_TRUE(Execute(
"!.somExpression=0"));
TEST_F(CFXJSE_FormCalcContextEmbedderTest, TranslateEmpty)
EventParamScope(CFXJSE_Engine *pEngine, CXFA_Node *pTarget, CXFA_EventParam *pEventParam)
friend class EventParamScope
void ExecuteExpectBool(ByteStringView input, bool expected)
~CFXJSE_FormCalcContextEmbedderTest() override=default
CFXJSE_FormCalcContextEmbedderTest()=default
void ExecuteExpectNaN(ByteStringView input)
void ExecuteExpectFloat(ByteStringView input, float expected)
void ExecuteExpectError(ByteStringView input)
void ExecuteExpectInt32(ByteStringView input, int32_t expected)
void ExecuteExpectString(ByteStringView input, const char *expected)
void ExecuteExpectNull(ByteStringView input)
CFXJSE_Context * GetJseContext()
void ExecuteExpectFloatNear(ByteStringView input, float expected)
CFXJSE_ScopeUtil_IsolateHandleContext(CFXJSE_Context *pContext)
WideString GetNewText() const
CXFA_EventParam(XFA_EVENTTYPE type)
bool Execute(ByteStringView input)
CFXJSE_Engine * GetScriptContext() const