diff --git a/packages/win32-api/test/root.config.ts b/packages/win32-api/test/root.config.ts index b5a187e0..e99c96fc 100644 --- a/packages/win32-api/test/root.config.ts +++ b/packages/win32-api/test/root.config.ts @@ -8,8 +8,9 @@ import { isWinLocaleChinese } from './util.js' export const testDir = genCurrentDirname(import.meta.url) export const baseDir = join(testDir, '..') -export const CI = !! ((process.env['CI'] - ?? process.env['MIDWAY_SERVER_ENV'] === 'unittest') +export const CI = !! process.env['CI'] // GithubAction +export const TEST = !! (CI + || process.env['MIDWAY_SERVER_ENV'] === 'unittest' || process.env['MIDWAY_SERVER_ENV'] === 'local' || process.env['NODE_ENV'] === 'unittest' || process.env['NODE_ENV'] === 'local' @@ -20,6 +21,7 @@ export interface TestConfig { testDir: string testAppDir: string CI: boolean + TEST: boolean isWinChinese: boolean notepadTitle: string } @@ -31,6 +33,7 @@ export const testConfig = { testDir, testAppDir, CI, + TEST, isWinChinese, notepadTitle: isWinChinese ? '无标题 - 记事本' : 'Untitled - Notepad', } as TestConfig diff --git a/packages/win32-def/demo/EnumPrintersW.mts b/packages/win32-def/demo/EnumPrintersW.mts index 610c8a93..e7a099a9 100644 --- a/packages/win32-def/demo/EnumPrintersW.mts +++ b/packages/win32-def/demo/EnumPrintersW.mts @@ -17,20 +17,19 @@ const lib = ffi.load('winspool.drv') const func1 = lib.func( 'EnumPrintersW', D.BOOL, - [D.DWORD, 'str16', D.DWORD, `_Out_ ${S.PPRINTER_INFO_1}`, D.DWORD, D.LPDWORD, D.LPDWORD] + [D.DWORD, 'str16', D.DWORD, `_Out_ ${S.PPRINTER_INFO_1}`, D.DWORD, D.LPDWORD, D.LPDWORD], ) const func4 = lib.func( 'EnumPrintersW', D.BOOL, - [D.DWORD, 'str16', D.DWORD, `_Out_ ${S.PPRINTER_INFO_4}`, D.DWORD, D.LPDWORD, D.LPDWORD] + [D.DWORD, 'str16', D.DWORD, `_Out_ ${S.PPRINTER_INFO_4}`, D.DWORD, D.LPDWORD, D.LPDWORD], ) const flags = PrinterEnumFlags.PRINTER_ENUM_LOCAL const name = '' const cbBuf = 4096 -assert(cbBuf > 2, 'cbBuf must be > 2') const printerInfo1 = {} as S.PRINTER_INFO_1_Type const printerInfo4 = {} as S.PRINTER_INFO_4_Type @@ -58,7 +57,7 @@ const ret4 = func4( pcReturned, ) as number -console.log({ ret1, ret4, printerInfo1, printerInfo4 }) +console.info({ ret1, ret4, printerInfo1, printerInfo4 }) assert(ret1, 'EnumPrintersW(PRINTER_INFO_1) failed') assert(ret4, 'EnumPrintersW(PRINTER_INFO_4) failed') diff --git a/packages/win32-def/test/def.class/20.loader.test.ts b/packages/win32-def/test/def.class/20.loader.test.ts index 5290579b..fca9d80c 100644 --- a/packages/win32-def/test/def.class/20.loader.test.ts +++ b/packages/win32-def/test/def.class/20.loader.test.ts @@ -19,7 +19,7 @@ describe(fileShortPath(import.meta.url), () => { const lib = load(options) const { payload: pos } = POINT_Factory() - const res = lib.GetCursorPos(pos) + const res = await lib.GetCursorPos_Async(pos) assert(res > 0) console.info({ res, pos }) assert(pos.x >= 0 && pos.y >= 0) diff --git a/packages/win32-def/test/def.class/21.loader-multiple-choice.test.ts b/packages/win32-def/test/def.class/21.loader-multiple-choice.test.ts index d8fa9041..df725370 100644 --- a/packages/win32-def/test/def.class/21.loader-multiple-choice.test.ts +++ b/packages/win32-def/test/def.class/21.loader-multiple-choice.test.ts @@ -10,13 +10,12 @@ import type { PRINTER_INFO_5_Type, } from '##/index.struct.js' import { multipleChoiceMapperList, multipleChoiceMapperSet } from '#@/mapper/EnumPrintersW.mapper.js' +import { expectPrinterInfo } from '#@/test.config.js' import { DefWinspool, Winspool } from './api.helper.js' describe(fileShortPath(import.meta.url), () => { - const expectName = 'Microsoft Print to PDF' - const flags = PrinterEnumFlags.PRINTER_ENUM_LOCAL const name = '' const cbBuf = 4096 @@ -47,8 +46,8 @@ describe(fileShortPath(import.meta.url), () => { pcReturned, ) assert(ret, 'EnumPrintersW(PRINTER_INFO_1) failed') - assert(printerInfo.pName === expectName) - assert(printerInfo.pDescription.includes(expectName)) + assert(printerInfo.pName === expectPrinterInfo.name) + assert(printerInfo.pDescription.includes(expectPrinterInfo.name)) assert(printerInfo.pComment === '') assert(printerInfo.Flags === 8388608) }) @@ -79,10 +78,10 @@ describe(fileShortPath(import.meta.url), () => { pcReturned, ) assert(ret, 'EnumPrintersW(PRINTER_INFO_1) failed') - assert(printerInfo.pName === expectName) - assert(printerInfo.pDescription.includes(expectName)) + assert(printerInfo.pName === expectPrinterInfo.name) + assert(printerInfo.pDescription.includes(expectPrinterInfo.name)) assert(printerInfo.pComment === '') - assert(printerInfo.Flags === 8388608) + assert(printerInfo.Flags === expectPrinterInfo.flags) }) it('multi params Level=1', async () => { @@ -107,10 +106,10 @@ describe(fileShortPath(import.meta.url), () => { ) console.log({ ret, level, printerInfo }) assert(ret, 'EnumPrintersW(PRINTER_INFO_1) failed') - assert(printerInfo.pName === expectName) - assert(printerInfo.pDescription.includes(expectName)) + assert(printerInfo.pName === expectPrinterInfo.name) + assert(printerInfo.pDescription.includes(expectPrinterInfo.name)) assert(printerInfo.pComment === '') - assert(printerInfo.Flags === 8388608) + assert(printerInfo.Flags === expectPrinterInfo.flags) }) it('multi params Level=4', async () => { @@ -136,7 +135,7 @@ describe(fileShortPath(import.meta.url), () => { console.log({ ret, level, printerInfo }) assert(ret, 'EnumPrintersW(PRINTER_INFO_4) failed') - assert(printerInfo.pPrinterName === expectName) + assert(printerInfo.pPrinterName === expectPrinterInfo.name) assert(printerInfo.pServerName === null) assert(printerInfo.Attributes === 576) }) @@ -164,7 +163,7 @@ describe(fileShortPath(import.meta.url), () => { console.log({ ret, level, printerInfo }) assert(ret, 'EnumPrintersW(PRINTER_INFO_5) failed') - assert(printerInfo.pPrinterName === expectName) + assert(printerInfo.pPrinterName === expectPrinterInfo.name) assert(printerInfo.pPortName === 'PORTPROMPT:') assert(printerInfo.Attributes === 576) assert(printerInfo.DeviceNotSelectedTimeout === 45000) diff --git a/packages/win32-def/test/def.class/22.loader-updateMultipleChoiceMapper.map.test.ts b/packages/win32-def/test/def.class/22.loader-updateMultipleChoiceMapper.map.test.ts index e382dda8..26ab2fb2 100644 --- a/packages/win32-def/test/def.class/22.loader-updateMultipleChoiceMapper.map.test.ts +++ b/packages/win32-def/test/def.class/22.loader-updateMultipleChoiceMapper.map.test.ts @@ -6,13 +6,12 @@ import { PrinterEnumFlags } from '##/index.consts.js' import { load } from '##/index.js' import { PRINTER_INFO_1_Type, PRINTER_INFO_4_Type } from '##/index.struct.js' import { multipleChoiceMapperList } from '#@/mapper/EnumPrintersW.mapper.js' +import { expectPrinterInfo } from '#@/test.config.js' import { DefWinspool, Winspool } from './api.helper.js' describe(fileShortPath(import.meta.url), () => { - const expectName = 'Microsoft Print to PDF' - const flags = PrinterEnumFlags.PRINTER_ENUM_LOCAL const name = '' const cbBuf = 4096 @@ -32,7 +31,7 @@ describe(fileShortPath(import.meta.url), () => { }) lib.updateMultipleChoiceMapper({ mapperList: multipleChoiceMapperList }) - const ret1 = lib.EnumPrintersW( + const ret1 = await lib.EnumPrintersW_Async( flags, name, 1, @@ -43,12 +42,12 @@ describe(fileShortPath(import.meta.url), () => { ) console.log({ ret1, printerInfo1 }) assert(ret1, 'EnumPrintersW(PRINTER_INFO_1) failed') - assert(printerInfo1.pName === expectName) - assert(printerInfo1.pDescription.includes(expectName)) + assert(printerInfo1.pName === expectPrinterInfo.name) + assert(printerInfo1.pDescription.includes(expectPrinterInfo.name)) assert(printerInfo1.pComment === '') - assert(printerInfo1.Flags === 8388608) + assert(printerInfo1.Flags === expectPrinterInfo.flags) - const ret4 = lib.EnumPrintersW( + const ret4 = await lib.EnumPrintersW_Async( flags, name, 4, @@ -60,7 +59,7 @@ describe(fileShortPath(import.meta.url), () => { console.log({ ret4, printerInfo4 }) assert(ret4, 'EnumPrintersW(PRINTER_INFO_4) failed') - assert(printerInfo4.pPrinterName === expectName) + assert(printerInfo4.pPrinterName === expectPrinterInfo.name) assert(printerInfo4.pServerName === null) assert(printerInfo4.Attributes === 576) }) diff --git a/packages/win32-def/test/def.class/23.loader-updateMultipleChoiceMapper.set.test.ts b/packages/win32-def/test/def.class/23.loader-updateMultipleChoiceMapper.set.test.ts index 93915f9a..81410957 100644 --- a/packages/win32-def/test/def.class/23.loader-updateMultipleChoiceMapper.set.test.ts +++ b/packages/win32-def/test/def.class/23.loader-updateMultipleChoiceMapper.set.test.ts @@ -6,13 +6,12 @@ import { PrinterEnumFlags } from '##/index.consts.js' import { load } from '##/index.js' import { PRINTER_INFO_1_Type, PRINTER_INFO_4_Type } from '##/index.struct.js' import { fnName, multipleChoiceMapperSet } from '#@/mapper/EnumPrintersW.mapper.js' +import { expectPrinterInfo } from '#@/test.config.js' import { DefWinspool, Winspool } from './api.helper.js' describe(fileShortPath(import.meta.url), () => { - const expectName = 'Microsoft Print to PDF' - const flags = PrinterEnumFlags.PRINTER_ENUM_LOCAL const name = '' const cbBuf = 4096 @@ -35,7 +34,7 @@ describe(fileShortPath(import.meta.url), () => { mapperSet: multipleChoiceMapperSet, }) - const ret1 = lib.EnumPrintersW( + const ret1 = await lib.EnumPrintersW_Async( flags, name, 1, @@ -46,10 +45,10 @@ describe(fileShortPath(import.meta.url), () => { ) console.log({ ret1, printerInfo1 }) assert(ret1, 'EnumPrintersW(PRINTER_INFO_1) failed') - assert(printerInfo1.pName === expectName) - assert(printerInfo1.pDescription.includes(expectName)) + assert(printerInfo1.pName === expectPrinterInfo.name) + assert(printerInfo1.pDescription.includes(expectPrinterInfo.name)) assert(printerInfo1.pComment === '') - assert(printerInfo1.Flags === 8388608) + assert(printerInfo1.Flags === expectPrinterInfo.flags) const ret4 = lib.EnumPrintersW( flags, @@ -63,7 +62,7 @@ describe(fileShortPath(import.meta.url), () => { console.log({ ret4, printerInfo4 }) assert(ret4, 'EnumPrintersW(PRINTER_INFO_4) failed') - assert(printerInfo4.pPrinterName === expectName) + assert(printerInfo4.pPrinterName === expectPrinterInfo.name) assert(printerInfo4.pServerName === null) assert(printerInfo4.Attributes === 576) }) diff --git a/packages/win32-def/test/def.const/21c.loader-multiple-choice.test.ts b/packages/win32-def/test/def.const/21c.loader-multiple-choice.test.ts index ddbc930a..c6c85db9 100644 --- a/packages/win32-def/test/def.const/21c.loader-multiple-choice.test.ts +++ b/packages/win32-def/test/def.const/21c.loader-multiple-choice.test.ts @@ -10,13 +10,12 @@ import type { PRINTER_INFO_5_Type, } from '##/index.struct.js' import { multipleChoiceMapperList, multipleChoiceMapperSet } from '#@/mapper/EnumPrintersW.mapper.js' +import { expectPrinterInfo } from '#@/test.config.js' import { defWinspool, WinspoolFns } from './api.helper.js' describe(fileShortPath(import.meta.url), () => { - const expectName = 'Microsoft Print to PDF' - const flags = PrinterEnumFlags.PRINTER_ENUM_LOCAL const name = '' const cbBuf = 4096 @@ -47,10 +46,10 @@ describe(fileShortPath(import.meta.url), () => { pcReturned, ) assert(ret, 'EnumPrintersW(PRINTER_INFO_1) failed') - assert(printerInfo.pName === expectName) - assert(printerInfo.pDescription.includes(expectName)) + assert(printerInfo.pName === expectPrinterInfo.name) + assert(printerInfo.pDescription.includes(expectPrinterInfo.name)) assert(printerInfo.pComment === '') - assert(printerInfo.Flags === 8388608) + assert(printerInfo.Flags === expectPrinterInfo.flags) }) it('using fnName+Map (before)', async () => { @@ -65,7 +64,6 @@ describe(fileShortPath(import.meta.url), () => { mapperSet: multipleChoiceMapperSet, }) - const level = 1 const printerInfo = {} as PRINTER_INFO_1_Type @@ -79,10 +77,10 @@ describe(fileShortPath(import.meta.url), () => { pcReturned, ) assert(ret, 'EnumPrintersW(PRINTER_INFO_1) failed') - assert(printerInfo.pName === expectName) - assert(printerInfo.pDescription.includes(expectName)) + assert(printerInfo.pName === expectPrinterInfo.name) + assert(printerInfo.pDescription.includes(expectPrinterInfo.name)) assert(printerInfo.pComment === '') - assert(printerInfo.Flags === 8388608) + assert(printerInfo.Flags === expectPrinterInfo.flags) }) it('multi params Level=1', async () => { @@ -107,10 +105,10 @@ describe(fileShortPath(import.meta.url), () => { ) console.log({ ret, level, printerInfo }) assert(ret, 'EnumPrintersW(PRINTER_INFO_1) failed') - assert(printerInfo.pName === expectName) - assert(printerInfo.pDescription.includes(expectName)) + assert(printerInfo.pName === expectPrinterInfo.name) + assert(printerInfo.pDescription.includes(expectPrinterInfo.name)) assert(printerInfo.pComment === '') - assert(printerInfo.Flags === 8388608) + assert(printerInfo.Flags === expectPrinterInfo.flags) }) it('multi params Level=4', async () => { @@ -136,7 +134,7 @@ describe(fileShortPath(import.meta.url), () => { console.log({ ret, level, printerInfo }) assert(ret, 'EnumPrintersW(PRINTER_INFO_4) failed') - assert(printerInfo.pPrinterName === expectName) + assert(printerInfo.pPrinterName === expectPrinterInfo.name) assert(printerInfo.pServerName === null) assert(printerInfo.Attributes === 576) }) @@ -164,7 +162,7 @@ describe(fileShortPath(import.meta.url), () => { console.log({ ret, level, printerInfo }) assert(ret, 'EnumPrintersW(PRINTER_INFO_5) failed') - assert(printerInfo.pPrinterName === expectName) + assert(printerInfo.pPrinterName === expectPrinterInfo.name) assert(printerInfo.pPortName === 'PORTPROMPT:') assert(printerInfo.Attributes === 576) assert(printerInfo.DeviceNotSelectedTimeout === 45000) diff --git a/packages/win32-def/test/def.const/22c.loader-updateMultipleChoiceMapper.map.test.ts b/packages/win32-def/test/def.const/22c.loader-updateMultipleChoiceMapper.map.test.ts index 34a6fcd3..641a6b1c 100644 --- a/packages/win32-def/test/def.const/22c.loader-updateMultipleChoiceMapper.map.test.ts +++ b/packages/win32-def/test/def.const/22c.loader-updateMultipleChoiceMapper.map.test.ts @@ -6,13 +6,12 @@ import { PrinterEnumFlags } from '##/index.consts.js' import { load } from '##/index.js' import { PRINTER_INFO_1_Type, PRINTER_INFO_4_Type } from '##/index.struct.js' import { multipleChoiceMapperList } from '#@/mapper/EnumPrintersW.mapper.js' +import { expectPrinterInfo } from '#@/test.config.js' import { defWinspool, WinspoolFns } from './api.helper.js' describe(fileShortPath(import.meta.url), () => { - const expectName = 'Microsoft Print to PDF' - const flags = PrinterEnumFlags.PRINTER_ENUM_LOCAL const name = '' const cbBuf = 4096 @@ -32,7 +31,7 @@ describe(fileShortPath(import.meta.url), () => { }) lib.updateMultipleChoiceMapper({ mapperList: multipleChoiceMapperList }) - const ret1 = lib.EnumPrintersW( + const ret1 = await lib.EnumPrintersW_Async( flags, name, 1, @@ -43,10 +42,10 @@ describe(fileShortPath(import.meta.url), () => { ) console.log({ ret1, printerInfo1 }) assert(ret1, 'EnumPrintersW(PRINTER_INFO_1) failed') - assert(printerInfo1.pName === expectName) - assert(printerInfo1.pDescription.includes(expectName)) + assert(printerInfo1.pName === expectPrinterInfo.name) + assert(printerInfo1.pDescription.includes(expectPrinterInfo.name)) assert(printerInfo1.pComment === '') - assert(printerInfo1.Flags === 8388608) + assert(printerInfo1.Flags === expectPrinterInfo.flags) const ret4 = lib.EnumPrintersW( flags, @@ -60,7 +59,7 @@ describe(fileShortPath(import.meta.url), () => { console.log({ ret4, printerInfo4 }) assert(ret4, 'EnumPrintersW(PRINTER_INFO_4) failed') - assert(printerInfo4.pPrinterName === expectName) + assert(printerInfo4.pPrinterName === expectPrinterInfo.name) assert(printerInfo4.pServerName === null) assert(printerInfo4.Attributes === 576) }) diff --git a/packages/win32-def/test/def.const/23c.loader-updateMultipleChoiceMapper.set.test.ts b/packages/win32-def/test/def.const/23c.loader-updateMultipleChoiceMapper.set.test.ts index 632f43a0..f5867f25 100644 --- a/packages/win32-def/test/def.const/23c.loader-updateMultipleChoiceMapper.set.test.ts +++ b/packages/win32-def/test/def.const/23c.loader-updateMultipleChoiceMapper.set.test.ts @@ -6,13 +6,12 @@ import { PrinterEnumFlags } from '##/index.consts.js' import { load } from '##/index.js' import { PRINTER_INFO_1_Type, PRINTER_INFO_4_Type } from '##/index.struct.js' import { fnName, multipleChoiceMapperSet } from '#@/mapper/EnumPrintersW.mapper.js' +import { expectPrinterInfo } from '#@/test.config.js' import { defWinspool, WinspoolFns } from './api.helper.js' describe(fileShortPath(import.meta.url), () => { - const expectName = 'Microsoft Print to PDF' - const flags = PrinterEnumFlags.PRINTER_ENUM_LOCAL const name = '' const cbBuf = 4096 @@ -46,10 +45,10 @@ describe(fileShortPath(import.meta.url), () => { ) console.log({ ret1, printerInfo1 }) assert(ret1, 'EnumPrintersW(PRINTER_INFO_1) failed') - assert(printerInfo1.pName === expectName) - assert(printerInfo1.pDescription.includes(expectName)) + assert(printerInfo1.pName === expectPrinterInfo.name) + assert(printerInfo1.pDescription.includes(expectPrinterInfo.name)) assert(printerInfo1.pComment === '') - assert(printerInfo1.Flags === 8388608) + assert(printerInfo1.Flags === expectPrinterInfo.flags) const ret4 = lib.EnumPrintersW( flags, @@ -63,7 +62,7 @@ describe(fileShortPath(import.meta.url), () => { console.log({ ret4, printerInfo4 }) assert(ret4, 'EnumPrintersW(PRINTER_INFO_4) failed') - assert(printerInfo4.pPrinterName === expectName) + assert(printerInfo4.pPrinterName === expectPrinterInfo.name) assert(printerInfo4.pServerName === null) assert(printerInfo4.Attributes === 576) }) diff --git a/packages/win32-def/test/root.config.ts b/packages/win32-def/test/root.config.ts index 047c8c46..b55cd037 100644 --- a/packages/win32-def/test/root.config.ts +++ b/packages/win32-def/test/root.config.ts @@ -6,8 +6,9 @@ import { genCurrentDirname } from '@waiting/shared-core' export const testDir = genCurrentDirname(import.meta.url) export const baseDir = join(testDir, '..') -export const CI = !! ((process.env['CI'] - ?? process.env['MIDWAY_SERVER_ENV'] === 'unittest') +export const CI = !! process.env['CI'] // GithubAction +export const TEST = !! (CI + || process.env['MIDWAY_SERVER_ENV'] === 'unittest' || process.env['MIDWAY_SERVER_ENV'] === 'local' || process.env['NODE_ENV'] === 'unittest' || process.env['NODE_ENV'] === 'local' @@ -18,6 +19,8 @@ export interface TestConfig { testDir: string testAppDir: string CI: boolean + TEST: boolean + isWinChinese: boolean } const testAppDir = join(testDir, 'fixtures', 'base-app') @@ -26,5 +29,6 @@ export const testConfig = { testDir, testAppDir, CI, + TEST, } as TestConfig diff --git a/packages/win32-def/test/test.config.ts b/packages/win32-def/test/test.config.ts new file mode 100644 index 00000000..73add6d9 --- /dev/null +++ b/packages/win32-def/test/test.config.ts @@ -0,0 +1,11 @@ +import assert from 'node:assert' + +import { testConfig } from '#@/root.config.js' + + +export const expectPrinterInfo = { + name: testConfig.CI ? 'Microsoft XPS Document Writer' : 'Microsoft Print to PDF', + description: testConfig.CI ? 'Microsoft XPS Document Writer,Microsoft XPS Document Writer v4,' : 'Microsoft Print to PDF', + flags: testConfig.CI ? 8388608 : 8388608, +} +