interplane.Get Omega
Read in your language

omega-office

Omega office documents: read and write office files in Omega

Brought by drakestapleton

branch main Branches Tags History

omega-office / tests / mkcases.om

422 lines · 7432 bytes Raw Blame History
1om2
2note tests/mkcases.om: writes the generated test files into the directory named by argument 1 (it must exist).
3note Build and run from the repository root:
4note OMC < tests/mkcases.om > build/mkcases && chmod +x build/mkcases && build/mkcases corpus/gen
5note Every file is a function of this source only (no clock, no randomness), so a rerun gives the same bytes.
6note rb-name256.xml, rb-name257.xml an element name of 256 (accepted) and 257 bytes (refusal 70)
7note rb-attr256.xml, rb-attr257.xml 256 (accepted) and 257 attributes on one element (refusal 71)
8note rb-abytes-ok.xml, rb-abytes.xml attribute bytes of one tag 262144 (accepted) and 262145 (refusal 72)
9note rb-depth1024.xml, rb-depth1025.xml nesting 1024 (accepted) and 1025 (refusal 73)
10note rb-ns4095.xml, rb-ns4096.xml 4095 (accepted) and 4096 namespace declarations in scope (refusal 74)
11note rb-ref32.xml, rb-ref33.xml a character reference of 32 (accepted) and 33 bytes (refusal 75)
12note sst1048576.xml, sst1048577.xml shared string tables of 1048576 (accepted) and 1048577 items (refusal 85)
13note rows.csv 5000 rows of six columns (numbers, text, quotes, commas, empty cells)
14
15global ob uchar 65536
16global onb ulong 1
17global wfd ulong 1
18global path uchar 4096
19global dl ulong 1
20
21text tsl "/"
22text tusage "usage: mkcases DIR [big]\n"
23text terr "mkcases: cannot write a file\n"
24text kq "\"/>"
25text ksst1 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<sst xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">"
26text ksst2 "<si><t>s</t></si>"
27text ksst3 "</sst>\n"
28
29fn die t view uchar * to void
30r = write 2 t 0 len t
31exit 1
32end
33
34fn wflush to void
35n = get onb 0
36o = ulong 0
37while lt o n bound 1000000
38r = write int get wfd 0 ob o sub n o
39if le r 0
40die terr
41end
42o = add o ulong r
43end
44put onb 0 0
45end
46
47fn b c ulong to void
48n = get onb 0
49put ob n uchar c
50n = add n 1
51put onb 0 n
52if eq n 65536
53wflush
54end
55end
56
57fn s t view uchar * to void
58for i ulong len t bound 4096
59b ulong get t i
60end
61end
62
63fn num v ulong to void
64d = new uchar 24 0
65k = ulong 0
66x = v
67while true bound 24
68put d k uchar add rem x 10 48
69k = add k 1
70x = div x 10
71if eq x 0
72break
73end
74end
75while gt k 0 bound 24
76k = sub k 1
77b ulong get d k
78end
79end
80
81fn rep c ulong n ulong to void
82for i ulong n bound 1000000
83b c
84end
85end
86
87note wopen: create DIR/name (truncate) for writing.
88fn wopen t view uchar * to void
89n = get dl 0
90put path n 47
91for i ulong len t bound 64
92put path add add n 1 i get t i
93end
94fd = fopen path 0 add add n 1 len t 577 420
95if lt fd 0
96die terr
97end
98put wfd 0 ulong fd
99put onb 0 0
100end
101
102fn wclose to void
103wflush
104r = fclose int get wfd 0
105if lt r 0
106die terr
107end
108end
109
110text n256 "rb-name256.xml"
111text n257 "rb-name257.xml"
112fn gname t view uchar * k ulong to void
113wopen t
114b 60
115rep 97 k
116b 47
117b 62
118wclose
119end
120
121text a256 "rb-attr256.xml"
122text a257 "rb-attr257.xml"
123fn gattr t view uchar * k ulong to void
124wopen t
125b 60
126b 97
127for i ulong k bound 1000
128b 32
129b 97
130num i
131b 61
132b 34
133b 49
134b 34
135end
136b 47
137b 62
138wclose
139end
140
141text ab1 "rb-abytes-ok.xml"
142text ab2 "rb-abytes.xml"
143note gabytes: one attribute v whose value has k bytes: the tag holds 1 + k bytes of names and values.
144fn gabytes t view uchar * k ulong to void
145wopen t
146b 60
147b 97
148b 32
149b 118
150b 61
151b 34
152rep 120 k
153s kq
154wclose
155end
156
157text d1024 "rb-depth1024.xml"
158text d1025 "rb-depth1025.xml"
159fn gdepth t view uchar * k ulong to void
160wopen t
161for i ulong k bound 2000
162b 60
163b 97
164b 62
165end
166for i ulong k bound 2000
167b 60
168b 47
169b 97
170b 62
171end
172wclose
173end
174
175text ns4095 "rb-ns4095.xml"
176text ns4096 "rb-ns4096.xml"
177note gns: k declarations xmlns:pN="u", at most 256 per element, elements nested so all are in scope.
178fn gns t view uchar * k ulong to void
179wopen t
180e = ulong 0
181i = ulong 0
182while lt i k bound 100
183b 60
184b 101
185j = ulong 0
186while and lt j 256 lt i k bound 257
187b 32
188b 120
189b 109
190b 108
191b 110
192b 115
193b 58
194b 112
195num i
196b 61
197b 34
198b 117
199b 34
200i = add i 1
201j = add j 1
202end
203b 62
204e = add e 1
205end
206for x ulong e bound 100
207b 60
208b 47
209b 101
210b 62
211end
212wclose
213end
214
215text r32 "rb-ref32.xml"
216text r33 "rb-ref33.xml"
217note gref: a character reference with z leading zeros: the body "#" + z zeros + "65" has 3 + z bytes.
218fn gref t view uchar * z ulong to void
219wopen t
220b 60
221b 114
222b 62
223b 38
224b 35
225rep 48 z
226b 54
227b 53
228b 59
229b 60
230b 47
231b 114
232b 62
233wclose
234end
235
236text sst1 "sst1048576.xml"
237text sst2 "sst1048577.xml"
238fn gsst t view uchar * k ulong to void
239wopen t
240s ksst1
241for i ulong k bound 1100000
242s ksst2
243end
244s ksst3
245wclose
246end
247
248note rows.csv: row i (1..5000): i, i*7 mod 1000 / 8 as a decimal, a word, a field that needs quoting every
249note 7th row, an empty field every 5th row, -i.
250text trows "rows.csv"
251text kw1 "alpha"
252text kw2 "beta"
253text kw3 "gamma"
254text kq1 "\"comma, and \"\"quote\"\"\""
255fn grow i ulong to void
256num i
257b 44
258v = rem mul i 7 1000
259num div v 8
260b 46
261num rem v 8
262b 44
263k = rem i 3
264if eq k 0
265s kw1
266end
267if eq k 1
268s kw2
269end
270if eq k 2
271s kw3
272end
273b 44
274if eq rem i 7 0
275s kq1
276else
277b 120
278num i
279end
280b 44
281if ne rem i 5 0
282b 121
283end
284b 44
285b 45
286num i
287b 10
288end
289
290fn grows to void
291wopen trows
292for i ulong 5000
293grow add i 1
294end
295wclose
296end
297
298note ---- mkcases DIR big: inputs for the throughput measurement only (README "Measured speed"), not committed ----
299note big-document.xml: 600000 paragraphs, each two runs (an entity, a tab), about 64 MiB of WordprocessingML.
300note big-sheet.xml: 400000 rows of five cells (number, shared string, decimal, inline string, boolean);
301note big-sst.xml: 1000 shared strings.
302text tbdoc "big-document.xml"
303text tbsh "big-sheet.xml"
304text tbsst "big-sst.xml"
305text kbd1 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<w:document xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:body>"
306text kbp1 "<w:p><w:r><w:t xml:space=\"preserve\">Sentence "
307text kbp2 " of the throughput document, with &amp; an entity and some more ordinary words.</w:t></w:r><w:r><w:tab/><w:t>tail</w:t></w:r></w:p>\n"
308text kbd2 "</w:body></w:document>\n"
309text kbs1 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\"><sheetData>"
310text kbs2 "</sheetData></worksheet>\n"
311text krow1 "<row r=\""
312text kc1 "\"><c r=\"A"
313text kc2 "\"><v>"
314text kc3 "</v></c><c r=\"B"
315text kc4 "\" t=\"s\"><v>"
316text kc5 "</v></c><c r=\"C"
317text kc6 "</v></c><c r=\"D"
318text kc7 "\" t=\"inlineStr\"><is><t>inline "
319text kc8 "</t></is></c><c r=\"E"
320text kc9 "\" t=\"b\"><v>"
321text kc10 "</v></c></row>\n"
322text kss1 "<si><t>shared string "
323
324fn gbdoc to void
325wopen tbdoc
326s kbd1
327for i ulong 600000
328s kbp1
329num i
330s kbp2
331end
332s kbd2
333wclose
334end
335
336fn gbrow r ulong to void
337s krow1
338num r
339s kc1
340num r
341s kc2
342num r
343s kc3
344num r
345s kc4
346num rem r 1000
347s kc5
348num r
349s kc2
350num div r 2
351b 46
352num mul rem r 2 5
353s kc6
354num r
355s kc7
356num r
357s kc8
358num r
359s kc9
360num rem r 2
361s kc10
362end
363
364fn gbsheet to void
365wopen tbsh
366s kbs1
367for i ulong 400000
368gbrow add i 1
369end
370s kbs2
371wclose
372wopen tbsst
373s ksst1
374for i ulong 1000
375s kss1
376num i
377b 60
378b 47
379b 116
380b 62
381b 60
382b 47
383b 115
384b 105
385b 62
386end
387s ksst3
388wclose
389end
390
391fn main to int
392n = argcnt
393if and ne n 2 ne n 3
394die tusage
395end
396k = argread 1 path 0 4000
397if or le k 0 gt k 3999
398die tusage
399end
400put dl 0 ulong k
401if eq n 3
402gbdoc
403gbsheet
404ret 0
405end
406gname n256 256
407gname n257 257
408gattr a256 256
409gattr a257 257
410gabytes ab1 262143
411gabytes ab2 262144
412gdepth d1024 1024
413gdepth d1025 1025
414gns ns4095 4095
415gns ns4096 4096
416gref r32 29
417gref r33 30
418gsst sst1 1048576
419gsst sst2 1048577
420grows
421ret 0
422end