测试用例框架——C语言
目录1 宏定义
static int TestNum = 0;
static int PassNum = 0;
static int FaildNum = 0;
2 初始化函数
void InitNum(void) {
TestNum = 0;
PassNum = 0;
FaildNum = 0;
}
3 测试的结果函数
void TestResult(void) {
printf("Print test result;\n");
printf("TestNum = %d, PassNum = %d, FaildNum = %d\n", TestNum, PassNum, FaildNum);
}
4 状态测试函数
OP_STATUS StatusTest(OP_STATUS Status1, OP_STATUS Status2) {
TestNum++;
printf("StatusTest:\n");
if (Status1 == Status2) {
printf("Test succeed!\n");
PassNum++;
return SUCCESS;
} else {
printf("%s test faild!\n", __func__);
FaildNum++;
return ERROR;
}
}
5 字符串的比较函数
int StrCopmare(const char *Str1, const char *Str2) {
char *TraStr1 = Str1;
char *TraStr2 = Str2;
int ret;
int Str1Len = StringLen(Str1);
int Str2Len = StringLen(Str2);
printf("StrCopmare start\n");
printf("Str1 = %s\n", Str1);
printf("Str2 = %s\n", Str2);
while (*TraStr1 != '\0' || *TraStr2 != '\0') {
if (*TraStr1 == *TraStr2) {
TraStr1++;
TraStr2++;
} else {
break;
}
}
if (*TraStr1 == '\0' && *TraStr2 == '\0' && Str1Len == Str2Len) {
ret = 0;
goto EXIT;
}
if (*TraStr1 == '\0' && Str1Len < Str2Len) {
ret = -1;
goto EXIT;
}
if (*TraStr1 != '\0' && *TraStr2 != '\0' && *TraStr1 < *TraStr2) {
ret = -1;
goto EXIT;
}
ret = 1;
EXIT:
printf("ret = %d\n", ret);
printf("StrCopmare end\n");
return ret;
}
void StringCompareTest(const char *TestStr1, const char *NewStrRep) {
int Res;
char *TraTestStr1 = TestStr1;
char *TraNewStrRep = NewStrRep;
Res = StrCopmare(TraTestStr1, TraNewStrRep);
if (Res == 0) {
printf("%s test succeed!\n", __func__);
PassNum++;
return SUCCESS;
}
else {
printf("%s test faild!\n", __func__);
FaildNum++;
return ERROR;
}
}
6 值比较函数
void ValueTest(const unsigned int Value01, const unsigned int Value02) {
if (Value01 == Value02) {
printf("%s test succeed!\n", __func__);
PassNum++;
return SUCCESS;
}
else {
printf("%s test faild!\n", __func__);
FaildNum++;
return ERROR;
}
}
标签:__,框架,int,ret,C语言,char,++,测试用例,printf
From: https://www.cnblogs.com/meditatorss/p/16747723.html