quickwin 3.0.0 → 3.0.2

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 (253) hide show
  1. package/README.en.md +3 -0
  2. package/README.md +2 -0
  3. package/lib/abort.d.ts +21 -0
  4. package/lib/assert.d.ts +2 -0
  5. package/lib/bitmap.d.ts +7 -0
  6. package/lib/cache-utils.d.ts +6 -0
  7. package/lib/certs.d.ts +1 -0
  8. package/lib/dpi.d.ts +9 -0
  9. package/lib/dumpRects.d.ts +2 -0
  10. package/lib/exec-log.d.ts +23 -0
  11. package/lib/fetch.d.ts +4 -0
  12. package/lib/ffi/bind.d.ts +70 -0
  13. package/lib/ffi/ctype.d.ts +117 -0
  14. package/lib/ffi/index.d.ts +2 -0
  15. package/lib/ffi/struct.d.ts +174 -0
  16. package/lib/http-common.d.ts +143 -0
  17. package/lib/http-server.d.ts +59 -0
  18. package/lib/polyfill.d.ts +22 -0
  19. package/lib/react-qw/components/Button.d.ts +9 -0
  20. package/lib/react-qw/components/CheckBox.d.ts +11 -0
  21. package/lib/react-qw/components/ComboBox.d.ts +11 -0
  22. package/lib/react-qw/components/DateTimePicker.d.ts +15 -0
  23. package/lib/react-qw/components/Input.d.ts +15 -0
  24. package/lib/react-qw/components/Link.d.ts +12 -0
  25. package/lib/react-qw/components/ListBox.d.ts +13 -0
  26. package/lib/react-qw/components/ListView.d.ts +37 -0
  27. package/lib/react-qw/components/PathPicker.d.ts +23 -0
  28. package/lib/react-qw/components/ProgressBar.d.ts +9 -0
  29. package/lib/react-qw/components/RadioButton.d.ts +11 -0
  30. package/lib/react-qw/components/ScrollView.d.ts +9 -0
  31. package/lib/react-qw/components/Slider.d.ts +12 -0
  32. package/lib/react-qw/components/Tab.d.ts +14 -0
  33. package/lib/react-qw/components/Tooltip.d.ts +7 -0
  34. package/lib/react-qw/components/TreeView.d.ts +18 -0
  35. package/lib/react-qw/components/index.d.ts +16 -0
  36. package/lib/react-qw/index.d.ts +24 -0
  37. package/lib/react-qw/layout.d.ts +29 -0
  38. package/lib/react-qw/nmhdr.d.ts +1 -0
  39. package/lib/react-qw/props.d.ts +2 -0
  40. package/lib/react-qw/reconciler.d.ts +21 -0
  41. package/lib/stream.d.ts +20 -0
  42. package/lib/text-codec.d.ts +39 -0
  43. package/lib/text-measure.d.ts +14 -0
  44. package/lib/url.d.ts +54 -0
  45. package/lib/websocket.d.ts +73 -0
  46. package/lib/windows/{advapi32.ts → advapi32.d.ts} +6 -21
  47. package/lib/windows/comctl32.d.ts +14 -0
  48. package/lib/windows/comdlg32.d.ts +4 -0
  49. package/lib/windows/{gdi32.ts → gdi32.d.ts} +161 -98
  50. package/lib/windows/{kernel32.ts → kernel32.d.ts} +138 -115
  51. package/lib/windows/{msimg32.ts → msimg32.d.ts} +11 -14
  52. package/lib/windows/ntdll.d.ts +5 -0
  53. package/lib/windows/ole32.d.ts +3 -0
  54. package/lib/windows/{psapi.ts → psapi.d.ts} +9 -18
  55. package/lib/windows/{shell32.ts → shell32.d.ts} +25 -24
  56. package/lib/windows/structs.d.ts +3141 -0
  57. package/lib/windows/{user32.ts → user32.d.ts} +196 -193
  58. package/lib/windows/version.d.ts +27 -0
  59. package/lib/windows/{winspool.ts → winspool.d.ts} +18 -32
  60. package/package.json +15 -8
  61. package/qwin-nowasm-x86.exe +0 -0
  62. package/qwin-nowasm.exe +0 -0
  63. package/qwin-x86.exe +0 -0
  64. package/qwin.exe +0 -0
  65. package/examples/PdfCanvas.js +0 -38
  66. package/examples/PdfCanvas.tsx +0 -54
  67. package/examples/execd/main.js +0 -23379
  68. package/examples/execd/tray.js +0 -192
  69. package/examples/execd/worker.js +0 -122
  70. package/examples/pdf_preview2.js +0 -398
  71. package/examples/pdf_preview2.ts +0 -353
  72. package/examples/pdf_viewer.js +0 -22515
  73. package/examples/pdf_viewer.tsx +0 -228
  74. package/examples/test_gallery.js +0 -18692
  75. package/examples/test_gallery.tsx +0 -291
  76. package/examples/test_react_lazy.js +0 -18560
  77. package/examples/test_react_lazy.tsx +0 -65
  78. package/examples/test_react_listbox.js +0 -18562
  79. package/examples/test_react_listbox.tsx +0 -73
  80. package/examples/test_root_window.js +0 -18532
  81. package/examples/test_root_window.tsx +0 -41
  82. package/examples/test_tab.js +0 -18563
  83. package/examples/test_tab.tsx +0 -77
  84. package/examples/tray_demo.js +0 -86
  85. package/examples/tray_demo.tsx +0 -89
  86. package/lib/abort.ts +0 -69
  87. package/lib/assert.ts +0 -7
  88. package/lib/bitmap.ts +0 -39
  89. package/lib/cache-utils.ts +0 -40
  90. package/lib/certs.ts +0 -258
  91. package/lib/dpi.ts +0 -31
  92. package/lib/dumpRects.ts +0 -34
  93. package/lib/exec-log.ts +0 -30
  94. package/lib/fetch.ts +0 -589
  95. package/lib/ffi/bind.ts +0 -540
  96. package/lib/ffi/ctype.ts +0 -371
  97. package/lib/ffi/index.ts +0 -6
  98. package/lib/ffi/struct.ts +0 -780
  99. package/lib/http-common.ts +0 -441
  100. package/lib/http-server.ts +0 -604
  101. package/lib/polyfill.ts +0 -171
  102. package/lib/react-qw/components/index.ts +0 -17
  103. package/lib/react-qw/index.ts +0 -96
  104. package/lib/react-qw/layout.ts +0 -111
  105. package/lib/react-qw/nmhdr.ts +0 -7
  106. package/lib/react-qw/props.ts +0 -41
  107. package/lib/react-qw/reconciler.ts +0 -379
  108. package/lib/stream.ts +0 -22
  109. package/lib/text-codec.ts +0 -171
  110. package/lib/text-measure.ts +0 -44
  111. package/lib/url.ts +0 -201
  112. package/lib/websocket.ts +0 -600
  113. package/lib/windows/comctl32.ts +0 -20
  114. package/lib/windows/comdlg32.ts +0 -10
  115. package/lib/windows/ntdll.ts +0 -11
  116. package/lib/windows/ole32.ts +0 -9
  117. package/lib/windows/structs.ts +0 -807
  118. package/lib/windows/version.ts +0 -35
  119. package/test/add.wasm +0 -0
  120. package/test/bench_ffi_callraw.js +0 -235
  121. package/test/bench_ffi_callraw.ts +0 -235
  122. package/test/bench_ffi_overhead.js +0 -139
  123. package/test/bench_ffi_overhead.ts +0 -141
  124. package/test/bench_sendmessage.js +0 -104
  125. package/test/bench_sendmessage.ts +0 -100
  126. package/test/bench_sendmessage_nonnull.js +0 -187
  127. package/test/bench_sendmessage_nonnull.ts +0 -188
  128. package/test/complex.wasm +0 -0
  129. package/test/complex_imports.wasm +0 -0
  130. package/test/debug/http_server_e2e.js +0 -31
  131. package/test/debug/minwasm.js +0 -52
  132. package/test/debug/mupdf_debug.js +0 -86
  133. package/test/debug/wasm.js +0 -122
  134. package/test/debug/wasm_export_debug.js +0 -54
  135. package/test/debug/wasm_names.js +0 -36
  136. package/test/example.pdf +0 -0
  137. package/test/global_imports.wasm +0 -0
  138. package/test/import_func.wasm +0 -0
  139. package/test/imports.wasm +0 -0
  140. package/test/mupdf-cdn.js +0 -40
  141. package/test/mupdf-cdn.ts +0 -43
  142. package/test/run.js +0 -111
  143. package/test/run.ts +0 -116
  144. package/test/sjlj.wasm +0 -0
  145. package/test/test_basic.js +0 -7
  146. package/test/test_basic.ts +0 -9
  147. package/test/test_basic_fetch.js +0 -63
  148. package/test/test_basic_fetch.ts +0 -59
  149. package/test/test_brotli.js +0 -48
  150. package/test/test_brotli.ts +0 -52
  151. package/test/test_fetch_cache.js +0 -169
  152. package/test/test_fetch_cache.ts +0 -187
  153. package/test/test_ffi.js +0 -157
  154. package/test/test_ffi.ts +0 -170
  155. package/test/test_ffi_abi.js +0 -290
  156. package/test/test_ffi_abi.ts +0 -274
  157. package/test/test_ffi_array.js +0 -116
  158. package/test/test_ffi_array.ts +0 -141
  159. package/test/test_ffi_bind.js +0 -656
  160. package/test/test_ffi_bind.ts +0 -670
  161. package/test/test_ffi_struct.js +0 -779
  162. package/test/test_ffi_struct.ts +0 -828
  163. package/test/test_ffi_struct_layout.js +0 -495
  164. package/test/test_ffi_struct_layout.ts +0 -543
  165. package/test/test_ffi_user32.js +0 -103
  166. package/test/test_ffi_user32.ts +0 -113
  167. package/test/test_ffi_windows.js +0 -172
  168. package/test/test_ffi_windows.ts +0 -187
  169. package/test/test_files.js +0 -102
  170. package/test/test_files.ts +0 -121
  171. package/test/test_frame_encoding.js +0 -128
  172. package/test/test_frame_encoding.ts +0 -132
  173. package/test/test_gdi_draw.js +0 -681
  174. package/test/test_gdi_draw.ts +0 -725
  175. package/test/test_helper.js +0 -91
  176. package/test/test_helper.ts +0 -88
  177. package/test/test_http_import.js +0 -96
  178. package/test/test_http_import.ts +0 -93
  179. package/test/test_http_server.js +0 -214
  180. package/test/test_http_server.ts +0 -211
  181. package/test/test_import_dir.js +0 -4
  182. package/test/test_import_dir.ts +0 -5
  183. package/test/test_ipv6.js +0 -134
  184. package/test/test_ipv6.ts +0 -130
  185. package/test/test_jsx.js +0 -1314
  186. package/test/test_meta_url.js +0 -3
  187. package/test/test_meta_url.ts +0 -4
  188. package/test/test_mupdf_render.js +0 -51
  189. package/test/test_mupdf_render.ts +0 -55
  190. package/test/test_mupdf_twice.js +0 -62
  191. package/test/test_mupdf_twice.ts +0 -65
  192. package/test/test_mupdf_wasm.js +0 -39
  193. package/test/test_mupdf_wasm.ts +0 -32
  194. package/test/test_net_event.js +0 -57
  195. package/test/test_net_event.ts +0 -56
  196. package/test/test_net_fetch.js +0 -384
  197. package/test/test_net_fetch.ts +0 -373
  198. package/test/test_net_websocket.js +0 -180
  199. package/test/test_net_websocket.ts +0 -164
  200. package/test/test_polyfill.js +0 -144
  201. package/test/test_polyfill.ts +0 -159
  202. package/test/test_printer.js +0 -137
  203. package/test/test_printer.ts +0 -148
  204. package/test/test_proc.js +0 -141
  205. package/test/test_proc.ts +0 -163
  206. package/test/test_react_complex.js +0 -18678
  207. package/test/test_react_counter.js +0 -18555
  208. package/test/test_react_flex.js +0 -18871
  209. package/test/test_react_hidden.js +0 -18560
  210. package/test/test_react_listview_link.js +0 -18590
  211. package/test/test_react_notify.js +0 -18797
  212. package/test/test_react_render.js +0 -18550
  213. package/test/test_registry.js +0 -74
  214. package/test/test_registry.ts +0 -95
  215. package/test/test_sysinfo.js +0 -122
  216. package/test/test_sysinfo.ts +0 -141
  217. package/test/test_url.js +0 -173
  218. package/test/test_url.ts +0 -183
  219. package/test/test_wasm_basic.js +0 -85
  220. package/test/test_wasm_basic.ts +0 -73
  221. package/test/test_wasm_import_global.js +0 -41
  222. package/test/test_wasm_import_global.ts +0 -45
  223. package/test/test_wasm_sjlj.js +0 -145
  224. package/test/test_wasm_sjlj.ts +0 -125
  225. package/test/test_wasm_types.js +0 -97
  226. package/test/test_wasm_types.ts +0 -124
  227. package/test/test_wolfssl_read.js +0 -203
  228. package/test/test_wolfssl_read.ts +0 -184
  229. package/test/test_worker.js +0 -21
  230. package/test/test_worker.ts +0 -24
  231. package/test/test_worker_concurrent.js +0 -45
  232. package/test/test_worker_concurrent.ts +0 -56
  233. package/test/test_worker_data_url.js +0 -46
  234. package/test/test_worker_data_url.ts +0 -51
  235. package/test/test_worker_fetch.js +0 -26
  236. package/test/test_worker_fetch.ts +0 -27
  237. package/test/test_worker_net.js +0 -69
  238. package/test/test_worker_net.ts +0 -66
  239. package/test/test_worker_wasm_concurrent.js +0 -44
  240. package/test/test_worker_wasm_concurrent.ts +0 -45
  241. package/test/types.wasm +0 -0
  242. package/test/worker_fetch.js +0 -13
  243. package/test/worker_fetch.ts +0 -13
  244. package/test/worker_helper.js +0 -1
  245. package/test/worker_helper.ts +0 -1
  246. package/test/worker_http.js +0 -18
  247. package/test/worker_http.ts +0 -20
  248. package/test/worker_import_lib.js +0 -12
  249. package/test/worker_import_lib.ts +0 -13
  250. package/test/worker_module.js +0 -16
  251. package/test/worker_module.ts +0 -17
  252. package/test/worker_wasm_concurrent.js +0 -22
  253. package/test/worker_wasm_concurrent.ts +0 -22
@@ -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
- };
package/test/test_ffi.ts DELETED
@@ -1,170 +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
- import { Tester } from './test_helper.js'
7
-
8
- const MAX_WCHARS = 4096
9
-
10
- function decodeWideAtPtr(ptr: number): string {
11
- if (!ptr) return ''
12
- const chars: number[] = []
13
- let pos = ptr
14
- while (chars.length < MAX_WCHARS) {
15
- const low = ffi.readByte(pos)
16
- const high = ffi.readByte(pos + 1)
17
- const ch = low + high * 256
18
- if (ch === 0) break
19
- chars.push(ch)
20
- pos += 2
21
- }
22
- return String.fromCharCode(...chars)
23
- }
24
-
25
- function readPtr(dv: DataView, offset: number): number {
26
- if (os.arch === 'ia32') {
27
- return dv.getUint32(offset, true)
28
- }
29
- const low = dv.getUint32(offset, true)
30
- const high = dv.getUint32(offset + 4, true)
31
- return low + high * 4294967296
32
- }
33
-
34
- const STATUS_FLAGS: [number, string][] = [
35
- [0x00000001, 'PAUSED'],
36
- [0x00000002, 'ERROR'],
37
- [0x00000004, 'PENDING_DELETION'],
38
- [0x00000008, 'PAPER_JAM'],
39
- [0x00000010, 'PAPER_OUT'],
40
- [0x00000020, 'MANUAL_FEED'],
41
- [0x00000040, 'PAPER_PROBLEM'],
42
- [0x00000080, 'OFFLINE'],
43
- [0x00000100, 'IO_ACTIVE'],
44
- [0x00000200, 'BUSY'],
45
- [0x00000400, 'PRINTING'],
46
- [0x00000800, 'OUTPUT_BIN_FULL'],
47
- [0x00001000, 'NOT_AVAILABLE'],
48
- [0x00002000, 'WAITING'],
49
- [0x00004000, 'PROCESSING'],
50
- [0x00008000, 'INITIALIZING'],
51
- [0x00010000, 'WARMING_UP'],
52
- [0x00020000, 'TONER_LOW'],
53
- [0x00040000, 'NO_TONER'],
54
- [0x00080000, 'PAGE_PUNT'],
55
- [0x00100000, 'USER_INTERVENTION'],
56
- [0x00200000, 'OUT_OF_MEMORY'],
57
- [0x00400000, 'DOOR_OPEN'],
58
- [0x00800000, 'SERVER_UNKNOWN'],
59
- [0x01000000, 'POWER_SAVE'],
60
- [0x02000000, 'SERVER_OFFLINE'],
61
- [0x04000000, 'DRIVER_UPDATE'],
62
- ];
63
-
64
- function formatStatus(status: number): string {
65
- if (status === 0) return 'OK'
66
- const parts: string[] = []
67
- for (const [flag, name] of STATUS_FLAGS) {
68
- if (status & flag) parts.push(name)
69
- }
70
- return parts.join('|') || 'UNKNOWN'
71
- }
72
-
73
- export const suite = {
74
- name: 'ffi',
75
- run: (t: Tester) => {
76
- t.section('EnumPrinters')
77
- const hWinspool = ffi.LoadLibrary('winspool.drv')
78
- t.checkTrue('LoadLibrary("winspool.drv") succeeds', !!hWinspool)
79
- if (!hWinspool) return
80
-
81
- const enumPrinters = ffi.GetProcAddress(hWinspool, 'EnumPrintersW')
82
- t.checkTrue('GetProcAddress("EnumPrintersW") succeeds', !!enumPrinters)
83
- if (!enumPrinters) return
84
-
85
- const { EnumPrintersW: EnumPrinters } = bindLib('winspool.drv', {
86
- EnumPrintersW: 'u32 <>ptr u32 <BYTE>ptr u32 <BYTE>ptr <BYTE>ptr -> i32',
87
- })
88
-
89
- const flags = 0x06
90
- const level = 2
91
- const neededB = new PtrArrayBuffer(4)
92
- const neededBuf = new Uint32Array(neededB)
93
- const returnedB = new PtrArrayBuffer(4)
94
- const returnedBuf = new Uint32Array(returnedB)
95
-
96
- const ret1 = EnumPrinters(flags, NULL, level, NULL, 0, neededB, returnedB)
97
- std.printf(' first call: ret=%d needed=%d returned=%d\n', ret1, neededBuf[0], returnedBuf[0])
98
- if (neededBuf[0]! > 0) {
99
- t.checkTrue('pcbNeeded > 0', neededBuf[0]! > 0)
100
- } else {
101
- // 无打印机环境(CI VM)EnumPrinters 的 pcbNeeded 为 0,属环境差异非缺陷,
102
- // 记 SKIP 而非 FAIL,CI 无需再对 ffi 用例做失败容忍。
103
- t.skipCase('pcbNeeded > 0 (no printers on this VM)')
104
- return
105
- }
106
-
107
- const printerBuf = new PtrArrayBuffer(neededBuf[0]!)
108
- const ret2 = EnumPrinters(
109
- flags,
110
- NULL,
111
- level,
112
- printerBuf,
113
- neededBuf[0]!,
114
- neededB,
115
- returnedB
116
- )
117
- t.checkTrue('EnumPrinters succeeds', ret2 !== 0)
118
- if (ret2 === 0) return
119
-
120
- std.printf(' printers found: %d\n', returnedBuf[0])
121
-
122
- if (returnedBuf[0]! > 0) {
123
- const dv = new DataView(printerBuf)
124
- // PRINTER_INFO_2W layout (MinGW verified):
125
- // x64: sizeof=136 name=8 port=24 drv=32 comment=40 location=48 status=124
126
- // ia32: sizeof=84 name=4 port=12 drv=16 comment=20 location=24 status=72
127
- const ia32 = os.arch === 'ia32'
128
- const structSize = ia32 ? 84 : 136
129
- const offName = ia32 ? 4 : 8
130
- const offPort = ia32 ? 12 : 24
131
- const offDrv = ia32 ? 16 : 32
132
- const offComment = ia32 ? 20 : 40
133
- const offLocation = ia32 ? 24 : 48
134
- const offStatus = ia32 ? 72 : 124
135
-
136
- for (let i = 0; i < returnedBuf[0]! && i < 20; i++) {
137
- const off = i * structSize
138
- const name = decodeWideAtPtr(readPtr(dv, off + offName))
139
- const port = decodeWideAtPtr(readPtr(dv, off + offPort))
140
- const driver = decodeWideAtPtr(readPtr(dv, off + offDrv))
141
- const location = decodeWideAtPtr(readPtr(dv, off + offLocation))
142
- const comment = decodeWideAtPtr(readPtr(dv, off + offComment))
143
- const status = dv.getUint32(off + offStatus, true)
144
- std.printf(' [%d] %s\n', i + 1, name)
145
- std.printf(' port: %s\n', port)
146
- std.printf(' driver: %s\n', driver)
147
- if (location) std.printf(' location: %s\n', location)
148
- if (comment) std.printf(' comment: %s\n', comment)
149
- std.printf(' status: 0x%08X (%s)\n', status, formatStatus(status))
150
- }
151
- } else {
152
- std.printf(' no printers installed (skip)\n')
153
- }
154
-
155
- t.section('PTR accepts raw number handles (XP 32-bit fix)')
156
- const hUser32 = ffi.LoadLibrary('user32.dll')
157
- t.checkTrue('LoadLibrary("user32.dll") succeeds', !!hUser32)
158
- if (hUser32) {
159
- const getDC = ffi.GetProcAddress(hUser32, 'GetDC')
160
- t.checkTrue('GetProcAddress("GetDC") succeeds', !!getDC)
161
- if (getDC) {
162
- const GetDC = bind('user32.dll', 'GetDC', '<>ptr -> <>ptr')
163
- const screenDc = GetDC(0)
164
- t.checkTrue('PTR slot takes number (NULL hwnd) and returns a DC handle', screenDc !== 0)
165
- const bogus = GetDC(0x12345678)
166
- t.checkTrue('PTR slot takes non-zero number without throwing', bogus === 0)
167
- }
168
- }
169
- }
170
- }