summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fxjs/cjs_publicmethods.cpp2
-rw-r--r--fxjs/cjs_publicmethods_embeddertest.cpp36
-rw-r--r--testing/resources/calculate.in62
-rw-r--r--testing/resources/calculate.pdf127
4 files changed, 226 insertions, 1 deletions
diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp
index 30927beac2..74428c3724 100644
--- a/fxjs/cjs_publicmethods.cpp
+++ b/fxjs/cjs_publicmethods.cpp
@@ -1587,7 +1587,7 @@ CJS_Return CJS_PublicMethods::AFSimple_Calculate(
double dValue = wcscmp(sFunction.c_str(), L"PRD") == 0 ? 1.0 : 0.0;
v8::Local<v8::Array> FieldNameArray =
- AF_MakeArrayFromList(pRuntime, params[0]);
+ AF_MakeArrayFromList(pRuntime, params[1]);
int nFieldsCount = 0;
for (size_t i = 0; i < pRuntime->GetArrayLength(FieldNameArray); ++i) {
WideString wsFieldName =
diff --git a/fxjs/cjs_publicmethods_embeddertest.cpp b/fxjs/cjs_publicmethods_embeddertest.cpp
index dbab0817ce..874f59f5ae 100644
--- a/fxjs/cjs_publicmethods_embeddertest.cpp
+++ b/fxjs/cjs_publicmethods_embeddertest.cpp
@@ -3,8 +3,10 @@
// found in the LICENSE file.
#include <cmath>
+#include <vector>
#include "core/fxcrt/fx_string.h"
+#include "fxjs/cjs_event_context.h"
#include "fxjs/cjs_publicmethods.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/js_embedder_test.h"
@@ -160,3 +162,37 @@ TEST_F(CJS_PublicMethodsEmbedderTest, MakeFormatDate) {
CJS_PublicMethods::MakeFormatDate(3947356800000.0, L"mmddyyyy");
EXPECT_STREQ(L"02012095", formatted_date.c_str());
}
+
+TEST_F(CJS_PublicMethodsEmbedderTest, AFSimple_CalculateSum) {
+ v8::Isolate::Scope isolate_scope(isolate());
+ v8::HandleScope handle_scope(isolate());
+ v8::Context::Scope context_scope(GetV8Context());
+
+ EXPECT_TRUE(OpenDocument("calculate.pdf"));
+ auto* page = LoadPage(0);
+ ASSERT_TRUE(page);
+
+ CJS_Runtime runtime(static_cast<CPDFSDK_FormFillEnvironment*>(form_handle()));
+ runtime.NewEventContext();
+
+ WideString result;
+ runtime.GetCurrentEventContext()->GetEventHandler()->m_pValue = &result;
+
+ auto ary = runtime.NewArray();
+
+ runtime.PutArrayElement(ary, 0, runtime.NewString(L"Calc1_A"));
+ runtime.PutArrayElement(ary, 1, runtime.NewString(L"Calc1_B"));
+
+ std::vector<v8::Local<v8::Value>> params;
+ params.push_back(runtime.NewString("SUM"));
+ params.push_back(ary);
+
+ CJS_Return ret = CJS_PublicMethods::AFSimple_Calculate(&runtime, params);
+ UnloadPage(page);
+
+ runtime.GetCurrentEventContext()->GetEventHandler()->m_pValue = nullptr;
+
+ ASSERT_TRUE(!ret.HasError());
+ ASSERT_TRUE(!ret.HasReturn());
+ ASSERT_EQ(L"7", result);
+}
diff --git a/testing/resources/calculate.in b/testing/resources/calculate.in
new file mode 100644
index 0000000000..3e40bf8ff5
--- /dev/null
+++ b/testing/resources/calculate.in
@@ -0,0 +1,62 @@
+{{header}}
+{{object 1 0}} <<
+ /AcroForm 11 0 R
+ /Pages 5 0 R
+ /Type /Catalog
+>>
+endobj
+
+{{object 11 0}} <<
+ /Fields [57 0 R 61 0 R]
+>>
+endobj
+
+{{object 5 0}} <<
+ /Count 1
+ /Type /Pages
+ /Kids [12 0 R]
+>>
+endobj
+
+{{object 12 0}} <<
+ /CropBox [0.0 0.0 720.0 540.0]
+ /Annots [57 0 R 61 0 R]
+ /Parent 5 0 R
+ /MediaBox[0.0 0.0 720.0 540.0]
+ /TrimBox[0.0 0.0 720.0 540.0]
+ /Type /Page
+>>
+endobj
+
+{{object 57 0}} <<
+ /Rect [142.13 307.409 208.842 331.442]
+ /Subtype /Widget
+ /F 4
+ /P 12 0 R
+ /Q 2
+ /T (Calc1_A)
+ /V (5)
+ /DV (5)
+ /FT /Tx
+ /Type /Annot
+>>
+endobj
+
+{{object 61 0}} <<
+ /Rect [290.306 307.409 357.793 331.442]
+ /Subtype /Widget
+ /F 4
+ /P 12 0 R
+ /Q 2
+ /T (Calc1_B)
+ /V (2)
+ /DV (2)
+ /FT /Tx
+ /Type /Annot
+>>
+endobj
+
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
diff --git a/testing/resources/calculate.pdf b/testing/resources/calculate.pdf
new file mode 100644
index 0000000000..8b2b9441d7
--- /dev/null
+++ b/testing/resources/calculate.pdf
@@ -0,0 +1,127 @@
+%PDF-1.7
+% ò¤ô
+1 0 obj <<
+ /AcroForm 11 0 R
+ /Pages 5 0 R
+ /Type /Catalog
+>>
+endobj
+
+11 0 obj <<
+ /Fields [57 0 R 61 0 R]
+>>
+endobj
+
+5 0 obj <<
+ /Count 1
+ /Type /Pages
+ /Kids [12 0 R]
+>>
+endobj
+
+12 0 obj <<
+ /CropBox [0.0 0.0 720.0 540.0]
+ /Annots [57 0 R 61 0 R]
+ /Parent 5 0 R
+ /MediaBox[0.0 0.0 720.0 540.0]
+ /TrimBox[0.0 0.0 720.0 540.0]
+ /Type /Page
+>>
+endobj
+
+57 0 obj <<
+ /Rect [142.13 307.409 208.842 331.442]
+ /Subtype /Widget
+ /F 4
+ /P 12 0 R
+ /Q 2
+ /T (Calc1_A)
+ /V (5)
+ /DV (5)
+ /FT /Tx
+ /Type /Annot
+>>
+endobj
+
+61 0 obj <<
+ /Rect [290.306 307.409 357.793 331.442]
+ /Subtype /Widget
+ /F 4
+ /P 12 0 R
+ /Q 2
+ /T (Calc1_B)
+ /V (2)
+ /DV (2)
+ /FT /Tx
+ /Type /Annot
+>>
+endobj
+
+xref
+0 62
+0000000000 65535 f
+0000000015 00000 n
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000137 00000 n
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000088 00000 n
+0000000202 00000 n
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000379 00000 n
+0000000000 65535 f
+0000000000 65535 f
+0000000000 65535 f
+0000000547 00000 n
+trailer<< /Root 1 0 R /Size 62 >>
+startxref
+716
+%%EOF