git subrepo clone git@github.com:compihu/platform-test-f4-ll.git platforms/platform-test-f4-ll

subrepo:
  subdir:   "platforms/platform-test-f4-ll"
  merged:   "bc41134"
upstream:
  origin:   "git@github.com:compihu/platform-test-f4-ll.git"
  branch:   "master"
  commit:   "bc41134"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "87ee373"
This commit is contained in:
Attila Body 2021-02-24 21:46:35 +01:00
parent 46ce55c6a0
commit 95af4ce0d8
460 changed files with 84105 additions and 0 deletions

View file

@ -0,0 +1,116 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_CommandLineArguments_H
#define D_CommandLineArguments_H
#include "SimpleString.h"
#include "TestOutput.h"
#include "TestFilter.h"
class TestPlugin;
class CommandLineArguments
{
public:
explicit CommandLineArguments(int ac, const char *const *av);
virtual ~CommandLineArguments();
bool parse(TestPlugin* plugin);
bool needHelp() const;
bool isVerbose() const;
bool isVeryVerbose() const;
bool isColor() const;
bool isListingTestGroupNames() const;
bool isListingTestGroupAndCaseNames() const;
bool isRunIgnored() const;
size_t getRepeatCount() const;
bool isShuffling() const;
bool isReversing() const;
bool isCrashingOnFail() const;
size_t getShuffleSeed() const;
const TestFilter* getGroupFilters() const;
const TestFilter* getNameFilters() const;
bool isJUnitOutput() const;
bool isEclipseOutput() const;
bool isTeamCityOutput() const;
bool runTestsInSeperateProcess() const;
const SimpleString& getPackageName() const;
const char* usage() const;
const char* help() const;
private:
enum OutputType
{
OUTPUT_ECLIPSE, OUTPUT_JUNIT, OUTPUT_TEAMCITY
};
int ac_;
const char *const *av_;
bool needHelp_;
bool verbose_;
bool veryVerbose_;
bool color_;
bool runTestsAsSeperateProcess_;
bool listTestGroupNames_;
bool listTestGroupAndCaseNames_;
bool runIgnored_;
bool reversing_;
bool crashOnFail_;
bool shuffling_;
bool shufflingPreSeeded_;
size_t repeat_;
size_t shuffleSeed_;
TestFilter* groupFilters_;
TestFilter* nameFilters_;
OutputType outputType_;
SimpleString packageName_;
SimpleString getParameterField(int ac, const char *const *av, int& i, const SimpleString& parameterName);
void setRepeatCount(int ac, const char *const *av, int& index);
bool setShuffle(int ac, const char *const *av, int& index);
void addGroupFilter(int ac, const char *const *av, int& index);
bool addGroupDotNameFilter(int ac, const char *const *av, int& index);
void addStrictGroupFilter(int ac, const char *const *av, int& index);
void addExcludeGroupFilter(int ac, const char *const *av, int& index);
void addExcludeStrictGroupFilter(int ac, const char *const *av, int& index);
void addNameFilter(int ac, const char *const *av, int& index);
void addStrictNameFilter(int ac, const char *const *av, int& index);
void addExcludeNameFilter(int ac, const char *const *av, int& index);
void addExcludeStrictNameFilter(int ac, const char *const *av, int& index);
void addTestToRunBasedOnVerboseOutput(int ac, const char *const *av, int& index, const char* parameterName);
bool setOutputType(int ac, const char *const *av, int& index);
void setPackageName(int ac, const char *const *av, int& index);
CommandLineArguments(const CommandLineArguments&);
CommandLineArguments& operator=(const CommandLineArguments&);
};
#endif

View file

@ -0,0 +1,68 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_CommandLineTestRunner_H
#define D_CommandLineTestRunner_H
#include "TestHarness.h"
#include "TestOutput.h"
#include "CommandLineArguments.h"
#include "TestFilter.h"
class TestRegistry;
#define DEF_PLUGIN_MEM_LEAK "MemoryLeakPlugin"
#define DEF_PLUGIN_SET_POINTER "SetPointerPlugin"
class CommandLineTestRunner
{
public:
static int RunAllTests(int ac, const char *const *av);
static int RunAllTests(int ac, char** av);
CommandLineTestRunner(int ac, const char *const *av, TestRegistry* registry);
virtual ~CommandLineTestRunner();
int runAllTestsMain();
protected:
virtual TestOutput* createTeamCityOutput();
virtual TestOutput* createJUnitOutput(const SimpleString& packageName);
virtual TestOutput* createConsoleOutput();
virtual TestOutput* createCompositeOutput(TestOutput* outputOne, TestOutput* outputTwo);
TestOutput* output_;
private:
CommandLineArguments* arguments_;
TestRegistry* registry_;
bool parseArguments(TestPlugin*);
int runAllTests();
void initializeTestRun();
};
#endif

View file

@ -0,0 +1,332 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CPPUTESTCONFIG_H_
#define CPPUTESTCONFIG_H_
#ifndef CPPUTEST_USE_OWN_CONFIGURATION
#include "CppUTestGeneratedConfig.h"
#endif
/*
* This file is added for some specific CppUTest configurations that earlier were spread out into multiple files.
*
* The goal of this file is to stay really small and not to include other things, but mainly to remove duplication
* from other files and resolve dependencies in #includes.
*
*/
#ifdef __clang__
#pragma clang diagnostic push
#if (__clang_major__ == 3 && __clang_minor__ >= 6) || __clang_major__ >= 4
#pragma clang diagnostic ignored "-Wreserved-id-macro"
#endif
#endif
/*
* Lib C dependencies that are currently still left:
*
* stdarg.h -> We use formatting functions and va_list requires to include stdarg.h in SimpleString
* stdlib.h -> The TestHarness_c.h includes this to try to avoid conflicts in its malloc #define. This dependency can
* easily be removed by not enabling the MALLOC overrides.
*
* Lib C++ dependencies are all under the CPPUTEST_USE_STD_CPP_LIB.
* The only dependency is to <new> which has the bad_alloc struct
*
*/
/* Do we use Standard C or not? When doing Kernel development, standard C usage is out. */
#ifndef CPPUTEST_USE_STD_C_LIB
#ifdef CPPUTEST_STD_C_LIB_DISABLED
#define CPPUTEST_USE_STD_C_LIB 0
#else
#define CPPUTEST_USE_STD_C_LIB 1
#endif
#endif
/* Do we use Standard C++ or not? */
#ifndef CPPUTEST_USE_STD_CPP_LIB
#ifdef CPPUTEST_STD_CPP_LIB_DISABLED
#define CPPUTEST_USE_STD_CPP_LIB 0
#else
#define CPPUTEST_USE_STD_CPP_LIB 1
#endif
#endif
/* Is memory leak detection enabled?
* Controls the override of the global operator new/deleted and malloc/free.
* Without this, there will be no memory leak detection in C/C++.
*/
#ifndef CPPUTEST_USE_MEM_LEAK_DETECTION
#ifdef CPPUTEST_MEM_LEAK_DETECTION_DISABLED
#define CPPUTEST_USE_MEM_LEAK_DETECTION 0
#else
#define CPPUTEST_USE_MEM_LEAK_DETECTION 1
#endif
#endif
/* Should be the only #include here. Standard C library wrappers */
#include "StandardCLibrary.h"
/* Create a _no_return_ macro, which is used to flag a function as not returning.
* Used for functions that always throws for instance.
*
* This is needed for compiling with clang, without breaking other compilers.
*/
#ifndef __has_attribute
#define __has_attribute(x) 0
#endif
#if __has_attribute(noreturn)
#define _no_return_ __attribute__((noreturn))
#else
#define _no_return_
#endif
#if __has_attribute(format)
#define _check_format_(type, format_parameter, other_parameters) __attribute__ ((format (type, format_parameter, other_parameters)))
#else
#define _check_format_(type, format_parameter, other_parameters) /* type, format_parameter, other_parameters */
#endif
/*
* When we don't link Standard C++, then we won't throw exceptions as we assume the compiler might not support that!
*/
#if CPPUTEST_USE_STD_CPP_LIB
#if defined(__cplusplus) && __cplusplus >= 201103L
#define UT_THROW(exception)
#define UT_NOTHROW noexcept
#else
#define UT_THROW(exception) throw (exception)
#define UT_NOTHROW throw()
#endif
#else
#define UT_THROW(exception)
#ifdef __clang__
#define UT_NOTHROW throw()
#else
#define UT_NOTHROW
#endif
#endif
/*
* Visual C++ doesn't define __cplusplus as C++11 yet (201103), however it doesn't want the throw(exception) either, but
* it does want throw().
*/
#ifdef _MSC_VER
#undef UT_THROW
#define UT_THROW(exception)
#endif
#if defined(__cplusplus) && __cplusplus >= 201103L
#define DEFAULT_COPY_CONSTRUCTOR(classname) classname(const classname &) = default;
#else
#define DEFAULT_COPY_CONSTRUCTOR(classname)
#endif
/*
* g++-4.7 with stdc++11 enabled On MacOSX! will have a different exception specifier for operator new (and thank you!)
* I assume they'll fix this in the future, but for now, we'll change that here.
* (This should perhaps also be done in the configure.ac)
*/
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#ifdef __APPLE__
#ifdef _GLIBCXX_THROW
#undef UT_THROW
#define UT_THROW(exception) _GLIBCXX_THROW(exception)
#endif
#endif
#endif
/*
* Address sanitizer is a good thing... and it causes some conflicts with the CppUTest tests
* To check whether it is on or off, we create a CppUTest define here.
*/
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
#define CPPUTEST_SANITIZE_ADDRESS 1
#endif
#endif
#ifdef __SANITIZE_ADDRESS__
#define CPPUTEST_SANITIZE_ADDRESS 1
#endif
#ifndef CPPUTEST_SANITIZE_ADDRESS
#define CPPUTEST_SANITIZE_ADDRESS 0
#endif
#if CPPUTEST_SANITIZE_ADDRESS
#define CPPUTEST_SANITIZE_ADDRESS 1
#define CPPUTEST_DO_NOT_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
#if defined(__linux__) && defined(__clang__)
#if CPPUTEST_USE_MEM_LEAK_DETECTION
#warning Compiling with Address Sanitizer with clang on linux will cause duplicate symbols for operator new. Turning off memory leak detection. Compile with -DCPPUTEST_MEM_LEAK_DETECTION_DISABLED to get rid of this warning.
#undef CPPUTEST_USE_MEM_LEAK_DETECTION
#define CPPUTEST_USE_MEM_LEAK_DETECTION 0
#endif
#endif
#else
#define CPPUTEST_SANITIZER_ADDRESS 0
#define CPPUTEST_DO_NOT_SANITIZE_ADDRESS
#endif
/*
* Handling of IEEE754 floating point exceptions via fenv.h
* Predominantly works on non-Visual C++ compilers and Visual C++ 2008 and newer
*/
#if CPPUTEST_USE_STD_C_LIB && \
(!defined(_MSC_VER) || (_MSC_VER >= 1800)) && \
(!defined(__APPLE__)) && \
(!defined(__ghs__) || !defined(__ColdFire__))
#define CPPUTEST_HAVE_FENV
#if defined(__WATCOMC__) || defined(__ARMEL__) || defined(__m68k__)
#define CPPUTEST_FENV_IS_WORKING_PROPERLY 0
#else
#define CPPUTEST_FENV_IS_WORKING_PROPERLY 1
#endif
#endif
/*
* Detection of different 64 bit environments
*/
#if defined(__LP64__) || defined(_LP64) || (defined(__WORDSIZE) && (__WORDSIZE == 64 )) || defined(__x86_64) || defined(_WIN64)
#define CPPUTEST_64BIT
#if defined(_WIN64)
#define CPPUTEST_64BIT_32BIT_LONGS
#endif
#endif
/* Handling of systems with a different byte-width (e.g. 16 bit).
* Since CHAR_BIT is defined in limits.h (ANSI C), use default of 8 when building without Std C library.
*/
#if CPPUTEST_USE_STD_C_LIB
#define CPPUTEST_CHAR_BIT CHAR_BIT
#else
#define CPPUTEST_CHAR_BIT 8
#endif
/* Handling of systems with a different int-width (e.g. 16 bit).
*/
#if CPPUTEST_USE_STD_C_LIB && (INT_MAX == 0x7fff)
#define CPPUTEST_16BIT_INTS
#endif
/*
* Support for "long long" type.
*
* Not supported when CPPUTEST_LONG_LONG_DISABLED is set.
* Can be overridden by using CPPUTEST_USE_LONG_LONG
*
* CPPUTEST_HAVE_LONG_LONG_INT is set by configure
* LLONG_MAX is set in limits.h. This is a crude attempt to detect long long support when no configure is used
*
*/
#if !defined(CPPUTEST_LONG_LONG_DISABLED) && !defined(CPPUTEST_USE_LONG_LONG)
#if defined(CPPUTEST_HAVE_LONG_LONG_INT) || defined(LLONG_MAX)
#define CPPUTEST_USE_LONG_LONG 1
#endif
#endif
#ifdef CPPUTEST_USE_LONG_LONG
typedef long long cpputest_longlong;
typedef unsigned long long cpputest_ulonglong;
#else
/* Define some placeholders to disable the overloaded methods.
* It's not required to have these match the size of the "real" type, but it's occasionally convenient.
*/
#if defined(CPPUTEST_64BIT) && !defined(CPPUTEST_64BIT_32BIT_LONGS)
#define CPPUTEST_SIZE_OF_FAKE_LONG_LONG_TYPE 16
#else
#define CPPUTEST_SIZE_OF_FAKE_LONG_LONG_TYPE 8
#endif
struct cpputest_longlong
{
#if defined(__cplusplus)
cpputest_longlong() {}
cpputest_longlong(int) {}
#endif
char dummy[CPPUTEST_SIZE_OF_FAKE_LONG_LONG_TYPE];
};
struct cpputest_ulonglong
{
#if defined(__cplusplus)
cpputest_ulonglong() {}
cpputest_ulonglong(int) {}
#endif
char dummy[CPPUTEST_SIZE_OF_FAKE_LONG_LONG_TYPE];
};
#if !defined(__cplusplus)
typedef struct cpputest_longlong cpputest_longlong;
typedef struct cpputest_ulonglong cpputest_ulonglong;
#endif
#endif
/* Visual C++ 10.0+ (2010+) supports the override keyword, but doesn't define the C++ version as C++11 */
#if defined(__cplusplus) && ((__cplusplus >= 201103L) || (defined(_MSC_VER) && (_MSC_VER >= 1600)))
#if !defined(__ghs__)
#define CPPUTEST_COMPILER_FULLY_SUPPORTS_CXX11
#define _override override
#else
/* GreenHills is not compatible with other compilers with regards to where
* it expects the override specifier to be on methods that return function
* pointers. Given this, it is easiest to not use the override specifier.
*/
#define _override
#endif
#define NULLPTR nullptr
#else
#define _override
#define NULLPTR NULL
#endif
/* Visual C++ 11.0+ (2012+) supports the override keyword on destructors */
#if defined(__cplusplus) && ((__cplusplus >= 201103L) || (defined(_MSC_VER) && (_MSC_VER >= 1700)))
#define _destructor_override override
#else
#define _destructor_override
#endif
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This file is confusing, sorry for that :) Please never edit this file.
*
* It serves 3 purposes
*
* 1) When you installed CppUTest on your system (make install), then this file should be overwritten by one that
* actually contains some configuration of your system. Mostly info such as availability of types, headers, etc.
* 2) When you build CppUTest using autotools, this file will be included and it will include the generated file.
* That should be the same file as will be installed if you run make install
* 3) When you use CppUTest on another platform that doesn't require configuration, then this file does nothing and
* should be harmless.
*
* If you have done make install and you still found this text, then please report a bug :)
*
*/
#ifdef HAVE_CONFIG_H
#include "generated/CppUTestGeneratedConfig.h"
#endif

View file

@ -0,0 +1,81 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_JUnitTestOutput_h
#define D_JUnitTestOutput_h
#include "TestOutput.h"
#include "SimpleString.h"
struct JUnitTestOutputImpl;
struct JUnitTestCaseResultNode;
class JUnitTestOutput: public TestOutput
{
public:
JUnitTestOutput();
virtual ~JUnitTestOutput() _destructor_override;
virtual void printTestsStarted() _override;
virtual void printTestsEnded(const TestResult& result) _override;
virtual void printCurrentTestStarted(const UtestShell& test) _override;
virtual void printCurrentTestEnded(const TestResult& res) _override;
virtual void printCurrentGroupStarted(const UtestShell& test) _override;
virtual void printCurrentGroupEnded(const TestResult& res) _override;
virtual void printBuffer(const char*) _override;
virtual void print(const char*) _override;
virtual void print(long) _override;
virtual void print(size_t) _override;
virtual void printFailure(const TestFailure& failure) _override;
virtual void flush() _override;
virtual SimpleString createFileName(const SimpleString& group);
void setPackageName(const SimpleString &package);
protected:
JUnitTestOutputImpl* impl_;
void resetTestGroupResult();
virtual void openFileForWrite(const SimpleString& fileName);
virtual void writeTestGroupToFile();
virtual void writeToFile(const SimpleString& buffer);
virtual void closeFile();
virtual void writeXmlHeader();
virtual void writeTestSuiteSummary();
virtual void writeProperties();
virtual void writeTestCases();
virtual SimpleString encodeXmlText(const SimpleString& textbody);
virtual SimpleString encodeFileName(const SimpleString& fileName);
virtual void writeFailure(JUnitTestCaseResultNode* node);
virtual void writeFileEnding();
};
#endif

View file

@ -0,0 +1,270 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_MemoryLeakDetector_h
#define D_MemoryLeakDetector_h
enum MemLeakPeriod
{
mem_leak_period_all,
mem_leak_period_disabled,
mem_leak_period_enabled,
mem_leak_period_checking
};
class TestMemoryAllocator;
class SimpleMutex;
class MemoryLeakFailure
{
public:
virtual ~MemoryLeakFailure()
{
}
virtual void fail(char* fail_string)=0;
};
struct SimpleStringBuffer
{
enum
{
SIMPLE_STRING_BUFFER_LEN = 4096
};
SimpleStringBuffer();
void clear();
void add(const char* format, ...) _check_format_(printf, 2, 3);
void addMemoryDump(const void* memory, size_t memorySize);
char* toString();
void setWriteLimit(size_t write_limit);
void resetWriteLimit();
bool reachedItsCapacity();
private:
char buffer_[SIMPLE_STRING_BUFFER_LEN];
size_t positions_filled_;
size_t write_limit_;
};
struct MemoryLeakDetectorNode;
class MemoryLeakOutputStringBuffer
{
public:
MemoryLeakOutputStringBuffer();
void clear();
void startMemoryLeakReporting();
void stopMemoryLeakReporting();
void reportMemoryLeak(MemoryLeakDetectorNode* leak);
void reportDeallocateNonAllocatedMemoryFailure(const char* freeFile, size_t freeLine, TestMemoryAllocator* freeAllocator, MemoryLeakFailure* reporter);
void reportMemoryCorruptionFailure(MemoryLeakDetectorNode* node, const char* freeFile, size_t freeLineNumber, TestMemoryAllocator* freeAllocator, MemoryLeakFailure* reporter);
void reportAllocationDeallocationMismatchFailure(MemoryLeakDetectorNode* node, const char* freeFile, size_t freeLineNumber, TestMemoryAllocator* freeAllocator, MemoryLeakFailure* reporter);
char* toString();
private:
void addAllocationLocation(const char* allocationFile, size_t allocationLineNumber, size_t allocationSize, TestMemoryAllocator* allocator);
void addDeallocationLocation(const char* freeFile, size_t freeLineNumber, TestMemoryAllocator* allocator);
void addMemoryLeakHeader();
void addMemoryLeakFooter(size_t totalAmountOfLeaks);
void addWarningForUsingMalloc();
void addNoMemoryLeaksMessage();
void addErrorMessageForTooMuchLeaks();
private:
size_t total_leaks_;
bool giveWarningOnUsingMalloc_;
void reportFailure(const char* message, const char* allocFile,
size_t allocLine, size_t allocSize,
TestMemoryAllocator* allocAllocator, const char* freeFile,
size_t freeLine, TestMemoryAllocator* freeAllocator, MemoryLeakFailure* reporter);
SimpleStringBuffer outputBuffer_;
};
struct MemoryLeakDetectorNode
{
MemoryLeakDetectorNode() :
size_(0), number_(0), memory_(NULLPTR), file_(NULLPTR), line_(0), allocator_(NULLPTR), period_(mem_leak_period_enabled), allocation_stage_(0), next_(NULLPTR)
{
}
void init(char* memory, unsigned number, size_t size, TestMemoryAllocator* allocator, MemLeakPeriod period, unsigned char allocation_stage, const char* file, size_t line);
size_t size_;
unsigned number_;
char* memory_;
const char* file_;
size_t line_;
TestMemoryAllocator* allocator_;
MemLeakPeriod period_;
unsigned char allocation_stage_;
private:
friend struct MemoryLeakDetectorList;
MemoryLeakDetectorNode* next_;
};
struct MemoryLeakDetectorList
{
MemoryLeakDetectorList() :
head_(NULLPTR)
{}
void addNewNode(MemoryLeakDetectorNode* node);
MemoryLeakDetectorNode* retrieveNode(char* memory);
MemoryLeakDetectorNode* removeNode(char* memory);
MemoryLeakDetectorNode* getFirstLeak(MemLeakPeriod period);
MemoryLeakDetectorNode* getFirstLeakForAllocationStage(unsigned char allocation_stage);
MemoryLeakDetectorNode* getNextLeak(MemoryLeakDetectorNode* node, MemLeakPeriod period);
MemoryLeakDetectorNode* getNextLeakForAllocationStage(MemoryLeakDetectorNode* node, unsigned char allocation_stage);
MemoryLeakDetectorNode* getLeakFrom(MemoryLeakDetectorNode* node, MemLeakPeriod period);
MemoryLeakDetectorNode* getLeakForAllocationStageFrom(MemoryLeakDetectorNode* node, unsigned char allocation_stage);
size_t getTotalLeaks(MemLeakPeriod period);
void clearAllAccounting(MemLeakPeriod period);
bool isInPeriod(MemoryLeakDetectorNode* node, MemLeakPeriod period);
bool isInAllocationStage(MemoryLeakDetectorNode* node, unsigned char allocation_stage);
private:
MemoryLeakDetectorNode* head_;
};
struct MemoryLeakDetectorTable
{
void clearAllAccounting(MemLeakPeriod period);
void addNewNode(MemoryLeakDetectorNode* node);
MemoryLeakDetectorNode* retrieveNode(char* memory);
MemoryLeakDetectorNode* removeNode(char* memory);
size_t getTotalLeaks(MemLeakPeriod period);
MemoryLeakDetectorNode* getFirstLeak(MemLeakPeriod period);
MemoryLeakDetectorNode* getFirstLeakForAllocationStage(unsigned char allocation_stage);
MemoryLeakDetectorNode* getNextLeak(MemoryLeakDetectorNode* leak, MemLeakPeriod period);
MemoryLeakDetectorNode* getNextLeakForAllocationStage(MemoryLeakDetectorNode* leak, unsigned char allocation_stage);
private:
unsigned long hash(char* memory);
enum
{
hash_prime = MEMORY_LEAK_HASH_TABLE_SIZE
};
MemoryLeakDetectorList table_[hash_prime];
};
class MemoryLeakDetector
{
public:
MemoryLeakDetector(MemoryLeakFailure* reporter);
virtual ~MemoryLeakDetector();
void enable();
void disable();
void disableAllocationTypeChecking();
void enableAllocationTypeChecking();
void startChecking();
void stopChecking();
unsigned char getCurrentAllocationStage() const;
void increaseAllocationStage();
void decreaseAllocationStage();
const char* report(MemLeakPeriod period);
void markCheckingPeriodLeaksAsNonCheckingPeriod();
size_t totalMemoryLeaks(MemLeakPeriod period);
void clearAllAccounting(MemLeakPeriod period);
char* allocMemory(TestMemoryAllocator* allocator, size_t size, bool allocatNodesSeperately = false);
char* allocMemory(TestMemoryAllocator* allocator, size_t size,
const char* file, size_t line, bool allocatNodesSeperately = false);
void deallocMemory(TestMemoryAllocator* allocator, void* memory, bool allocatNodesSeperately = false);
void deallocMemory(TestMemoryAllocator* allocator, void* memory, const char* file, size_t line, bool allocatNodesSeperately = false);
void deallocAllMemoryInCurrentAllocationStage();
char* reallocMemory(TestMemoryAllocator* allocator, char* memory, size_t size, const char* file, size_t line, bool allocatNodesSeperately = false);
void invalidateMemory(char* memory);
void removeMemoryLeakInformationWithoutCheckingOrDeallocatingTheMemoryButDeallocatingTheAccountInformation(TestMemoryAllocator* allocator, void* memory, bool allocatNodesSeperately);
enum
{
#ifdef CPPUTEST_DISABLE_MEM_CORRUPTION_CHECK
memory_corruption_buffer_size = 0
#else
memory_corruption_buffer_size = 3
#endif
};
unsigned getCurrentAllocationNumber();
SimpleMutex* getMutex(void);
private:
MemoryLeakFailure* reporter_;
MemLeakPeriod current_period_;
MemoryLeakOutputStringBuffer outputBuffer_;
MemoryLeakDetectorTable memoryTable_;
bool doAllocationTypeChecking_;
unsigned allocationSequenceNumber_;
unsigned char current_allocation_stage_;
SimpleMutex* mutex_;
char* allocateMemoryWithAccountingInformation(TestMemoryAllocator* allocator, size_t size, const char* file, size_t line, bool allocatNodesSeperately);
char* reallocateMemoryWithAccountingInformation(TestMemoryAllocator* allocator, char* memory, size_t size, const char* file, size_t line, bool allocatNodesSeperately);
MemoryLeakDetectorNode* createMemoryLeakAccountingInformation(TestMemoryAllocator* allocator, size_t size, char* memory, bool allocatNodesSeperately);
bool validMemoryCorruptionInformation(char* memory);
bool matchingAllocation(TestMemoryAllocator *alloc_allocator, TestMemoryAllocator *free_allocator);
void storeLeakInformation(MemoryLeakDetectorNode * node, char *new_memory, size_t size, TestMemoryAllocator *allocator, const char *file, size_t line);
void ConstructMemoryLeakReport(MemLeakPeriod period);
size_t sizeOfMemoryWithCorruptionInfo(size_t size);
MemoryLeakDetectorNode* getNodeFromMemoryPointer(char* memory, size_t size);
char* reallocateMemoryAndLeakInformation(TestMemoryAllocator* allocator, char* memory, size_t size, const char* file, size_t line, bool allocatNodesSeperately);
void addMemoryCorruptionInformation(char* memory);
void checkForCorruption(MemoryLeakDetectorNode* node, const char* file, size_t line, TestMemoryAllocator* allocator, bool allocateNodesSeperately);
};
#endif

View file

@ -0,0 +1,68 @@
/*
* This file can be used to get extra debugging information about memory leaks in your production code.
* It defines a preprocessor macro for malloc. This will pass additional information to the
* malloc and this will give the line/file information of the memory leaks in your code.
*
* You can use this by including this file to all your production code. When using gcc, you can use
* the -include file to do this for you.
*
*/
#include "CppUTestConfig.h"
#if CPPUTEST_USE_MEM_LEAK_DETECTION
/* This prevents the declaration from done twice and makes sure the file only #defines malloc, so it can be included anywhere */
#ifndef CPPUTEST_USE_MALLOC_MACROS
#ifdef __cplusplus
extern "C"
{
#endif
extern void* cpputest_malloc_location(size_t size, const char* file, size_t line);
extern void* cpputest_calloc_location(size_t count, size_t size, const char* file, size_t line);
extern void* cpputest_realloc_location(void *, size_t, const char* file, size_t line);
extern void cpputest_free_location(void* buffer, const char* file, size_t line);
#ifdef __cplusplus
}
#endif
extern void crash_on_allocation_number(unsigned number);
#define malloc(a) cpputest_malloc_location(a, __FILE__, __LINE__)
#define calloc(a, b) cpputest_calloc_location(a, b, __FILE__, __LINE__)
#define realloc(a, b) cpputest_realloc_location(a, b, __FILE__, __LINE__)
#define free(a) cpputest_free_location(a, __FILE__, __LINE__)
#define CPPUTEST_USE_MALLOC_MACROS 1
#endif /* CPPUTEST_USE_MALLOC_MACROS */
/* This prevents strdup macros to get defined, unless it has been enabled by the user or generated config */
#ifdef CPPUTEST_HAVE_STRDUP
/* This prevents the declaration from done twice and makes sure the file only #defines strdup, so it can be included anywhere */
#ifndef CPPUTEST_USE_STRDUP_MACROS
#ifdef __cplusplus
extern "C"
{
#endif
extern char* cpputest_strdup_location(const char* str, const char* file, size_t line);
extern char* cpputest_strndup_location(const char* str, size_t n, const char* file, size_t line);
#ifdef __cplusplus
}
#endif
#define strdup(str) cpputest_strdup_location(str, __FILE__, __LINE__)
#define strndup(str, n) cpputest_strndup_location(str, n, __FILE__, __LINE__)
#define CPPUTEST_USE_STRDUP_MACROS 1
#endif /* CPPUTEST_USE_STRDUP_MACROS */
#endif /* CPPUTEST_HAVE_STRDUP */
#endif /* CPPUTEST_USE_MEM_LEAK_DETECTION */

View file

@ -0,0 +1,95 @@
/*
* This file can be used to get extra debugging information about memory leaks in your production code.
* It defines a preprocessor macro for operator new. This will pass additional information to the
* operator new and this will give the line/file information of the memory leaks in your code.
*
* You can use this by including this file to all your production code. When using gcc, you can use
* the -include file to do this for you.
*
* Warning: Using the new macro can cause a conflict with newly declared operator news. This can be
* resolved by:
* 1. #undef operator new before including this file
* 2. Including the files that override operator new before this file.
* This can be done by creating your own NewMacros.h file that includes your operator new overrides
* and THEN this file.
*
* STL (or StdC++ lib) also does overrides for operator new. Therefore, you'd need to include the STL
* files *before* this file too.
*
*/
#include "CppUTestConfig.h"
/* Make sure that mem leak detection is on and that this is being included from a C++ file */
#if CPPUTEST_USE_MEM_LEAK_DETECTION && defined(__cplusplus)
/* This #ifndef prevents <new> from being included twice and enables the file to be included anywhere */
#ifndef CPPUTEST_USE_NEW_MACROS
#if CPPUTEST_USE_STD_CPP_LIB
#ifdef CPPUTEST_USE_STRDUP_MACROS
#if CPPUTEST_USE_STRDUP_MACROS == 1
/*
* Some platforms (OSx, i.e.) will get <string.h> or <cstring> included when using <memory> header,
* in order to avoid conflicts with strdup and strndup macros defined by MemoryLeakDetectorMallocMacros.h
* we will undefined those macros, include the C++ headers and then reinclude MemoryLeakDetectorMallocMacros.h.
* The check `#if CPPUTEST_USE_STRDUP_MACROS` will ensure we only include MemoryLeakDetectorMallocMacros.h if
* it has already been includeded earlier.
*/
#undef strdup
#undef strndup
#undef CPPUTEST_USE_STRDUP_MACROS
#define __CPPUTEST_REINCLUDE_MALLOC_MEMORY_LEAK_DETECTOR
#endif
#endif
#include <new>
#include <memory>
#include <string>
#ifdef __CPPUTEST_REINCLUDE_MALLOC_MEMORY_LEAK_DETECTOR
#include "MemoryLeakDetectorMallocMacros.h"
#endif
#endif
/* Some toolkits, e.g. MFC, provide their own new overloads with signature (size_t, const char *, int).
* If we don't provide them, in addition to the (size_t, const char *, size_t) version, we don't get to
* know about all allocations and report freeing of unallocated blocks. Hence, provide both overloads.
*/
void* operator new(size_t size, const char* file, int line) UT_THROW (std::bad_alloc);
void* operator new(size_t size, const char* file, size_t line) UT_THROW (std::bad_alloc);
void* operator new[](size_t size, const char* file, int line) UT_THROW (std::bad_alloc);
void* operator new[](size_t size, const char* file, size_t line) UT_THROW (std::bad_alloc);
void* operator new(size_t size) UT_THROW(std::bad_alloc);
void* operator new[](size_t size) UT_THROW(std::bad_alloc);
void operator delete(void* mem, const char* file, int line) UT_NOTHROW;
void operator delete(void* mem, const char* file, size_t line) UT_NOTHROW;
void operator delete[](void* mem, const char* file, int line) UT_NOTHROW;
void operator delete[](void* mem, const char* file, size_t line) UT_NOTHROW;
void operator delete(void* mem) UT_NOTHROW;
void operator delete[](void* mem) UT_NOTHROW;
#if __cplusplus >= 201402L
void operator delete (void* mem, size_t size) UT_NOTHROW;
void operator delete[] (void* mem, size_t size) UT_NOTHROW;
#endif
#endif
#ifdef __clang__
#pragma clang diagnostic push
#if (__clang_major__ == 3 && __clang_minor__ >= 6) || __clang_major__ >= 4
#pragma clang diagnostic ignored "-Wkeyword-macro"
#endif
#endif
#define new new(__FILE__, __LINE__)
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#define CPPUTEST_USE_NEW_MACROS 1
#endif

View file

@ -0,0 +1,89 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_MemoryLeakWarningPlugin_h
#define D_MemoryLeakWarningPlugin_h
#include "TestPlugin.h"
#include "MemoryLeakDetectorNewMacros.h"
#define IGNORE_ALL_LEAKS_IN_TEST() if (MemoryLeakWarningPlugin::getFirstPlugin()) MemoryLeakWarningPlugin::getFirstPlugin()->ignoreAllLeaksInTest()
#define EXPECT_N_LEAKS(n) if (MemoryLeakWarningPlugin::getFirstPlugin()) MemoryLeakWarningPlugin::getFirstPlugin()->expectLeaksInTest(n)
extern void crash_on_allocation_number(unsigned alloc_number);
class MemoryLeakDetector;
class MemoryLeakFailure;
class MemoryLeakWarningPlugin: public TestPlugin
{
public:
MemoryLeakWarningPlugin(const SimpleString& name, MemoryLeakDetector* localDetector = NULLPTR);
virtual ~MemoryLeakWarningPlugin() _destructor_override;
virtual void preTestAction(UtestShell& test, TestResult& result) _override;
virtual void postTestAction(UtestShell& test, TestResult& result) _override;
virtual const char* FinalReport(size_t toBeDeletedLeaks = 0);
void ignoreAllLeaksInTest();
void expectLeaksInTest(size_t n);
void destroyGlobalDetectorAndTurnOffMemoryLeakDetectionInDestructor(bool des);
MemoryLeakDetector* getMemoryLeakDetector();
static MemoryLeakWarningPlugin* getFirstPlugin();
static MemoryLeakDetector* getGlobalDetector();
static MemoryLeakFailure* getGlobalFailureReporter();
static void setGlobalDetector(MemoryLeakDetector* detector, MemoryLeakFailure* reporter);
static void destroyGlobalDetector();
static void turnOffNewDeleteOverloads();
static void turnOnDefaultNotThreadSafeNewDeleteOverloads();
static void turnOnThreadSafeNewDeleteOverloads();
static bool areNewDeleteOverloaded();
static void saveAndDisableNewDeleteOverloads();
static void restoreNewDeleteOverloads();
private:
MemoryLeakDetector* memLeakDetector_;
bool ignoreAllWarnings_;
bool destroyGlobalDetectorAndTurnOfMemoryLeakDetectionInDestructor_;
size_t expectedLeaks_;
size_t failureCount_;
static MemoryLeakWarningPlugin* firstPlugin_;
};
extern void* cpputest_malloc_location_with_leak_detection(size_t size, const char* file, size_t line);
extern void* cpputest_realloc_location_with_leak_detection(void* memory, size_t size, const char* file, size_t line);
extern void cpputest_free_location_with_leak_detection(void* buffer, const char* file, size_t line);
#endif

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PLATFORMSPECIFICFUNCTIONS_H_
#define PLATFORMSPECIFICFUNCTIONS_H_
#include "CppUTest/TestOutput.h"
TestOutput::WorkingEnvironment PlatformSpecificGetWorkingEnvironment();
class TestPlugin;
extern void (*PlatformSpecificRunTestInASeperateProcess)(UtestShell* shell, TestPlugin* plugin, TestResult* result);
extern int (*PlatformSpecificFork)(void);
extern int (*PlatformSpecificWaitPid)(int pid, int* status, int options);
/* Platform specific interface we use in order to minimize dependencies with LibC.
* This enables porting to different embedded platforms.
*
*/
#include "CppUTest/PlatformSpecificFunctions_c.h"
#endif

View file

@ -0,0 +1,93 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/******************************************************************************
*
* PlatformSpecificFunctions_c.H
*
* Provides an interface for when working with pure C
*
*******************************************************************************/
#ifndef PLATFORMSPECIFICFUNCTIONS_C_H_
#define PLATFORMSPECIFICFUNCTIONS_C_H_
#ifdef __cplusplus
extern "C" {
#endif
/* Jumping operations. They manage their own jump buffers */
extern int (*PlatformSpecificSetJmp)(void (*function) (void*), void* data);
extern void (*PlatformSpecificLongJmp)(void);
extern void (*PlatformSpecificRestoreJumpBuffer)(void);
/* Time operations */
extern long (*GetPlatformSpecificTimeInMillis)(void);
extern const char* (*GetPlatformSpecificTimeString)(void);
/* String operations */
extern int (*PlatformSpecificVSNprintf)(char *str, size_t size, const char* format, va_list va_args_list);
/* Misc */
extern double (*PlatformSpecificFabs)(double d);
extern int (*PlatformSpecificIsNan)(double d);
extern int (*PlatformSpecificIsInf)(double d);
extern int (*PlatformSpecificAtExit)(void(*func)(void));
/* IO operations */
typedef void* PlatformSpecificFile;
extern PlatformSpecificFile (*PlatformSpecificFOpen)(const char* filename, const char* flag);
extern void (*PlatformSpecificFPuts)(const char* str, PlatformSpecificFile file);
extern void (*PlatformSpecificFClose)(PlatformSpecificFile file);
extern int (*PlatformSpecificPutchar)(int c);
extern void (*PlatformSpecificFlush)(void);
/* Random operations */
extern void (*PlatformSpecificSrand)(unsigned int);
extern int (*PlatformSpecificRand)(void);
/* Dynamic Memory operations */
extern void* (*PlatformSpecificMalloc)(size_t size);
extern void* (*PlatformSpecificRealloc)(void* memory, size_t size);
extern void (*PlatformSpecificFree)(void* memory);
extern void* (*PlatformSpecificMemCpy)(void* s1, const void* s2, size_t size);
extern void* (*PlatformSpecificMemset)(void* mem, int c, size_t size);
typedef void* PlatformSpecificMutex;
extern PlatformSpecificMutex (*PlatformSpecificMutexCreate)(void);
extern void (*PlatformSpecificMutexLock)(PlatformSpecificMutex mtx);
extern void (*PlatformSpecificMutexUnlock)(PlatformSpecificMutex mtx);
extern void (*PlatformSpecificMutexDestroy)(PlatformSpecificMutex mtx);
#ifdef __cplusplus
}
#endif
#endif /* PLATFORMSPECIFICFUNCTIONS_C_H_ */

View file

@ -0,0 +1,54 @@
/*
* Copyright (c) 2014, Michael Feathers, James Grenning, Bas Vodde and Chen YewMing
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_SimpleMutex_h
#define D_SimpleMutex_h
#include "CppUTest/PlatformSpecificFunctions.h"
class SimpleMutex
{
public:
SimpleMutex(void);
~SimpleMutex(void);
void Lock(void);
void Unlock(void);
private:
PlatformSpecificMutex psMtx;
};
class ScopedMutexLock
{
public:
ScopedMutexLock(SimpleMutex *);
~ScopedMutexLock(void);
private:
SimpleMutex * mutex;
};
#endif

View file

@ -0,0 +1,244 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
///////////////////////////////////////////////////////////////////////////////
//
// SIMPLESTRING.H
//
// One of the design goals of CppUnitLite is to compilation with very old C++
// compilers. For that reason, the simple string class that provides
// only the operations needed in CppUnitLite.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef D_SimpleString_h
#define D_SimpleString_h
#include "StandardCLibrary.h"
class SimpleStringCollection;
class TestMemoryAllocator;
class SimpleString
{
friend bool operator==(const SimpleString& left, const SimpleString& right);
friend bool operator!=(const SimpleString& left, const SimpleString& right);
public:
SimpleString(const char *value = "");
SimpleString(const char *value, size_t repeatCount);
SimpleString(const SimpleString& other);
~SimpleString();
SimpleString& operator=(const SimpleString& other);
SimpleString operator+(const SimpleString&) const;
SimpleString& operator+=(const SimpleString&);
SimpleString& operator+=(const char*);
static const size_t npos = (size_t) -1;
char at(size_t pos) const;
size_t find(char ch) const;
size_t findFrom(size_t starting_position, char ch) const;
bool contains(const SimpleString& other) const;
bool containsNoCase(const SimpleString& other) const;
bool startsWith(const SimpleString& other) const;
bool endsWith(const SimpleString& other) const;
void split(const SimpleString& split,
SimpleStringCollection& outCollection) const;
bool equalsNoCase(const SimpleString& str) const;
size_t count(const SimpleString& str) const;
void replace(char to, char with);
void replace(const char* to, const char* with);
SimpleString lowerCase() const;
SimpleString subString(size_t beginPos) const;
SimpleString subString(size_t beginPos, size_t amount) const;
SimpleString subStringFromTill(char startChar, char lastExcludedChar) const;
void copyToBuffer(char* buffer, size_t bufferSize) const;
SimpleString printable() const;
const char *asCharString() const;
size_t size() const;
bool isEmpty() const;
static void padStringsToSameLength(SimpleString& str1, SimpleString& str2, char ch);
static TestMemoryAllocator* getStringAllocator();
static void setStringAllocator(TestMemoryAllocator* allocator);
static int AtoI(const char*str);
static unsigned AtoU(const char*str);
static int StrCmp(const char* s1, const char* s2);
static size_t StrLen(const char*);
static int StrNCmp(const char* s1, const char* s2, size_t n);
static char* StrNCpy(char* s1, const char* s2, size_t n);
static const char* StrStr(const char* s1, const char* s2);
static char ToLower(char ch);
static int MemCmp(const void* s1, const void *s2, size_t n);
static char* allocStringBuffer(size_t size, const char* file, size_t line);
static void deallocStringBuffer(char* str, size_t size, const char* file, size_t line);
private:
const char* getBuffer() const;
void deallocateInternalBuffer();
void setInternalBufferAsEmptyString();
void setInternalBufferToNewBuffer(size_t bufferSize);
void setInternalBufferTo(char* buffer, size_t bufferSize);
void copyBufferToNewInternalBuffer(const char* otherBuffer);
void copyBufferToNewInternalBuffer(const char* otherBuffer, size_t bufferSize);
void copyBufferToNewInternalBuffer(const SimpleString& otherBuffer);
char *buffer_;
size_t bufferSize_;
static TestMemoryAllocator* stringAllocator_;
char* getEmptyString() const;
static char* copyToNewBuffer(const char* bufferToCopy, size_t bufferSize);
static bool isDigit(char ch);
static bool isSpace(char ch);
static bool isUpper(char ch);
static bool isControl(char ch);
static bool isControlWithShortEscapeSequence(char ch);
size_t getPrintableSize() const;
};
class SimpleStringCollection
{
public:
SimpleStringCollection();
~SimpleStringCollection();
void allocate(size_t size);
size_t size() const;
SimpleString& operator[](size_t index);
private:
SimpleString* collection_;
SimpleString empty_;
size_t size_;
void operator =(SimpleStringCollection&);
SimpleStringCollection(SimpleStringCollection&);
};
class GlobalSimpleStringAllocatorStash
{
public:
GlobalSimpleStringAllocatorStash();
void save();
void restore();
private:
TestMemoryAllocator* originalAllocator_;
};
class MemoryAccountant;
class AccountingTestMemoryAllocator;
class GlobalSimpleStringMemoryAccountant
{
public:
GlobalSimpleStringMemoryAccountant();
~GlobalSimpleStringMemoryAccountant();
void useCacheSizes(size_t cacheSizes[], size_t length);
void start();
void stop();
SimpleString report();
AccountingTestMemoryAllocator* getAllocator();
private:
void restoreAllocator();
AccountingTestMemoryAllocator* allocator_;
MemoryAccountant* accountant_;
};
SimpleString StringFrom(bool value);
SimpleString StringFrom(const void* value);
SimpleString StringFrom(void (*value)());
SimpleString StringFrom(char value);
SimpleString StringFrom(const char *value);
SimpleString StringFromOrNull(const char * value);
SimpleString StringFrom(int value);
SimpleString StringFrom(unsigned int value);
SimpleString StringFrom(long value);
SimpleString StringFrom(unsigned long value);
SimpleString StringFrom(cpputest_longlong value);
SimpleString StringFrom(cpputest_ulonglong value);
SimpleString HexStringFrom(unsigned int value);
SimpleString HexStringFrom(int value);
SimpleString HexStringFrom(signed char value);
SimpleString HexStringFrom(long value);
SimpleString HexStringFrom(unsigned long value);
SimpleString HexStringFrom(cpputest_longlong value);
SimpleString HexStringFrom(cpputest_ulonglong value);
SimpleString HexStringFrom(const void* value);
SimpleString HexStringFrom(void (*value)());
SimpleString StringFrom(double value, int precision = 6);
SimpleString StringFrom(const SimpleString& other);
SimpleString StringFromFormat(const char* format, ...) _check_format_(printf, 1, 2);
SimpleString VStringFromFormat(const char* format, va_list args);
SimpleString StringFromBinary(const unsigned char* value, size_t size);
SimpleString StringFromBinaryOrNull(const unsigned char* value, size_t size);
SimpleString StringFromBinaryWithSize(const unsigned char* value, size_t size);
SimpleString StringFromBinaryWithSizeOrNull(const unsigned char* value, size_t size);
SimpleString StringFromMaskedBits(unsigned long value, unsigned long mask, size_t byteCount);
SimpleString StringFromOrdinalNumber(unsigned int number);
SimpleString BracketsFormattedHexStringFrom(int value);
SimpleString BracketsFormattedHexStringFrom(unsigned int value);
SimpleString BracketsFormattedHexStringFrom(long value);
SimpleString BracketsFormattedHexStringFrom(unsigned long value);
SimpleString BracketsFormattedHexStringFrom(cpputest_longlong value);
SimpleString BracketsFormattedHexStringFrom(cpputest_ulonglong value);
SimpleString BracketsFormattedHexStringFrom(signed char value);
SimpleString BracketsFormattedHexString(SimpleString hexString);
SimpleString PrintableStringFromOrNull(const char * expected);
/*
* ARM compiler has only partial support for C++11.
* Specifically nullptr_t is not officially supported
*/
#if __cplusplus > 199711L && !defined __arm__ && CPPUTEST_USE_STD_CPP_LIB
SimpleString StringFrom(const std::nullptr_t value);
#endif
#if CPPUTEST_USE_STD_CPP_LIB
SimpleString StringFrom(const std::string& other);
#endif
#endif

View file

@ -0,0 +1,110 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_SimpleStringInternalCache_h
#define D_SimpleStringInternalCache_h
#include "CppUTest/TestMemoryAllocator.h"
struct SimpleStringMemoryBlock;
struct SimpleStringInternalCacheNode;
class SimpleStringInternalCache
{
public:
SimpleStringInternalCache();
~SimpleStringInternalCache();
void setAllocator(TestMemoryAllocator* allocator);
char* alloc(size_t size);
void dealloc(char* memory, size_t size);
bool hasFreeBlocksOfSize(size_t size);
void clearCache();
void clearAllIncludingCurrentlyUsedMemory();
private:
void printDeallocatingUnknownMemory(char* memory);
enum { amountOfInternalCacheNodes = 5};
bool isCached(size_t size);
size_t getIndexForCache(size_t size);
SimpleStringInternalCacheNode* getCacheNodeFromSize(size_t size);
SimpleStringInternalCacheNode* createInternalCacheNodes();
void destroyInternalCacheNode(SimpleStringInternalCacheNode * node);
SimpleStringMemoryBlock* createSimpleStringMemoryBlock(size_t sizeOfString, SimpleStringMemoryBlock* next);
void destroySimpleStringMemoryBlock(SimpleStringMemoryBlock * block, size_t size);
void destroySimpleStringMemoryBlockList(SimpleStringMemoryBlock * block, size_t size);
SimpleStringMemoryBlock* reserveCachedBlockFrom(SimpleStringInternalCacheNode* node);
void releaseCachedBlockFrom(char* memory, SimpleStringInternalCacheNode* node);
void releaseNonCachedMemory(char* memory, size_t size);
SimpleStringMemoryBlock* allocateNewCacheBlockFrom(SimpleStringInternalCacheNode* node);
SimpleStringMemoryBlock* addToSimpleStringMemoryBlockList(SimpleStringMemoryBlock* newBlock, SimpleStringMemoryBlock* previousHead);
TestMemoryAllocator* allocator_;
SimpleStringInternalCacheNode* cache_;
SimpleStringMemoryBlock* nonCachedAllocations_;
bool hasWarnedAboutDeallocations;
};
class SimpleStringCacheAllocator : public TestMemoryAllocator
{
public:
SimpleStringCacheAllocator(SimpleStringInternalCache& cache, TestMemoryAllocator* previousAllocator);
virtual ~SimpleStringCacheAllocator() _destructor_override;
virtual char* alloc_memory(size_t size, const char* file, size_t line) _override;
virtual void free_memory(char* memory, size_t size, const char* file, size_t line) _override;
virtual const char* name() const _override;
virtual const char* alloc_name() const _override;
virtual const char* free_name() const _override;
virtual TestMemoryAllocator* actualAllocator() _override;
TestMemoryAllocator* originalAllocator();
private:
SimpleStringInternalCache& cache_;
TestMemoryAllocator* originalAllocator_;
};
class GlobalSimpleStringCache
{
SimpleStringCacheAllocator* allocator_;
SimpleStringInternalCache cache_;
public:
GlobalSimpleStringCache();
~GlobalSimpleStringCache();
TestMemoryAllocator* getAllocator();
};
#endif

View file

@ -0,0 +1,96 @@
/* Must include this first to ensure the StandardC include in CppUTestConfig still happens at the right moment */
#include "CppUTestConfig.h"
#ifndef STANDARDCLIBRARY_H_
#define STANDARDCLIBRARY_H_
#if CPPUTEST_USE_STD_C_LIB
/* Needed for size_t */
#include <stddef.h>
/* Sometimes the C++ library does an #undef in stdlib of malloc and free. We want to prevent that */
#ifdef __cplusplus
#if CPPUTEST_USE_STD_CPP_LIB
#include <cstdlib>
#include <string>
#endif
#endif
/* Needed for malloc */
#include <stdlib.h>
/* Needed for std::nullptr */
#ifdef __cplusplus
#if CPPUTEST_USE_STD_CPP_LIB
#include <cstddef>
#endif
#endif
/* Needed for ... */
#include <stdarg.h>
/* Kludge to get a va_copy in VC++ V6 and in GCC 98 */
#ifndef va_copy
#ifdef __GNUC__
#define va_copy __va_copy
#else
#define va_copy(copy, original) copy = original;
#endif
#endif
/* Needed for some detection of long long and 64 bit */
#include <limits.h>
/* Needed to ensure that string.h is included prior to strdup redefinition */
#ifdef CPPUTEST_HAVE_STRING_H
#include <string.h>
#endif
#else
#ifdef __KERNEL__
/* Unfinished and not working! Hacking hacking hacking. Why bother make the header files C++ safe! */
#define false kernel_false
#define true kernel_true
#define bool kernel_bool
#define new kernel_new
#define _Bool int
#include <linux/acpi.h>
#include <linux/types.h>
#undef false
#undef true
#undef bool
#undef new
#else
/*
* #warning "These definitions in StandardCLibrary.h are pure (educated, from linux kernel) guesses at the moment. Replace with your platform includes."
* Not on as warning are as errors :P
*/
#ifdef __SIZE_TYPE__
typedef __SIZE_TYPE__ size_t;
#else
typedef long unsigned int size_t;
#endif
#define NULL (0)
extern void* malloc(size_t);
extern void free(void *);
#define _bnd(X, bnd) (((sizeof (X)) + (bnd)) & (~(bnd)))
#define va_list __builtin_va_list
#define va_copy __builtin_va_copy
#define va_start __builtin_va_start
#define va_end __builtin_va_end
#endif
#endif
#endif

View file

@ -0,0 +1,28 @@
#ifndef D_TeamCityTestOutput_h
#define D_TeamCityTestOutput_h
#include "TestOutput.h"
#include "SimpleString.h"
class TeamCityTestOutput: public ConsoleTestOutput
{
public:
TeamCityTestOutput(void);
virtual ~TeamCityTestOutput(void) _destructor_override;
virtual void printCurrentTestStarted(const UtestShell& test) _override;
virtual void printCurrentTestEnded(const TestResult& res) _override;
virtual void printCurrentGroupStarted(const UtestShell& test) _override;
virtual void printCurrentGroupEnded(const TestResult& res) _override;
virtual void printFailure(const TestFailure& failure) _override;
protected:
private:
void printEscaped(const char* s);
const UtestShell *currtest_;
SimpleString currGroup_;
};
#endif

View file

@ -0,0 +1,185 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
///////////////////////////////////////////////////////////////////////////////
//
// Failure is a class which holds information for a specific
// test failure. It can be overriden for more complex failure messages
//
///////////////////////////////////////////////////////////////////////////////
#ifndef D_TestFailure_H
#define D_TestFailure_H
#include "SimpleString.h"
class UtestShell;
class TestOutput;
class TestFailure
{
public:
TestFailure(UtestShell*, const char* fileName, size_t lineNumber, const SimpleString& theMessage);
TestFailure(UtestShell*, const SimpleString& theMessage);
TestFailure(UtestShell*, const char* fileName, size_t lineNumber);
TestFailure(const TestFailure&);
virtual ~TestFailure();
virtual SimpleString getFileName() const;
virtual SimpleString getTestName() const;
virtual SimpleString getTestNameOnly() const;
virtual size_t getFailureLineNumber() const;
virtual SimpleString getMessage() const;
virtual SimpleString getTestFileName() const;
virtual size_t getTestLineNumber() const;
bool isOutsideTestFile() const;
bool isInHelperFunction() const;
protected:
SimpleString createButWasString(const SimpleString& expected, const SimpleString& actual);
SimpleString createDifferenceAtPosString(const SimpleString& actual, size_t offset, size_t reportedPosition);
SimpleString createUserText(const SimpleString& text);
SimpleString testName_;
SimpleString testNameOnly_;
SimpleString fileName_;
size_t lineNumber_;
SimpleString testFileName_;
size_t testLineNumber_;
SimpleString message_;
TestFailure& operator=(const TestFailure&);
};
class EqualsFailure: public TestFailure
{
public:
EqualsFailure(UtestShell*, const char* fileName, size_t lineNumber, const char* expected, const char* actual, const SimpleString& text);
EqualsFailure(UtestShell*, const char* fileName, size_t lineNumber, const SimpleString& expected, const SimpleString& actual, const SimpleString& text);
};
class DoublesEqualFailure: public TestFailure
{
public:
DoublesEqualFailure(UtestShell*, const char* fileName, size_t lineNumber, double expected, double actual, double threshold, const SimpleString& text);
};
class CheckEqualFailure : public TestFailure
{
public:
CheckEqualFailure(UtestShell* test, const char* fileName, size_t lineNumber, const SimpleString& expected, const SimpleString& actual, const SimpleString& text);
};
class ComparisonFailure : public TestFailure
{
public:
ComparisonFailure(UtestShell* test, const char *fileName, size_t lineNumber, const SimpleString& checkString, const SimpleString& comparisonString, const SimpleString& text);
};
class ContainsFailure: public TestFailure
{
public:
ContainsFailure(UtestShell*, const char* fileName, size_t lineNumber, const SimpleString& expected, const SimpleString& actual, const SimpleString& text);
};
class CheckFailure : public TestFailure
{
public:
CheckFailure(UtestShell* test, const char* fileName, size_t lineNumber, const SimpleString& checkString, const SimpleString& conditionString, const SimpleString& textString = "");
};
class FailFailure : public TestFailure
{
public:
FailFailure(UtestShell* test, const char* fileName, size_t lineNumber, const SimpleString& message);
};
class LongsEqualFailure : public TestFailure
{
public:
LongsEqualFailure(UtestShell* test, const char* fileName, size_t lineNumber, long expected, long actual, const SimpleString& text);
};
class UnsignedLongsEqualFailure : public TestFailure
{
public:
UnsignedLongsEqualFailure(UtestShell* test, const char* fileName, size_t lineNumber, unsigned long expected, unsigned long actual, const SimpleString& text);
};
class LongLongsEqualFailure : public TestFailure
{
public:
LongLongsEqualFailure(UtestShell* test, const char* fileName, size_t lineNumber, cpputest_longlong expected, cpputest_longlong actual, const SimpleString& text);
};
class UnsignedLongLongsEqualFailure : public TestFailure
{
public:
UnsignedLongLongsEqualFailure(UtestShell* test, const char* fileName, size_t lineNumber, cpputest_ulonglong expected, cpputest_ulonglong actual, const SimpleString& text);
};
class SignedBytesEqualFailure : public TestFailure
{
public:
SignedBytesEqualFailure (UtestShell* test, const char* fileName, size_t lineNumber, signed char expected, signed char actual, const SimpleString& text);
};
class StringEqualFailure : public TestFailure
{
public:
StringEqualFailure(UtestShell* test, const char* fileName, size_t lineNumber, const char* expected, const char* actual, const SimpleString& text);
};
class StringEqualNoCaseFailure : public TestFailure
{
public:
StringEqualNoCaseFailure(UtestShell* test, const char* fileName, size_t lineNumber, const char* expected, const char* actual, const SimpleString& text);
};
class BinaryEqualFailure : public TestFailure
{
public:
BinaryEqualFailure(UtestShell* test, const char* fileName, size_t lineNumber, const unsigned char* expected, const unsigned char* actual, size_t size, const SimpleString& text);
};
class BitsEqualFailure : public TestFailure
{
public:
BitsEqualFailure(UtestShell* test, const char* fileName, size_t lineNumber, unsigned long expected, unsigned long actual, unsigned long mask, size_t byteCount, const SimpleString& text);
};
class FeatureUnsupportedFailure : public TestFailure
{
public:
FeatureUnsupportedFailure(UtestShell* test, const char* fileName, size_t lineNumber, const SimpleString& featureName, const SimpleString& text);
};
#endif

View file

@ -0,0 +1,63 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef TESTFILTER_H_
#define TESTFILTER_H_
#include "SimpleString.h"
class TestFilter
{
public:
TestFilter();
TestFilter(const char* filter);
TestFilter(const SimpleString& filter);
TestFilter* add(TestFilter* filter);
TestFilter* getNext() const;
bool match(const SimpleString& name) const;
void strictMatching();
void invertMatching();
bool operator==(const TestFilter& filter) const;
bool operator!=(const TestFilter& filter) const;
SimpleString asString() const;
private:
SimpleString filter_;
bool strictMatching_;
bool invertMatching_;
TestFilter* next_;
};
SimpleString StringFrom(const TestFilter& filter);
#endif

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_TestHarness_h
#define D_TestHarness_h
#include "CppUTestConfig.h"
/* original value was 9973 which works well with large programs. Now set to smaller since it takes
* a lot of memory in embedded apps. Change it if you experience the memory leak detector to be slow.
*/
#define MEMORY_LEAK_HASH_TABLE_SIZE 73
#include "Utest.h"
#include "UtestMacros.h"
#include "SimpleString.h"
#include "TestResult.h"
#include "TestFailure.h"
#include "TestPlugin.h"
#include "MemoryLeakWarningPlugin.h"
#endif

View file

@ -0,0 +1,251 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/******************************************************************************
*
* Provides an interface for when working with pure C
*
*******************************************************************************/
#ifndef D_TestHarness_c_h
#define D_TestHarness_c_h
#include "CppUTestConfig.h"
#define CHECK_EQUAL_C_BOOL(expected,actual) \
CHECK_EQUAL_C_BOOL_LOCATION(expected,actual,NULLPTR,__FILE__,__LINE__)
#define CHECK_EQUAL_C_BOOL_TEXT(expected,actual,text) \
CHECK_EQUAL_C_BOOL_LOCATION(expected,actual,text,__FILE__,__LINE__)
#define CHECK_EQUAL_C_INT(expected,actual) \
CHECK_EQUAL_C_INT_LOCATION(expected,actual,NULLPTR,__FILE__,__LINE__)
#define CHECK_EQUAL_C_INT_TEXT(expected,actual,text) \
CHECK_EQUAL_C_INT_LOCATION(expected,actual,text,__FILE__,__LINE__)
#define CHECK_EQUAL_C_UINT(expected,actual) \
CHECK_EQUAL_C_UINT_LOCATION(expected,actual,NULLPTR,__FILE__,__LINE__)
#define CHECK_EQUAL_C_UINT_TEXT(expected,actual,text) \
CHECK_EQUAL_C_UINT_LOCATION(expected,actual,text,__FILE__,__LINE__)
#define CHECK_EQUAL_C_LONG(expected,actual) \
CHECK_EQUAL_C_LONG_LOCATION(expected,actual,NULLPTR,__FILE__,__LINE__)
#define CHECK_EQUAL_C_LONG_TEXT(expected,actual,text) \
CHECK_EQUAL_C_LONG_LOCATION(expected,actual,text,__FILE__,__LINE__)
#define CHECK_EQUAL_C_ULONG(expected,actual) \
CHECK_EQUAL_C_ULONG_LOCATION(expected,actual,NULLPTR,__FILE__,__LINE__)
#define CHECK_EQUAL_C_ULONG_TEXT(expected,actual,text) \
CHECK_EQUAL_C_ULONG_LOCATION(expected,actual,text,__FILE__,__LINE__)
#define CHECK_EQUAL_C_LONGLONG(expected,actual) \
CHECK_EQUAL_C_LONGLONG_LOCATION(expected,actual,NULLPTR,__FILE__,__LINE__)
#define CHECK_EQUAL_C_LONGLONG_TEXT(expected,actual,text) \
CHECK_EQUAL_C_LONGLONG_LOCATION(expected,actual,text,__FILE__,__LINE__)
#define CHECK_EQUAL_C_ULONGLONG(expected,actual) \
CHECK_EQUAL_C_ULONGLONG_LOCATION(expected,actual,NULLPTR,__FILE__,__LINE__)
#define CHECK_EQUAL_C_ULONGLONG_TEXT(expected,actual,text) \
CHECK_EQUAL_C_ULONGLONG_LOCATION(expected,actual,text,__FILE__,__LINE__)
#define CHECK_EQUAL_C_REAL(expected,actual,threshold) \
CHECK_EQUAL_C_REAL_LOCATION(expected,actual,threshold,NULLPTR,__FILE__,__LINE__)
#define CHECK_EQUAL_C_REAL_TEXT(expected,actual,threshold,text) \
CHECK_EQUAL_C_REAL_LOCATION(expected,actual,threshold,text,__FILE__,__LINE__)
#define CHECK_EQUAL_C_CHAR(expected,actual) \
CHECK_EQUAL_C_CHAR_LOCATION(expected,actual,NULLPTR,__FILE__,__LINE__)
#define CHECK_EQUAL_C_CHAR_TEXT(expected,actual,text) \
CHECK_EQUAL_C_CHAR_LOCATION(expected,actual,text,__FILE__,__LINE__)
#define CHECK_EQUAL_C_UBYTE(expected,actual) \
CHECK_EQUAL_C_UBYTE_LOCATION(expected,actual,NULLPTR,__FILE__,__LINE__)
#define CHECK_EQUAL_C_UBYTE_TEXT(expected,actual,text) \
CHECK_EQUAL_C_UBYTE_LOCATION(expected,actual,text,__FILE__,__LINE__)
#define CHECK_EQUAL_C_SBYTE(expected,actual) \
CHECK_EQUAL_C_SBYTE_LOCATION(expected,actual,NULLPTR,__FILE__,__LINE__)
#define CHECK_EQUAL_C_SBYTE_TEXT(expected,actual,text) \
CHECK_EQUAL_C_SBYTE_LOCATION(expected,actual,text,__FILE__,__LINE__)
#define CHECK_EQUAL_C_STRING(expected,actual) \
CHECK_EQUAL_C_STRING_LOCATION(expected,actual,NULLPTR,__FILE__,__LINE__)
#define CHECK_EQUAL_C_STRING_TEXT(expected,actual,text) \
CHECK_EQUAL_C_STRING_LOCATION(expected,actual,text,__FILE__,__LINE__)
#define CHECK_EQUAL_C_POINTER(expected,actual) \
CHECK_EQUAL_C_POINTER_LOCATION(expected,actual,NULLPTR,__FILE__,__LINE__)
#define CHECK_EQUAL_C_POINTER_TEXT(expected,actual,text) \
CHECK_EQUAL_C_POINTER_LOCATION(expected,actual,text,__FILE__,__LINE__)
#define CHECK_EQUAL_C_BITS(expected, actual, mask) \
CHECK_EQUAL_C_BITS_LOCATION(expected, actual, mask, sizeof(actual), NULLPTR, __FILE__, __LINE__)
#define CHECK_EQUAL_C_BITS_TEXT(expected, actual, mask, text) \
CHECK_EQUAL_C_BITS_LOCATION(expected, actual, mask, sizeof(actual), text, __FILE__, __LINE__)
#define FAIL_TEXT_C(text) \
FAIL_TEXT_C_LOCATION(text,__FILE__,__LINE__)
#define FAIL_C() \
FAIL_C_LOCATION(__FILE__,__LINE__)
#define CHECK_C(condition) \
CHECK_C_LOCATION(condition, #condition, NULLPTR, __FILE__,__LINE__)
#define CHECK_C_TEXT(condition, text) \
CHECK_C_LOCATION(condition, #condition, text, __FILE__, __LINE__)
/******************************************************************************
*
* TEST macros for in C.
*
*******************************************************************************/
/* For use in C file */
#define TEST_GROUP_C_SETUP(group_name) \
extern void group_##group_name##_setup_wrapper_c(void); \
void group_##group_name##_setup_wrapper_c()
#define TEST_GROUP_C_TEARDOWN(group_name) \
extern void group_##group_name##_teardown_wrapper_c(void); \
void group_##group_name##_teardown_wrapper_c()
#define TEST_C(group_name, test_name) \
extern void test_##group_name##_##test_name##_wrapper_c(void);\
void test_##group_name##_##test_name##_wrapper_c()
#define IGNORE_TEST_C(group_name, test_name) \
extern void ignore_##group_name##_##test_name##_wrapper_c(void);\
void ignore_##group_name##_##test_name##_wrapper_c()
/* For use in C++ file */
#define TEST_GROUP_C_WRAPPER(group_name) \
extern "C" void group_##group_name##_setup_wrapper_c(void); \
extern "C" void group_##group_name##_teardown_wrapper_c(void); \
TEST_GROUP(group_name)
#define TEST_GROUP_C_SETUP_WRAPPER(group_name) \
void setup() _override { \
group_##group_name##_setup_wrapper_c(); \
}
#define TEST_GROUP_C_TEARDOWN_WRAPPER(group_name) \
void teardown() _override { \
group_##group_name##_teardown_wrapper_c(); \
}
#define TEST_C_WRAPPER(group_name, test_name) \
extern "C" void test_##group_name##_##test_name##_wrapper_c(); \
TEST(group_name, test_name) { \
test_##group_name##_##test_name##_wrapper_c(); \
}
#define IGNORE_TEST_C_WRAPPER(group_name, test_name) \
extern "C" void ignore_##group_name##_##test_name##_wrapper_c(); \
IGNORE_TEST(group_name, test_name) { \
ignore_##group_name##_##test_name##_wrapper_c(); \
}
#ifdef __cplusplus
extern "C"
{
#endif
/* CHECKS that can be used from C code */
extern void CHECK_EQUAL_C_BOOL_LOCATION(int expected, int actual, const char* text, const char* fileName, size_t lineNumber);
extern void CHECK_EQUAL_C_INT_LOCATION(int expected, int actual, const char* text, const char* fileName, size_t lineNumber);
extern void CHECK_EQUAL_C_UINT_LOCATION(unsigned int expected, unsigned int actual, const char* text, const char* fileName, size_t lineNumber);
extern void CHECK_EQUAL_C_LONG_LOCATION(long expected, long actual, const char* text, const char* fileName, size_t lineNumber);
extern void CHECK_EQUAL_C_ULONG_LOCATION(unsigned long expected, unsigned long actual, const char* text, const char* fileName, size_t lineNumber);
extern void CHECK_EQUAL_C_LONGLONG_LOCATION(cpputest_longlong expected, cpputest_longlong actual, const char* text, const char* fileName, size_t lineNumber);
extern void CHECK_EQUAL_C_ULONGLONG_LOCATION(cpputest_ulonglong expected, cpputest_ulonglong actual, const char* text, const char* fileName, size_t lineNumber);
extern void CHECK_EQUAL_C_REAL_LOCATION(double expected, double actual, double threshold, const char* text, const char* fileName, size_t lineNumber);
extern void CHECK_EQUAL_C_CHAR_LOCATION(char expected, char actual, const char* text, const char* fileName, size_t lineNumber);
extern void CHECK_EQUAL_C_UBYTE_LOCATION(unsigned char expected, unsigned char actual, const char* text, const char* fileName, size_t lineNumber);
extern void CHECK_EQUAL_C_SBYTE_LOCATION(signed char expected, signed char actual, const char* text, const char* fileName, size_t lineNumber);
extern void CHECK_EQUAL_C_STRING_LOCATION(const char* expected, const char* actual, const char* text, const char* fileName, size_t lineNumber);
extern void CHECK_EQUAL_C_POINTER_LOCATION(const void* expected, const void* actual, const char* text, const char* fileName, size_t lineNumber);
extern void CHECK_EQUAL_C_BITS_LOCATION(unsigned int expected, unsigned int actual, unsigned int mask, size_t size, const char* text, const char* fileName, size_t lineNumber);
extern void FAIL_TEXT_C_LOCATION(const char* text, const char* fileName, size_t lineNumber);
extern void FAIL_C_LOCATION(const char* fileName, size_t lineNumber);
extern void CHECK_C_LOCATION(int condition, const char* conditionString, const char* text, const char* fileName, size_t lineNumber);
extern void* cpputest_malloc(size_t size);
extern char* cpputest_strdup(const char* str);
extern char* cpputest_strndup(const char* str, size_t n);
extern void* cpputest_calloc(size_t num, size_t size);
extern void* cpputest_realloc(void* ptr, size_t size);
extern void cpputest_free(void* buffer);
extern void* cpputest_malloc_location(size_t size, const char* file, size_t line);
extern char* cpputest_strdup_location(const char* str, const char* file, size_t line);
extern char* cpputest_strndup_location(const char* str, size_t n, const char* file, size_t line);
extern void* cpputest_calloc_location(size_t num, size_t size, const char* file, size_t line);
extern void* cpputest_realloc_location(void* memory, size_t size, const char* file, size_t line);
extern void cpputest_free_location(void* buffer, const char* file, size_t line);
void cpputest_malloc_set_out_of_memory(void);
void cpputest_malloc_set_not_out_of_memory(void);
void cpputest_malloc_set_out_of_memory_countdown(int);
void cpputest_malloc_count_reset(void);
int cpputest_malloc_get_count(void);
#ifdef __cplusplus
}
#endif
/*
* Small additional macro for unused arguments. This is common when stubbing, but in C you cannot remove the
* name of the parameter (as in C++).
*/
#ifndef PUNUSED
#if defined(__GNUC__) || defined(__clang__)
# define PUNUSED(x) PUNUSED_ ##x __attribute__((unused))
#else
# define PUNUSED(x) x
#endif
#endif
#endif

View file

@ -0,0 +1,261 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_TestMemoryAllocator_h
#define D_TestMemoryAllocator_h
struct MemoryLeakNode;
class TestMemoryAllocator;
extern void setCurrentNewAllocator(TestMemoryAllocator* allocator);
extern TestMemoryAllocator* getCurrentNewAllocator();
extern void setCurrentNewAllocatorToDefault();
extern TestMemoryAllocator* defaultNewAllocator();
extern void setCurrentNewArrayAllocator(TestMemoryAllocator* allocator);
extern TestMemoryAllocator* getCurrentNewArrayAllocator();
extern void setCurrentNewArrayAllocatorToDefault();
extern TestMemoryAllocator* defaultNewArrayAllocator();
extern void setCurrentMallocAllocator(TestMemoryAllocator* allocator);
extern TestMemoryAllocator* getCurrentMallocAllocator();
extern void setCurrentMallocAllocatorToDefault();
extern TestMemoryAllocator* defaultMallocAllocator();
class GlobalMemoryAllocatorStash
{
public:
GlobalMemoryAllocatorStash();
void save();
void restore();
private:
TestMemoryAllocator* originalMallocAllocator;
TestMemoryAllocator* originalNewAllocator;
TestMemoryAllocator* originalNewArrayAllocator;
};
class TestMemoryAllocator
{
public:
TestMemoryAllocator(const char* name_str = "generic", const char* alloc_name_str = "alloc", const char* free_name_str = "free");
virtual ~TestMemoryAllocator();
bool hasBeenDestroyed();
virtual char* alloc_memory(size_t size, const char* file, size_t line);
virtual void free_memory(char* memory, size_t size, const char* file, size_t line);
virtual const char* name() const;
virtual const char* alloc_name() const;
virtual const char* free_name() const;
virtual bool isOfEqualType(TestMemoryAllocator* allocator);
virtual char* allocMemoryLeakNode(size_t size);
virtual void freeMemoryLeakNode(char* memory);
virtual TestMemoryAllocator* actualAllocator();
protected:
const char* name_;
const char* alloc_name_;
const char* free_name_;
bool hasBeenDestroyed_;
};
class MemoryLeakAllocator : public TestMemoryAllocator
{
public:
MemoryLeakAllocator(TestMemoryAllocator* originalAllocator);
virtual ~MemoryLeakAllocator() _destructor_override;
virtual char* alloc_memory(size_t size, const char* file, size_t line) _override;
virtual void free_memory(char* memory, size_t size, const char* file, size_t line) _override;
virtual const char* name() const _override;
virtual const char* alloc_name() const _override;
virtual const char* free_name() const _override;
virtual TestMemoryAllocator* actualAllocator() _override;
private:
TestMemoryAllocator* originalAllocator_;
};
class CrashOnAllocationAllocator : public TestMemoryAllocator
{
unsigned allocationToCrashOn_;
public:
CrashOnAllocationAllocator();
virtual ~CrashOnAllocationAllocator() _destructor_override;
virtual void setNumberToCrashOn(unsigned allocationToCrashOn);
virtual char* alloc_memory(size_t size, const char* file, size_t line) _override;
};
class NullUnknownAllocator: public TestMemoryAllocator
{
public:
NullUnknownAllocator();
virtual ~NullUnknownAllocator() _destructor_override;
virtual char* alloc_memory(size_t size, const char* file, size_t line) _override;
virtual void free_memory(char* memory, size_t size, const char* file, size_t line) _override;
static TestMemoryAllocator* defaultAllocator();
};
class LocationToFailAllocNode;
class FailableMemoryAllocator: public TestMemoryAllocator
{
public:
FailableMemoryAllocator(const char* name_str = "failable alloc", const char* alloc_name_str = "alloc", const char* free_name_str = "free");
virtual ~FailableMemoryAllocator() _destructor_override;
virtual char* alloc_memory(size_t size, const char* file, size_t line) _override;
virtual char* allocMemoryLeakNode(size_t size) _override;
virtual void failAllocNumber(int number);
virtual void failNthAllocAt(int allocationNumber, const char* file, size_t line);
virtual void checkAllFailedAllocsWereDone();
virtual void clearFailedAllocs();
protected:
LocationToFailAllocNode* head_;
int currentAllocNumber_;
};
struct MemoryAccountantAllocationNode;
class MemoryAccountant
{
public:
MemoryAccountant();
~MemoryAccountant();
void useCacheSizes(size_t sizes[], size_t length);
void clear();
void alloc(size_t size);
void dealloc(size_t size);
size_t totalAllocationsOfSize(size_t size) const;
size_t totalDeallocationsOfSize(size_t size) const;
size_t maximumAllocationAtATimeOfSize(size_t size) const;
size_t totalAllocations() const;
size_t totalDeallocations() const;
SimpleString report() const;
void setAllocator(TestMemoryAllocator* allocator);
private:
MemoryAccountantAllocationNode* findOrCreateNodeOfSize(size_t size);
MemoryAccountantAllocationNode* findNodeOfSize(size_t size) const;
MemoryAccountantAllocationNode* createNewAccountantAllocationNode(size_t size, MemoryAccountantAllocationNode* next) const;
void destroyAccountantAllocationNode(MemoryAccountantAllocationNode* node) const;
void createCacheSizeNodes(size_t sizes[], size_t length);
MemoryAccountantAllocationNode* head_;
TestMemoryAllocator* allocator_;
bool useCacheSizes_;
SimpleString reportNoAllocations() const;
SimpleString reportTitle() const;
SimpleString reportHeader() const;
SimpleString reportFooter() const;
SimpleString stringSize(size_t size) const;
};
struct AccountingTestMemoryAllocatorMemoryNode;
class AccountingTestMemoryAllocator : public TestMemoryAllocator
{
public:
AccountingTestMemoryAllocator(MemoryAccountant& accountant, TestMemoryAllocator* originalAllocator);
virtual ~AccountingTestMemoryAllocator() _destructor_override;
virtual char* alloc_memory(size_t size, const char* file, size_t line) _override;
virtual void free_memory(char* memory, size_t size, const char* file, size_t line) _override;
virtual TestMemoryAllocator* actualAllocator() _override;
TestMemoryAllocator* originalAllocator();
virtual const char* alloc_name() const _override;
virtual const char* free_name() const _override;
private:
void addMemoryToMemoryTrackingToKeepTrackOfSize(char* memory, size_t size);
size_t removeMemoryFromTrackingAndReturnAllocatedSize(char* memory);
size_t removeNextNodeAndReturnSize(AccountingTestMemoryAllocatorMemoryNode* node);
size_t removeHeadAndReturnSize();
MemoryAccountant& accountant_;
TestMemoryAllocator* originalAllocator_;
AccountingTestMemoryAllocatorMemoryNode* head_;
};
class GlobalMemoryAccountant
{
public:
GlobalMemoryAccountant();
~GlobalMemoryAccountant();
void useCacheSizes(size_t sizes[], size_t length);
void start();
void stop();
SimpleString report();
SimpleString reportWithCacheSizes(size_t sizes[], size_t length);
TestMemoryAllocator* getMallocAllocator();
TestMemoryAllocator* getNewAllocator();
TestMemoryAllocator* getNewArrayAllocator();
private:
void restoreMemoryAllocators();
MemoryAccountant accountant_;
AccountingTestMemoryAllocator* mallocAllocator_;
AccountingTestMemoryAllocator* newAllocator_;
AccountingTestMemoryAllocator* newArrayAllocator_;
};
#endif

View file

@ -0,0 +1,212 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_TestOutput_h
#define D_TestOutput_h
///////////////////////////////////////////////////////////////////////////////
//
// This is a minimal printer interface.
// We kept streams out to keep footprint small, and so the test
// harness could be used with less capable compilers so more
// platforms could use this test harness
//
///////////////////////////////////////////////////////////////////////////////
#include "SimpleString.h"
class UtestShell;
class TestFailure;
class TestResult;
class TestOutput
{
public:
enum WorkingEnvironment {visualStudio, eclipse, detectEnvironment};
enum VerbosityLevel {level_quiet, level_verbose, level_veryVerbose};
explicit TestOutput();
virtual ~TestOutput();
virtual void printTestsStarted();
virtual void printTestsEnded(const TestResult& result);
virtual void printCurrentTestStarted(const UtestShell& test);
virtual void printCurrentTestEnded(const TestResult& res);
virtual void printCurrentGroupStarted(const UtestShell& test);
virtual void printCurrentGroupEnded(const TestResult& res);
virtual void verbose(VerbosityLevel level);
virtual void color();
virtual void printBuffer(const char*)=0;
virtual void print(const char*);
virtual void print(long);
virtual void print(size_t);
virtual void printDouble(double);
virtual void printFailure(const TestFailure& failure);
virtual void printTestRun(size_t number, size_t total);
virtual void setProgressIndicator(const char*);
virtual void printVeryVerbose(const char*);
virtual void flush()=0;
static void setWorkingEnvironment(WorkingEnvironment workEnvironment);
static WorkingEnvironment getWorkingEnvironment();
protected:
virtual void printEclipseErrorInFileOnLine(SimpleString file, size_t lineNumber);
virtual void printVisualStudioErrorInFileOnLine(SimpleString file, size_t lineNumber);
virtual void printProgressIndicator();
void printFileAndLineForTestAndFailure(const TestFailure& failure);
void printFileAndLineForFailure(const TestFailure& failure);
void printFailureInTest(SimpleString testName);
void printFailureMessage(SimpleString reason);
void printErrorInFileOnLineFormattedForWorkingEnvironment(SimpleString testFile, size_t lineNumber);
TestOutput(const TestOutput&);
TestOutput& operator=(const TestOutput&);
int dotCount_;
VerbosityLevel verbose_;
bool color_;
const char* progressIndication_;
static WorkingEnvironment workingEnvironment_;
};
TestOutput& operator<<(TestOutput&, const char*);
TestOutput& operator<<(TestOutput&, long);
///////////////////////////////////////////////////////////////////////////////
//
// ConsoleTestOutput.h
//
// Printf Based Solution
//
///////////////////////////////////////////////////////////////////////////////
class ConsoleTestOutput: public TestOutput
{
public:
explicit ConsoleTestOutput()
{
}
virtual ~ConsoleTestOutput() _destructor_override
{
}
virtual void printBuffer(const char* s) _override;
virtual void flush() _override;
private:
ConsoleTestOutput(const ConsoleTestOutput&);
ConsoleTestOutput& operator=(const ConsoleTestOutput&);
};
///////////////////////////////////////////////////////////////////////////////
//
// StringBufferTestOutput.h
//
// TestOutput for test purposes
//
///////////////////////////////////////////////////////////////////////////////
class StringBufferTestOutput: public TestOutput
{
public:
explicit StringBufferTestOutput()
{
}
virtual ~StringBufferTestOutput() _destructor_override;
void printBuffer(const char* s) _override
{
output += s;
}
void flush() _override
{
output = "";
}
const SimpleString& getOutput()
{
return output;
}
protected:
SimpleString output;
private:
StringBufferTestOutput(const StringBufferTestOutput&);
StringBufferTestOutput& operator=(const StringBufferTestOutput&);
};
class CompositeTestOutput : public TestOutput
{
public:
virtual void setOutputOne(TestOutput* output);
virtual void setOutputTwo(TestOutput* output);
CompositeTestOutput();
virtual ~CompositeTestOutput() _destructor_override;
virtual void printTestsStarted() _override;
virtual void printTestsEnded(const TestResult& result) _override;
virtual void printCurrentTestStarted(const UtestShell& test) _override;
virtual void printCurrentTestEnded(const TestResult& res) _override;
virtual void printCurrentGroupStarted(const UtestShell& test) _override;
virtual void printCurrentGroupEnded(const TestResult& res) _override;
virtual void verbose(VerbosityLevel level) _override;
virtual void color() _override;
virtual void printBuffer(const char*) _override;
virtual void print(const char*) _override;
virtual void print(long) _override;
virtual void print(size_t) _override;
virtual void printDouble(double) _override;
virtual void printFailure(const TestFailure& failure) _override;
virtual void setProgressIndicator(const char*) _override;
virtual void flush() _override;
protected:
CompositeTestOutput(const TestOutput&);
CompositeTestOutput& operator=(const TestOutput&);
private:
TestOutput* outputOne_;
TestOutput* outputTwo_;
};
#endif

View file

@ -0,0 +1,117 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_TestPlugin_h
#define D_TestPlugin_h
class UtestShell;
class TestResult;
class TestPlugin
{
public:
TestPlugin(const SimpleString& name);
virtual ~TestPlugin();
virtual void preTestAction(UtestShell&, TestResult&)
{
}
virtual void postTestAction(UtestShell&, TestResult&)
{
}
virtual bool parseArguments(int /* ac */, const char *const * /* av */, int /* index */ )
{
return false;
}
virtual void runAllPreTestAction(UtestShell&, TestResult&);
virtual void runAllPostTestAction(UtestShell&, TestResult&);
virtual bool parseAllArguments(int ac, const char *const *av, int index);
virtual bool parseAllArguments(int ac, char** av, int index);
virtual TestPlugin* addPlugin(TestPlugin*);
virtual TestPlugin* removePluginByName(const SimpleString& name);
virtual TestPlugin* getNext();
virtual void disable();
virtual void enable();
virtual bool isEnabled();
const SimpleString& getName();
TestPlugin* getPluginByName(const SimpleString& name);
protected:
TestPlugin(TestPlugin* next_);
private:
TestPlugin* next_;
SimpleString name_;
bool enabled_;
};
///////////////////////////////////////////////////////////////////////////////
//
// SetPointerPlugin
//
// This is a very small plugin_ that resets pointers to their original value.
//
///////////////////////////////////////////////////////////////////////////////
extern void CppUTestStore(void **location);
class SetPointerPlugin: public TestPlugin
{
public:
SetPointerPlugin(const SimpleString& name);
virtual void postTestAction(UtestShell&, TestResult&) _override;
enum
{
MAX_SET = 32
};
};
#define UT_PTR_SET(a, b) do { CppUTestStore( (void**)&a ); a = b; } while(0)
///////////// Null Plugin
class NullTestPlugin: public TestPlugin
{
public:
NullTestPlugin();
virtual void runAllPreTestAction(UtestShell& test, TestResult& result) _override;
virtual void runAllPostTestAction(UtestShell& test, TestResult& result) _override;
static NullTestPlugin* instance();
};
#endif

View file

@ -0,0 +1,95 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
///////////////////////////////////////////////////////////////////////////////
//
// TestRegistry is a collection of tests that can be run
//
#ifndef D_TestRegistry_h
#define D_TestRegistry_h
#include "StandardCLibrary.h"
#include "SimpleString.h"
#include "TestFilter.h"
class UtestShell;
class TestResult;
class TestPlugin;
class TestRegistry
{
public:
TestRegistry();
virtual ~TestRegistry();
virtual void addTest(UtestShell *test);
virtual void unDoLastAddTest();
virtual size_t countTests();
virtual void runAllTests(TestResult& result);
virtual void shuffleTests(size_t seed);
virtual void reverseTests();
virtual void listTestGroupNames(TestResult& result);
virtual void listTestGroupAndCaseNames(TestResult& result);
virtual void setNameFilters(const TestFilter* filters);
virtual void setGroupFilters(const TestFilter* filters);
virtual void installPlugin(TestPlugin* plugin);
virtual void resetPlugins();
virtual TestPlugin* getFirstPlugin();
virtual TestPlugin* getPluginByName(const SimpleString& name);
virtual void removePluginByName(const SimpleString& name);
virtual int countPlugins();
virtual UtestShell* getFirstTest();
virtual UtestShell* getTestWithNext(UtestShell* test);
virtual UtestShell* findTestWithName(const SimpleString& name);
virtual UtestShell* findTestWithGroup(const SimpleString& name);
static TestRegistry* getCurrentRegistry();
virtual void setCurrentRegistry(TestRegistry* registry);
virtual void setRunTestsInSeperateProcess();
int getCurrentRepetition();
void setRunIgnored();
private:
bool testShouldRun(UtestShell* test, TestResult& result);
bool endOfGroup(UtestShell* test);
UtestShell * tests_;
const TestFilter* nameFilters_;
const TestFilter* groupFilters_;
TestPlugin* firstPlugin_;
static TestRegistry* currentRegistry_;
bool runInSeperateProcess_;
int currentRepetition_;
bool runIgnored_;
};
#endif

View file

@ -0,0 +1,116 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
///////////////////////////////////////////////////////////////////////////////
//
// A TestResult is a collection of the history of some test runs. Right now
// it just collects failures. Really it just prints the failures.
//
#ifndef D_TestResult_h
#define D_TestResult_h
class TestFailure;
class TestOutput;
class UtestShell;
class TestResult
{
public:
TestResult(TestOutput&);
DEFAULT_COPY_CONSTRUCTOR(TestResult)
virtual ~TestResult();
virtual void testsStarted();
virtual void testsEnded();
virtual void currentGroupStarted(UtestShell* test);
virtual void currentGroupEnded(UtestShell* test);
virtual void currentTestStarted(UtestShell* test);
virtual void currentTestEnded(UtestShell* test);
virtual void countTest();
virtual void countRun();
virtual void countCheck();
virtual void countFilteredOut();
virtual void countIgnored();
virtual void addFailure(const TestFailure& failure);
virtual void print(const char* text);
virtual void printVeryVerbose(const char* text);
size_t getTestCount() const
{
return testCount_;
}
size_t getRunCount() const
{
return runCount_;
}
size_t getCheckCount() const
{
return checkCount_;
}
size_t getFilteredOutCount() const
{
return filteredOutCount_;
}
size_t getIgnoredCount() const
{
return ignoredCount_;
}
size_t getFailureCount() const
{
return failureCount_;
}
bool isFailure() const
{
return (getFailureCount() != 0) || (getRunCount() + getIgnoredCount() == 0);
}
size_t getTotalExecutionTime() const;
void setTotalExecutionTime(size_t exTime);
size_t getCurrentTestTotalExecutionTime() const;
size_t getCurrentGroupTotalExecutionTime() const;
private:
TestOutput& output_;
size_t testCount_;
size_t runCount_;
size_t checkCount_;
size_t failureCount_;
size_t filteredOutCount_;
size_t ignoredCount_;
size_t totalExecutionTime_;
size_t timeStarted_;
size_t currentTestTimeStarted_;
size_t currentTestTotalExecutionTime_;
size_t currentGroupTimeStarted_;
size_t currentGroupTotalExecutionTime_;
};
#endif

View file

@ -0,0 +1,97 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_TestTestingFixture_H
#define D_TestTestingFixture_H
#include "TestRegistry.h"
#include "TestOutput.h"
class TestTestingFixture
{
public:
TestTestingFixture();
virtual ~TestTestingFixture();
void flushOutputAndResetResult();
void addTest(UtestShell * test);
void installPlugin(TestPlugin* plugin);
void setTestFunction(void(*testFunction)());
void setTestFunction(ExecFunction* testFunction);
void setSetup(void(*setupFunction)());
void setTeardown(void(*teardownFunction)());
void setOutputVerbose();
void setRunTestsInSeperateProcess();
void runTestWithMethod(void(*method)());
void runAllTests();
size_t getFailureCount();
size_t getCheckCount();
size_t getIgnoreCount();
size_t getRunCount();
size_t getTestCount();
const SimpleString& getOutput();
TestRegistry* getRegistry();
bool hasTestFailed();
void assertPrintContains(const SimpleString& contains);
void assertPrintContainsNot(const SimpleString& contains);
void checkTestFailsWithProperTestLocation(const char* text, const char* file, size_t line);
static void lineExecutedAfterCheck();
private:
void clearExecFunction();
static bool lineOfCodeExecutedAfterCheck;
TestRegistry* registry_;
ExecFunctionTestShell* genTest_;
bool ownsExecFunction_;
StringBufferTestOutput* output_;
TestResult * result_;
};
class SetBooleanOnDestructorCall
{
bool& booleanToSet_;
public:
SetBooleanOnDestructorCall(bool& booleanToSet) : booleanToSet_(booleanToSet)
{
}
virtual ~SetBooleanOnDestructorCall()
{
booleanToSet_ = true;
}
};
#endif

View file

@ -0,0 +1,322 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// This file contains the Test class along with the macros which make effective
// in the harness.
#ifndef D_UTest_h
#define D_UTest_h
#include "SimpleString.h"
class TestResult;
class TestPlugin;
class TestFailure;
class TestFilter;
class TestTerminator;
extern bool doubles_equal(double d1, double d2, double threshold);
//////////////////// Utest
class UtestShell;
class Utest
{
public:
Utest();
virtual ~Utest();
virtual void run();
virtual void setup();
virtual void teardown();
virtual void testBody();
};
//////////////////// TestTerminator
class TestTerminator
{
public:
virtual void exitCurrentTest() const=0;
virtual ~TestTerminator();
};
class NormalTestTerminator : public TestTerminator
{
public:
virtual void exitCurrentTest() const _override;
virtual ~NormalTestTerminator() _destructor_override;
};
class TestTerminatorWithoutExceptions : public TestTerminator
{
public:
virtual void exitCurrentTest() const _override;
virtual ~TestTerminatorWithoutExceptions() _destructor_override;
};
class CrashingTestTerminator : public NormalTestTerminator
{
public:
virtual void exitCurrentTest() const _override;
virtual ~CrashingTestTerminator() _destructor_override;
};
//////////////////// UtestShell
class UtestShell
{
public:
static UtestShell *getCurrent();
static const TestTerminator &getCurrentTestTerminator();
static void setCrashOnFail();
static void restoreDefaultTestTerminator();
public:
UtestShell(const char* groupName, const char* testName, const char* fileName, size_t lineNumber);
virtual ~UtestShell();
virtual UtestShell* addTest(UtestShell* test);
virtual UtestShell *getNext() const;
virtual size_t countTests();
bool shouldRun(const TestFilter* groupFilters, const TestFilter* nameFilters) const;
const SimpleString getName() const;
const SimpleString getGroup() const;
virtual SimpleString getFormattedName() const;
const SimpleString getFile() const;
size_t getLineNumber() const;
virtual bool willRun() const;
virtual bool hasFailed() const;
void countCheck();
virtual void assertTrue(bool condition, const char *checkString, const char *conditionString, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator());
virtual void assertCstrEqual(const char *expected, const char *actual, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator());
virtual void assertCstrNEqual(const char *expected, const char *actual, size_t length, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator());
virtual void assertCstrNoCaseEqual(const char *expected, const char *actual, const char* text, const char *fileName, size_t lineNumber);
virtual void assertCstrContains(const char *expected, const char *actual, const char* text, const char *fileName, size_t lineNumber);
virtual void assertCstrNoCaseContains(const char *expected, const char *actual, const char* text, const char *fileName, size_t lineNumber);
virtual void assertLongsEqual(long expected, long actual, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator());
virtual void assertUnsignedLongsEqual(unsigned long expected, unsigned long actual, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator());
virtual void assertLongLongsEqual(cpputest_longlong expected, cpputest_longlong actual, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator());
virtual void assertUnsignedLongLongsEqual(cpputest_ulonglong expected, cpputest_ulonglong actual, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator());
virtual void assertSignedBytesEqual(signed char expected, signed char actual, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator());
virtual void assertPointersEqual(const void *expected, const void *actual, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator());
virtual void assertFunctionPointersEqual(void (*expected)(), void (*actual)(), const char* text, const char* fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator());
virtual void assertDoublesEqual(double expected, double actual, double threshold, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator());
virtual void assertEquals(bool failed, const char* expected, const char* actual, const char* text, const char* file, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator());
virtual void assertBinaryEqual(const void *expected, const void *actual, size_t length, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator());
virtual void assertBitsEqual(unsigned long expected, unsigned long actual, unsigned long mask, size_t byteCount, const char* text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator());
virtual void assertCompare(bool comparison, const char *checkString, const char *comparisonString, const char *text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator());
virtual void fail(const char *text, const char *fileName, size_t lineNumber, const TestTerminator& testTerminator = getCurrentTestTerminator());
virtual void exitTest(const TestTerminator& testTerminator = getCurrentTestTerminator());
virtual void print(const char *text, const char *fileName, size_t lineNumber);
virtual void print(const SimpleString & text, const char *fileName, size_t lineNumber);
virtual void printVeryVerbose(const char* text);
void setFileName(const char *fileName);
void setLineNumber(size_t lineNumber);
void setGroupName(const char *groupName);
void setTestName(const char *testName);
static void crash();
static void setCrashMethod(void (*crashme)());
static void resetCrashMethod();
virtual bool isRunInSeperateProcess() const;
virtual void setRunInSeperateProcess();
virtual void setRunIgnored();
virtual Utest* createTest();
virtual void destroyTest(Utest* test);
virtual void runOneTest(TestPlugin* plugin, TestResult& result);
virtual void runOneTestInCurrentProcess(TestPlugin *plugin, TestResult & result);
virtual void failWith(const TestFailure& failure);
virtual void failWith(const TestFailure& failure, const TestTerminator& terminator);
protected:
UtestShell();
UtestShell(const char *groupName, const char *testName, const char *fileName, size_t lineNumber, UtestShell *nextTest);
virtual SimpleString getMacroName() const;
TestResult *getTestResult();
private:
const char *group_;
const char *name_;
const char *file_;
size_t lineNumber_;
UtestShell *next_;
bool isRunAsSeperateProcess_;
bool hasFailed_;
void setTestResult(TestResult* result);
void setCurrentTest(UtestShell* test);
bool match(const char* target, const TestFilter* filters) const;
static UtestShell* currentTest_;
static TestResult* testResult_;
static const TestTerminator *currentTestTerminator_;
};
//////////////////// ExecFunctionTest
class ExecFunctionTestShell;
class ExecFunctionTest : public Utest
{
public:
ExecFunctionTest(ExecFunctionTestShell* shell);
void testBody() _override;
virtual void setup() _override;
virtual void teardown() _override;
private:
ExecFunctionTestShell* shell_;
};
//////////////////// ExecFunction
class ExecFunction
{
public:
ExecFunction();
virtual ~ExecFunction();
virtual void exec()=0;
};
class ExecFunctionWithoutParameters : public ExecFunction
{
public:
void (*testFunction_)();
ExecFunctionWithoutParameters(void(*testFunction)());
virtual ~ExecFunctionWithoutParameters() _destructor_override;
virtual void exec() _override;
};
//////////////////// ExecFunctionTestShell
class ExecFunctionTestShell : public UtestShell
{
public:
void (*setup_)();
void (*teardown_)();
ExecFunction* testFunction_;
ExecFunctionTestShell(void(*set)() = NULLPTR, void(*tear)() = NULLPTR) :
UtestShell("ExecFunction", "ExecFunction", "ExecFunction", 1), setup_(set), teardown_(tear), testFunction_(NULLPTR)
{
}
Utest* createTest() _override { return new ExecFunctionTest(this); }
virtual ~ExecFunctionTestShell() _destructor_override;
};
//////////////////// CppUTestFailedException
class CppUTestFailedException
{
public:
int dummy_;
};
//////////////////// IgnoredTest
class IgnoredUtestShell : public UtestShell
{
public:
IgnoredUtestShell();
virtual ~IgnoredUtestShell() _destructor_override;
explicit IgnoredUtestShell(const char* groupName, const char* testName,
const char* fileName, size_t lineNumber);
virtual bool willRun() const _override;
virtual void setRunIgnored() _override;
protected:
virtual SimpleString getMacroName() const _override;
virtual void runOneTest(TestPlugin* plugin, TestResult& result) _override;
private:
IgnoredUtestShell(const IgnoredUtestShell&);
IgnoredUtestShell& operator=(const IgnoredUtestShell&);
bool runIgnored_;
};
//////////////////// UtestShellPointerArray
class UtestShellPointerArray
{
public:
UtestShellPointerArray(UtestShell* firstTest);
~UtestShellPointerArray();
void shuffle(size_t seed);
void reverse();
void relinkTestsInOrder();
UtestShell* getFirstTest() const;
UtestShell* get(size_t index) const;
private:
void swap(size_t index1, size_t index2);
UtestShell** arrayOfTests_;
size_t count_;
};
//////////////////// TestInstaller
class TestInstaller
{
public:
explicit TestInstaller(UtestShell& shell, const char* groupName, const char* testName,
const char* fileName, size_t lineNumber);
virtual ~TestInstaller();
void unDo();
private:
TestInstaller(const TestInstaller&);
TestInstaller& operator=(const TestInstaller&);
};
#endif

View file

@ -0,0 +1,384 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_UTestMacros_h
#define D_UTestMacros_h
/*! \brief Define a group of tests
*
* All tests in a TEST_GROUP share the same setup()
* and teardown(). setup() is run before the opening
* curly brace of each TEST and teardown() is
* called after the closing curly brace of TEST.
*
*/
#define TEST_GROUP_BASE(testGroup, baseclass) \
extern int externTestGroup##testGroup; \
int externTestGroup##testGroup = 0; \
struct TEST_GROUP_##CppUTestGroup##testGroup : public baseclass
#define TEST_BASE(testBaseClass) \
struct testBaseClass : public Utest
#define TEST_GROUP(testGroup) \
TEST_GROUP_BASE(testGroup, Utest)
#define TEST_SETUP() \
virtual void setup() _override
#define TEST_TEARDOWN() \
virtual void teardown() _override
#define TEST(testGroup, testName) \
/* External declarations for strict compilers */ \
class TEST_##testGroup##_##testName##_TestShell; \
extern TEST_##testGroup##_##testName##_TestShell TEST_##testGroup##_##testName##_TestShell_instance; \
\
class TEST_##testGroup##_##testName##_Test : public TEST_GROUP_##CppUTestGroup##testGroup \
{ public: TEST_##testGroup##_##testName##_Test () : TEST_GROUP_##CppUTestGroup##testGroup () {} \
void testBody() _override; }; \
class TEST_##testGroup##_##testName##_TestShell : public UtestShell { \
virtual Utest* createTest() _override { return new TEST_##testGroup##_##testName##_Test; } \
} TEST_##testGroup##_##testName##_TestShell_instance; \
static TestInstaller TEST_##testGroup##_##testName##_Installer(TEST_##testGroup##_##testName##_TestShell_instance, #testGroup, #testName, __FILE__,__LINE__); \
void TEST_##testGroup##_##testName##_Test::testBody()
#define IGNORE_TEST(testGroup, testName)\
/* External declarations for strict compilers */ \
class IGNORE##testGroup##_##testName##_TestShell; \
extern IGNORE##testGroup##_##testName##_TestShell IGNORE##testGroup##_##testName##_TestShell_instance; \
\
class IGNORE##testGroup##_##testName##_Test : public TEST_GROUP_##CppUTestGroup##testGroup \
{ public: IGNORE##testGroup##_##testName##_Test () : TEST_GROUP_##CppUTestGroup##testGroup () {} \
public: void testBody() _override; }; \
class IGNORE##testGroup##_##testName##_TestShell : public IgnoredUtestShell { \
virtual Utest* createTest() _override { return new IGNORE##testGroup##_##testName##_Test; } \
} IGNORE##testGroup##_##testName##_TestShell_instance; \
static TestInstaller TEST_##testGroup##testName##_Installer(IGNORE##testGroup##_##testName##_TestShell_instance, #testGroup, #testName, __FILE__,__LINE__); \
void IGNORE##testGroup##_##testName##_Test::testBody ()
#define IMPORT_TEST_GROUP(testGroup) \
extern int externTestGroup##testGroup;\
extern int* p##testGroup; \
int* p##testGroup = &externTestGroup##testGroup
#define CPPUTEST_DEFAULT_MAIN \
/*#include <CppUTest/CommandLineTestRunner.h>*/ \
int main(int argc, char** argv) \
{ \
return CommandLineTestRunner::RunAllTests(argc, argv); \
}
// Different checking macros
#define CHECK(condition)\
CHECK_TRUE_LOCATION(condition, "CHECK", #condition, NULLPTR, __FILE__, __LINE__)
#define CHECK_TEXT(condition, text) \
CHECK_TRUE_LOCATION((bool)(condition), "CHECK", #condition, text, __FILE__, __LINE__)
#define CHECK_TRUE(condition)\
CHECK_TRUE_LOCATION((bool) (condition), "CHECK_TRUE", #condition, NULLPTR, __FILE__, __LINE__)
#define CHECK_TRUE_TEXT(condition, text)\
CHECK_TRUE_LOCATION(condition, "CHECK_TRUE", #condition, text, __FILE__, __LINE__)
#define CHECK_FALSE(condition)\
CHECK_FALSE_LOCATION(condition, "CHECK_FALSE", #condition, NULLPTR, __FILE__, __LINE__)
#define CHECK_FALSE_TEXT(condition, text)\
CHECK_FALSE_LOCATION(condition, "CHECK_FALSE", #condition, text, __FILE__, __LINE__)
#define CHECK_TRUE_LOCATION(condition, checkString, conditionString, text, file, line)\
do { UtestShell::getCurrent()->assertTrue((condition), checkString, conditionString, text, file, line); } while(0)
#define CHECK_FALSE_LOCATION(condition, checkString, conditionString, text, file, line)\
do { UtestShell::getCurrent()->assertTrue(!(condition), checkString, conditionString, text, file, line); } while(0)
//This check needs the operator!=(), and a StringFrom(YourType) function
#define CHECK_EQUAL(expected, actual)\
CHECK_EQUAL_LOCATION(expected, actual, NULLPTR, __FILE__, __LINE__)
#define CHECK_EQUAL_TEXT(expected, actual, text)\
CHECK_EQUAL_LOCATION(expected, actual, text, __FILE__, __LINE__)
#define CHECK_EQUAL_LOCATION(expected, actual, text, file, line)\
do { if ((expected) != (actual)) { \
if ((actual) != (actual)) \
UtestShell::getCurrent()->print("WARNING:\n\tThe \"Actual Parameter\" parameter is evaluated multiple times resulting in different values.\n\tThus the value in the error message is probably incorrect.", file, line); \
if ((expected) != (expected)) \
UtestShell::getCurrent()->print("WARNING:\n\tThe \"Expected Parameter\" parameter is evaluated multiple times resulting in different values.\n\tThus the value in the error message is probably incorrect.", file, line); \
UtestShell::getCurrent()->assertEquals(true, StringFrom(expected).asCharString(), StringFrom(actual).asCharString(), text, file, line); \
} \
else \
{ \
UtestShell::getCurrent()->assertLongsEqual((long)0, (long)0, NULLPTR, file, line); \
} } while(0)
#define CHECK_EQUAL_ZERO(actual) CHECK_EQUAL(0, (actual))
#define CHECK_EQUAL_ZERO_TEXT(actual, text) CHECK_EQUAL_TEXT(0, (actual), (text))
#define CHECK_COMPARE(first, relop, second)\
CHECK_COMPARE_TEXT(first, relop, second, NULLPTR)
#define CHECK_COMPARE_TEXT(first, relop, second, text)\
CHECK_COMPARE_LOCATION(first, relop, second, text, __FILE__, __LINE__)
#define CHECK_COMPARE_LOCATION(first, relop, second, text, file, line)\
do { SimpleString conditionString;\
conditionString += StringFrom(first); conditionString += " ";\
conditionString += #relop; conditionString += " ";\
conditionString += StringFrom(second);\
UtestShell::getCurrent()->assertCompare((first) relop (second), "CHECK_COMPARE", conditionString.asCharString(), text, __FILE__, __LINE__);\
} while(0)
//This check checks for char* string equality using strcmp.
//This makes up for the fact that CHECK_EQUAL only compares the pointers to char*'s
#define STRCMP_EQUAL(expected, actual)\
STRCMP_EQUAL_LOCATION(expected, actual, NULLPTR, __FILE__, __LINE__)
#define STRCMP_EQUAL_TEXT(expected, actual, text)\
STRCMP_EQUAL_LOCATION(expected, actual, text, __FILE__, __LINE__)
#define STRCMP_EQUAL_LOCATION(expected, actual, text, file, line)\
do { UtestShell::getCurrent()->assertCstrEqual(expected, actual, text, file, line); } while(0)
#define STRNCMP_EQUAL(expected, actual, length)\
STRNCMP_EQUAL_LOCATION(expected, actual, length, NULLPTR, __FILE__, __LINE__)
#define STRNCMP_EQUAL_TEXT(expected, actual, length, text)\
STRNCMP_EQUAL_LOCATION(expected, actual, length, text, __FILE__, __LINE__)
#define STRNCMP_EQUAL_LOCATION(expected, actual, length, text, file, line)\
do { UtestShell::getCurrent()->assertCstrNEqual(expected, actual, length, text, file, line); } while(0)
#define STRCMP_NOCASE_EQUAL(expected, actual)\
STRCMP_NOCASE_EQUAL_LOCATION(expected, actual, NULLPTR, __FILE__, __LINE__)
#define STRCMP_NOCASE_EQUAL_TEXT(expected, actual, text)\
STRCMP_NOCASE_EQUAL_LOCATION(expected, actual, text, __FILE__, __LINE__)
#define STRCMP_NOCASE_EQUAL_LOCATION(expected, actual, text, file, line)\
do { UtestShell::getCurrent()->assertCstrNoCaseEqual(expected, actual, text, file, line); } while(0)
#define STRCMP_CONTAINS(expected, actual)\
STRCMP_CONTAINS_LOCATION(expected, actual, NULLPTR, __FILE__, __LINE__)
#define STRCMP_CONTAINS_TEXT(expected, actual, text)\
STRCMP_CONTAINS_LOCATION(expected, actual, text, __FILE__, __LINE__)
#define STRCMP_CONTAINS_LOCATION(expected, actual, text, file, line)\
do { UtestShell::getCurrent()->assertCstrContains(expected, actual, text, file, line); } while(0)
#define STRCMP_NOCASE_CONTAINS(expected, actual)\
STRCMP_NOCASE_CONTAINS_LOCATION(expected, actual, NULLPTR, __FILE__, __LINE__)
#define STRCMP_NOCASE_CONTAINS_TEXT(expected, actual, text)\
STRCMP_NOCASE_CONTAINS_LOCATION(expected, actual, text, __FILE__, __LINE__)
#define STRCMP_NOCASE_CONTAINS_LOCATION(expected, actual, text, file, line)\
do { UtestShell::getCurrent()->assertCstrNoCaseContains(expected, actual, text, file, line); } while(0)
//Check two long integers for equality
#define LONGS_EQUAL(expected, actual)\
LONGS_EQUAL_LOCATION((expected), (actual), "LONGS_EQUAL(" #expected ", " #actual ") failed", __FILE__, __LINE__)
#define LONGS_EQUAL_TEXT(expected, actual, text)\
LONGS_EQUAL_LOCATION((expected), (actual), text, __FILE__, __LINE__)
#define UNSIGNED_LONGS_EQUAL(expected, actual)\
UNSIGNED_LONGS_EQUAL_LOCATION((expected), (actual), NULLPTR, __FILE__, __LINE__)
#define UNSIGNED_LONGS_EQUAL_TEXT(expected, actual, text)\
UNSIGNED_LONGS_EQUAL_LOCATION((expected), (actual), text, __FILE__, __LINE__)
#define LONGS_EQUAL_LOCATION(expected, actual, text, file, line)\
do { UtestShell::getCurrent()->assertLongsEqual((long)expected, (long)actual, text, file, line); } while(0)
#define UNSIGNED_LONGS_EQUAL_LOCATION(expected, actual, text, file, line)\
do { UtestShell::getCurrent()->assertUnsignedLongsEqual((unsigned long)expected, (unsigned long)actual, text, file, line); } while(0)
#define LONGLONGS_EQUAL(expected, actual)\
LONGLONGS_EQUAL_LOCATION(expected, actual, NULLPTR, __FILE__, __LINE__)
#define LONGLONGS_EQUAL_TEXT(expected, actual, text)\
LONGLONGS_EQUAL_LOCATION(expected, actual, text, __FILE__, __LINE__)
#define UNSIGNED_LONGLONGS_EQUAL(expected, actual)\
UNSIGNED_LONGLONGS_EQUAL_LOCATION(expected, actual, NULLPTR, __FILE__, __LINE__)
#define UNSIGNED_LONGLONGS_EQUAL_TEXT(expected, actual, text)\
UNSIGNED_LONGLONGS_EQUAL_LOCATION(expected, actual, text, __FILE__, __LINE__)
#define LONGLONGS_EQUAL_LOCATION(expected, actual, text, file, line)\
do { UtestShell::getCurrent()->assertLongLongsEqual((long long)expected, (long long)actual, text, file, line); } while(0)
#define UNSIGNED_LONGLONGS_EQUAL_LOCATION(expected, actual, text, file, line)\
do { UtestShell::getCurrent()->assertUnsignedLongLongsEqual((unsigned long long)expected, (unsigned long long)actual, text, file, line); } while(0)
#define BYTES_EQUAL(expected, actual)\
LONGS_EQUAL((expected) & 0xff,(actual) & 0xff)
#define BYTES_EQUAL_TEXT(expected, actual, text)\
LONGS_EQUAL_TEXT((expected) & 0xff, (actual) & 0xff, text)
#define SIGNED_BYTES_EQUAL(expected, actual)\
SIGNED_BYTES_EQUAL_LOCATION(expected, actual, __FILE__, __LINE__)
#define SIGNED_BYTES_EQUAL_LOCATION(expected, actual, file, line) \
do { UtestShell::getCurrent()->assertSignedBytesEqual(expected, actual, NULLPTR, file, line); } while(0)
#define SIGNED_BYTES_EQUAL_TEXT(expected, actual, text)\
SIGNED_BYTES_EQUAL_TEXT_LOCATION(expected, actual, text, __FILE__, __LINE__)
#define SIGNED_BYTES_EQUAL_TEXT_LOCATION(expected, actual, text, file, line) \
do { UtestShell::getCurrent()->assertSignedBytesEqual(expected, actual, text, file, line); } while(0)
#define POINTERS_EQUAL(expected, actual)\
POINTERS_EQUAL_LOCATION((expected), (actual), NULLPTR, __FILE__, __LINE__)
#define POINTERS_EQUAL_TEXT(expected, actual, text)\
POINTERS_EQUAL_LOCATION((expected), (actual), text, __FILE__, __LINE__)
#define POINTERS_EQUAL_LOCATION(expected, actual, text, file, line)\
do { UtestShell::getCurrent()->assertPointersEqual((const void *)expected, (const void *)actual, text, file, line); } while(0)
#define FUNCTIONPOINTERS_EQUAL(expected, actual)\
FUNCTIONPOINTERS_EQUAL_LOCATION((expected), (actual), NULLPTR, __FILE__, __LINE__)
#define FUNCTIONPOINTERS_EQUAL_TEXT(expected, actual, text)\
FUNCTIONPOINTERS_EQUAL_LOCATION((expected), (actual), text, __FILE__, __LINE__)
#define FUNCTIONPOINTERS_EQUAL_LOCATION(expected, actual, text, file, line)\
do { UtestShell::getCurrent()->assertFunctionPointersEqual((void (*)())expected, (void (*)())actual, text, file, line); } while(0)
//Check two doubles for equality within a tolerance threshold
#define DOUBLES_EQUAL(expected, actual, threshold)\
DOUBLES_EQUAL_LOCATION(expected, actual, threshold, NULLPTR, __FILE__, __LINE__)
#define DOUBLES_EQUAL_TEXT(expected, actual, threshold, text)\
DOUBLES_EQUAL_LOCATION(expected, actual, threshold, text, __FILE__, __LINE__)
#define DOUBLES_EQUAL_LOCATION(expected, actual, threshold, text, file, line)\
do { UtestShell::getCurrent()->assertDoublesEqual(expected, actual, threshold, text, file, line); } while(0)
#define MEMCMP_EQUAL(expected, actual, size)\
MEMCMP_EQUAL_LOCATION(expected, actual, size, NULLPTR, __FILE__, __LINE__)
#define MEMCMP_EQUAL_TEXT(expected, actual, size, text)\
MEMCMP_EQUAL_LOCATION(expected, actual, size, text, __FILE__, __LINE__)
#define MEMCMP_EQUAL_LOCATION(expected, actual, size, text, file, line)\
do { UtestShell::getCurrent()->assertBinaryEqual(expected, actual, size, text, file, line); } while(0)
#define BITS_EQUAL(expected, actual, mask)\
BITS_LOCATION(expected, actual, mask, NULLPTR, __FILE__, __LINE__)
#define BITS_EQUAL_TEXT(expected, actual, mask, text)\
BITS_LOCATION(expected, actual, mask, text, __FILE__, __LINE__)
#define BITS_LOCATION(expected, actual, mask, text, file, line)\
do { UtestShell::getCurrent()->assertBitsEqual(expected, actual, mask, sizeof(actual), text, file, line); } while(0)
#define ENUMS_EQUAL_INT(expected, actual)\
ENUMS_EQUAL_TYPE(int, expected, actual)
#define ENUMS_EQUAL_INT_TEXT(expected, actual, text)\
ENUMS_EQUAL_TYPE_TEXT(int, expected, actual, text)
#define ENUMS_EQUAL_TYPE(underlying_type, expected, actual)\
ENUMS_EQUAL_TYPE_LOCATION(underlying_type, expected, actual, NULLPTR, __FILE__, __LINE__)
#define ENUMS_EQUAL_TYPE_TEXT(underlying_type, expected, actual, text)\
ENUMS_EQUAL_TYPE_LOCATION(underlying_type, expected, actual, text, __FILE__, __LINE__)
#define ENUMS_EQUAL_TYPE_LOCATION(underlying_type, expected, actual, text, file, line)\
do { underlying_type expected_underlying_value = (underlying_type)(expected); \
underlying_type actual_underlying_value = (underlying_type)(actual); \
if (expected_underlying_value != actual_underlying_value) { \
UtestShell::getCurrent()->assertEquals(true, StringFrom(expected_underlying_value).asCharString(), StringFrom(actual_underlying_value).asCharString(), text, file, line); \
} \
else \
{ \
UtestShell::getCurrent()->assertLongsEqual((long)0, long(0), NULLPTR, file, line); \
} \
} while(0)
//Fail if you get to this macro
//The macro FAIL may already be taken, so allow FAIL_TEST too
#ifndef FAIL
#define FAIL(text)\
FAIL_LOCATION(text, __FILE__,__LINE__)
#define FAIL_LOCATION(text, file, line)\
do { UtestShell::getCurrent()->fail(text, file, line); } while(0)
#endif
#define FAIL_TEST(text)\
FAIL_TEST_LOCATION(text, __FILE__,__LINE__)
#define FAIL_TEST_LOCATION(text, file,line)\
do { UtestShell::getCurrent()->fail(text, file, line); } while(0)
#define TEST_EXIT\
do { UtestShell::getCurrent()->exitTest(); } while(0)
#define UT_PRINT_LOCATION(text, file, line) \
do { UtestShell::getCurrent()->print(text, file, line); } while(0)
#define UT_PRINT(text) \
UT_PRINT_LOCATION(text, __FILE__, __LINE__)
#if CPPUTEST_USE_STD_CPP_LIB
#define CHECK_THROWS(expected, expression) \
do { \
SimpleString failure_msg("expected to throw "#expected "\nbut threw nothing"); \
bool caught_expected = false; \
try { \
(expression); \
} catch(const expected &) { \
caught_expected = true; \
} catch(...) { \
failure_msg = "expected to throw " #expected "\nbut threw a different type"; \
} \
if (!caught_expected) { \
UtestShell::getCurrent()->fail(failure_msg.asCharString(), __FILE__, __LINE__); \
} \
else { \
UtestShell::getCurrent()->countCheck(); \
} \
} while(0)
#endif /* CPPUTEST_USE_STD_CPP_LIB */
#define UT_CRASH() do { UtestShell::crash(); } while(0)
#define RUN_ALL_TESTS(ac, av) CommandLineTestRunner::RunAllTests(ac, av)
#endif /*D_UTestMacros_h*/

View file

@ -0,0 +1,67 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_CodeMemoryReportFormatter_h
#define D_CodeMemoryReportFormatter_h
#include "CppUTestExt/MemoryReportFormatter.h"
struct CodeReportingAllocationNode;
class CodeMemoryReportFormatter : public MemoryReportFormatter
{
private:
CodeReportingAllocationNode* codeReportingList_;
TestMemoryAllocator* internalAllocator_;
public:
CodeMemoryReportFormatter(TestMemoryAllocator* internalAllocator);
virtual ~CodeMemoryReportFormatter() _destructor_override;
virtual void report_testgroup_start(TestResult* result, UtestShell& test) _override;
virtual void report_testgroup_end(TestResult* /*result*/, UtestShell& /*test*/) _override {} // LCOV_EXCL_LINE
virtual void report_test_start(TestResult* result, UtestShell& test) _override;
virtual void report_test_end(TestResult* result, UtestShell& test) _override;
virtual void report_alloc_memory(TestResult* result, TestMemoryAllocator* allocator, size_t size, char* memory, const char* file, size_t line) _override;
virtual void report_free_memory(TestResult* result, TestMemoryAllocator* allocator, char* memory, const char* file, size_t line) _override;
private:
void addNodeToList(const char* variableName, void* memory, CodeReportingAllocationNode* next);
CodeReportingAllocationNode* findNode(void* memory);
bool variableExists(const SimpleString& variableName);
void clearReporting();
bool isNewAllocator(TestMemoryAllocator* allocator);
SimpleString createVariableNameFromFileLineInfo(const char *file, size_t line);
SimpleString getAllocationString(TestMemoryAllocator* allocator, const SimpleString& variableName, size_t size);
SimpleString getDeallocationString(TestMemoryAllocator* allocator, const SimpleString& variableName, const char* file, size_t line);
};
#endif

View file

@ -0,0 +1,54 @@
/*
* Copyright (c) 2011, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef GMOCK_H_
#define GMOCK_H_
#undef new
#undef strdup
#undef strndup
#undef RUN_ALL_TESTS
#define GTEST_DONT_DEFINE_TEST 1
#define GTEST_DONT_DEFINE_FAIL 1
#include "gmock/gmock.h"
#undef RUN_ALL_TESTS
using testing::Return;
using testing::NiceMock;
#ifdef CPPUTEST_USE_NEW_MACROS
#include "CppUTest/MemoryLeakDetectorNewMacros.h"
#endif
#ifdef CPPUTEST_USE_MALLOC_MACROS
#include "CppUTest/MemoryLeakDetectorMallocMacros.h"
#endif
#endif

View file

@ -0,0 +1,61 @@
/*
* Copyright (c) 2011, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef GTEST__H_
#define GTEST__H_
#undef new
#undef strdup
#undef strndup
#undef RUN_ALL_TESTS
#include "gtest/gtest.h"
#ifdef CPPUTEST_USE_NEW_MACROS
#include "CppUTest/MemoryLeakDetectorNewMacros.h"
#endif
#ifdef CPPUTEST_USE_MALLOC_MACROS
#include "CppUTest/MemoryLeakDetectorMallocMacros.h"
#endif
#include "CppUTestExt/GTestSupport.h"
#ifndef RUN_ALL_TESTS
#define GTEST_VERSION_GTEST_1_7
#else
#ifdef ADD_FAILURE_AT
#define GTEST_VERSION_GTEST_1_6
#else
#define GTEST_VERSION_GTEST_1_5
#endif
#endif
#undef RUN_ALL_TESTS
#endif

View file

@ -0,0 +1,387 @@
/*
* Copyright (c) 2011, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef GTESTCONVERTOR_H_
#define GTESTCONVERTOR_H_
#include "CppUTest/Utest.h"
#ifdef GTEST__H_
#error "Please include this file before you include any other GTest files"
#endif
/*
* Usage:
*
* This file must only be included in the main. The whole implementation is inline so that this can
* be compiled on usage and not on CppUTest compile-time. This avoids a hard dependency with CppUTest
* and with GTest
*
* Add the following lines to your main:
*
* GTestConvertor convertor;
* convertor.addAllGTestToTestRegistry();
*
*
*/
class GTestResultReporter;
class GTestFlagsThatAllocateMemory;
namespace testing {
class TestInfo;
class TestCase;
class Test;
}
class GTestShell : public UtestShell
{
::testing::TestInfo* testinfo_;
GTestShell* next_;
GTestFlagsThatAllocateMemory* flags_;
public:
GTestShell(::testing::TestInfo* testinfo, GTestShell* next, GTestFlagsThatAllocateMemory* flags);
virtual Utest* createTest() _override;
GTestShell* nextGTest()
{
return next_;
}
};
/* Enormous hack!
*
* This sucks enormously. We need to do two things in GTest that seem to not be possible without
* this hack. Hopefully there is *another way*.
*
* We need to access the factory in the TestInfo in order to be able to create tests. The factory
* is private and there seems to be no way to access it...
*
* We need to be able to call the Test SetUp and TearDown methods, but they are protected for
* some reason. We can't subclass either as the tests are created with the TEST macro.
*
* If anyone knows how to get the above things done *without* these ugly #defines, let me know!
*
*/
#define private public
#define protected public
#include "CppUTestExt/GTest.h"
#include "CppUTestExt/GMock.h"
#include "gtest/gtest-spi.h"
#include "gtest/gtest-death-test.h"
/*
* We really need some of its internals as they don't have a public interface.
*
*/
#define GTEST_IMPLEMENTATION_ 1
#include "src/gtest-internal-inl.h"
#include "CppUTest/TestRegistry.h"
#include "CppUTest/TestFailure.h"
#include "CppUTest/TestResult.h"
#ifdef GTEST_VERSION_GTEST_1_7
#define GTEST_STRING std::string
#define GTEST_NO_STRING_VALUE ""
#else
#define GTEST_STRING ::testing::internal::String
#define GTEST_NO_STRING_VALUE NULL
#endif
/* Store some of the flags as we'll need to reset them each test to avoid leaking memory */
class GTestFlagsThatAllocateMemory
{
public:
void storeValuesOfGTestFLags()
{
GTestFlagcolor = ::testing::GTEST_FLAG(color);
GTestFlagfilter = ::testing::GTEST_FLAG(filter);
GTestFlagoutput = ::testing::GTEST_FLAG(output);
GTestFlagdeath_test_style = ::testing::GTEST_FLAG(death_test_style);
GTestFlaginternal_run_death_test = ::testing::internal::GTEST_FLAG(internal_run_death_test);
#ifndef GTEST_VERSION_GTEST_1_5
GTestFlagstream_result_to = ::testing::GTEST_FLAG(stream_result_to);
#endif
}
void resetValuesOfGTestFlags()
{
::testing::GTEST_FLAG(color) = GTestFlagcolor;
::testing::GTEST_FLAG(filter) = GTestFlagfilter;
::testing::GTEST_FLAG(output) = GTestFlagoutput;
::testing::GTEST_FLAG(death_test_style) = GTestFlagdeath_test_style;
::testing::internal::GTEST_FLAG(internal_run_death_test) = GTestFlaginternal_run_death_test;
#ifndef GTEST_VERSION_GTEST_1_5
::testing::GTEST_FLAG(stream_result_to) = GTestFlagstream_result_to;
#endif
}
void setGTestFLagValuesToNULLToAvoidMemoryLeaks()
{
#ifndef GTEST_VERSION_GTEST_1_7
::testing::GTEST_FLAG(color) = GTEST_NO_STRING_VALUE;
::testing::GTEST_FLAG(filter) = GTEST_NO_STRING_VALUE;
::testing::GTEST_FLAG(output) = GTEST_NO_STRING_VALUE;
::testing::GTEST_FLAG(death_test_style) = GTEST_NO_STRING_VALUE;
::testing::internal::GTEST_FLAG(internal_run_death_test) = GTEST_NO_STRING_VALUE;
#ifndef GTEST_VERSION_GTEST_1_5
::testing::GTEST_FLAG(stream_result_to) = GTEST_NO_STRING_VALUE;
#endif
#endif
}
private:
GTEST_STRING GTestFlagcolor;
GTEST_STRING GTestFlagfilter;
GTEST_STRING GTestFlagoutput;
GTEST_STRING GTestFlagdeath_test_style;
GTEST_STRING GTestFlaginternal_run_death_test;
#ifndef GTEST_VERSION_GTEST_1_5
GTEST_STRING GTestFlagstream_result_to;
#endif
};
class GTestConvertor
{
public:
GTestConvertor(bool shouldSimulateFailureAtCreationToAllocateThreadLocalData = true);
virtual ~GTestConvertor();
virtual void addAllGTestToTestRegistry();
protected:
virtual void simulateGTestFailureToPreAllocateAllTheThreadLocalData();
virtual void addNewTestCaseForTestInfo(::testing::TestInfo* testinfo);
virtual void addAllTestsFromTestCaseToTestRegistry(::testing::TestCase* testcase);
virtual void createDummyInSequenceToAndFailureReporterAvoidMemoryLeakInGMock();
private:
GTestResultReporter* reporter_;
GTestShell* first_;
GTestFlagsThatAllocateMemory flags_;
};
class GTestDummyResultReporter : public ::testing::ScopedFakeTestPartResultReporter
{
public:
GTestDummyResultReporter () : ::testing::ScopedFakeTestPartResultReporter(INTERCEPT_ALL_THREADS, NULL) {}
virtual void ReportTestPartResult(const ::testing::TestPartResult& /*result*/) {}
};
class GMockTestTerminator : public TestTerminator
{
public:
GMockTestTerminator(const ::testing::TestPartResult& result) : result_(result)
{
}
virtual void exitCurrentTest() const
{
/*
* When using GMock, it throws an exception from the destructor leaving
* the system in an unstable state.
* Therefore, when the test fails because of failed gmock expectation
* then don't throw the exception, but let it return. Usually this should
* already be at the end of the test, so it doesn't matter much
*/
/*
* TODO: We probably want this check here, however the tests fail when putting it there. Also, we'll need to
* check how to get all the gTest tests to run within CppUTest. At the moment, the 'death tests' seem to fail
* still.
*
* if (result_.type() == ::testing::TestPartResult::kFatalFailure) {
*/
if (!SimpleString(result_.message()).contains("Actual: never called") &&
!SimpleString(result_.message()).contains("Actual function call count doesn't match"))
throw CppUTestFailedException();
}
virtual ~GMockTestTerminator()
{
}
private:
const ::testing::TestPartResult& result_;
};
class GTestResultReporter : public ::testing::ScopedFakeTestPartResultReporter
{
public:
GTestResultReporter () : ::testing::ScopedFakeTestPartResultReporter(INTERCEPT_ALL_THREADS, NULL) {}
virtual void ReportTestPartResult(const ::testing::TestPartResult& result)
{
FailFailure failure(UtestShell::getCurrent(), result.file_name(), result.line_number(), result.message());
UtestShell::getCurrent()->failWith(failure, GMockTestTerminator(result));
}
};
inline GTestShell::GTestShell(::testing::TestInfo* testinfo, GTestShell* next, GTestFlagsThatAllocateMemory* flags) : testinfo_(testinfo), next_(next), flags_(flags)
{
setGroupName(testinfo->test_case_name());
setTestName(testinfo->name());
}
class GTestUTest: public Utest {
public:
GTestUTest(::testing::TestInfo* testinfo, GTestFlagsThatAllocateMemory* flags) : testinfo_(testinfo), test_(NULL), flags_(flags)
{
}
void testBody()
{
try {
test_->TestBody();
}
catch (CppUTestFailedException& ex)
{
}
}
void setup()
{
flags_->resetValuesOfGTestFlags();
#ifdef GTEST_VERSION_GTEST_1_5
test_ = testinfo_->impl()->factory_->CreateTest();
#else
test_ = testinfo_->factory_->CreateTest();
#endif
::testing::UnitTest::GetInstance()->impl()->set_current_test_info(testinfo_);
try {
test_->SetUp();
}
catch (CppUTestFailedException& ex)
{
}
}
void teardown()
{
try {
test_->TearDown();
}
catch (CppUTestFailedException& ex)
{
}
::testing::UnitTest::GetInstance()->impl()->set_current_test_info(NULL);
delete test_;
flags_->setGTestFLagValuesToNULLToAvoidMemoryLeaks();
::testing::internal::DeathTest::set_last_death_test_message(GTEST_NO_STRING_VALUE);
}
private:
::testing::Test* test_;
::testing::TestInfo* testinfo_;
GTestFlagsThatAllocateMemory* flags_;
};
inline Utest* GTestShell::createTest()
{
return new GTestUTest(testinfo_, flags_);
};
inline void GTestConvertor::simulateGTestFailureToPreAllocateAllTheThreadLocalData()
{
GTestDummyResultReporter *dummyReporter = new GTestDummyResultReporter();
ASSERT_TRUE(false);
delete dummyReporter;
}
inline GTestConvertor::GTestConvertor(bool shouldSimulateFailureAtCreationToAllocateThreadLocalData) : first_(NULL)
{
if (shouldSimulateFailureAtCreationToAllocateThreadLocalData)
simulateGTestFailureToPreAllocateAllTheThreadLocalData();
reporter_ = new GTestResultReporter();
}
inline GTestConvertor::~GTestConvertor()
{
delete reporter_;
while (first_) {
GTestShell* next = first_->nextGTest();
delete first_;
first_ = next;
}
}
inline void GTestConvertor::addNewTestCaseForTestInfo(::testing::TestInfo* testinfo)
{
first_ = new GTestShell(testinfo, first_, &flags_);
TestRegistry::getCurrentRegistry()->addTest(first_);
}
inline void GTestConvertor::addAllTestsFromTestCaseToTestRegistry(::testing::TestCase* testcase)
{
int currentTestCount = 0;
::testing::TestInfo* currentTest = (::testing::TestInfo*) testcase->GetTestInfo(currentTestCount);
while (currentTest) {
addNewTestCaseForTestInfo(currentTest);
currentTestCount++;
currentTest = (::testing::TestInfo*) testcase->GetTestInfo(currentTestCount);
}
}
inline void GTestConvertor::createDummyInSequenceToAndFailureReporterAvoidMemoryLeakInGMock()
{
::testing::InSequence seq;
::testing::internal::GetFailureReporter();
}
inline void GTestConvertor::addAllGTestToTestRegistry()
{
createDummyInSequenceToAndFailureReporterAvoidMemoryLeakInGMock();
flags_.storeValuesOfGTestFLags();
int argc = 2;
const char * argv[] = {"NameOfTheProgram", "--gmock_catch_leaked_mocks=0"};
::testing::InitGoogleMock(&argc, (char**) argv);
::testing::UnitTest* unitTests = ::testing::UnitTest::GetInstance();
int currentUnitTestCount = 0;
::testing::TestCase* currentTestCase = (::testing::TestCase*) unitTests->GetTestCase(currentUnitTestCount);
while (currentTestCase) {
addAllTestsFromTestCaseToTestRegistry(currentTestCase);
currentUnitTestCount++;
currentTestCase = (::testing::TestCase*) unitTests->GetTestCase(currentUnitTestCount);
}
}
#endif

View file

@ -0,0 +1,33 @@
/*
* Copyright (c) 2011, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef GTESTSUPPORT__H_
#define GTESTSUPPORT__H_
extern void CppuTestGTestIgnoreLeaksInTest();
#endif

View file

@ -0,0 +1,53 @@
/*
* Copyright (c) 2015, Michael Feathers, James Grenning, Bas Vodde
* and Arnd Strube. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_IEEE754ExceptionsPlugin_h
#define D_IEEE754ExceptionsPlugin_h
#include "CppUTest/TestPlugin.h"
class IEEE754ExceptionsPlugin: public TestPlugin
{
public:
IEEE754ExceptionsPlugin(const SimpleString& name = "IEEE754ExceptionsPlugin");
virtual void preTestAction(UtestShell& test, TestResult& result) _override;
virtual void postTestAction(UtestShell& test, TestResult& result) _override;
static void disableInexact(void);
static void enableInexact(void);
static bool checkIeee754OverflowExceptionFlag();
static bool checkIeee754UnderflowExceptionFlag();
static bool checkIeee754InexactExceptionFlag();
static bool checkIeee754DivByZeroExceptionFlag();
private:
void ieee754Check(UtestShell& test, TestResult& result, int flag, const char* text);
static bool inexactDisabled_;
};
#endif

View file

@ -0,0 +1,61 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_MemoryReportAllocator_h
#define D_MemoryReportAllocator_h
#include "CppUTest/TestMemoryAllocator.h"
class MemoryReportFormatter;
class MemoryReportAllocator : public TestMemoryAllocator
{
protected:
TestResult* result_;
TestMemoryAllocator* realAllocator_;
MemoryReportFormatter* formatter_;
public:
MemoryReportAllocator();
virtual ~MemoryReportAllocator() _destructor_override;
virtual void setFormatter(MemoryReportFormatter* formatter);
virtual void setTestResult(TestResult* result);
virtual void setRealAllocator(TestMemoryAllocator* allocator);
virtual TestMemoryAllocator* getRealAllocator();
virtual char* alloc_memory(size_t size, const char* file, size_t line) _override;
virtual void free_memory(char* memory, size_t size, const char* file, size_t line) _override;
virtual const char* name() const _override;
virtual const char* alloc_name() const _override;
virtual const char* free_name() const _override;
virtual TestMemoryAllocator* actualAllocator() _override;
};
#endif

View file

@ -0,0 +1,65 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_MemoryReportFormatter_h
#define D_MemoryReportFormatter_h
class TestOutput;
class UtestShell;
class MemoryReportFormatter
{
public:
virtual ~MemoryReportFormatter(){}
virtual void report_testgroup_start(TestResult* result, UtestShell& test)=0;
virtual void report_testgroup_end(TestResult* result, UtestShell& test)=0;
virtual void report_test_start(TestResult* result, UtestShell& test)=0;
virtual void report_test_end(TestResult* result, UtestShell& test)=0;
virtual void report_alloc_memory(TestResult* result, TestMemoryAllocator* allocator, size_t size, char* memory, const char* file, size_t line)=0;
virtual void report_free_memory(TestResult* result, TestMemoryAllocator* allocator, char* memory, const char* file, size_t line)=0;
};
class NormalMemoryReportFormatter : public MemoryReportFormatter
{
public:
NormalMemoryReportFormatter();
virtual ~NormalMemoryReportFormatter() _destructor_override;
virtual void report_testgroup_start(TestResult* /*result*/, UtestShell& /*test*/) _override;
virtual void report_testgroup_end(TestResult* /*result*/, UtestShell& /*test*/) _override {} // LCOV_EXCL_LINE
virtual void report_test_start(TestResult* result, UtestShell& test) _override;
virtual void report_test_end(TestResult* result, UtestShell& test) _override;
virtual void report_alloc_memory(TestResult* result, TestMemoryAllocator* allocator, size_t size, char* memory, const char* file, size_t line) _override;
virtual void report_free_memory(TestResult* result, TestMemoryAllocator* allocator, char* memory, const char* file, size_t line) _override;
};
#endif

View file

@ -0,0 +1,68 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_MemoryReporterPlugin_h
#define D_MemoryReporterPlugin_h
#include "CppUTest/TestPlugin.h"
#include "CppUTestExt/MemoryReportAllocator.h"
class MemoryReportFormatter;
class MemoryReporterPlugin : public TestPlugin
{
MemoryReportFormatter* formatter_;
MemoryReportAllocator mallocAllocator;
MemoryReportAllocator newAllocator;
MemoryReportAllocator newArrayAllocator;
SimpleString currentTestGroup_;
public:
MemoryReporterPlugin();
virtual ~MemoryReporterPlugin() _destructor_override;
virtual void preTestAction(UtestShell & test, TestResult & result) _override;
virtual void postTestAction(UtestShell & test, TestResult & result) _override;
virtual bool parseArguments(int, const char *const *, int) _override;
MemoryReportAllocator* getMallocAllocator();
MemoryReportAllocator* getNewAllocator();
MemoryReportAllocator* getNewArrayAllocator();
protected:
virtual MemoryReportFormatter* createMemoryFormatter(const SimpleString& type);
private:
void destroyMemoryFormatter(MemoryReportFormatter* formatter);
void setGlobalMemoryReportAllocators();
void removeGlobalMemoryReportAllocators();
void initializeAllocator(MemoryReportAllocator* allocator, TestResult & result);
};
#endif

View file

@ -0,0 +1,120 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_MockActualCall_h
#define D_MockActualCall_h
#include "CppUTest/CppUTestConfig.h"
#include "CppUTest/TestHarness.h"
#include "CppUTestExt/MockNamedValue.h"
#include "CppUTestExt/MockExpectedCallsList.h"
class MockFailureReporter;
class MockFailure;
class MockActualCall
{
public:
MockActualCall();
virtual ~MockActualCall();
virtual MockActualCall& withName(const SimpleString& name)=0;
virtual MockActualCall& withCallOrder(unsigned int callOrder)=0;
MockActualCall& withParameter(const SimpleString& name, bool value) { return withBoolParameter(name, value); }
MockActualCall& withParameter(const SimpleString& name, int value) { return withIntParameter(name, value); }
MockActualCall& withParameter(const SimpleString& name, unsigned int value) { return withUnsignedIntParameter(name, value); }
MockActualCall& withParameter(const SimpleString& name, long int value) { return withLongIntParameter(name, value); }
MockActualCall& withParameter(const SimpleString& name, unsigned long int value) { return withUnsignedLongIntParameter(name, value); }
MockActualCall& withParameter(const SimpleString& name, cpputest_longlong value) { return withLongLongIntParameter(name, value); }
MockActualCall& withParameter(const SimpleString& name, cpputest_ulonglong value) { return withUnsignedLongLongIntParameter(name, value); }
MockActualCall& withParameter(const SimpleString& name, double value) { return withDoubleParameter(name, value); }
MockActualCall& withParameter(const SimpleString& name, const char* value) { return withStringParameter(name, value); }
MockActualCall& withParameter(const SimpleString& name, void* value) { return withPointerParameter(name, value); }
MockActualCall& withParameter(const SimpleString& name, void (*value)()) { return withFunctionPointerParameter(name, value); }
MockActualCall& withParameter(const SimpleString& name, const void* value) { return withConstPointerParameter(name, value); }
MockActualCall& withParameter(const SimpleString& name, const unsigned char* value, size_t size) { return withMemoryBufferParameter(name, value, size); }
virtual MockActualCall& withParameterOfType(const SimpleString& typeName, const SimpleString& name, const void* value)=0;
virtual MockActualCall& withOutputParameter(const SimpleString& name, void* output)=0;
virtual MockActualCall& withOutputParameterOfType(const SimpleString& typeName, const SimpleString& name, void* output)=0;
virtual MockActualCall& withBoolParameter(const SimpleString& name, bool value)=0;
virtual MockActualCall& withIntParameter(const SimpleString& name, int value)=0;
virtual MockActualCall& withUnsignedIntParameter(const SimpleString& name, unsigned int value)=0;
virtual MockActualCall& withLongIntParameter(const SimpleString& name, long int value)=0;
virtual MockActualCall& withUnsignedLongIntParameter(const SimpleString& name, unsigned long int value)=0;
virtual MockActualCall& withLongLongIntParameter(const SimpleString& name, cpputest_longlong value)=0;
virtual MockActualCall& withUnsignedLongLongIntParameter(const SimpleString& name, cpputest_ulonglong value)=0;
virtual MockActualCall& withDoubleParameter(const SimpleString& name, double value)=0;
virtual MockActualCall& withStringParameter(const SimpleString& name, const char* value)=0;
virtual MockActualCall& withPointerParameter(const SimpleString& name, void* value)=0;
virtual MockActualCall& withFunctionPointerParameter(const SimpleString& name, void (*value)())=0;
virtual MockActualCall& withConstPointerParameter(const SimpleString& name, const void* value)=0;
virtual MockActualCall& withMemoryBufferParameter(const SimpleString& name, const unsigned char* value, size_t size)=0;
virtual bool hasReturnValue()=0;
virtual MockNamedValue returnValue()=0;
virtual bool returnBoolValueOrDefault(bool default_value)=0;
virtual bool returnBoolValue()=0;
virtual int returnIntValueOrDefault(int default_value)=0;
virtual int returnIntValue()=0;
virtual unsigned long int returnUnsignedLongIntValue()=0;
virtual unsigned long int returnUnsignedLongIntValueOrDefault(unsigned long int default_value)=0;
virtual long int returnLongIntValue()=0;
virtual long int returnLongIntValueOrDefault(long int default_value)=0;
virtual cpputest_ulonglong returnUnsignedLongLongIntValue()=0;
virtual cpputest_ulonglong returnUnsignedLongLongIntValueOrDefault(cpputest_ulonglong default_value)=0;
virtual cpputest_longlong returnLongLongIntValue()=0;
virtual cpputest_longlong returnLongLongIntValueOrDefault(cpputest_longlong default_value)=0;
virtual unsigned int returnUnsignedIntValue()=0;
virtual unsigned int returnUnsignedIntValueOrDefault(unsigned int default_value)=0;
virtual const char * returnStringValueOrDefault(const char * default_value)=0;
virtual const char * returnStringValue()=0;
virtual double returnDoubleValue()=0;
virtual double returnDoubleValueOrDefault(double default_value)=0;
virtual void * returnPointerValue()=0;
virtual void * returnPointerValueOrDefault(void * default_value)=0;
virtual const void * returnConstPointerValue()=0;
virtual const void * returnConstPointerValueOrDefault(const void * default_value)=0;
virtual void (*returnFunctionPointerValue())()=0;
virtual void (*returnFunctionPointerValueOrDefault(void (*default_value)()))()=0;
virtual MockActualCall& onObject(const void* objectPtr)=0;
};
#endif

View file

@ -0,0 +1,300 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_MockCheckedActualCall_h
#define D_MockCheckedActualCall_h
#include "CppUTestExt/MockActualCall.h"
#include "CppUTestExt/MockExpectedCallsList.h"
class MockCheckedActualCall : public MockActualCall
{
public:
MockCheckedActualCall(unsigned int callOrder, MockFailureReporter* reporter, const MockExpectedCallsList& expectations);
virtual ~MockCheckedActualCall() _destructor_override;
virtual MockActualCall& withName(const SimpleString& name) _override;
virtual MockActualCall& withCallOrder(unsigned int) _override;
virtual MockActualCall& withBoolParameter(const SimpleString& name, bool value) _override;
virtual MockActualCall& withIntParameter(const SimpleString& name, int value) _override;
virtual MockActualCall& withUnsignedIntParameter(const SimpleString& name, unsigned int value) _override;
virtual MockActualCall& withLongIntParameter(const SimpleString& name, long int value) _override;
virtual MockActualCall& withUnsignedLongIntParameter(const SimpleString& name, unsigned long int value) _override;
virtual MockActualCall& withLongLongIntParameter(const SimpleString& name, cpputest_longlong value) _override;
virtual MockActualCall& withUnsignedLongLongIntParameter(const SimpleString& name, cpputest_ulonglong value) _override;
virtual MockActualCall& withDoubleParameter(const SimpleString& name, double value) _override;
virtual MockActualCall& withStringParameter(const SimpleString& name, const char* value) _override;
virtual MockActualCall& withPointerParameter(const SimpleString& name, void* value) _override;
virtual MockActualCall& withConstPointerParameter(const SimpleString& name, const void* value) _override;
virtual MockActualCall& withFunctionPointerParameter(const SimpleString& name, void (*value)()) _override;
virtual MockActualCall& withMemoryBufferParameter(const SimpleString& name, const unsigned char* value, size_t size) _override;
virtual MockActualCall& withParameterOfType(const SimpleString& type, const SimpleString& name, const void* value) _override;
virtual MockActualCall& withOutputParameter(const SimpleString& name, void* output) _override;
virtual MockActualCall& withOutputParameterOfType(const SimpleString& type, const SimpleString& name, void* output) _override;
virtual bool hasReturnValue() _override;
virtual MockNamedValue returnValue() _override;
virtual bool returnBoolValueOrDefault(bool default_value) _override;
virtual bool returnBoolValue() _override;
virtual int returnIntValueOrDefault(int default_value) _override;
virtual int returnIntValue() _override;
virtual unsigned long int returnUnsignedLongIntValue() _override;
virtual unsigned long int returnUnsignedLongIntValueOrDefault(unsigned long int) _override;
virtual long int returnLongIntValue() _override;
virtual long int returnLongIntValueOrDefault(long int default_value) _override;
virtual cpputest_ulonglong returnUnsignedLongLongIntValue() _override;
virtual cpputest_ulonglong returnUnsignedLongLongIntValueOrDefault(cpputest_ulonglong default_value) _override;
virtual cpputest_longlong returnLongLongIntValue() _override;
virtual cpputest_longlong returnLongLongIntValueOrDefault(cpputest_longlong default_value) _override;
virtual unsigned int returnUnsignedIntValue() _override;
virtual unsigned int returnUnsignedIntValueOrDefault(unsigned int default_value) _override;
virtual const char * returnStringValueOrDefault(const char * default_value) _override;
virtual const char * returnStringValue() _override;
virtual double returnDoubleValue() _override;
virtual double returnDoubleValueOrDefault(double default_value) _override;
virtual const void * returnConstPointerValue() _override;
virtual const void * returnConstPointerValueOrDefault(const void * default_value) _override;
virtual void * returnPointerValue() _override;
virtual void * returnPointerValueOrDefault(void *) _override;
virtual void (*returnFunctionPointerValue())() _override;
virtual void (*returnFunctionPointerValueOrDefault(void (*)()))() _override;
virtual MockActualCall& onObject(const void* objectPtr) _override;
virtual bool isFulfilled() const;
virtual bool hasFailed() const;
virtual void checkExpectations();
virtual void setMockFailureReporter(MockFailureReporter* reporter);
protected:
void setName(const SimpleString& name);
SimpleString getName() const;
virtual UtestShell* getTest() const;
virtual void callHasSucceeded();
virtual void copyOutputParameters(MockCheckedExpectedCall* call);
virtual void completeCallWhenMatchIsFound();
virtual void failTest(const MockFailure& failure);
virtual void checkInputParameter(const MockNamedValue& actualParameter);
virtual void checkOutputParameter(const MockNamedValue& outputParameter);
virtual void discardCurrentlyMatchingExpectations();
enum ActualCallState {
CALL_IN_PROGRESS,
CALL_FAILED,
CALL_SUCCEED
};
virtual void setState(ActualCallState state);
private:
SimpleString functionName_;
unsigned int callOrder_;
MockFailureReporter* reporter_;
ActualCallState state_;
bool expectationsChecked_;
MockCheckedExpectedCall* matchingExpectation_;
MockExpectedCallsList potentiallyMatchingExpectations_;
const MockExpectedCallsList& allExpectations_;
class MockOutputParametersListNode
{
public:
SimpleString name_;
SimpleString type_;
void* ptr_;
MockOutputParametersListNode* next_;
MockOutputParametersListNode(const SimpleString& name, const SimpleString& type, void* ptr)
: name_(name), type_(type), ptr_(ptr), next_(NULLPTR) {}
};
MockOutputParametersListNode* outputParameterExpectations_;
virtual void addOutputParameter(const SimpleString& name, const SimpleString& type, void* ptr);
virtual void cleanUpOutputParameterList();
};
class MockActualCallTrace : public MockActualCall
{
public:
MockActualCallTrace();
virtual ~MockActualCallTrace() _destructor_override;
virtual MockActualCall& withName(const SimpleString& name) _override;
virtual MockActualCall& withCallOrder(unsigned int) _override;
virtual MockActualCall& withBoolParameter(const SimpleString& name, bool value) _override;
virtual MockActualCall& withIntParameter(const SimpleString& name, int value) _override;
virtual MockActualCall& withUnsignedIntParameter(const SimpleString& name, unsigned int value) _override;
virtual MockActualCall& withLongIntParameter(const SimpleString& name, long int value) _override;
virtual MockActualCall& withUnsignedLongIntParameter(const SimpleString& name, unsigned long int value) _override;
virtual MockActualCall& withLongLongIntParameter(const SimpleString& name, cpputest_longlong value) _override;
virtual MockActualCall& withUnsignedLongLongIntParameter(const SimpleString& name, cpputest_ulonglong value) _override;
virtual MockActualCall& withDoubleParameter(const SimpleString& name, double value) _override;
virtual MockActualCall& withStringParameter(const SimpleString& name, const char* value) _override;
virtual MockActualCall& withPointerParameter(const SimpleString& name, void* value) _override;
virtual MockActualCall& withConstPointerParameter(const SimpleString& name, const void* value) _override;
virtual MockActualCall& withFunctionPointerParameter(const SimpleString& name, void (*value)()) _override;
virtual MockActualCall& withMemoryBufferParameter(const SimpleString& name, const unsigned char* value, size_t size) _override;
virtual MockActualCall& withParameterOfType(const SimpleString& typeName, const SimpleString& name, const void* value) _override;
virtual MockActualCall& withOutputParameter(const SimpleString& name, void* output) _override;
virtual MockActualCall& withOutputParameterOfType(const SimpleString& typeName, const SimpleString& name, void* output) _override;
virtual bool hasReturnValue() _override;
virtual MockNamedValue returnValue() _override;
virtual bool returnBoolValueOrDefault(bool default_value) _override;
virtual bool returnBoolValue() _override;
virtual int returnIntValueOrDefault(int default_value) _override;
virtual int returnIntValue() _override;
virtual unsigned long int returnUnsignedLongIntValue() _override;
virtual unsigned long int returnUnsignedLongIntValueOrDefault(unsigned long int) _override;
virtual long int returnLongIntValue() _override;
virtual long int returnLongIntValueOrDefault(long int default_value) _override;
virtual cpputest_ulonglong returnUnsignedLongLongIntValue() _override;
virtual cpputest_ulonglong returnUnsignedLongLongIntValueOrDefault(cpputest_ulonglong default_value) _override;
virtual cpputest_longlong returnLongLongIntValue() _override;
virtual cpputest_longlong returnLongLongIntValueOrDefault(cpputest_longlong default_value) _override;
virtual unsigned int returnUnsignedIntValue() _override;
virtual unsigned int returnUnsignedIntValueOrDefault(unsigned int default_value) _override;
virtual const char * returnStringValueOrDefault(const char * default_value) _override;
virtual const char * returnStringValue() _override;
virtual double returnDoubleValue() _override;
virtual double returnDoubleValueOrDefault(double default_value) _override;
virtual void * returnPointerValue() _override;
virtual void * returnPointerValueOrDefault(void *) _override;
virtual const void * returnConstPointerValue() _override;
virtual const void * returnConstPointerValueOrDefault(const void * default_value) _override;
virtual void (*returnFunctionPointerValue())() _override;
virtual void (*returnFunctionPointerValueOrDefault(void (*)()))() _override;
virtual MockActualCall& onObject(const void* objectPtr) _override;
const char* getTraceOutput();
void clear();
static MockActualCallTrace& instance();
static void clearInstance();
private:
SimpleString traceBuffer_;
static MockActualCallTrace* instance_;
void addParameterName(const SimpleString& name);
};
class MockIgnoredActualCall: public MockActualCall
{
public:
virtual MockActualCall& withName(const SimpleString&) _override { return *this;}
virtual MockActualCall& withCallOrder(unsigned int) _override { return *this; }
virtual MockActualCall& withBoolParameter(const SimpleString&, bool) _override { return *this; }
virtual MockActualCall& withIntParameter(const SimpleString&, int) _override { return *this; }
virtual MockActualCall& withUnsignedIntParameter(const SimpleString&, unsigned int) _override { return *this; }
virtual MockActualCall& withLongIntParameter(const SimpleString&, long int) _override { return *this; }
virtual MockActualCall& withUnsignedLongIntParameter(const SimpleString&, unsigned long int) _override { return *this; }
virtual MockActualCall& withLongLongIntParameter(const SimpleString&, cpputest_longlong) _override { return *this; }
virtual MockActualCall& withUnsignedLongLongIntParameter(const SimpleString&, cpputest_ulonglong) _override { return *this; }
virtual MockActualCall& withDoubleParameter(const SimpleString&, double) _override { return *this; }
virtual MockActualCall& withStringParameter(const SimpleString&, const char*) _override { return *this; }
virtual MockActualCall& withPointerParameter(const SimpleString& , void*) _override { return *this; }
virtual MockActualCall& withConstPointerParameter(const SimpleString& , const void*) _override { return *this; }
virtual MockActualCall& withFunctionPointerParameter(const SimpleString& , void (*)()) _override { return *this; }
virtual MockActualCall& withMemoryBufferParameter(const SimpleString&, const unsigned char*, size_t) _override { return *this; }
virtual MockActualCall& withParameterOfType(const SimpleString&, const SimpleString&, const void*) _override { return *this; }
virtual MockActualCall& withOutputParameter(const SimpleString&, void*) _override { return *this; }
virtual MockActualCall& withOutputParameterOfType(const SimpleString&, const SimpleString&, void*) _override { return *this; }
virtual bool hasReturnValue() _override { return false; }
virtual MockNamedValue returnValue() _override { return MockNamedValue(""); }
virtual bool returnBoolValueOrDefault(bool value) _override { return value; }
virtual bool returnBoolValue() _override { return false; }
virtual int returnIntValue() _override { return 0; }
virtual int returnIntValueOrDefault(int value) _override { return value; }
virtual unsigned long int returnUnsignedLongIntValue() _override { return 0; }
virtual unsigned long int returnUnsignedLongIntValueOrDefault(unsigned long int value) _override { return value; }
virtual long int returnLongIntValue() _override { return 0; }
virtual long int returnLongIntValueOrDefault(long int value) _override { return value; }
virtual cpputest_ulonglong returnUnsignedLongLongIntValue() _override { return 0; }
virtual cpputest_ulonglong returnUnsignedLongLongIntValueOrDefault(cpputest_ulonglong value) _override { return value; }
virtual cpputest_longlong returnLongLongIntValue() _override { return 0; }
virtual cpputest_longlong returnLongLongIntValueOrDefault(cpputest_longlong value) _override { return value; }
virtual unsigned int returnUnsignedIntValue() _override { return 0; }
virtual unsigned int returnUnsignedIntValueOrDefault(unsigned int value) _override { return value; }
virtual double returnDoubleValue() _override { return 0.0; }
virtual double returnDoubleValueOrDefault(double value) _override { return value; }
virtual const char * returnStringValue() _override { return ""; }
virtual const char * returnStringValueOrDefault(const char * value) _override { return value; }
virtual void * returnPointerValue() _override { return NULLPTR; }
virtual void * returnPointerValueOrDefault(void * value) _override { return value; }
virtual const void * returnConstPointerValue() _override { return NULLPTR; }
virtual const void * returnConstPointerValueOrDefault(const void * value) _override { return value; }
virtual void (*returnFunctionPointerValue())() _override { return NULLPTR; }
virtual void (*returnFunctionPointerValueOrDefault(void (*value)()))() _override { return value; }
virtual MockActualCall& onObject(const void* ) _override { return *this; }
static MockIgnoredActualCall& instance();
};
#endif

View file

@ -0,0 +1,195 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_MockCheckedExpectedCall_h
#define D_MockCheckedExpectedCall_h
#include "CppUTestExt/MockExpectedCall.h"
#include "CppUTestExt/MockNamedValue.h"
class MockCheckedExpectedCall : public MockExpectedCall
{
public:
MockCheckedExpectedCall();
MockCheckedExpectedCall(unsigned int numCalls);
virtual ~MockCheckedExpectedCall() _destructor_override;
virtual MockExpectedCall& withName(const SimpleString& name) _override;
virtual MockExpectedCall& withCallOrder(unsigned int callOrder) _override { return withCallOrder(callOrder, callOrder); }
virtual MockExpectedCall& withCallOrder(unsigned int initialCallOrder, unsigned int finalCallOrder) _override;
virtual MockExpectedCall& withBoolParameter(const SimpleString& name, bool value) _override;
virtual MockExpectedCall& withIntParameter(const SimpleString& name, int value) _override;
virtual MockExpectedCall& withUnsignedIntParameter(const SimpleString& name, unsigned int value) _override;
virtual MockExpectedCall& withLongIntParameter(const SimpleString& name, long int value) _override;
virtual MockExpectedCall& withUnsignedLongIntParameter(const SimpleString& name, unsigned long int value) _override;
virtual MockExpectedCall& withLongLongIntParameter(const SimpleString& name, cpputest_longlong value) _override;
virtual MockExpectedCall& withUnsignedLongLongIntParameter(const SimpleString& name, cpputest_ulonglong value) _override;
virtual MockExpectedCall& withDoubleParameter(const SimpleString& name, double value) _override;
virtual MockExpectedCall& withDoubleParameter(const SimpleString& name, double value, double tolerance) _override;
virtual MockExpectedCall& withStringParameter(const SimpleString& name, const char* value) _override;
virtual MockExpectedCall& withPointerParameter(const SimpleString& name, void* value) _override;
virtual MockExpectedCall& withConstPointerParameter(const SimpleString& name, const void* value) _override;
virtual MockExpectedCall& withFunctionPointerParameter(const SimpleString& name, void (*value)()) _override;
virtual MockExpectedCall& withMemoryBufferParameter(const SimpleString& name, const unsigned char* value, size_t size) _override;
virtual MockExpectedCall& withParameterOfType(const SimpleString& typeName, const SimpleString& name, const void* value) _override;
virtual MockExpectedCall& withOutputParameterReturning(const SimpleString& name, const void* value, size_t size) _override;
virtual MockExpectedCall& withOutputParameterOfTypeReturning(const SimpleString& typeName, const SimpleString& name, const void* value) _override;
virtual MockExpectedCall& withUnmodifiedOutputParameter(const SimpleString& name) _override;
virtual MockExpectedCall& ignoreOtherParameters() _override;
virtual MockExpectedCall& andReturnValue(bool value) _override;
virtual MockExpectedCall& andReturnValue(int value) _override;
virtual MockExpectedCall& andReturnValue(unsigned int value) _override;
virtual MockExpectedCall& andReturnValue(long int value) _override;
virtual MockExpectedCall& andReturnValue(unsigned long int value) _override;
virtual MockExpectedCall& andReturnValue(cpputest_longlong value) _override;
virtual MockExpectedCall& andReturnValue(cpputest_ulonglong value) _override;
virtual MockExpectedCall& andReturnValue(double value) _override;
virtual MockExpectedCall& andReturnValue(const char* value) _override;
virtual MockExpectedCall& andReturnValue(void* value) _override;
virtual MockExpectedCall& andReturnValue(const void* value) _override;
virtual MockExpectedCall& andReturnValue(void (*value)()) _override;
virtual MockNamedValue returnValue();
virtual MockExpectedCall& onObject(void* objectPtr) _override;
virtual MockNamedValue getInputParameter(const SimpleString& name);
virtual MockNamedValue getOutputParameter(const SimpleString& name);
virtual SimpleString getInputParameterType(const SimpleString& name);
virtual SimpleString getInputParameterValueString(const SimpleString& name);
virtual bool hasInputParameterWithName(const SimpleString& name);
virtual bool hasInputParameter(const MockNamedValue& parameter);
virtual bool hasOutputParameterWithName(const SimpleString& name);
virtual bool hasOutputParameter(const MockNamedValue& parameter);
virtual bool relatesTo(const SimpleString& functionName);
virtual bool relatesToObject(const void* objectPtr) const;
virtual bool isFulfilled();
virtual bool canMatchActualCalls();
virtual bool isMatchingActualCallAndFinalized();
virtual bool isMatchingActualCall();
virtual bool areParametersMatchingActualCall();
virtual bool isOutOfOrder() const;
virtual void callWasMade(unsigned int callOrder);
virtual void inputParameterWasPassed(const SimpleString& name);
virtual void outputParameterWasPassed(const SimpleString& name);
virtual void finalizeActualCallMatch();
virtual void wasPassedToObject();
virtual void resetActualCallMatchingState();
virtual SimpleString callToString();
virtual SimpleString missingParametersToString();
enum { NO_EXPECTED_CALL_ORDER = 0 };
virtual unsigned int getActualCallsFulfilled() const;
protected:
void setName(const SimpleString& name);
SimpleString getName() const;
private:
SimpleString functionName_;
class MockExpectedFunctionParameter : public MockNamedValue
{
public:
MockExpectedFunctionParameter(const SimpleString& name);
void setMatchesActualCall(bool b);
bool isMatchingActualCall() const;
private:
bool matchesActualCall_;
};
MockExpectedFunctionParameter* item(MockNamedValueListNode* node);
bool ignoreOtherParameters_;
bool isActualCallMatchFinalized_;
unsigned int initialExpectedCallOrder_;
unsigned int finalExpectedCallOrder_;
bool outOfOrder_;
MockNamedValueList* inputParameters_;
MockNamedValueList* outputParameters_;
MockNamedValue returnValue_;
void* objectPtr_;
bool isSpecificObjectExpected_;
bool wasPassedToObject_;
unsigned int actualCalls_;
unsigned int expectedCalls_;
};
class MockIgnoredExpectedCall: public MockExpectedCall
{
public:
virtual MockExpectedCall& withName(const SimpleString&) _override { return *this;}
virtual MockExpectedCall& withCallOrder(unsigned int) _override { return *this; }
virtual MockExpectedCall& withCallOrder(unsigned int, unsigned int) _override { return *this; }
virtual MockExpectedCall& withBoolParameter(const SimpleString&, bool) _override { return *this; }
virtual MockExpectedCall& withIntParameter(const SimpleString&, int) _override { return *this; }
virtual MockExpectedCall& withUnsignedIntParameter(const SimpleString&, unsigned int) _override{ return *this; }
virtual MockExpectedCall& withLongIntParameter(const SimpleString&, long int) _override { return *this; }
virtual MockExpectedCall& withUnsignedLongIntParameter(const SimpleString&, unsigned long int) _override { return *this; }
virtual MockExpectedCall& withLongLongIntParameter(const SimpleString&, cpputest_longlong) _override { return *this; }
virtual MockExpectedCall& withUnsignedLongLongIntParameter(const SimpleString&, cpputest_ulonglong) _override { return *this; }
virtual MockExpectedCall& withDoubleParameter(const SimpleString&, double) _override { return *this; }
virtual MockExpectedCall& withDoubleParameter(const SimpleString&, double, double) _override { return *this; }
virtual MockExpectedCall& withStringParameter(const SimpleString&, const char*) _override { return *this; }
virtual MockExpectedCall& withPointerParameter(const SimpleString& , void*) _override { return *this; }
virtual MockExpectedCall& withConstPointerParameter(const SimpleString& , const void*) _override { return *this; }
virtual MockExpectedCall& withFunctionPointerParameter(const SimpleString& , void(*)()) _override { return *this; }
virtual MockExpectedCall& withMemoryBufferParameter(const SimpleString&, const unsigned char*, size_t) _override { return *this; }
virtual MockExpectedCall& withParameterOfType(const SimpleString&, const SimpleString&, const void*) _override { return *this; }
virtual MockExpectedCall& withOutputParameterReturning(const SimpleString&, const void*, size_t) _override { return *this; }
virtual MockExpectedCall& withOutputParameterOfTypeReturning(const SimpleString&, const SimpleString&, const void*) _override { return *this; }
virtual MockExpectedCall& withUnmodifiedOutputParameter(const SimpleString&) _override { return *this; }
virtual MockExpectedCall& ignoreOtherParameters() _override { return *this;}
virtual MockExpectedCall& andReturnValue(bool) _override { return *this; }
virtual MockExpectedCall& andReturnValue(int) _override { return *this; }
virtual MockExpectedCall& andReturnValue(unsigned int) _override { return *this; }
virtual MockExpectedCall& andReturnValue(long int) _override { return *this; }
virtual MockExpectedCall& andReturnValue(unsigned long int) _override { return *this; }
virtual MockExpectedCall& andReturnValue(cpputest_longlong) _override { return *this; }
virtual MockExpectedCall& andReturnValue(cpputest_ulonglong) _override { return *this; }
virtual MockExpectedCall& andReturnValue(double) _override { return *this;}
virtual MockExpectedCall& andReturnValue(const char*) _override { return *this; }
virtual MockExpectedCall& andReturnValue(void*) _override { return *this; }
virtual MockExpectedCall& andReturnValue(const void*) _override { return *this; }
virtual MockExpectedCall& andReturnValue(void (*)()) _override { return *this; }
virtual MockExpectedCall& onObject(void*) _override { return *this; }
static MockExpectedCall& instance();
};
#endif

View file

@ -0,0 +1,96 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_MockExpectedCall_h
#define D_MockExpectedCall_h
#include "CppUTest/CppUTestConfig.h"
class MockNamedValue;
extern SimpleString StringFrom(const MockNamedValue& parameter);
class MockExpectedCall
{
public:
MockExpectedCall();
virtual ~MockExpectedCall();
virtual MockExpectedCall& withName(const SimpleString& name)=0;
virtual MockExpectedCall& withCallOrder(unsigned int)=0;
virtual MockExpectedCall& withCallOrder(unsigned int, unsigned int)=0;
MockExpectedCall& withParameter(const SimpleString& name, bool value) { return withBoolParameter(name, value); }
MockExpectedCall& withParameter(const SimpleString& name, int value) { return withIntParameter(name, value); }
MockExpectedCall& withParameter(const SimpleString& name, unsigned int value) { return withUnsignedIntParameter(name, value); }
MockExpectedCall& withParameter(const SimpleString& name, long int value) { return withLongIntParameter(name, value); }
MockExpectedCall& withParameter(const SimpleString& name, unsigned long int value) { return withUnsignedLongIntParameter(name, value); }
MockExpectedCall& withParameter(const SimpleString& name, cpputest_longlong value) { return withLongLongIntParameter(name, value); }
MockExpectedCall& withParameter(const SimpleString& name, cpputest_ulonglong value) { return withUnsignedLongLongIntParameter(name, value); }
MockExpectedCall& withParameter(const SimpleString& name, double value) { return withDoubleParameter(name, value); }
MockExpectedCall& withParameter(const SimpleString& name, double value, double tolerance) { return withDoubleParameter(name, value, tolerance); }
MockExpectedCall& withParameter(const SimpleString& name, const char* value) { return withStringParameter(name, value); }
MockExpectedCall& withParameter(const SimpleString& name, void* value) { return withPointerParameter(name, value); }
MockExpectedCall& withParameter(const SimpleString& name, const void* value) { return withConstPointerParameter(name, value); }
MockExpectedCall& withParameter(const SimpleString& name, void (*value)()) { return withFunctionPointerParameter(name, value); }
MockExpectedCall& withParameter(const SimpleString& name, const unsigned char* value, size_t size) { return withMemoryBufferParameter(name, value, size); }
virtual MockExpectedCall& withParameterOfType(const SimpleString& typeName, const SimpleString& name, const void* value)=0;
virtual MockExpectedCall& withOutputParameterReturning(const SimpleString& name, const void* value, size_t size)=0;
virtual MockExpectedCall& withOutputParameterOfTypeReturning(const SimpleString& typeName, const SimpleString& name, const void* value)=0;
virtual MockExpectedCall& withUnmodifiedOutputParameter(const SimpleString& name)=0;
virtual MockExpectedCall& ignoreOtherParameters()=0;
virtual MockExpectedCall& withBoolParameter(const SimpleString& name, bool value)=0;
virtual MockExpectedCall& withIntParameter(const SimpleString& name, int value)=0;
virtual MockExpectedCall& withUnsignedIntParameter(const SimpleString& name, unsigned int value)=0;
virtual MockExpectedCall& withLongIntParameter(const SimpleString& name, long int value)=0;
virtual MockExpectedCall& withUnsignedLongIntParameter(const SimpleString& name, unsigned long int value)=0;
virtual MockExpectedCall& withLongLongIntParameter(const SimpleString& name, cpputest_longlong value)=0;
virtual MockExpectedCall& withUnsignedLongLongIntParameter(const SimpleString& name, cpputest_ulonglong value)=0;
virtual MockExpectedCall& withDoubleParameter(const SimpleString& name, double value)=0;
virtual MockExpectedCall& withDoubleParameter(const SimpleString& name, double value, double tolerance)=0;
virtual MockExpectedCall& withStringParameter(const SimpleString& name, const char* value)=0;
virtual MockExpectedCall& withPointerParameter(const SimpleString& name, void* value)=0;
virtual MockExpectedCall& withFunctionPointerParameter(const SimpleString& name, void (*value)())=0;
virtual MockExpectedCall& withConstPointerParameter(const SimpleString& name, const void* value)=0;
virtual MockExpectedCall& withMemoryBufferParameter(const SimpleString& name, const unsigned char* value, size_t size)=0;
virtual MockExpectedCall& andReturnValue(bool value)=0;
virtual MockExpectedCall& andReturnValue(int value)=0;
virtual MockExpectedCall& andReturnValue(unsigned int value)=0;
virtual MockExpectedCall& andReturnValue(long int value)=0;
virtual MockExpectedCall& andReturnValue(unsigned long int value)=0;
virtual MockExpectedCall& andReturnValue(cpputest_longlong value)=0;
virtual MockExpectedCall& andReturnValue(cpputest_ulonglong value)=0;
virtual MockExpectedCall& andReturnValue(double value)=0;
virtual MockExpectedCall& andReturnValue(const char* value)=0;
virtual MockExpectedCall& andReturnValue(void* value)=0;
virtual MockExpectedCall& andReturnValue(const void* value)=0;
virtual MockExpectedCall& andReturnValue(void (*value)())=0;
virtual MockExpectedCall& onObject(void* objectPtr)=0;
};
#endif

View file

@ -0,0 +1,99 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_MockExpectedCallsList_h
#define D_MockExpectedCallsList_h
class MockCheckedExpectedCall;
class MockNamedValue;
class MockExpectedCallsList
{
public:
MockExpectedCallsList();
virtual ~MockExpectedCallsList();
virtual void deleteAllExpectationsAndClearList();
virtual unsigned int size() const;
virtual unsigned int amountOfActualCallsFulfilledFor(const SimpleString& name) const;
virtual unsigned int amountOfUnfulfilledExpectations() const;
virtual bool hasUnfulfilledExpectations() const;
virtual bool hasFinalizedMatchingExpectations() const;
virtual bool hasUnmatchingExpectationsBecauseOfMissingParameters() const;
virtual bool hasExpectationWithName(const SimpleString& name) const;
virtual bool hasCallsOutOfOrder() const;
virtual bool isEmpty() const;
virtual void addExpectedCall(MockCheckedExpectedCall* call);
virtual void addExpectations(const MockExpectedCallsList& list);
virtual void addExpectationsRelatedTo(const SimpleString& name, const MockExpectedCallsList& list);
virtual void onlyKeepOutOfOrderExpectations();
virtual void addPotentiallyMatchingExpectations(const MockExpectedCallsList& list);
virtual void onlyKeepExpectationsRelatedTo(const SimpleString& name);
virtual void onlyKeepExpectationsWithInputParameter(const MockNamedValue& parameter);
virtual void onlyKeepExpectationsWithInputParameterName(const SimpleString& name);
virtual void onlyKeepExpectationsWithOutputParameter(const MockNamedValue& parameter);
virtual void onlyKeepExpectationsWithOutputParameterName(const SimpleString& name);
virtual void onlyKeepExpectationsOnObject(const void* objectPtr);
virtual void onlyKeepUnmatchingExpectations();
virtual MockCheckedExpectedCall* removeFirstFinalizedMatchingExpectation();
virtual MockCheckedExpectedCall* removeFirstMatchingExpectation();
virtual MockCheckedExpectedCall* getFirstMatchingExpectation();
virtual void resetActualCallMatchingState();
virtual void wasPassedToObject();
virtual void parameterWasPassed(const SimpleString& parameterName);
virtual void outputParameterWasPassed(const SimpleString& parameterName);
virtual SimpleString unfulfilledCallsToString(const SimpleString& linePrefix = "") const;
virtual SimpleString fulfilledCallsToString(const SimpleString& linePrefix = "") const;
virtual SimpleString missingParametersToString() const;
protected:
virtual void pruneEmptyNodeFromList();
class MockExpectedCallsListNode
{
public:
MockCheckedExpectedCall* expectedCall_;
MockExpectedCallsListNode* next_;
MockExpectedCallsListNode(MockCheckedExpectedCall* expectedCall)
: expectedCall_(expectedCall), next_(NULLPTR) {}
};
private:
MockExpectedCallsListNode* head_;
MockExpectedCallsList(const MockExpectedCallsList&);
};
#endif

View file

@ -0,0 +1,123 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_MockFailure_h
#define D_MockFailure_h
#include "CppUTest/TestFailure.h"
class MockExpectedCallsList;
class MockCheckedActualCall;
class MockNamedValue;
class MockFailure;
class MockFailureReporter
{
protected:
bool crashOnFailure_;
public:
MockFailureReporter() : crashOnFailure_(false){}
virtual ~MockFailureReporter() {}
virtual void failTest(const MockFailure& failure);
virtual UtestShell* getTestToFail();
virtual void crashOnFailure(bool shouldCrash) { crashOnFailure_ = shouldCrash; }
};
class MockFailure : public TestFailure
{
public:
MockFailure(UtestShell* test);
virtual ~MockFailure() _destructor_override {}
protected:
void addExpectationsAndCallHistory(const MockExpectedCallsList& expectations);
void addExpectationsAndCallHistoryRelatedTo(const SimpleString& function, const MockExpectedCallsList& expectations);
};
class MockExpectedCallsDidntHappenFailure : public MockFailure
{
public:
MockExpectedCallsDidntHappenFailure(UtestShell* test, const MockExpectedCallsList& expectations);
};
class MockUnexpectedCallHappenedFailure : public MockFailure
{
public:
MockUnexpectedCallHappenedFailure(UtestShell* test, const SimpleString& name, const MockExpectedCallsList& expectations);
};
class MockCallOrderFailure : public MockFailure
{
public:
MockCallOrderFailure(UtestShell* test, const MockExpectedCallsList& expectations);
};
class MockUnexpectedInputParameterFailure : public MockFailure
{
public:
MockUnexpectedInputParameterFailure(UtestShell* test, const SimpleString& functionName, const MockNamedValue& parameter, const MockExpectedCallsList& expectations);
};
class MockUnexpectedOutputParameterFailure : public MockFailure
{
public:
MockUnexpectedOutputParameterFailure(UtestShell* test, const SimpleString& functionName, const MockNamedValue& parameter, const MockExpectedCallsList& expectations);
};
class MockExpectedParameterDidntHappenFailure : public MockFailure
{
public:
MockExpectedParameterDidntHappenFailure(UtestShell* test, const SimpleString& functionName, const MockExpectedCallsList& expectations);
};
class MockNoWayToCompareCustomTypeFailure : public MockFailure
{
public:
MockNoWayToCompareCustomTypeFailure(UtestShell* test, const SimpleString& typeName);
};
class MockNoWayToCopyCustomTypeFailure : public MockFailure
{
public:
MockNoWayToCopyCustomTypeFailure(UtestShell* test, const SimpleString& typeName);
};
class MockUnexpectedObjectFailure : public MockFailure
{
public:
MockUnexpectedObjectFailure(UtestShell* test, const SimpleString& functionName, const void* expected, const MockExpectedCallsList& expectations);
};
class MockExpectedObjectDidntHappenFailure : public MockFailure
{
public:
MockExpectedObjectDidntHappenFailure(UtestShell* test, const SimpleString& functionName, const MockExpectedCallsList& expectations);
};
#endif

View file

@ -0,0 +1,251 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_MockNamedValue_h
#define D_MockNamedValue_h
#include "CppUTest/CppUTestConfig.h"
/*
* MockNamedValueComparator is an interface that needs to be used when creating Comparators.
* This is needed when comparing values of non-native type.
*/
class MockNamedValueComparator
{
public:
MockNamedValueComparator() {}
virtual ~MockNamedValueComparator() {}
virtual bool isEqual(const void* object1, const void* object2)=0;
virtual SimpleString valueToString(const void* object)=0;
};
/*
* MockNamedValueCopier is an interface that needs to be used when creating Copiers.
* This is needed when copying values of non-native type.
*/
class MockNamedValueCopier
{
public:
MockNamedValueCopier() {}
virtual ~MockNamedValueCopier() {}
virtual void copy(void* out, const void* in)=0;
};
class MockFunctionComparator : public MockNamedValueComparator
{
public:
typedef bool (*isEqualFunction)(const void*, const void*);
typedef SimpleString (*valueToStringFunction)(const void*);
MockFunctionComparator(isEqualFunction equal, valueToStringFunction valToString)
: equal_(equal), valueToString_(valToString) {}
virtual bool isEqual(const void* object1, const void* object2) _override { return equal_(object1, object2); }
virtual SimpleString valueToString(const void* object) _override { return valueToString_(object); }
private:
isEqualFunction equal_;
valueToStringFunction valueToString_;
};
class MockFunctionCopier : public MockNamedValueCopier
{
public:
typedef void (*copyFunction)(void*, const void*);
MockFunctionCopier(copyFunction copier) : copier_(copier) {}
virtual void copy(void* dst, const void* src) _override { copier_(dst, src); }
private:
copyFunction copier_;
};
/*
* MockNamedValue is the generic value class used. It encapsulates basic types and can use them "as if one"
* Also it enables other types by putting object pointers. They can be compared with comparators.
*
* Basically this class ties together a Name, a Value, a Type, and a Comparator
*/
class MockNamedValueComparatorsAndCopiersRepository;
class MockNamedValue
{
public:
MockNamedValue(const SimpleString& name);
DEFAULT_COPY_CONSTRUCTOR(MockNamedValue)
virtual ~MockNamedValue();
virtual void setValue(bool value);
virtual void setValue(int value);
virtual void setValue(unsigned int value);
virtual void setValue(long int value);
virtual void setValue(unsigned long int value);
virtual void setValue(cpputest_longlong value);
virtual void setValue(cpputest_ulonglong value);
virtual void setValue(double value);
virtual void setValue(double value, double tolerance);
virtual void setValue(void* value);
virtual void setValue(const void* value);
virtual void setValue(void (*value)());
virtual void setValue(const char* value);
virtual void setMemoryBuffer(const unsigned char* value, size_t size);
virtual void setConstObjectPointer(const SimpleString& type, const void* objectPtr);
virtual void setObjectPointer(const SimpleString& type, void* objectPtr);
virtual void setSize(size_t size);
virtual void setName(const char* name);
virtual bool equals(const MockNamedValue& p) const;
virtual bool compatibleForCopying(const MockNamedValue& p) const;
virtual SimpleString toString() const;
virtual SimpleString getName() const;
virtual SimpleString getType() const;
virtual bool getBoolValue() const;
virtual int getIntValue() const;
virtual unsigned int getUnsignedIntValue() const;
virtual long int getLongIntValue() const;
virtual unsigned long int getUnsignedLongIntValue() const;
virtual cpputest_longlong getLongLongIntValue() const;
virtual cpputest_ulonglong getUnsignedLongLongIntValue() const;
virtual double getDoubleValue() const;
virtual double getDoubleTolerance() const;
virtual const char* getStringValue() const;
virtual void* getPointerValue() const;
virtual const void* getConstPointerValue() const;
virtual void (*getFunctionPointerValue() const)();
virtual const unsigned char* getMemoryBuffer() const;
virtual const void* getConstObjectPointer() const;
virtual void* getObjectPointer() const;
virtual size_t getSize() const;
virtual MockNamedValueComparator* getComparator() const;
virtual MockNamedValueCopier* getCopier() const;
static void setDefaultComparatorsAndCopiersRepository(MockNamedValueComparatorsAndCopiersRepository* repository);
static MockNamedValueComparatorsAndCopiersRepository* getDefaultComparatorsAndCopiersRepository();
static const double defaultDoubleTolerance;
private:
SimpleString name_;
SimpleString type_;
union {
bool boolValue_;
int intValue_;
unsigned int unsignedIntValue_;
long int longIntValue_;
unsigned long int unsignedLongIntValue_;
#ifdef CPPUTEST_USE_LONG_LONG
cpputest_longlong longLongIntValue_;
cpputest_ulonglong unsignedLongLongIntValue_;
#else
char longLongPlaceholder_[CPPUTEST_SIZE_OF_FAKE_LONG_LONG_TYPE];
#endif
struct {
double value;
double tolerance;
} doubleValue_;
const char* stringValue_;
void* pointerValue_;
const void* constPointerValue_;
void (*functionPointerValue_)();
const unsigned char* memoryBufferValue_;
const void* constObjectPointerValue_;
void* objectPointerValue_;
const void* outputPointerValue_;
} value_;
size_t size_;
MockNamedValueComparator* comparator_;
MockNamedValueCopier* copier_;
static MockNamedValueComparatorsAndCopiersRepository* defaultRepository_;
};
class MockNamedValueListNode
{
public:
MockNamedValueListNode(MockNamedValue* newValue);
SimpleString getName() const;
SimpleString getType() const;
MockNamedValueListNode* next();
MockNamedValue* item();
void destroy();
void setNext(MockNamedValueListNode* node);
private:
MockNamedValue* data_;
MockNamedValueListNode* next_;
};
class MockNamedValueList
{
public:
MockNamedValueList();
MockNamedValueListNode* begin();
void add(MockNamedValue* newValue);
void clear();
MockNamedValue* getValueByName(const SimpleString& name);
private:
MockNamedValueListNode* head_;
};
/*
* MockParameterComparatorRepository is a class which stores comparators and copiers which can be used for comparing non-native types
*
*/
struct MockNamedValueComparatorsAndCopiersRepositoryNode;
class MockNamedValueComparatorsAndCopiersRepository
{
MockNamedValueComparatorsAndCopiersRepositoryNode* head_;
public:
MockNamedValueComparatorsAndCopiersRepository();
virtual ~MockNamedValueComparatorsAndCopiersRepository();
virtual void installComparator(const SimpleString& name, MockNamedValueComparator& comparator);
virtual void installCopier(const SimpleString& name, MockNamedValueCopier& copier);
virtual void installComparatorsAndCopiers(const MockNamedValueComparatorsAndCopiersRepository& repository);
virtual MockNamedValueComparator* getComparatorForType(const SimpleString& name);
virtual MockNamedValueCopier* getCopierForType(const SimpleString& name);
void clear();
};
#endif

View file

@ -0,0 +1,165 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_MockSupport_h
#define D_MockSupport_h
#include "CppUTestExt/MockFailure.h"
#include "CppUTestExt/MockCheckedActualCall.h"
#include "CppUTestExt/MockCheckedExpectedCall.h"
#include "CppUTestExt/MockExpectedCallsList.h"
class UtestShell;
class MockSupport;
/* This allows access to "the global" mocking support for easier testing */
MockSupport& mock(const SimpleString& mockName = "", MockFailureReporter* failureReporterForThisCall = NULLPTR);
class MockSupport
{
public:
MockSupport(const SimpleString& mockName = "");
virtual ~MockSupport();
virtual void strictOrder();
virtual MockExpectedCall& expectOneCall(const SimpleString& functionName);
virtual void expectNoCall(const SimpleString& functionName);
virtual MockExpectedCall& expectNCalls(unsigned int amount, const SimpleString& functionName);
virtual MockActualCall& actualCall(const SimpleString& functionName);
virtual bool hasReturnValue();
virtual MockNamedValue returnValue();
virtual bool boolReturnValue();
virtual bool returnBoolValueOrDefault(bool defaultValue);
virtual int intReturnValue();
virtual int returnIntValueOrDefault(int defaultValue);
virtual unsigned int unsignedIntReturnValue();
virtual long int longIntReturnValue();
virtual long int returnLongIntValueOrDefault(long int defaultValue);
virtual unsigned long int unsignedLongIntReturnValue();
virtual unsigned long int returnUnsignedLongIntValueOrDefault(unsigned long int defaultValue);
virtual cpputest_longlong longLongIntReturnValue();
virtual cpputest_longlong returnLongLongIntValueOrDefault(cpputest_longlong defaultValue);
virtual cpputest_ulonglong unsignedLongLongIntReturnValue();
virtual cpputest_ulonglong returnUnsignedLongLongIntValueOrDefault(cpputest_ulonglong defaultValue);
virtual unsigned int returnUnsignedIntValueOrDefault(unsigned int defaultValue);
virtual const char* stringReturnValue();
virtual const char* returnStringValueOrDefault(const char * defaultValue);
virtual double returnDoubleValueOrDefault(double defaultValue);
virtual double doubleReturnValue();
virtual void* pointerReturnValue();
virtual void* returnPointerValueOrDefault(void * defaultValue);
virtual const void* returnConstPointerValueOrDefault(const void * defaultValue);
virtual const void* constPointerReturnValue();
virtual void (*returnFunctionPointerValueOrDefault(void (*defaultValue)()))();
virtual void (*functionPointerReturnValue())();
bool hasData(const SimpleString& name);
void setData(const SimpleString& name, bool value);
void setData(const SimpleString& name, int value);
void setData(const SimpleString& name, unsigned int value);
void setData(const SimpleString& name, const char* value);
void setData(const SimpleString& name, double value);
void setData(const SimpleString& name, void* value);
void setData(const SimpleString& name, const void* value);
void setData(const SimpleString& name, void (*value)());
void setDataObject(const SimpleString& name, const SimpleString& type, void* value);
void setDataConstObject(const SimpleString& name, const SimpleString& type, const void* value);
MockNamedValue getData(const SimpleString& name);
MockSupport* getMockSupportScope(const SimpleString& name);
const char* getTraceOutput();
/*
* The following functions are recursively through the lower MockSupports scopes
* This means, if you do mock().disable() it will disable *all* mocking scopes, including mock("myScope").
*/
virtual void disable();
virtual void enable();
virtual void tracing(bool enabled);
virtual void ignoreOtherCalls();
virtual void checkExpectations();
virtual bool expectedCallsLeft();
virtual void clear();
virtual void crashOnFailure(bool shouldFail = true);
/*
* Each mock() call will set the activeReporter to standard, unless a special reporter is passed for this call.
*/
virtual void setMockFailureStandardReporter(MockFailureReporter* reporter);
virtual void setActiveReporter(MockFailureReporter* activeReporter);
virtual void setDefaultComparatorsAndCopiersRepository();
virtual void installComparator(const SimpleString& typeName, MockNamedValueComparator& comparator);
virtual void installCopier(const SimpleString& typeName, MockNamedValueCopier& copier);
virtual void installComparatorsAndCopiers(const MockNamedValueComparatorsAndCopiersRepository& repository);
virtual void removeAllComparatorsAndCopiers();
protected:
MockSupport* clone(const SimpleString& mockName);
virtual MockCheckedActualCall *createActualCall();
virtual void failTest(MockFailure& failure);
void countCheck();
private:
unsigned int actualCallOrder_;
unsigned int expectedCallOrder_;
bool strictOrdering_;
MockFailureReporter *activeReporter_;
MockFailureReporter *standardReporter_;
MockFailureReporter defaultReporter_;
MockExpectedCallsList expectations_;
bool ignoreOtherCalls_;
bool enabled_;
MockCheckedActualCall *lastActualFunctionCall_;
MockNamedValueComparatorsAndCopiersRepository comparatorsAndCopiersRepository_;
MockNamedValueList data_;
const SimpleString mockName_;
bool tracing_;
void checkExpectationsOfLastActualCall();
bool wasLastActualCallFulfilled();
void failTestWithExpectedCallsNotFulfilled();
void failTestWithOutOfOrderCalls();
MockNamedValue* retrieveDataFromStore(const SimpleString& name);
MockSupport* getMockSupport(MockNamedValueListNode* node);
bool callIsIgnored(const SimpleString& functionName);
bool hasCallsOutOfOrder();
SimpleString appendScopeToName(const SimpleString& functionName);
};
#endif

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_MockSupportPlugin_h
#define D_MockSupportPlugin_h
#include "CppUTest/TestPlugin.h"
#include "CppUTestExt/MockNamedValue.h"
class MockSupportPlugin : public TestPlugin
{
public:
MockSupportPlugin(const SimpleString& name = "MockSupportPLugin");
virtual ~MockSupportPlugin() _destructor_override;
virtual void preTestAction(UtestShell&, TestResult&) _override;
virtual void postTestAction(UtestShell&, TestResult&) _override;
virtual void installComparator(const SimpleString& name, MockNamedValueComparator& comparator);
virtual void installCopier(const SimpleString& name, MockNamedValueCopier& copier);
void clear();
private:
MockNamedValueComparatorsAndCopiersRepository repository_;
};
#endif

View file

@ -0,0 +1,238 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_MockSupport_c_h
#define D_MockSupport_c_h
#ifdef __cplusplus
extern "C" {
#endif
#include "CppUTest/CppUTestConfig.h"
#include "CppUTest/StandardCLibrary.h"
typedef enum {
MOCKVALUETYPE_BOOL,
MOCKVALUETYPE_UNSIGNED_INTEGER,
MOCKVALUETYPE_INTEGER,
MOCKVALUETYPE_LONG_INTEGER,
MOCKVALUETYPE_UNSIGNED_LONG_INTEGER,
MOCKVALUETYPE_LONG_LONG_INTEGER,
MOCKVALUETYPE_UNSIGNED_LONG_LONG_INTEGER,
MOCKVALUETYPE_DOUBLE,
MOCKVALUETYPE_STRING,
MOCKVALUETYPE_POINTER,
MOCKVALUETYPE_CONST_POINTER,
MOCKVALUETYPE_FUNCTIONPOINTER,
MOCKVALUETYPE_MEMORYBUFFER,
MOCKVALUETYPE_OBJECT
} MockValueType_c;
typedef struct SMockValue_c
{
MockValueType_c type;
union {
int boolValue;
int intValue;
unsigned int unsignedIntValue;
long int longIntValue;
unsigned long int unsignedLongIntValue;
#ifdef CPPUTEST_USE_LONG_LONG
cpputest_longlong longLongIntValue;
cpputest_ulonglong unsignedLongLongIntValue;
#else
char longLongPlaceholder[CPPUTEST_SIZE_OF_FAKE_LONG_LONG_TYPE];
#endif
double doubleValue;
const char* stringValue;
void* pointerValue;
const void* constPointerValue;
void (*functionPointerValue)(void);
const unsigned char* memoryBufferValue;
void* objectValue;
const void* constObjectValue;
} value;
} MockValue_c;
typedef struct SMockActualCall_c MockActualCall_c;
struct SMockActualCall_c
{
MockActualCall_c* (*withBoolParameters)(const char* name, int value);
MockActualCall_c* (*withIntParameters)(const char* name, int value);
MockActualCall_c* (*withUnsignedIntParameters)(const char* name, unsigned int value);
MockActualCall_c* (*withLongIntParameters)(const char* name, long int value);
MockActualCall_c* (*withUnsignedLongIntParameters)(const char* name, unsigned long int value);
MockActualCall_c* (*withLongLongIntParameters)(const char* name, cpputest_longlong value);
MockActualCall_c* (*withUnsignedLongLongIntParameters)(const char* name, cpputest_ulonglong value);
MockActualCall_c* (*withDoubleParameters)(const char* name, double value);
MockActualCall_c* (*withStringParameters)(const char* name, const char* value);
MockActualCall_c* (*withPointerParameters)(const char* name, void* value);
MockActualCall_c* (*withConstPointerParameters)(const char* name, const void* value);
MockActualCall_c* (*withFunctionPointerParameters)(const char* name, void (*value)(void));
MockActualCall_c* (*withMemoryBufferParameter)(const char* name, const unsigned char* value, size_t size);
MockActualCall_c* (*withParameterOfType)(const char* type, const char* name, const void* value);
MockActualCall_c* (*withOutputParameter)(const char* name, void* value);
MockActualCall_c* (*withOutputParameterOfType)(const char* type, const char* name, void* value);
int (*hasReturnValue)(void);
MockValue_c (*returnValue)(void);
int (*boolReturnValue)(void);
int (*returnBoolValueOrDefault)(int defaultValue);
int (*intReturnValue)(void);
int (*returnIntValueOrDefault)(int defaultValue);
unsigned int (*unsignedIntReturnValue)(void);
unsigned int (*returnUnsignedIntValueOrDefault)(unsigned int defaultValue);
long int (*longIntReturnValue)(void);
long int (*returnLongIntValueOrDefault)(long int defaultValue);
unsigned long int (*unsignedLongIntReturnValue)(void);
unsigned long int (*returnUnsignedLongIntValueOrDefault)(unsigned long int defaultValue);
cpputest_longlong (*longLongIntReturnValue)(void);
cpputest_longlong (*returnLongLongIntValueOrDefault)(cpputest_longlong defaultValue);
cpputest_ulonglong (*unsignedLongLongIntReturnValue)(void);
cpputest_ulonglong (*returnUnsignedLongLongIntValueOrDefault)(cpputest_ulonglong defaultValue);
const char* (*stringReturnValue)(void);
const char* (*returnStringValueOrDefault)(const char * defaultValue);
double (*doubleReturnValue)(void);
double (*returnDoubleValueOrDefault)(double defaultValue);
void* (*pointerReturnValue)(void);
void* (*returnPointerValueOrDefault)(void * defaultValue);
const void* (*constPointerReturnValue)(void);
const void* (*returnConstPointerValueOrDefault)(const void * defaultValue);
void (*(*functionPointerReturnValue)(void))(void);
void (*(*returnFunctionPointerValueOrDefault)(void(*defaultValue)(void)))(void);
};
typedef struct SMockExpectedCall_c MockExpectedCall_c;
struct SMockExpectedCall_c
{
MockExpectedCall_c* (*withBoolParameters)(const char* name, int value);
MockExpectedCall_c* (*withIntParameters)(const char* name, int value);
MockExpectedCall_c* (*withUnsignedIntParameters)(const char* name, unsigned int value);
MockExpectedCall_c* (*withLongIntParameters)(const char* name, long int value);
MockExpectedCall_c* (*withUnsignedLongIntParameters)(const char* name, unsigned long int value);
MockExpectedCall_c* (*withLongLongIntParameters)(const char* name, cpputest_longlong value);
MockExpectedCall_c* (*withUnsignedLongLongIntParameters)(const char* name, cpputest_ulonglong value);
MockExpectedCall_c* (*withDoubleParameters)(const char* name, double value);
MockExpectedCall_c* (*withDoubleParametersAndTolerance)(const char* name, double value, double tolerance);
MockExpectedCall_c* (*withStringParameters)(const char* name, const char* value);
MockExpectedCall_c* (*withPointerParameters)(const char* name, void* value);
MockExpectedCall_c* (*withConstPointerParameters)(const char* name, const void* value);
MockExpectedCall_c* (*withFunctionPointerParameters)(const char* name, void (*value)(void));
MockExpectedCall_c* (*withMemoryBufferParameter)(const char* name, const unsigned char* value, size_t size);
MockExpectedCall_c* (*withParameterOfType)(const char* type, const char* name, const void* value);
MockExpectedCall_c* (*withOutputParameterReturning)(const char* name, const void* value, size_t size);
MockExpectedCall_c* (*withOutputParameterOfTypeReturning)(const char* type, const char* name, const void* value);
MockExpectedCall_c* (*withUnmodifiedOutputParameter)(const char* name);
MockExpectedCall_c* (*ignoreOtherParameters)(void);
MockExpectedCall_c* (*andReturnBoolValue)(int value);
MockExpectedCall_c* (*andReturnUnsignedIntValue)(unsigned int value);
MockExpectedCall_c* (*andReturnIntValue)(int value);
MockExpectedCall_c* (*andReturnLongIntValue)(long int value);
MockExpectedCall_c* (*andReturnUnsignedLongIntValue)(unsigned long int value);
MockExpectedCall_c* (*andReturnLongLongIntValue)(cpputest_longlong value);
MockExpectedCall_c* (*andReturnUnsignedLongLongIntValue)(cpputest_ulonglong value);
MockExpectedCall_c* (*andReturnDoubleValue)(double value);
MockExpectedCall_c* (*andReturnStringValue)(const char* value);
MockExpectedCall_c* (*andReturnPointerValue)(void* value);
MockExpectedCall_c* (*andReturnConstPointerValue)(const void* value);
MockExpectedCall_c* (*andReturnFunctionPointerValue)(void (*value)(void));
};
typedef int (*MockTypeEqualFunction_c)(const void* object1, const void* object2);
typedef const char* (*MockTypeValueToStringFunction_c)(const void* object1);
typedef void (*MockTypeCopyFunction_c)(void* dst, const void* src);
typedef struct SMockSupport_c MockSupport_c;
struct SMockSupport_c
{
void (*strictOrder)(void);
MockExpectedCall_c* (*expectOneCall)(const char* name);
void (*expectNoCall)(const char* name);
MockExpectedCall_c* (*expectNCalls)(unsigned int number, const char* name);
MockActualCall_c* (*actualCall)(const char* name);
int (*hasReturnValue)(void);
MockValue_c (*returnValue)(void);
int (*boolReturnValue)(void);
int (*returnBoolValueOrDefault)(int defaultValue);
int (*intReturnValue)(void);
int (*returnIntValueOrDefault)(int defaultValue);
unsigned int (*unsignedIntReturnValue)(void);
unsigned int (*returnUnsignedIntValueOrDefault)(unsigned int defaultValue);
long int (*longIntReturnValue)(void);
long int (*returnLongIntValueOrDefault)(long int defaultValue);
unsigned long int (*unsignedLongIntReturnValue)(void);
unsigned long int (*returnUnsignedLongIntValueOrDefault)(unsigned long int defaultValue);
cpputest_longlong (*longLongIntReturnValue)(void);
cpputest_longlong (*returnLongLongIntValueOrDefault)(cpputest_longlong defaultValue);
cpputest_ulonglong (*unsignedLongLongIntReturnValue)(void);
cpputest_ulonglong (*returnUnsignedLongLongIntValueOrDefault)(cpputest_ulonglong defaultValue);
const char* (*stringReturnValue)(void);
const char* (*returnStringValueOrDefault)(const char * defaultValue);
double (*doubleReturnValue)(void);
double (*returnDoubleValueOrDefault)(double defaultValue);
void* (*pointerReturnValue)(void);
void* (*returnPointerValueOrDefault)(void * defaultValue);
const void* (*constPointerReturnValue)(void);
const void* (*returnConstPointerValueOrDefault)(const void * defaultValue);
void (*(*functionPointerReturnValue)(void))(void);
void (*(*returnFunctionPointerValueOrDefault) (void(*defaultValue)(void)))(void);
void (*setBoolData) (const char* name, int value);
void (*setIntData) (const char* name, int value);
void (*setUnsignedIntData) (const char* name, unsigned int value);
void (*setStringData) (const char* name, const char* value);
void (*setDoubleData) (const char* name, double value);
void (*setPointerData) (const char* name, void* value);
void (*setConstPointerData) (const char* name, const void* value);
void (*setFunctionPointerData) (const char* name, void (*value)(void));
void (*setDataObject) (const char* name, const char* type, void* value);
void (*setDataConstObject) (const char* name, const char* type, const void* value);
MockValue_c (*getData)(const char* name);
void (*disable)(void);
void (*enable)(void);
void (*ignoreOtherCalls)(void);
void (*checkExpectations)(void);
int (*expectedCallsLeft)(void);
void (*clear)(void);
void (*crashOnFailure)(unsigned shouldCrash);
void (*installComparator) (const char* typeName, MockTypeEqualFunction_c isEqual, MockTypeValueToStringFunction_c valueToString);
void (*installCopier) (const char* typeName, MockTypeCopyFunction_c copier);
void (*removeAllComparatorsAndCopiers)(void);
};
MockSupport_c* mock_c(void);
MockSupport_c* mock_scope_c(const char* scope);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,87 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef D_OrderedTest_h
#define D_OrderedTest_h
class OrderedTestShell : public UtestShell
{
public:
OrderedTestShell();
virtual ~OrderedTestShell() _destructor_override;
virtual OrderedTestShell* addOrderedTest(OrderedTestShell* test);
virtual OrderedTestShell* getNextOrderedTest();
int getLevel();
void setLevel(int level);
static void addOrderedTestToHead(OrderedTestShell* test);
static OrderedTestShell* getOrderedTestHead();
static bool firstOrderedTest();
static void setOrderedTestHead(OrderedTestShell* test);
private:
static OrderedTestShell* _orderedTestsHead;
OrderedTestShell* _nextOrderedTest;
int _level;
};
class OrderedTestInstaller
{
public:
explicit OrderedTestInstaller(OrderedTestShell& test, const char* groupName, const char* testName, const char* fileName, size_t lineNumber, int level);
virtual ~OrderedTestInstaller();
private:
void addOrderedTestInOrder(OrderedTestShell* test);
void addOrderedTestInOrderNotAtHeadPosition(OrderedTestShell* test);
};
#define TEST_ORDERED(testGroup, testName, testLevel) \
/* declarations for compilers */ \
class TEST_##testGroup##_##testName##_TestShell; \
extern TEST_##testGroup##_##testName##_TestShell TEST_##testGroup##_##testName##_Instance; \
class TEST_##testGroup##_##testName##_Test : public TEST_GROUP_##CppUTestGroup##testGroup \
{ public: TEST_##testGroup##_##testName##_Test () : TEST_GROUP_##CppUTestGroup##testGroup () {} \
void testBody() _override; }; \
class TEST_##testGroup##_##testName##_TestShell : public OrderedTestShell { \
virtual Utest* createTest() _override { return new TEST_##testGroup##_##testName##_Test; } \
} TEST_##testGroup##_##testName##_Instance; \
static OrderedTestInstaller TEST_##testGroup##_##testName##_Installer(TEST_##testGroup##_##testName##_Instance, #testGroup, #testName, __FILE__,__LINE__, testLevel); \
void TEST_##testGroup##_##testName##_Test::testBody()
#define TEST_ORDERED_C_WRAPPER(group_name, test_name, testLevel) \
extern "C" void test_##group_name##_##test_name##_wrapper_c(void); \
TEST_ORDERED(group_name, test_name, testLevel) { \
test_##group_name##_##test_name##_wrapper_c(); \
}
#endif

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2007, Michael Feathers, James Grenning, Bas Vodde
* and Arnd R. Strube
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef stdint_wrapper_h
#define stdint_wrapper_h
#include <stdint.h>
typedef unsigned char uint8_t; /* This will still compile to 16 bit */
#endif /* stdint_wrapper_h */