diff --git a/CMakeLists.txt b/CMakeLists.txt index 3512422..b1a8033 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,10 +9,5 @@ target_link_libraries (CuTestTest cutest) enable_testing() add_test (cutest CuTestTest) -IF (MSVC) - find_package (MSVC MODULE) - MSVC_CRT_SECURE_NO_WARNINGS (${PROJECT_NAME} CuTestTest) -ENDIF (MSVC) - set (CUTEST_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "CuTest headers") set (CUTEST_LIBRARIES cutest CACHE INTERNAL "CuTest libraries") diff --git a/CuTest.c b/CuTest.c index da6d180..4b14ce9 100644 --- a/CuTest.c +++ b/CuTest.c @@ -1,3 +1,6 @@ +#ifdef _MSC_VER +#define _CRT_SECURE_NO_WARNINGS +#endif #include #include #include @@ -11,7 +14,7 @@ * CuStr *-------------------------------------------------------------------------*/ -char* CuStrAlloc(int size) +char* CuStrAlloc(size_t size) { char* newStr = (char*) malloc( sizeof(char) * (size) ); return newStr; @@ -19,7 +22,7 @@ char* CuStrAlloc(int size) char* CuStrCopy(const char* old) { - int len = strlen(old); + size_t len = strlen(old); char* newStr = CuStrAlloc(len + 1); strcpy(newStr, old); return newStr; @@ -54,7 +57,7 @@ void CuStringDelete(CuString *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->size = newSize; @@ -62,7 +65,7 @@ void CuStringResize(CuString* str, int newSize) void CuStringAppend(CuString* str, const char* text) { - int length; + size_t length; if (text == NULL) { text = "NULL"; @@ -93,9 +96,9 @@ void CuStringAppendFormat(CuString* str, const char* format, ...) 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) pos = str->length; if (str->length + length + 1 >= str->size) diff --git a/CuTest.h b/CuTest.h index 4d08be3..1ffb0f8 100644 --- a/CuTest.h +++ b/CuTest.h @@ -3,12 +3,13 @@ #include #include +#include -#define CUTEST_VERSION "CuTest 1.5b" +#define CUTEST_VERSION "CuTest 1.5c" /* CuString */ -char* CuStrAlloc(int size); +char* CuStrAlloc(size_t size); char* CuStrCopy(const char* old); #define CU_ALLOC(TYPE) ((TYPE*) malloc(sizeof(TYPE))) @@ -19,8 +20,8 @@ char* CuStrCopy(const char* old); typedef struct { - int length; - int size; + size_t length; + size_t size; char* buffer; } CuString; @@ -30,8 +31,8 @@ void CuStringRead(CuString* str, const char* path); void CuStringAppend(CuString* str, const char* text); void CuStringAppendChar(CuString* str, char ch); void CuStringAppendFormat(CuString* str, const char* format, ...); -void CuStringInsert(CuString* str, const char* text, int pos); -void CuStringResize(CuString* str, int newSize); +void CuStringInsert(CuString* str, const char* text, size_t pos); +void CuStringResize(CuString* str, size_t newSize); void CuStringDelete(CuString* str); /* CuTest */ diff --git a/CuTestTest.c b/CuTestTest.c index 1911131..110e22b 100644 --- a/CuTestTest.c +++ b/CuTestTest.c @@ -1,3 +1,6 @@ +#ifdef _MSC_VER +#define _CRT_SECURE_NO_WARNINGS +#endif #include #include #include @@ -55,10 +58,10 @@ void TestCuStringAppend(CuTest* tc) { CuString* str = CuStringNew(); CuStringAppend(str, "hello"); - CuAssertIntEquals(tc, 5, str->length); + CuAssertIntEquals(tc, 5, (int)str->length); CuAssertStrEquals(tc, "hello", str->buffer); CuStringAppend(str, " world"); - CuAssertIntEquals(tc, 11, str->length); + CuAssertIntEquals(tc, 11, (int)str->length); CuAssertStrEquals(tc, "hello world", str->buffer); } @@ -67,7 +70,7 @@ void TestCuStringAppendNULL(CuTest* tc) { CuString* str = CuStringNew(); CuStringAppend(str, NULL); - CuAssertIntEquals(tc, 4, str->length); + CuAssertIntEquals(tc, 4, (int)str->length); CuAssertStrEquals(tc, "NULL", str->buffer); } @@ -79,7 +82,7 @@ void TestCuStringAppendChar(CuTest* tc) CuStringAppendChar(str, 'b'); CuStringAppendChar(str, 'c'); CuStringAppendChar(str, 'd'); - CuAssertIntEquals(tc, 4, str->length); + CuAssertIntEquals(tc, 4, (int)str->length); CuAssertStrEquals(tc, "abcd", str->buffer); } @@ -88,16 +91,16 @@ void TestCuStringInserts(CuTest* tc) { CuString* str = CuStringNew(); CuStringAppend(str, "world"); - CuAssertIntEquals(tc, 5, str->length); + CuAssertIntEquals(tc, 5, (int)str->length); CuAssertStrEquals(tc, "world", str->buffer); CuStringInsert(str, "hell", 0); - CuAssertIntEquals(tc, 9, str->length); + CuAssertIntEquals(tc, 9, (int)str->length); CuAssertStrEquals(tc, "hellworld", str->buffer); CuStringInsert(str, "o ", 4); - CuAssertIntEquals(tc, 11, str->length); + CuAssertIntEquals(tc, 11, (int)str->length); CuAssertStrEquals(tc, "hello world", str->buffer); CuStringInsert(str, "!", 11); - CuAssertIntEquals(tc, 12, str->length); + CuAssertIntEquals(tc, 12, (int)str->length); CuAssertStrEquals(tc, "hello world!", str->buffer); }