2007-01-22 15:31:00 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2007 Hans Leidekker
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <wine/test.h>
|
|
|
|
|
|
|
|
#include <windef.h>
|
|
|
|
#include <snmp.h>
|
|
|
|
|
2007-08-08 17:58:29 +02:00
|
|
|
static INT (WINAPI *pSnmpUtilAsnAnyCpy)(AsnAny*, AsnAny*);
|
|
|
|
static VOID (WINAPI *pSnmpUtilAsnAnyFree)(AsnAny*);
|
|
|
|
static INT (WINAPI *pSnmpUtilOctetsCmp)(AsnOctetString*, AsnOctetString*);
|
|
|
|
static INT (WINAPI *pSnmpUtilOctetsCpy)(AsnOctetString*, AsnOctetString*);
|
|
|
|
static VOID (WINAPI *pSnmpUtilOctetsFree)(AsnOctetString*);
|
|
|
|
static INT (WINAPI *pSnmpUtilOctetsNCmp)(AsnOctetString*, AsnOctetString*, UINT);
|
|
|
|
|
|
|
|
static void InitFunctionPtrs(void)
|
|
|
|
{
|
2013-10-01 23:26:28 +02:00
|
|
|
HMODULE hSnmpapi = GetModuleHandleA("snmpapi.dll");
|
2007-08-10 13:47:07 +02:00
|
|
|
|
|
|
|
#define SNMPAPI_GET_PROC(func) \
|
|
|
|
p ## func = (void*)GetProcAddress(hSnmpapi, #func); \
|
|
|
|
if(!p ## func) \
|
|
|
|
trace("GetProcAddress(%s) failed\n", #func);
|
|
|
|
|
|
|
|
SNMPAPI_GET_PROC(SnmpUtilAsnAnyCpy)
|
|
|
|
SNMPAPI_GET_PROC(SnmpUtilAsnAnyFree)
|
|
|
|
SNMPAPI_GET_PROC(SnmpUtilOctetsCmp)
|
|
|
|
SNMPAPI_GET_PROC(SnmpUtilOctetsCpy)
|
|
|
|
SNMPAPI_GET_PROC(SnmpUtilOctetsFree)
|
|
|
|
SNMPAPI_GET_PROC(SnmpUtilOctetsNCmp)
|
|
|
|
|
|
|
|
#undef SNMPAPI_GET_PROC
|
2007-08-08 17:58:29 +02:00
|
|
|
}
|
|
|
|
|
2007-01-22 15:31:00 +01:00
|
|
|
static void test_SnmpUtilOidToA(void)
|
|
|
|
{
|
|
|
|
LPSTR ret;
|
|
|
|
static UINT ids1[] = { 1,3,6,1,4,1,311 };
|
|
|
|
static UINT ids2[] = {
|
|
|
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
|
|
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
|
|
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
|
|
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
|
|
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
|
|
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
|
|
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
|
|
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
|
|
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 };
|
|
|
|
static UINT ids3[] = { 0xffffffff };
|
|
|
|
static AsnObjectIdentifier oid0 = { 0, ids1 };
|
|
|
|
static AsnObjectIdentifier oid1 = { 7, ids1 };
|
|
|
|
static AsnObjectIdentifier oid2 = { 256, ids2 };
|
|
|
|
static AsnObjectIdentifier oid3 = { 257, ids2 };
|
|
|
|
static AsnObjectIdentifier oid4 = { 258, ids2 };
|
|
|
|
static AsnObjectIdentifier oid5 = { 1, ids3 };
|
|
|
|
static const char expect0[] = "<null oid>";
|
2008-11-12 12:20:11 +01:00
|
|
|
static const char expect0_alt[] = "NUL";
|
2007-01-22 15:31:00 +01:00
|
|
|
static const char expect1[] = "1.3.6.1.4.1.311";
|
|
|
|
static const char expect2[] =
|
|
|
|
"1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
|
|
|
|
"1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
|
|
|
|
"1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
|
|
|
|
"1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
|
|
|
|
"1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
|
|
|
|
"1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
|
|
|
|
"1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
|
|
|
|
"1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1";
|
|
|
|
static const char expect3[] =
|
|
|
|
"1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
|
|
|
|
"1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
|
|
|
|
"1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
|
|
|
|
"1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
|
|
|
|
"1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
|
|
|
|
"1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
|
|
|
|
"1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
|
|
|
|
"1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1";
|
2008-11-12 12:20:11 +01:00
|
|
|
static const char expect3_alt[] =
|
|
|
|
"1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
|
|
|
|
"1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
|
|
|
|
"1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
|
|
|
|
"1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
|
|
|
|
"1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
|
|
|
|
"1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
|
|
|
|
"1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1."
|
|
|
|
"1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1";
|
2007-01-22 15:31:00 +01:00
|
|
|
static const char expect4[] = "-1";
|
|
|
|
|
2008-06-03 12:08:02 +02:00
|
|
|
/* This crashes under win98 */
|
|
|
|
if(0)
|
|
|
|
{
|
|
|
|
ret = SnmpUtilOidToA(NULL);
|
|
|
|
ok(ret != NULL, "SnmpUtilOidToA failed\n");
|
2009-03-08 23:48:03 +01:00
|
|
|
ok(!strcmp(ret, expect0), "SnmpUtilOidToA failed got\n%s\n expected\n%s\n",
|
2008-06-03 12:08:02 +02:00
|
|
|
ret, expect1);
|
|
|
|
}
|
2007-01-22 15:31:00 +01:00
|
|
|
|
|
|
|
ret = SnmpUtilOidToA(&oid0);
|
|
|
|
ok(ret != NULL, "SnmpUtilOidToA failed\n");
|
2008-11-12 12:20:11 +01:00
|
|
|
ok(!strcmp(ret, expect0) ||
|
|
|
|
broken(!strcmp(ret, expect0_alt)), /* Win98, WinMe, NT4 */
|
2009-03-08 23:48:03 +01:00
|
|
|
"SnmpUtilOidToA failed got\n%s\n expected\n%s\n",
|
2007-01-22 15:31:00 +01:00
|
|
|
ret, expect0);
|
|
|
|
|
|
|
|
ret = SnmpUtilOidToA(&oid1);
|
|
|
|
ok(ret != NULL, "SnmpUtilOidToA failed\n");
|
2009-03-08 23:48:03 +01:00
|
|
|
ok(!strcmp(ret, expect1), "SnmpUtilOidToA failed got\n%s\n expected\n%s\n",
|
2007-01-22 15:31:00 +01:00
|
|
|
ret, expect1);
|
|
|
|
|
|
|
|
ret = SnmpUtilOidToA(&oid2);
|
|
|
|
ok(ret != NULL, "SnmpUtilOidToA failed\n");
|
2009-03-08 23:48:03 +01:00
|
|
|
ok(!strcmp(ret, expect2), "SnmpUtilOidToA failed got\n%s\n expected\n%s\n",
|
2007-01-26 13:07:05 +01:00
|
|
|
ret, expect2);
|
2007-01-22 15:31:00 +01:00
|
|
|
|
|
|
|
ret = SnmpUtilOidToA(&oid3);
|
|
|
|
ok(ret != NULL, "SnmpUtilOidToA failed\n");
|
2009-03-08 23:48:03 +01:00
|
|
|
ok(!strcmp(ret, expect3), "SnmpUtilOidToA failed got\n%s\n expected\n%s\n",
|
2007-01-26 13:07:05 +01:00
|
|
|
ret, expect3);
|
2007-01-22 15:31:00 +01:00
|
|
|
|
|
|
|
ret = SnmpUtilOidToA(&oid4);
|
|
|
|
ok(ret != NULL, "SnmpUtilOidToA failed\n");
|
2008-11-12 12:20:11 +01:00
|
|
|
ok(!strcmp(ret, expect3) ||
|
|
|
|
broken(!strcmp(ret, expect3_alt)), /* Win98, WinMe, NT4 */
|
2009-03-08 23:48:03 +01:00
|
|
|
"SnmpUtilOidToA failed got\n%s\n expected\n%s\n",
|
2007-01-26 13:07:05 +01:00
|
|
|
ret, expect3);
|
2007-01-22 15:31:00 +01:00
|
|
|
|
|
|
|
ret = SnmpUtilOidToA(&oid5);
|
|
|
|
ok(ret != NULL, "SnmpUtilOidToA failed\n");
|
2009-03-08 23:48:03 +01:00
|
|
|
ok(!strcmp(ret, expect4), "SnmpUtilOidToA failed got\n%s\n expected\n%s\n",
|
2007-01-26 13:07:05 +01:00
|
|
|
ret, expect4);
|
2007-01-22 15:31:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_SnmpUtilAsnAnyCpyFree(void)
|
|
|
|
{
|
|
|
|
INT ret;
|
|
|
|
static AsnAny dst, src = { ASN_INTEGER, { 1 } };
|
|
|
|
|
|
|
|
if (0) { /* these crash on XP */
|
2007-08-08 17:58:29 +02:00
|
|
|
ret = pSnmpUtilAsnAnyCpy(NULL, NULL);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(!ret, "SnmpUtilAsnAnyCpy succeeded\n");
|
|
|
|
|
2007-08-08 17:58:29 +02:00
|
|
|
ret = pSnmpUtilAsnAnyCpy(&dst, NULL);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(!ret, "SnmpUtilAsnAnyCpy succeeded\n");
|
|
|
|
|
2007-08-08 17:58:29 +02:00
|
|
|
ret = pSnmpUtilAsnAnyCpy(NULL, &src);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(!ret, "SnmpUtilAsnAnyCpy succeeded\n");
|
|
|
|
}
|
|
|
|
|
2007-08-08 17:58:29 +02:00
|
|
|
ret = pSnmpUtilAsnAnyCpy(&dst, &src);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(ret, "SnmpUtilAsnAnyCpy failed\n");
|
|
|
|
ok(!memcmp(&src, &dst, sizeof(AsnAny)), "SnmpUtilAsnAnyCpy failed\n");
|
|
|
|
|
|
|
|
if (0) { /* crashes on XP */
|
2007-08-08 17:58:29 +02:00
|
|
|
pSnmpUtilAsnAnyFree(NULL);
|
2007-01-22 15:31:00 +01:00
|
|
|
}
|
2007-08-08 17:58:29 +02:00
|
|
|
pSnmpUtilAsnAnyFree(&dst);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(dst.asnType == ASN_NULL, "SnmpUtilAsnAnyFree failed\n");
|
|
|
|
ok(dst.asnValue.number == 1, "SnmpUtilAsnAnyFree failed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_SnmpUtilOctetsCpyFree(void)
|
|
|
|
{
|
|
|
|
INT ret;
|
|
|
|
static BYTE stream[] = { '1', '2', '3', '4' };
|
|
|
|
static AsnOctetString dst, src = { stream, 4, TRUE };
|
|
|
|
|
2007-08-08 17:58:29 +02:00
|
|
|
ret = pSnmpUtilOctetsCpy(NULL, NULL);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(!ret, "SnmpUtilOctetsCpy succeeded\n");
|
|
|
|
|
|
|
|
memset(&dst, 1, sizeof(AsnOctetString));
|
2007-08-08 17:58:29 +02:00
|
|
|
ret = pSnmpUtilOctetsCpy(&dst, NULL);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(ret, "SnmpUtilOctetsCpy failed\n");
|
|
|
|
ok(dst.length == 0, "SnmpUtilOctetsCpy failed\n");
|
|
|
|
ok(dst.stream == NULL, "SnmpUtilOctetsCpy failed\n");
|
|
|
|
ok(dst.dynamic == FALSE, "SnmpUtilOctetsCpy failed\n");
|
|
|
|
|
2007-08-08 17:58:29 +02:00
|
|
|
ret = pSnmpUtilOctetsCpy(NULL, &src);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(!ret, "SnmpUtilOctetsCpy succeeded\n");
|
|
|
|
|
|
|
|
memset(&dst, 0, sizeof(AsnOctetString));
|
2007-08-08 17:58:29 +02:00
|
|
|
ret = pSnmpUtilOctetsCpy(&dst, &src);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(ret, "SnmpUtilOctetsCpy failed\n");
|
|
|
|
ok(src.length == dst.length, "SnmpUtilOctetsCpy failed\n");
|
|
|
|
ok(!memcmp(src.stream, dst.stream, dst.length), "SnmpUtilOctetsCpy failed\n");
|
|
|
|
ok(dst.dynamic == TRUE, "SnmpUtilOctetsCpy failed\n");
|
|
|
|
|
2007-08-08 17:58:29 +02:00
|
|
|
pSnmpUtilOctetsFree(NULL);
|
|
|
|
pSnmpUtilOctetsFree(&dst);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(dst.stream == NULL, "SnmpUtilOctetsFree failed\n");
|
|
|
|
ok(dst.length == 0, "SnmpUtilOctetsFree failed\n");
|
|
|
|
ok(dst.dynamic == FALSE, "SnmpUtilOctetsFree failed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_SnmpUtilOidCpyFree(void)
|
|
|
|
{
|
|
|
|
INT ret;
|
|
|
|
static UINT ids[] = { 1, 3, 6, 1, 4, 1, 311 };
|
2018-05-30 21:15:43 +02:00
|
|
|
static AsnObjectIdentifier dst, src = { ARRAY_SIZE(ids), ids };
|
2007-01-22 15:31:00 +01:00
|
|
|
|
2008-06-03 12:08:02 +02:00
|
|
|
/* These crashes under win98 */
|
|
|
|
if(0)
|
|
|
|
{
|
|
|
|
ret = SnmpUtilOidCpy(NULL, NULL);
|
|
|
|
ok(!ret, "SnmpUtilOidCpy succeeded\n");
|
|
|
|
|
|
|
|
memset(&dst, 1, sizeof(AsnObjectIdentifier));
|
|
|
|
ret = SnmpUtilOidCpy(&dst, NULL);
|
|
|
|
ok(ret, "SnmpUtilOidCpy failed\n");
|
|
|
|
ok(dst.idLength == 0, "SnmpUtilOidCpy failed\n");
|
|
|
|
ok(dst.ids == NULL, "SnmpUtilOidCpy failed\n");
|
|
|
|
|
|
|
|
ret = SnmpUtilOidCpy(NULL, &src);
|
|
|
|
ok(!ret, "SnmpUtilOidCpy succeeded\n");
|
|
|
|
}
|
2007-01-22 15:31:00 +01:00
|
|
|
|
2008-06-03 12:08:02 +02:00
|
|
|
memset(&dst, 0, sizeof(AsnObjectIdentifier));
|
|
|
|
ret = SnmpUtilOidCpy(&dst, &src);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(ret, "SnmpUtilOidCpy failed\n");
|
2008-06-03 12:08:02 +02:00
|
|
|
ok(src.idLength == dst.idLength, "SnmpUtilOidCpy failed\n");
|
|
|
|
ok(!memcmp(src.ids, dst.ids, dst.idLength * sizeof(UINT)), "SnmpUtilOidCpy failed\n");
|
2008-07-19 19:53:54 +02:00
|
|
|
SnmpUtilOidFree(&dst);
|
2007-01-22 15:31:00 +01:00
|
|
|
|
2008-06-03 12:08:02 +02:00
|
|
|
/* These crashes under win98 */
|
|
|
|
if(0)
|
|
|
|
{
|
|
|
|
ret = SnmpUtilOidCpy(NULL, NULL);
|
|
|
|
ok(!ret, "SnmpUtilOidCpy succeeded\n");
|
|
|
|
|
|
|
|
memset(&dst, 1, sizeof(AsnObjectIdentifier));
|
|
|
|
ret = SnmpUtilOidCpy(&dst, NULL);
|
|
|
|
ok(ret, "SnmpUtilOidCpy failed\n");
|
|
|
|
ok(dst.idLength == 0, "SnmpUtilOidCpy failed\n");
|
|
|
|
ok(dst.ids == NULL, "SnmpUtilOidCpy failed\n");
|
|
|
|
|
|
|
|
ret = SnmpUtilOidCpy(NULL, &src);
|
|
|
|
ok(!ret, "SnmpUtilOidCpy succeeded\n");
|
|
|
|
}
|
2007-01-22 15:31:00 +01:00
|
|
|
|
|
|
|
memset(&dst, 0, sizeof(AsnObjectIdentifier));
|
|
|
|
ret = SnmpUtilOidCpy(&dst, &src);
|
|
|
|
ok(ret, "SnmpUtilOidCpy failed\n");
|
|
|
|
ok(src.idLength == dst.idLength, "SnmpUtilOidCpy failed\n");
|
|
|
|
ok(!memcmp(src.ids, dst.ids, dst.idLength * sizeof(UINT)), "SnmpUtilOidCpy failed\n");
|
|
|
|
|
2008-06-03 12:08:02 +02:00
|
|
|
/* This crashes under win98 */
|
|
|
|
if(0)
|
|
|
|
{
|
|
|
|
SnmpUtilOidFree(NULL);
|
|
|
|
}
|
2007-01-22 15:31:00 +01:00
|
|
|
SnmpUtilOidFree(&dst);
|
|
|
|
ok(dst.idLength == 0, "SnmpUtilOidFree failed\n");
|
|
|
|
ok(dst.ids == NULL, "SnmpUtilOidFree failed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_SnmpUtilOctetsNCmp(void)
|
|
|
|
{
|
|
|
|
INT ret;
|
|
|
|
static BYTE stream1[] = { '1', '2', '3', '4' };
|
|
|
|
static BYTE stream2[] = { '5', '6', '7', '8' };
|
|
|
|
static AsnOctetString octets1 = { stream1, 4, FALSE };
|
|
|
|
static AsnOctetString octets2 = { stream2, 4, FALSE };
|
|
|
|
|
2007-08-08 17:58:29 +02:00
|
|
|
ret = pSnmpUtilOctetsNCmp(NULL, NULL, 0);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(!ret, "SnmpUtilOctetsNCmp succeeded\n");
|
|
|
|
|
2007-08-08 17:58:29 +02:00
|
|
|
ret = pSnmpUtilOctetsNCmp(NULL, NULL, 1);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(!ret, "SnmpUtilOctetsNCmp succeeded\n");
|
|
|
|
|
2007-08-08 17:58:29 +02:00
|
|
|
ret = pSnmpUtilOctetsNCmp(&octets1, NULL, 0);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(!ret, "SnmpUtilOctetsNCmp succeeded\n");
|
|
|
|
|
2007-08-08 17:58:29 +02:00
|
|
|
ret = pSnmpUtilOctetsNCmp(&octets1, NULL, 1);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(!ret, "SnmpUtilOctetsNCmp succeeded\n");
|
|
|
|
|
2007-08-08 17:58:29 +02:00
|
|
|
ret = pSnmpUtilOctetsNCmp(NULL, &octets2, 0);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(!ret, "SnmpUtilOctetsNCmp succeeded\n");
|
|
|
|
|
2007-08-08 17:58:29 +02:00
|
|
|
ret = pSnmpUtilOctetsNCmp(NULL, &octets2, 1);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(!ret, "SnmpUtilOctetsNCmp succeeded\n");
|
|
|
|
|
2007-08-08 17:58:29 +02:00
|
|
|
ret = pSnmpUtilOctetsNCmp(&octets1, &octets1, 0);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(!ret, "SnmpUtilOctetsNCmp failed\n");
|
|
|
|
|
2007-08-08 17:58:29 +02:00
|
|
|
ret = pSnmpUtilOctetsNCmp(&octets1, &octets1, 4);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(!ret, "SnmpUtilOctetsNCmp failed\n");
|
|
|
|
|
2007-08-08 17:58:29 +02:00
|
|
|
ret = pSnmpUtilOctetsNCmp(&octets1, &octets2, 4);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(ret == -4, "SnmpUtilOctetsNCmp failed\n");
|
|
|
|
|
2007-08-08 17:58:29 +02:00
|
|
|
ret = pSnmpUtilOctetsNCmp(&octets2, &octets1, 4);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(ret == 4, "SnmpUtilOctetsNCmp failed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_SnmpUtilOctetsCmp(void)
|
|
|
|
{
|
|
|
|
INT ret;
|
|
|
|
static BYTE stream1[] = { '1', '2', '3' };
|
|
|
|
static BYTE stream2[] = { '1', '2', '3', '4' };
|
|
|
|
static AsnOctetString octets1 = { stream1, 3, FALSE };
|
|
|
|
static AsnOctetString octets2 = { stream2, 4, FALSE };
|
|
|
|
|
|
|
|
if (0) { /* these crash on XP */
|
2007-08-08 17:58:29 +02:00
|
|
|
ret = pSnmpUtilOctetsCmp(NULL, NULL);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(!ret, "SnmpUtilOctetsCmp succeeded\n");
|
|
|
|
|
2007-08-08 17:58:29 +02:00
|
|
|
ret = pSnmpUtilOctetsCmp(&octets1, NULL);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(!ret, "SnmpUtilOctetsCmp succeeded\n");
|
|
|
|
|
2007-08-08 17:58:29 +02:00
|
|
|
ret = pSnmpUtilOctetsCmp(NULL, &octets2);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(!ret, "SnmpUtilOctetsCmp succeeded\n");
|
|
|
|
}
|
|
|
|
|
2007-08-08 17:58:29 +02:00
|
|
|
ret = pSnmpUtilOctetsCmp(&octets2, &octets1);
|
2007-01-22 15:31:00 +01:00
|
|
|
ok(ret == 1, "SnmpUtilOctetsCmp failed\n");
|
|
|
|
|
2007-08-08 17:58:29 +02:00
|
|
|
ret = pSnmpUtilOctetsCmp(&octets1, &octets2);
|
2009-02-13 18:38:29 +01:00
|
|
|
ok(ret < 0, "SnmpUtilOctetsCmp failed\n");
|
2007-01-22 15:31:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_SnmpUtilOidNCmp(void)
|
|
|
|
{
|
|
|
|
INT ret;
|
|
|
|
static UINT ids1[] = { 1, 2, 3, 4 };
|
|
|
|
static UINT ids2[] = { 5, 6, 7, 8 };
|
|
|
|
static AsnObjectIdentifier oid1 = { 4, ids1 };
|
|
|
|
static AsnObjectIdentifier oid2 = { 4, ids2 };
|
|
|
|
|
2008-06-03 12:08:02 +02:00
|
|
|
/* This crashes under win98 */
|
|
|
|
if(0)
|
|
|
|
{
|
|
|
|
ret = SnmpUtilOidNCmp(NULL, NULL, 0);
|
|
|
|
ok(!ret, "SnmpUtilOidNCmp succeeded\n");
|
2007-01-22 15:31:00 +01:00
|
|
|
|
2008-06-03 12:08:02 +02:00
|
|
|
ret = SnmpUtilOidNCmp(NULL, NULL, 1);
|
|
|
|
ok(!ret, "SnmpUtilOidNCmp succeeded\n");
|
2007-01-22 15:31:00 +01:00
|
|
|
|
2008-06-03 12:08:02 +02:00
|
|
|
ret = SnmpUtilOidNCmp(&oid1, NULL, 0);
|
|
|
|
ok(!ret, "SnmpUtilOidNCmp succeeded\n");
|
2007-01-22 15:31:00 +01:00
|
|
|
|
2008-06-03 12:08:02 +02:00
|
|
|
ret = SnmpUtilOidNCmp(&oid1, NULL, 1);
|
|
|
|
ok(!ret, "SnmpUtilOidNCmp succeeded\n");
|
2007-01-22 15:31:00 +01:00
|
|
|
|
2008-06-03 12:08:02 +02:00
|
|
|
ret = SnmpUtilOidNCmp(NULL, &oid2, 0);
|
|
|
|
ok(!ret, "SnmpUtilOidNCmp succeeded\n");
|
2007-01-22 15:31:00 +01:00
|
|
|
|
2008-06-03 12:08:02 +02:00
|
|
|
ret = SnmpUtilOidNCmp(NULL, &oid2, 1);
|
|
|
|
ok(!ret, "SnmpUtilOidNCmp succeeded\n");
|
|
|
|
}
|
2007-01-22 15:31:00 +01:00
|
|
|
|
|
|
|
ret = SnmpUtilOidNCmp(&oid1, &oid1, 0);
|
|
|
|
ok(!ret, "SnmpUtilOidNCmp failed\n");
|
|
|
|
|
|
|
|
ret = SnmpUtilOidNCmp(&oid1, &oid1, 4);
|
|
|
|
ok(!ret, "SnmpUtilOidNCmp failed\n");
|
|
|
|
|
|
|
|
ret = SnmpUtilOidNCmp(&oid1, &oid2, 4);
|
2009-02-13 18:38:29 +01:00
|
|
|
ok(ret < 0, "SnmpUtilOidNCmp failed: %d\n", ret);
|
2007-01-22 15:31:00 +01:00
|
|
|
|
|
|
|
ret = SnmpUtilOidNCmp(&oid2, &oid1, 4);
|
2009-02-13 18:38:29 +01:00
|
|
|
ok(ret > 0, "SnmpUtilOidNCmp failed: %d\n", ret);
|
2008-05-17 01:09:11 +02:00
|
|
|
|
|
|
|
oid1.idLength = 3;
|
|
|
|
memcpy(oid1.ids, oid2.ids, sizeof(UINT) * 4);
|
|
|
|
ret = SnmpUtilOidNCmp(&oid1, &oid1, 4);
|
|
|
|
ok(!ret, "SnmpUtilOidNCmp failed: %d\n", ret);
|
|
|
|
ret = SnmpUtilOidNCmp(&oid2, &oid1, 4);
|
2009-02-13 18:38:29 +01:00
|
|
|
ok(ret > 0, "SnmpUtilOidNCmp failed: %d\n", ret);
|
2008-05-17 01:09:11 +02:00
|
|
|
ret = SnmpUtilOidNCmp(&oid1, &oid2, 4);
|
2009-02-13 18:38:29 +01:00
|
|
|
ok(ret < 0, "SnmpUtilOidNCmp failed: %d\n", ret);
|
2008-05-17 01:09:34 +02:00
|
|
|
|
|
|
|
ret = SnmpUtilOidNCmp(&oid1, &oid2, 2);
|
|
|
|
ok(!ret, "SnmpUtilOidNCmp failed: %d\n", ret);
|
|
|
|
ret = SnmpUtilOidNCmp(&oid2, &oid1, 2);
|
|
|
|
ok(!ret, "SnmpUtilOidNCmp failed: %d\n", ret);
|
2007-01-22 15:31:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_SnmpUtilOidCmp(void)
|
|
|
|
{
|
|
|
|
INT ret;
|
|
|
|
static UINT ids1[] = { 1, 2, 3 };
|
|
|
|
static UINT ids2[] = { 1, 2, 3, 4 };
|
|
|
|
static AsnObjectIdentifier oid1 = { 3, ids1 };
|
|
|
|
static AsnObjectIdentifier oid2 = { 4, ids2 };
|
|
|
|
|
|
|
|
if (0) { /* these crash on XP */
|
|
|
|
ret = SnmpUtilOidCmp(NULL, NULL);
|
|
|
|
ok(!ret, "SnmpUtilOidCmp succeeded\n");
|
|
|
|
|
|
|
|
ret = SnmpUtilOidCmp(&oid1, NULL);
|
|
|
|
ok(!ret, "SnmpUtilOidCmp succeeded\n");
|
|
|
|
|
|
|
|
ret = SnmpUtilOidCmp(NULL, &oid2);
|
|
|
|
ok(!ret, "SnmpUtilOidCmp succeeded\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = SnmpUtilOidCmp(&oid2, &oid1);
|
2009-02-13 18:38:29 +01:00
|
|
|
ok(ret > 0, "SnmpUtilOidCmp failed\n");
|
2007-01-22 15:31:00 +01:00
|
|
|
|
|
|
|
ret = SnmpUtilOidCmp(&oid1, &oid2);
|
2009-02-13 18:38:29 +01:00
|
|
|
ok(ret < 0, "SnmpUtilOidCmp failed\n");
|
2007-01-22 15:31:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_SnmpUtilOidAppend(void)
|
|
|
|
{
|
|
|
|
INT ret;
|
2007-11-11 13:34:45 +01:00
|
|
|
UINT *ids1;
|
2007-01-22 15:31:00 +01:00
|
|
|
static UINT ids2[] = { 4, 5, 6 };
|
2007-11-11 13:34:45 +01:00
|
|
|
static AsnObjectIdentifier oid1;
|
2007-01-22 15:31:00 +01:00
|
|
|
static AsnObjectIdentifier oid2 = { 3, ids2 };
|
|
|
|
|
2009-11-24 13:33:28 +01:00
|
|
|
ids1 = SnmpUtilMemAlloc(3 * sizeof(UINT));
|
2007-11-11 13:34:45 +01:00
|
|
|
ids1[0] = 1;
|
|
|
|
ids1[1] = 2;
|
|
|
|
ids1[2] = 3;
|
|
|
|
|
|
|
|
oid1.idLength = 3;
|
|
|
|
oid1.ids = ids1;
|
|
|
|
|
2008-06-03 12:08:02 +02:00
|
|
|
/* This crashes under win98 */
|
|
|
|
if(0)
|
|
|
|
{
|
|
|
|
ret = SnmpUtilOidAppend(NULL, NULL);
|
|
|
|
ok(!ret, "SnmpUtilOidAppend succeeded\n");
|
2007-01-22 15:31:00 +01:00
|
|
|
|
2008-06-03 12:08:02 +02:00
|
|
|
ret = SnmpUtilOidAppend(&oid1, NULL);
|
|
|
|
ok(ret, "SnmpUtilOidAppend failed\n");
|
2007-01-22 15:31:00 +01:00
|
|
|
|
2008-06-03 12:08:02 +02:00
|
|
|
ret = SnmpUtilOidAppend(NULL, &oid2);
|
|
|
|
ok(!ret, "SnmpUtilOidAppend succeeded\n");
|
|
|
|
}
|
2007-01-22 15:31:00 +01:00
|
|
|
|
|
|
|
ret = SnmpUtilOidAppend(&oid1, &oid2);
|
|
|
|
ok(ret, "SnmpUtilOidAppend failed\n");
|
|
|
|
ok(oid1.idLength == 6, "SnmpUtilOidAppend failed\n");
|
|
|
|
ok(!memcmp(&oid1.ids[3], ids2, 3 * sizeof(UINT)),
|
|
|
|
"SnmpUtilOidAppend failed\n");
|
2007-11-11 13:34:45 +01:00
|
|
|
|
2009-11-24 13:33:28 +01:00
|
|
|
SnmpUtilOidFree(&oid1);
|
2007-01-22 15:31:00 +01:00
|
|
|
}
|
|
|
|
|
2007-01-22 15:31:50 +01:00
|
|
|
static void test_SnmpUtilVarBindCpyFree(void)
|
|
|
|
{
|
|
|
|
INT ret;
|
|
|
|
static UINT ids[] = { 1, 3, 6, 1, 4, 1, 311 };
|
|
|
|
static SnmpVarBind dst, src = { { 7, ids }, { ASN_INTEGER, { 1 } } };
|
|
|
|
|
2008-06-03 12:08:02 +02:00
|
|
|
/* This crashes under win98 */
|
|
|
|
if(0)
|
|
|
|
{
|
|
|
|
ret = SnmpUtilVarBindCpy(NULL, NULL);
|
|
|
|
ok(!ret, "SnmpUtilVarBindCpy succeeded\n");
|
|
|
|
|
|
|
|
memset(&dst, 0, sizeof(SnmpVarBind));
|
|
|
|
ret = SnmpUtilVarBindCpy(&dst, NULL);
|
|
|
|
ok(ret, "SnmpUtilVarBindCpy failed\n");
|
|
|
|
ok(dst.name.idLength == 0, "SnmpUtilVarBindCpy failed\n");
|
|
|
|
ok(dst.name.ids == NULL, "SnmpUtilVarBindCpy failed\n");
|
|
|
|
ok(dst.value.asnType == ASN_NULL, "SnmpUtilVarBindCpy failed\n");
|
|
|
|
ok(dst.value.asnValue.number == 0, "SnmpUtilVarBindCpy failed\n");
|
|
|
|
|
|
|
|
ret = SnmpUtilVarBindCpy(NULL, &src);
|
|
|
|
ok(!ret, "SnmpUtilVarBindCpy succeeded\n");
|
|
|
|
}
|
2007-01-22 15:31:50 +01:00
|
|
|
|
|
|
|
memset(&dst, 0, sizeof(SnmpVarBind));
|
|
|
|
ret = SnmpUtilVarBindCpy(&dst, &src);
|
|
|
|
ok(ret, "SnmpUtilVarBindCpy failed\n");
|
|
|
|
ok(src.name.idLength == dst.name.idLength, "SnmpUtilVarBindCpy failed\n");
|
|
|
|
ok(!memcmp(src.name.ids, dst.name.ids, dst.name.idLength * sizeof(UINT)),
|
|
|
|
"SnmpUtilVarBindCpy failed\n");
|
|
|
|
ok(!memcmp(&src.value, &dst.value, sizeof(AsnObjectSyntax)),
|
|
|
|
"SnmpUtilVarBindCpy failed\n");
|
|
|
|
|
2008-06-03 12:08:02 +02:00
|
|
|
/* This crashes under win98 */
|
|
|
|
if(0)
|
|
|
|
{
|
|
|
|
SnmpUtilVarBindFree(NULL);
|
|
|
|
}
|
2007-01-22 15:31:50 +01:00
|
|
|
SnmpUtilVarBindFree(&dst);
|
|
|
|
ok(dst.name.idLength == 0, "SnmpUtilVarBindFree failed\n");
|
|
|
|
ok(dst.name.ids == NULL, "SnmpUtilVarBindFree failed\n");
|
|
|
|
ok(dst.value.asnType == ASN_NULL, "SnmpUtilVarBindFree failed\n");
|
|
|
|
ok(dst.value.asnValue.number == 1, "SnmpUtilVarBindFree failed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_SnmpUtilVarBindListCpyFree(void)
|
|
|
|
{
|
|
|
|
INT ret;
|
|
|
|
static UINT ids[] = { 1, 3, 6, 1, 4, 1, 311 };
|
|
|
|
static SnmpVarBind src = { { 7, ids }, { ASN_INTEGER, { 1 } } };
|
|
|
|
static SnmpVarBindList dst_list, src_list = { &src, 1 };
|
|
|
|
|
|
|
|
if (0) { /* these crash on XP */
|
|
|
|
ret = SnmpUtilVarBindListCpy(NULL, NULL);
|
|
|
|
ok(!ret, "SnmpUtilVarBindCpy succeeded\n");
|
|
|
|
|
|
|
|
ret = SnmpUtilVarBindListCpy(NULL, &src_list);
|
|
|
|
ok(!ret, "SnmpUtilVarBindListCpy succeeded\n");
|
|
|
|
}
|
|
|
|
|
2008-06-03 12:08:02 +02:00
|
|
|
/* This crashes under win98 */
|
|
|
|
if(0)
|
|
|
|
{
|
|
|
|
memset(&dst_list, 0xff, sizeof(SnmpVarBindList));
|
|
|
|
ret = SnmpUtilVarBindListCpy(&dst_list, NULL);
|
|
|
|
ok(ret, "SnmpUtilVarBindListCpy failed\n");
|
|
|
|
ok(dst_list.list == NULL, "SnmpUtilVarBindListCpy failed\n");
|
|
|
|
ok(dst_list.len == 0, "SnmpUtilVarBindListCpy failed\n");
|
|
|
|
}
|
2007-01-22 15:31:50 +01:00
|
|
|
|
|
|
|
ret = SnmpUtilVarBindListCpy(&dst_list, &src_list);
|
|
|
|
ok(ret, "SnmpUtilVarBindListCpy failed\n");
|
|
|
|
ok(src_list.len == dst_list.len, "SnmpUtilVarBindListCpy failed\n");
|
|
|
|
ok(src_list.list->name.idLength == dst_list.list->name.idLength,
|
|
|
|
"SnmpUtilVarBindListCpy failed\n");
|
|
|
|
ok(!memcmp(src_list.list->name.ids, dst_list.list->name.ids,
|
|
|
|
dst_list.list->name.idLength * sizeof(UINT)),
|
|
|
|
"SnmpUtilVarBindListCpy failed\n");
|
|
|
|
ok(!memcmp(&src_list.list->value, &dst_list.list->value, sizeof(AsnAny)),
|
|
|
|
"SnmpUtilVarBindListCpy failed\n");
|
|
|
|
|
|
|
|
if (0) { /* crashes on XP */
|
|
|
|
SnmpUtilVarBindListFree(NULL);
|
|
|
|
}
|
|
|
|
SnmpUtilVarBindListFree(&dst_list);
|
|
|
|
ok(dst_list.list == NULL, "SnmpUtilVarBindListFree failed\n");
|
|
|
|
ok(dst_list.len == 0, "SnmpUtilVarBindListFree failed\n");
|
|
|
|
}
|
|
|
|
|
2007-01-22 15:31:00 +01:00
|
|
|
START_TEST(util)
|
|
|
|
{
|
2007-08-08 17:58:29 +02:00
|
|
|
InitFunctionPtrs();
|
|
|
|
|
2007-01-22 15:31:00 +01:00
|
|
|
test_SnmpUtilOidToA();
|
2007-08-08 17:58:29 +02:00
|
|
|
|
|
|
|
if (!pSnmpUtilAsnAnyCpy || !pSnmpUtilAsnAnyFree)
|
2009-02-25 10:29:38 +01:00
|
|
|
win_skip("SnmpUtilAsnAnyCpy and/or SnmpUtilAsnAnyFree not available\n");
|
2007-08-08 17:58:29 +02:00
|
|
|
else
|
|
|
|
test_SnmpUtilAsnAnyCpyFree();
|
|
|
|
|
|
|
|
if (!pSnmpUtilOctetsCpy || !pSnmpUtilOctetsFree)
|
2009-02-25 10:29:38 +01:00
|
|
|
win_skip("SnmpUtilOctetsCpy and/or SnmpUtilOctetsFree not available\n");
|
2007-08-08 17:58:29 +02:00
|
|
|
else
|
|
|
|
test_SnmpUtilOctetsCpyFree();
|
|
|
|
|
2007-01-22 15:31:00 +01:00
|
|
|
test_SnmpUtilOidCpyFree();
|
2007-08-08 17:58:29 +02:00
|
|
|
|
|
|
|
if (!pSnmpUtilOctetsNCmp)
|
2009-02-25 10:29:38 +01:00
|
|
|
win_skip("SnmpUtilOctetsNCmp not available\n");
|
2007-08-08 17:58:29 +02:00
|
|
|
else
|
|
|
|
test_SnmpUtilOctetsNCmp();
|
|
|
|
|
|
|
|
if (!pSnmpUtilOctetsCmp)
|
2009-02-25 10:29:38 +01:00
|
|
|
win_skip("SnmpUtilOctetsCmp not available\n");
|
2007-08-08 17:58:29 +02:00
|
|
|
else
|
|
|
|
test_SnmpUtilOctetsCmp();
|
|
|
|
|
2007-01-22 15:31:00 +01:00
|
|
|
test_SnmpUtilOidCmp();
|
|
|
|
test_SnmpUtilOidNCmp();
|
|
|
|
test_SnmpUtilOidAppend();
|
2007-01-22 15:31:50 +01:00
|
|
|
test_SnmpUtilVarBindCpyFree();
|
|
|
|
test_SnmpUtilVarBindListCpyFree();
|
2007-01-22 15:31:00 +01:00
|
|
|
}
|