"The King of Fighters '98 Ultimate Match Final Edition" depends on this behavior. At least, the build I have is; it seems other builds are not.
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
-- v2: xactengine3_7/tests: Test notifications when loading a wave bank.
From: Giovanni Mascellani gmascellani@codeweavers.com
"The King of Fighters '98 Ultimate Match Final Edition" depends on this behavior. At least, the build I have is; it seems other builds are not.
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- dlls/xactengine3_7/tests/Makefile.in | 2 + dlls/xactengine3_7/tests/gen_xwb.py | 89 ++++++++++++++++++++++ dlls/xactengine3_7/tests/resource.rc | 24 ++++++ dlls/xactengine3_7/tests/test.xwb | Bin 0 -> 172 bytes dlls/xactengine3_7/tests/xact3.c | 109 +++++++++++++++++++++++++++ 5 files changed, 224 insertions(+) create mode 100755 dlls/xactengine3_7/tests/gen_xwb.py create mode 100644 dlls/xactengine3_7/tests/resource.rc create mode 100644 dlls/xactengine3_7/tests/test.xwb
diff --git a/dlls/xactengine3_7/tests/Makefile.in b/dlls/xactengine3_7/tests/Makefile.in index c32b2562546..70128e00a78 100644 --- a/dlls/xactengine3_7/tests/Makefile.in +++ b/dlls/xactengine3_7/tests/Makefile.in @@ -3,3 +3,5 @@ IMPORTS = ole32
C_SRCS = \ xact3.c + +RC_SRCS = resource.rc diff --git a/dlls/xactengine3_7/tests/gen_xwb.py b/dlls/xactengine3_7/tests/gen_xwb.py new file mode 100755 index 00000000000..19ea1af1a66 --- /dev/null +++ b/dlls/xactengine3_7/tests/gen_xwb.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 + +# Copyright 2022 Giovanni Mascellani for CodeWeavers + +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. + +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. + +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + +# Creates a valid (i.e., accepted by native xactengine3_7.dll) XACT +# wave bank file; the file is pretty trivial: it has a single wave of +# zero length. + +# All magic numbers are taken from a working file + +import struct +import sys + +def gen_bankdata(): + bank_name = 'test'.encode('ascii') + buf = b'' + buf += struct.pack('<II', 1, 1) # flags, entry count + buf += bank_name + b'\x00' * (64 - len(bank_name)) # bank name + buf += struct.pack('<IIIIQ', 24, 64, 0x800, 0, 0) # entry metadata element size, entry name element size, alignment, compact format, build time + return buf + +def gen_entrymetadata(): + flags_duration = 0 + wave_format = 0 # bits per sample + wave_format <<= 8 + wave_format |= 48 # block align + wave_format <<= 18 + wave_format |= 22051 # samples per second + wave_format <<= 3 + wave_format |= 2 # channel count + wave_format <<= 2 + wave_format |= 2 # format tag + return struct.pack('<IIIIII', flags_duration, wave_format, 0, 0, 0, 0) # flags and duration, format, play region offset, play region length, loop region start sample, loop region total samples + +def gen_xwb(fout): + sections = [ + gen_bankdata(), # BANKDATA + gen_entrymetadata(), # ENTRYMETADATA + b'', # SEEKTABLES + b'', # ENTRYNAMES + b'', # ENTRYWAVEDATA + ] + + write_xwb(fout, sections) + +def write_xwb(fout, sections): + pos = 4 * (3 + 2 * 5) + fout.write(struct.pack('<III', 0x444E4257, 0x2e, 0x2c)) # signature, version, header version + for i in range(5): + fout.write(struct.pack('<II', pos, len(sections[i]))) # offset, length + pos += len(sections[i]) + for i in range(5): + fout.write(sections[i]) + +# def read_xwb(fin): +# fin.read(12) +# section_data = [] +# for i in range(5): +# section_data.append(struct.unpack('<II', fin.read(8))) +# sections = [] +# for offset, length in section_data: +# fin.seek(offset) +# sections.append(fin.read(length)) +# assert len(sections[-1]) == length +# return sections + +def main(): + # with open(sys.argv[1], 'rb') as fin: + # sections = read_xwb(fin) + with open(sys.argv[1], 'wb') as fout: + #write_xwb(fout, sections) + gen_xwb(fout) + +if __name__ == '__main__': + main() diff --git a/dlls/xactengine3_7/tests/resource.rc b/dlls/xactengine3_7/tests/resource.rc new file mode 100644 index 00000000000..7e801b61529 --- /dev/null +++ b/dlls/xactengine3_7/tests/resource.rc @@ -0,0 +1,24 @@ +/* + * Resources for xactengine3_7 test suite. + * + * Copyright 2022 Giovanni Mascellani for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "windef.h" + +/* @makedep: test.xwb */ +test.xwb RCDATA test.xwb diff --git a/dlls/xactengine3_7/tests/test.xwb b/dlls/xactengine3_7/tests/test.xwb new file mode 100644 index 0000000000000000000000000000000000000000..8fe9eaa0361bfaa9c832015344595d8597a0eb39 GIT binary patch literal 172 zcmWG{@^jH+U|`SzViO=v0OBb?ECIx8fEWbOX-1$J2$!T5mw@ES1t2>dK$<x~1S-fn J!Ud8>0RX{p2s{7)
literal 0 HcmV?d00001
diff --git a/dlls/xactengine3_7/tests/xact3.c b/dlls/xactengine3_7/tests/xact3.c index 623a1c97db8..7e60686e5ab 100644 --- a/dlls/xactengine3_7/tests/xact3.c +++ b/dlls/xactengine3_7/tests/xact3.c @@ -90,11 +90,120 @@ static void test_interfaces(void) } }
+static WCHAR *load_resource(const WCHAR *name) +{ + static WCHAR pathW[MAX_PATH]; + DWORD written; + HANDLE file; + HRSRC res; + void *ptr; + + GetTempPathW(ARRAY_SIZE(pathW), pathW); + lstrcatW(pathW, name); + + file = CreateFileW(pathW, GENERIC_READ|GENERIC_WRITE, 0, + NULL, CREATE_ALWAYS, 0, 0); + ok(file != INVALID_HANDLE_VALUE, "file creation failed, at %s, error %ld\n", + wine_dbgstr_w(pathW), GetLastError()); + + res = FindResourceW(NULL, name, (LPCWSTR)RT_RCDATA); + ok(res != 0, "couldn't find resource\n"); + ptr = LockResource(LoadResource(GetModuleHandleA(NULL), res)); + WriteFile(file, ptr, SizeofResource(GetModuleHandleA(NULL), res), + &written, NULL); + ok(written == SizeofResource(GetModuleHandleA(NULL), res), + "couldn't write resource\n" ); + CloseHandle(file); + + return pathW; +} + +struct notification_cb_data +{ + IXACT3WaveBank *wave_bank; + BOOL received; +}; + +static void WINAPI notification_cb(const XACT_NOTIFICATION *notification) +{ + struct notification_cb_data *data = notification->pvContext; + + data->received = TRUE; + ok(notification->type == XACTNOTIFICATIONTYPE_WAVEBANKPREPARED, + "Unexpected notification type %u\n", notification->type); + ok(notification->waveBank.pWaveBank == data->wave_bank, "Unexpected wave bank %p instead of %p\n", + notification->waveBank.pWaveBank, data->wave_bank); +} + +static void test_notifications(void) +{ + XACT_NOTIFICATION_DESCRIPTION notification_desc = { 0 }; + struct notification_cb_data notification_data = { 0 }; + XACT_STREAMING_PARAMETERS streaming_params = { 0 }; + XACT_RUNTIME_PARAMETERS params = { 0 }; + IXACT3Engine *engine; + WCHAR *filename; + unsigned int i; + HANDLE file; + DWORD state; + HRESULT hr; + + hr = CoCreateInstance(&CLSID_XACTEngine, NULL, CLSCTX_INPROC_SERVER, &IID_IXACT3Engine, (void **)&engine); + ok(hr == S_OK || broken(hr == REGDB_E_CLASSNOTREG) /* Win 10 v1507 */, "Cannot create engine, hr %#lx\n", hr); + + if (hr == REGDB_E_CLASSNOTREG) + { + win_skip("XACT not supported\n"); + return; + } + + params.lookAheadTime = XACT_ENGINE_LOOKAHEAD_DEFAULT; + params.fnNotificationCallback = notification_cb; + + hr = IXACT3Engine_Initialize(engine, ¶ms); + ok(hr == S_OK, "Cannot initialize engine, hr %#lx\n", hr); + + notification_desc.type = XACTNOTIFICATIONTYPE_WAVEBANKPREPARED; + notification_desc.flags = XACT_FLAG_NOTIFICATION_PERSIST; + notification_desc.pvContext = ¬ification_data; + hr = IXACT3Engine_RegisterNotification(engine, ¬ification_desc); + ok(hr == S_OK, "Cannot register notification, hr %#lx\n", hr); + + filename = load_resource(L"test.xwb"); + + file = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); + ok(file != INVALID_HANDLE_VALUE, "Cannot open file\n"); + + streaming_params.file = file; + streaming_params.packetSize = 0x800; + hr = IXACT3Engine_CreateStreamingWaveBank(engine, &streaming_params, ¬ification_data.wave_bank); + ok(hr == S_OK, "Cannot create a streaming wave bank, hr %#lx\n", hr); + + for (i = 0; i < 10 && !notification_data.received; i++) + { + IXACT3Engine_DoWork(engine); + Sleep(1); + } + + hr = IXACT3WaveBank_GetState(notification_data.wave_bank, &state); + ok(hr == S_OK, "Cannot query wave bank state, hr %#lx\n", hr); + ok(state == XACT_WAVEBANKSTATE_PREPARED, "Wave bank is not in prepared state, but in %#lx\n", state); + + todo_wine ok(notification_data.received, "The 'wave bank prepared' notification was never received\n"); + + IXACT3WaveBank_Destroy(notification_data.wave_bank); + CloseHandle(file); + IXACT3Engine_Release(engine); + + DeleteFileW(filename); +} + START_TEST(xact3) { CoInitialize(NULL);
test_interfaces(); + test_notifications();
CoUninitialize(); }