2017-12-08 08:12:24 +00:00
|
|
|
#include <qse/cmn/mem.h>
|
|
|
|
#include <qse/cmn/str.h>
|
|
|
|
#include <qse/rad/raddic.h>
|
|
|
|
#include <qse/si/sio.h>
|
2017-12-13 08:21:13 +00:00
|
|
|
#include <string.h>
|
2017-12-26 10:06:00 +00:00
|
|
|
#include <qse/cmn/test.h>
|
2017-12-08 08:12:24 +00:00
|
|
|
|
2017-12-18 06:27:54 +00:00
|
|
|
#if 0
|
|
|
|
#include <qse/rad/radmsg.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2017-12-08 08:12:24 +00:00
|
|
|
#define R(f) \
|
|
|
|
do { \
|
|
|
|
qse_printf (QSE_T("== %s ==\n"), QSE_T(#f)); \
|
2017-12-18 06:27:54 +00:00
|
|
|
if (f() == -1) goto oops; \
|
2017-12-08 08:12:24 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
static int test1 ()
|
2017-12-11 10:02:49 +00:00
|
|
|
{
|
2017-12-08 08:12:24 +00:00
|
|
|
qse_raddic_t* dic;
|
2017-12-26 10:06:00 +00:00
|
|
|
qse_raddic_vendor_t* vendor, * v;
|
2017-12-08 08:12:24 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
dic = qse_raddic_open (QSE_MMGR_GETDFL(), 0);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (dic != QSE_NULL, QSE_T("unable to create a radius dictionary"));
|
2017-12-08 08:12:24 +00:00
|
|
|
|
|
|
|
vendor = qse_raddic_addvendor (dic, QSE_T("abiyo.net"), 12365);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (vendor != QSE_NULL, QSE_T("unable to add the first vendor"));
|
|
|
|
QSE_TESASSERT1 (vendor->vendorpec == 12365, QSE_T("the vendor value is not 12365"));
|
|
|
|
QSE_TESASSERT1 (qse_strcasecmp(vendor->name, QSE_T("abiyo.net")) == 0, QSE_T("the vendor name is not abiyo.net"));
|
2017-12-08 08:12:24 +00:00
|
|
|
|
|
|
|
vendor = qse_raddic_addvendor (dic, QSE_T("abiyo.net"), 99999);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (vendor == QSE_NULL, QSE_T("a duplicate name must not be allowed"));
|
2017-12-08 08:12:24 +00:00
|
|
|
|
|
|
|
vendor = qse_raddic_addvendor (dic, QSE_T("abiyo-aliased.net"), 12365);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (vendor != QSE_NULL, QSE_T("unable to add a duplicate id"));
|
2017-12-08 08:12:24 +00:00
|
|
|
|
|
|
|
vendor = qse_raddic_findvendorbyname (dic, QSE_T("Abiyo.Net"));
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (vendor != QSE_NULL && vendor->vendorpec == 12365, QSE_T("unable to find a vendor named Abiyo.Net"));
|
2017-12-08 08:12:24 +00:00
|
|
|
|
|
|
|
vendor = qse_raddic_findvendorbyvalue (dic, 12365);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (vendor != QSE_NULL && vendor->vendorpec == 12365, QSE_T("unable to find a vendor of value 12365"));
|
|
|
|
QSE_TESASSERT1 (qse_strcasecmp(vendor->name, QSE_T("abiyo-aliased.net")) == 0, QSE_T("unable to find a vendor of value 12365"));
|
2017-12-08 08:12:24 +00:00
|
|
|
|
|
|
|
vendor = qse_raddic_findvendorbyname (dic, QSE_T("Abiyo-aliased.Net"));
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (vendor != QSE_NULL && vendor->vendorpec == 12365, QSE_T("unable to find a vendor named Abiyo-aliased.Net"));
|
|
|
|
QSE_TESASSERT1 (qse_strcasecmp(vendor->name, QSE_T("abiyo-aliased.net")) == 0, QSE_T("unable to find a vendor of value 12365"));
|
2017-12-08 08:12:24 +00:00
|
|
|
|
2017-12-11 08:48:06 +00:00
|
|
|
#define COUNT1 600
|
|
|
|
#define COUNT2 700
|
2017-12-08 08:12:24 +00:00
|
|
|
|
2017-12-11 10:02:49 +00:00
|
|
|
for (i = 1; i < COUNT1; i++)
|
2017-12-08 08:12:24 +00:00
|
|
|
{
|
|
|
|
qse_char_t tmp[64];
|
2017-12-12 07:27:17 +00:00
|
|
|
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test-%d"), i);
|
2017-12-08 08:12:24 +00:00
|
|
|
vendor = qse_raddic_addvendor (dic, tmp, i);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (vendor != QSE_NULL, QSE_T("unable to add a vendor"));
|
|
|
|
QSE_TESASSERT1 (vendor->vendorpec == i, QSE_T("wrong vendor value"));
|
|
|
|
QSE_TESASSERT1 (qse_strcasecmp(vendor->name, tmp) == 0, QSE_T("wrong vendor name"));
|
2017-12-08 08:12:24 +00:00
|
|
|
}
|
|
|
|
|
2017-12-11 10:02:49 +00:00
|
|
|
for (i = 1; i < COUNT1; i++)
|
2017-12-08 08:12:24 +00:00
|
|
|
{
|
|
|
|
qse_char_t tmp[64];
|
2017-12-12 07:27:17 +00:00
|
|
|
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test-%d"), i);
|
2017-12-08 08:12:24 +00:00
|
|
|
vendor = qse_raddic_findvendorbyname (dic, tmp);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (vendor != QSE_NULL, QSE_T("unable to find a vendor"));
|
|
|
|
QSE_TESASSERT1 (vendor->vendorpec == i, QSE_T("wrong vendor value"));
|
|
|
|
QSE_TESASSERT1 (qse_strcasecmp(vendor->name, tmp) == 0, QSE_T("wrong vendor name"));
|
2017-12-08 08:12:24 +00:00
|
|
|
}
|
|
|
|
|
2017-12-11 10:02:49 +00:00
|
|
|
for (i = 1; i < COUNT1; i++)
|
2017-12-08 08:12:24 +00:00
|
|
|
{
|
|
|
|
qse_char_t tmp[64];
|
2017-12-12 07:27:17 +00:00
|
|
|
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test-%d"), i);
|
2017-12-08 08:12:24 +00:00
|
|
|
vendor = qse_raddic_findvendorbyvalue (dic, i);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (vendor != QSE_NULL, QSE_T("unable to find a vendor"));
|
|
|
|
QSE_TESASSERT1 (vendor->vendorpec == i, QSE_T("wrong vendor value"));
|
|
|
|
QSE_TESASSERT1 (qse_strcasecmp(vendor->name, tmp) == 0, QSE_T("wrong vendor name"));
|
2017-12-08 08:12:24 +00:00
|
|
|
}
|
|
|
|
|
2017-12-11 08:48:06 +00:00
|
|
|
for (i = COUNT1; i < COUNT2; i++)
|
|
|
|
{
|
|
|
|
qse_char_t tmp[64];
|
2017-12-12 07:27:17 +00:00
|
|
|
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test-%d"), i);
|
2017-12-11 08:48:06 +00:00
|
|
|
vendor = qse_raddic_addvendor (dic, tmp, COUNT1);
|
|
|
|
// insert different items with the same value
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (vendor != QSE_NULL, QSE_T("unable to add a vendor"));
|
|
|
|
QSE_TESASSERT1 (vendor->vendorpec == COUNT1, QSE_T("wrong vendor value"));
|
|
|
|
QSE_TESASSERT1 (qse_strcasecmp(vendor->name, tmp) == 0, QSE_T("wrong vendor name"));
|
2017-12-11 08:48:06 +00:00
|
|
|
|
|
|
|
v = qse_raddic_findvendorbyvalue (dic, COUNT1);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (vendor == v, QSE_T("unable to find a last added vendor by value"));
|
2017-12-11 08:48:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = COUNT1; i < COUNT2 - 1; i++)
|
|
|
|
{
|
|
|
|
qse_char_t tmp[64];
|
|
|
|
int n;
|
|
|
|
|
2017-12-12 07:27:17 +00:00
|
|
|
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test-%d"), i);
|
2017-12-11 08:48:06 +00:00
|
|
|
|
|
|
|
n = qse_raddic_deletevendorbyname (dic, tmp);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (n == 0, QSE_T("unable to delete a vendor"));
|
2017-12-11 08:48:06 +00:00
|
|
|
|
|
|
|
v = qse_raddic_findvendorbyname (dic, tmp);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (v == QSE_NULL, QSE_T("vendor found errorenously"));
|
2017-12-11 08:48:06 +00:00
|
|
|
|
|
|
|
if (i == COUNT2 - 1)
|
|
|
|
{
|
|
|
|
v = qse_raddic_findvendorbyvalue (dic, COUNT1);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (v == QSE_NULL, QSE_T("vendor of COUNT1 found errorenously"));
|
2017-12-11 08:48:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-12-12 07:27:17 +00:00
|
|
|
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test-%d"), i + 1);
|
2017-12-11 08:48:06 +00:00
|
|
|
v = qse_raddic_findvendorbyname (dic, tmp);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (v != QSE_NULL && v->vendorpec == COUNT1 && qse_strcasecmp(tmp, v->name) == 0, QSE_T("unable to find an expected vendor"));
|
2017-12-11 08:48:06 +00:00
|
|
|
|
|
|
|
v = qse_raddic_findvendorbyvalue (dic, COUNT1);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (v != QSE_NULL && v->vendorpec == COUNT1, QSE_T("unable to find the vendor of COUNT1"));
|
2017-12-11 08:48:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-11 10:02:49 +00:00
|
|
|
for (i = 1; i < COUNT1; i++)
|
2017-12-11 08:48:06 +00:00
|
|
|
{
|
|
|
|
qse_char_t tmp[64];
|
|
|
|
int n;
|
|
|
|
|
2017-12-12 07:27:17 +00:00
|
|
|
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test-%d"), i);
|
2017-12-11 08:48:06 +00:00
|
|
|
n = qse_raddic_deletevendorbyname (dic, tmp);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (n == 0, QSE_T("unable to delete a vendor"));
|
2017-12-11 08:48:06 +00:00
|
|
|
}
|
|
|
|
|
2017-12-11 10:02:49 +00:00
|
|
|
for (i = 1; i < COUNT1; i++)
|
2017-12-11 08:48:06 +00:00
|
|
|
{
|
|
|
|
qse_char_t tmp[64];
|
2017-12-12 07:27:17 +00:00
|
|
|
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test-%d"), i);
|
2017-12-11 08:48:06 +00:00
|
|
|
v = qse_raddic_addvendor (dic, tmp, i);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (v != QSE_NULL && v->vendorpec == i, QSE_T("unable to add a vendor"));
|
2017-12-11 08:48:06 +00:00
|
|
|
|
2017-12-12 07:27:17 +00:00
|
|
|
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("testx-%d"), i);
|
2017-12-11 08:48:06 +00:00
|
|
|
v = qse_raddic_addvendor (dic, tmp, i);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (v != QSE_NULL && v->vendorpec == i, QSE_T("unable to add a vendor"));
|
2017-12-11 08:48:06 +00:00
|
|
|
|
2017-12-12 07:27:17 +00:00
|
|
|
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("testy-%d"), i);
|
2017-12-11 08:48:06 +00:00
|
|
|
v = qse_raddic_addvendor (dic, tmp, i);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (v != QSE_NULL && v->vendorpec == i, QSE_T("unable to add a vendor"));
|
2017-12-11 08:48:06 +00:00
|
|
|
}
|
|
|
|
|
2017-12-11 10:02:49 +00:00
|
|
|
for (i = 1; i < COUNT1; i++)
|
2017-12-11 08:48:06 +00:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
n = qse_raddic_deletevendorbyvalue (dic, i);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (n == 0, QSE_T("unable to delete a vendor by value"));
|
2017-12-11 08:48:06 +00:00
|
|
|
|
|
|
|
n = qse_raddic_deletevendorbyvalue (dic, i);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (n == 0, QSE_T("unable to delete a vendor by value"));
|
2017-12-11 08:48:06 +00:00
|
|
|
|
|
|
|
n = qse_raddic_deletevendorbyvalue (dic, i);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (n == 0, QSE_T("unable to delete a vendor by value"));
|
2017-12-11 08:48:06 +00:00
|
|
|
|
|
|
|
n = qse_raddic_deletevendorbyvalue (dic, i);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (n <= -1, QSE_T("erroreneously successful vendor deletion by value"));
|
2017-12-11 08:48:06 +00:00
|
|
|
}
|
2017-12-11 10:02:49 +00:00
|
|
|
|
|
|
|
qse_raddic_close (dic);
|
|
|
|
return 0;
|
2017-12-18 06:27:54 +00:00
|
|
|
|
|
|
|
oops:
|
|
|
|
if (dic) qse_raddic_close (dic);
|
|
|
|
return -1;
|
2017-12-11 10:02:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int test2 ()
|
|
|
|
{
|
|
|
|
qse_raddic_t* dic;
|
2017-12-12 07:27:17 +00:00
|
|
|
qse_raddic_attr_t* attr;
|
2017-12-11 10:02:49 +00:00
|
|
|
qse_raddic_attr_flags_t f;
|
2017-12-12 07:27:17 +00:00
|
|
|
qse_raddic_const_t* con;
|
2017-12-11 10:02:49 +00:00
|
|
|
int i, j;
|
|
|
|
|
|
|
|
dic = qse_raddic_open (QSE_MMGR_GETDFL(), 0);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (dic != QSE_NULL, QSE_T("unable to create a radius dictionary"));
|
2017-12-11 10:02:49 +00:00
|
|
|
|
2017-12-12 07:27:17 +00:00
|
|
|
memset (&f, 0, QSE_SIZEOF(f));
|
|
|
|
|
2017-12-11 10:02:49 +00:00
|
|
|
for (j = 0; j < 100; j++)
|
|
|
|
{
|
|
|
|
for (i = 0; i <= 255; i++)
|
|
|
|
{
|
|
|
|
qse_char_t tmp[64];
|
2017-12-12 07:27:17 +00:00
|
|
|
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test-%d-%d"), j, i);
|
2017-12-14 10:02:44 +00:00
|
|
|
attr = qse_raddic_addattr (dic, tmp, j, QSE_RADDIC_ATTR_TYPE_UINT32, i, &f);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (attr != QSE_NULL, QSE_T("unable to add an attribute"));
|
|
|
|
QSE_TESASSERT1 (attr->attr == QSE_RADDIC_ATTR_MAKE(j, i), QSE_T("wrong attr value"));
|
|
|
|
QSE_TESASSERT1 (qse_strcasecmp(attr->name, tmp) == 0, QSE_T("wrong attr name"));
|
2017-12-11 10:02:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < 100; j++)
|
|
|
|
{
|
|
|
|
for (i = 0; i <= 255; i++)
|
|
|
|
{
|
|
|
|
qse_char_t tmp[64];
|
2017-12-12 07:27:17 +00:00
|
|
|
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test-%d-%d"), j, i);
|
2017-12-11 10:02:49 +00:00
|
|
|
attr = qse_raddic_findattrbyname (dic, tmp);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (attr != QSE_NULL, QSE_T("unable to find an attribute"));
|
|
|
|
QSE_TESASSERT1 (attr->attr == QSE_RADDIC_ATTR_MAKE(j, i), QSE_T("wrong attr value"));
|
|
|
|
QSE_TESASSERT1 (qse_strcasecmp(attr->name, tmp) == 0, QSE_T("wrong attr name"));
|
2017-12-12 03:17:02 +00:00
|
|
|
|
|
|
|
attr = qse_raddic_findattrbyvalue (dic, QSE_RADDIC_ATTR_MAKE(j, i));
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (attr != QSE_NULL, QSE_T("unable to find an attribute"));
|
|
|
|
QSE_TESASSERT1 (attr->attr == QSE_RADDIC_ATTR_MAKE(j, i), QSE_T("wrong attr value"));
|
|
|
|
QSE_TESASSERT1 (qse_strcasecmp(attr->name, tmp) == 0, QSE_T("wrong attr name"));
|
2017-12-11 10:02:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-12 03:17:02 +00:00
|
|
|
for (j = 0; j < 100; j++)
|
2017-12-11 10:02:49 +00:00
|
|
|
{
|
2017-12-12 03:17:02 +00:00
|
|
|
for (i = 0; i <= 255; i++)
|
|
|
|
{
|
|
|
|
qse_char_t tmp[64];
|
2017-12-12 07:27:17 +00:00
|
|
|
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("testx-%d-%d"), j, i);
|
2017-12-14 10:02:44 +00:00
|
|
|
attr = qse_raddic_addattr (dic, tmp, j, QSE_RADDIC_ATTR_TYPE_UINT32, i, &f);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (attr != QSE_NULL, QSE_T("unable to add an attribute"));
|
|
|
|
QSE_TESASSERT1 (attr->attr == QSE_RADDIC_ATTR_MAKE(j, i), QSE_T("wrong attr value"));
|
|
|
|
QSE_TESASSERT1 (qse_strcasecmp(attr->name, tmp) == 0, QSE_T("wrong attr name"));
|
2017-12-12 03:17:02 +00:00
|
|
|
|
2017-12-12 07:27:17 +00:00
|
|
|
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("testy-%d-%d"), j, i);
|
2017-12-14 10:02:44 +00:00
|
|
|
attr = qse_raddic_addattr (dic, tmp, j, QSE_RADDIC_ATTR_TYPE_UINT32, i, &f);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (attr != QSE_NULL, QSE_T("unable to add an attribute"));
|
|
|
|
QSE_TESASSERT1 (attr->attr == QSE_RADDIC_ATTR_MAKE(j, i), QSE_T("wrong attr value"));
|
|
|
|
QSE_TESASSERT1 (qse_strcasecmp(attr->name, tmp) == 0, QSE_T("wrong attr name"));
|
2017-12-12 03:17:02 +00:00
|
|
|
}
|
2017-12-11 10:02:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-12 03:17:02 +00:00
|
|
|
for (j = 0; j < 100; j++)
|
2017-12-11 10:02:49 +00:00
|
|
|
{
|
2017-12-12 03:17:02 +00:00
|
|
|
for (i = 0; i <= 255; i++)
|
|
|
|
{
|
|
|
|
qse_char_t tmp[64], tmpx[64], tmpy[64];
|
2017-12-12 07:27:17 +00:00
|
|
|
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test-%d-%d"), j, i);
|
|
|
|
qse_strxfmt(tmpx, QSE_COUNTOF(tmpx), QSE_T("testx-%d-%d"), j, i);
|
|
|
|
qse_strxfmt(tmpy, QSE_COUNTOF(tmpy), QSE_T("testy-%d-%d"), j, i);
|
2017-12-11 10:02:49 +00:00
|
|
|
|
2017-12-12 03:17:02 +00:00
|
|
|
attr = qse_raddic_findattrbyname (dic, tmp);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (attr != QSE_NULL, QSE_T("unable to add an attribute"));
|
|
|
|
QSE_TESASSERT1 (attr->attr == QSE_RADDIC_ATTR_MAKE(j, i), QSE_T("wrong attr value"));
|
|
|
|
QSE_TESASSERT1 (qse_strcasecmp(attr->name, tmp) == 0, QSE_T("wrong attr name"));
|
2017-12-11 10:02:49 +00:00
|
|
|
|
2017-12-12 03:17:02 +00:00
|
|
|
attr = qse_raddic_findattrbyname (dic, tmpx);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (attr != QSE_NULL, QSE_T("unable to add an attribute"));
|
|
|
|
QSE_TESASSERT1 (attr->attr == QSE_RADDIC_ATTR_MAKE(j, i), QSE_T("wrong attr value"));
|
|
|
|
QSE_TESASSERT1 (qse_strcasecmp(attr->name, tmpx) == 0, QSE_T("wrong attr name"));
|
2017-12-11 10:02:49 +00:00
|
|
|
|
2017-12-12 03:17:02 +00:00
|
|
|
attr = qse_raddic_findattrbyname (dic, tmpy);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (attr != QSE_NULL, QSE_T("unable to add an attribute"));
|
|
|
|
QSE_TESASSERT1 (attr->attr == QSE_RADDIC_ATTR_MAKE(j, i), QSE_T("wrong attr value"));
|
|
|
|
QSE_TESASSERT1 (qse_strcasecmp(attr->name, tmpy) == 0, QSE_T("wrong attr name"));
|
2017-12-11 10:02:49 +00:00
|
|
|
|
2017-12-12 03:17:02 +00:00
|
|
|
attr = qse_raddic_findattrbyvalue (dic, QSE_RADDIC_ATTR_MAKE(j, i));
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (attr != QSE_NULL, QSE_T("unable to add an attribute"));
|
|
|
|
QSE_TESASSERT1 (attr->attr == QSE_RADDIC_ATTR_MAKE(j, i), QSE_T("wrong attr value"));
|
|
|
|
QSE_TESASSERT1 (qse_strcasecmp(attr->name, tmpy) == 0, QSE_T("wrong attr name"));
|
2017-12-11 10:02:49 +00:00
|
|
|
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (attr->nexta != QSE_NULL, QSE_T("unable to find an old attribute"));
|
|
|
|
QSE_TESASSERT1 (attr->nexta->attr == QSE_RADDIC_ATTR_MAKE(j, i), QSE_T("wrong attr value"));
|
|
|
|
QSE_TESASSERT1 (qse_strcasecmp(attr->nexta->name, tmpx) == 0, QSE_T("wrong attr name"));
|
2017-12-11 10:02:49 +00:00
|
|
|
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (attr->nexta->nexta != QSE_NULL, QSE_T("unable to find an old attribute"));
|
|
|
|
QSE_TESASSERT1 (attr->nexta->nexta->attr == QSE_RADDIC_ATTR_MAKE(j, i), QSE_T("wrong attr value"));
|
|
|
|
QSE_TESASSERT1 (qse_strcasecmp(attr->nexta->nexta->name, tmp) == 0, QSE_T("wrong attr name"));
|
2017-12-11 10:02:49 +00:00
|
|
|
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (attr->nexta->nexta->nexta == QSE_NULL, QSE_T("wrong attribute chian"));
|
2017-12-11 10:02:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-12 03:17:02 +00:00
|
|
|
for (j = 0; j < 100; j++)
|
2017-12-11 10:02:49 +00:00
|
|
|
{
|
2017-12-12 03:17:02 +00:00
|
|
|
for (i = 0; i <= 255; i++)
|
|
|
|
{
|
|
|
|
qse_char_t tmp[64];
|
|
|
|
int n;
|
2017-12-11 10:02:49 +00:00
|
|
|
|
2017-12-12 07:27:17 +00:00
|
|
|
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("testx-%d-%d"), j, i);
|
2017-12-12 03:17:02 +00:00
|
|
|
n = qse_raddic_deleteattrbyname (dic, tmp);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (n == 0, QSE_T("erroreneous attribute deletion failure by name"));
|
2017-12-12 03:17:02 +00:00
|
|
|
}
|
2017-12-11 10:02:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-12 03:17:02 +00:00
|
|
|
for (j = 0; j < 100; j++)
|
2017-12-11 10:02:49 +00:00
|
|
|
{
|
2017-12-12 03:17:02 +00:00
|
|
|
for (i = 0; i <= 255; i++)
|
|
|
|
{
|
|
|
|
qse_char_t tmp[64], tmpx[64], tmpy[64];
|
2017-12-12 07:27:17 +00:00
|
|
|
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test-%d-%d"), j, i);
|
|
|
|
qse_strxfmt(tmpx, QSE_COUNTOF(tmpx), QSE_T("testx-%d-%d"), j, i);
|
|
|
|
qse_strxfmt(tmpy, QSE_COUNTOF(tmpy), QSE_T("testy-%d-%d"), j, i);
|
2017-12-11 10:02:49 +00:00
|
|
|
|
2017-12-12 03:17:02 +00:00
|
|
|
attr = qse_raddic_findattrbyname (dic, tmp);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (attr != QSE_NULL, QSE_T("unable to add an attribute"));
|
|
|
|
QSE_TESASSERT1 (attr->attr == QSE_RADDIC_ATTR_MAKE(j, i), QSE_T("wrong attr value"));
|
|
|
|
QSE_TESASSERT1 (qse_strcasecmp(attr->name, tmp) == 0, QSE_T("wrong attr name"));
|
2017-12-11 10:02:49 +00:00
|
|
|
|
2017-12-12 03:17:02 +00:00
|
|
|
attr = qse_raddic_findattrbyname (dic, tmpx);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (attr == QSE_NULL, QSE_T("erroneous search success"));
|
2017-12-12 03:17:02 +00:00
|
|
|
|
|
|
|
attr = qse_raddic_findattrbyname (dic, tmpy);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (attr != QSE_NULL, QSE_T("unable to add an attribute"));
|
|
|
|
QSE_TESASSERT1 (attr->attr == QSE_RADDIC_ATTR_MAKE(j, i), QSE_T("wrong attr value"));
|
|
|
|
QSE_TESASSERT1 (qse_strcasecmp(attr->name, tmpy) == 0, QSE_T("wrong attr name"));
|
2017-12-12 03:17:02 +00:00
|
|
|
|
|
|
|
attr = qse_raddic_findattrbyvalue (dic, QSE_RADDIC_ATTR_MAKE(j, i));
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (attr != QSE_NULL, QSE_T("unable to add an attribute"));
|
|
|
|
QSE_TESASSERT1 (attr->attr == QSE_RADDIC_ATTR_MAKE(j, i), QSE_T("wrong attr value"));
|
|
|
|
QSE_TESASSERT1 (qse_strcasecmp(attr->name, tmpy) == 0, QSE_T("wrong attr name"));
|
2017-12-12 03:17:02 +00:00
|
|
|
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (attr->nexta != QSE_NULL, QSE_T("unable to find an old attribute"));
|
|
|
|
QSE_TESASSERT1 (attr->nexta->attr == QSE_RADDIC_ATTR_MAKE(j, i), QSE_T("wrong attr value"));
|
|
|
|
QSE_TESASSERT1 (qse_strcasecmp(attr->nexta->name, tmp) == 0, QSE_T("wrong attr name"));
|
2017-12-12 03:17:02 +00:00
|
|
|
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (attr->nexta->nexta == QSE_NULL, QSE_T("wrong attribute chian"));
|
2017-12-12 03:17:02 +00:00
|
|
|
}
|
2017-12-11 10:02:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-12 03:17:02 +00:00
|
|
|
|
2017-12-11 10:02:49 +00:00
|
|
|
{
|
|
|
|
int n;
|
2017-12-12 03:17:02 +00:00
|
|
|
n = qse_raddic_deleteattrbyvalue (dic, QSE_RADDIC_ATTR_MAKE(0, 0));
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (n == 0, QSE_T("erroneous deletion failure by value"));
|
2017-12-11 10:02:49 +00:00
|
|
|
|
2017-12-12 03:17:02 +00:00
|
|
|
n = qse_raddic_deleteattrbyvalue (dic, QSE_RADDIC_ATTR_MAKE(0, 0));
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (n == 0, QSE_T("erroneous deletion failure by value"));
|
2017-12-11 10:02:49 +00:00
|
|
|
|
2017-12-12 03:17:02 +00:00
|
|
|
n = qse_raddic_deleteattrbyvalue (dic, QSE_RADDIC_ATTR_MAKE(0, 0));
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (n <= -1, QSE_T("erroneous deletion success by value"));
|
2017-12-11 10:02:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-12 07:27:17 +00:00
|
|
|
|
|
|
|
for (j = 1; j < 100; j++)
|
|
|
|
{
|
|
|
|
for (i = 1; i <= 255; i++)
|
|
|
|
{
|
|
|
|
qse_char_t constr[64], attrstr[64];
|
2017-12-14 10:02:44 +00:00
|
|
|
|
2017-12-12 07:27:17 +00:00
|
|
|
qse_strxfmt(attrstr, QSE_COUNTOF(attrstr), QSE_T("test-%d-%d"), j, i);
|
|
|
|
qse_strxfmt(constr, QSE_COUNTOF(constr), QSE_T("const-%d-%d"), j, i);
|
2017-12-18 06:27:54 +00:00
|
|
|
con = qse_raddic_addconst (dic, constr, attrstr, 10);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT2 (con != QSE_NULL, QSE_T("unable to add an constant"), qse_raddic_geterrmsg(dic));
|
|
|
|
QSE_TESASSERT1 (con->value == 10, QSE_T("wrong constant value"));
|
|
|
|
QSE_TESASSERT1 (qse_strcasecmp(con->name, constr) == 0, QSE_T("wrong constant name"));
|
2017-12-12 07:27:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 1; j < 100; j++)
|
|
|
|
{
|
|
|
|
for (i = 1; i <= 255; i++)
|
|
|
|
{
|
|
|
|
qse_char_t constr[64];
|
2017-12-14 10:02:44 +00:00
|
|
|
|
2017-12-12 07:27:17 +00:00
|
|
|
qse_strxfmt(constr, QSE_COUNTOF(constr), QSE_T("const-%d-%d"), j, i);
|
|
|
|
|
|
|
|
con = qse_raddic_findconstbyname (dic, QSE_RADDIC_ATTR_MAKE(j, i), constr);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (con != QSE_NULL, QSE_T("unable to find an constant"));
|
|
|
|
QSE_TESASSERT1 (con->attr == QSE_RADDIC_ATTR_MAKE(j, i), QSE_T("wrong constant value"));
|
|
|
|
QSE_TESASSERT1 (con->value == 10, QSE_T("wrong constant value"));
|
2017-12-12 07:27:17 +00:00
|
|
|
|
2017-12-18 06:27:54 +00:00
|
|
|
con = qse_raddic_findconstbyvalue (dic, QSE_RADDIC_ATTR_MAKE(j, i), 10);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (con != QSE_NULL, QSE_T("unable to find an constant"));
|
|
|
|
QSE_TESASSERT1 (con->value == 10, QSE_T("wrong constant value"));
|
|
|
|
QSE_TESASSERT1 (con->attr == QSE_RADDIC_ATTR_MAKE(j, i), QSE_T("wrong constant value"));
|
2017-12-12 07:27:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
int n;
|
2017-12-14 10:02:44 +00:00
|
|
|
|
2017-12-12 07:27:17 +00:00
|
|
|
n = qse_raddic_deleteconstbyname (dic, QSE_RADDIC_ATTR_MAKE(1,1), QSE_T("const-1-1"));
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (n == 0, QSE_T("erroneous constant deletion failure"));
|
2017-12-12 07:27:17 +00:00
|
|
|
|
|
|
|
n = qse_raddic_deleteconstbyname (dic, QSE_RADDIC_ATTR_MAKE(1,1), QSE_T("const-1-1"));
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (n <= -1, QSE_T("erroneous constant deletion success"));
|
2017-12-12 07:27:17 +00:00
|
|
|
|
2017-12-18 06:27:54 +00:00
|
|
|
n = qse_raddic_deleteconstbyvalue (dic, QSE_RADDIC_ATTR_MAKE(2,2), 20);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (n <= -1, QSE_T("erroneous constant deletion success"));
|
2017-12-12 07:27:17 +00:00
|
|
|
|
2017-12-18 06:27:54 +00:00
|
|
|
n = qse_raddic_deleteconstbyvalue (dic, QSE_RADDIC_ATTR_MAKE(2,2), 10);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (n == 0, QSE_T("erroneous constant deletion success"));
|
2017-12-12 07:27:17 +00:00
|
|
|
|
2017-12-18 06:27:54 +00:00
|
|
|
n = qse_raddic_deleteconstbyvalue (dic, QSE_RADDIC_ATTR_MAKE(2,2), 10);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (n <= -1, QSE_T("erroneous constant deletion success"));
|
2017-12-12 07:27:17 +00:00
|
|
|
}
|
|
|
|
|
2017-12-08 08:12:24 +00:00
|
|
|
qse_raddic_close (dic);
|
|
|
|
return 0;
|
2017-12-18 06:27:54 +00:00
|
|
|
|
|
|
|
oops:
|
|
|
|
if (dic) qse_raddic_close (dic);
|
|
|
|
return -1;
|
2017-12-08 08:12:24 +00:00
|
|
|
}
|
|
|
|
|
2017-12-13 08:21:13 +00:00
|
|
|
static int test3 ()
|
|
|
|
{
|
|
|
|
qse_raddic_t* dic;
|
2017-12-14 10:02:44 +00:00
|
|
|
qse_raddic_vendor_t* v;
|
|
|
|
qse_raddic_const_t* c;
|
2017-12-13 08:21:13 +00:00
|
|
|
int n, trait;
|
|
|
|
|
|
|
|
dic = qse_raddic_open (QSE_MMGR_GETDFL(), 0);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (dic != QSE_NULL, QSE_T("unable to create a radius dictionary"));
|
2017-12-13 08:21:13 +00:00
|
|
|
|
2017-12-14 04:08:10 +00:00
|
|
|
trait = QSE_RADDIC_ALLOW_CONST_WITHOUT_ATTR | QSE_RADDIC_ALLOW_DUPLICATE_CONST;
|
2017-12-13 08:21:13 +00:00
|
|
|
n = qse_raddic_setopt (dic, QSE_RADDIC_TRAIT, &trait);
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (n == 0, QSE_T("cannot set trait"));
|
2017-12-13 08:21:13 +00:00
|
|
|
|
2017-12-18 06:27:54 +00:00
|
|
|
n = qse_raddic_load (dic, QSE_T("fr/dictionary"));
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT2 (n == 0, QSE_T("unabled to load dictionary"), qse_raddic_geterrmsg(dic));
|
2017-12-13 08:21:13 +00:00
|
|
|
|
2017-12-14 10:02:44 +00:00
|
|
|
v = qse_raddic_findvendorbyname (dic, QSE_T("cisco"));
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (v && v->vendorpec == 9, "wrong vendor value");
|
2017-12-14 10:02:44 +00:00
|
|
|
|
|
|
|
c = qse_raddic_findconstbyname (dic, QSE_RADDIC_ATTR_MAKE(0,49), QSE_T("Reauthentication-Failure"));
|
2017-12-26 10:06:00 +00:00
|
|
|
QSE_TESASSERT1 (c && c->value == 20, QSE_T("wrong constant value"));
|
2017-12-14 10:02:44 +00:00
|
|
|
|
2017-12-13 08:21:13 +00:00
|
|
|
qse_raddic_close (dic);
|
|
|
|
return 0;
|
2017-12-18 06:27:54 +00:00
|
|
|
|
|
|
|
oops:
|
|
|
|
if (dic) qse_raddic_close (dic);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static int test10()
|
|
|
|
{
|
|
|
|
struct sockaddr_in sin;
|
|
|
|
int s;
|
|
|
|
char buf[10000];
|
|
|
|
|
|
|
|
if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) return -1;
|
|
|
|
|
|
|
|
memset (&sin, 0, sizeof(sin));
|
|
|
|
sin.sin_family = AF_INET;
|
|
|
|
sin.sin_addr.s_addr = inet_addr("192.168.1.2");
|
|
|
|
sin.sin_port = htons(1812);
|
|
|
|
|
|
|
|
qse_rad_initialize (buf, QSE_RAD_ACCESS_REQUEST, 99);
|
|
|
|
qse_rad_insert_extended_vendor_specific_attribute (buf, sizeof(buf), 243, 12345, 5, "xxxxxx", 6);
|
|
|
|
|
|
|
|
sendto (s, buf, ntohs(((qse_rad_hdr_t*)buf)->length), 0, &sin, sizeof(sin));
|
|
|
|
|
|
|
|
close (s);
|
|
|
|
return 0;
|
2017-12-13 08:21:13 +00:00
|
|
|
}
|
2017-12-18 06:27:54 +00:00
|
|
|
#endif
|
2017-12-13 08:21:13 +00:00
|
|
|
|
2017-12-08 08:12:24 +00:00
|
|
|
int main ()
|
|
|
|
{
|
|
|
|
qse_open_stdsios ();
|
2017-12-18 06:27:54 +00:00
|
|
|
|
2017-12-08 08:12:24 +00:00
|
|
|
R (test1);
|
2017-12-11 10:02:49 +00:00
|
|
|
R (test2);
|
2017-12-13 08:21:13 +00:00
|
|
|
R (test3);
|
2017-12-18 06:27:54 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
R (test10);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
oops:
|
2017-12-08 08:12:24 +00:00
|
|
|
qse_close_stdsios ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|