po: Update French translation.
[wine] / dlls / snmpapi / tests / util.c
1 /*
2  * Copyright 2007 Hans Leidekker
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 <stdio.h>
20
21 #include <wine/test.h>
22
23 #include <windef.h>
24 #include <snmp.h>
25
26 static INT  (WINAPI *pSnmpUtilAsnAnyCpy)(AsnAny*, AsnAny*);
27 static VOID (WINAPI *pSnmpUtilAsnAnyFree)(AsnAny*);
28 static INT  (WINAPI *pSnmpUtilOctetsCmp)(AsnOctetString*, AsnOctetString*);
29 static INT  (WINAPI *pSnmpUtilOctetsCpy)(AsnOctetString*, AsnOctetString*);
30 static VOID (WINAPI *pSnmpUtilOctetsFree)(AsnOctetString*);
31 static INT  (WINAPI *pSnmpUtilOctetsNCmp)(AsnOctetString*, AsnOctetString*, UINT);
32
33 static void InitFunctionPtrs(void)
34 {
35     HMODULE hSnmpapi = GetModuleHandle("snmpapi.dll");
36
37 #define SNMPAPI_GET_PROC(func) \
38     p ## func = (void*)GetProcAddress(hSnmpapi, #func); \
39     if(!p ## func) \
40       trace("GetProcAddress(%s) failed\n", #func);
41
42     SNMPAPI_GET_PROC(SnmpUtilAsnAnyCpy)
43     SNMPAPI_GET_PROC(SnmpUtilAsnAnyFree)
44     SNMPAPI_GET_PROC(SnmpUtilOctetsCmp)
45     SNMPAPI_GET_PROC(SnmpUtilOctetsCpy)
46     SNMPAPI_GET_PROC(SnmpUtilOctetsFree)
47     SNMPAPI_GET_PROC(SnmpUtilOctetsNCmp)
48
49 #undef SNMPAPI_GET_PROC
50 }
51
52 static void test_SnmpUtilOidToA(void)
53 {
54     LPSTR ret;
55     static UINT ids1[] = { 1,3,6,1,4,1,311 };
56     static UINT ids2[] = {
57           1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
58           1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
59           1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
60           1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
61           1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
62           1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
63           1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
64           1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
65           1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 };
66     static UINT ids3[] = { 0xffffffff };
67     static AsnObjectIdentifier oid0 = { 0, ids1 };
68     static AsnObjectIdentifier oid1 = { 7, ids1 };
69     static AsnObjectIdentifier oid2 = { 256, ids2 };
70     static AsnObjectIdentifier oid3 = { 257, ids2 };
71     static AsnObjectIdentifier oid4 = { 258, ids2 };
72     static AsnObjectIdentifier oid5 = { 1, ids3 };
73     static const char expect0[] = "<null oid>";
74     static const char expect0_alt[] = "NUL";
75     static const char expect1[] = "1.3.6.1.4.1.311";
76     static const char expect2[] =
77         "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
78         "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
79         "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
80         "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
81         "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
82         "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
83         "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
84         "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1";
85     static const char expect3[] =
86         "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
87         "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
88         "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
89         "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
90         "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
91         "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
92         "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
93         "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1";
94     static const char expect3_alt[] =
95         "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
96         "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
97         "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
98         "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
99         "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
100         "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
101         "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
102         "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1";
103     static const char expect4[] = "-1";
104
105     /* This crashes under win98 */
106     if(0)
107     {
108         ret = SnmpUtilOidToA(NULL);
109         ok(ret != NULL, "SnmpUtilOidToA failed\n");
110         ok(!strcmp(ret, expect0), "SnmpUtilOidToA failed got\n%s\n expected\n%s\n",
111            ret, expect1);
112     }
113
114     ret = SnmpUtilOidToA(&oid0);
115     ok(ret != NULL, "SnmpUtilOidToA failed\n");
116     ok(!strcmp(ret, expect0) ||
117        broken(!strcmp(ret, expect0_alt)), /* Win98, WinMe, NT4 */
118        "SnmpUtilOidToA failed got\n%s\n expected\n%s\n",
119        ret, expect0);
120
121     ret = SnmpUtilOidToA(&oid1);
122     ok(ret != NULL, "SnmpUtilOidToA failed\n");
123     ok(!strcmp(ret, expect1), "SnmpUtilOidToA failed got\n%s\n expected\n%s\n",
124        ret, expect1);
125
126     ret = SnmpUtilOidToA(&oid2);
127     ok(ret != NULL, "SnmpUtilOidToA failed\n");
128     ok(!strcmp(ret, expect2), "SnmpUtilOidToA failed got\n%s\n expected\n%s\n",
129        ret, expect2);
130
131     ret = SnmpUtilOidToA(&oid3);
132     ok(ret != NULL, "SnmpUtilOidToA failed\n");
133     ok(!strcmp(ret, expect3), "SnmpUtilOidToA failed got\n%s\n expected\n%s\n",
134        ret, expect3);
135
136     ret = SnmpUtilOidToA(&oid4);
137     ok(ret != NULL, "SnmpUtilOidToA failed\n");
138     ok(!strcmp(ret, expect3) ||
139        broken(!strcmp(ret, expect3_alt)), /* Win98, WinMe, NT4 */
140        "SnmpUtilOidToA failed got\n%s\n expected\n%s\n",
141        ret, expect3);
142
143     ret = SnmpUtilOidToA(&oid5);
144     ok(ret != NULL, "SnmpUtilOidToA failed\n");
145     ok(!strcmp(ret, expect4), "SnmpUtilOidToA failed got\n%s\n expected\n%s\n",
146        ret, expect4);
147 }
148
149 static void test_SnmpUtilAsnAnyCpyFree(void)
150 {
151     INT ret;
152     static AsnAny dst, src = { ASN_INTEGER, { 1 } };
153
154     if (0) { /* these crash on XP */
155     ret = pSnmpUtilAsnAnyCpy(NULL, NULL);
156     ok(!ret, "SnmpUtilAsnAnyCpy succeeded\n");
157
158     ret = pSnmpUtilAsnAnyCpy(&dst, NULL);
159     ok(!ret, "SnmpUtilAsnAnyCpy succeeded\n");
160
161     ret = pSnmpUtilAsnAnyCpy(NULL, &src);
162     ok(!ret, "SnmpUtilAsnAnyCpy succeeded\n");
163     }
164
165     ret = pSnmpUtilAsnAnyCpy(&dst, &src);
166     ok(ret, "SnmpUtilAsnAnyCpy failed\n");
167     ok(!memcmp(&src, &dst, sizeof(AsnAny)), "SnmpUtilAsnAnyCpy failed\n");
168
169     if (0) { /* crashes on XP */
170     pSnmpUtilAsnAnyFree(NULL);
171     }
172     pSnmpUtilAsnAnyFree(&dst);
173     ok(dst.asnType == ASN_NULL, "SnmpUtilAsnAnyFree failed\n");
174     ok(dst.asnValue.number == 1, "SnmpUtilAsnAnyFree failed\n");
175 }
176
177 static void test_SnmpUtilOctetsCpyFree(void)
178 {
179     INT ret;
180     static BYTE stream[] = { '1', '2', '3', '4' };
181     static AsnOctetString dst, src = { stream, 4, TRUE };
182
183     ret = pSnmpUtilOctetsCpy(NULL, NULL);
184     ok(!ret, "SnmpUtilOctetsCpy succeeded\n");
185
186     memset(&dst, 1, sizeof(AsnOctetString));
187     ret = pSnmpUtilOctetsCpy(&dst, NULL);
188     ok(ret, "SnmpUtilOctetsCpy failed\n");
189     ok(dst.length == 0, "SnmpUtilOctetsCpy failed\n");
190     ok(dst.stream == NULL, "SnmpUtilOctetsCpy failed\n");
191     ok(dst.dynamic == FALSE, "SnmpUtilOctetsCpy failed\n");
192
193     ret = pSnmpUtilOctetsCpy(NULL, &src);
194     ok(!ret, "SnmpUtilOctetsCpy succeeded\n");
195
196     memset(&dst, 0, sizeof(AsnOctetString));
197     ret = pSnmpUtilOctetsCpy(&dst, &src);
198     ok(ret, "SnmpUtilOctetsCpy failed\n");
199     ok(src.length == dst.length, "SnmpUtilOctetsCpy failed\n");
200     ok(!memcmp(src.stream, dst.stream, dst.length), "SnmpUtilOctetsCpy failed\n");
201     ok(dst.dynamic == TRUE, "SnmpUtilOctetsCpy failed\n");
202
203     pSnmpUtilOctetsFree(NULL);
204     pSnmpUtilOctetsFree(&dst);
205     ok(dst.stream == NULL, "SnmpUtilOctetsFree failed\n");
206     ok(dst.length == 0, "SnmpUtilOctetsFree failed\n");
207     ok(dst.dynamic == FALSE, "SnmpUtilOctetsFree failed\n");
208 }
209
210 static void test_SnmpUtilOidCpyFree(void)
211 {
212     INT ret;
213     static UINT ids[] = { 1, 3, 6, 1, 4, 1, 311 };
214     static AsnObjectIdentifier dst, src = { sizeof(ids) / sizeof(ids[0]), ids };
215
216     /* These crashes under win98 */
217     if(0)
218     {
219         ret = SnmpUtilOidCpy(NULL, NULL);
220         ok(!ret, "SnmpUtilOidCpy succeeded\n");
221
222         memset(&dst, 1, sizeof(AsnObjectIdentifier));
223         ret = SnmpUtilOidCpy(&dst, NULL);
224         ok(ret, "SnmpUtilOidCpy failed\n");
225         ok(dst.idLength == 0, "SnmpUtilOidCpy failed\n");
226         ok(dst.ids == NULL, "SnmpUtilOidCpy failed\n");
227
228         ret = SnmpUtilOidCpy(NULL, &src);
229         ok(!ret, "SnmpUtilOidCpy succeeded\n");
230     }
231
232     memset(&dst, 0, sizeof(AsnObjectIdentifier));
233     ret = SnmpUtilOidCpy(&dst, &src);
234     ok(ret, "SnmpUtilOidCpy failed\n");
235     ok(src.idLength == dst.idLength, "SnmpUtilOidCpy failed\n");
236     ok(!memcmp(src.ids, dst.ids, dst.idLength * sizeof(UINT)), "SnmpUtilOidCpy failed\n");
237     SnmpUtilOidFree(&dst);
238
239     /* These crashes under win98 */
240     if(0)
241     {
242         ret = SnmpUtilOidCpy(NULL, NULL);
243         ok(!ret, "SnmpUtilOidCpy succeeded\n");
244
245         memset(&dst, 1, sizeof(AsnObjectIdentifier));
246         ret = SnmpUtilOidCpy(&dst, NULL);
247         ok(ret, "SnmpUtilOidCpy failed\n");
248         ok(dst.idLength == 0, "SnmpUtilOidCpy failed\n");
249         ok(dst.ids == NULL, "SnmpUtilOidCpy failed\n");
250
251         ret = SnmpUtilOidCpy(NULL, &src);
252         ok(!ret, "SnmpUtilOidCpy succeeded\n");
253     }
254
255     memset(&dst, 0, sizeof(AsnObjectIdentifier));
256     ret = SnmpUtilOidCpy(&dst, &src);
257     ok(ret, "SnmpUtilOidCpy failed\n");
258     ok(src.idLength == dst.idLength, "SnmpUtilOidCpy failed\n");
259     ok(!memcmp(src.ids, dst.ids, dst.idLength * sizeof(UINT)), "SnmpUtilOidCpy failed\n");
260
261     /* This crashes under win98 */
262     if(0)
263     {
264         SnmpUtilOidFree(NULL);
265     }
266     SnmpUtilOidFree(&dst);
267     ok(dst.idLength == 0, "SnmpUtilOidFree failed\n");
268     ok(dst.ids == NULL, "SnmpUtilOidFree failed\n");
269 }
270
271 static void test_SnmpUtilOctetsNCmp(void)
272 {
273     INT ret;
274     static BYTE stream1[] = { '1', '2', '3', '4' };
275     static BYTE stream2[] = { '5', '6', '7', '8' };
276     static AsnOctetString octets1 = { stream1, 4, FALSE };
277     static AsnOctetString octets2 = { stream2, 4, FALSE };
278
279     ret = pSnmpUtilOctetsNCmp(NULL, NULL, 0);
280     ok(!ret, "SnmpUtilOctetsNCmp succeeded\n");
281
282     ret = pSnmpUtilOctetsNCmp(NULL, NULL, 1);
283     ok(!ret, "SnmpUtilOctetsNCmp succeeded\n");
284
285     ret = pSnmpUtilOctetsNCmp(&octets1, NULL, 0);
286     ok(!ret, "SnmpUtilOctetsNCmp succeeded\n");
287
288     ret = pSnmpUtilOctetsNCmp(&octets1, NULL, 1);
289     ok(!ret, "SnmpUtilOctetsNCmp succeeded\n");
290
291     ret = pSnmpUtilOctetsNCmp(NULL, &octets2, 0);
292     ok(!ret, "SnmpUtilOctetsNCmp succeeded\n");
293
294     ret = pSnmpUtilOctetsNCmp(NULL, &octets2, 1);
295     ok(!ret, "SnmpUtilOctetsNCmp succeeded\n");
296
297     ret = pSnmpUtilOctetsNCmp(&octets1, &octets1, 0);
298     ok(!ret, "SnmpUtilOctetsNCmp failed\n");
299
300     ret = pSnmpUtilOctetsNCmp(&octets1, &octets1, 4);
301     ok(!ret, "SnmpUtilOctetsNCmp failed\n");
302
303     ret = pSnmpUtilOctetsNCmp(&octets1, &octets2, 4);
304     ok(ret == -4, "SnmpUtilOctetsNCmp failed\n");
305
306     ret = pSnmpUtilOctetsNCmp(&octets2, &octets1, 4);
307     ok(ret == 4, "SnmpUtilOctetsNCmp failed\n");
308 }
309
310 static void test_SnmpUtilOctetsCmp(void)
311 {
312     INT ret;
313     static BYTE stream1[] = { '1', '2', '3' };
314     static BYTE stream2[] = { '1', '2', '3', '4' };
315     static AsnOctetString octets1 = { stream1, 3, FALSE };
316     static AsnOctetString octets2 = { stream2, 4, FALSE };
317
318     if (0) { /* these crash on XP */
319     ret = pSnmpUtilOctetsCmp(NULL, NULL);
320     ok(!ret, "SnmpUtilOctetsCmp succeeded\n");
321
322     ret = pSnmpUtilOctetsCmp(&octets1, NULL);
323     ok(!ret, "SnmpUtilOctetsCmp succeeded\n");
324
325     ret = pSnmpUtilOctetsCmp(NULL, &octets2);
326     ok(!ret, "SnmpUtilOctetsCmp succeeded\n");
327     }
328
329     ret = pSnmpUtilOctetsCmp(&octets2, &octets1);
330     ok(ret == 1, "SnmpUtilOctetsCmp failed\n");
331
332     ret = pSnmpUtilOctetsCmp(&octets1, &octets2);
333     ok(ret < 0, "SnmpUtilOctetsCmp failed\n");
334 }
335
336 static void test_SnmpUtilOidNCmp(void)
337 {
338     INT ret;
339     static UINT ids1[] = { 1, 2, 3, 4 };
340     static UINT ids2[] = { 5, 6, 7, 8 };
341     static AsnObjectIdentifier oid1 = { 4, ids1 };
342     static AsnObjectIdentifier oid2 = { 4, ids2 };
343
344     /* This crashes under win98 */
345     if(0)
346     {
347         ret = SnmpUtilOidNCmp(NULL, NULL, 0);
348         ok(!ret, "SnmpUtilOidNCmp succeeded\n");
349
350         ret = SnmpUtilOidNCmp(NULL, NULL, 1);
351         ok(!ret, "SnmpUtilOidNCmp succeeded\n");
352
353         ret = SnmpUtilOidNCmp(&oid1, NULL, 0);
354         ok(!ret, "SnmpUtilOidNCmp succeeded\n");
355
356         ret = SnmpUtilOidNCmp(&oid1, NULL, 1);
357         ok(!ret, "SnmpUtilOidNCmp succeeded\n");
358
359         ret = SnmpUtilOidNCmp(NULL, &oid2, 0);
360         ok(!ret, "SnmpUtilOidNCmp succeeded\n");
361
362         ret = SnmpUtilOidNCmp(NULL, &oid2, 1);
363         ok(!ret, "SnmpUtilOidNCmp succeeded\n");
364     }
365
366     ret = SnmpUtilOidNCmp(&oid1, &oid1, 0);
367     ok(!ret, "SnmpUtilOidNCmp failed\n");
368
369     ret = SnmpUtilOidNCmp(&oid1, &oid1, 4);
370     ok(!ret, "SnmpUtilOidNCmp failed\n");
371
372     ret = SnmpUtilOidNCmp(&oid1, &oid2, 4);
373     ok(ret < 0, "SnmpUtilOidNCmp failed: %d\n", ret);
374
375     ret = SnmpUtilOidNCmp(&oid2, &oid1, 4);
376     ok(ret > 0, "SnmpUtilOidNCmp failed: %d\n", ret);
377
378     oid1.idLength = 3;
379     memcpy(oid1.ids, oid2.ids, sizeof(UINT) * 4);
380     ret = SnmpUtilOidNCmp(&oid1, &oid1, 4);
381     ok(!ret, "SnmpUtilOidNCmp failed: %d\n", ret);
382     ret = SnmpUtilOidNCmp(&oid2, &oid1, 4);
383     ok(ret > 0, "SnmpUtilOidNCmp failed: %d\n", ret);
384     ret = SnmpUtilOidNCmp(&oid1, &oid2, 4);
385     ok(ret < 0, "SnmpUtilOidNCmp failed: %d\n", ret);
386
387     ret = SnmpUtilOidNCmp(&oid1, &oid2, 2);
388     ok(!ret, "SnmpUtilOidNCmp failed: %d\n", ret);
389     ret = SnmpUtilOidNCmp(&oid2, &oid1, 2);
390     ok(!ret, "SnmpUtilOidNCmp failed: %d\n", ret);
391 }
392
393 static void test_SnmpUtilOidCmp(void)
394 {
395     INT ret;
396     static UINT ids1[] = { 1, 2, 3 };
397     static UINT ids2[] = { 1, 2, 3, 4 };
398     static AsnObjectIdentifier oid1 = { 3, ids1 };
399     static AsnObjectIdentifier oid2 = { 4, ids2 };
400
401     if (0) { /* these crash on XP */
402     ret = SnmpUtilOidCmp(NULL, NULL);
403     ok(!ret, "SnmpUtilOidCmp succeeded\n");
404
405     ret = SnmpUtilOidCmp(&oid1, NULL);
406     ok(!ret, "SnmpUtilOidCmp succeeded\n");
407
408     ret = SnmpUtilOidCmp(NULL, &oid2);
409     ok(!ret, "SnmpUtilOidCmp succeeded\n");
410     }
411
412     ret = SnmpUtilOidCmp(&oid2, &oid1);
413     ok(ret > 0, "SnmpUtilOidCmp failed\n");
414
415     ret = SnmpUtilOidCmp(&oid1, &oid2);
416     ok(ret < 0, "SnmpUtilOidCmp failed\n");
417 }
418
419 static void test_SnmpUtilOidAppend(void)
420 {
421     INT ret;
422     UINT *ids1;
423     static UINT ids2[] = { 4, 5, 6 };
424     static AsnObjectIdentifier oid1;
425     static AsnObjectIdentifier oid2 = { 3, ids2 };
426
427     ids1 = SnmpUtilMemAlloc(3 * sizeof(UINT));
428     ids1[0] = 1;
429     ids1[1] = 2;
430     ids1[2] = 3;
431
432     oid1.idLength = 3;
433     oid1.ids = ids1;
434
435     /* This crashes under win98 */
436     if(0)
437     {
438         ret = SnmpUtilOidAppend(NULL, NULL);
439         ok(!ret, "SnmpUtilOidAppend succeeded\n");
440
441         ret = SnmpUtilOidAppend(&oid1, NULL);
442         ok(ret, "SnmpUtilOidAppend failed\n");
443
444         ret = SnmpUtilOidAppend(NULL, &oid2);
445         ok(!ret, "SnmpUtilOidAppend succeeded\n");
446     }
447
448     ret = SnmpUtilOidAppend(&oid1, &oid2);
449     ok(ret, "SnmpUtilOidAppend failed\n");
450     ok(oid1.idLength == 6, "SnmpUtilOidAppend failed\n");
451     ok(!memcmp(&oid1.ids[3], ids2, 3 * sizeof(UINT)),
452        "SnmpUtilOidAppend failed\n");
453
454     SnmpUtilOidFree(&oid1);
455 }
456
457 static void test_SnmpUtilVarBindCpyFree(void)
458 {
459     INT ret;
460     static UINT ids[] = { 1, 3, 6, 1, 4, 1, 311 };
461     static SnmpVarBind dst, src = { { 7, ids }, { ASN_INTEGER, { 1 } } };
462
463     /* This crashes under win98 */
464     if(0)
465     {
466         ret = SnmpUtilVarBindCpy(NULL, NULL);
467         ok(!ret, "SnmpUtilVarBindCpy succeeded\n");
468
469         memset(&dst, 0, sizeof(SnmpVarBind));
470         ret = SnmpUtilVarBindCpy(&dst, NULL);
471         ok(ret, "SnmpUtilVarBindCpy failed\n");
472         ok(dst.name.idLength == 0, "SnmpUtilVarBindCpy failed\n");
473         ok(dst.name.ids == NULL, "SnmpUtilVarBindCpy failed\n");
474         ok(dst.value.asnType == ASN_NULL, "SnmpUtilVarBindCpy failed\n");
475         ok(dst.value.asnValue.number == 0, "SnmpUtilVarBindCpy failed\n");
476
477         ret = SnmpUtilVarBindCpy(NULL, &src);
478         ok(!ret, "SnmpUtilVarBindCpy succeeded\n");
479     }
480
481     memset(&dst, 0, sizeof(SnmpVarBind));
482     ret = SnmpUtilVarBindCpy(&dst, &src);
483     ok(ret, "SnmpUtilVarBindCpy failed\n");
484     ok(src.name.idLength == dst.name.idLength, "SnmpUtilVarBindCpy failed\n");
485     ok(!memcmp(src.name.ids, dst.name.ids, dst.name.idLength * sizeof(UINT)),
486        "SnmpUtilVarBindCpy failed\n");
487     ok(!memcmp(&src.value, &dst.value, sizeof(AsnObjectSyntax)),
488        "SnmpUtilVarBindCpy failed\n");
489
490     /* This crashes under win98 */
491     if(0)
492     {
493         SnmpUtilVarBindFree(NULL);
494     }
495     SnmpUtilVarBindFree(&dst);
496     ok(dst.name.idLength == 0, "SnmpUtilVarBindFree failed\n");
497     ok(dst.name.ids == NULL, "SnmpUtilVarBindFree failed\n");
498     ok(dst.value.asnType == ASN_NULL, "SnmpUtilVarBindFree failed\n");
499     ok(dst.value.asnValue.number == 1, "SnmpUtilVarBindFree failed\n");
500 }
501
502 static void test_SnmpUtilVarBindListCpyFree(void)
503 {
504     INT ret;
505     static UINT ids[] = { 1, 3, 6, 1, 4, 1, 311 };
506     static SnmpVarBind src = { { 7, ids }, { ASN_INTEGER, { 1 } } };
507     static SnmpVarBindList dst_list, src_list = { &src, 1 };
508
509     if (0) { /* these crash on XP */
510     ret = SnmpUtilVarBindListCpy(NULL, NULL);
511     ok(!ret, "SnmpUtilVarBindCpy succeeded\n");
512
513     ret = SnmpUtilVarBindListCpy(NULL, &src_list);
514     ok(!ret, "SnmpUtilVarBindListCpy succeeded\n");
515     }
516
517     /* This crashes under win98 */
518     if(0)
519     {
520         memset(&dst_list, 0xff, sizeof(SnmpVarBindList));
521         ret = SnmpUtilVarBindListCpy(&dst_list, NULL);
522         ok(ret, "SnmpUtilVarBindListCpy failed\n");
523         ok(dst_list.list == NULL, "SnmpUtilVarBindListCpy failed\n");
524         ok(dst_list.len == 0, "SnmpUtilVarBindListCpy failed\n");
525     }
526
527     ret = SnmpUtilVarBindListCpy(&dst_list, &src_list);
528     ok(ret, "SnmpUtilVarBindListCpy failed\n");
529     ok(src_list.len == dst_list.len, "SnmpUtilVarBindListCpy failed\n");
530     ok(src_list.list->name.idLength == dst_list.list->name.idLength,
531        "SnmpUtilVarBindListCpy failed\n");
532     ok(!memcmp(src_list.list->name.ids, dst_list.list->name.ids,
533                dst_list.list->name.idLength * sizeof(UINT)),
534        "SnmpUtilVarBindListCpy failed\n");
535     ok(!memcmp(&src_list.list->value, &dst_list.list->value, sizeof(AsnAny)),
536        "SnmpUtilVarBindListCpy failed\n");
537
538     if (0) { /* crashes on XP */
539     SnmpUtilVarBindListFree(NULL);
540     }
541     SnmpUtilVarBindListFree(&dst_list);
542     ok(dst_list.list == NULL, "SnmpUtilVarBindListFree failed\n");
543     ok(dst_list.len == 0, "SnmpUtilVarBindListFree failed\n");
544 }
545
546 START_TEST(util)
547 {
548     InitFunctionPtrs();
549
550     test_SnmpUtilOidToA();
551
552     if (!pSnmpUtilAsnAnyCpy || !pSnmpUtilAsnAnyFree)
553         win_skip("SnmpUtilAsnAnyCpy and/or SnmpUtilAsnAnyFree not available\n");
554     else
555         test_SnmpUtilAsnAnyCpyFree();
556
557     if (!pSnmpUtilOctetsCpy || !pSnmpUtilOctetsFree)
558         win_skip("SnmpUtilOctetsCpy and/or SnmpUtilOctetsFree not available\n");
559     else
560         test_SnmpUtilOctetsCpyFree();
561
562     test_SnmpUtilOidCpyFree();
563
564     if (!pSnmpUtilOctetsNCmp)
565         win_skip("SnmpUtilOctetsNCmp not available\n");
566     else
567         test_SnmpUtilOctetsNCmp();
568
569     if (!pSnmpUtilOctetsCmp)
570         win_skip("SnmpUtilOctetsCmp not available\n");
571     else
572         test_SnmpUtilOctetsCmp();
573
574     test_SnmpUtilOidCmp();
575     test_SnmpUtilOidNCmp();
576     test_SnmpUtilOidAppend();
577     test_SnmpUtilVarBindCpyFree();
578     test_SnmpUtilVarBindListCpyFree();
579 }