added constant manipulation functions in raddic

This commit is contained in:
hyung-hwan 2017-12-12 07:27:17 +00:00
parent b081c10f83
commit f9970ef086
3 changed files with 740 additions and 1071 deletions

View File

@ -74,13 +74,14 @@ struct qse_raddic_attr_t
qse_char_t name[1];
};
struct qse_raddic_value_t
typedef struct qse_raddic_const_t qse_raddic_const_t;
struct qse_raddic_const_t
{
int attr;
int value;
qse_char_t name[1];
int attr; /* vendor + attribute-value */
int value;
qse_raddic_const_t* nextc;
qse_char_t name[1];
};
typedef struct qse_raddic_value_t qse_raddic_value_t;
typedef struct qse_raddic_vendor_t qse_raddic_vendor_t;
struct qse_raddic_vendor_t
@ -170,6 +171,40 @@ QSE_EXPORT int qse_raddic_deleteattrbyvalue (
int attr
);
QSE_EXPORT qse_raddic_const_t* qse_raddic_findconstbyname (
qse_raddic_t* dic,
int attr,
const qse_char_t* name
);
QSE_EXPORT qse_raddic_const_t* qse_raddic_findconstbyvalue (
qse_raddic_t* dic,
int attr,
int value
);
QSE_EXPORT qse_raddic_const_t* qse_raddic_addconst (
qse_raddic_t* dic,
const qse_char_t* name,
const qse_char_t* attrstr,
int value
);
QSE_EXPORT int qse_raddic_deleteconstbyname (
qse_raddic_t* dic,
int attr,
const qse_char_t* name
);
QSE_EXPORT int qse_raddic_deleteconstbyvalue (
qse_raddic_t* dic,
int attr,
int value
);
#if defined(__cplusplus)
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -51,7 +51,7 @@ static int test1 ()
for (i = 1; i < COUNT1; i++)
{
qse_char_t tmp[64];
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test%d"), i);
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test-%d"), i);
vendor = qse_raddic_addvendor (dic, tmp, i);
_assert (vendor != QSE_NULL, "unable to add a vendor");
_assert (vendor->vendorpec == i, "wrong vendor value");
@ -61,7 +61,7 @@ static int test1 ()
for (i = 1; i < COUNT1; i++)
{
qse_char_t tmp[64];
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test%d"), i);
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test-%d"), i);
vendor = qse_raddic_findvendorbyname (dic, tmp);
_assert (vendor != QSE_NULL, "unable to find a vendor");
_assert (vendor->vendorpec == i, "wrong vendor value");
@ -71,7 +71,7 @@ static int test1 ()
for (i = 1; i < COUNT1; i++)
{
qse_char_t tmp[64];
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test%d"), i);
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test-%d"), i);
vendor = qse_raddic_findvendorbyvalue (dic, i);
_assert (vendor != QSE_NULL, "unable to find a vendor");
_assert (vendor->vendorpec == i, "wrong vendor value");
@ -81,7 +81,7 @@ static int test1 ()
for (i = COUNT1; i < COUNT2; i++)
{
qse_char_t tmp[64];
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test%d"), i);
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test-%d"), i);
vendor = qse_raddic_addvendor (dic, tmp, COUNT1);
// insert different items with the same value
_assert (vendor != QSE_NULL, "unable to add a vendor");
@ -97,7 +97,7 @@ static int test1 ()
qse_char_t tmp[64];
int n;
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test%d"), i);
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test-%d"), i);
n = qse_raddic_deletevendorbyname (dic, tmp);
_assert (n == 0, "unable to delete a vendor");
@ -112,7 +112,7 @@ static int test1 ()
}
else
{
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test%d"), i + 1);
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test-%d"), i + 1);
v = qse_raddic_findvendorbyname (dic, tmp);
_assert (v != QSE_NULL && v->vendorpec == COUNT1 && qse_strcasecmp(tmp, v->name) == 0, "unable to find an expected vendor");
@ -126,7 +126,7 @@ static int test1 ()
qse_char_t tmp[64];
int n;
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test%d"), i);
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test-%d"), i);
n = qse_raddic_deletevendorbyname (dic, tmp);
_assert (n == 0, "unable to delete a vendor");
}
@ -134,15 +134,15 @@ static int test1 ()
for (i = 1; i < COUNT1; i++)
{
qse_char_t tmp[64];
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test%d"), i);
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test-%d"), i);
v = qse_raddic_addvendor (dic, tmp, i);
_assert (v != QSE_NULL && v->vendorpec == i, "unable to add a vendor");
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("testx%d"), i);
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("testx-%d"), i);
v = qse_raddic_addvendor (dic, tmp, i);
_assert (v != QSE_NULL && v->vendorpec == i, "unable to add a vendor");
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("testy%d"), i);
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("testy-%d"), i);
v = qse_raddic_addvendor (dic, tmp, i);
_assert (v != QSE_NULL && v->vendorpec == i, "unable to add a vendor");
}
@ -171,19 +171,22 @@ static int test1 ()
static int test2 ()
{
qse_raddic_t* dic;
qse_raddic_attr_t* attr, * v;
qse_raddic_attr_t* attr;
qse_raddic_attr_flags_t f;
qse_raddic_const_t* con;
int i, j;
dic = qse_raddic_open (QSE_MMGR_GETDFL(), 0);
_assert (dic != QSE_NULL, "unable to create a radius dictionary");
memset (&f, 0, QSE_SIZEOF(f));
for (j = 0; j < 100; j++)
{
for (i = 0; i <= 255; i++)
{
qse_char_t tmp[64];
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test%d-%d"), j, i);
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test-%d-%d"), j, i);
attr = qse_raddic_addattr (dic, tmp, j, QSE_RADDIC_ATTR_TYPE_STRING, i, &f);
_assert (attr != QSE_NULL, "unable to add an attribute");
_assert (attr->attr == QSE_RADDIC_ATTR_MAKE(j, i), "wrong attr value");
@ -196,14 +199,14 @@ static int test2 ()
for (i = 0; i <= 255; i++)
{
qse_char_t tmp[64];
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test%d-%d"), j, i);
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test-%d-%d"), j, i);
attr = qse_raddic_findattrbyname (dic, tmp);
_assert (attr != QSE_NULL, "unable to add an attribute");
_assert (attr != QSE_NULL, "unable to find an attribute");
_assert (attr->attr == QSE_RADDIC_ATTR_MAKE(j, i), "wrong attr value");
_assert (qse_strcasecmp(attr->name, tmp) == 0, "wrong attr name");
attr = qse_raddic_findattrbyvalue (dic, QSE_RADDIC_ATTR_MAKE(j, i));
_assert (attr != QSE_NULL, "unable to add an attribute");
_assert (attr != QSE_NULL, "unable to find an attribute");
_assert (attr->attr == QSE_RADDIC_ATTR_MAKE(j, i), "wrong attr value");
_assert (qse_strcasecmp(attr->name, tmp) == 0, "wrong attr name");
}
@ -214,13 +217,13 @@ static int test2 ()
for (i = 0; i <= 255; i++)
{
qse_char_t tmp[64];
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("testx%d-%d"), j, i);
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("testx-%d-%d"), j, i);
attr = qse_raddic_addattr (dic, tmp, j, QSE_RADDIC_ATTR_TYPE_STRING, i, &f);
_assert (attr != QSE_NULL, "unable to add an attribute");
_assert (attr->attr == QSE_RADDIC_ATTR_MAKE(j, i), "wrong attr value");
_assert (qse_strcasecmp(attr->name, tmp) == 0, "wrong attr name");
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("testy%d-%d"), j, i);
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("testy-%d-%d"), j, i);
attr = qse_raddic_addattr (dic, tmp, j, QSE_RADDIC_ATTR_TYPE_STRING, i, &f);
_assert (attr != QSE_NULL, "unable to add an attribute");
_assert (attr->attr == QSE_RADDIC_ATTR_MAKE(j, i), "wrong attr value");
@ -233,9 +236,9 @@ static int test2 ()
for (i = 0; i <= 255; i++)
{
qse_char_t tmp[64], tmpx[64], tmpy[64];
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);
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);
attr = qse_raddic_findattrbyname (dic, tmp);
_assert (attr != QSE_NULL, "unable to add an attribute");
@ -276,7 +279,7 @@ static int test2 ()
qse_char_t tmp[64];
int n;
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("testx%d-%d"), j, i);
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("testx-%d-%d"), j, i);
n = qse_raddic_deleteattrbyname (dic, tmp);
_assert (n == 0, "erroreneous attribute deletion failure by name");
}
@ -287,9 +290,9 @@ static int test2 ()
for (i = 0; i <= 255; i++)
{
qse_char_t tmp[64], tmpx[64], tmpy[64];
qse_strxfmt(tmp, QSE_COUNTOF(tmp), QSE_T("test%d-%d"), j, i);
qse_strxfmt(tmpy, QSE_COUNTOF(tmpy), QSE_T("testx%d-%d"), j, i);
qse_strxfmt(tmpy, QSE_COUNTOF(tmpy), QSE_T("testy%d-%d"), j, i);
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);
attr = qse_raddic_findattrbyname (dic, tmp);
_assert (attr != QSE_NULL, "unable to add an attribute");
@ -304,7 +307,6 @@ static int test2 ()
_assert (attr->attr == QSE_RADDIC_ATTR_MAKE(j, i), "wrong attr value");
_assert (qse_strcasecmp(attr->name, tmpy) == 0, "wrong attr name");
attr = qse_raddic_findattrbyvalue (dic, QSE_RADDIC_ATTR_MAKE(j, i));
_assert (attr != QSE_NULL, "unable to add an attribute");
_assert (attr->attr == QSE_RADDIC_ATTR_MAKE(j, i), "wrong attr value");
@ -331,6 +333,59 @@ static int test2 ()
_assert (n <= -1, "errorneous deletion success by value");
}
for (j = 1; j < 100; j++)
{
for (i = 1; i <= 255; i++)
{
qse_char_t constr[64], attrstr[64];
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);
con = qse_raddic_addconst (dic, constr, attrstr, 10);
_assert (con != QSE_NULL, "unable to add an constant");
_assert (con->value == 10, "wrong constant value");
_assert (qse_strcasecmp(con->name, constr) == 0, "wrong constant name");
}
}
for (j = 1; j < 100; j++)
{
for (i = 1; i <= 255; i++)
{
qse_char_t constr[64];
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);
_assert (con != QSE_NULL, "unable to find an constant");
_assert (con->attr == QSE_RADDIC_ATTR_MAKE(j, i), "wrong constant value");
_assert (con->value == 10, "wrong constant value");
con = qse_raddic_findconstbyvalue (dic, QSE_RADDIC_ATTR_MAKE(j, i), 10);
_assert (con != QSE_NULL, "unable to find an constant");
_assert (con->value == 10, "wrong constant value");
_assert (con->attr == QSE_RADDIC_ATTR_MAKE(j, i), "wrong constant value");
}
}
{
int n;
n = qse_raddic_deleteconstbyname (dic, QSE_RADDIC_ATTR_MAKE(1,1), QSE_T("const-1-1"));
_assert (n == 0, "errorneous constant deletion failure");
n = qse_raddic_deleteconstbyname (dic, QSE_RADDIC_ATTR_MAKE(1,1), QSE_T("const-1-1"));
_assert (n <= -1, "errorneous constant deletion success");
n = qse_raddic_deleteconstbyvalue (dic, QSE_RADDIC_ATTR_MAKE(2,2), 20);
_assert (n <= -1, "errorneous constant deletion success");
n = qse_raddic_deleteconstbyvalue (dic, QSE_RADDIC_ATTR_MAKE(2,2), 10);
_assert (n == 0, "errorneous constant deletion success");
n = qse_raddic_deleteconstbyvalue (dic, QSE_RADDIC_ATTR_MAKE(2,2), 10);
_assert (n <= -1, "errorneous constant deletion success");
}
qse_raddic_close (dic);
return 0;
}