inetmib1: Implement SnmpExtensionQuery.
[wine/hacks.git] / dlls / inetmib1 / tests / main.c
blob6e4627e6ff4f908e8b6c75ccb58f206dd8ce5060
1 /*
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
18 #include <stdio.h>
19 #include <stdarg.h>
20 #include <windef.h>
21 #include <winbase.h>
22 #include <snmp.h>
24 #include "wine/test.h"
26 static HMODULE inetmib1;
28 static void testInit(void)
30 BOOL (WINAPI *pInit)(DWORD, HANDLE *, AsnObjectIdentifier *);
31 BOOL ret;
32 HANDLE event;
33 AsnObjectIdentifier oid;
35 pInit = (void *)GetProcAddress(inetmib1, "SnmpExtensionInit");
36 if (!pInit)
38 skip("no SnmpExtensionInit\n");
39 return;
41 /* Crash
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 *,
55 AsnInteger32 *);
56 BOOL ret, moreData;
57 SnmpVarBindList list;
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");
66 if (!pQuery)
68 skip("couldn't find SnmpExtensionQuery\n");
69 return;
71 /* Crash
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 */
80 list.len = 0;
81 error = 0xdeadbeef;
82 index = 0xdeadbeef;
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
90 * unsupported.
92 vars[0].name.idLength = sizeof(bogus) / sizeof(bogus[0]);
93 vars[0].name.ids = bogus;
94 vars[0].value.asnType = 0;
95 list.len = 1;
96 list.list = vars;
97 SetLastError(0xdeadbeef);
98 error = 0xdeadbeef;
99 index = 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);
113 error = 0xdeadbeef;
114 index = 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
124 * interface.
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;
130 list.len = 1;
131 list.list = vars2;
132 moreData = TRUE;
133 ret = pQuery(SNMP_PDU_GETNEXT, &list, &error, &index);
134 ok(ret, "SnmpExtensionQuery failed: %d\n", GetLastError());
135 todo_wine {
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]);
147 START_TEST(main)
149 inetmib1 = LoadLibraryA("inetmib1");
150 testInit();
151 testQuery();