Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/programs/net/tests/net.c
4389 views
1
/*
2
* Copyright 2024 Fabian Maurer
3
*
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.
8
*
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.
13
*
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
17
*/
18
19
#include <windows.h>
20
#include <stdio.h>
21
#include "wine/test.h"
22
23
static HANDLE nul_file;
24
25
#define check_exit_code(x) ok(r == (x), "got exit code %ld, expected %d\n", r, (x))
26
27
/* Copied and modified from the reg.exe tests */
28
#define run_net_exe(c,r) run_net_exe_(__FILE__,__LINE__,c,r)
29
static BOOL run_net_exe_(const char *file, unsigned line, const char *cmd, DWORD *rc)
30
{
31
STARTUPINFOA si = {sizeof(STARTUPINFOA)};
32
PROCESS_INFORMATION pi;
33
BOOL bret;
34
DWORD ret;
35
char cmdline[256];
36
37
si.dwFlags = STARTF_USESTDHANDLES;
38
si.hStdInput = nul_file;
39
si.hStdOutput = nul_file;
40
si.hStdError = nul_file;
41
42
strcpy(cmdline, cmd);
43
if (!CreateProcessA(NULL, cmdline, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi))
44
return FALSE;
45
46
ret = WaitForSingleObject(pi.hProcess, 10000);
47
if (ret == WAIT_TIMEOUT)
48
TerminateProcess(pi.hProcess, 1);
49
50
bret = GetExitCodeProcess(pi.hProcess, rc);
51
ok_(__FILE__, line)(bret, "GetExitCodeProcess failed: %ld\n", GetLastError());
52
53
CloseHandle(pi.hThread);
54
CloseHandle(pi.hProcess);
55
return bret;
56
}
57
58
static void test_stop(void)
59
{
60
DWORD r;
61
62
/* Stop non existing service */
63
64
run_net_exe("net stop non-existing-service", &r);
65
check_exit_code(2);
66
}
67
68
START_TEST(net)
69
{
70
SECURITY_ATTRIBUTES secattr = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
71
72
nul_file = CreateFileA("NUL", GENERIC_READ | GENERIC_WRITE, 0, &secattr, OPEN_EXISTING,
73
FILE_ATTRIBUTE_NORMAL, NULL);
74
75
test_stop();
76
77
CloseHandle(nul_file);
78
}
79
80