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,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