提交 861c4a85 编写于 作者: L linghuazaii

Change iniparser_getint64(...) to iniparset_getlongint(...) and add unittest...

Change iniparser_getint64(...) to iniparset_getlongint(...) and add unittest for iniparser_getlongint(...) and also add interface for longint equal in CuTest.h/CuTest.c.
上级 545fde23
......@@ -449,7 +449,7 @@ int iniparser_getint(const dictionary * d, const char * key, int notfound)
handling.
*/
/*--------------------------------------------------------------------------*/
int64_t iniparser_getint64(const dictionary * d, const char * key, int64_t notfound)
int64_t iniparser_getlongint(const dictionary * d, const char * key, int64_t notfound)
{
const char * str ;
......
......@@ -216,7 +216,7 @@ int iniparser_getint(const dictionary * d, const char * key, int notfound);
handling.
*/
/*--------------------------------------------------------------------------*/
int64_t iniparser_getint64(const dictionary * d, const char * key, int64_t notfound);
int64_t iniparser_getlongint(const dictionary * d, const char * key, int64_t notfound);
/*-------------------------------------------------------------------------*/
......
......@@ -211,6 +211,15 @@ void CuAssertIntEquals_LineMsg(CuTest* tc, const char* file, int line, const cha
CuFail_Line(tc, file, line, message, buf);
}
void CuAssertLongIntEquals_LineMsg(CuTest *tc, const char *file, int line, const char *message,
int64_t expected, int64_t actual)
{
char buf[STRING_MAX];
if (expected == actual) return;
sprintf(buf, "expected <%ld> but was <%ld>", expected, actual);
CuFail_Line(tc, file, line, message, buf);
}
void CuAssertDblEquals_LineMsg(CuTest* tc, const char* file, int line, const char* message,
double expected, double actual, double delta)
{
......
......@@ -3,6 +3,7 @@
#include <setjmp.h>
#include <stdarg.h>
#include <stdint.h>
#define CUTEST_VERSION "CuTest 1.5"
......@@ -64,6 +65,9 @@ void CuAssertStrEquals_LineMsg(CuTest* tc,
void CuAssertIntEquals_LineMsg(CuTest* tc,
const char* file, int line, const char* message,
int expected, int actual);
void CuAssertLongIntEquals_LineMsg(CuTest *tc,
const char *file, int line, const char *message,
int64_t expected, int64_t actual);
void CuAssertDblEquals_LineMsg(CuTest* tc,
const char* file, int line, const char* message,
double expected, double actual, double delta);
......@@ -81,6 +85,8 @@ void CuAssertPtrEquals_LineMsg(CuTest* tc,
#define CuAssertStrEquals_Msg(tc,ms,ex,ac) CuAssertStrEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac))
#define CuAssertIntEquals(tc,ex,ac) CuAssertIntEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac))
#define CuAssertIntEquals_Msg(tc,ms,ex,ac) CuAssertIntEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac))
#define CuAssertLongIntEquals(tc,ex,ac) CuAssertLongIntEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac))
#define CuAssertLongIntEquals_Msg(tc,ms,ex,ac) CuAssertLongIntEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac))
#define CuAssertDblEquals(tc,ex,ac,dl) CuAssertDblEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac),(dl))
#define CuAssertDblEquals_Msg(tc,ms,ex,ac,dl) CuAssertDblEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac),(dl))
#define CuAssertPtrEquals(tc,ex,ac) CuAssertPtrEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac))
......
#include <stdio.h>
#include <dirent.h>
#include <unistd.h>
#include <stdint.h>
#include <sys/stat.h>
#include <sys/types.h>
......@@ -337,6 +338,69 @@ void Test_iniparser_getint(CuTest *tc)
dictionary_del(dic);
}
void Test_iniparser_getlongint(CuTest *tc)
{
unsigned i;
char key_name[64];
dictionary *dic;
const struct { int64_t num; const char *value; } good_val[] = {
{ 0, "0" },
{ 1, "1" },
{ -1, "-1" },
{ 1000, "1000" },
{ 077, "077" },
{ -01000, "-01000" },
{ 0x7FFFFFFFFFFFFFFF, "0x7FFFFFFFFFFFFFFF" },
{ -0x7FFFFFFFFFFFFFFF, "-0x7FFFFFFFFFFFFFFF" },
{ 0x4242, "0x4242" },
{ 0, NULL} /* must be last */
};
const char *bad_val[] = {
"",
"notanumber",
"0x",
"k2000",
" ",
"0xG1"
};
/* NULL test */
CuAssertLongIntEquals(tc, -42, iniparser_getlongint(NULL, NULL, -42));
CuAssertLongIntEquals(tc, -42, iniparser_getlongint(NULL, "dummy", -42));
/* Check the def return element */
dic = dictionary_new(10);
CuAssertLongIntEquals(tc, 42, iniparser_getlongint(dic, "dummy", 42));
CuAssertLongIntEquals(tc, 0x7FFFFFFFFFFFFFFF, iniparser_getlongint(dic, NULL, 0x7FFFFFFFFFFFFFFF));
CuAssertLongIntEquals(tc, -0x7FFFFFFFFFFFFFFF, iniparser_getlongint(dic, "dummy", -0x7FFFFFFFFFFFFFFF));
dictionary_del(dic);
/* Generic dictionary */
dic = dictionary_new(10);
for (i = 0; good_val[i].value != NULL; ++i) {
sprintf(key_name, "longint:value%d", i);
dictionary_set(dic, key_name, good_val[i].value);
}
for (i = 0; good_val[i].value != NULL; ++i) {
sprintf(key_name, "longint:value%d", i);
CuAssertLongIntEquals(tc, good_val[i].num,
iniparser_getlongint(dic, key_name, 0));
}
dictionary_del(dic);
/* Test bad names */
dic = dictionary_new(10);
for (i = 0; i < sizeof (bad_val) / sizeof (char *); ++i) {
sprintf(key_name, "longint:bad%d", i);
dictionary_set(dic, key_name, bad_val[i]);
}
for (i = 0; i < sizeof (bad_val) / sizeof (char *); ++i) {
sprintf(key_name, "longint:bad%d", i);
CuAssertLongIntEquals(tc, 0,
iniparser_getlongint(dic, key_name, 0));
}
dictionary_del(dic);
}
void Test_iniparser_getdouble(CuTest *tc)
{
dictionary *dic;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册