update cutest
This commit is contained in:
parent
4cc709c2a0
commit
dd52b6da67
|
@ -1,3 +1,6 @@
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
|
#endif
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -11,7 +14,7 @@
|
||||||
* CuStr
|
* CuStr
|
||||||
*-------------------------------------------------------------------------*/
|
*-------------------------------------------------------------------------*/
|
||||||
|
|
||||||
char* CuStrAlloc(int size)
|
char* CuStrAlloc(size_t size)
|
||||||
{
|
{
|
||||||
char* newStr = (char*) malloc( sizeof(char) * (size) );
|
char* newStr = (char*) malloc( sizeof(char) * (size) );
|
||||||
return newStr;
|
return newStr;
|
||||||
|
@ -19,7 +22,7 @@ char* CuStrAlloc(int size)
|
||||||
|
|
||||||
char* CuStrCopy(const char* old)
|
char* CuStrCopy(const char* old)
|
||||||
{
|
{
|
||||||
int len = strlen(old);
|
size_t len = strlen(old);
|
||||||
char* newStr = CuStrAlloc(len + 1);
|
char* newStr = CuStrAlloc(len + 1);
|
||||||
strcpy(newStr, old);
|
strcpy(newStr, old);
|
||||||
return newStr;
|
return newStr;
|
||||||
|
@ -54,7 +57,7 @@ void CuStringDelete(CuString *str)
|
||||||
free(str);
|
free(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CuStringResize(CuString* str, int newSize)
|
void CuStringResize(CuString* str, size_t newSize)
|
||||||
{
|
{
|
||||||
str->buffer = (char*) realloc(str->buffer, sizeof(char) * newSize);
|
str->buffer = (char*) realloc(str->buffer, sizeof(char) * newSize);
|
||||||
str->size = newSize;
|
str->size = newSize;
|
||||||
|
@ -62,7 +65,7 @@ void CuStringResize(CuString* str, int newSize)
|
||||||
|
|
||||||
void CuStringAppend(CuString* str, const char* text)
|
void CuStringAppend(CuString* str, const char* text)
|
||||||
{
|
{
|
||||||
int length;
|
size_t length;
|
||||||
|
|
||||||
if (text == NULL) {
|
if (text == NULL) {
|
||||||
text = "NULL";
|
text = "NULL";
|
||||||
|
@ -93,9 +96,9 @@ void CuStringAppendFormat(CuString* str, const char* format, ...)
|
||||||
CuStringAppend(str, buf);
|
CuStringAppend(str, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CuStringInsert(CuString* str, const char* text, int pos)
|
void CuStringInsert(CuString* str, const char* text, size_t pos)
|
||||||
{
|
{
|
||||||
int length = strlen(text);
|
size_t length = strlen(text);
|
||||||
if (pos > str->length)
|
if (pos > str->length)
|
||||||
pos = str->length;
|
pos = str->length;
|
||||||
if (str->length + length + 1 >= str->size)
|
if (str->length + length + 1 >= str->size)
|
||||||
|
@ -129,6 +132,7 @@ CuTest* CuTestNew(const char* name, TestFunction function)
|
||||||
void CuTestDelete(CuTest *t)
|
void CuTestDelete(CuTest *t)
|
||||||
{
|
{
|
||||||
if (!t) return;
|
if (!t) return;
|
||||||
|
CuStringDelete(t->message);
|
||||||
free(t->name);
|
free(t->name);
|
||||||
free(t);
|
free(t);
|
||||||
}
|
}
|
||||||
|
@ -153,7 +157,9 @@ static void CuFailInternal(CuTest* tc, const char* file, int line, CuString* str
|
||||||
CuStringInsert(string, buf, 0);
|
CuStringInsert(string, buf, 0);
|
||||||
|
|
||||||
tc->failed = 1;
|
tc->failed = 1;
|
||||||
tc->message = string->buffer;
|
free(tc->message);
|
||||||
|
tc->message = CuStringNew();
|
||||||
|
CuStringAppend(tc->message, string->buffer);
|
||||||
if (tc->jumpBuf != 0) longjmp(*(tc->jumpBuf), 0);
|
if (tc->jumpBuf != 0) longjmp(*(tc->jumpBuf), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,7 +333,7 @@ void CuSuiteDetails(CuSuite* testSuite, CuString* details)
|
||||||
{
|
{
|
||||||
failCount++;
|
failCount++;
|
||||||
CuStringAppendFormat(details, "%d) %s: %s\n",
|
CuStringAppendFormat(details, "%d) %s: %s\n",
|
||||||
failCount, testCase->name, testCase->message);
|
failCount, testCase->name, testCase->message->buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CuStringAppend(details, "\n!!!FAILURES!!!\n");
|
CuStringAppend(details, "\n!!!FAILURES!!!\n");
|
||||||
|
|
|
@ -3,12 +3,13 @@
|
||||||
|
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#define CUTEST_VERSION "CuTest 1.5"
|
#define CUTEST_VERSION "CuTest 1.5c"
|
||||||
|
|
||||||
/* CuString */
|
/* CuString */
|
||||||
|
|
||||||
char* CuStrAlloc(int size);
|
char* CuStrAlloc(size_t size);
|
||||||
char* CuStrCopy(const char* old);
|
char* CuStrCopy(const char* old);
|
||||||
|
|
||||||
#define CU_ALLOC(TYPE) ((TYPE*) malloc(sizeof(TYPE)))
|
#define CU_ALLOC(TYPE) ((TYPE*) malloc(sizeof(TYPE)))
|
||||||
|
@ -19,8 +20,8 @@ char* CuStrCopy(const char* old);
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int length;
|
size_t length;
|
||||||
int size;
|
size_t size;
|
||||||
char* buffer;
|
char* buffer;
|
||||||
} CuString;
|
} CuString;
|
||||||
|
|
||||||
|
@ -30,8 +31,8 @@ void CuStringRead(CuString* str, const char* path);
|
||||||
void CuStringAppend(CuString* str, const char* text);
|
void CuStringAppend(CuString* str, const char* text);
|
||||||
void CuStringAppendChar(CuString* str, char ch);
|
void CuStringAppendChar(CuString* str, char ch);
|
||||||
void CuStringAppendFormat(CuString* str, const char* format, ...);
|
void CuStringAppendFormat(CuString* str, const char* format, ...);
|
||||||
void CuStringInsert(CuString* str, const char* text, int pos);
|
void CuStringInsert(CuString* str, const char* text, size_t pos);
|
||||||
void CuStringResize(CuString* str, int newSize);
|
void CuStringResize(CuString* str, size_t newSize);
|
||||||
void CuStringDelete(CuString* str);
|
void CuStringDelete(CuString* str);
|
||||||
|
|
||||||
/* CuTest */
|
/* CuTest */
|
||||||
|
@ -46,7 +47,7 @@ struct CuTest
|
||||||
TestFunction function;
|
TestFunction function;
|
||||||
int failed;
|
int failed;
|
||||||
int ran;
|
int ran;
|
||||||
const char* message;
|
CuString *message;
|
||||||
jmp_buf *jumpBuf;
|
jmp_buf *jumpBuf;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -86,8 +87,8 @@ void CuAssertPtrEquals_LineMsg(CuTest* tc,
|
||||||
#define CuAssertPtrEquals(tc,ex,ac) CuAssertPtrEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac))
|
#define CuAssertPtrEquals(tc,ex,ac) CuAssertPtrEquals_LineMsg((tc),__FILE__,__LINE__,NULL,(ex),(ac))
|
||||||
#define CuAssertPtrEquals_Msg(tc,ms,ex,ac) CuAssertPtrEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac))
|
#define CuAssertPtrEquals_Msg(tc,ms,ex,ac) CuAssertPtrEquals_LineMsg((tc),__FILE__,__LINE__,(ms),(ex),(ac))
|
||||||
|
|
||||||
#define CuAssertPtrNotNull(tc,p) CuAssert_Line((tc),__FILE__,__LINE__,"null pointer unexpected",(p != NULL))
|
#define CuAssertPtrNotNull(tc,p) CuAssert_Line((tc),__FILE__,__LINE__,"null pointer unexpected",((p) != NULL))
|
||||||
#define CuAssertPtrNotNullMsg(tc,msg,p) CuAssert_Line((tc),__FILE__,__LINE__,(msg),(p != NULL))
|
#define CuAssertPtrNotNullMsg(tc,msg,p) CuAssert_Line((tc),__FILE__,__LINE__,(msg),((p) != NULL))
|
||||||
|
|
||||||
/* CuSuite */
|
/* CuSuite */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue