summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fxjs/cjs_publicmethods.cpp30
-rw-r--r--testing/resources/javascript/public_methods.in266
-rw-r--r--testing/resources/javascript/public_methods_expected.txt112
3 files changed, 393 insertions, 15 deletions
diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp
index fb65cc4098..a96cf23b0d 100644
--- a/fxjs/cjs_publicmethods.cpp
+++ b/fxjs/cjs_publicmethods.cpp
@@ -35,28 +35,28 @@
// static
const JSMethodSpec CJS_PublicMethods::GlobalFunctionSpecs[] = {
+ {"AFDate_Format", AFDate_Format_static},
+ {"AFDate_FormatEx", AFDate_FormatEx_static},
+ {"AFDate_Keystroke", AFDate_Keystroke_static},
+ {"AFDate_KeystrokeEx", AFDate_KeystrokeEx_static},
+ {"AFExtractNums", AFExtractNums_static},
+ {"AFMakeNumber", AFMakeNumber_static},
+ {"AFMergeChange", AFMergeChange_static},
{"AFNumber_Format", AFNumber_Format_static},
{"AFNumber_Keystroke", AFNumber_Keystroke_static},
+ {"AFParseDateEx", AFParseDateEx_static},
{"AFPercent_Format", AFPercent_Format_static},
{"AFPercent_Keystroke", AFPercent_Keystroke_static},
- {"AFDate_FormatEx", AFDate_FormatEx_static},
- {"AFDate_KeystrokeEx", AFDate_KeystrokeEx_static},
- {"AFDate_Format", AFDate_Format_static},
- {"AFDate_Keystroke", AFDate_Keystroke_static},
- {"AFTime_FormatEx", AFTime_FormatEx_static},
- {"AFTime_KeystrokeEx", AFTime_KeystrokeEx_static},
- {"AFTime_Format", AFTime_Format_static},
- {"AFTime_Keystroke", AFTime_Keystroke_static},
+ {"AFRange_Validate", AFRange_Validate_static},
+ {"AFSimple", AFSimple_static},
+ {"AFSimple_Calculate", AFSimple_Calculate_static},
{"AFSpecial_Format", AFSpecial_Format_static},
{"AFSpecial_Keystroke", AFSpecial_Keystroke_static},
{"AFSpecial_KeystrokeEx", AFSpecial_KeystrokeEx_static},
- {"AFSimple", AFSimple_static},
- {"AFMakeNumber", AFMakeNumber_static},
- {"AFSimple_Calculate", AFSimple_Calculate_static},
- {"AFRange_Validate", AFRange_Validate_static},
- {"AFMergeChange", AFMergeChange_static},
- {"AFParseDateEx", AFParseDateEx_static},
- {"AFExtractNums", AFExtractNums_static},
+ {"AFTime_Format", AFTime_Format_static},
+ {"AFTime_FormatEx", AFTime_FormatEx_static},
+ {"AFTime_Keystroke", AFTime_Keystroke_static},
+ {"AFTime_KeystrokeEx", AFTime_KeystrokeEx_static},
};
namespace {
diff --git a/testing/resources/javascript/public_methods.in b/testing/resources/javascript/public_methods.in
new file mode 100644
index 0000000000..4b70375b91
--- /dev/null
+++ b/testing/resources/javascript/public_methods.in
@@ -0,0 +1,266 @@
+{{header}}
+{{object 1 0}} <<
+ /Type /Catalog
+ /Pages 2 0 R
+ /AcroForm << /Fields [ 4 0 R 10 0 R ] /DR 5 0 R >>
+>>
+endobj
+{{object 2 0}} <<
+ /Count 1
+ /Kids [ 3 0 R ]
+ /Type /Pages
+>>
+endobj
+{{object 3 0}} <<
+ /Type /Page
+ /Parent 2 0 R
+ /Resources 5 0 R
+ /MediaBox [ 0 0 300 200 ]
+ /Contents 8 0 R
+ /Annots [ 4 0 R 10 0 R ]
+>>
+endobj
+{{object 4 0}} <<
+ /Type /Annot
+ /FT /Tx
+ /T (Text Box)
+ /DA (0 0 0 rg /F1 12 Tf)
+ /Rect [ 100 100 200 130 ]
+ /Subtype /Widget
+ /AA <<
+ /F 9 0 R
+ >>
+>>
+endobj
+{{object 5 0}} <<
+ /Font 6 0 R
+>>
+endobj
+{{object 6 0}} <<
+ /F1 7 0 R
+>>
+endobj
+{{object 7 0}} <<
+ /Type /Font
+ /Subtype /Type1
+ /BaseFont /Helvetica
+>>
+endobj
+{{object 8 0}} <<
+{{streamlen}}
+>>
+stream
+endstream
+endobj
+{{object 9 0}} <<
+ /JS (
+ function expect(initial, expression, expected) {
+ try {
+ event.value = initial;
+ var actual = eval(expression);
+ if (actual == expected) {
+ app.alert('PASS: ' + expression + ' = ' + actual);
+ } else {
+ app.alert('FAIL: ' + expression + ' = ' + actual + ', expected ' + expected + " ");
+ }
+ } catch (e) {
+ app.alert('ERROR: ' + e);
+ }
+ }
+
+ function expectEventValue(initial, expression, expected) {
+ try {
+ event.value = initial;
+ eval(expression);
+ var actual = event.value;
+ if (actual == expected) {
+ app.alert('PASS: ' + expression + ' = ' + actual);
+ } else {
+ app.alert('FAIL: ' + expression + ' = ' + actual + ', expected ' + expected + " ");
+ }
+ } catch (e) {
+ app.alert('ERROR: ' + e);
+ }
+ }
+
+ function expectError(initial, expression) {
+ try {
+ event.value = initial;
+ var actual = eval(expression);
+ app.alert('FAIL: ' + expression + ' = ' + actual + ', expected to throw');
+ } catch (e) {
+ app.alert('PASS: ' + expression + ' threw ' + e);
+ }
+ }
+
+ try {
+ app.alert("*** starting test ***");
+
+ expectError(undefined, "AFDate_Format()");
+ expectError(undefined, "AFDate_Format(1, 2)");
+ expectEventValue("GMT", "AFDate_Format(1)", "1/1/70");
+ expectEventValue("PDT", "AFDate_Format(1)", "5/9/14");
+ expectEventValue("GMT", "AFDate_Format('blooey')", "1/1");
+ expectEventValue("PDT", "AFDate_Format('blooey')", "5/9");
+
+ app.alert("**********************");
+
+ expectError(undefined, "AFDate_FormatEx()");
+ expectError(undefined, "AFDate_FormatEx(1, 2)");
+ expectEventValue("x", "AFDate_FormatEx(2)", "2");
+ expectEventValue("x", "AFDate_FormatEx('blooey')", "blooey");
+ expectEventValue("x", "AFDate_FormatEx('m/d')", "5/9");
+
+ app.alert("**********************");
+
+ expectError(undefined, "AFDate_Keystroke()");
+ expectError(undefined, "AFDate_Keystroke(1, 2)");
+ expectEventValue("04/19", "AFDate_Keystroke(2)", "04/19");
+ expectEventValue("04/19/15", "AFDate_Keystroke('blooey')", "04/19/15");
+
+ app.alert("**********************");
+
+ expectError(undefined, "AFDate_KeystrokeEx()");
+ expectError(undefined, "AFDate_KeystrokeEx(1, 2)");
+ expectEventValue("x", "AFDate_KeystrokeEx(2)", "x");
+ expectEventValue("x", "AFDate_KeystrokeEx('blooey')", "x");
+ expectEventValue("x", "AFDate_KeystrokeEx('m/d')", "x");
+
+ app.alert("**********************");
+
+ expectError(undefined, "AFExtractNums()");
+ expectError(undefined, "AFExtractNums(1, 2)");
+ expect(undefined, "AFExtractNums('100 200')", "100,200");
+
+ app.alert("**********************");
+
+ expectError(undefined, "AFMakeNumber()");
+ expectError(undefined, "AFMakeNumber(1, 2)");
+ expect(undefined, "AFMakeNumber('2blooey')", 0);
+ expect(undefined, "AFMakeNumber(1)", 1);
+ expect(undefined, "AFMakeNumber('1.2')", 1.2);
+ expect(undefined, "AFMakeNumber('1,2')", 1.2);
+
+ app.alert("**********************");
+
+ expectError(undefined, "AFMergeChange()");
+ expectError(undefined, "AFMergeChange(1, 2)");
+ expect("one", "AFMergeChange(undefined)", "one");
+
+ app.alert("**********************");
+
+ expectError(undefined, "AFNumber_Format()");
+ expectError(undefined, "AFNumber_Format(0, 1, 0, 0, '', false, 42)");
+ expectEventValue("blooey", "AFNumber_Format(0, 1, 0, 0, '', false)", 0);
+ expectEventValue(12, "AFNumber_Format(0, 1, 0, 0, '', false)", 12);
+
+ app.alert("**********************");
+
+ expectError(undefined, "AFNumber_Keystroke()");
+ expectError(undefined, "AFNumber_Keystroke(1)");
+ expectError("abc", "AFNumber_Keystroke(1, 2)");
+ expectEventValue("123", "AFNumber_Keystroke(1, 2)", "123");
+ expectEventValue("123", "AFNumber_Keystroke(1, 2, 3)", "123");
+
+ app.alert("**********************");
+
+ expectError(undefined, "AFParseDateEx()");
+ expectError(undefined, "AFParseDateEx(1, 2, 3)");
+ expect(undefined, "AFParseDateEx(1, 2)", "1399646930000");
+
+ app.alert("**********************");
+
+ expectError(undefined, "AFPercent_Format()");
+ expectError(undefined, "AFPercent_Format(1, 2, 3)");
+ expectEventValue(12.3456, "AFPercent_Format(1, 0)", "1,234.6%");
+ expectEventValue(12.3456, "AFPercent_Format(4, 1)", "1234.5600%");
+
+ app.alert("**********************");
+
+ expectError(undefined, "AFPercent_Keystroke()");
+ expectError(undefined, "AFPercent_Keystroke(1)");
+ expectError("abc", "AFPercent_Keystroke(1, 0)");
+ expectEventValue(".123", "AFPercent_Keystroke(1, 0)", ".123");
+
+ app.alert("**********************");
+
+ expectError(undefined, "AFRange_Validate()", undefined);
+ expectError(undefined, "AFRange_Validate(1, 2, 3, 4, 5)", undefined);
+ expectEventValue("3", "AFRange_Validate(true, 2, false, 4)", "3");
+
+ app.alert("**********************");
+
+ expectError(undefined, "AFSimple()", 2);
+ expectError(undefined, "AFSimple(1, 2, 3, 4)");
+ expect(undefined, "AFSimple(1, 2, 3)", 2);
+
+ app.alert("**********************");
+
+ expectError(undefined, "AFSimple_Calculate()");
+ expectError(undefined, "AFSimple_Calculate(1)");
+ expectEventValue(undefined, "AFSimple_Calculate('blooey', [1, 3, 14])", 0);
+ expectEventValue(undefined, "AFSimple_Calculate('AVG', [1, 3, 14])", 0);
+ expectEventValue(undefined, "AFSimple_Calculate('SUM', [1, 3, 14])", 0);
+
+ app.alert("**********************");
+
+ expectError(undefined, "AFSpecial_Format()", undefined);
+ expectError(undefined, "AFSpecial_Format(1, 2)", undefined);
+ expectEventValue(undefined, "AFSpecial_Format(3)", "--");
+
+ app.alert("**********************");
+
+ expectError(undefined, "AFSpecial_Keystroke()");
+ expectError(undefined, "AFSpecial_Keystroke(65, 66)");
+ expectEventValue("abc", "AFSpecial_Keystroke(65)", "abc");
+
+ app.alert("**********************");
+
+ expectError(undefined, "AFSpecial_KeystrokeEx()", undefined);
+ expectEventValue("12", "AFSpecial_KeystrokeEx('999999')", "12");
+
+ app.alert("**********************");
+
+ expectError(undefined, "AFTime_Format()");
+ expectError(undefined, "AFTime_Format(1, 2)");
+ expectEventValue(undefined, "AFTime_Format(1)", "2:48 pm");
+
+ app.alert("**********************");
+
+ expectError(undefined, "AFTime_FormatEx()");
+ expectError(undefined, "AFTime_FormatEx('blooey', 42)");
+ expectEventValue(undefined, "AFTime_FormatEx('blooey')", "blooey");
+
+ app.alert("**********************");
+
+ expectError(undefined, "AFTime_Keystroke()", undefined);
+ expectError(undefined, "AFTime_Keystroke(1, 2)", undefined);
+ expectEventValue("12:03", "AFTime_Keystroke(65)", "12:03");
+
+ app.alert("**********************");
+
+ expectError(undefined, "AFTime_KeystrokeEx()");
+ expectError(undefined, "AFTime_KeystrokeEx(1, 2)");
+ expectEventValue("12:04", "AFTime_KeystrokeEx('blooey')", "12:04");
+
+ app.alert("*** ending test ***");
+ } catch (e) {
+ app.alert("Truly unexpected error occured: " + e);
+ }
+ )
+ /S /JavaScript
+>>
+endobj
+{{object 10 0}} <<
+ /Type /Annot
+ /FT /Tx
+ /T (Text2)
+ /DA (0 0 0 rg /F1 12 Tf)
+ /Rect [ 100 40 200 70 ]
+ /Subtype /Widget
+>>
+endobj
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
diff --git a/testing/resources/javascript/public_methods_expected.txt b/testing/resources/javascript/public_methods_expected.txt
new file mode 100644
index 0000000000..12e8496af5
--- /dev/null
+++ b/testing/resources/javascript/public_methods_expected.txt
@@ -0,0 +1,112 @@
+Alert: *** starting test ***
+Alert: PASS: AFDate_Format() threw AFDate_Format: Incorrect number of parameters passed to function.
+Alert: PASS: AFDate_Format(1, 2) threw AFDate_Format: Incorrect number of parameters passed to function.
+Alert: PASS: AFDate_Format(1) = 1/1/70
+Alert: PASS: AFDate_Format(1) = 5/9/14
+Alert: PASS: AFDate_Format('blooey') = 1/1
+Alert: PASS: AFDate_Format('blooey') = 5/9
+Alert: **********************
+Alert: PASS: AFDate_FormatEx() threw AFDate_FormatEx: Incorrect number of parameters passed to function.
+Alert: PASS: AFDate_FormatEx(1, 2) threw AFDate_FormatEx: Incorrect number of parameters passed to function.
+Alert: PASS: AFDate_FormatEx(2) = 2
+Alert: PASS: AFDate_FormatEx('blooey') = blooey
+Alert: PASS: AFDate_FormatEx('m/d') = 5/9
+Alert: **********************
+Alert: PASS: AFDate_Keystroke() threw AFDate_Keystroke: Incorrect number of parameters passed to function.
+Alert: PASS: AFDate_Keystroke(1, 2) threw AFDate_Keystroke: Incorrect number of parameters passed to function.
+Alert: PASS: AFDate_Keystroke(2) = 04/19
+Alert: PASS: AFDate_Keystroke('blooey') = 04/19/15
+Alert: **********************
+Alert: PASS: AFDate_KeystrokeEx() threw AFDate_KeystrokeEx: AFDate_KeystrokeEx's parameter size not correct
+Alert: PASS: AFDate_KeystrokeEx(1, 2) threw AFDate_KeystrokeEx: AFDate_KeystrokeEx's parameter size not correct
+[icon=3,type=0]: The input value can't be parsed as a valid date/time (2).
+Alert: PASS: AFDate_KeystrokeEx(2) = x
+[icon=3,type=0]: The input value can't be parsed as a valid date/time (blooey).
+Alert: PASS: AFDate_KeystrokeEx('blooey') = x
+[icon=3,type=0]: The input value can't be parsed as a valid date/time (m/d).
+Alert: PASS: AFDate_KeystrokeEx('m/d') = x
+Alert: **********************
+Alert: PASS: AFExtractNums() threw AFExtractNums: Incorrect number of parameters passed to function.
+Alert: PASS: AFExtractNums(1, 2) threw AFExtractNums: Incorrect number of parameters passed to function.
+Alert: PASS: AFExtractNums('100 200') = 100,200
+Alert: **********************
+Alert: PASS: AFMakeNumber() threw AFMakeNumber: Incorrect number of parameters passed to function.
+Alert: PASS: AFMakeNumber(1, 2) threw AFMakeNumber: Incorrect number of parameters passed to function.
+Alert: PASS: AFMakeNumber('2blooey') = 0
+Alert: PASS: AFMakeNumber(1) = 1
+Alert: PASS: AFMakeNumber('1.2') = 1.2
+Alert: PASS: AFMakeNumber('1,2') = 1.2
+Alert: **********************
+Alert: PASS: AFMergeChange() threw AFMergeChange: Incorrect number of parameters passed to function.
+Alert: PASS: AFMergeChange(1, 2) threw AFMergeChange: Incorrect number of parameters passed to function.
+Alert: PASS: AFMergeChange(undefined) = one
+Alert: **********************
+Alert: PASS: AFNumber_Format() threw AFNumber_Format: Incorrect number of parameters passed to function.
+Alert: PASS: AFNumber_Format(0, 1, 0, 0, '', false, 42) threw AFNumber_Format: Incorrect number of parameters passed to function.
+Alert: PASS: AFNumber_Format(0, 1, 0, 0, '', false) = 0
+Alert: PASS: AFNumber_Format(0, 1, 0, 0, '', false) = 12
+Alert: **********************
+Alert: PASS: AFNumber_Keystroke() threw AFNumber_Keystroke: Incorrect number of parameters passed to function.
+Alert: PASS: AFNumber_Keystroke(1) threw AFNumber_Keystroke: Incorrect number of parameters passed to function.
+[icon=3,type=0]: The input value is invalid.
+Alert: PASS: AFNumber_Keystroke(1, 2) threw AFNumber_Keystroke: The input value is invalid.
+Alert: PASS: AFNumber_Keystroke(1, 2) = 123
+Alert: PASS: AFNumber_Keystroke(1, 2, 3) = 123
+Alert: **********************
+Alert: PASS: AFParseDateEx() threw AFParseDateEx: Incorrect number of parameters passed to function.
+Alert: PASS: AFParseDateEx(1, 2, 3) threw AFParseDateEx: Incorrect number of parameters passed to function.
+Alert: PASS: AFParseDateEx(1, 2) = 1399646930000
+Alert: **********************
+Alert: PASS: AFPercent_Format() threw AFPercent_Format: Incorrect number of parameters passed to function.
+Alert: PASS: AFPercent_Format(1, 2, 3) threw AFPercent_Format: Incorrect number of parameters passed to function.
+Alert: PASS: AFPercent_Format(1, 0) = 1,234.6%
+Alert: PASS: AFPercent_Format(4, 1) = 1234.5600%
+Alert: **********************
+Alert: PASS: AFPercent_Keystroke() threw AFPercent_Keystroke: Incorrect number of parameters passed to function.
+Alert: PASS: AFPercent_Keystroke(1) threw AFPercent_Keystroke: Incorrect number of parameters passed to function.
+[icon=3,type=0]: The input value is invalid.
+Alert: PASS: AFPercent_Keystroke(1, 0) threw AFPercent_Keystroke: The input value is invalid.
+Alert: PASS: AFPercent_Keystroke(1, 0) = .123
+Alert: **********************
+Alert: PASS: AFRange_Validate() threw AFRange_Validate: Incorrect number of parameters passed to function.
+Alert: PASS: AFRange_Validate(1, 2, 3, 4, 5) threw AFRange_Validate: Incorrect number of parameters passed to function.
+Alert: PASS: AFRange_Validate(true, 2, false, 4) = 3
+Alert: **********************
+Alert: PASS: AFSimple() threw AFSimple: Incorrect number of parameters passed to function.
+Alert: PASS: AFSimple(1, 2, 3, 4) threw AFSimple: Incorrect number of parameters passed to function.
+Alert: PASS: AFSimple(1, 2, 3) = 2
+Alert: **********************
+Alert: PASS: AFSimple_Calculate() threw AFSimple_Calculate: Incorrect number of parameters passed to function.
+Alert: PASS: AFSimple_Calculate(1) threw AFSimple_Calculate: Incorrect number of parameters passed to function.
+Alert: PASS: AFSimple_Calculate('blooey', [1, 3, 14]) = 0
+Alert: PASS: AFSimple_Calculate('AVG', [1, 3, 14]) = 0
+Alert: PASS: AFSimple_Calculate('SUM', [1, 3, 14]) = 0
+Alert: **********************
+Alert: PASS: AFSpecial_Format() threw AFSpecial_Format: Incorrect number of parameters passed to function.
+Alert: PASS: AFSpecial_Format(1, 2) threw AFSpecial_Format: Incorrect number of parameters passed to function.
+Alert: PASS: AFSpecial_Format(3) = --
+Alert: **********************
+Alert: PASS: AFSpecial_Keystroke() threw AFSpecial_Keystroke: Incorrect number of parameters passed to function.
+Alert: PASS: AFSpecial_Keystroke(65, 66) threw AFSpecial_Keystroke: Incorrect number of parameters passed to function.
+Alert: PASS: AFSpecial_Keystroke(65) = abc
+Alert: **********************
+Alert: PASS: AFSpecial_KeystrokeEx() threw AFSpecial_KeystrokeEx: Incorrect number of parameters passed to function.
+[icon=3,type=0]: The input value is invalid.
+Alert: PASS: AFSpecial_KeystrokeEx('999999') = 12
+Alert: **********************
+Alert: PASS: AFTime_Format() threw AFTime_Format: Incorrect number of parameters passed to function.
+Alert: PASS: AFTime_Format(1, 2) threw AFTime_Format: Incorrect number of parameters passed to function.
+Alert: PASS: AFTime_Format(1) = 2:48 pm
+Alert: **********************
+Alert: PASS: AFTime_FormatEx() threw AFTime_FormatEx: Incorrect number of parameters passed to function.
+Alert: PASS: AFTime_FormatEx('blooey', 42) threw AFTime_FormatEx: Incorrect number of parameters passed to function.
+Alert: PASS: AFTime_FormatEx('blooey') = blooey
+Alert: **********************
+Alert: PASS: AFTime_Keystroke() threw AFTime_Keystroke: Incorrect number of parameters passed to function.
+Alert: PASS: AFTime_Keystroke(1, 2) threw AFTime_Keystroke: Incorrect number of parameters passed to function.
+Alert: PASS: AFTime_Keystroke(65) = 12:03
+Alert: **********************
+Alert: PASS: AFTime_KeystrokeEx() threw AFTime_KeystrokeEx: AFDate_KeystrokeEx's parameter size not correct
+Alert: PASS: AFTime_KeystrokeEx(1, 2) threw AFTime_KeystrokeEx: AFDate_KeystrokeEx's parameter size not correct
+Alert: PASS: AFTime_KeystrokeEx('blooey') = 12:04
+Alert: *** ending test ***