Skip to content

Commit

Permalink
updated readme file.
Browse files Browse the repository at this point in the history
Added SRC_FILES symbol to makefile so that the ComponentMakefile can be very specific about which source files to include in a test run.

Fixed comment in release script.

Changed output of STRCMP_EQUAL and no case variety to put a marker "<!>" into a mismatched string pointing to the start of the mismatch.
  • Loading branch information
jwgrenning committed Jul 30, 2010
1 parent b5e31c0 commit 6bf1ba5
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 14 deletions.
5 changes: 2 additions & 3 deletions README_InstallCppUTest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
2a. For unix/gcc (including cygwin)
Use the command line to execute makeAndRunTests.sh
> cd <someDirectory>/CppUTest
> chmod +x *.sh
> ./makeAndRunTests.sh

> make

NOTE: the builds run their unit tests to verify the build
NOTE: Older cygwin installs may report memory leaks.

Expand Down
5 changes: 3 additions & 2 deletions build/ComponentMakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# ComponentMakefileExampleParameters
#
# Inputs
# SRC - srouce code built into the library
# SRC_FILES - Specific source files to build into library
# SRC_DIRS - Directories od source file to built into the library
# TEST_SRC - unit test code build into the unit test runner
# MOCKS_SRC - mock objects build into the test runner
# INCLUDES - List of -I files
Expand All @@ -37,7 +38,7 @@ src_to = $(subst .c,$1, $(subst .cpp,$1,$2))
#Derived
STUFF_TO_CLEAN += $(TEST_TARGET) $(TEST_TARGET).exe $(TARGET_LIB)

SRC = $(call get_src_from_dir_list, $(SRC_DIRS))
SRC += $(call get_src_from_dir_list, $(SRC_DIRS)) $(SRC_FILES)
OBJ = $(call src_to_o,$(SRC))
STUFF_TO_CLEAN += $(OBJ)

Expand Down
5 changes: 5 additions & 0 deletions include/CppUTest/Utest.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ class Utest

SimpleString stringFromOrNull(const char * expected);
void failEqualsTest(const char * expected, const char* actual, const char * fileName, int lineNumber);
void failCstrEqualsTest(const char * expected, const char* actual, const char * fileName, int lineNumber);
void failCstrEqualsTestNoCase(const char * expected, const char* actual, const char * fileName, int lineNumber);
void failContainsTest(const char * expected, const char* actual, const char * fileName, int lineNumber);
int findStartOfCstrEqualsFailNoCase(const char * expected, const char* actual);
int findStartOfCstrEqualsFail(const char * expected, const char* actual);
const char* formCStrEqualsFailMessage(const char* actual, int failStart);
};

//////////////////// NulLTest
Expand Down
4 changes: 2 additions & 2 deletions scripts/ReleaseCppUTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ generateCppUTestRelease() {
}


//Main stuff
#Main stuff
SCRIPTS_DIR=scripts
version=v2.2
version=v2.2a
generateCppUTestRelease $version

37 changes: 37 additions & 0 deletions src/CppUTest/Extensions/OrderedTest.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
\
src/CppUTest/Extensions/OrderedTest.o src/CppUTest/Extensions/OrderedTest.d: \
src/CppUTest/Extensions/OrderedTest.cpp \
include/CppUTest/MemoryLeakDetectorNewMacros.h /usr/include/stdlib.h \
/usr/include/Availability.h /usr/include/AvailabilityInternal.h \
/usr/include/_types.h /usr/include/sys/_types.h \
/usr/include/sys/cdefs.h /usr/include/machine/_types.h \
/usr/include/i386/_types.h /usr/include/sys/wait.h \
/usr/include/sys/signal.h /usr/include/sys/appleapiopts.h \
/usr/include/machine/signal.h /usr/include/i386/signal.h \
/usr/include/i386/_structs.h /usr/include/sys/_structs.h \
/usr/include/machine/_structs.h /usr/include/mach/i386/_structs.h \
/usr/include/sys/resource.h /usr/include/machine/endian.h \
/usr/include/i386/endian.h /usr/include/sys/_endian.h \
/usr/include/libkern/_OSByteOrder.h \
/usr/include/libkern/i386/_OSByteOrder.h /usr/include/alloca.h \
/usr/include/machine/types.h /usr/include/i386/types.h \
/usr/include/i386/_types.h /usr/include/c++/4.2.1/new \
/usr/include/c++/4.2.1/cstddef \
/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/bits/c++config.h \
/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/bits/os_defines.h \
/usr/include/unistd.h /usr/include/sys/unistd.h \
/usr/include/sys/select.h /usr/include/sys/_select.h \
/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/bits/cpu_defines.h \
/usr/lib/gcc/i686-apple-darwin10/4.2.1/include/stddef.h \
/usr/include/c++/4.2.1/exception \
include/CppUTest/MemoryLeakDetectorMallocMacros.h \
include/CppUTest/TestHarness.h include/CppUTest/Utest.h \
include/CppUTest/SimpleString.h \
/usr/lib/gcc/i686-apple-darwin10/4.2.1/include/stdarg.h \
include/CppUTest/UtestMacros.h include/CppUTest/TestResult.h \
include/CppUTest/Failure.h include/CppUTest/TestPlugin.h \
include/CppUTest/MemoryLeakWarningPlugin.h \
include/CppUTest/TestHarness_c.h \
include/CppUTest/MemoryLeakDetectorNewMacros.h \
include/CppUTest/TestRegistry.h \
include/CppUTest/Extensions/OrderedTest.h
90 changes: 90 additions & 0 deletions src/CppUTest/Extensions/SimpleStringExtensions.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
\
src/CppUTest/Extensions/SimpleStringExtensions.o src/CppUTest/Extensions/SimpleStringExtensions.d: \
src/CppUTest/Extensions/SimpleStringExtensions.cpp \
include/CppUTest/MemoryLeakDetectorNewMacros.h /usr/include/stdlib.h \
/usr/include/Availability.h /usr/include/AvailabilityInternal.h \
/usr/include/_types.h /usr/include/sys/_types.h \
/usr/include/sys/cdefs.h /usr/include/machine/_types.h \
/usr/include/i386/_types.h /usr/include/sys/wait.h \
/usr/include/sys/signal.h /usr/include/sys/appleapiopts.h \
/usr/include/machine/signal.h /usr/include/i386/signal.h \
/usr/include/i386/_structs.h /usr/include/sys/_structs.h \
/usr/include/machine/_structs.h /usr/include/mach/i386/_structs.h \
/usr/include/sys/resource.h /usr/include/machine/endian.h \
/usr/include/i386/endian.h /usr/include/sys/_endian.h \
/usr/include/libkern/_OSByteOrder.h \
/usr/include/libkern/i386/_OSByteOrder.h /usr/include/alloca.h \
/usr/include/machine/types.h /usr/include/i386/types.h \
/usr/include/i386/_types.h /usr/include/c++/4.2.1/new \
/usr/include/c++/4.2.1/cstddef \
/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/bits/c++config.h \
/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/bits/os_defines.h \
/usr/include/unistd.h /usr/include/sys/unistd.h \
/usr/include/sys/select.h /usr/include/sys/_select.h \
/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/bits/cpu_defines.h \
/usr/lib/gcc/i686-apple-darwin10/4.2.1/include/stddef.h \
/usr/include/c++/4.2.1/exception \
include/CppUTest/MemoryLeakDetectorMallocMacros.h \
include/CppUTest/Extensions/SimpleStringExtensions.h \
/usr/include/c++/4.2.1/string /usr/include/c++/4.2.1/bits/stringfwd.h \
/usr/include/c++/4.2.1/bits/char_traits.h \
/usr/include/c++/4.2.1/cstring /usr/include/string.h \
/usr/include/c++/4.2.1/bits/stl_algobase.h \
/usr/include/c++/4.2.1/climits \
/usr/lib/gcc/i686-apple-darwin10/4.2.1/include/limits.h \
/usr/lib/gcc/i686-apple-darwin10/4.2.1/include/syslimits.h \
/usr/include/limits.h /usr/include/machine/limits.h \
/usr/include/i386/limits.h /usr/include/i386/_limits.h \
/usr/include/sys/syslimits.h /usr/include/c++/4.2.1/cstdlib \
/usr/include/c++/4.2.1/iosfwd \
/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/bits/c++locale.h \
/usr/include/c++/4.2.1/clocale /usr/include/locale.h \
/usr/include/_locale.h /usr/include/c++/4.2.1/cstdio \
/usr/include/stdio.h /usr/include/c++/4.2.1/cstdarg \
/usr/lib/gcc/i686-apple-darwin10/4.2.1/include/stdarg.h \
/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/bits/c++io.h \
/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/bits/gthr.h \
/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/bits/gthr-default.h \
/usr/include/pthread.h /usr/include/pthread_impl.h /usr/include/sched.h \
/usr/include/time.h /usr/include/_structs.h \
/usr/include/c++/4.2.1/cctype /usr/include/ctype.h \
/usr/include/runetype.h /usr/include/c++/4.2.1/bits/postypes.h \
/usr/include/c++/4.2.1/cwchar /usr/include/c++/4.2.1/ctime \
/usr/include/wchar.h /usr/include/_wctype.h \
/usr/lib/gcc/i686-apple-darwin10/4.2.1/include/stdint.h \
/usr/include/c++/4.2.1/bits/functexcept.h \
/usr/include/c++/4.2.1/exception_defines.h \
/usr/include/c++/4.2.1/bits/stl_pair.h \
/usr/include/c++/4.2.1/bits/cpp_type_traits.h \
/usr/include/c++/4.2.1/ext/type_traits.h /usr/include/c++/4.2.1/utility \
/usr/include/c++/4.2.1/bits/stl_relops.h \
/usr/include/c++/4.2.1/bits/stl_iterator_base_types.h \
/usr/include/c++/4.2.1/bits/stl_iterator_base_funcs.h \
/usr/include/c++/4.2.1/bits/concept_check.h \
/usr/include/c++/4.2.1/bits/stl_iterator.h \
/usr/include/c++/4.2.1/debug/debug.h /usr/include/c++/4.2.1/memory \
/usr/include/c++/4.2.1/bits/allocator.h \
/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/bits/c++allocator.h \
/usr/include/c++/4.2.1/ext/new_allocator.h \
/usr/include/c++/4.2.1/bits/stl_construct.h \
/usr/include/c++/4.2.1/bits/stl_uninitialized.h \
/usr/include/c++/4.2.1/bits/stl_raw_storage_iter.h \
/usr/include/c++/4.2.1/limits \
/usr/include/c++/4.2.1/bits/ostream_insert.h \
/usr/include/c++/4.2.1/bits/stl_function.h \
/usr/include/c++/4.2.1/bits/basic_string.h \
/usr/include/c++/4.2.1/ext/atomicity.h \
/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/bits/atomic_word.h \
/usr/include/c++/4.2.1/algorithm /usr/include/c++/4.2.1/bits/stl_algo.h \
/usr/include/c++/4.2.1/bits/stl_heap.h \
/usr/include/c++/4.2.1/bits/stl_tempbuf.h \
/usr/include/c++/4.2.1/bits/basic_string.tcc \
include/CppUTest/MemoryLeakDetectorNewMacros.h \
include/CppUTest/TestHarness.h include/CppUTest/Utest.h \
include/CppUTest/SimpleString.h include/CppUTest/UtestMacros.h \
include/CppUTest/TestResult.h include/CppUTest/Failure.h \
include/CppUTest/TestPlugin.h \
include/CppUTest/MemoryLeakWarningPlugin.h \
include/CppUTest/TestHarness_c.h \
include/CppUTest/MemoryLeakDetectorNewMacros.h \
include/CppUTest/SimpleString.h
39 changes: 39 additions & 0 deletions src/CppUTest/Extensions/SimpleStringFromStdint.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
\
src/CppUTest/Extensions/SimpleStringFromStdint.o src/CppUTest/Extensions/SimpleStringFromStdint.d: \
src/CppUTest/Extensions/SimpleStringFromStdint.cpp \
include/CppUTest/MemoryLeakDetectorNewMacros.h /usr/include/stdlib.h \
/usr/include/Availability.h /usr/include/AvailabilityInternal.h \
/usr/include/_types.h /usr/include/sys/_types.h \
/usr/include/sys/cdefs.h /usr/include/machine/_types.h \
/usr/include/i386/_types.h /usr/include/sys/wait.h \
/usr/include/sys/signal.h /usr/include/sys/appleapiopts.h \
/usr/include/machine/signal.h /usr/include/i386/signal.h \
/usr/include/i386/_structs.h /usr/include/sys/_structs.h \
/usr/include/machine/_structs.h /usr/include/mach/i386/_structs.h \
/usr/include/sys/resource.h /usr/include/machine/endian.h \
/usr/include/i386/endian.h /usr/include/sys/_endian.h \
/usr/include/libkern/_OSByteOrder.h \
/usr/include/libkern/i386/_OSByteOrder.h /usr/include/alloca.h \
/usr/include/machine/types.h /usr/include/i386/types.h \
/usr/include/i386/_types.h /usr/include/c++/4.2.1/new \
/usr/include/c++/4.2.1/cstddef \
/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/bits/c++config.h \
/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/bits/os_defines.h \
/usr/include/unistd.h /usr/include/sys/unistd.h \
/usr/include/sys/select.h /usr/include/sys/_select.h \
/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/bits/cpu_defines.h \
/usr/lib/gcc/i686-apple-darwin10/4.2.1/include/stddef.h \
/usr/include/c++/4.2.1/exception \
include/CppUTest/MemoryLeakDetectorMallocMacros.h \
include/CppUTest/TestHarness.h include/CppUTest/Utest.h \
include/CppUTest/SimpleString.h \
/usr/lib/gcc/i686-apple-darwin10/4.2.1/include/stdarg.h \
include/CppUTest/UtestMacros.h include/CppUTest/TestResult.h \
include/CppUTest/Failure.h include/CppUTest/TestPlugin.h \
include/CppUTest/MemoryLeakWarningPlugin.h \
include/CppUTest/TestHarness_c.h \
include/CppUTest/MemoryLeakDetectorNewMacros.h \
include/CppUTest/Extensions/SimpleStringFromStdint.h \
include/CppUTest/SimpleString.h \
/usr/lib/gcc/i686-apple-darwin10/4.2.1/include/stdint.h \
include/CppUTest/PlatformSpecificFunctions.h
63 changes: 61 additions & 2 deletions src/CppUTest/Utest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,65 @@ void Utest::fail(const char *text, const char* fileName, int lineNumber)
Utest::getCurrent()->exitCurrentTest();
}

int Utest::findStartOfCstrEqualsFailNoCase(const char * expected, const char* actual)
{
int i;
for (i = 0; tolower(actual[i]) == tolower(expected[i]); i++)
;
return i;
}

int Utest::findStartOfCstrEqualsFail(const char * expected, const char* actual)
{
int i;
for (i = 0; actual[i] == expected[i]; i++)
;
return i;
}

const char* Utest::formCStrEqualsFailMessage(const char* actual, int failStart)
{
const char * error = "<!>";
char * message;

message = new char[PlatformSpecificStrLen(actual) + PlatformSpecificStrLen(error) + 10];

int j;
for (j = 0; j < failStart; j++)
message[j] = actual[j];

for (int k = 0; k < (int)PlatformSpecificStrLen(error); j++, k++)
message[j] = error[k];

for (int i = failStart; actual[i]; i++, j++)
message[j] = actual[i];

message[j] = 0;

return message;
}


void Utest::failCstrEqualsTest(const char * expected, const char* actual, const char * fileName, int lineNumber)
{
int failStart = findStartOfCstrEqualsFail(expected, actual);
const char * markedActual = formCStrEqualsFailMessage(actual, failStart);
EqualsFailure _f(this, fileName, lineNumber, stringFromOrNull(expected), stringFromOrNull(markedActual));
testResult_->addFailure(_f);
delete [] markedActual;
Utest::getCurrent()->exitCurrentTest();
}

void Utest::failCstrEqualsTestNoCase(const char * expected, const char* actual, const char * fileName, int lineNumber)
{
int failStart = findStartOfCstrEqualsFailNoCase(expected, actual);
const char * markedActual = formCStrEqualsFailMessage(actual, failStart);
EqualsFailure _f(this, fileName, lineNumber, stringFromOrNull(expected), stringFromOrNull(markedActual));
testResult_->addFailure(_f);
delete [] markedActual;
Utest::getCurrent()->exitCurrentTest();
}

void Utest::failEqualsTest(const char * expected, const char* actual, const char * fileName, int lineNumber)
{
EqualsFailure _f(this, fileName, lineNumber, stringFromOrNull(expected), stringFromOrNull(actual));
Expand All @@ -269,7 +328,7 @@ void Utest::assertCstrEqual(const char* expected, const char* actual, const char
if (actual == 0 || expected == 0)
failEqualsTest (expected, actual, fileName, lineNumber);
if (PlatformSpecificStrCmp(expected, actual) != 0)
failEqualsTest (expected, actual, fileName, lineNumber);
failCstrEqualsTest (expected, actual, fileName, lineNumber);
}

void Utest::assertCstrNoCaseEqual(const char* expected, const char* actual, const char* fileName, int lineNumber)
Expand All @@ -279,7 +338,7 @@ void Utest::assertCstrNoCaseEqual(const char* expected, const char* actual, cons
if (actual == 0 || expected == 0)
failEqualsTest (expected, actual, fileName, lineNumber);
if (!SimpleString(expected).equalsNoCase(actual))
failEqualsTest (expected, actual, fileName, lineNumber);
failCstrEqualsTestNoCase(expected, actual, fileName, lineNumber);
}

void Utest::assertCstrContains(const char* expected, const char* actual, const char* fileName, int lineNumber)
Expand Down
4 changes: 2 additions & 2 deletions tests/TestHarness_cTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ TEST(TestHarness_c, checkChar)

void _failStringMethod()
{
CHECK_EQUAL_C_STRING("Hello", "World");
CHECK_EQUAL_C_STRING("Hello", "Hello World");
}

TEST(TestHarness_c, checkString)
{
CHECK_EQUAL_C_STRING("Hello", "Hello");
fixture->setTestFunction(_failStringMethod);
fixture->runAllTests();
fixture->assertPrintContains("expected <Hello>\n but was <World>");
fixture->assertPrintContains("expected <Hello>\n but was <Hello<!> World>");
fixture->assertPrintContains("arness_c");
}

Expand Down
15 changes: 12 additions & 3 deletions tests/UtestTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ TEST_GROUP(Utest)
CHECK(!afterCheck);
}

void testFailureWithMethodShouldContain(void(*method)(), const char * expected)
{
fixture->setTestFunction(method);
fixture->runAllTests();
fixture->assertPrintContains(expected);
LONGS_EQUAL(1, fixture->getFailureCount());
CHECK(!afterCheck);
}

};

static void _passMethod()
Expand Down Expand Up @@ -103,7 +112,7 @@ static void _failMethodSTRCMP_EQUAL()

static void _failMethodSTRCMP_NOCASE_EQUAL()
{
STRCMP_NOCASE_EQUAL("a", "B");
STRCMP_NOCASE_EQUAL("ac", "AB");
afterCheck = true;
}

Expand Down Expand Up @@ -185,12 +194,12 @@ TEST(Utest, FailureWithCHECK_EQUAL)

TEST(Utest, FailureWithSTRCMP_EQUAL)
{
testFailureWith(_failMethodSTRCMP_EQUAL);
testFailureWithMethodShouldContain(_failMethodSTRCMP_EQUAL, "but was <<!>b>");
}

TEST(Utest, FailureWithSTRCMP_NOCASE_EQUAL)
{
testFailureWith(_failMethodSTRCMP_NOCASE_EQUAL);
testFailureWithMethodShouldContain(_failMethodSTRCMP_NOCASE_EQUAL, "but was <A<!>B>");
}

TEST(Utest, FailureWithSTRCMP_CONTAINS)
Expand Down

0 comments on commit 6bf1ba5

Please sign in to comment.