makefiles: Explicitly create destination dirs when installing symlinks.
[wine/zf.git] / dlls / schedsvc / tests / atsvcapi.c
blobf10c9d072325c2ab73d4b0fe1dab4cbd06f231ae
1 /*
2 * Copyright 2018 Dmitry Timoshkov
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdio.h>
20 #include <windows.h>
21 #include <ole2.h>
22 #include <rpcdce.h>
23 #include <mstask.h>
24 #include "atsvc.h"
26 #include "wine/test.h"
28 /* lmat.h defines those, but other types in that file conflict
29 * with generated atsvc.h typedefs.
31 #define JOB_ADD_CURRENT_DATE 0x08
32 #define JOB_NONINTERACTIVE 0x10
34 extern handle_t atsvc_handle;
36 static int test_failures, test_skipped;
38 static LONG CALLBACK rpc_exception_filter(EXCEPTION_POINTERS *ptrs)
40 if (test_skipped)
41 skip("Can't connect to ATSvc service: %#x\n", ptrs->ExceptionRecord->ExceptionCode);
43 if (winetest_debug)
45 fprintf(stdout, "%04x:atsvcapi: 1 tests executed (0 marked as todo, %d %s), %d skipped.\n",
46 GetCurrentProcessId(), test_failures, test_failures != 1 ? "failures" : "failure", test_skipped);
47 fflush(stdout);
49 ExitProcess(test_failures);
52 START_TEST(atsvcapi)
54 static unsigned char ncalrpc[] = "ncalrpc";
55 static WCHAR task1W[] = { 'T','a','s','k','1','.','e','x','e',0 };
56 HRESULT hr;
57 unsigned char *binding_str;
58 WCHAR server_name[MAX_COMPUTERNAME_LENGTH + 1];
59 PTOP_LEVEL_EXCEPTION_FILTER old_exception_filter;
60 AT_ENUM_CONTAINER container;
61 AT_INFO info, *info2;
62 DWORD ret, i, total, start_index, jobid, try, try_count;
63 BOOL found;
65 total = MAX_COMPUTERNAME_LENGTH + 1;
66 SetLastError(0xdeadbeef);
67 ret = GetComputerNameW(server_name, &total);
68 ok(ret, "GetComputerName error %u\n", GetLastError());
70 hr = RpcStringBindingComposeA(NULL, ncalrpc, NULL, NULL, NULL, &binding_str);
71 ok(hr == RPC_S_OK, "RpcStringBindingCompose error %#x\n", hr);
72 hr = RpcBindingFromStringBindingA(binding_str, &atsvc_handle);
73 ok(hr == RPC_S_OK, "RpcBindingFromStringBinding error %#x\n", hr);
74 hr = RpcStringFreeA(&binding_str);
75 ok(hr == RPC_S_OK, "RpcStringFree error %#x\n", hr);
77 /* widl generated RpcTryExcept/RpcExcept can't catch raised exceptions */
78 old_exception_filter = SetUnhandledExceptionFilter(rpc_exception_filter);
80 /* If the first call fails that's probably because the service is not running */
81 test_failures = 0;
82 test_skipped = 1;
84 memset(&info, 0, sizeof(info));
85 info.Flags = JOB_ADD_CURRENT_DATE | JOB_NONINTERACTIVE;
86 info.Command = task1W;
87 jobid = 0;
88 ret = NetrJobAdd(server_name, &info, &jobid);
89 if (ret == ERROR_ACCESS_DENIED)
91 win_skip("NetrJobAdd: Access denied, skipping the tests\n");
92 goto skip_tests;
94 ok(ret == ERROR_SUCCESS || broken(ret == ERROR_NOT_SUPPORTED) /* Win8+ */, "NetrJobAdd error %u\n", ret);
95 if (ret == ERROR_NOT_SUPPORTED)
97 /* FIXME: use win_skip() when todo_wine above is removed */
98 skip("NetrJobAdd is not supported on this platform\n");
99 goto skip_tests;
101 ok(jobid != 0, "jobid should not be 0\n");
103 /* From now on: if the call fails that's a failure */
104 test_failures = 1;
105 test_skipped = 0;
107 info2 = NULL;
108 ret = NetrJobGetInfo(server_name, 0xdeadbeef, &info2);
109 ok(ret == APE_AT_ID_NOT_FOUND || broken(1) /* vista and w2008 return rubbish here */, "wrong error %u\n", ret);
111 ret = NetrJobDel(server_name, 0xdeadbeef, 0xdeadbeef);
112 ok(ret == APE_AT_ID_NOT_FOUND, "wrong error %u\n", ret);
114 try_count = 5;
116 for (try = 1; try <= try_count; try++)
118 container.EntriesRead = 0;
119 container.Buffer = NULL;
120 total = start_index = 0;
121 ret = NetrJobEnum(server_name, &container, -1, &total, &start_index);
122 if (ret == ERROR_ACCESS_DENIED)
124 win_skip("NetrJobEnum: Access denied, skipping the tests\n");
125 goto skip_tests_delete;
127 ok(ret == ERROR_SUCCESS, "NetrJobEnum error %u (%#x)\n", ret, ret);
128 ok(total != 0, "total %u\n", total);
129 ok(start_index == 0, "start_index %u\n", start_index);
130 ok(container.Buffer != NULL, "Buffer %p\n", container.Buffer);
131 ok(container.EntriesRead != 0, "EntriesRead %u\n", container.EntriesRead);
133 found = FALSE;
135 for (i = 0; i < container.EntriesRead; i++)
137 trace("%u: jobid %u, command %s\n", i, container.Buffer[i].JobId, wine_dbgstr_w(container.Buffer[i].Command));
139 if (container.Buffer[i].JobId == jobid ||
140 !lstrcmpW(container.Buffer[i].Command, task1W))
142 found = TRUE;
143 trace("found %u: jobid %u, command %s\n", i, container.Buffer[i].JobId, wine_dbgstr_w(container.Buffer[i].Command));
146 info2 = NULL;
147 ret = NetrJobGetInfo(server_name, container.Buffer[i].JobId, &info2);
148 ok(ret == ERROR_SUCCESS, "NetrJobGetInfo error %u\n", ret);
150 ok(container.Buffer[i].JobTime == info2->JobTime, "%u != %u\n", (UINT)container.Buffer[i].JobTime, (UINT)info2->JobTime);
151 ok(container.Buffer[i].DaysOfMonth == info2->DaysOfMonth, "%u != %u\n", container.Buffer[i].DaysOfMonth, info2->DaysOfMonth);
152 ok(container.Buffer[i].DaysOfWeek == info2->DaysOfWeek, "%u != %u\n", container.Buffer[i].DaysOfWeek, info2->DaysOfWeek);
153 ok(container.Buffer[i].Flags == info2->Flags, "%#x != %#x\n", container.Buffer[i].Flags, info2->Flags);
154 ok(!lstrcmpW(container.Buffer[i].Command, info2->Command), "%s != %s\n", wine_dbgstr_w(container.Buffer[i].Command), wine_dbgstr_w(info2->Command));
156 MIDL_user_free(container.Buffer[i].Command);
157 MIDL_user_free(info2->Command);
158 MIDL_user_free(info2);
161 if (found)
162 break;
165 MIDL_user_free(container.Buffer);
167 ok(found, "just added jobid %u should be found\n", jobid);
169 skip_tests_delete:
170 ret = NetrJobDel(server_name, jobid, jobid);
171 ok(ret == ERROR_SUCCESS, "NetrJobDel error %u\n", ret);
173 skip_tests:
174 SetUnhandledExceptionFilter(old_exception_filter);
176 hr = RpcBindingFree(&atsvc_handle);
177 ok(hr == RPC_S_OK, "RpcBindingFree error %#x\n", hr);
180 DECLSPEC_HIDDEN handle_t __RPC_USER ATSVC_HANDLE_bind(ATSVC_HANDLE str)
182 static unsigned char ncalrpc[] = "ncalrpc";
183 unsigned char *binding_str;
184 handle_t rpc_handle;
185 HRESULT hr;
187 hr = RpcStringBindingComposeA(NULL, ncalrpc, NULL, NULL, NULL, &binding_str);
188 ok(hr == RPC_S_OK, "RpcStringBindingCompose error %#x\n", hr);
190 hr = RpcBindingFromStringBindingA(binding_str, &rpc_handle);
191 ok(hr == RPC_S_OK, "RpcBindingFromStringBinding error %#x\n", hr);
193 RpcStringFreeA(&binding_str);
194 return rpc_handle;
197 DECLSPEC_HIDDEN void __RPC_USER ATSVC_HANDLE_unbind(ATSVC_HANDLE ServerName, handle_t rpc_handle)
199 RpcBindingFree(&rpc_handle);