update for HEAD-2003091401
[reactos.git] / lib / rpcrt4 / tests / rpc.c
1 /*
2  * Unit test suite for rpc functions
3  *
4  * Copyright 2002 Greg Turner
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "wine/test.h"
22 #include <stdarg.h>
23
24 #include <windef.h>
25 #include <winbase.h>
26 #include <winnt.h>
27 #include <winerror.h>
28
29 #include "wine/unicode.h"
30 #include "rpc.h"
31
32 static UUID Uuid_Table[10] = {
33   { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, /* 0 (null) */
34   { 0xdeadbeef, 0xdead, 0xbeef, {0x10, 0x21, 0x35, 0x56, 0x89, 0xa0, 0xf4, 0x8a} }, /* 1 */
35   { 0xabadfeed, 0x49ff, 0xbead, {0x8a, 0xf4, 0xa0, 0x89, 0x56, 0x35, 0x21, 0x10} }, /* 2 */
36   { 0x93da375c, 0x1324, 0x1355, {0x87, 0xff, 0x49, 0x44, 0x34, 0x44, 0x22, 0x19} }, /* 3 */
37   { 0xdeadbeef, 0xdead, 0xbeef, {0x10, 0x21, 0x35, 0x56, 0x89, 0xa0, 0xf4, 0x8b} }, /* 4 (~1) */
38   { 0x9badfeed, 0x49ff, 0xbead, {0x8a, 0xf4, 0xa0, 0x89, 0x56, 0x35, 0x21, 0x10} }, /* 5 (~2) */
39   { 0x00000000, 0x0001, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, /* 6 (~0) */
40   { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} }, /* 7 (~0) */
41   { 0x12312312, 0x1231, 0x1231, {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xff} }, /* 8 */
42   { 0x11111111, 0x1111, 0x1111, {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11} }  /* 9 */
43 };
44
45 /* index of "10" means "NULL" */
46 static BOOL Uuid_Comparison_Grid[11][11] = {
47   { TRUE,  FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE  },
48   { FALSE, TRUE,  FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE },
49   { FALSE, FALSE, TRUE,  FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE },
50   { FALSE, FALSE, FALSE, TRUE,  FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE },
51   { FALSE, FALSE, FALSE, FALSE, TRUE,  FALSE, FALSE, FALSE, FALSE, FALSE, FALSE },
52   { FALSE, FALSE, FALSE, FALSE, FALSE, TRUE,  FALSE, FALSE, FALSE, FALSE, FALSE },
53   { FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE,  FALSE, FALSE, FALSE, FALSE },
54   { FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE,  FALSE, FALSE, FALSE },
55   { FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE,  FALSE, FALSE },
56   { FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE,  FALSE },
57   { TRUE,  FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE  }
58 };
59
60 void UuidConversionAndComparison(void) {
61     CHAR strx[100], x;
62     LPSTR str = strx;
63     WCHAR wstrx[100], wx;
64     LPWSTR wstr = wstrx;
65
66     UUID Uuid1, Uuid2, *PUuid1, *PUuid2;
67     RPC_STATUS rslt;
68
69     int i1,i2;
70
71     /* Uuid Equality */
72     for (i1 = 0; i1 < 11; i1++)
73         for (i2 = 0; i2 < 11; i2++) {
74             if (i1 < 10) {
75                 Uuid1 = Uuid_Table[i1]; 
76                 PUuid1 = &Uuid1;
77             } else {
78                 PUuid1 = NULL;
79             }        
80             if (i2 < 10) {
81                 Uuid2 = Uuid_Table[i2];
82                 PUuid2 = &Uuid2;
83             } else {
84                 PUuid2 = NULL;
85             }
86             ok( (UuidEqual(PUuid1, PUuid2, &rslt) == Uuid_Comparison_Grid[i1][i2]), "UUID Equality" );
87         }
88
89     /* Uuid to String to Uuid (char) */
90     for (i1 = 0; i1 < 10; i1++) {
91         Uuid1 = Uuid_Table[i1];
92         ok( (UuidToStringA(&Uuid1, (unsigned char**)&str) == RPC_S_OK), "Simple UUID->String copy" );
93         ok( (UuidFromStringA(str, &Uuid2) == RPC_S_OK), "Simple String->UUID copy from generated UUID String" );
94         ok( UuidEqual(&Uuid1, &Uuid2, &rslt), "Uuid -> String -> Uuid transform" );
95         /* invalid uuid tests  -- size of valid UUID string=36 */
96         for (i2 = 0; i2 < 36; i2++) {
97             x = str[i2];
98             str[i2] = 'g'; /* whatever, but "g" is a good boundary condition */
99             ok( (UuidFromStringA(str, &Uuid1) == RPC_S_INVALID_STRING_UUID), "Invalid UUID String" );
100             str[i2] = x; /* change it back so remaining tests are interesting. */
101         }
102     }
103
104     /* Uuid to String to Uuid (wchar) */
105     for (i1 = 0; i1 < 10; i1++) {
106         Uuid1 = Uuid_Table[i1];
107         rslt=UuidToStringW(&Uuid1, &wstr);
108         if (rslt==RPC_S_CANNOT_SUPPORT) {
109             /* Must be Win9x (no Unicode support), skip the tests */
110             break;
111         }
112         ok( (rslt == RPC_S_OK), "Simple UUID->WString copy" );
113         ok( (UuidFromStringW(wstr, &Uuid2) == RPC_S_OK), "Simple WString->UUID copy from generated UUID String" );
114         ok( UuidEqual(&Uuid1, &Uuid2, &rslt), "Uuid -> WString -> Uuid transform" );
115         /* invalid uuid tests  -- size of valid UUID string=36 */
116         for (i2 = 0; i2 < 36; i2++) {
117             wx = wstr[i2];
118             wstr[i2] = 'g'; /* whatever, but "g" is a good boundary condition */
119             ok( (UuidFromStringW(wstr, &Uuid1) == RPC_S_INVALID_STRING_UUID), "Invalid UUID WString" );
120             wstr[i2] = wx; /* change it back so remaining tests are interesting. */
121         }
122     }
123 }
124
125 START_TEST( rpc )
126 {
127     trace ( " ** Uuid Conversion and Comparison Tests **\n" );
128     UuidConversionAndComparison();
129 }