summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-10-23 21:38:28 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-10-23 21:38:28 +0000
commit5ff1ddeb54a425e1af25607646697e93a39bd51d (patch)
tree31266c1e22ab146883cc165bc7925a341ce28a9d /testing
parent401077e47c49c3b1cb865ee6f1f29a931a6ca45b (diff)
downloadpdfium-5ff1ddeb54a425e1af25607646697e93a39bd51d.tar.xz
Test color.convert() and equal() from JS (and fix comparison logic).
Currently, color.equal(a, b) may not give the same result as color.equal(b, a) since arg1 is converted to be the type of arg2, and some of these conversions lose information. Instead promote to the type with the most components in the hope of preserving the most information. Better error message when there are the right number of parameters but the types are wrong. Change-Id: I1d93fa29db4fb65e0f7c07c3ba7d9ca87ebf7bc9 Reviewed-on: https://pdfium-review.googlesource.com/c/44413 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'testing')
-rw-r--r--testing/resources/javascript/color_methods.in133
-rw-r--r--testing/resources/javascript/color_methods_expected.txt57
2 files changed, 190 insertions, 0 deletions
diff --git a/testing/resources/javascript/color_methods.in b/testing/resources/javascript/color_methods.in
new file mode 100644
index 0000000000..1268657650
--- /dev/null
+++ b/testing/resources/javascript/color_methods.in
@@ -0,0 +1,133 @@
+{{header}}
+{{object 1 0}} <<
+ /Type /Catalog
+ /Pages 2 0 R
+ /OpenAction 10 0 R
+>>
+endobj
+{{object 2 0}} <<
+ /Type /Pages
+ /Count 1
+ /Kids [
+ 3 0 R
+ ]
+>>
+endobj
+% Page number 0.
+{{object 3 0}} <<
+ /Type /Page
+ /Parent 2 0 R
+ /MediaBox [0 0 612 792]
+>>
+endobj
+% OpenAction action
+{{object 10 0}} <<
+ /Type /Action
+ /S /JavaScript
+ /JS 11 0 R
+>>
+endobj
+% JS program to exexute
+{{object 11 0}} <<
+ {{streamlen}}
+>>
+stream
+function expect(str, expected) {
+ try {
+ var result = eval(str);
+ if (result == expected) {
+ app.alert('PASS: ' + str + ' = ' + result);
+ } else {
+ app.alert('FAIL: ' + str + ' = ' + result + ', expected = ' + expected);
+ }
+ } catch (e) {
+ app.alert('ERROR: ' + e.toString());
+ }
+}
+
+function expectError(str) {
+ try {
+ var result = eval(str);
+ app.alert('FAIL: ' + str + ' = ' + result + ', expected to throw error');
+ } catch (e) {
+ app.alert('PASS: ' + str + ' threw error ' + e.toString());
+ }
+}
+
+try {
+ expectError("color.convert()");
+ expectError("color.convert(1)");
+ expectError("color.convert(undefined, 'RGB')");
+ expectError("color.convert('BOGUS', 'RGB')");
+ expectError("color.convert('{}', 'RGB')");
+
+ // Can't convert transparent into anything else.
+ expect("color.convert(['T'], 'BOGUS')", "T");
+ expect("color.convert(['T'], 'T')", "T");
+ expect("color.convert(['T'], 'G')", "T");
+ expect("color.convert(['T'], 'RGB')", "T");
+ expect("color.convert(['T'], 'CMYK')", "T");
+
+ expect("color.convert(['G', 0.50], 'BOGUS')", "T");
+ expect("color.convert(['G', 0.50], 'T')", "T");
+ expect("color.convert(['G', 0.50], 'G')", "G,0.5");
+ expect("color.convert(['G', 0.50], 'RGB')", "RGB,0.5,0.5,0.5");
+ expect("color.convert(['G', 0.50], 'CMYK')", "CMYK,0,0,0,0.5");
+
+ expect("color.convert(['RGB', 0.25, 0.50, 0.75], 'BOGUS')", "T");
+ expect("color.convert(['RGB', 0.25, 0.50, 0.75], 'T')", "T");
+ expect("color.convert(['RGB', 1.00, 1.00, 1.00], 'G')", "G,1");
+ expect("color.convert(['RGB', 0.25, 0.50, 0.75], 'RGB')", "RGB,0.25,0.5,0.75");
+ expect("color.convert(['RGB', 0.25, 0.50, 0.75], 'CMYK')", "CMYK,0.75,0.5,0.25,0.25");
+
+ expect("color.convert(['CMYK',0.25,0.25,0.25,0.50], 'BOGUS')", "T");
+ expect("color.convert(['CMYK',0.25,0.25,0.25,0.50], 'T')", "T");
+ expect("color.convert(['CMYK',0.25,0.25,0.25,0.50], 'G')", "G,0.25");
+ expect("color.convert(['CMYK',0.25,0.25,0.25,0.50], 'RGB')", "RGB,0.25,0.25,0.25");
+ expect("color.convert(['CMYK',0.25,0.25,0.25,0.50], 'CMYK')", "CMYK,0.25,0.25,0.25,0.5");
+
+ expectError("color.equal()");
+ expectError("color.equal(1)");
+ expectError("color.equal(undefined, undefined)");
+ expectError("color.equal(undefined, 'BOGUS')");
+ expectError("color.equal('BOGUS', 'BOGUS')");
+ expectError("color.equal('BOGUS', ['T'])");
+ expectError("color.equal(['T'], 'BOGUS')");
+
+ expect("color.equal(['T'], ['T'])", true);
+ expect("color.equal(['T'], ['G', 0])", false);
+ expect("color.equal(['T'], ['RGB', 0, 0, 0])", false);
+ expect("color.equal(['T'], ['CMYK', 0, 0, 0, 0])", false);
+
+ expect("color.equal(['G', 0.50], ['T'])", false);
+ expect("color.equal(['G', 0.50], ['G', 0])", false);
+ expect("color.equal(['G', 0.50], ['G', 0.50])", true);
+ expect("color.equal(['G', 0.50], ['RGB', 0, 0, 0])", false);
+ expect("color.equal(['G', 0.50], ['RGB', 0.50, 0.50, 0.50])", true);
+ expect("color.equal(['G', 0.50], ['CMYK', 0, 0, 0, 0])", false);
+ expect("color.equal(['G', 0.50], ['CMYK', 0, 0, 0, 0.50])", true);
+
+ expect("color.equal(['RGB', 0.25, 0.25, 0.25], ['T'])", false);
+ expect("color.equal(['RGB', 0.25, 0.25, 0.25], ['G', 0])", false);
+ expect("color.equal(['RGB', 0.25, 0.25, 0.25], ['G', 0.25])", true);
+ expect("color.equal(['RGB', 0.25, 0.25, 0.25], ['RGB', 0, 0, 0])", false);
+ expect("color.equal(['RGB', 0.25, 0.25, 0.25], ['RGB', 0.25, 0.25, 0.25])", true);
+ expect("color.equal(['RGB', 0.25, 0.25, 0.25], ['CMYK', 0, 0, 0, 0])", false);
+ expect("color.equal(['RGB', 0.25, 0.25, 0.25], ['CMYK', 0.75, 0.75, 0.75, 0.75])", true);
+
+ expect("color.equal(['CMYK', 0.25, 0.25, 0.25, 0.50], ['T'])", false);
+ expect("color.equal(['CMYK', 0.00, 0.25, 0.25, 0.50], ['G', 0])", false);
+ expect("color.equal(['CMYK', 0.00, 0.00, 0.00, 0.50], ['G', 0.50])", true);
+ expect("color.equal(['CMYK', 0.75, 0.50, 0.25, 0.25], ['RGB', 0, 0, 0])", false);
+ expect("color.equal(['CMYK', 0.75, 0.50, 0.25, 0.25], ['RGB', 0.25, 0.50, 0.75])", true);
+ expect("color.equal(['CMYK', 0.25, 0.25, 0.25, 0.50], ['CMYK', 0, 0, 0, 0])", false);
+ expect("color.equal(['CMYK', 0.25, 0.25, 0.25, 0.50], ['CMYK', 0.25, 0.25, 0.25, 0.50])", true);
+} catch (e) {
+ app.alert("Truly unexpected error: " + e);
+}
+endstream
+endobj
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
diff --git a/testing/resources/javascript/color_methods_expected.txt b/testing/resources/javascript/color_methods_expected.txt
new file mode 100644
index 0000000000..2552a5e4ba
--- /dev/null
+++ b/testing/resources/javascript/color_methods_expected.txt
@@ -0,0 +1,57 @@
+Alert: PASS: color.convert() threw error color.convert: Incorrect number of parameters passed to function.
+Alert: PASS: color.convert(1) threw error color.convert: Incorrect number of parameters passed to function.
+Alert: PASS: color.convert(undefined, 'RGB') threw error color.convert: Incorrect parameter type.
+Alert: PASS: color.convert('BOGUS', 'RGB') threw error color.convert: Incorrect parameter type.
+Alert: PASS: color.convert('{}', 'RGB') threw error color.convert: Incorrect parameter type.
+Alert: PASS: color.convert(['T'], 'BOGUS') = T
+Alert: PASS: color.convert(['T'], 'T') = T
+Alert: PASS: color.convert(['T'], 'G') = T
+Alert: PASS: color.convert(['T'], 'RGB') = T
+Alert: PASS: color.convert(['T'], 'CMYK') = T
+Alert: PASS: color.convert(['G', 0.50], 'BOGUS') = T
+Alert: PASS: color.convert(['G', 0.50], 'T') = T
+Alert: PASS: color.convert(['G', 0.50], 'G') = G,0.5
+Alert: PASS: color.convert(['G', 0.50], 'RGB') = RGB,0.5,0.5,0.5
+Alert: PASS: color.convert(['G', 0.50], 'CMYK') = CMYK,0,0,0,0.5
+Alert: PASS: color.convert(['RGB', 0.25, 0.50, 0.75], 'BOGUS') = T
+Alert: PASS: color.convert(['RGB', 0.25, 0.50, 0.75], 'T') = T
+Alert: PASS: color.convert(['RGB', 1.00, 1.00, 1.00], 'G') = G,1
+Alert: PASS: color.convert(['RGB', 0.25, 0.50, 0.75], 'RGB') = RGB,0.25,0.5,0.75
+Alert: PASS: color.convert(['RGB', 0.25, 0.50, 0.75], 'CMYK') = CMYK,0.75,0.5,0.25,0.25
+Alert: PASS: color.convert(['CMYK',0.25,0.25,0.25,0.50], 'BOGUS') = T
+Alert: PASS: color.convert(['CMYK',0.25,0.25,0.25,0.50], 'T') = T
+Alert: PASS: color.convert(['CMYK',0.25,0.25,0.25,0.50], 'G') = G,0.25
+Alert: PASS: color.convert(['CMYK',0.25,0.25,0.25,0.50], 'RGB') = RGB,0.25,0.25,0.25
+Alert: PASS: color.convert(['CMYK',0.25,0.25,0.25,0.50], 'CMYK') = CMYK,0.25,0.25,0.25,0.5
+Alert: PASS: color.equal() threw error color.equal: Incorrect number of parameters passed to function.
+Alert: PASS: color.equal(1) threw error color.equal: Incorrect number of parameters passed to function.
+Alert: PASS: color.equal(undefined, undefined) threw error color.equal: Incorrect parameter type.
+Alert: PASS: color.equal(undefined, 'BOGUS') threw error color.equal: Incorrect parameter type.
+Alert: PASS: color.equal('BOGUS', 'BOGUS') threw error color.equal: Incorrect parameter type.
+Alert: PASS: color.equal('BOGUS', ['T']) threw error color.equal: Incorrect parameter type.
+Alert: PASS: color.equal(['T'], 'BOGUS') threw error color.equal: Incorrect parameter type.
+Alert: PASS: color.equal(['T'], ['T']) = true
+Alert: PASS: color.equal(['T'], ['G', 0]) = false
+Alert: PASS: color.equal(['T'], ['RGB', 0, 0, 0]) = false
+Alert: PASS: color.equal(['T'], ['CMYK', 0, 0, 0, 0]) = false
+Alert: PASS: color.equal(['G', 0.50], ['T']) = false
+Alert: PASS: color.equal(['G', 0.50], ['G', 0]) = false
+Alert: PASS: color.equal(['G', 0.50], ['G', 0.50]) = true
+Alert: PASS: color.equal(['G', 0.50], ['RGB', 0, 0, 0]) = false
+Alert: PASS: color.equal(['G', 0.50], ['RGB', 0.50, 0.50, 0.50]) = true
+Alert: PASS: color.equal(['G', 0.50], ['CMYK', 0, 0, 0, 0]) = false
+Alert: PASS: color.equal(['G', 0.50], ['CMYK', 0, 0, 0, 0.50]) = true
+Alert: PASS: color.equal(['RGB', 0.25, 0.25, 0.25], ['T']) = false
+Alert: PASS: color.equal(['RGB', 0.25, 0.25, 0.25], ['G', 0]) = false
+Alert: PASS: color.equal(['RGB', 0.25, 0.25, 0.25], ['G', 0.25]) = true
+Alert: PASS: color.equal(['RGB', 0.25, 0.25, 0.25], ['RGB', 0, 0, 0]) = false
+Alert: PASS: color.equal(['RGB', 0.25, 0.25, 0.25], ['RGB', 0.25, 0.25, 0.25]) = true
+Alert: PASS: color.equal(['RGB', 0.25, 0.25, 0.25], ['CMYK', 0, 0, 0, 0]) = false
+Alert: PASS: color.equal(['RGB', 0.25, 0.25, 0.25], ['CMYK', 0.75, 0.75, 0.75, 0.75]) = true
+Alert: PASS: color.equal(['CMYK', 0.25, 0.25, 0.25, 0.50], ['T']) = false
+Alert: PASS: color.equal(['CMYK', 0.00, 0.25, 0.25, 0.50], ['G', 0]) = false
+Alert: PASS: color.equal(['CMYK', 0.00, 0.00, 0.00, 0.50], ['G', 0.50]) = true
+Alert: PASS: color.equal(['CMYK', 0.75, 0.50, 0.25, 0.25], ['RGB', 0, 0, 0]) = false
+Alert: PASS: color.equal(['CMYK', 0.75, 0.50, 0.25, 0.25], ['RGB', 0.25, 0.50, 0.75]) = true
+Alert: PASS: color.equal(['CMYK', 0.25, 0.25, 0.25, 0.50], ['CMYK', 0, 0, 0, 0]) = false
+Alert: PASS: color.equal(['CMYK', 0.25, 0.25, 0.25, 0.50], ['CMYK', 0.25, 0.25, 0.25, 0.50]) = true