mirror of
https://github.com/ennorehling/cutest.git
synced 2024-12-22 07:52:21 +00:00
Upgrade to CuTest version 1.5
This commit is contained in:
parent
457823ff5e
commit
c4e7ef9755
36
CuTest.c
36
CuTest.c
@ -19,7 +19,7 @@ char* CuStrAlloc(int size)
|
|||||||
|
|
||||||
char* CuStrCopy(const char* old)
|
char* CuStrCopy(const char* old)
|
||||||
{
|
{
|
||||||
int len = (int)strlen(old);
|
int len = strlen(old);
|
||||||
char* newStr = CuStrAlloc(len + 1);
|
char* newStr = CuStrAlloc(len + 1);
|
||||||
strcpy(newStr, old);
|
strcpy(newStr, old);
|
||||||
return newStr;
|
return newStr;
|
||||||
@ -47,6 +47,13 @@ CuString* CuStringNew(void)
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CuStringDelete(CuString *str)
|
||||||
|
{
|
||||||
|
if (!str) return;
|
||||||
|
free(str->buffer);
|
||||||
|
free(str);
|
||||||
|
}
|
||||||
|
|
||||||
void CuStringResize(CuString* str, int newSize)
|
void CuStringResize(CuString* str, int newSize)
|
||||||
{
|
{
|
||||||
str->buffer = (char*) realloc(str->buffer, sizeof(char) * newSize);
|
str->buffer = (char*) realloc(str->buffer, sizeof(char) * newSize);
|
||||||
@ -61,7 +68,7 @@ void CuStringAppend(CuString* str, const char* text)
|
|||||||
text = "NULL";
|
text = "NULL";
|
||||||
}
|
}
|
||||||
|
|
||||||
length = (int)strlen(text);
|
length = strlen(text);
|
||||||
if (str->length + length + 1 >= str->size)
|
if (str->length + length + 1 >= str->size)
|
||||||
CuStringResize(str, str->length + length + 1 + STRING_INC);
|
CuStringResize(str, str->length + length + 1 + STRING_INC);
|
||||||
str->length += length;
|
str->length += length;
|
||||||
@ -88,7 +95,7 @@ void CuStringAppendFormat(CuString* str, const char* format, ...)
|
|||||||
|
|
||||||
void CuStringInsert(CuString* str, const char* text, int pos)
|
void CuStringInsert(CuString* str, const char* text, int pos)
|
||||||
{
|
{
|
||||||
int length = (int)strlen(text);
|
int 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)
|
||||||
@ -119,6 +126,13 @@ CuTest* CuTestNew(const char* name, TestFunction function)
|
|||||||
return tc;
|
return tc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CuTestDelete(CuTest *t)
|
||||||
|
{
|
||||||
|
if (!t) return;
|
||||||
|
free(t->name);
|
||||||
|
free(t);
|
||||||
|
}
|
||||||
|
|
||||||
void CuTestRun(CuTest* tc)
|
void CuTestRun(CuTest* tc)
|
||||||
{
|
{
|
||||||
jmp_buf buf;
|
jmp_buf buf;
|
||||||
@ -203,6 +217,7 @@ void CuAssertDblEquals_LineMsg(CuTest* tc, const char* file, int line, const cha
|
|||||||
char buf[STRING_MAX];
|
char buf[STRING_MAX];
|
||||||
if (fabs(expected - actual) <= delta) return;
|
if (fabs(expected - actual) <= delta) return;
|
||||||
sprintf(buf, "expected <%f> but was <%f>", expected, actual);
|
sprintf(buf, "expected <%f> but was <%f>", expected, actual);
|
||||||
|
|
||||||
CuFail_Line(tc, file, line, message, buf);
|
CuFail_Line(tc, file, line, message, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,6 +239,7 @@ void CuSuiteInit(CuSuite* testSuite)
|
|||||||
{
|
{
|
||||||
testSuite->count = 0;
|
testSuite->count = 0;
|
||||||
testSuite->failCount = 0;
|
testSuite->failCount = 0;
|
||||||
|
memset(testSuite->list, 0, sizeof(testSuite->list));
|
||||||
}
|
}
|
||||||
|
|
||||||
CuSuite* CuSuiteNew(void)
|
CuSuite* CuSuiteNew(void)
|
||||||
@ -233,6 +249,20 @@ CuSuite* CuSuiteNew(void)
|
|||||||
return testSuite;
|
return testSuite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CuSuiteDelete(CuSuite *testSuite)
|
||||||
|
{
|
||||||
|
unsigned int n;
|
||||||
|
for (n=0; n < MAX_TEST_CASES; n++)
|
||||||
|
{
|
||||||
|
if (testSuite->list[n])
|
||||||
|
{
|
||||||
|
CuTestDelete(testSuite->list[n]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(testSuite);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void CuSuiteAdd(CuSuite* testSuite, CuTest *testCase)
|
void CuSuiteAdd(CuSuite* testSuite, CuTest *testCase)
|
||||||
{
|
{
|
||||||
assert(testSuite->count < MAX_TEST_CASES);
|
assert(testSuite->count < MAX_TEST_CASES);
|
||||||
|
7
CuTest.h
7
CuTest.h
@ -4,6 +4,8 @@
|
|||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#define CUTEST_VERSION "CuTest 1.5"
|
||||||
|
|
||||||
/* CuString */
|
/* CuString */
|
||||||
|
|
||||||
char* CuStrAlloc(int size);
|
char* CuStrAlloc(int size);
|
||||||
@ -30,6 +32,7 @@ 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, int pos);
|
||||||
void CuStringResize(CuString* str, int newSize);
|
void CuStringResize(CuString* str, int newSize);
|
||||||
|
void CuStringDelete(CuString* str);
|
||||||
|
|
||||||
/* CuTest */
|
/* CuTest */
|
||||||
|
|
||||||
@ -39,7 +42,7 @@ typedef void (*TestFunction)(CuTest *);
|
|||||||
|
|
||||||
struct CuTest
|
struct CuTest
|
||||||
{
|
{
|
||||||
const char* name;
|
char* name;
|
||||||
TestFunction function;
|
TestFunction function;
|
||||||
int failed;
|
int failed;
|
||||||
int ran;
|
int ran;
|
||||||
@ -50,6 +53,7 @@ struct CuTest
|
|||||||
void CuTestInit(CuTest* t, const char* name, TestFunction function);
|
void CuTestInit(CuTest* t, const char* name, TestFunction function);
|
||||||
CuTest* CuTestNew(const char* name, TestFunction function);
|
CuTest* CuTestNew(const char* name, TestFunction function);
|
||||||
void CuTestRun(CuTest* tc);
|
void CuTestRun(CuTest* tc);
|
||||||
|
void CuTestDelete(CuTest *t);
|
||||||
|
|
||||||
/* Internal versions of assert functions -- use the public versions */
|
/* Internal versions of assert functions -- use the public versions */
|
||||||
void CuFail_Line(CuTest* tc, const char* file, int line, const char* message2, const char* message);
|
void CuFail_Line(CuTest* tc, const char* file, int line, const char* message2, const char* message);
|
||||||
@ -102,6 +106,7 @@ typedef struct
|
|||||||
|
|
||||||
void CuSuiteInit(CuSuite* testSuite);
|
void CuSuiteInit(CuSuite* testSuite);
|
||||||
CuSuite* CuSuiteNew(void);
|
CuSuite* CuSuiteNew(void);
|
||||||
|
void CuSuiteDelete(CuSuite *testSuite);
|
||||||
void CuSuiteAdd(CuSuite* testSuite, CuTest *testCase);
|
void CuSuiteAdd(CuSuite* testSuite, CuTest *testCase);
|
||||||
void CuSuiteAddSuite(CuSuite* testSuite, CuSuite* testSuite2);
|
void CuSuiteAddSuite(CuSuite* testSuite, CuSuite* testSuite2);
|
||||||
void CuSuiteRun(CuSuite* testSuite);
|
void CuSuiteRun(CuSuite* testSuite);
|
||||||
|
12
README
12
README
@ -202,8 +202,10 @@ AllTests.c or dealing with any of the other suite code.
|
|||||||
|
|
||||||
CREDITS
|
CREDITS
|
||||||
|
|
||||||
[02.23.2003] Dave Glowacki <dglo@hyde.ssec.wisc.edu> has added
|
These people have contributed useful code changes to the CuTest project.
|
||||||
(1) file name and line numbers to the error messages, (2)
|
Thanks!
|
||||||
AssertDblEquals for doubles, (3) Assert<X>Equals_Msg version of
|
|
||||||
all the Assert<X>Equals to pass in optional message which is
|
- [02.23.2003] Dave Glowacki <dglo@hyde.ssec.wisc.edu>
|
||||||
printed out on assert failure.
|
- [04.17.2009] Tobias Lippert <herrmarder@googlemail.com>
|
||||||
|
- [11.13.2009] Eli Bendersky <eliben@gmail.com>
|
||||||
|
- [12.14.2009] Andrew Brown <abrown@datasci.com>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/usr/local/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Auto generate single AllTests file for CuTest.
|
# Auto generate single AllTests file for CuTest.
|
||||||
# Searches through all *.c files in the current directory.
|
# Searches through all *.c files in the current directory.
|
||||||
@ -11,6 +11,8 @@ if test $# -eq 0 ; then FILES=*.c ; else FILES=$* ; fi
|
|||||||
echo '
|
echo '
|
||||||
|
|
||||||
/* This is auto-generated code. Edit at your own peril. */
|
/* This is auto-generated code. Edit at your own peril. */
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "CuTest.h"
|
#include "CuTest.h"
|
||||||
|
|
||||||
@ -42,6 +44,8 @@ echo \
|
|||||||
CuSuiteSummary(suite, output);
|
CuSuiteSummary(suite, output);
|
||||||
CuSuiteDetails(suite, output);
|
CuSuiteDetails(suite, output);
|
||||||
printf("%s\n", output->buffer);
|
printf("%s\n", output->buffer);
|
||||||
|
CuStringDelete(output);
|
||||||
|
CuSuiteDelete(suite);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user