quartz: Give video renderer's Inner_QueryInterface a less generic name.
[wine] / dlls / rsabase / tests / rsabase.c
1 /*
2  * Unit tests for rsabase functions
3  *
4  * Copyright (c) 2004 Michael Jung
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
21 #include <string.h>
22 #include "wine/test.h"
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winerror.h"
26 #include "wincrypt.h"
27
28 HCRYPTPROV hProv;
29 static const char szContainer[] = "Wine Test Container";
30 static const char szProvider[] = MS_DEF_PROV_A;
31
32 static int init_environment(void)
33 {
34         hProv = (HCRYPTPROV)INVALID_HANDLE_VALUE;
35         
36         if (!CryptAcquireContext(&hProv, szContainer, szProvider, PROV_RSA_FULL, 0))
37         {
38                 if (GetLastError()==NTE_BAD_KEYSET)
39                 {
40                         if(!CryptAcquireContext(&hProv, szContainer, szProvider, PROV_RSA_FULL, CRYPT_NEWKEYSET)) 
41                         {
42                                 trace("%08x\n", GetLastError());
43                                 return 0;
44                         }
45                 }
46                 else
47                 {
48                         trace("%08x\n", GetLastError());
49                         return 0;
50                 }
51         }
52
53         return 1;
54 }
55
56 static void clean_up_environment(void)
57 {
58         CryptAcquireContext(&hProv, szContainer, szProvider, PROV_RSA_FULL, CRYPT_DELETEKEYSET);
59 }
60
61 static void test_gen_random(void)
62 {
63         BOOL result;
64         BYTE rnd1[16], rnd2[16];
65
66         memset(rnd1, 0, sizeof(rnd1));
67         memset(rnd2, 0, sizeof(rnd2));
68         
69         result = CryptGenRandom(hProv, sizeof(rnd1), rnd1);
70         ok(result, "%08x\n", GetLastError());
71
72         result = CryptGenRandom(hProv, sizeof(rnd2), rnd2);
73         ok(result, "%08x\n", GetLastError());
74
75         ok(memcmp(rnd1, rnd2, sizeof(rnd1)), "CryptGenRandom generates non random data\n");
76 }
77
78 START_TEST(rsabase)
79 {
80         if (!init_environment()) 
81                 return;
82         test_gen_random();
83         clean_up_environment();
84 }