atl: Add support for the registrar parameter of AtlModuleUpdateRegistryFromResourceD.
[wine] / dlls / secur32 / tests / secur32.c
1 /*
2  * tests
3  *
4  * Copyright 2006 Robert Reif
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 #include <stdio.h>
21 #include <stdarg.h>
22 #include <windef.h>
23 #include <winbase.h>
24 #include <winnls.h>
25 #define SECURITY_WIN32
26 #include <security.h>
27 #include <schannel.h>
28
29 #include "wine/test.h"
30
31 static HMODULE secdll;
32
33 static BOOLEAN (WINAPI * pGetComputerObjectNameA)(EXTENDED_NAME_FORMAT NameFormat, LPSTR lpNameBuffer, PULONG lpnSize);
34 static BOOLEAN (WINAPI * pGetComputerObjectNameW)(EXTENDED_NAME_FORMAT NameFormat, LPWSTR lpNameBuffer, PULONG lpnSize);
35
36 static EXTENDED_NAME_FORMAT formats[] = {
37     NameUnknown, NameFullyQualifiedDN, NameSamCompatible, NameDisplay,
38     NameUniqueId, NameCanonical, NameUserPrincipal, NameCanonicalEx,
39     NameServicePrincipal, NameDnsDomain
40 };
41
42 static void testGetComputerObjectNameA(void)
43 {
44     char name[256];
45     ULONG size;
46     BOOLEAN rc;
47     int i;
48
49     for (i = 0; i < (sizeof(formats) / sizeof(formats[0])); i++) {
50         size = sizeof(name);
51         ZeroMemory(name, sizeof(name));
52         rc = pGetComputerObjectNameA(formats[i], name, &size);
53         ok(rc || ((formats[i] == NameUnknown) &&
54            (GetLastError() == ERROR_INVALID_PARAMETER)) ||
55            (GetLastError() == ERROR_CANT_ACCESS_DOMAIN_INFO) ||
56            (GetLastError() == ERROR_NO_SUCH_DOMAIN),
57            "GetComputerObjectNameA(%d) failed: %d\n",
58            formats[i], GetLastError());
59         if (rc)
60             trace("GetComputerObjectNameA() returned %s\n", name);
61     }
62 }
63
64 static void testGetComputerObjectNameW(void)
65 {
66     WCHAR nameW[256];
67     ULONG size;
68     BOOLEAN rc;
69     int i;
70
71     for (i = 0; i < (sizeof(formats) / sizeof(formats[0])); i++) {
72         size = sizeof(nameW)/sizeof(nameW[0]);
73         ZeroMemory(nameW, sizeof(nameW));
74         rc = pGetComputerObjectNameW(formats[i], nameW, &size);
75         ok(rc || ((formats[i] == NameUnknown) &&
76            (GetLastError() == ERROR_INVALID_PARAMETER)) ||
77            (GetLastError() == ERROR_CANT_ACCESS_DOMAIN_INFO) ||
78            (GetLastError() == ERROR_NO_SUCH_DOMAIN),
79            "GetComputerObjectNameW(%d) failed: %d\n",
80            formats[i], GetLastError());
81         if (rc) {
82             char name[256];
83             WideCharToMultiByte( CP_ACP, 0, nameW, -1, name, sizeof(name), NULL, NULL );
84             trace("GetComputerObjectNameW() returned %s\n", name);
85         }
86     }
87 }
88
89 START_TEST(secur32)
90 {
91     secdll = LoadLibraryA("secur32.dll");
92
93     if (!secdll)
94         secdll = LoadLibraryA("security.dll");
95
96     if (secdll)
97     {
98         pGetComputerObjectNameA = (PVOID)GetProcAddress(secdll, "GetComputerObjectNameA");
99         pGetComputerObjectNameW = (PVOID)GetProcAddress(secdll, "GetComputerObjectNameW");
100  
101         if (pGetComputerObjectNameA)
102             testGetComputerObjectNameA();
103
104         if (pGetComputerObjectNameW)
105             testGetComputerObjectNameW();
106
107         FreeLibrary(secdll);
108     }
109 }