quickwin 3.0.1 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/README.en.md +3 -0
  2. package/README.md +2 -0
  3. package/package.json +2 -3
  4. package/qwin-nowasm-x86.exe +0 -0
  5. package/qwin-nowasm.exe +0 -0
  6. package/qwin-x86.exe +0 -0
  7. package/qwin.exe +0 -0
  8. package/examples/PdfCanvas.js +0 -38
  9. package/examples/PdfCanvas.tsx +0 -54
  10. package/examples/execd/main.js +0 -23379
  11. package/examples/execd/tray.js +0 -192
  12. package/examples/execd/worker.js +0 -122
  13. package/examples/pdf_preview2.js +0 -398
  14. package/examples/pdf_preview2.ts +0 -353
  15. package/examples/pdf_viewer.js +0 -22515
  16. package/examples/pdf_viewer.tsx +0 -228
  17. package/examples/test_gallery.js +0 -18692
  18. package/examples/test_gallery.tsx +0 -291
  19. package/examples/test_react_lazy.js +0 -18560
  20. package/examples/test_react_lazy.tsx +0 -65
  21. package/examples/test_react_listbox.js +0 -18562
  22. package/examples/test_react_listbox.tsx +0 -73
  23. package/examples/test_root_window.js +0 -18532
  24. package/examples/test_root_window.tsx +0 -41
  25. package/examples/test_tab.js +0 -18563
  26. package/examples/test_tab.tsx +0 -77
  27. package/examples/tray_demo.js +0 -86
  28. package/examples/tray_demo.tsx +0 -89
  29. package/test/add.wasm +0 -0
  30. package/test/bench_ffi_callraw.js +0 -235
  31. package/test/bench_ffi_callraw.ts +0 -235
  32. package/test/bench_ffi_overhead.js +0 -139
  33. package/test/bench_ffi_overhead.ts +0 -141
  34. package/test/bench_sendmessage.js +0 -104
  35. package/test/bench_sendmessage.ts +0 -100
  36. package/test/bench_sendmessage_nonnull.js +0 -187
  37. package/test/bench_sendmessage_nonnull.ts +0 -188
  38. package/test/complex.wasm +0 -0
  39. package/test/complex_imports.wasm +0 -0
  40. package/test/debug/http_server_e2e.js +0 -31
  41. package/test/debug/minwasm.js +0 -52
  42. package/test/debug/mupdf_debug.js +0 -86
  43. package/test/debug/wasm.js +0 -122
  44. package/test/debug/wasm_export_debug.js +0 -54
  45. package/test/debug/wasm_names.js +0 -36
  46. package/test/example.pdf +0 -0
  47. package/test/global_imports.wasm +0 -0
  48. package/test/import_func.wasm +0 -0
  49. package/test/imports.wasm +0 -0
  50. package/test/mupdf-cdn.js +0 -40
  51. package/test/mupdf-cdn.ts +0 -43
  52. package/test/run.js +0 -111
  53. package/test/run.ts +0 -116
  54. package/test/sjlj.wasm +0 -0
  55. package/test/test_basic.js +0 -7
  56. package/test/test_basic.ts +0 -9
  57. package/test/test_basic_fetch.js +0 -63
  58. package/test/test_basic_fetch.ts +0 -59
  59. package/test/test_brotli.js +0 -48
  60. package/test/test_brotli.ts +0 -52
  61. package/test/test_fetch_cache.js +0 -169
  62. package/test/test_fetch_cache.ts +0 -187
  63. package/test/test_ffi.js +0 -157
  64. package/test/test_ffi.ts +0 -170
  65. package/test/test_ffi_abi.js +0 -290
  66. package/test/test_ffi_abi.ts +0 -274
  67. package/test/test_ffi_array.js +0 -116
  68. package/test/test_ffi_array.ts +0 -141
  69. package/test/test_ffi_bind.js +0 -656
  70. package/test/test_ffi_bind.ts +0 -670
  71. package/test/test_ffi_struct.js +0 -779
  72. package/test/test_ffi_struct.ts +0 -828
  73. package/test/test_ffi_struct_layout.js +0 -495
  74. package/test/test_ffi_struct_layout.ts +0 -543
  75. package/test/test_ffi_user32.js +0 -103
  76. package/test/test_ffi_user32.ts +0 -113
  77. package/test/test_ffi_windows.js +0 -172
  78. package/test/test_ffi_windows.ts +0 -187
  79. package/test/test_files.js +0 -102
  80. package/test/test_files.ts +0 -121
  81. package/test/test_frame_encoding.js +0 -128
  82. package/test/test_frame_encoding.ts +0 -132
  83. package/test/test_gdi_draw.js +0 -681
  84. package/test/test_gdi_draw.ts +0 -725
  85. package/test/test_helper.js +0 -91
  86. package/test/test_helper.ts +0 -88
  87. package/test/test_http_import.js +0 -96
  88. package/test/test_http_import.ts +0 -93
  89. package/test/test_http_server.js +0 -214
  90. package/test/test_http_server.ts +0 -211
  91. package/test/test_import_dir.js +0 -4
  92. package/test/test_import_dir.ts +0 -5
  93. package/test/test_ipv6.js +0 -134
  94. package/test/test_ipv6.ts +0 -130
  95. package/test/test_jsx.js +0 -1314
  96. package/test/test_meta_url.js +0 -3
  97. package/test/test_meta_url.ts +0 -4
  98. package/test/test_mupdf_render.js +0 -51
  99. package/test/test_mupdf_render.ts +0 -55
  100. package/test/test_mupdf_twice.js +0 -62
  101. package/test/test_mupdf_twice.ts +0 -65
  102. package/test/test_mupdf_wasm.js +0 -39
  103. package/test/test_mupdf_wasm.ts +0 -32
  104. package/test/test_net_event.js +0 -57
  105. package/test/test_net_event.ts +0 -56
  106. package/test/test_net_fetch.js +0 -384
  107. package/test/test_net_fetch.ts +0 -373
  108. package/test/test_net_websocket.js +0 -180
  109. package/test/test_net_websocket.ts +0 -164
  110. package/test/test_polyfill.js +0 -144
  111. package/test/test_polyfill.ts +0 -159
  112. package/test/test_printer.js +0 -137
  113. package/test/test_printer.ts +0 -148
  114. package/test/test_proc.js +0 -141
  115. package/test/test_proc.ts +0 -163
  116. package/test/test_react_complex.js +0 -18678
  117. package/test/test_react_counter.js +0 -18555
  118. package/test/test_react_flex.js +0 -18871
  119. package/test/test_react_hidden.js +0 -18560
  120. package/test/test_react_listview_link.js +0 -18590
  121. package/test/test_react_notify.js +0 -18797
  122. package/test/test_react_render.js +0 -18550
  123. package/test/test_registry.js +0 -74
  124. package/test/test_registry.ts +0 -95
  125. package/test/test_sysinfo.js +0 -122
  126. package/test/test_sysinfo.ts +0 -141
  127. package/test/test_url.js +0 -173
  128. package/test/test_url.ts +0 -183
  129. package/test/test_wasm_basic.js +0 -85
  130. package/test/test_wasm_basic.ts +0 -73
  131. package/test/test_wasm_import_global.js +0 -41
  132. package/test/test_wasm_import_global.ts +0 -45
  133. package/test/test_wasm_sjlj.js +0 -145
  134. package/test/test_wasm_sjlj.ts +0 -125
  135. package/test/test_wasm_types.js +0 -97
  136. package/test/test_wasm_types.ts +0 -124
  137. package/test/test_wolfssl_read.js +0 -203
  138. package/test/test_wolfssl_read.ts +0 -184
  139. package/test/test_worker.js +0 -21
  140. package/test/test_worker.ts +0 -24
  141. package/test/test_worker_concurrent.js +0 -45
  142. package/test/test_worker_concurrent.ts +0 -56
  143. package/test/test_worker_data_url.js +0 -46
  144. package/test/test_worker_data_url.ts +0 -51
  145. package/test/test_worker_fetch.js +0 -26
  146. package/test/test_worker_fetch.ts +0 -27
  147. package/test/test_worker_net.js +0 -69
  148. package/test/test_worker_net.ts +0 -66
  149. package/test/test_worker_wasm_concurrent.js +0 -44
  150. package/test/test_worker_wasm_concurrent.ts +0 -45
  151. package/test/types.wasm +0 -0
  152. package/test/worker_fetch.js +0 -13
  153. package/test/worker_fetch.ts +0 -13
  154. package/test/worker_helper.js +0 -1
  155. package/test/worker_helper.ts +0 -1
  156. package/test/worker_http.js +0 -18
  157. package/test/worker_http.ts +0 -20
  158. package/test/worker_import_lib.js +0 -12
  159. package/test/worker_import_lib.ts +0 -13
  160. package/test/worker_module.js +0 -16
  161. package/test/worker_module.ts +0 -17
  162. package/test/worker_wasm_concurrent.js +0 -22
  163. package/test/worker_wasm_concurrent.ts +0 -22
@@ -1,59 +0,0 @@
1
- import * as std from 'std'
2
- import '../lib/fetch.js'
3
- import { Tester } from './test_helper.js'
4
-
5
- const PORT = 18923
6
- const URL127 = `http://127.0.0.1:${PORT}/`
7
- const URLLocalhost = `http://localhost:${PORT}/`
8
-
9
- export const suite = {
10
- name: 'basic-fetch',
11
- run: async (t: Tester) => {
12
- function assert(name: string, ok: boolean): void {
13
- if (ok) { t.ok++; std.printf(' PASS: %s\n', name) }
14
- else { t.fail++; std.printf(' FAIL: %s\n', name) }
15
- }
16
-
17
- t.section('fetch 127.0.0.1')
18
- {
19
- const r = await fetch(URL127)
20
- assert('status 200', r.status === 200)
21
- const body = await r.text()
22
- assert('body = hello from test server', body === 'hello from test server')
23
- }
24
-
25
- t.section('fetch localhost')
26
- {
27
- const r = await fetch(URLLocalhost)
28
- assert('status 200', r.status === 200)
29
- const body = await r.text()
30
- assert('body = hello from test server', body === 'hello from test server')
31
- }
32
-
33
- t.section('fetch chunked response with Trailer')
34
- {
35
- const r = await fetch(URL127 + 'trailer')
36
- assert('status 200', r.status === 200)
37
- assert('trailer declared', (r.headers.get('trailer') || '').toLowerCase() === 'x-checksum')
38
- const body = await r.text()
39
- assert('body decoded without trailer footer', body === 'chunkA/chunkB')
40
- }
41
-
42
- t.section('protocol whitelist (reject non-http(s))')
43
- {
44
- const badUrls = [
45
- 'file:///C:/secret.txt',
46
- 'data:text/plain,hello',
47
- 'javascript:alert(1)',
48
- 'ftp://example.com/resource',
49
- ]
50
- for (const u of badUrls) {
51
- let err = ''
52
- let rejected = false
53
- try { await fetch(u) }
54
- catch (e: unknown) { rejected = true; err = (e as Error).message }
55
- assert(`reject ${u} with TypeError`, rejected && err.includes('unsupported protocol'))
56
- }
57
- }
58
- }
59
- }
@@ -1,48 +0,0 @@
1
- import * as brotli from 'brotli';
2
- function abToString(buf) {
3
- const bytes = new Uint8Array(buf);
4
- let s = '';
5
- for (let i = 0; i < bytes.length; i++)
6
- s += String.fromCharCode(bytes[i]);
7
- return s;
8
- }
9
- // pre-compressed with brotli CLI: "hello brotli! this is a test of decompression"
10
- const COMPRESSED_HEX = 'a16001c0ef4cb07142bdbbe12588185985d055995ca6b1bdb52083f4028dc6e59c8660a24efa701549c30701';
11
- function hexToArrayBuffer(hex) {
12
- const bytes = new Uint8Array(hex.length / 2);
13
- for (let i = 0; i < hex.length; i += 2)
14
- bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16);
15
- return bytes.buffer;
16
- }
17
- export const suite = {
18
- name: 'brotli',
19
- run: (t) => {
20
- t.section('decompress function exists');
21
- t.checkTrue('decompress is function', typeof brotli.decompress === 'function');
22
- t.section('decompress known string');
23
- const compressed = hexToArrayBuffer(COMPRESSED_HEX);
24
- const decompressed = brotli.decompress(compressed);
25
- t.checkTrue('returns ArrayBuffer', decompressed instanceof ArrayBuffer);
26
- const result = abToString(decompressed);
27
- t.check('roundtrip', 'hello brotli! this is a test of decompression', result);
28
- t.section('invalid data throws');
29
- let threw = false;
30
- try {
31
- brotli.decompress(new ArrayBuffer(10));
32
- }
33
- catch (e) {
34
- threw = true;
35
- }
36
- t.checkTrue('throws on invalid brotli data', threw);
37
- t.section('non-ArrayBuffer throws');
38
- let threw2 = false;
39
- try {
40
- ;
41
- brotli.decompress('not a buffer');
42
- }
43
- catch (e) {
44
- threw2 = true;
45
- }
46
- t.checkTrue('throws on non-ArrayBuffer', threw2);
47
- }
48
- };
@@ -1,52 +0,0 @@
1
- import * as brotli from 'brotli'
2
- import { Tester } from './test_helper.js'
3
-
4
- function abToString(buf: ArrayBuffer): string {
5
- const bytes = new Uint8Array(buf)
6
- let s = ''
7
- for (let i = 0; i < bytes.length; i++) s += String.fromCharCode(bytes[i]!)
8
- return s
9
- }
10
-
11
- // pre-compressed with brotli CLI: "hello brotli! this is a test of decompression"
12
- const COMPRESSED_HEX = 'a16001c0ef4cb07142bdbbe12588185985d055995ca6b1bdb52083f4028dc6e59c8660a24efa701549c30701'
13
-
14
- function hexToArrayBuffer(hex: string): ArrayBuffer {
15
- const bytes = new Uint8Array(hex.length / 2)
16
- for (let i = 0; i < hex.length; i += 2)
17
- bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16)
18
- return bytes.buffer as ArrayBuffer
19
- }
20
-
21
- export const suite = {
22
- name: 'brotli',
23
- run: (t: Tester) => {
24
- t.section('decompress function exists')
25
- t.checkTrue('decompress is function', typeof brotli.decompress === 'function')
26
-
27
- t.section('decompress known string')
28
- const compressed = hexToArrayBuffer(COMPRESSED_HEX)
29
- const decompressed = brotli.decompress(compressed)
30
- t.checkTrue('returns ArrayBuffer', decompressed instanceof ArrayBuffer)
31
- const result = abToString(decompressed)
32
- t.check('roundtrip', 'hello brotli! this is a test of decompression', result)
33
-
34
- t.section('invalid data throws')
35
- let threw = false
36
- try {
37
- brotli.decompress(new ArrayBuffer(10))
38
- } catch (e) {
39
- threw = true
40
- }
41
- t.checkTrue('throws on invalid brotli data', threw)
42
-
43
- t.section('non-ArrayBuffer throws')
44
- let threw2 = false
45
- try {
46
- ;(brotli as any).decompress('not a buffer')
47
- } catch (e) {
48
- threw2 = true
49
- }
50
- t.checkTrue('throws on non-ArrayBuffer', threw2)
51
- }
52
- }
@@ -1,169 +0,0 @@
1
- import '../lib/fetch.js';
2
- import * as std from 'std';
3
- import * as os from 'os';
4
- import { parseIni, toIni } from '../lib/cache-utils.js';
5
- function getCacheDir() {
6
- const url = import.meta.url;
7
- let path = url.slice(7);
8
- if (path.length >= 3 && path[1] === ':')
9
- path = path.slice(1);
10
- const idx = path.lastIndexOf('/');
11
- if (idx < 0)
12
- return '_cache';
13
- const buildDir = path.slice(0, idx);
14
- const idx2 = buildDir.lastIndexOf('/');
15
- if (idx2 < 0)
16
- return '_cache';
17
- return buildDir.slice(0, idx2 + 1) + '_cache';
18
- }
19
- export const suite = {
20
- name: 'fetch-cache',
21
- run: async (t) => {
22
- function assert(name, ok) {
23
- if (ok) {
24
- t.ok++;
25
- std.printf(' PASS: %s\n', name);
26
- }
27
- else {
28
- t.fail++;
29
- std.printf(' FAIL: %s\n', name);
30
- }
31
- }
32
- const cacheDir = getCacheDir();
33
- const trackedUrls = [];
34
- t.section('__httpCache__ API exists');
35
- assert('__httpCache__ is defined', typeof __httpCache__ !== 'undefined');
36
- if (!__httpCache__)
37
- return;
38
- assert('readMeta is function', typeof __httpCache__.readMeta === 'function');
39
- assert('readBody is function', typeof __httpCache__.readBody === 'function');
40
- assert('writeBodyOnly is function', typeof __httpCache__.writeBodyOnly === 'function');
41
- assert('writeMeta is function', typeof __httpCache__.writeMeta === 'function');
42
- assert('cacheKey is function', typeof __httpCache__.cacheKey === 'function');
43
- t.section('writeBodyOnly + writeMeta + readMeta + readBody');
44
- const fakeUrl = 'https://test.local/cache-test';
45
- trackedUrls.push(fakeUrl);
46
- const testBody = 'hello cache test!';
47
- __httpCache__.writeBodyOnly(fakeUrl, testBody);
48
- __httpCache__.writeMeta(fakeUrl, toIni({}, {
49
- url: fakeUrl,
50
- storedAt: String(Math.floor(Date.now() / 1000)),
51
- maxAge: '60',
52
- status: '200',
53
- statusText: 'OK',
54
- }));
55
- const metaStr = __httpCache__.readMeta(fakeUrl);
56
- assert('meta written', metaStr !== null);
57
- if (metaStr) {
58
- const ini = parseIni(metaStr);
59
- assert('meta has storedAt', typeof ini.meta.storedAt === 'string' && ini.meta.storedAt.length > 0);
60
- assert('meta has maxAge', ini.meta.maxAge === '60');
61
- }
62
- const fullMeta = toIni({ 'content-type': 'text/plain' }, {
63
- url: fakeUrl,
64
- storedAt: String(Math.floor(Date.now() / 1000)),
65
- maxAge: '60',
66
- status: '200',
67
- statusText: 'OK',
68
- });
69
- __httpCache__.writeMeta(fakeUrl, fullMeta);
70
- const metaStr2 = __httpCache__.readMeta(fakeUrl);
71
- assert('meta overwritten', metaStr2 !== null);
72
- if (metaStr2) {
73
- const ini2 = parseIni(metaStr2);
74
- assert('meta has status', ini2.meta.status === '200');
75
- assert('meta has headers', ini2.headers['content-type'] === 'text/plain');
76
- }
77
- const bodyAb = __httpCache__.readBody(fakeUrl);
78
- assert('body read as ArrayBuffer', bodyAb !== null);
79
- if (bodyAb) {
80
- const view = new Uint8Array(bodyAb);
81
- let str = '';
82
- for (let i = 0; i < view.length; i++)
83
- str += String.fromCharCode(view[i]);
84
- assert('body content correct', str === testBody);
85
- }
86
- t.section('cacheKey');
87
- const key = __httpCache__.cacheKey('https://example.com/test.js');
88
- assert('cacheKey returns 16 hex chars', /^[0-9a-f]{16}$/.test(key));
89
- t.section('lastAccess via readMeta/writeMeta');
90
- const laUrl = 'https://test.local/lastaccess-test';
91
- trackedUrls.push(laUrl);
92
- __httpCache__.writeBodyOnly(laUrl, 'test');
93
- __httpCache__.writeMeta(laUrl, toIni({}, {
94
- url: laUrl,
95
- storedAt: String(Math.floor(Date.now() / 1000)),
96
- maxAge: '300',
97
- status: '200',
98
- statusText: 'OK',
99
- }));
100
- const beforeMeta = __httpCache__.readMeta(laUrl);
101
- if (beforeMeta) {
102
- const ini0 = parseIni(beforeMeta);
103
- assert('no lastAccess before update', ini0.meta.lastAccess === undefined);
104
- }
105
- const now = Math.floor(Date.now() / 1000);
106
- const laMeta = parseIni(__httpCache__.readMeta(laUrl) || '');
107
- laMeta.meta.lastAccess = String(now);
108
- __httpCache__.writeMeta(laUrl, toIni(laMeta.headers, laMeta.meta));
109
- const afterMeta = __httpCache__.readMeta(laUrl);
110
- if (afterMeta) {
111
- const ini1 = parseIni(afterMeta);
112
- assert('lastAccess present after update', typeof ini1.meta.lastAccess === 'string' && ini1.meta.lastAccess.length > 0);
113
- assert('lastAccess is numeric', /^\d+$/.test(ini1.meta.lastAccess));
114
- assert('meta preserved after lastAccess', ini1.meta.maxAge === '300');
115
- assert('no headers leaked', Object.keys(ini1.headers).length === 0);
116
- }
117
- t.section('fetch with caching');
118
- const cacheTestUrl = 'http://localhost:18923/cache/60';
119
- trackedUrls.push(cacheTestUrl);
120
- const resp1 = await fetch(cacheTestUrl);
121
- assert('first fetch ok', resp1.ok);
122
- const body1 = await resp1.text();
123
- assert('first fetch body non-empty', body1.length > 0);
124
- const cachedMeta = __httpCache__.readMeta(cacheTestUrl);
125
- assert('cached meta exists', cachedMeta !== null);
126
- if (cachedMeta) {
127
- const ini = parseIni(cachedMeta);
128
- assert('cached status = 200', ini.meta.status === '200');
129
- assert('cached maxAge = 60', ini.meta.maxAge === '60');
130
- }
131
- const cachedBody = __httpCache__.readBody(cacheTestUrl);
132
- assert('cached body exists', cachedBody !== null);
133
- if (cachedBody) {
134
- assert('cached body matches', cachedBody.byteLength > 0);
135
- }
136
- t.section('second fetch hits cache');
137
- const resp2 = await fetch(cacheTestUrl);
138
- assert('second fetch ok', resp2.ok);
139
- const body2 = await resp2.text();
140
- assert('second fetch body same length', body2.length === body1.length);
141
- const afterFetchMeta = __httpCache__.readMeta(cacheTestUrl);
142
- if (afterFetchMeta) {
143
- const iniLA = parseIni(afterFetchMeta);
144
- assert('lastAccess set after fetch cache hit', typeof iniLA.meta.lastAccess === 'string' && iniLA.meta.lastAccess.length > 0);
145
- }
146
- t.section('timing: network vs cache');
147
- const timingUrl = 'http://localhost:18923/cache/60?t=' + String(Date.now());
148
- trackedUrls.push(timingUrl);
149
- const rNet = await fetch(timingUrl);
150
- assert('network fetch ok', rNet.ok);
151
- const bodyNet = await rNet.text();
152
- assert('network body non-empty', bodyNet.length > 0);
153
- const t2 = Date.now();
154
- const rCache = await fetch(timingUrl);
155
- const t3 = Date.now();
156
- const timeCache = t3 - t2;
157
- assert('cache fetch ok', rCache.ok);
158
- const bodyCache = await rCache.text();
159
- assert('cache body same length', bodyCache.length === bodyNet.length);
160
- assert('cache non-negative time (' + timeCache + 'ms)', timeCache >= 0);
161
- t.section('cleanup');
162
- for (const url of trackedUrls) {
163
- const key = __httpCache__.cacheKey(url);
164
- os.remove(cacheDir + '/' + key + '.meta');
165
- os.remove(cacheDir + '/' + key + '.body');
166
- assert('no meta leftover for ' + key, __httpCache__.readMeta(url) === null);
167
- }
168
- }
169
- };
@@ -1,187 +0,0 @@
1
- import '../lib/fetch.js'
2
- import * as std from 'std'
3
- import * as os from 'os'
4
- import { Tester } from './test_helper.js'
5
- import { parseIni, toIni } from '../lib/cache-utils.js'
6
-
7
- function getCacheDir(): string {
8
- const url = import.meta.url
9
- let path = url.slice(7)
10
- if (path.length >= 3 && path[1] === ':') path = path.slice(1)
11
- const idx = path.lastIndexOf('/')
12
- if (idx < 0) return '_cache'
13
- const buildDir = path.slice(0, idx)
14
- const idx2 = buildDir.lastIndexOf('/')
15
- if (idx2 < 0) return '_cache'
16
- return buildDir.slice(0, idx2 + 1) + '_cache'
17
- }
18
-
19
- export const suite = {
20
- name: 'fetch-cache',
21
- run: async (t: Tester) => {
22
- function assert(name: string, ok: boolean): void {
23
- if (ok) { t.ok++; std.printf(' PASS: %s\n', name) }
24
- else { t.fail++; std.printf(' FAIL: %s\n', name) }
25
- }
26
-
27
- const cacheDir = getCacheDir()
28
- const trackedUrls: string[] = []
29
-
30
- t.section('__httpCache__ API exists')
31
- assert('__httpCache__ is defined', typeof __httpCache__ !== 'undefined')
32
- if (!__httpCache__) return
33
-
34
- assert('readMeta is function', typeof __httpCache__.readMeta === 'function')
35
- assert('readBody is function', typeof __httpCache__.readBody === 'function')
36
- assert('writeBodyOnly is function', typeof __httpCache__.writeBodyOnly === 'function')
37
- assert('writeMeta is function', typeof __httpCache__.writeMeta === 'function')
38
- assert('cacheKey is function', typeof __httpCache__.cacheKey === 'function')
39
-
40
- t.section('writeBodyOnly + writeMeta + readMeta + readBody')
41
- const fakeUrl = 'https://test.local/cache-test'
42
- trackedUrls.push(fakeUrl)
43
- const testBody = 'hello cache test!'
44
- __httpCache__.writeBodyOnly(fakeUrl, testBody)
45
- __httpCache__.writeMeta(fakeUrl, toIni(
46
- {},
47
- {
48
- url: fakeUrl,
49
- storedAt: String(Math.floor(Date.now() / 1000)),
50
- maxAge: '60',
51
- status: '200',
52
- statusText: 'OK',
53
- }
54
- ))
55
-
56
- const metaStr = __httpCache__.readMeta(fakeUrl)
57
- assert('meta written', metaStr !== null)
58
- if (metaStr) {
59
- const ini = parseIni(metaStr)
60
- assert('meta has storedAt', typeof ini.meta.storedAt === 'string' && ini.meta.storedAt.length > 0)
61
- assert('meta has maxAge', ini.meta.maxAge === '60')
62
- }
63
-
64
- const fullMeta = toIni(
65
- { 'content-type': 'text/plain' },
66
- {
67
- url: fakeUrl,
68
- storedAt: String(Math.floor(Date.now() / 1000)),
69
- maxAge: '60',
70
- status: '200',
71
- statusText: 'OK',
72
- }
73
- )
74
- __httpCache__.writeMeta(fakeUrl, fullMeta)
75
-
76
- const metaStr2 = __httpCache__.readMeta(fakeUrl)
77
- assert('meta overwritten', metaStr2 !== null)
78
- if (metaStr2) {
79
- const ini2 = parseIni(metaStr2)
80
- assert('meta has status', ini2.meta.status === '200')
81
- assert('meta has headers', ini2.headers['content-type'] === 'text/plain')
82
- }
83
-
84
- const bodyAb = __httpCache__.readBody(fakeUrl)
85
- assert('body read as ArrayBuffer', bodyAb !== null)
86
- if (bodyAb) {
87
- const view = new Uint8Array(bodyAb)
88
- let str = ''
89
- for (let i = 0; i < view.length; i++) str += String.fromCharCode(view[i]!)
90
- assert('body content correct', str === testBody)
91
- }
92
-
93
- t.section('cacheKey')
94
- const key = __httpCache__.cacheKey('https://example.com/test.js')
95
- assert('cacheKey returns 16 hex chars', /^[0-9a-f]{16}$/.test(key))
96
-
97
- t.section('lastAccess via readMeta/writeMeta')
98
- const laUrl = 'https://test.local/lastaccess-test'
99
- trackedUrls.push(laUrl)
100
- __httpCache__.writeBodyOnly(laUrl, 'test')
101
- __httpCache__.writeMeta(laUrl, toIni({}, {
102
- url: laUrl,
103
- storedAt: String(Math.floor(Date.now() / 1000)),
104
- maxAge: '300',
105
- status: '200',
106
- statusText: 'OK',
107
- }))
108
- const beforeMeta = __httpCache__.readMeta(laUrl)
109
- if (beforeMeta) {
110
- const ini0 = parseIni(beforeMeta)
111
- assert('no lastAccess before update', ini0.meta.lastAccess === undefined)
112
- }
113
- const now = Math.floor(Date.now() / 1000)
114
- const laMeta = parseIni(__httpCache__.readMeta(laUrl) || '')
115
- laMeta.meta.lastAccess = String(now)
116
- __httpCache__.writeMeta(laUrl, toIni(laMeta.headers, laMeta.meta))
117
- const afterMeta = __httpCache__.readMeta(laUrl)
118
- if (afterMeta) {
119
- const ini1 = parseIni(afterMeta)
120
- assert('lastAccess present after update', typeof ini1.meta.lastAccess === 'string' && ini1.meta.lastAccess.length > 0)
121
- assert('lastAccess is numeric', /^\d+$/.test(ini1.meta.lastAccess!))
122
- assert('meta preserved after lastAccess', ini1.meta.maxAge === '300')
123
- assert('no headers leaked', Object.keys(ini1.headers).length === 0)
124
- }
125
-
126
- t.section('fetch with caching')
127
- const cacheTestUrl = 'http://localhost:18923/cache/60'
128
- trackedUrls.push(cacheTestUrl)
129
-
130
- const resp1 = await fetch(cacheTestUrl)
131
- assert('first fetch ok', resp1.ok)
132
- const body1 = await resp1.text()
133
- assert('first fetch body non-empty', body1.length > 0)
134
-
135
- const cachedMeta = __httpCache__.readMeta(cacheTestUrl)
136
- assert('cached meta exists', cachedMeta !== null)
137
- if (cachedMeta) {
138
- const ini = parseIni(cachedMeta)
139
- assert('cached status = 200', ini.meta.status === '200')
140
- assert('cached maxAge = 60', ini.meta.maxAge === '60')
141
- }
142
-
143
- const cachedBody = __httpCache__.readBody(cacheTestUrl)
144
- assert('cached body exists', cachedBody !== null)
145
- if (cachedBody) {
146
- assert('cached body matches', cachedBody.byteLength > 0)
147
- }
148
-
149
- t.section('second fetch hits cache')
150
- const resp2 = await fetch(cacheTestUrl)
151
- assert('second fetch ok', resp2.ok)
152
- const body2 = await resp2.text()
153
- assert('second fetch body same length', body2.length === body1.length)
154
-
155
- const afterFetchMeta = __httpCache__.readMeta(cacheTestUrl)
156
- if (afterFetchMeta) {
157
- const iniLA = parseIni(afterFetchMeta)
158
- assert('lastAccess set after fetch cache hit', typeof iniLA.meta.lastAccess === 'string' && iniLA.meta.lastAccess.length > 0)
159
- }
160
-
161
- t.section('timing: network vs cache')
162
- const timingUrl = 'http://localhost:18923/cache/60?t=' + String(Date.now())
163
- trackedUrls.push(timingUrl)
164
-
165
- const rNet = await fetch(timingUrl)
166
- assert('network fetch ok', rNet.ok)
167
- const bodyNet = await rNet.text()
168
- assert('network body non-empty', bodyNet.length > 0)
169
-
170
- const t2 = Date.now()
171
- const rCache = await fetch(timingUrl)
172
- const t3 = Date.now()
173
- const timeCache = t3 - t2
174
- assert('cache fetch ok', rCache.ok)
175
- const bodyCache = await rCache.text()
176
- assert('cache body same length', bodyCache.length === bodyNet.length)
177
- assert('cache non-negative time (' + timeCache + 'ms)', timeCache >= 0)
178
-
179
- t.section('cleanup')
180
- for (const url of trackedUrls) {
181
- const key = __httpCache__.cacheKey(url)
182
- os.remove(cacheDir + '/' + key + '.meta')
183
- os.remove(cacheDir + '/' + key + '.body')
184
- assert('no meta leftover for ' + key, __httpCache__.readMeta(url) === null)
185
- }
186
- }
187
- }
package/test/test_ffi.js DELETED
@@ -1,157 +0,0 @@
1
- import * as std from 'std';
2
- import * as ffi from 'ffi';
3
- import * as os from 'os';
4
- import { bind, bindLib } from '../lib/ffi/bind.js';
5
- import { NULL, PtrArrayBuffer } from '../lib/ffi/ctype.js';
6
- const MAX_WCHARS = 4096;
7
- function decodeWideAtPtr(ptr) {
8
- if (!ptr)
9
- return '';
10
- const chars = [];
11
- let pos = ptr;
12
- while (chars.length < MAX_WCHARS) {
13
- const low = ffi.readByte(pos);
14
- const high = ffi.readByte(pos + 1);
15
- const ch = low + high * 256;
16
- if (ch === 0)
17
- break;
18
- chars.push(ch);
19
- pos += 2;
20
- }
21
- return String.fromCharCode(...chars);
22
- }
23
- function readPtr(dv, offset) {
24
- if (os.arch === 'ia32') {
25
- return dv.getUint32(offset, true);
26
- }
27
- const low = dv.getUint32(offset, true);
28
- const high = dv.getUint32(offset + 4, true);
29
- return low + high * 4294967296;
30
- }
31
- const STATUS_FLAGS = [
32
- [0x00000001, 'PAUSED'],
33
- [0x00000002, 'ERROR'],
34
- [0x00000004, 'PENDING_DELETION'],
35
- [0x00000008, 'PAPER_JAM'],
36
- [0x00000010, 'PAPER_OUT'],
37
- [0x00000020, 'MANUAL_FEED'],
38
- [0x00000040, 'PAPER_PROBLEM'],
39
- [0x00000080, 'OFFLINE'],
40
- [0x00000100, 'IO_ACTIVE'],
41
- [0x00000200, 'BUSY'],
42
- [0x00000400, 'PRINTING'],
43
- [0x00000800, 'OUTPUT_BIN_FULL'],
44
- [0x00001000, 'NOT_AVAILABLE'],
45
- [0x00002000, 'WAITING'],
46
- [0x00004000, 'PROCESSING'],
47
- [0x00008000, 'INITIALIZING'],
48
- [0x00010000, 'WARMING_UP'],
49
- [0x00020000, 'TONER_LOW'],
50
- [0x00040000, 'NO_TONER'],
51
- [0x00080000, 'PAGE_PUNT'],
52
- [0x00100000, 'USER_INTERVENTION'],
53
- [0x00200000, 'OUT_OF_MEMORY'],
54
- [0x00400000, 'DOOR_OPEN'],
55
- [0x00800000, 'SERVER_UNKNOWN'],
56
- [0x01000000, 'POWER_SAVE'],
57
- [0x02000000, 'SERVER_OFFLINE'],
58
- [0x04000000, 'DRIVER_UPDATE'],
59
- ];
60
- function formatStatus(status) {
61
- if (status === 0)
62
- return 'OK';
63
- const parts = [];
64
- for (const [flag, name] of STATUS_FLAGS) {
65
- if (status & flag)
66
- parts.push(name);
67
- }
68
- return parts.join('|') || 'UNKNOWN';
69
- }
70
- export const suite = {
71
- name: 'ffi',
72
- run: (t) => {
73
- t.section('EnumPrinters');
74
- const hWinspool = ffi.LoadLibrary('winspool.drv');
75
- t.checkTrue('LoadLibrary("winspool.drv") succeeds', !!hWinspool);
76
- if (!hWinspool)
77
- return;
78
- const enumPrinters = ffi.GetProcAddress(hWinspool, 'EnumPrintersW');
79
- t.checkTrue('GetProcAddress("EnumPrintersW") succeeds', !!enumPrinters);
80
- if (!enumPrinters)
81
- return;
82
- const { EnumPrintersW: EnumPrinters } = bindLib('winspool.drv', {
83
- EnumPrintersW: 'u32 <>ptr u32 <BYTE>ptr u32 <BYTE>ptr <BYTE>ptr -> i32',
84
- });
85
- const flags = 0x06;
86
- const level = 2;
87
- const neededB = new PtrArrayBuffer(4);
88
- const neededBuf = new Uint32Array(neededB);
89
- const returnedB = new PtrArrayBuffer(4);
90
- const returnedBuf = new Uint32Array(returnedB);
91
- const ret1 = EnumPrinters(flags, NULL, level, NULL, 0, neededB, returnedB);
92
- std.printf(' first call: ret=%d needed=%d returned=%d\n', ret1, neededBuf[0], returnedBuf[0]);
93
- if (neededBuf[0] > 0) {
94
- t.checkTrue('pcbNeeded > 0', neededBuf[0] > 0);
95
- }
96
- else {
97
- // 无打印机环境(CI VM)EnumPrinters 的 pcbNeeded 为 0,属环境差异非缺陷,
98
- // 记 SKIP 而非 FAIL,CI 无需再对 ffi 用例做失败容忍。
99
- t.skipCase('pcbNeeded > 0 (no printers on this VM)');
100
- return;
101
- }
102
- const printerBuf = new PtrArrayBuffer(neededBuf[0]);
103
- const ret2 = EnumPrinters(flags, NULL, level, printerBuf, neededBuf[0], neededB, returnedB);
104
- t.checkTrue('EnumPrinters succeeds', ret2 !== 0);
105
- if (ret2 === 0)
106
- return;
107
- std.printf(' printers found: %d\n', returnedBuf[0]);
108
- if (returnedBuf[0] > 0) {
109
- const dv = new DataView(printerBuf);
110
- // PRINTER_INFO_2W layout (MinGW verified):
111
- // x64: sizeof=136 name=8 port=24 drv=32 comment=40 location=48 status=124
112
- // ia32: sizeof=84 name=4 port=12 drv=16 comment=20 location=24 status=72
113
- const ia32 = os.arch === 'ia32';
114
- const structSize = ia32 ? 84 : 136;
115
- const offName = ia32 ? 4 : 8;
116
- const offPort = ia32 ? 12 : 24;
117
- const offDrv = ia32 ? 16 : 32;
118
- const offComment = ia32 ? 20 : 40;
119
- const offLocation = ia32 ? 24 : 48;
120
- const offStatus = ia32 ? 72 : 124;
121
- for (let i = 0; i < returnedBuf[0] && i < 20; i++) {
122
- const off = i * structSize;
123
- const name = decodeWideAtPtr(readPtr(dv, off + offName));
124
- const port = decodeWideAtPtr(readPtr(dv, off + offPort));
125
- const driver = decodeWideAtPtr(readPtr(dv, off + offDrv));
126
- const location = decodeWideAtPtr(readPtr(dv, off + offLocation));
127
- const comment = decodeWideAtPtr(readPtr(dv, off + offComment));
128
- const status = dv.getUint32(off + offStatus, true);
129
- std.printf(' [%d] %s\n', i + 1, name);
130
- std.printf(' port: %s\n', port);
131
- std.printf(' driver: %s\n', driver);
132
- if (location)
133
- std.printf(' location: %s\n', location);
134
- if (comment)
135
- std.printf(' comment: %s\n', comment);
136
- std.printf(' status: 0x%08X (%s)\n', status, formatStatus(status));
137
- }
138
- }
139
- else {
140
- std.printf(' no printers installed (skip)\n');
141
- }
142
- t.section('PTR accepts raw number handles (XP 32-bit fix)');
143
- const hUser32 = ffi.LoadLibrary('user32.dll');
144
- t.checkTrue('LoadLibrary("user32.dll") succeeds', !!hUser32);
145
- if (hUser32) {
146
- const getDC = ffi.GetProcAddress(hUser32, 'GetDC');
147
- t.checkTrue('GetProcAddress("GetDC") succeeds', !!getDC);
148
- if (getDC) {
149
- const GetDC = bind('user32.dll', 'GetDC', '<>ptr -> <>ptr');
150
- const screenDc = GetDC(0);
151
- t.checkTrue('PTR slot takes number (NULL hwnd) and returns a DC handle', screenDc !== 0);
152
- const bogus = GetDC(0x12345678);
153
- t.checkTrue('PTR slot takes non-zero number without throwing', bogus === 0);
154
- }
155
- }
156
- }
157
- };