Signed-off-by: Dmitry Timoshkov <dmitry(a)baikal.ru>
---
configure.ac | 1 +
dlls/prntvpt/tests/Makefile.in | 5 ++
dlls/prntvpt/tests/prntvpt.c | 148 +++++++++++++++++++++++++++++++++
include/prntvpt.h | 1 +
4 files changed, 155 insertions(+)
create mode 100644 dlls/prntvpt/tests/Makefile.in
create mode 100644 dlls/prntvpt/tests/prntvpt.c
diff --git a/configure.ac b/configure.ac
index e61a98455c..72276fc066 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3616,6 +3616,7 @@ WINE_CONFIG_MAKEFILE(dlls/pidgen)
WINE_CONFIG_MAKEFILE(dlls/powrprof)
WINE_CONFIG_MAKEFILE(dlls/printui)
WINE_CONFIG_MAKEFILE(dlls/prntvpt)
+WINE_CONFIG_MAKEFILE(dlls/prntvpt/tests)
WINE_CONFIG_MAKEFILE(dlls/propsys)
WINE_CONFIG_MAKEFILE(dlls/propsys/tests)
WINE_CONFIG_MAKEFILE(dlls/psapi)
diff --git a/dlls/prntvpt/tests/Makefile.in b/dlls/prntvpt/tests/Makefile.in
new file mode 100644
index 0000000000..692a134d01
--- /dev/null
+++ b/dlls/prntvpt/tests/Makefile.in
@@ -0,0 +1,5 @@
+TESTDLL = prntvpt.dll
+IMPORTS = prntvpt winspool ole32
+
+C_SRCS = \
+ prntvpt.c
diff --git a/dlls/prntvpt/tests/prntvpt.c b/dlls/prntvpt/tests/prntvpt.c
new file mode 100644
index 0000000000..55b6f3fdef
--- /dev/null
+++ b/dlls/prntvpt/tests/prntvpt.c
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2019 Dmitry Timoshkov
+ *
+ * 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
+ */
+
+#define COBJMACROS
+
+#include <stdarg.h>
+
+#include <windef.h>
+#include <winbase.h>
+#include <wingdi.h>
+#include <winspool.h>
+#include <objbase.h>
+#include <prntvpt.h>
+
+#include "wine/test.h"
+
+static WCHAR default_name[256];
+
+struct hprov_data
+{
+ HPTPROVIDER hprov;
+ HRESULT hr;
+};
+
+static DWORD WINAPI CloseProvider_proc(void *param)
+{
+ struct hprov_data *data = param;
+
+ data->hr = PTCloseProvider(data->hprov);
+
+ return 0;
+}
+
+static void test_PTOpenProvider(void)
+{
+ DWORD tid, i;
+ HPTPROVIDER hprov;
+ HRESULT hr;
+ HANDLE hthread;
+ struct hprov_data data;
+
+ hr = PTOpenProvider(default_name, 1, &hprov);
+ ok(hr == S_OK, "got %#x\n", hr);
+
+ data.hprov = hprov;
+ hthread = CreateThread(NULL, 0, CloseProvider_proc, &data, 0, &tid);
+ WaitForSingleObject(hthread, INFINITE);
+ CloseHandle(hthread);
+ ok(data.hr == E_HANDLE || data.hr == E_INVALIDARG /* XP */ || broken(data.hr == S_OK) /* Win8 */, "got %#x\n", data.hr);
+
+ if (data.hr != S_OK)
+ {
+ hr = PTCloseProvider(hprov);
+ ok(hr == S_OK, "got %#x\n", hr);
+ }
+
+ hr = PTOpenProvider(default_name, 0, &hprov);
+ ok(hr == E_INVALIDARG, "got %#x\n", hr);
+
+ for (i = 2; i < 20; i++)
+ {
+ hr = PTOpenProvider(default_name, i, &hprov);
+ ok(hr == 0x80040001 || hr == E_INVALIDARG /* Wine */, "%u: got %#x\n", i, hr);
+ }
+}
+
+static void test_PTOpenProviderEx(void)
+{
+ DWORD tid, ver, i;
+ HPTPROVIDER hprov;
+ HRESULT hr;
+ HANDLE hthread;
+ struct hprov_data data;
+
+ hr = PTOpenProviderEx(default_name, 1, 1, &hprov, NULL);
+ ok(hr == E_INVALIDARG, "got %#x\n", hr);
+
+ ver = 0xdeadbeef;
+ hr = PTOpenProviderEx(default_name, 1, 1, &hprov, &ver);
+ ok(hr == S_OK, "got %#x\n", hr);
+ ok(ver == 1, "got %#x\n", ver);
+
+ data.hprov = hprov;
+ hthread = CreateThread(NULL, 0, CloseProvider_proc, &data, 0, &tid);
+ WaitForSingleObject(hthread, INFINITE);
+ CloseHandle(hthread);
+ ok(data.hr == E_HANDLE || data.hr == E_INVALIDARG /* XP */ || broken(data.hr == S_OK) /* Win8 */, "got %#x\n", data.hr);
+
+ if (data.hr != S_OK)
+ {
+ hr = PTCloseProvider(hprov);
+ ok(hr == S_OK, "got %#x\n", hr);
+ }
+
+ for (i = 1; i < 20; i++)
+ {
+ hr = PTOpenProviderEx(default_name, 0, i, &hprov, &ver);
+ ok(hr == E_INVALIDARG, "%u: got %#x\n", i, hr);
+
+ ver = 0xdeadbeef;
+ hr = PTOpenProviderEx(default_name, 1, i, &hprov, &ver);
+ ok(hr == S_OK, "%u: got %#x\n", i, hr);
+ ok(ver == 1, "%u: got %#x\n", i, ver);
+ PTCloseProvider(hprov);
+
+ ver = 0xdeadbeef;
+ hr = PTOpenProviderEx(default_name, i, i, &hprov, &ver);
+ ok(hr == S_OK, "%u: got %#x\n", i, hr);
+ ok(ver == 1, "%u: got %#x\n", i, ver);
+ PTCloseProvider(hprov);
+ }
+}
+
+START_TEST(prntvpt)
+{
+ DWORD size;
+
+ CoInitializeEx(NULL, COINIT_MULTITHREADED);
+
+ size = ARRAY_SIZE(default_name);
+ if (!GetDefaultPrinterW(default_name, &size))
+ {
+ skip("no default printer set\n");
+ return;
+ }
+
+ trace("default printer: %s\n", wine_dbgstr_w(default_name));
+
+ test_PTOpenProvider();
+ test_PTOpenProviderEx();
+
+ CoUninitialize();
+}
diff --git a/include/prntvpt.h b/include/prntvpt.h
index 8b873dd0aa..a453f8cb37 100644
--- a/include/prntvpt.h
+++ b/include/prntvpt.h
@@ -27,6 +27,7 @@ DECLARE_HANDLE(HPTPROVIDER);
HRESULT WINAPI PTOpenProvider(const WCHAR *printer, DWORD version, HPTPROVIDER *provider);
HRESULT WINAPI PTOpenProviderEx(const WCHAR *printer, DWORD max_version, DWORD pref_version, HPTPROVIDER *provider, DWORD *used_version);
+HRESULT WINAPI PTCloseProvider(HPTPROVIDER);
#ifdef __cplusplus
}
--
2.26.2