summaryrefslogtreecommitdiff
path: root/testing/resources/javascript/field.in
blob: 588ae334e5ab33975dc443d6364b5cef4cc31cb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
{{header}}
{{object 1 0}} <<
  /Type /Catalog
  /Pages 2 0 R
  /AcroForm 4 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
  /Resources <<
    /Font <</F1 15 0 R>>
  >>
  /Contents [21 0 R]
  /MediaBox [0 0 612 792]
>>
endobj
% Forms
{{object 4 0}} <<
  /Fields [5 0 R]
>>
endobj
% Fields
{{object 5 0}} <<
  /T (MyField)
  /Type /Annot
  /Subtype /Widget
  /Rect [100 100 400 400]
  /Kids [
    6 0 R
    7 0 R
    8 0 R
    9 0 R
  ]
>>
endobj
{{object 6 0}} <<
  /FT /Tx
  /Parent 5 0 R
  /T (Sub_X)
  /Type /Annot
  /Subtype /Widget
  /Rect [200 200 220 220]
>>
endobj
{{object 7 0}} <<
  /FT /Tx
  /Parent 5 0 R
  /T (Sub_A)
  /Type /Annot
  /Subtype /Widget
  /Rect [220 220 240 240]
>>
endobj
{{object 8 0}} <<
  /FT /Tx
  /Parent 5 0 R
  /T (Sub_Z)
  /Type /Annot
  /Subtype /Widget
  /Rect [240 240 260 260]
>>
endobj
{{object 9 0}} <<
  /FT /Tx
  /Parent 5 0 R
  /T (Sub_B)
  /Type /Annot
  /Subtype /Widget
  /Rect [260 260 280 280]
>>
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 testGetField() {
  try {
    var field = this.getField("MyField");
    app.alert("field is " + field.name);
    var sub_a = this.getField("MyField.Sub_A");
    app.alert("sub_a is " + sub_a.name);
    var nonesuch = this.getField("MyField.nonesuch");
    app.alert("nonesuch is " + nonesuch);
  } catch (e) {
    app.alert("Unexpected error: " + e);
  }
}

function testGetArray() {
  try {
    var subs = this.getField("MyField").getArray();
    app.alert("found " + subs.length + " sub-fields:");
    for (i = 0; i < subs.length; ++i) {
      app.alert(subs[i].name);
    }
  } catch (e) {
    app.alert("Unexpected error: " + e);
  }
}

function testReadProperty(field, prop, expected) {
  try {
    var actual = field[prop];
    if (actual == expected) {
      app.alert('PASS: ' + prop + ' = ' + actual);
    } else {
      app.alert('FAIL: ' + prop + ' = ' + actual + ', expected = ' + expected);
    }
  } catch (e) {
    app.alert('ERROR: ' + e.toString());
  }
}

function testUnreadableProperty(field, prop) {
  try {
    var value = field[prop];
    app.alert('FAIL: ' + prop + ', expected to throw error');
  } catch (e) {
    app.alert('PASS: ' + prop + ' threw error ' + e.toString());
  }
}

function testWriteProperty(field, prop, newValue) {
  try {
    field[prop] = newValue;
    var actual = field[prop];
    if (actual == newValue) {
      app.alert('PASS: ' + prop + ' = ' + actual);
    } else {
      app.alert('FAIL: ' + prop + ' = ' + actual + ', expected = ' + newValue);
    }
  } catch (e) {
    app.alert('ERROR: ' + e.toString());
  }
}

function testWriteIgnoredProperty(field, prop, expected, newValue) {
  try {
    field[prop] = newValue;
    var actual = field[prop];
    if (actual == expected) {
      app.alert('PASS: ' + prop + ' = ' + actual);
    } else {
      app.alert('FAIL: ' + prop + ' = ' + actual + ', expected = ' + expected);
    }
  } catch (e) {
    app.alert('ERROR: ' + e.toString());
  }
}

function testUnwritableProperty(field, prop, newValue) {
  try {
    field[prop] = newValue;
    app.alert('FAIL: ' + prop + ' = ' + newValue + ', expected to throw error');
  } catch (e) {
    app.alert('PASS: ' + prop + ' threw error ' + e.toString());
  }
}

function testRWProperty(field, prop, expected, newValue) {
  testReadProperty(field, prop, expected);
  testWriteProperty(field, prop, newValue);
}

function testRIProperty(field, prop, expected, newValue) {
  testReadProperty(field, prop, expected);
  testWriteIgnoredProperty(field, prop, expected, newValue);
}

function testROProperty(field, prop, expected) {
  testReadProperty(field, prop, expected);
  testUnwritableProperty(field, prop, 42);
}

function testXXProperty(field, prop) {
  testUnreadableProperty(field, prop);
  testUnwritableProperty(field, prop, 42);
}

function testProperties() {
  try {
    var field = this.getField("MyField");
    app.alert('Testing properties under delay');
    testRWProperty(field, "delay", false, true);
    // TODO(tsepez): try this case, too.
    // testPropertiesCase(field);
    app.alert('Testing properties under non-delay');
    testRWProperty(field, "delay", true, false);
    testPropertiesCase(field);
  } catch (e) {
    app.alert("Unexpected error: " + e);
  }
}

function testPropertiesCase(field) {
  try {
    // TODO(tsepez): devise tests and uncomment.
    testRIProperty(field, "alignment", "left", "center");
    // testRWProperty(field, "borderStyle", "solid", "inset");
    // testROProperty(field, "buttonAlignX", "clams");
    // testROProperty(field, "buttonAlignY", "clams");
    // testROProperty(field, "buttonFitBounds", "clams");
    // testROProperty(field, "buttonPosition", "clams");
    // testROProperty(field, "buttonScaleHow", "clams");
    // testROProperty(field, "buttonScaleWhen", "clams");
    testRIProperty(field, "calcOrderIndex", -1, 100);
    testRIProperty(field, "charLimit", 0, 100);
    testRIProperty(field, "comb", false, true);
    // testRIProperty(field, "commitOnSelChange", false, true);
    // testROProperty(field, "currentValueIndices", "clams");
    testXXProperty(field, "defaultStyle");
    // testROProperty(field, "defaultValue", "clams");
    testRIProperty(field, "doNotScroll", false, true);
    testRIProperty(field, "doNotSpellCheck", false, true);
    // testROProperty(field, "display", "clams");
    testROProperty(field, "doc", "[object global]");
    // testROProperty(field, "editable", "clams");
    // testROProperty(field, "exportValues", "clams");
    // testROProperty(field, "hidden", "clams");
    testRIProperty(field, "fileSelect", false, true);
    testRIProperty(field, "fillColor", "T", ["RGB", 0, 0, 0]);
    // testROProperty(field, "lineWidth", "clams");
    // testROProperty(field, "highlight", "clams");
    testRIProperty(field, "multiline", false, true);
    // testROProperty(field, "multipleSelection", "clams");
    testROProperty(field, "name", "MyField");
    // testROProperty(field, "numItems", "clams");
    testROProperty(field, "page", -1);
    testRIProperty(field, "password", false, 42);
    // testROProperty(field, "print", "clams");
    // testROProperty(field, "radiosInUnison", "clams");
    testRIProperty(field, "readonly", false, true);
    // testRWProperty(field, "rect", [0,0,0,0], [0,0,0,0]);
    // testROProperty(field, "required", "clams");
    testRIProperty(field, "richText", false, true);
    testRIProperty(field, "richValue", undefined, "clams");
    testRIProperty(field, "rotation", 0, 42);
    testRIProperty(field, "source", undefined, "clams");
    testRIProperty(field, "strokeColor", "T", ["RGB", 0, 0, 0]);
    // testROProperty(field, "style", "clams");
    testRIProperty(field, "submitName", undefined, "clams");
    testRIProperty(field, "textColor", "T", ["RGB", 0, 0, 0]);
    // testROProperty(field, "textFont", "clams");
    testRIProperty(field, "textSize", 0, 32);
    testROProperty(field, "type", "text");
    testRIProperty(field, "userName", "");
    testRIProperty(field, "value", "", "clams");
    testROProperty(field, "valueAsString", "");
  } catch (e) {
    app.alert("Unexpected error: " + e);
  }
}

function testMethods() {
  try {
    var field = this.getField("MyField");
  } catch (e) {
    app.alert("Unexpected error: " + e);
  }
}

testGetField();
testGetArray();
testProperties();
testMethods();
endstream
endobj
{{xref}}
{{trailer}}
{{startxref}}
%%EOF