2 * Copyright 2008 Juan Lang
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
24 #include "wine/test.h"
26 static HMODULE inetmib1
;
28 static void testInit(void)
30 BOOL (WINAPI
*pInit
)(DWORD
, HANDLE
*, AsnObjectIdentifier
*);
33 AsnObjectIdentifier oid
;
35 pInit
= (void *)GetProcAddress(inetmib1
, "SnmpExtensionInit");
38 skip("no SnmpExtensionInit\n");
42 ret = pInit(0, NULL, NULL);
43 ret = pInit(0, NULL, &oid);
44 ret = pInit(0, &event, NULL);
46 ret
= pInit(0, &event
, &oid
);
47 ok(ret
, "SnmpExtensionInit failed: %d\n", GetLastError());
48 ok(!strcmp("1.3.6.1.2.1.1", SnmpUtilOidToA(&oid
)),
49 "Expected 1.3.6.1.2.1.1, got %s\n", SnmpUtilOidToA(&oid
));
52 static void testQuery(void)
54 BOOL (WINAPI
*pQuery
)(BYTE
, SnmpVarBindList
*, AsnInteger32
*,
58 AsnInteger32 error
, index
;
59 UINT bogus
[] = { 1,2,3,4 };
60 UINT mib2System
[] = { 1,3,6,1,2,1,1 };
61 UINT mib2If
[] = { 1,3,6,1,2,1,2 };
62 UINT mib2IfTable
[] = { 1,3,6,1,2,1,2,2 };
63 SnmpVarBind vars
[3], vars2
[3];
65 pQuery
= (void *)GetProcAddress(inetmib1
, "SnmpExtensionQuery");
68 skip("couldn't find SnmpExtensionQuery\n");
72 ret = pQuery(0, NULL, NULL, NULL);
73 ret = pQuery(0, NULL, &error, NULL);
74 ret = pQuery(0, NULL, NULL, &index);
75 ret = pQuery(0, &list, NULL, NULL);
76 ret = pQuery(0, &list, &error, NULL);
79 /* An empty list succeeds */
83 ret
= pQuery(SNMP_PDU_GET
, &list
, &error
, &index
);
84 ok(ret
, "SnmpExtensionQuery failed: %d\n", GetLastError());
85 ok(error
== SNMP_ERRORSTATUS_NOERROR
,
86 "expected SNMP_ERRORSTATUS_NOERROR, got %d\n", error
);
87 ok(index
== 0, "expected index 0, got %d\n", index
);
89 /* Oddly enough, this "succeeds," even though the OID is clearly
92 vars
[0].name
.idLength
= sizeof(bogus
) / sizeof(bogus
[0]);
93 vars
[0].name
.ids
= bogus
;
94 vars
[0].value
.asnType
= 0;
97 SetLastError(0xdeadbeef);
100 ret
= pQuery(SNMP_PDU_GET
, &list
, &error
, &index
);
101 ok(ret
, "SnmpExtensionQuery failed: %d\n", GetLastError());
102 ok(error
== SNMP_ERRORSTATUS_NOERROR
,
103 "expected SNMP_ERRORSTATUS_NOERROR, got %d\n", error
);
104 ok(index
== 0, "expected index 0, got %d\n", index
);
105 /* The OID isn't changed either: */
106 ok(!strcmp("1.2.3.4", SnmpUtilOidToA(&vars
[0].name
)),
107 "expected 1.2.3.4, got %s\n", SnmpUtilOidToA(&vars
[0].name
));
109 /* The table is not an accessible variable, so it fails */
110 vars
[0].name
.idLength
= sizeof(mib2IfTable
) / sizeof(mib2IfTable
[0]);
111 vars
[0].name
.ids
= mib2IfTable
;
112 SetLastError(0xdeadbeef);
115 ret
= pQuery(SNMP_PDU_GET
, &list
, &error
, &index
);
116 ok(ret
, "SnmpExtensionQuery failed: %d\n", GetLastError());
117 ok(error
== SNMP_ERRORSTATUS_NOSUCHNAME
,
118 "expected SNMP_ERRORSTATUS_NOSUCHNAME, got %d\n", error
);
119 /* The index is 1-based rather than 0-based */
120 ok(index
== 1, "expected index 1, got %d\n", index
);
122 /* Even though SnmpExtensionInit says this DLL supports the MIB2 system
123 * variables, the first variable it returns a value for is the first
126 vars
[0].name
.idLength
= sizeof(mib2System
) / sizeof(mib2System
[0]);
127 vars
[0].name
.ids
= mib2System
;
128 SnmpUtilOidCpy(&vars2
[0].name
, &vars
[0].name
);
129 vars2
[0].value
.asnType
= 0;
133 ret
= pQuery(SNMP_PDU_GETNEXT
, &list
, &error
, &index
);
134 ok(ret
, "SnmpExtensionQuery failed: %d\n", GetLastError());
136 ok(error
== SNMP_ERRORSTATUS_NOERROR
,
137 "expected SNMP_ERRORSTATUS_NOERROR, got %d\n", error
);
138 ok(index
== 0, "expected index 0, got %d\n", index
);
140 vars
[0].name
.idLength
= sizeof(mib2If
) / sizeof(mib2If
[0]);
141 vars
[0].name
.ids
= mib2If
;
142 ok(!SnmpUtilOidNCmp(&vars2
[0].name
, &vars
[0].name
, vars
[0].name
.idLength
),
143 "expected 1.3.6.1.2.1.2, got %s\n", SnmpUtilOidToA(&vars2
[0].name
));
144 SnmpUtilVarBindFree(&vars2
[0]);
149 inetmib1
= LoadLibraryA("inetmib1");