forked from cpputest/cpputest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
374 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<?eclipse-cdt version="2.0"?> | ||
|
||
<cdtproject id="org.eclipse.cdt.make.core.make"> | ||
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/> | ||
<data> | ||
<item id="scannerConfiguration"> | ||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile"/> | ||
<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile"> | ||
<buildOutputProvider> | ||
<openAction enabled="true" filePath=""/> | ||
<parser enabled="true"/> | ||
</buildOutputProvider> | ||
<scannerInfoProvider id="specsFile"> | ||
<runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/> | ||
<parser enabled="true"/> | ||
</scannerInfoProvider> | ||
</profile> | ||
<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"> | ||
<buildOutputProvider> | ||
<openAction enabled="false" filePath=""/> | ||
<parser enabled="true"/> | ||
</buildOutputProvider> | ||
<scannerInfoProvider id="makefileGenerator"> | ||
<runAction arguments="-f ${project_name}_scd.mk" command="make" useDefault="true"/> | ||
<parser enabled="false"/> | ||
</scannerInfoProvider> | ||
</profile> | ||
<profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfile"> | ||
<buildOutputProvider> | ||
<openAction enabled="false" filePath=""/> | ||
<parser enabled="true"/> | ||
</buildOutputProvider> | ||
<scannerInfoProvider id="specsFile"> | ||
<runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/> | ||
<parser enabled="false"/> | ||
</scannerInfoProvider> | ||
</profile> | ||
<profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfile"> | ||
<buildOutputProvider> | ||
<openAction enabled="false" filePath=""/> | ||
<parser enabled="true"/> | ||
</buildOutputProvider> | ||
<scannerInfoProvider id="specsFile"> | ||
<runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/> | ||
<parser enabled="false"/> | ||
</scannerInfoProvider> | ||
</profile> | ||
</item> | ||
<item id="org.eclipse.cdt.core.pathentry"> | ||
<pathentry kind="src" path=""/> | ||
<pathentry kind="out" path=""/> | ||
<pathentry kind="con" path="org.eclipse.cdt.make.core.DISCOVERED_SCANNER_INFO"/> | ||
</item> | ||
</data> | ||
</cdtproject> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>CppUTest</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.cdt.make.core.makeBuilder</name> | ||
<arguments> | ||
<dictionary> | ||
<key>org.eclipse.cdt.make.core.build.arguments</key> | ||
<value></value> | ||
</dictionary> | ||
<dictionary> | ||
<key>org.eclipse.cdt.core.errorOutputParser</key> | ||
<value>org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.VCErrorParser;</value> | ||
</dictionary> | ||
<dictionary> | ||
<key>org.eclipse.cdt.make.core.environment</key> | ||
<value></value> | ||
</dictionary> | ||
<dictionary> | ||
<key>org.eclipse.cdt.make.core.enableAutoBuild</key> | ||
<value>true</value> | ||
</dictionary> | ||
<dictionary> | ||
<key>org.eclipse.cdt.make.core.build.target.inc</key> | ||
<value>all</value> | ||
</dictionary> | ||
<dictionary> | ||
<key>org.eclipse.cdt.make.core.enableFullBuild</key> | ||
<value>true</value> | ||
</dictionary> | ||
<dictionary> | ||
<key>org.eclipse.cdt.make.core.enabledIncrementalBuild</key> | ||
<value>true</value> | ||
</dictionary> | ||
<dictionary> | ||
<key>org.eclipse.cdt.make.core.build.location</key> | ||
<value></value> | ||
</dictionary> | ||
<dictionary> | ||
<key>org.eclipse.cdt.make.core.build.command</key> | ||
<value>make</value> | ||
</dictionary> | ||
<dictionary> | ||
<key>org.eclipse.cdt.make.core.build.target.clean</key> | ||
<value>clean</value> | ||
</dictionary> | ||
<dictionary> | ||
<key>org.eclipse.cdt.make.core.enableCleanBuild</key> | ||
<value>true</value> | ||
</dictionary> | ||
<dictionary> | ||
<key>org.eclipse.cdt.make.core.append_environment</key> | ||
<value>true</value> | ||
</dictionary> | ||
<dictionary> | ||
<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key> | ||
<value>true</value> | ||
</dictionary> | ||
<dictionary> | ||
<key>org.eclipse.cdt.make.core.build.target.auto</key> | ||
<value>all</value> | ||
</dictionary> | ||
<dictionary> | ||
<key>org.eclipse.cdt.make.core.stopOnError</key> | ||
<value>false</value> | ||
</dictionary> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.cdt.make.core.ScannerConfigBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.cdt.core.cnature</nature> | ||
<nature>org.eclipse.cdt.make.core.makeNature</nature> | ||
<nature>org.eclipse.cdt.make.core.ScannerConfigNature</nature> | ||
<nature>org.eclipse.cdt.core.ccnature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
Microsoft Developer Studio Workspace File, Format Version 6.00 | ||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! | ||
|
||
############################################################################### | ||
|
||
Project: "Helpers"=.\Helpers\Helpers.dsp - Package Owner=<4> | ||
|
||
Package=<5> | ||
{{{ | ||
}}} | ||
|
||
Package=<4> | ||
{{{ | ||
}}} | ||
|
||
############################################################################### | ||
|
||
Project: "UnitTestHarness"=.\UnitTestHarness\UnitTestHarness.dsp - Package Owner=<4> | ||
|
||
Package=<5> | ||
{{{ | ||
}}} | ||
|
||
Package=<4> | ||
{{{ | ||
}}} | ||
|
||
############################################################################### | ||
|
||
Project: "UnitTestHarnessTests"=.\UnitTestHarnessTests\UnitTestHarnessTests.dsp - Package Owner=<4> | ||
|
||
Package=<5> | ||
{{{ | ||
}}} | ||
|
||
Package=<4> | ||
{{{ | ||
Begin Project Dependency | ||
Project_Dep_Name Helpers | ||
End Project Dependency | ||
Begin Project Dependency | ||
Project_Dep_Name UnitTestHarness | ||
End Project Dependency | ||
Begin Project Dependency | ||
Project_Dep_Name VisualCpp | ||
End Project Dependency | ||
}}} | ||
|
||
############################################################################### | ||
|
||
Project: "VisualCpp"=.\Platforms\VisualCpp\VisualCpp.dsp - Package Owner=<4> | ||
|
||
Package=<5> | ||
{{{ | ||
}}} | ||
|
||
Package=<4> | ||
{{{ | ||
}}} | ||
|
||
############################################################################### | ||
|
||
Global: | ||
|
||
Package=<5> | ||
{{{ | ||
}}} | ||
|
||
Package=<3> | ||
{{{ | ||
}}} | ||
|
||
############################################################################### | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export CPP_U_TEST = $(shell pwd) | ||
export CPP_PLATFORM = Gcc | ||
export APP_CXXFLAGS = -Wall | ||
|
||
all: compile test | ||
|
||
compile: | ||
$(MAKE) -C src/Platforms/Gcc all | ||
$(MAKE) -C src/CppUTest all | ||
$(MAKE) -C lib all | ||
|
||
test: all | ||
$(MAKE) -C tests all test | ||
|
||
example: all | ||
$(MAKE) -C examples all | ||
|
||
clean: | ||
$(MAKE) -C src/Platforms/Gcc clean | ||
$(MAKE) -C src/CppUTest clean | ||
$(MAKE) -C tests clean | ||
$(MAKE) -C lib clean | ||
|
||
depend: | ||
$(MAKE) -C src/Platforms/Gcc depend | ||
$(MAKE) -C src depend | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
The unit test harness supplied with CppUTest is based on Michael | ||
Feathers' CppUnitLite. | ||
|
||
CppUTest.UnitTestHarness supports these features | ||
|
||
Command line switches | ||
|
||
* -v verbose, print each test name as it runs | ||
* -r# repeat the tests some number of times, default is one, default | ||
is # is not specified is 2. This is handy if you are experiencing | ||
memory leaks. A second run that has no leaks indicates that someone | ||
is allocating statics and not releasing them. | ||
* -g group only run test whose group contains the substring group | ||
* -n name only run test whose name contains the substring name | ||
|
||
|
||
Test Macros | ||
|
||
* TEST(group, name) - define a test | ||
* IGNORE_TEST(group, name) - turn off the execution of a test | ||
* IMPORT_TEST_GROUP(group) - Link in a test group from another library to | ||
the test main (this goes in main, a header file included by main, or a | ||
cpp file linked to main | ||
* EXPORT_TEST_GROUP(group) - Export the name of a test group so it can | ||
be linked in from a library | ||
|
||
|
||
Set up and tear down support | ||
|
||
* Each test file defines SetUp and TearDown functions | ||
* SetUp is called prior to each TEST body and TearDown is called after | ||
the test body | ||
|
||
|
||
Assertion Macros | ||
The failure of one of these macros causes the current test to immediately exit | ||
|
||
* CHECK(boolean condition) - checks any boolean result | ||
* CHECK_EQUAL(expected, actual) - checks for equality between entities | ||
using ==. So if you have a class that supports operator==() you can use | ||
this macro to compare two instances. | ||
* STRCMP_EQUAL(expected, actual) - check const char* strings for equality | ||
using strcmp | ||
* LONGS_EQUAL(expected, actual) - Compares two numbers | ||
* DOUBLES_EQUAL(expected, actual, tolerance) - Compares two doubles | ||
within some tolerance | ||
* FAIL(text) - always fails | ||
|
||
|
||
Customize CHECK_EQUAL to work with your types that support operator==() | ||
|
||
* Create the function | ||
|
||
SimpleString StringFrom (const yourType&) | ||
|
||
|
||
Memory leak detection | ||
|
||
* A platform specific memory leak detection mechanism is provided. | ||
* If a test fails and has allocated memory prior to the fail and | ||
that memory is not cleaned up by TearDown, a memory leak is reported. It is best to only chase memory leaks when other errors have been eliminated. | ||
* Some code uses lazy initialization and appears to leak when it | ||
really does not (for example: gcc stringstream used to in an earlier release). One cause is that some standard library calls allocate something and do not free it until after main (or never). To find out if a memory leak is due to lazy initialization set the -r switch to run tests twice. The signature of this situation is that the first run shows leaks and the second run shows no leaks. When both runs show leaks, you have a leak to find. | ||
|
||
How is memory leak detection implemented? | ||
|
||
* Before SetUp() a memory usage checkpoint is recorded | ||
* After TearDown() another checkpoint is taken and compared to the | ||
original checkpoint | ||
* In Visual Studio the MS debug heap capabilities are used | ||
* For GCC a simple new/delete count is used in overriden operators new, | ||
new[], delete and delete[] | ||
|
||
|
||
If you use some leaky code that you can't or won't fix you can tell a | ||
TEST to ignore a certain number of leaks as in this example: | ||
|
||
TEST(MemoryLeakWarningTest, Ignore1) | ||
{ | ||
IGNORE_N_LEAKS(1); | ||
char* arrayToLeak1 = new char[100]; | ||
} | ||
|
||
|
||
Example Main | ||
|
||
#include "UnitTestHarness/CommandLineTestRunner.h" | ||
|
||
int main(int ac, char** av) | ||
{ | ||
return CommandLineTestRunner::RunAllTests(ac, av); | ||
} | ||
|
||
IMPORT_TEST_GROUP(ClassName) | ||
|
||
|
||
Example Test | ||
|
||
#include "UnitTestHarness/TestHarness.h" | ||
#include "ClassName.h" | ||
|
||
EXPORT_TEST_GROUP(ClassName) | ||
|
||
namespace | ||
{ | ||
ClassName* className; | ||
|
||
void SetUp() | ||
{ | ||
className = new ClassName(); | ||
} | ||
void TearDown() | ||
{ | ||
delete className; | ||
} | ||
} | ||
|
||
TEST(ClassName, Create) | ||
{ | ||
CHECK(0 != className); | ||
CHECK(true); | ||
CHECK_EQUALS(1,1); | ||
LONGS_EQUAL(1,1); | ||
DOUBLES_EQUAL(1.000, 1.001, .01); | ||
STRCMP_EQUAL("hello", "hello"); | ||
FAIL("The prior tests pass, but this one doesn't"); | ||
} | ||
|
||
|
||
SetUp and TearDown are located within the unnamed namespace. This avoids | ||
global name pollution as SetUp and TearDown will only be visable within | ||
the current file. |