2 * Copyright 2007 Hans Leidekker
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.
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.
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
21 #include <wine/test.h>
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
);
33 static void InitFunctionPtrs(void)
35 HMODULE hSnmpapi
= GetModuleHandle("snmpapi.dll");
37 #define SNMPAPI_GET_PROC(func) \
38 p ## func = (void*)GetProcAddress(hSnmpapi, #func); \
40 trace("GetProcAddress(%s) failed\n", #func);
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
)
49 #undef SNMPAPI_GET_PROC
52 static void test_SnmpUtilOidToA(void)
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";
105 /* This crashes under win98 */
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",
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",
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",
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",
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",
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",
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",
149 static void test_SnmpUtilAsnAnyCpyFree(void)
152 static AsnAny dst
, src
= { ASN_INTEGER
, { 1 } };
154 if (0) { /* these crash on XP */
155 ret
= pSnmpUtilAsnAnyCpy(NULL
, NULL
);
156 ok(!ret
, "SnmpUtilAsnAnyCpy succeeded\n");
158 ret
= pSnmpUtilAsnAnyCpy(&dst
, NULL
);
159 ok(!ret
, "SnmpUtilAsnAnyCpy succeeded\n");
161 ret
= pSnmpUtilAsnAnyCpy(NULL
, &src
);
162 ok(!ret
, "SnmpUtilAsnAnyCpy succeeded\n");
165 ret
= pSnmpUtilAsnAnyCpy(&dst
, &src
);
166 ok(ret
, "SnmpUtilAsnAnyCpy failed\n");
167 ok(!memcmp(&src
, &dst
, sizeof(AsnAny
)), "SnmpUtilAsnAnyCpy failed\n");
169 if (0) { /* crashes on XP */
170 pSnmpUtilAsnAnyFree(NULL
);
172 pSnmpUtilAsnAnyFree(&dst
);
173 ok(dst
.asnType
== ASN_NULL
, "SnmpUtilAsnAnyFree failed\n");
174 ok(dst
.asnValue
.number
== 1, "SnmpUtilAsnAnyFree failed\n");
177 static void test_SnmpUtilOctetsCpyFree(void)
180 static BYTE stream
[] = { '1', '2', '3', '4' };
181 static AsnOctetString dst
, src
= { stream
, 4, TRUE
};
183 ret
= pSnmpUtilOctetsCpy(NULL
, NULL
);
184 ok(!ret
, "SnmpUtilOctetsCpy succeeded\n");
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");
193 ret
= pSnmpUtilOctetsCpy(NULL
, &src
);
194 ok(!ret
, "SnmpUtilOctetsCpy succeeded\n");
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");
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");
210 static void test_SnmpUtilOidCpyFree(void)
213 static UINT ids
[] = { 1, 3, 6, 1, 4, 1, 311 };
214 static AsnObjectIdentifier dst
, src
= { sizeof(ids
) / sizeof(ids
[0]), ids
};
216 /* These crashes under win98 */
219 ret
= SnmpUtilOidCpy(NULL
, NULL
);
220 ok(!ret
, "SnmpUtilOidCpy succeeded\n");
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");
228 ret
= SnmpUtilOidCpy(NULL
, &src
);
229 ok(!ret
, "SnmpUtilOidCpy succeeded\n");
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
);
239 /* These crashes under win98 */
242 ret
= SnmpUtilOidCpy(NULL
, NULL
);
243 ok(!ret
, "SnmpUtilOidCpy succeeded\n");
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");
251 ret
= SnmpUtilOidCpy(NULL
, &src
);
252 ok(!ret
, "SnmpUtilOidCpy succeeded\n");
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");
261 /* This crashes under win98 */
264 SnmpUtilOidFree(NULL
);
266 SnmpUtilOidFree(&dst
);
267 ok(dst
.idLength
== 0, "SnmpUtilOidFree failed\n");
268 ok(dst
.ids
== NULL
, "SnmpUtilOidFree failed\n");
271 static void test_SnmpUtilOctetsNCmp(void)
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
};
279 ret
= pSnmpUtilOctetsNCmp(NULL
, NULL
, 0);
280 ok(!ret
, "SnmpUtilOctetsNCmp succeeded\n");
282 ret
= pSnmpUtilOctetsNCmp(NULL
, NULL
, 1);
283 ok(!ret
, "SnmpUtilOctetsNCmp succeeded\n");
285 ret
= pSnmpUtilOctetsNCmp(&octets1
, NULL
, 0);
286 ok(!ret
, "SnmpUtilOctetsNCmp succeeded\n");
288 ret
= pSnmpUtilOctetsNCmp(&octets1
, NULL
, 1);
289 ok(!ret
, "SnmpUtilOctetsNCmp succeeded\n");
291 ret
= pSnmpUtilOctetsNCmp(NULL
, &octets2
, 0);
292 ok(!ret
, "SnmpUtilOctetsNCmp succeeded\n");
294 ret
= pSnmpUtilOctetsNCmp(NULL
, &octets2
, 1);
295 ok(!ret
, "SnmpUtilOctetsNCmp succeeded\n");
297 ret
= pSnmpUtilOctetsNCmp(&octets1
, &octets1
, 0);
298 ok(!ret
, "SnmpUtilOctetsNCmp failed\n");
300 ret
= pSnmpUtilOctetsNCmp(&octets1
, &octets1
, 4);
301 ok(!ret
, "SnmpUtilOctetsNCmp failed\n");
303 ret
= pSnmpUtilOctetsNCmp(&octets1
, &octets2
, 4);
304 ok(ret
== -4, "SnmpUtilOctetsNCmp failed\n");
306 ret
= pSnmpUtilOctetsNCmp(&octets2
, &octets1
, 4);
307 ok(ret
== 4, "SnmpUtilOctetsNCmp failed\n");
310 static void test_SnmpUtilOctetsCmp(void)
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
};
318 if (0) { /* these crash on XP */
319 ret
= pSnmpUtilOctetsCmp(NULL
, NULL
);
320 ok(!ret
, "SnmpUtilOctetsCmp succeeded\n");
322 ret
= pSnmpUtilOctetsCmp(&octets1
, NULL
);
323 ok(!ret
, "SnmpUtilOctetsCmp succeeded\n");
325 ret
= pSnmpUtilOctetsCmp(NULL
, &octets2
);
326 ok(!ret
, "SnmpUtilOctetsCmp succeeded\n");
329 ret
= pSnmpUtilOctetsCmp(&octets2
, &octets1
);
330 ok(ret
== 1, "SnmpUtilOctetsCmp failed\n");
332 ret
= pSnmpUtilOctetsCmp(&octets1
, &octets2
);
333 ok(ret
< 0, "SnmpUtilOctetsCmp failed\n");
336 static void test_SnmpUtilOidNCmp(void)
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
};
344 /* This crashes under win98 */
347 ret
= SnmpUtilOidNCmp(NULL
, NULL
, 0);
348 ok(!ret
, "SnmpUtilOidNCmp succeeded\n");
350 ret
= SnmpUtilOidNCmp(NULL
, NULL
, 1);
351 ok(!ret
, "SnmpUtilOidNCmp succeeded\n");
353 ret
= SnmpUtilOidNCmp(&oid1
, NULL
, 0);
354 ok(!ret
, "SnmpUtilOidNCmp succeeded\n");
356 ret
= SnmpUtilOidNCmp(&oid1
, NULL
, 1);
357 ok(!ret
, "SnmpUtilOidNCmp succeeded\n");
359 ret
= SnmpUtilOidNCmp(NULL
, &oid2
, 0);
360 ok(!ret
, "SnmpUtilOidNCmp succeeded\n");
362 ret
= SnmpUtilOidNCmp(NULL
, &oid2
, 1);
363 ok(!ret
, "SnmpUtilOidNCmp succeeded\n");
366 ret
= SnmpUtilOidNCmp(&oid1
, &oid1
, 0);
367 ok(!ret
, "SnmpUtilOidNCmp failed\n");
369 ret
= SnmpUtilOidNCmp(&oid1
, &oid1
, 4);
370 ok(!ret
, "SnmpUtilOidNCmp failed\n");
372 ret
= SnmpUtilOidNCmp(&oid1
, &oid2
, 4);
373 ok(ret
< 0, "SnmpUtilOidNCmp failed: %d\n", ret
);
375 ret
= SnmpUtilOidNCmp(&oid2
, &oid1
, 4);
376 ok(ret
> 0, "SnmpUtilOidNCmp failed: %d\n", ret
);
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
);
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
);
393 static void test_SnmpUtilOidCmp(void)
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
};
401 if (0) { /* these crash on XP */
402 ret
= SnmpUtilOidCmp(NULL
, NULL
);
403 ok(!ret
, "SnmpUtilOidCmp succeeded\n");
405 ret
= SnmpUtilOidCmp(&oid1
, NULL
);
406 ok(!ret
, "SnmpUtilOidCmp succeeded\n");
408 ret
= SnmpUtilOidCmp(NULL
, &oid2
);
409 ok(!ret
, "SnmpUtilOidCmp succeeded\n");
412 ret
= SnmpUtilOidCmp(&oid2
, &oid1
);
413 ok(ret
> 0, "SnmpUtilOidCmp failed\n");
415 ret
= SnmpUtilOidCmp(&oid1
, &oid2
);
416 ok(ret
< 0, "SnmpUtilOidCmp failed\n");
419 static void test_SnmpUtilOidAppend(void)
423 static UINT ids2
[] = { 4, 5, 6 };
424 static AsnObjectIdentifier oid1
;
425 static AsnObjectIdentifier oid2
= { 3, ids2
};
427 ids1
= SnmpUtilMemAlloc(3 * sizeof(UINT
));
435 /* This crashes under win98 */
438 ret
= SnmpUtilOidAppend(NULL
, NULL
);
439 ok(!ret
, "SnmpUtilOidAppend succeeded\n");
441 ret
= SnmpUtilOidAppend(&oid1
, NULL
);
442 ok(ret
, "SnmpUtilOidAppend failed\n");
444 ret
= SnmpUtilOidAppend(NULL
, &oid2
);
445 ok(!ret
, "SnmpUtilOidAppend succeeded\n");
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");
454 SnmpUtilOidFree(&oid1
);
457 static void test_SnmpUtilVarBindCpyFree(void)
460 static UINT ids
[] = { 1, 3, 6, 1, 4, 1, 311 };
461 static SnmpVarBind dst
, src
= { { 7, ids
}, { ASN_INTEGER
, { 1 } } };
463 /* This crashes under win98 */
466 ret
= SnmpUtilVarBindCpy(NULL
, NULL
);
467 ok(!ret
, "SnmpUtilVarBindCpy succeeded\n");
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");
477 ret
= SnmpUtilVarBindCpy(NULL
, &src
);
478 ok(!ret
, "SnmpUtilVarBindCpy succeeded\n");
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");
490 /* This crashes under win98 */
493 SnmpUtilVarBindFree(NULL
);
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");
502 static void test_SnmpUtilVarBindListCpyFree(void)
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 };
509 if (0) { /* these crash on XP */
510 ret
= SnmpUtilVarBindListCpy(NULL
, NULL
);
511 ok(!ret
, "SnmpUtilVarBindCpy succeeded\n");
513 ret
= SnmpUtilVarBindListCpy(NULL
, &src_list
);
514 ok(!ret
, "SnmpUtilVarBindListCpy succeeded\n");
517 /* This crashes under win98 */
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");
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");
538 if (0) { /* crashes on XP */
539 SnmpUtilVarBindListFree(NULL
);
541 SnmpUtilVarBindListFree(&dst_list
);
542 ok(dst_list
.list
== NULL
, "SnmpUtilVarBindListFree failed\n");
543 ok(dst_list
.len
== 0, "SnmpUtilVarBindListFree failed\n");
550 test_SnmpUtilOidToA();
552 if (!pSnmpUtilAsnAnyCpy
|| !pSnmpUtilAsnAnyFree
)
553 win_skip("SnmpUtilAsnAnyCpy and/or SnmpUtilAsnAnyFree not available\n");
555 test_SnmpUtilAsnAnyCpyFree();
557 if (!pSnmpUtilOctetsCpy
|| !pSnmpUtilOctetsFree
)
558 win_skip("SnmpUtilOctetsCpy and/or SnmpUtilOctetsFree not available\n");
560 test_SnmpUtilOctetsCpyFree();
562 test_SnmpUtilOidCpyFree();
564 if (!pSnmpUtilOctetsNCmp
)
565 win_skip("SnmpUtilOctetsNCmp not available\n");
567 test_SnmpUtilOctetsNCmp();
569 if (!pSnmpUtilOctetsCmp
)
570 win_skip("SnmpUtilOctetsCmp not available\n");
572 test_SnmpUtilOctetsCmp();
574 test_SnmpUtilOidCmp();
575 test_SnmpUtilOidNCmp();
576 test_SnmpUtilOidAppend();
577 test_SnmpUtilVarBindCpyFree();
578 test_SnmpUtilVarBindListCpyFree();