From 7212b91306542f5a71fe51a99b012a402db700ab Mon Sep 17 00:00:00 2001
From: Alistair Leslie-Hughes <leslie_alistair@hotmail.com>
Date: Sat, 18 Jan 2020 18:50:34 +1100
Subject: [PATCH] xaudio2_7/tests: Add more tests

---
 dlls/x3daudio1_7/Makefile.in     |   1 +
 dlls/xaudio2_7/tests/Makefile.in |   5 +-
 dlls/xaudio2_7/tests/globals.xgs | Bin 0 -> 440 bytes
 dlls/xaudio2_7/tests/rsrc.rc     |  22 +++++++
 dlls/xaudio2_7/tests/xact.c      |  99 ++++++++++++++++++++++++++-----
 5 files changed, 112 insertions(+), 15 deletions(-)
 create mode 100644 dlls/xaudio2_7/tests/globals.xgs
 create mode 100644 dlls/xaudio2_7/tests/rsrc.rc

diff --git a/dlls/x3daudio1_7/Makefile.in b/dlls/x3daudio1_7/Makefile.in
index 267a93fd6..5438bc6d8 100644
--- a/dlls/x3daudio1_7/Makefile.in
+++ b/dlls/x3daudio1_7/Makefile.in
@@ -1,5 +1,6 @@
 EXTRADEFS = -DX3DAUDIO1_VER=7 -DXAUDIO2_VER=7
 MODULE    = x3daudio1_7.dll
+IMPORTLIB = x3daudio1_7
 PARENTSRC = ../xaudio2_7
 EXTRALIBS = $(FAUDIO_LIBS)
 EXTRAINCL = $(FAUDIO_CFLAGS)
diff --git a/dlls/xaudio2_7/tests/Makefile.in b/dlls/xaudio2_7/tests/Makefile.in
index ecd728d65..1bb39cc56 100644
--- a/dlls/xaudio2_7/tests/Makefile.in
+++ b/dlls/xaudio2_7/tests/Makefile.in
@@ -1,6 +1,9 @@
 TESTDLL = xaudio2_7.dll
-IMPORTS = ole32
+IMPORTS = ole32 x3daudio1_7
 
 C_SRCS = \
 	xact.c \
 	xaudio2.c
+
+RC_SRCS = \
+	rsrc.rc
diff --git a/dlls/xaudio2_7/tests/globals.xgs b/dlls/xaudio2_7/tests/globals.xgs
new file mode 100644
index 0000000000000000000000000000000000000000..37bd75b44d64fdf0862ba41c5548ec140f6607e6
GIT binary patch
literal 440
zcmZ8cF;2rk5FFb;L=nLwsF0vai3CxsL@7cLMuL*V*@R0jXUjgf$Uoo@e1L`@Af=?E
z-~&8>iq5R>EJ(Q1&d!YXR&zIlsDF$@e3d63Q8j;i_ksW|?DKVJ#BIT~;`-!jd%zLb
zH}h-m)%sztc3%9-GGL7bdyU7f4FAOKyuTsZZmjbPbb2hxQ)iTCyY)*e4$QC_W68qX
zjKPuo#&H4buxwgv+0X-(+zEw{rlL>=qav3vd<6d%0Uox0J@?-kFW5q6*F0E!wD`oh
zgJ;Xni)F8%q0WuaG3DqQBjUxCToNuxk;uvNaVAL{VPvAadZq|rlBSBX3u)r}C>Ba&
Sh*F}-cp4>zo*<NNBYptThnF`1

literal 0
HcmV?d00001

diff --git a/dlls/xaudio2_7/tests/rsrc.rc b/dlls/xaudio2_7/tests/rsrc.rc
new file mode 100644
index 000000000..2c1961c72
--- /dev/null
+++ b/dlls/xaudio2_7/tests/rsrc.rc
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2020 Alistair Leslie-Hughes
+ *
+ * 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: globals.xgs*/
+globals.xgs RCDATA "globals.xgs"
diff --git a/dlls/xaudio2_7/tests/xact.c b/dlls/xaudio2_7/tests/xact.c
index afe8e4d83..881513668 100644
--- a/dlls/xaudio2_7/tests/xact.c
+++ b/dlls/xaudio2_7/tests/xact.c
@@ -18,14 +18,25 @@
 
 #include <windows.h>
 #include <math.h>
+#include <limits.h>
+#include <float.h>
 
 #define COBJMACROS
 #include "wine/test.h"
 
 #include "xact3.h"
+#include "x3daudio.h"
 
 #include "initguid.h"
-DEFINE_GUID(IID_IXACT3Engine301, 0xe72c1b9a, 0xd717, 0x41c0, 0x81, 0xa6, 0x50, 0xeb, 0x56, 0xe8, 0x06, 0x49);
+DEFINE_GUID(IID_IXACT3Engine31, 0xe72c1b9a, 0xd717, 0x41c0, 0x81, 0xa6, 0x50, 0xeb, 0x56, 0xe8, 0x06, 0x49);
+
+DEFINE_GUID(CLSID_XACTEngine30, 0x3b80ee2a, 0xb0f5, 0x4780, 0x9e,0x30, 0x90,0xcb,0x39,0x68,0x5b,0x03);
+DEFINE_GUID(CLSID_XACTEngine31, 0x962f5027, 0x99be, 0x4692, 0xa4,0x68, 0x85,0x80,0x2c,0xf8,0xde,0x61);
+DEFINE_GUID(CLSID_XACTEngine32, 0xd3332f02, 0x3dd0, 0x4de9, 0x9a,0xec, 0x20,0xd8,0x5c,0x41,0x11,0xb6);
+DEFINE_GUID(CLSID_XACTEngine33, 0x94c1affa, 0x66e7, 0x4961, 0x95,0x21, 0xcf,0xde,0xf3,0x12,0x8d,0x4f);
+DEFINE_GUID(CLSID_XACTEngine34, 0x0977d092, 0x2d95, 0x4e43, 0x8d,0x42, 0x9d,0xdc,0xc2,0x54,0x5e,0xd5);
+DEFINE_GUID(CLSID_XACTEngine35, 0x074b110f, 0x7f58, 0x4743, 0xae,0xa5, 0x12,0xf1,0x5b,0x50,0x74,0xed);
+DEFINE_GUID(CLSID_XACTEngine36, 0x248d8a3b, 0x6256, 0x44d3, 0xa0,0x18, 0x2a,0xc9,0x6c,0x45,0x9f,0x47);
 
 struct xact_interfaces
 {
@@ -35,25 +46,25 @@ struct xact_interfaces
     BOOL todo;
 } xact_interfaces[] =
 {
-    {&CLSID_XACTEngine30, &IID_IXACT3Engine301, E_NOINTERFACE, TRUE },
-    {&CLSID_XACTEngine30, &IID_IXACT3Engine,    E_NOINTERFACE, TRUE },
+    {&CLSID_XACTEngine30, &IID_IXACT3Engine31, E_NOINTERFACE, TRUE },
+    {&CLSID_XACTEngine30, &IID_IXACT3Engine,   E_NOINTERFACE, TRUE },
 
     /* Version 3.1 to 3.4 use the same inteface */
-    {&CLSID_XACTEngine31, &IID_IXACT3Engine301, S_OK },
-    {&CLSID_XACTEngine32, &IID_IXACT3Engine301, S_OK },
-    {&CLSID_XACTEngine33, &IID_IXACT3Engine301, S_OK },
-    {&CLSID_XACTEngine34, &IID_IXACT3Engine301, S_OK },
+    {&CLSID_XACTEngine31, &IID_IXACT3Engine31, S_OK },
+    {&CLSID_XACTEngine32, &IID_IXACT3Engine31, S_OK },
+    {&CLSID_XACTEngine33, &IID_IXACT3Engine31, S_OK },
+    {&CLSID_XACTEngine34, &IID_IXACT3Engine31, S_OK },
 
     /* Version 3.5 to 3.7 use the same inteface */
-    {&CLSID_XACTEngine35, &IID_IXACT3Engine301, E_NOINTERFACE },
-    {&CLSID_XACTEngine35, &IID_IXACT3Engine,    S_OK },
+    {&CLSID_XACTEngine35, &IID_IXACT3Engine31, E_NOINTERFACE },
+    {&CLSID_XACTEngine35, &IID_IXACT3Engine,   S_OK },
 
-    {&CLSID_XACTEngine36, &IID_IXACT3Engine301, E_NOINTERFACE },
-    {&CLSID_XACTEngine36, &IID_IXACT3Engine,    S_OK },
+    {&CLSID_XACTEngine36, &IID_IXACT3Engine31, E_NOINTERFACE },
+    {&CLSID_XACTEngine36, &IID_IXACT3Engine,   S_OK },
 
-    {&CLSID_XACTEngine37, &IID_IXACT3Engine301, E_NOINTERFACE },
-    {&CLSID_XACTEngine37, &IID_IXACT3Engine,    S_OK },
-    {&CLSID_XACTEngine37, &IID_IUnknown,        S_OK },
+    {&CLSID_XACTEngine,   &IID_IXACT3Engine31, E_NOINTERFACE },
+    {&CLSID_XACTEngine,   &IID_IXACT3Engine,   S_OK },
+    {&CLSID_XACTEngine,   &IID_IUnknown,       S_OK },
 };
 
 static void test_interfaces(void)
@@ -78,11 +89,71 @@ static void test_interfaces(void)
     }
 }
 
+static void test_global_properties(void)
+{
+    HRESULT hr;
+    IXACT3Engine *engine;
+    XACTVARIABLEINDEX index;
+    XACTVARIABLEVALUE value;
+    HRSRC res;
+    void *ptr;
+    XACT_RUNTIME_PARAMETERS xparams = {0};
+    WAVEFORMATEXTENSIBLE format;
+    X3DAUDIO_HANDLE instance = {0};
+
+    hr = CoCreateInstance(&CLSID_XACTEngine, NULL, CLSCTX_INPROC_SERVER, &IID_IXACT3Engine, (void**)&engine);
+
+    if (FAILED(hr))
+    {
+        win_skip("IXACT3Engine Unsupported.\n");
+        return;
+    }
+
+    index = IXACT3Engine_GetGlobalVariableIndex(engine, "SpeedOfSound");
+    ok(index == XACTVARIABLEINDEX_INVALID , "Found variable 0x%08x\n", index);
+
+    res = FindResourceW(NULL, L"globals.xgs", (LPCWSTR)RT_RCDATA);
+
+    ptr = LockResource(LoadResource(GetModuleHandleA(NULL), res));
+
+    xparams.lookAheadTime = 250;
+    xparams.globalSettingsBufferSize = SizeofResource( GetModuleHandleA(NULL), res);
+    xparams.pGlobalSettingsBuffer = ptr;
+    hr = IXACT3Engine_Initialize(engine, &xparams);
+    ok(hr == S_OK ||
+        hr == XAUDIO2_E_INVALID_CALL /* Vista */, "got 0x%08x\n", hr);
+    if (FAILED(hr))
+        goto end;
+
+    index = IXACT3Engine_GetGlobalVariableIndex(engine, "SpeedOfSound");
+    ok(index != XACTVARIABLEINDEX_INVALID, "Failed to find variable %d\n", index);
+
+    value = 0.1f;
+    hr = IXACT3Engine_GetGlobalVariable(engine, index, &value);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+    ok(value == 0.0f, "got %f\n", value);
+
+    hr = IXACT3Engine_GetFinalMixFormat(engine, &format);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+
+    /* Invalid SpeedOfSound value  */
+    X3DAudioInitialize(format.dwChannelMask, value, instance);
+    ok(instance[0] != 0, "got 0x%08x\n", instance[0]);
+
+    hr = IXACT3Engine_GetGlobalVariable(engine, index, &value);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+    ok(value == 0.0f, "got %f\n", value);
+
+end:
+    IXACT3Engine_Release(engine);
+}
+
 START_TEST(xact)
 {
     CoInitialize(NULL);
 
     test_interfaces();
+    test_global_properties();
 
     CoUninitialize();
 }
-- 
2.25.1

