ID
int64
1
1.09k
Language
stringclasses
1 value
Repository Name
stringclasses
8 values
File Name
stringlengths
3
35
File Path in Repository
stringlengths
9
82
File Path for Unit Test
stringclasses
5 values
Code
stringlengths
17
1.91M
Unit Test - (Ground Truth)
stringclasses
5 values
301
cpp
blalor-cpputest
AllTests.cpp
examples/AllTests/AllTests.cpp
null
/* * 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. */ #include "CppUTest/CommandLineTestRunner.h" #include "CppUTest/TestPlugin.h" #include "CppUTest/TestRegistry.h" #include "CppUTestExt/MockSupportPlugin.h" class MyDummyComparator : public MockNamedValueComparator { public: virtual bool isEqual(void* object1, void* object2) { return object1 == object2; } virtual SimpleString valueToString(void* object) { return StringFrom(object); } }; int main(int ac, char** av) { MyDummyComparator dummyComparator; MockSupportPlugin mockPlugin; mockPlugin.installComparator("MyDummyType", dummyComparator); TestRegistry::getCurrentRegistry()->installPlugin(&mockPlugin); return CommandLineTestRunner::RunAllTests(ac, av); } #include "ApplicationLib/AllTests.h"
null
302
cpp
blalor-cpputest
PrinterTest.cpp
examples/ApplicationLib/PrinterTest.cpp
null
/* * 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. */ #include "CppUTest/TestHarness.h" #include "Printer.h" #include "MockPrinter.h" TEST_GROUP(Printer) { Printer* printer; MockPrinter* mockPrinter; void setup() { mockPrinter = new MockPrinter(); printer = mockPrinter; } void teardown() { delete printer; } }; TEST(Printer, PrintConstCharStar) { printer->Print("hello"); printer->Print("hello\n"); CHECK_EQUAL("hellohello\n", mockPrinter->getOutput()); } TEST(Printer, PrintLong) { printer->Print(1234); CHECK_EQUAL("1234", mockPrinter->getOutput()); } TEST(Printer, StreamOperators) { *printer << "n=" << 1234; CHECK_EQUAL("n=1234", mockPrinter->getOutput()); }
null
303
cpp
blalor-cpputest
HelloTest.cpp
examples/ApplicationLib/HelloTest.cpp
null
/* * 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. */ extern "C" { #include "hello.h" } #include <stdio.h> #include <stdarg.h> #include "CppUTest/TestHarness.h" static SimpleString* buffer; TEST_GROUP(HelloWorld) { static int output_method(const char* output, ...) { va_list arguments; va_start(arguments, output); *buffer = VStringFromFormat(output, arguments); va_end(arguments); return 1; } void setup() { buffer = new SimpleString(); UT_PTR_SET(PrintFormated, &output_method); } void teardown() { delete buffer; } }; TEST(HelloWorld, PrintOk) { printHelloWorld(); STRCMP_EQUAL("Hello World!\n", buffer->asCharString()); }
null
304
cpp
blalor-cpputest
CircularBuffer.cpp
examples/ApplicationLib/CircularBuffer.cpp
null
/* * 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. */ #include "CircularBuffer.h" #include "Printer.h" CircularBuffer::CircularBuffer(int _capacity) : index(0), outdex(0), capacity(_capacity), empty(true), full(false) { buffer = new int[this->capacity]; } CircularBuffer::~CircularBuffer() { delete[] buffer; } bool CircularBuffer::IsEmpty() { return empty; } bool CircularBuffer::IsFull() { return full; } void CircularBuffer::Put(int i) { empty = false; buffer[index] = i; index = Next(index); if (full) outdex = Next(outdex); else if (index == outdex) full = true; } int CircularBuffer::Get() { int result = -1; full = false; if (!empty) { result = buffer[outdex]; outdex = Next(outdex); if (outdex == index) empty = true; } return result; } int CircularBuffer::Capacity() { return capacity; } int CircularBuffer::Next(int i) { if (++i >= capacity) i = 0; return i; } void CircularBuffer::Print(Printer* p) { p->Print("Circular buffer content:\n<"); int printIndex = outdex; int count = index - outdex; if (!empty && (index <= outdex)) count = capacity - (outdex - index); for (int i = 0; i < count; i++) { p->Print(buffer[printIndex]); printIndex = Next(printIndex); if (i + 1 != count) p->Print(", "); } p->Print(">\n"); }
null
305
cpp
blalor-cpputest
hello.h
examples/ApplicationLib/hello.h
null
/* * 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 HELLO_H_ #define HELLO_H_ extern void printHelloWorld(); extern int (*PrintFormated)(const char*, ...); #endif /*HELLO_H_*/
null
306
cpp
blalor-cpputest
Printer.h
examples/ApplicationLib/Printer.h
null
/* * 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_Printer_H #define D_Printer_H /////////////////////////////////////////////////////////////////////////////// // // Printer is responsible for ... // /////////////////////////////////////////////////////////////////////////////// class Printer { public: explicit Printer(); virtual ~Printer(); virtual void Print(const char*); virtual void Print(long int); private: Printer(const Printer&); Printer& operator=(const Printer&); }; Printer& operator<<(Printer&, const char*); Printer& operator<<(Printer&, long int); #endif // D_Printer_H
null
307
cpp
blalor-cpputest
ExamplesNewOverrides.h
examples/ApplicationLib/ExamplesNewOverrides.h
null
/* * 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. */ #include <list> #include "CppUTest/MemoryLeakDetectorNewMacros.h"
null
308
cpp
blalor-cpputest
EventDispatcherTest.cpp
examples/ApplicationLib/EventDispatcherTest.cpp
null
/* * 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. */ #include "CppUTest/TestHarness.h" #include "CppUTestExt/MockSupport.h" #include "EventDispatcher.h" class ObserverMock : public EventObserver { public: virtual void notify(const Event& event, int timeOutInSeconds) { mock().actualCall("notify").onObject(this).withParameterOfType("Event", "event", (void*) &event).withParameter("timeOutInSeconds", timeOutInSeconds); } virtual void notifyRegistration(EventObserver* newObserver) { mock().actualCall("notifyRegistration").onObject(this).withParameter("newObserver", newObserver); } }; class EventComparator : public MockNamedValueComparator { public: virtual bool isEqual(void* object1, void* object2) { return ((Event*)object1)->type == ((Event*)object2)->type; } virtual SimpleString valueToString(void* object) { return StringFrom(((Event*)object)->type); } }; TEST_GROUP(EventDispatcher) { Event event; EventDispatcher* dispatcher; ObserverMock observer; ObserverMock observer2; EventComparator eventComparator; void setup() { dispatcher = new EventDispatcher; mock().installComparator("Event", eventComparator); } void teardown() { delete dispatcher; mock().removeAllComparators(); } }; TEST(EventDispatcher, EventWithoutRegistrationsResultsIntoNoCalls) { dispatcher->dispatchEvent(event, 10); } TEST(EventDispatcher, EventWithRegistrationForEventResultsIntoCallback) { mock().expectOneCall("notify").onObject(&observer).withParameterOfType("Event", "event", &event).withParameter("timeOutInSeconds", 10); event.type = IMPORTANT_EVENT; dispatcher->registerObserver(IMPORTANT_EVENT, &observer); dispatcher->dispatchEvent(event, 10); } TEST(EventDispatcher, DifferentEventWithRegistrationDoesNotResultIntoCallback) { event.type = LESS_IMPORTANT_EVENT; dispatcher->registerObserver(IMPORTANT_EVENT, &observer); dispatcher->dispatchEvent(event, 10); } TEST(EventDispatcher, RegisterTwoObserversResultIntoTwoCallsAndARegistrationNotification) { mock().expectOneCall("notify").onObject(&observer).withParameterOfType("Event", "event", &event).withParameter("timeOutInSeconds", 10); mock().expectOneCall("notify").onObject(&observer2).withParameterOfType("Event", "event", &event).withParameter("timeOutInSeconds", 10); mock().expectOneCall("notifyRegistration").onObject(&observer).withParameter("newObserver", &observer2); event.type = IMPORTANT_EVENT; dispatcher->registerObserver(IMPORTANT_EVENT, &observer); dispatcher->registerObserver(IMPORTANT_EVENT, &observer2); dispatcher->dispatchEvent(event, 10); }
null
309
cpp
blalor-cpputest
EventDispatcher.cpp
examples/ApplicationLib/EventDispatcher.cpp
null
/* * 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. */ #include "EventDispatcher.h" EventDispatcher::EventDispatcher() { } void EventDispatcher::registerObserver(EventType type, EventObserver* observer) { for (list<pair<EventType, EventObserver*> >::iterator i = observerList_.begin(); i != observerList_.end(); i++) i->second->notifyRegistration(observer); observerList_.push_back(make_pair(type, observer)); } void EventDispatcher::dispatchEvent(const Event& event, int timeoutSeconds) { for (list<pair<EventType, EventObserver*> >::iterator i = observerList_.begin(); i != observerList_.end(); i++) { if (i->first == event.type) i->second->notify(event, timeoutSeconds); } }
null
310
cpp
blalor-cpputest
MockPrinter.h
examples/ApplicationLib/MockPrinter.h
null
/* * 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_MockPrinter_H #define D_MockPrinter_H /////////////////////////////////////////////////////////////////////////////// // // MockPrinter.h // // MockPrinter is responsible for providing a test stub for Printer // /////////////////////////////////////////////////////////////////////////////// #include "Printer.h" #include "CppUTest/SimpleString.h" #include <stdlib.h> #include <string> class MockPrinter: public Printer { public: explicit MockPrinter() { } virtual ~MockPrinter() { } virtual void Print(const char* s) { savedOutput.append(s); } virtual void Print(long int value) { SimpleString buffer; buffer = StringFromFormat("%ld", value); savedOutput.append(buffer.asCharString()); } std::string getOutput() const { return savedOutput; } private: std::string savedOutput; MockPrinter(const MockPrinter&); MockPrinter& operator=(const MockPrinter&); }; #endif // D_MockPrinter_H
null
311
cpp
blalor-cpputest
EventDispatcher.h
examples/ApplicationLib/EventDispatcher.h
null
/* * 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 EVENTDISPATCHER__H #define EVENTDISPATCHER__H #include <list> using namespace std; enum EventType { IMPORTANT_EVENT, LESS_IMPORTANT_EVENT }; class Event { public: EventType type; }; class EventObserver { public: virtual void notify(const Event& event, int timeOutInSeconds)=0; virtual void notifyRegistration(EventObserver* newObserver)=0; }; class EventDispatcher { list<pair<EventType, EventObserver*> > observerList_; public: EventDispatcher(); void registerObserver(EventType type, EventObserver* observer); void dispatchEvent(const Event& event, int timeoutSeconds); }; #endif
null
312
cpp
blalor-cpputest
AllTests.h
examples/ApplicationLib/AllTests.h
null
/* * 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. */ IMPORT_TEST_GROUP( Printer); IMPORT_TEST_GROUP( CircularBuffer); IMPORT_TEST_GROUP( HelloWorld); IMPORT_TEST_GROUP( EventDispatcher); IMPORT_TEST_GROUP( MockDocumentation);
null
313
cpp
blalor-cpputest
Printer.cpp
examples/ApplicationLib/Printer.cpp
null
/* * 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. */ #include "Printer.h" #include "CppUTest/TestHarness.h" #include "CppUTest/SimpleString.h" #include <stdio.h> Printer::Printer() { } Printer::~Printer() { } void Printer::Print(const char* s) { for (const char* p = s; *p; p++) putchar(*p); } void Printer::Print(long n) { Print(StringFrom(n).asCharString()); } Printer& operator<<(Printer& p, const char* s) { p.Print(s); return p; } Printer& operator<<(Printer& p, long int i) { p.Print(i); return p; }
null
314
cpp
blalor-cpputest
CircularBuffer.h
examples/ApplicationLib/CircularBuffer.h
null
/* * 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_CircularBuffer_H #define D_CircularBuffer_H /////////////////////////////////////////////////////////////////////////////// // // CircularBuffer.h // // CircularBuffer is responsible for ... // /////////////////////////////////////////////////////////////////////////////// class Printer; class CircularBuffer { public: explicit CircularBuffer(int capacity = CAPACITY); virtual ~CircularBuffer(); void Put(int); int Get(); bool IsEmpty(); bool IsFull(); int Capacity(); int Next(int i); void Print(Printer*); private: int index; int outdex; int* buffer; int capacity; enum { CAPACITY = 5 }; bool empty; bool full; CircularBuffer(const CircularBuffer&); CircularBuffer& operator=(const CircularBuffer&); }; #endif // D_CircularBuffer_H
null
315
cpp
blalor-cpputest
CircularBufferTest.cpp
examples/ApplicationLib/CircularBufferTest.cpp
null
/* * 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. */ #include "CppUTest/TestHarness.h" #include "MockPrinter.h" #include "CircularBuffer.h" TEST_GROUP(CircularBuffer) { CircularBuffer* buffer; void setup() { buffer = new CircularBuffer(); } void teardown() { delete buffer; } void fillTheQueue(int seed, int howMany) { for (int i = 0; i < howMany; i++) buffer->Put(seed + i); } void removeFromQueue(int howMany) { for (int i = 0; i < howMany; i++) buffer->Get(); } }; TEST(CircularBuffer, EmptyAfterCreation) { CHECK(buffer->IsEmpty()); } TEST(CircularBuffer, NotEmpty) { buffer->Put(10046); CHECK(!buffer->IsEmpty()); } TEST(CircularBuffer, NotEmptyThenEmpty) { buffer->Put(4567); CHECK(!buffer->IsEmpty()); buffer->Get(); CHECK(buffer->IsEmpty()); } TEST(CircularBuffer, GetPutOneValue) { buffer->Put(4567); LONGS_EQUAL(4567, buffer->Get()); } TEST(CircularBuffer, GetPutAFew) { buffer->Put(1); buffer->Put(2); buffer->Put(3); LONGS_EQUAL(1, buffer->Get()); LONGS_EQUAL(2, buffer->Get()); LONGS_EQUAL(3, buffer->Get()); } TEST(CircularBuffer, Capacity) { CircularBuffer b(2); LONGS_EQUAL(2, b.Capacity()); } TEST(CircularBuffer, IsFull) { fillTheQueue(0, buffer->Capacity()); CHECK(buffer->IsFull()); } TEST(CircularBuffer, EmptyToFullToEmpty) { fillTheQueue(100, buffer->Capacity()); CHECK(buffer->IsFull()); removeFromQueue(buffer->Capacity()); CHECK(buffer->IsEmpty()); } TEST(CircularBuffer, WrapAround) { fillTheQueue(100, buffer->Capacity()); CHECK(buffer->IsFull()); LONGS_EQUAL(100, buffer->Get()); CHECK(!buffer->IsFull()); buffer->Put(1000); CHECK(buffer->IsFull()); removeFromQueue(buffer->Capacity() - 1); LONGS_EQUAL(1000, buffer->Get()); CHECK(buffer->IsEmpty()); } TEST(CircularBuffer, PutToFull) { int capacity = buffer->Capacity(); fillTheQueue(900, capacity); buffer->Put(9999); for (int i = 0; i < buffer->Capacity() - 1; i++) LONGS_EQUAL(i+900+1, buffer->Get()); LONGS_EQUAL(9999, buffer->Get()); CHECK(buffer->IsEmpty()); } //Sometime people ask what tests the tests. //Do you know the answer TEST(CircularBuffer, GetFromEmpty) { LONGS_EQUAL(-1, buffer->Get()); CHECK(buffer->IsEmpty()); } /* * the next tests demonstrate using a mock object for * capturing output * */ TEST(CircularBuffer, PrintEmpty) { MockPrinter mock; Printer* p = &mock; buffer->Print(p); CHECK_EQUAL("Circular buffer content:\n<>\n", mock.getOutput()); } TEST(CircularBuffer, PrintAfterOnePut) { MockPrinter mock; buffer->Put(1); buffer->Print(&mock); CHECK_EQUAL("Circular buffer content:\n<1>\n", mock.getOutput()); } TEST(CircularBuffer, PrintNotYetWrappedOrFull) { MockPrinter mock; buffer->Put(1); buffer->Put(2); buffer->Put(3); buffer->Print(&mock); CHECK_EQUAL("Circular buffer content:\n<1, 2, 3>\n", mock.getOutput()); } TEST(CircularBuffer, PrintNotYetWrappedAndIsFull) { MockPrinter mock; fillTheQueue(200, buffer->Capacity()); buffer->Print(&mock); const char* expected = "Circular buffer content:\n" "<200, 201, 202, 203, 204>\n"; CHECK_EQUAL(expected, mock.getOutput()); } TEST(CircularBuffer, PrintWrappedAndIsFullOldestToNewest) { MockPrinter mock; fillTheQueue(200, buffer->Capacity()); buffer->Get(); buffer->Put(999); buffer->Print(&mock); const char* expected = "Circular buffer content:\n" "<201, 202, 203, 204, 999>\n"; CHECK_EQUAL(expected, mock.getOutput()); } TEST(CircularBuffer, PrintWrappedAndFullOverwriteOldest) { MockPrinter mock; fillTheQueue(200, buffer->Capacity()); buffer->Put(9999); buffer->Print(&mock); const char* expected = "Circular buffer content:\n" "<201, 202, 203, 204, 9999>\n"; CHECK_EQUAL(expected, mock.getOutput()); } TEST(CircularBuffer, PrintBoundary) { MockPrinter mock; fillTheQueue(200, buffer->Capacity()); removeFromQueue(buffer->Capacity() - 2); buffer->Put(888); fillTheQueue(300, buffer->Capacity() - 1); buffer->Print(&mock); const char* expected = "Circular buffer content:\n" "<888, 300, 301, 302, 303>\n"; CHECK_EQUAL(expected, mock.getOutput()); } TEST(CircularBuffer, FillEmptyThenPrint) { MockPrinter mock; fillTheQueue(200, buffer->Capacity()); removeFromQueue(buffer->Capacity()); buffer->Print(&mock); const char* expected = "Circular buffer content:\n" "<>\n"; CHECK_EQUAL(expected, mock.getOutput()); }
null
316
cpp
blalor-cpputest
MockDocumentationTest.cpp
examples/ApplicationLib/MockDocumentationTest.cpp
null
/* * 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. */ #include "CppUTest/TestHarness.h" #include "CppUTestExt/MockSupport.h" extern "C" { #include "CppUTestExt/MockSupport_c.h" } TEST_GROUP(FirstTestGroup) { }; TEST(FirstTestGroup, FirsTest) { // FAIL("Fail me!"); } TEST(FirstTestGroup, SecondTest) { // STRCMP_EQUAL("hello", "world"); } TEST_GROUP(MockDocumentation) { }; void productionCode() { mock().actualCall("productionCode"); } TEST(MockDocumentation, SimpleScenario) { mock().expectOneCall("productionCode"); productionCode(); mock().checkExpectations(); } class ClassFromProductionCode { public: virtual void importantFunction(){} }; class ClassFromProductionCodeMock : public ClassFromProductionCode { public: virtual void importantFunction() { mock().actualCall("importantFunction").onObject(this); } }; TEST(MockDocumentation, SimpleScenarioObject) { ClassFromProductionCode* object = new ClassFromProductionCodeMock; /* create mock instead of real thing */ mock().expectOneCall("importantFunction").onObject(object); object->importantFunction(); mock().checkExpectations(); delete object; } void parameters_function(int p1, const char* p2) { void* object = (void*) 1; mock().actualCall("function").onObject(object).withParameter("p1", p1).withParameter("p2", p2); } TEST(MockDocumentation, parameters) { void* object = (void*) 1; mock().expectOneCall("function").onObject(object).withParameter("p1", 2).withParameter("p2", "hah"); parameters_function(2, "hah"); } class MyTypeComparator : public MockNamedValueComparator { public: virtual bool isEqual(void* object1, void* object2) { return object1 == object2; } virtual SimpleString valueToString(void* object) { return StringFrom(object); } }; TEST(MockDocumentation, ObjectParameters) { void* object = (void*) 1; MyTypeComparator comparator; mock().installComparator("myType", comparator); mock().expectOneCall("function").withParameterOfType("myType", "parameterName", object); mock().clear(); mock().removeAllComparators(); } TEST(MockDocumentation, returnValue) { mock().expectOneCall("function").andReturnValue(10); int value = mock().actualCall("function").returnValue().getIntValue(); value = mock().returnValue().getIntValue(); } TEST(MockDocumentation, setData) { ClassFromProductionCode object; mock().setData("importantValue", 10); mock().setDataObject("importantObject", "ClassFromProductionCode", &object); ClassFromProductionCode * pobject; int value = mock().getData("importantValue").getIntValue(); pobject = (ClassFromProductionCode*) mock().getData("importantObject").getObjectPointer(); LONGS_EQUAL(10, value); POINTERS_EQUAL(pobject, &object); } void doSomethingThatWouldOtherwiseBlowUpTheMockingFramework() { } TEST(MockDocumentation, otherMockSupport) { mock().crashOnFailure(); // mock().actualCall("unex"); mock().expectOneCall("foo"); mock().ignoreOtherCalls(); mock().disable(); doSomethingThatWouldOtherwiseBlowUpTheMockingFramework(); mock().enable(); mock().clear(); } TEST(MockDocumentation, scope) { mock("xmlparser").expectOneCall("open"); mock("filesystem").ignoreOtherCalls(); mock("xmlparser").actualCall("open"); } static int equalMethod(void* object1, void* object2) { return object1 == object2; } static char* toStringMethod(void*) { return (char*) "string"; } TEST(MockDocumentation, CInterface) { void* object = (void*) 0x1; mock_c()->expectOneCall("foo")->withIntParameters("integer", 10)->andReturnDoubleValue(1.11); mock_c()->actualCall("foo")->withIntParameters("integer", 10)->returnValue().value.doubleValue; mock_c()->installComparator("type", equalMethod, toStringMethod); mock_scope_c("scope")->expectOneCall("bar")->withParameterOfType("type", "name", object); mock_scope_c("scope")->actualCall("bar")->withParameterOfType("type", "name", object); mock_c()->removeAllComparators(); mock_c()->setIntData("important", 10); mock_c()->checkExpectations(); mock_c()->clear(); } TEST_GROUP(FooTestGroup) { void setup() { // Init stuff } void teardown() { // Uninit stuff } }; TEST(FooTestGroup, Foo) { // Test FOO } TEST(FooTestGroup, MoreFoo) { // Test more FOO } TEST_GROUP(BarTestGroup) { void setup() { // Init Bar } }; TEST(BarTestGroup, Bar) { // Test Bar }
null
317
cpp
blalor-cpputest
TestPlugin.h
include/CppUTest/TestPlugin.h
null
/* * 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. */ /////////////////////////////////////////////////////////////////////////////// // // TESTPlugin.H // // This file contains the ability to plugin_ general checks to all tests. // /////////////////////////////////////////////////////////////////////////////// #ifndef D_TestPlugin_h #define D_TestPlugin_h class Utest; class TestResult; class TestPlugin { public: TestPlugin(const SimpleString& name); virtual ~TestPlugin(); virtual void preTestAction(Utest&, TestResult&) { } virtual void postTestAction(Utest&, TestResult&) { } virtual bool parseArguments(int /* ac */, const char** /* av */, int /* index */ ) { return false; } virtual void runAllPreTestAction(Utest&, TestResult&); virtual void runAllPostTestAction(Utest&, TestResult&); virtual bool parseAllArguments(int ac, const char** av, int index); virtual bool parseAllArguments(int ac, char** av, int index); virtual TestPlugin* addPlugin(TestPlugin*); virtual TestPlugin* removePluginByName(const SimpleString& name); virtual TestPlugin* getNext(); virtual void disable(); virtual void enable(); virtual bool isEnabled(); const SimpleString& getName(); TestPlugin* getPluginByName(const SimpleString& name); protected: TestPlugin(TestPlugin* next_); private: TestPlugin* next_; SimpleString name_; bool enabled_; }; /////////////////////////////////////////////////////////////////////////////// // // SetPointerPlugin // // This is a very small plugin_ that resets pointers to their original value. // /////////////////////////////////////////////////////////////////////////////// extern void CppUTestStore(void **location, void *value); class SetPointerPlugin: public TestPlugin { public: SetPointerPlugin(const SimpleString& name); virtual ~SetPointerPlugin(); virtual void postTestAction(Utest&, TestResult&); enum { MAX_SET = 1024 }; }; /* C++ standard says we cannot cast function pointers to object pointers. Extra casting to fool the compiler */ #define UT_PTR_SET(a, b) { CppUTestStore( (void**)&a, *((void**) &a)); a = b; } ///////////// Null Plugin class NullTestPlugin: public TestPlugin { public: NullTestPlugin(); virtual ~NullTestPlugin() { } virtual void runAllPreTestAction(Utest& test, TestResult& result); virtual void runAllPostTestAction(Utest& test, TestResult& result); static NullTestPlugin* instance(); }; #endif
null
318
cpp
blalor-cpputest
PlatformSpecificFunctions.h
include/CppUTest/PlatformSpecificFunctions.h
null
/* * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the <organization> nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef PLATFORMSPECIFICFUNCTIONS_H_ #define PLATFORMSPECIFICFUNCTIONS_H_ /* Platform specific interface we use in order to minimize dependencies with LibC. * This enables porting to different embedded platforms. * */ /* For test execution control (long_jmp set_jmp) */ /* bool Utest::executePlatformSpecificSetup() * void Utest::executePlatformSpecificTestBody() * void Utest::executePlatformSpecificTeardown() * void Utest::executePlatformSpecificRunOneTest(TestPlugin* plugin, TestResult& result) * void Utest::executePlatformSpecificExitCurrentTest() */ /* Time operations */ long GetPlatformSpecificTimeInMillis(); void SetPlatformSpecificTimeInMillisMethod(long(*platformSpecific)()); const char* GetPlatformSpecificTimeString(); void SetPlatformSpecificTimeStringMethod(const char* (*platformMethod)()); /* String operations */ int PlatformSpecificAtoI(const char*str); size_t PlatformSpecificStrLen(const char* str); char* PlatformSpecificStrCat(char* s1, const char* s2); char* PlatformSpecificStrCpy(char* s1, const char* s2); char* PlatformSpecificStrNCpy(char* s1, const char* s2, size_t size); int PlatformSpecificStrCmp(const char* s1, const char* s2); int PlatformSpecificStrNCmp(const char* s1, const char* s2, size_t size); char* PlatformSpecificStrStr(const char* s1, const char* s2); int PlatformSpecificVSNprintf(char *str, unsigned int size, const char* format, va_list va_args_list); char PlatformSpecificToLower(char c); /* Misc */ double PlatformSpecificFabs(double d); int PlatformSpecificIsNan(double d); int PlatformSpecificAtExit(void(*func)()); /* IO operations */ typedef void* PlatformSpecificFile; PlatformSpecificFile PlatformSpecificFOpen(const char* filename, const char* flag); void PlatformSpecificFPuts(const char* str, PlatformSpecificFile file); void PlatformSpecificFClose(PlatformSpecificFile file); int PlatformSpecificPutchar(int c); void PlatformSpecificFlush(); /* Dynamic Memory operations */ void* PlatformSpecificMalloc(size_t size); void* PlatformSpecificRealloc(void* memory, size_t size); void PlatformSpecificFree(void* memory); void* PlatformSpecificMemCpy(void* s1, const void* s2, size_t size); void* PlatformSpecificMemset(void* mem, int c, size_t size); #endif
null
319
cpp
blalor-cpputest
TestResult.h
include/CppUTest/TestResult.h
null
/* * 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. */ /////////////////////////////////////////////////////////////////////////////// // // TESTRESULT.H // // A TestResult is a collection of the history of some test runs. Right now // it just collects failures. Really it just prints the failures. // /////////////////////////////////////////////////////////////////////////////// #ifndef D_TestResult_h #define D_TestResult_h class TestFailure; class TestOutput; class Utest; class TestResult { public: TestResult(TestOutput&); virtual ~TestResult(); virtual void testsStarted(); virtual void testsEnded(); virtual void currentGroupStarted(Utest* test); virtual void currentGroupEnded(Utest* test); virtual void currentTestStarted(Utest* test); virtual void currentTestEnded(Utest* test); virtual void countTest(); virtual void countRun(); virtual void countCheck(); virtual void countFilteredOut(); virtual void countIgnored(); virtual void addFailure(const TestFailure& failure); virtual void print(const char* text); virtual void setProgressIndicator(const char*); int getTestCount() const { return testCount_; } int getRunCount() const { return runCount_; } int getCheckCount() const { return checkCount_; } int getFilteredOutCount() const { return filteredOutCount_; } int getIgnoredCount() const { return ignoredCount_; } int getFailureCount() const { return failureCount_; } long getTotalExecutionTime() const; void setTotalExecutionTime(long exTime); long getCurrentTestTotalExecutionTime() const; long getCurrentGroupTotalExecutionTime() const; private: TestOutput& output_; int testCount_; int runCount_; int checkCount_; int failureCount_; int filteredOutCount_; int ignoredCount_; long totalExecutionTime_; long timeStarted_; long currentTestTimeStarted_; long currentTestTotalExecutionTime_; long currentGroupTimeStarted_; long currentGroupTotalExecutionTime_; }; #endif
null
320
cpp
blalor-cpputest
CommandLineArguments.h
include/CppUTest/CommandLineArguments.h
null
#ifndef D_CommandLineArguments_H #define D_CommandLineArguments_H /////////////////////////////////////////////////////////////////////////////// // // CommandLineArguments is responsible for ... // /////////////////////////////////////////////////////////////////////////////// #include "SimpleString.h" #include "TestOutput.h" class TestPlugin; class CommandLineArguments { public: explicit CommandLineArguments(int ac, const char** av); virtual ~CommandLineArguments(); bool parse(TestPlugin* plugin); bool isVerbose() const; int getRepeatCount() const; SimpleString getGroupFilter() const; SimpleString getNameFilter() const; bool isJUnitOutput() const; bool isEclipseOutput() const; const char* usage() const; private: enum OutputType { OUTPUT_ECLIPSE, OUTPUT_JUNIT }; int ac_; const char** av_; bool verbose_; int repeat_; SimpleString groupFilter_; SimpleString nameFilter_; OutputType outputType_; SimpleString getParameterField(int ac, const char** av, int& i); void SetRepeatCount(int ac, const char** av, int& index); void SetGroupFilter(int ac, const char** av, int& index); void SetNameFilter(int ac, const char** av, int& index); bool SetOutputType(int ac, const char** av, int& index); CommandLineArguments(const CommandLineArguments&); CommandLineArguments& operator=(const CommandLineArguments&); }; #endif // D_CommandLineArguments_H
null
321
cpp
blalor-cpputest
TestHarness.h
include/CppUTest/TestHarness.h
null
/* * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the <organization> nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef D_TestHarness_h #define D_TestHarness_h /* Memory leak detector macros: * * CPPUTEST_USE_MEM_LEAK_DETECTION pr CPPUTEST_MEM_LEAK_DETECTION_DISABLED * Controls the override of the global operator new/deleted and malloc/free. * Without this, there will be no memory leak detection in C/C++. */ #ifndef CPPUTEST_USE_MEM_LEAK_DETECTION #ifdef CPPUTEST_MEM_LEAK_DETECTION_DISABLED #define CPPUTEST_USE_MEM_LEAK_DETECTION 0 #else #define CPPUTEST_USE_MEM_LEAK_DETECTION 1 #endif #endif #ifndef CPPUTEST_USE_STD_CPP_LIB #ifdef CPPUTEST_STD_CPP_LIB_DISABLED #define CPPUTEST_USE_STD_CPP_LIB 0 #else #define CPPUTEST_USE_STD_CPP_LIB 1 #endif #endif /* original value was 9973 which works well with large programs. Now set to smaller since it takes * a lot of memory in embedded apps. Change it if you experience the memory leak detector to be slow. */ #define MEMORY_LEAK_HASH_TABLE_SIZE 73 /* * Lib C dependencies that are currently still left: * * stdarg.h -> We use formatting functions and va_list requires to include stdarg.h in SimpleString * stdlib.h -> The TestHarness_c.h includes this to try to avoid conflicts in its malloc #define. This dependency can * easily be removed by not enabling the MALLOC overrides. * * Lib C++ dependencies are all under the CPPUTEST_USE_STD_CPP_LIB. * The only dependency is to <new> which has the bad_alloc struct * */ #include "Utest.h" #include "UtestMacros.h" #include "SimpleString.h" #include "TestResult.h" #include "TestFailure.h" #include "TestPlugin.h" #include "MemoryLeakWarningPlugin.h" #endif
null
322
cpp
blalor-cpputest
JUnitTestOutput.h
include/CppUTest/JUnitTestOutput.h
null
/* * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the <organization> nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef D_JUnitTestOutput_h #define D_JUnitTestOutput_h #include "TestOutput.h" #include "SimpleString.h" struct JUnitTestOutputImpl; struct JUnitTestCaseResultNode; class JUnitTestOutput: public TestOutput { public: JUnitTestOutput(); virtual ~JUnitTestOutput(); virtual void printTestsStarted(); virtual void printTestsEnded(const TestResult& result); virtual void printCurrentTestStarted(const Utest& test); virtual void printCurrentTestEnded(const TestResult& res); virtual void printCurrentGroupStarted(const Utest& test); virtual void printCurrentGroupEnded(const TestResult& res); virtual void verbose(); virtual void printBuffer(const char*); virtual void print(const char*); virtual void print(long); virtual void print(const TestFailure& failure); virtual void printTestRun(int number, int total); virtual void flush(); protected: JUnitTestOutputImpl* impl_; void resetTestGroupResult(); virtual void openFileForWrite(const SimpleString& fileName); virtual void writeTestGroupToFile(); virtual void writeToFile(const SimpleString& buffer); virtual void closeFile(); virtual void writeXmlHeader(); virtual void writeTestSuiteSummery(); virtual void writeProperties(); virtual void writeTestCases(); virtual void writeFailure(JUnitTestCaseResultNode* node); virtual void writeFileEnding(); }; #endif
null
323
cpp
blalor-cpputest
TestTestingFixture.h
include/CppUTest/TestTestingFixture.h
null
/* * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the <organization> nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef D_TestTestingFixture_H #define D_TestTestingFixture_H class TestTestingFixture { public: TestTestingFixture() { output_ = new StringBufferTestOutput(); result_ = new TestResult(*output_); genTest_ = new ExecFunctionTest(); registry_ = new TestRegistry(); registry_->setCurrentRegistry(registry_); registry_->addTest(genTest_); } ; virtual ~TestTestingFixture() { registry_->setCurrentRegistry(0); delete registry_; delete result_; delete output_; delete genTest_; } void setTestFunction(void(*testFunction)()) { genTest_->testFunction_ = testFunction; } void setSetup(void(*setupFunction)()) { genTest_->setup_ = setupFunction; } void setTeardown(void(*teardownFunction)()) { genTest_->teardown_ = teardownFunction; } void runAllTests() { registry_->runAllTests(*result_); } int getFailureCount() { return result_->getFailureCount(); } void assertPrintContains(const SimpleString& contains) { assertPrintContains(output_, contains); } static void assertPrintContains(StringBufferTestOutput* output, const SimpleString& contains) { if (output->getOutput().contains(contains)) return; SimpleString message("\tActual <"); message += output->getOutput().asCharString(); message += ">\n"; message += "\tdid not contain <"; message += contains.asCharString(); message += ">\n"; FAIL(message.asCharString()); } TestRegistry* registry_; ExecFunctionTest* genTest_; StringBufferTestOutput* output_; TestResult * result_; }; #endif
null
324
cpp
blalor-cpputest
TestFailure.h
include/CppUTest/TestFailure.h
null
/* * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the <organization> nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /////////////////////////////////////////////////////////////////////////////// // // FAILURE.H // // Failure is a class which holds information for a specific // test failure. It can be overriden for more complex failure messages // /////////////////////////////////////////////////////////////////////////////// #ifndef D_TestFailure_H #define D_TestFailure_H #include "SimpleString.h" class Utest; class TestOutput; class TestFailure { public: TestFailure(Utest*, const char* fileName, int lineNumber, const SimpleString& theMessage); TestFailure(Utest*, const SimpleString& theMessage); TestFailure(Utest*, const char* fileName, int lineNumber); TestFailure(const TestFailure&); virtual ~TestFailure(); virtual SimpleString getFileName() const; virtual SimpleString getTestName() const; virtual int getFailureLineNumber() const; virtual SimpleString getMessage() const; virtual SimpleString getTestFileName() const; virtual int getTestLineNumber() const; bool isOutsideTestFile() const; bool isInHelperFunction() const; protected: SimpleString createButWasString(const SimpleString& expected, const SimpleString& actual); SimpleString createDifferenceAtPosString(const SimpleString& actual, int position); SimpleString testName_; SimpleString fileName_; int lineNumber_; SimpleString testFileName_; int testLineNumber_; SimpleString message_; TestFailure& operator=(const TestFailure&); }; class EqualsFailure: public TestFailure { public: EqualsFailure(Utest*, const char* fileName, int lineNumber, const char* expected, const char* actual); EqualsFailure(Utest*, const char* fileName, int lineNumber, const SimpleString& expected, const SimpleString& actual); }; class DoublesEqualFailure: public TestFailure { public: DoublesEqualFailure(Utest*, const char* fileName, int lineNumber, double expected, double actual, double threshold); }; class CheckEqualFailure : public TestFailure { public: CheckEqualFailure(Utest* test, const char* fileName, int lineNumber, const SimpleString& expected, const SimpleString& actual); }; class ContainsFailure: public TestFailure { public: ContainsFailure(Utest*, const char* fileName, int lineNumber, const SimpleString& expected, const SimpleString& actual); }; class CheckFailure : public TestFailure { public: CheckFailure(Utest* test, const char* fileName, int lineNumber, const SimpleString& checkString, const SimpleString& conditionString); }; class FailFailure : public TestFailure { public: FailFailure(Utest* test, const char* fileName, int lineNumber, const SimpleString& message); }; class LongsEqualFailure : public TestFailure { public: LongsEqualFailure(Utest* test, const char* fileName, int lineNumber, long expected, long actual); }; class StringEqualFailure : public TestFailure { public: StringEqualFailure(Utest* test, const char* fileName, int lineNumber, const char* expected, const char* actual); }; class StringEqualNoCaseFailure : public TestFailure { public: StringEqualNoCaseFailure(Utest* test, const char* fileName, int lineNumber, const char* expected, const char* actual); }; #endif
null
325
cpp
blalor-cpputest
CommandLineTestRunner.h
include/CppUTest/CommandLineTestRunner.h
null
/* * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the <organization> nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef D_CommandLineTestRunner_H #define D_CommandLineTestRunner_H #include "TestHarness.h" #include "TestOutput.h" #include "CommandLineArguments.h" /////////////////////////////////////////////////////////////////////////////// // // Main entry point for running a collection of unit tests // /////////////////////////////////////////////////////////////////////////////// class JUnitTestOutput; #define DEF_PLUGIN_MEM_LEAK "MemoryLeakPlugin" #define DEF_PLUGIN_SET_POINTER "SetPointerPlugin" class CommandLineTestRunner { public: enum OutputType { OUTPUT_NORMAL, OUTPUT_JUNIT }; static int RunAllTests(int ac, const char** av); static int RunAllTests(int ac, char** av); CommandLineTestRunner(int ac, const char** av, TestOutput*); virtual ~CommandLineTestRunner(); int runAllTestsMain(); private: TestOutput* output_; JUnitTestOutput* jUnitOutput_; CommandLineArguments* arguments_; bool parseArguments(TestPlugin*); int runAllTests(); void initializeTestRun(); bool isVerbose(); int getRepeatCount(); SimpleString getGroupFilter(); SimpleString getNameFilter(); }; #endif
null
326
cpp
blalor-cpputest
MemoryLeakDetectorMallocMacros.h
include/CppUTest/MemoryLeakDetectorMallocMacros.h
null
/* * This file can be used to get extra debugging information about memory leaks in your production code. * It defines a preprocessor macro for malloc. This will pass additional information to the * malloc and this will give the line/file information of the memory leaks in your code. * * You can use this by including this file to all your production code. When using gcc, you can use * the -include file to do this for you. * */ /* Warning for maintainers: * This macro code is duplicate from TestHarness.h. The reason for this is to make the two files * completely independent from each other. NewMacros file can be included in production code whereas * TestHarness.h is only included in test code. */ #ifndef CPPUTEST_USE_MEM_LEAK_DETECTION #ifdef CPPUTEST_MEM_LEAK_DETECTION_DISABLED #define CPPUTEST_USE_MEM_LEAK_DETECTION 0 #else #define CPPUTEST_USE_MEM_LEAK_DETECTION 1 #endif #endif #if CPPUTEST_USE_MEM_LEAK_DETECTION /* This prevents the declaration from done twice and makes sure the file only #defines malloc, so it can be included anywhere */ #ifndef CPPUTEST_USE_MALLOC_MACROS #include "StandardCLibrary.h" extern void* cpputest_malloc_location(size_t size, const char* file, int line); extern void* cpputest_calloc_location(size_t count, size_t size, const char* file, int line); extern void* cpputest_ralloc_location(void *, size_t, const char* file, int line); extern void cpputest_free_location(void* buffer, const char* file, int line); #endif /* NOTE on strdup! * * strdup was implemented earlier, however it is *not* an Standard C function but a POSIX function. * Because of that, it can lead to portability issues by providing more than is available on the local platform. * For that reason, strdup is *not* implemented as a macro. If you still want to use it, an easy implementation would be: * * size_t length = 1 + strlen(str); * char* result = (char*) cpputest_malloc_location(length, file, line); * memcpy(result, str, length); * return result; * */ #define malloc(a) cpputest_malloc_location(a, __FILE__, __LINE__) #define calloc(a, b) cpputest_calloc_location(a, b, __FILE__, __LINE__) #define realloc(a, b) cpputest_realloc_location(a, b, __FILE__, __LINE__) #define free(a) cpputest_free_location(a, __FILE__, __LINE__) #define CPPUTEST_USE_MALLOC_MACROS 1 #endif
null
327
cpp
blalor-cpputest
VirtualCall.h
include/CppUTest/VirtualCall.h
null
#ifndef D_VirtualCall_H #define D_VirtualCall_H #define send(obj,msg)\ ((obj)->msg(obj)) #define send1(obj,msg,arg0)\ ((obj)->msg((obj),(arg0))) #define send2(obj,msg,arg0,arg1)\ ((obj)->msg((obj),(arg0),(arg1))) #define send3(obj,msg,arg0,arg1,arg2)\ ((obj)->msg((obj),(arg0),(arg1),(arg2))) #define send4(obj,msg,arg0,arg1,arg2,arg3)\ ((obj)->msg((obj),(arg0),(arg1),(arg2),(arg3))) #define vBind(obj,msg,newMethod)\ (obj->msg=&newMethod) #define castToDestroyer(Class) (Class* (*)(Class*)) #endif
null
328
cpp
blalor-cpputest
StandardCLibrary.h
include/CppUTest/StandardCLibrary.h
null
#ifndef STANDARDCLIBRARY_H_ #define STANDARDCLIBRARY_H_ #if CPPUTEST_STD_C_LIB_DISABLED #ifdef __KERNEL__ /* Unfinished and not working! Hacking hacking hacking. Why bother make the header files C++ safe! */ #define false kernel_false #define true kernel_true #define bool kernel_bool #define new kernel_new #define _Bool int #include <linux/acpi.h> #include <linux/types.h> #undef false #undef true #undef bool #undef new #else /* * #warning "These definitions in StandardCLibrary.h are pure (educated, from linux kernel) guesses at the moment. Replace with your platform includes." * Not on as warning are as errors :P */ typedef unsigned long size_t; typedef char* va_list; #define NULL (0) extern void* malloc(size_t); extern void free(void *); #define _bnd(X, bnd) (((sizeof (X)) + (bnd)) & (~(bnd))) #define va_start(ap, A) (void) ((ap) = (((char *) &(A)) + (_bnd (A,sizeof(int)-1)))) #define va_end(ap) (void) 0 #endif #else /* Needed for size_t */ #include <stddef.h> /* Needed for malloc */ #include <stdlib.h> /* Needed for ... */ #include <stdarg.h> #endif #endif
null
329
cpp
blalor-cpputest
MemoryLeakWarningPlugin.h
include/CppUTest/MemoryLeakWarningPlugin.h
null
/* * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the <organization> nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef D_MemoryLeakWarningPlugin_h #define D_MemoryLeakWarningPlugin_h #include "TestPlugin.h" /////////////////////////////////////////////////////////////////////////////// // // MemoryLeakWarning.h // // MemoryLeakWarning defines the inteface to a platform specific // memory leak detection class. See Platforms directory for examples // /////////////////////////////////////////////////////////////////////////////// #define IGNORE_ALL_LEAKS_IN_TEST() MemoryLeakWarningPlugin::getFirstPlugin()->ignoreAllLeaksInTest(); #define EXPECT_N_LEAKS(n) MemoryLeakWarningPlugin::getFirstPlugin()->expectLeaksInTest(n); extern "C" { /* include for size_t definition */ #include "TestHarness_c.h" } #if CPPUTEST_USE_MEM_LEAK_DETECTION #undef new #if CPPUTEST_USE_STD_CPP_LIB #include <new> void* operator new(size_t size) throw(std::bad_alloc); void* operator new[](size_t size) throw(std::bad_alloc); void operator delete(void* mem) throw(); void operator delete[](void* mem) throw(); #else void* operator new(size_t size); void* operator new[](size_t size); void operator delete(void* mem); void operator delete[](void* mem); #endif #if CPPUTEST_USE_NEW_MACROS #include "MemoryLeakDetectorNewMacros.h" #endif #endif class MemoryLeakDetector; class MemoryLeakWarningPlugin: public TestPlugin { public: MemoryLeakWarningPlugin(const SimpleString& name, MemoryLeakDetector* localDetector = 0); virtual ~MemoryLeakWarningPlugin(); virtual void preTestAction(Utest& test, TestResult& result); virtual void postTestAction(Utest& test, TestResult& result); virtual const char* FinalReport(int toBeDeletedLeaks = 0); void ignoreAllLeaksInTest(); void expectLeaksInTest(int n); MemoryLeakDetector* getMemoryLeakDetector(); static MemoryLeakWarningPlugin* getFirstPlugin(); static MemoryLeakDetector* getGlobalDetector(); private: MemoryLeakDetector* memLeakDetector_; bool ignoreAllWarnings_; int expectedLeaks_; int failureCount_; static MemoryLeakWarningPlugin* firstPlugin_; }; #endif
null
330
cpp
blalor-cpputest
UtestMacros.h
include/CppUTest/UtestMacros.h
null
/* * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the <organization> nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef D_UTestMacros_h #define D_UTestMacros_h /*! \brief Define a group of tests * * All tests in a TEST_GROUP share the same setup * and teardown. setup is run before the opening * curly brace of the test group and teardown is * called after the closing curly brace of the test group. * */ #define TEST_GROUP_BASE(testGroup, baseclass) \ int externTestGroup##testGroup = 0; \ struct TEST_GROUP_##CppUTestGroup##testGroup : public baseclass #define TEST_BASE(testBaseClass) \ struct testBaseClass : public Utest #define TEST_GROUP(testGroup) \ TEST_GROUP_BASE(testGroup, Utest) #define TEST_SETUP() \ virtual void setup() #define TEST_TEARDOWN() \ virtual void teardown() #define TEST(testGroup, testName) \ class TEST_##testGroup##_##testName##_Test : public TEST_GROUP_##CppUTestGroup##testGroup \ { public: TEST_##testGroup##_##testName##_Test () : TEST_GROUP_##CppUTestGroup##testGroup () {} \ void testBody(); } \ TEST_##testGroup##_##testName##_Instance; \ TestInstaller TEST_##testGroup##_##testName##_Installer(&TEST_##testGroup##_##testName##_Instance, #testGroup, #testName, __FILE__,__LINE__); \ void TEST_##testGroup##_##testName##_Test::testBody() #define IGNORE_TEST(testGroup, testName)\ class IGNORE##testGroup##_##testName##_Test : public TEST_GROUP_##CppUTestGroup##testGroup \ { public: IGNORE##testGroup##_##testName##_Test () : TEST_GROUP_##CppUTestGroup##testGroup () {} \ virtual void run (TestResult& result_parameter) { \ result_parameter.countIgnored(); } \ virtual const char* getProgressIndicator() const {return "!";} \ protected: virtual SimpleString getMacroName() const \ { return "IGNORE_TEST"; } \ public: void testBodyThatNeverRuns (); } \ TEST_##testGroup##_##testName##_Instance; \ TestInstaller TEST_##testGroup##testName##_Installer(&TEST_##testGroup##_##testName##_Instance, #testGroup, #testName, __FILE__,__LINE__); \ void IGNORE##testGroup##_##testName##_Test::testBodyThatNeverRuns () #define IMPORT_TEST_GROUP(testGroup) \ extern int externTestGroup##testGroup;\ int* p##testGroup = &externTestGroup##testGroup //Check any boolean condition #define CHECK(condition)\ CHECK_LOCATION_TRUE(condition, "CHECK", #condition, __FILE__, __LINE__) #define CHECK_TRUE(condition)\ CHECK_LOCATION_TRUE(condition, "CHECK_TRUE", #condition, __FILE__, __LINE__) #define CHECK_FALSE(condition)\ CHECK_LOCATION_FALSE(condition, "CHECK_FALSE", #condition, __FILE__, __LINE__) #define CHECK_LOCATION_TRUE(condition, checkString, conditionString, file, line)\ { Utest::getCurrent()->assertTrue((condition) != 0, checkString, conditionString, file, line); } #define CHECK_LOCATION_FALSE(condition, checkString, conditionString, file, line)\ { Utest::getCurrent()->assertTrue((condition) == 0, checkString, conditionString, file, line); } //This check needs the operator!=(), and a StringFrom(YourType) function #define CHECK_EQUAL(expected,actual)\ CHECK_EQUAL_LOCATION(expected, actual, __FILE__, __LINE__) #define CHECK_EQUAL_LOCATION(expected,actual, file, line)\ if ((expected) != (actual))\ {\ { \ Utest::getTestResult()->countCheck();\ CheckEqualFailure _f(Utest::getCurrent(), file, line, StringFrom(expected), StringFrom(actual)); \ Utest::getTestResult()->addFailure(_f);\ } \ Utest::getCurrent()->exitCurrentTest(); \ }\ else\ Utest::getTestResult()->countCheck(); //This check checks for char* string equality using strcmp. //This makes up for the fact that CHECK_EQUAL only compares the pointers to char*'s #define STRCMP_EQUAL(expected,actual)\ STRCMP_EQUAL_LOCATION(expected, actual, __FILE__, __LINE__) #define STRCMP_EQUAL_LOCATION(expected,actual, file, line)\ { Utest::getCurrent()->assertCstrEqual(expected, actual, file, line); } #define STRCMP_NOCASE_EQUAL(expected,actual)\ STRCMP_NOCASE_EQUAL_LOCATION(expected, actual, __FILE__, __LINE__) #define STRCMP_NOCASE_EQUAL_LOCATION(expected,actual, file, line)\ { Utest::getCurrent()->assertCstrNoCaseEqual(expected, actual, file, line); } #define STRCMP_CONTAINS(expected,actual)\ STRCMP_CONTAINS_LOCATION(expected, actual, __FILE__, __LINE__) #define STRCMP_CONTAINS_LOCATION(expected,actual, file, line)\ { Utest::getCurrent()->assertCstrContains(expected, actual, file, line); } #define STRCMP_NOCASE_CONTAINS(expected,actual)\ STRCMP_NOCASE_CONTAINS_LOCATION(expected, actual, __FILE__, __LINE__) #define STRCMP_NOCASE_CONTAINS_LOCATION(expected,actual, file, line)\ { Utest::getCurrent()->assertCstrNoCaseContains(expected, actual, file, line); } //Check two long integers for equality #define LONGS_EQUAL(expected,actual)\ LONGS_EQUAL_LOCATION(expected,actual,__FILE__, __LINE__) #define LONGS_EQUAL_LOCATION(expected,actual,file,line)\ { Utest::getCurrent()->assertLongsEqual(expected, actual, file, line); } #define BYTES_EQUAL(expected, actual)\ LONGS_EQUAL((expected) & 0xff,(actual) & 0xff) #define POINTERS_EQUAL(expected, actual)\ POINTERS_EQUAL_LOCATION((expected),(actual), __FILE__, __LINE__) #define POINTERS_EQUAL_LOCATION(expected,actual,file,line)\ { Utest::getCurrent()->assertPointersEqual((void *)expected, (void *)actual, file, line); } //Check two doubles for equality within a tolerance threshold #define DOUBLES_EQUAL(expected,actual,threshold)\ DOUBLES_EQUAL_LOCATION(expected,actual,threshold,__FILE__,__LINE__) #define DOUBLES_EQUAL_LOCATION(expected,actual,threshold,file,line)\ { Utest::getCurrent()->assertDoublesEqual(expected, actual, threshold, file, line); } //Fail if you get to this macro //The macro FAIL may already be taken, so allow FAIL_TEST too #ifndef FAIL #define FAIL(text)\ FAIL_LOCATION(text, __FILE__,__LINE__) #define FAIL_LOCATION(text, file, line)\ { Utest::getCurrent()->fail(text, file, line); Utest::getCurrent()->exitCurrentTest(); } #endif #define FAIL_TEST(text)\ FAIL_TEST_LOCATION(text, __FILE__,__LINE__) #define FAIL_TEST_LOCATION(text, file,line)\ { Utest::getCurrent()->fail(text, file, line); Utest::getCurrent()->exitCurrentTest(); } #define UT_PRINT_LOCATION(text, file, line) \ { Utest::getCurrent()->print(text, file, line); } #define UT_PRINT(text) \ UT_PRINT_LOCATION(text, __FILE__, __LINE__) #define UT_CRASH() { UT_PRINT("Going to crash here\n"); Utest* ptr = (Utest*) 0x0; ptr->countTests(); } #define RUN_ALL_TESTS(ac, av) CommandLineTestRunner::RunAllTests(ac, av) #endif /*D_UTestMacros_h*/
null
331
cpp
blalor-cpputest
MemoryLeakDetectorNewMacros.h
include/CppUTest/MemoryLeakDetectorNewMacros.h
null
/* * This file can be used to get extra debugging information about memory leaks in your production code. * It defines a preprocessor macro for operator new. This will pass additional information to the * operator new and this will give the line/file information of the memory leaks in your code. * * You can use this by including this file to all your production code. When using gcc, you can use * the -include file to do this for you. * * Warning: Using the new macro can cause a conflict with newly declared operator news. This can be * resolved by: * 1. #undef operator new before including this file * 2. Including the files that override operator new before this file. * This can be done by creating your own NewMacros.h file that includes your operator new overrides * and THEN this file. * * STL (or StdC++ lib) also does overrides for operator new. Therefore, you'd need to include the STL * files *before* this file too. * */ /* Warning for maintainers: * This macro code is duplicate from TestHarness.h. The reason for this is to make the two files * completely independent from each other. NewMacros file can be included in production code whereas * TestHarness.h is only included in test code. */ #include "StandardCLibrary.h" #ifndef CPPUTEST_USE_MEM_LEAK_DETECTION #ifdef CPPUTEST_MEM_LEAK_DETECTION_DISABLED #define CPPUTEST_USE_MEM_LEAK_DETECTION 0 #else #define CPPUTEST_USE_MEM_LEAK_DETECTION 1 #endif #endif #if CPPUTEST_USE_MEM_LEAK_DETECTION #ifndef CPPUTEST_USE_STD_CPP_LIB #ifdef CPPUTEST_STD_CPP_LIB_DISABLED #define CPPUTEST_USE_STD_CPP_LIB 0 #else #define CPPUTEST_USE_STD_CPP_LIB 1 #endif #endif /* This #ifndef prevents <new> from being included twice and enables the file to be included anywhere */ #ifndef CPPUTEST_USE_NEW_MACROS #if CPPUTEST_USE_STD_CPP_LIB #include <new> void* operator new(size_t size, const char* file, int line) throw (std::bad_alloc); void* operator new[](size_t size, const char* file, int line) throw (std::bad_alloc); void* operator new(size_t size) throw(std::bad_alloc); void* operator new[](size_t size) throw(std::bad_alloc); #else void* operator new(size_t size, const char* file, int line); void* operator new[](size_t size, const char* file, int line); void* operator new(size_t size); void* operator new[](size_t size); #endif #endif #define new new(__FILE__, __LINE__) #ifndef CPPUTEST_USE_NEW_MACROS extern "C" { #endif #include "MemoryLeakDetectorMallocMacros.h" #ifndef CPPUTEST_USE_NEW_MACROS } #endif #define CPPUTEST_USE_NEW_MACROS 1 #endif
null
332
cpp
blalor-cpputest
Utest.h
include/CppUTest/Utest.h
null
/* * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the <organization> nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ // This file contains the Test class along with the macros which make effective // in the harness. #ifndef D_UTest_h #define D_UTest_h #include "SimpleString.h" /*! \brief UTest.h * \ingroup someGroup * * Something about UTest.h * * \see TEST_GROUP * \see TEST */ class TestResult; class TestPlugin; class TestFailure; extern bool doubles_equal(double d1, double d2, double threshold); class Utest { public: Utest(const char* groupName, const char* testName, const char* fileName, int lineNumber); virtual ~Utest(); virtual void run(TestResult& result); virtual void runOneTestWithPlugins(TestPlugin* plugin, TestResult& result); virtual SimpleString getFormattedName() const; virtual Utest* addTest(Utest* test); virtual Utest *getNext() const; virtual bool isNull() const; virtual int countTests(); bool shouldRun(const SimpleString& groupFilter, const SimpleString& nameFilter) const; const SimpleString getName() const; const SimpleString getGroup() const; const SimpleString getFile() const; int getLineNumber() const; const virtual char *getProgressIndicator() const; virtual void setup(); virtual void teardown(); virtual void testBody(); static TestResult *getTestResult(); static Utest *getCurrent(); virtual void assertTrue(bool condition, const char *checkString, const char *conditionString, const char *fileName, int lineNumber); virtual void assertCstrEqual(const char *expected, const char *actual, const char *fileName, int lineNumber); virtual void assertCstrNoCaseEqual(const char *expected, const char *actual, const char *fileName, int lineNumber); virtual void assertCstrContains(const char *expected, const char *actual, const char *fileName, int lineNumber); virtual void assertCstrNoCaseContains(const char *expected, const char *actual, const char *fileName, int lineNumber); virtual void assertLongsEqual(long expected, long actual, const char *fileName, int lineNumber); virtual void assertPointersEqual(const void *expected, const void *actual, const char *fileName, int lineNumber); virtual void assertDoublesEqual(double expected, double actual, double threshold, const char *fileName, int lineNumber); virtual void fail(const char *text, const char *fileName, int lineNumber); virtual void print(const char *text, const char *fileName, int lineNumber); virtual void print(const SimpleString & text, const char *fileName, int lineNumber); void setFileName(const char *fileName); void setLineNumber(int lineNumber); void setGroupName(const char *groupName); void setTestName(const char *testName); virtual void exitCurrentTest(); protected: virtual void runOneTest(TestPlugin *plugin, TestResult & result); virtual void executePlatformSpecificRunOneTest(TestPlugin *plugin, TestResult & result); virtual bool executePlatformSpecificSetup(); virtual void executePlatformSpecificTestBody(); virtual void executePlatformSpecificTeardown(); virtual void executePlatformSpecificExitCurrentTest(); Utest(); Utest(const char *groupName, const char *testName, const char *fileName, int lineNumber, Utest *nextTest); virtual SimpleString getMacroName() const; private: const char *group_; const char *name_; const char *file_; int lineNumber_; Utest *next_; void setTestResult(TestResult* result); void setCurrentTest(Utest* test); static Utest* currentTest_; static TestResult* testResult_; void failWith(const TestFailure& failure); }; //////////////////// NulLTest class NullTest: public Utest { public: explicit NullTest(); explicit NullTest(const char* fileName, int lineNumber); virtual ~NullTest(); void testBody() { } static NullTest& instance(); virtual int countTests(); virtual Utest*getNext() const; virtual bool isNull() const; private: NullTest(const NullTest&); NullTest& operator=(const NullTest&); }; //////////////////// ExecFunctionTest class ExecFunctionTest: public Utest { public: void (*setup_)(); void (*teardown_)(); void (*testFunction_)(); ExecFunctionTest(void(*set)() = 0, void(*tear)() = 0) : Utest("Generic", "Generic", "Generic", 1), setup_(set), teardown_( tear), testFunction_(0) { } void testBody() { if (testFunction_) testFunction_(); } virtual void setup() { if (setup_) setup_(); } virtual void teardown() { if (teardown_) teardown_(); } }; //////////////////// TestInstaller class TestInstaller { public: explicit TestInstaller(Utest*, const char* groupName, const char* testName, const char* fileName, int lineNumber); virtual ~TestInstaller(); void unDo(); private: TestInstaller(const TestInstaller&); TestInstaller& operator=(const TestInstaller&); }; #endif
null
333
cpp
blalor-cpputest
MemoryLeakAllocator.h
include/CppUTest/MemoryLeakAllocator.h
null
#ifndef D_MemoryLeakAllocator_h #define D_MemoryLeakAllocator_h struct MemoryLeakNode; class MemoryLeakAllocator { public: virtual char* alloc_memory(size_t size, const char* file, int line)=0; virtual void free_memory(char* memory, const char* file, int line)=0; virtual const char* name()=0; virtual const char* alloc_name()=0; virtual const char* free_name()=0; virtual bool isOfEqualType(MemoryLeakAllocator* allocator); virtual ~MemoryLeakAllocator() { } virtual bool allocateMemoryLeakNodeSeparately(); virtual char* allocMemoryLeakNode(size_t size); virtual void freeMemoryLeakNode(char* memory); static void setCurrentNewAllocator(MemoryLeakAllocator* allocator); static MemoryLeakAllocator* getCurrentNewAllocator(); static void setCurrentNewAllocatorToDefault(); static void setCurrentNewArrayAllocator(MemoryLeakAllocator* allocator); static MemoryLeakAllocator* getCurrentNewArrayAllocator(); static void setCurrentNewArrayAllocatorToDefault(); static void setCurrentMallocAllocator(MemoryLeakAllocator* allocator); static MemoryLeakAllocator* getCurrentMallocAllocator(); static void setCurrentMallocAllocatorToDefault(); private: static MemoryLeakAllocator* currentNewAllocator; static MemoryLeakAllocator* currentNewArrayAllocator; static MemoryLeakAllocator* currentMallocAllocator; }; class StandardMallocAllocator: public MemoryLeakAllocator { public: virtual char* alloc_memory(size_t size, const char* file, int line); virtual void free_memory(char* memory, const char* file, int line); const char* name(); const char* alloc_name(); const char* free_name(); virtual bool allocateMemoryLeakNodeSeparately(); static MemoryLeakAllocator* defaultAllocator(); }; class StandardNewAllocator: public MemoryLeakAllocator { public: virtual char* alloc_memory(size_t size, const char* file, int line); virtual void free_memory(char* memory, const char* file, int line); const char* name(); const char* alloc_name(); const char* free_name(); static MemoryLeakAllocator* defaultAllocator(); }; class StandardNewArrayAllocator: public MemoryLeakAllocator { public: virtual char* alloc_memory(size_t size, const char* file, int line); virtual void free_memory(char* memory, const char* file, int line); const char* name(); const char* alloc_name(); const char* free_name(); static MemoryLeakAllocator* defaultAllocator(); }; class NullUnknownAllocator: public MemoryLeakAllocator { public: virtual char* alloc_memory(size_t size, const char* file, int line); virtual void free_memory(char* memory, const char* file, int line); const char* name(); const char* alloc_name(); const char* free_name(); static MemoryLeakAllocator* defaultAllocator(); }; #endif
null
334
cpp
blalor-cpputest
TestHarness_c.h
include/CppUTest/TestHarness_c.h
null
/* * 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. */ /****************************************************************************** * * TESTHARNESS_c.H * * Provides an interface for when working with pure C * * Remember to use extern "C" when including in a cpp file! * *******************************************************************************/ #ifndef D_TestHarness_c_h #define D_TestHarness_c_h #define CHECK_EQUAL_C_INT(expected,actual) \ CHECK_EQUAL_C_INT_LOCATION(expected,actual,__FILE__,__LINE__) #define CHECK_EQUAL_C_REAL(expected,actual,threshold) \ CHECK_EQUAL_C_REAL_LOCATION(expected,actual,threshold,__FILE__,__LINE__) #define CHECK_EQUAL_C_CHAR(expected,actual) \ CHECK_EQUAL_C_CHAR_LOCATION(expected,actual,__FILE__,__LINE__) #define CHECK_EQUAL_C_STRING(expected,actual) \ CHECK_EQUAL_C_STRING_LOCATION(expected,actual,__FILE__,__LINE__) #define FAIL_TEXT_C(text) \ FAIL_TEXT_C_LOCATION(text,__FILE__,__LINE__) #define FAIL_C() \ FAIL_C_LOCATION(__FILE__,__LINE__) #define CHECK_C(condition) \ CHECK_C_LOCATION(condition, #condition, __FILE__,__LINE__) /* CHECKS that can be used from C code */ extern void CHECK_EQUAL_C_INT_LOCATION(int expected, int actual, const char* fileName, int lineNumber); extern void CHECK_EQUAL_C_REAL_LOCATION(double expected, double actual, double threshold, const char* fileName, int lineNumber); extern void CHECK_EQUAL_C_CHAR_LOCATION(char expected, char actual, const char* fileName, int lineNumber); extern void CHECK_EQUAL_C_STRING_LOCATION(const char* expected, const char* actual, const char* fileName, int lineNumber); extern void FAIL_TEXT_C_LOCATION(const char* text, const char* fileName, int lineNumber); extern void FAIL_C_LOCATION(const char* fileName, int lineNumber); extern void CHECK_C_LOCATION(int condition, const char* conditionString, const char* fileName, int lineNumber); #include "StandardCLibrary.h" extern void* cpputest_malloc(size_t size); extern void* cpputest_calloc(size_t num, size_t size); extern void* cpputest_realloc(void* ptr, size_t size); extern void cpputest_free(void* buffer); extern void* cpputest_malloc_location(size_t size, const char* file, int line); extern void* cpputest_calloc_location(size_t num, size_t size, const char* file, int line); extern void* cpputest_realloc_location(void* memory, size_t size, const char* file, int line); extern void cpputest_free_location(void* buffer, const char* file, int line); void cpputest_malloc_set_out_of_memory(void); void cpputest_malloc_set_not_out_of_memory(void); void cpputest_malloc_set_out_of_memory_countdown(int); void cpputest_malloc_count_reset(void); int cpputest_malloc_get_count(void); /* * Small additional macro for unused arguments. This is common when stubbing, but in C you cannot remove the * name of the parameter (as in C++). */ #ifndef PUNUSED #if defined(__GNUC__) # define PUNUSED(x) PUNUSED_ ##x __attribute__((unused)) #else # define PUNUSED(x) x #endif #endif #endif
null
335
cpp
blalor-cpputest
TestOutput.h
include/CppUTest/TestOutput.h
null
/* * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the <organization> nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef D_TestOutput_h #define D_TestOutput_h /////////////////////////////////////////////////////////////////////////////// // // TestOutput.h // // This is a minimal printer inteface. // We kept streams out too keep footprint small, and so the test // harness could be used with less capable compilers so more // platforms could use this test harness // /////////////////////////////////////////////////////////////////////////////// class Utest; class TestFailure; class TestResult; class TestOutput { public: explicit TestOutput(); virtual ~TestOutput(); virtual void printTestsStarted(); virtual void printTestsEnded(const TestResult& result); virtual void printCurrentTestStarted(const Utest& test); virtual void printCurrentTestEnded(const TestResult& res); virtual void printCurrentGroupStarted(const Utest& test); virtual void printCurrentGroupEnded(const TestResult& res); virtual void verbose(); virtual void printBuffer(const char*)=0; virtual void print(const char*); virtual void print(long); virtual void printDouble(double); virtual void printHex(long); virtual void print(const TestFailure& failure); virtual void printTestRun(int number, int total); virtual void setProgressIndicator(const char*); virtual void flush(); private: virtual void printProgressIndicator(); void printFileAndLineForTestAndFailure(const TestFailure& failure); void printFileAndLineForFailure(const TestFailure& failure); void printFailureInTest(SimpleString testName); void printFailureMessage(SimpleString reason); void printEclipseErrorInFileOnLine(SimpleString testFile, int lineNumber); TestOutput(const TestOutput&); TestOutput& operator=(const TestOutput&); int dotCount_; bool verbose_; const char* progressIndication_; }; TestOutput& operator<<(TestOutput&, const char*); TestOutput& operator<<(TestOutput&, long); /////////////////////////////////////////////////////////////////////////////// // // ConsoleTestOutput.h // // Printf Based Solution // /////////////////////////////////////////////////////////////////////////////// class ConsoleTestOutput: public TestOutput { public: explicit ConsoleTestOutput() { } ; virtual ~ConsoleTestOutput() { } ; virtual void printBuffer(const char* s); virtual void flush(); private: ConsoleTestOutput(const ConsoleTestOutput&); ConsoleTestOutput& operator=(const ConsoleTestOutput&); }; /////////////////////////////////////////////////////////////////////////////// // // StringBufferTestOutput.h // // TestOutput for test purposes // /////////////////////////////////////////////////////////////////////////////// class StringBufferTestOutput: public TestOutput { public: explicit StringBufferTestOutput() { } ; virtual ~StringBufferTestOutput() { } ; void printBuffer(const char* s) { output += s; } void flush() { output = ""; } const SimpleString& getOutput() { return output; } private: SimpleString output; StringBufferTestOutput(const StringBufferTestOutput&); StringBufferTestOutput& operator=(const StringBufferTestOutput&); }; #endif // D_TestOutput_h
null
336
cpp
blalor-cpputest
TestRegistry.h
include/CppUTest/TestRegistry.h
null
/* * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the <organization> nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /////////////////////////////////////////////////////////////////////////////// // // TESTREGISTRY.H // // TestRegistry is a collection of tests that can be run // /////////////////////////////////////////////////////////////////////////////// #ifndef D_TestRegistry_h #define D_TestRegistry_h #include "SimpleString.h" class Utest; class TestResult; class TestPlugin; class TestRegistry { public: TestRegistry(); virtual ~TestRegistry(); virtual void addTest(Utest *test); virtual void unDoLastAddTest(); virtual int countTests(); virtual void runAllTests(TestResult& result); virtual void nameFilter(SimpleString); virtual void groupFilter(SimpleString); virtual void installPlugin(TestPlugin* plugin); virtual void resetPlugins(); virtual TestPlugin* getFirstPlugin(); virtual TestPlugin* getPluginByName(const SimpleString& name); virtual void removePluginByName(const SimpleString& name); SimpleString getGroupFilter(); SimpleString getNameFilter(); virtual Utest* getFirstTest(); virtual Utest* getLastTest(); virtual Utest* getTestWithNext(Utest* test); static TestRegistry* getCurrentRegistry(); virtual void setCurrentRegistry(TestRegistry* registry); void cleanup(); private: bool testShouldRun(Utest* test, TestResult& result); bool endOfGroup(Utest* test); Utest * tests_; SimpleString* nameFilter_; SimpleString* groupFilter_; TestPlugin* firstPlugin_; static TestRegistry* currentRegistry_; }; #endif
null
337
cpp
blalor-cpputest
SimpleString.h
include/CppUTest/SimpleString.h
null
/* * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the <organization> nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /////////////////////////////////////////////////////////////////////////////// // // SIMPLESTRING.H // // One of the design goals of CppUnitLite is to compilation with very old C++ // compilers. For that reason, the simple string class that provides // only the operations needed in CppUnitLite. // /////////////////////////////////////////////////////////////////////////////// #ifndef D_SimpleString_h #define D_SimpleString_h #include "StandardCLibrary.h" class SimpleStringCollection; class MemoryLeakAllocator; class SimpleString { friend bool operator==(const SimpleString& left, const SimpleString& right); friend bool operator!=(const SimpleString& left, const SimpleString& right); public: SimpleString(const char *value = ""); SimpleString(const char *value, size_t repeatCount); SimpleString(const SimpleString& other); ~SimpleString(); SimpleString& operator=(const SimpleString& other); SimpleString operator+(const SimpleString&); SimpleString& operator+=(const SimpleString&); SimpleString& operator+=(const char*); bool contains(const SimpleString& other) const; bool containsNoCase(const SimpleString& other) const; bool startsWith(const SimpleString& other) const; bool endsWith(const SimpleString& other) const; void split(const SimpleString& split, SimpleStringCollection& outCollection) const; bool equalsNoCase(const SimpleString& str) const; size_t count(const SimpleString& str) const; void replace(char to, char with); void replace(const char* to, const char* with); SimpleString toLower() const; SimpleString subString(size_t beginPos, size_t amount) const; void copyToBuffer(char* buffer, size_t bufferSize) const; const char *asCharString() const; size_t size() const; bool isEmpty() const; static void padStringsToSameLength(SimpleString& str1, SimpleString& str2, char ch); static MemoryLeakAllocator* getStringAllocator(); static void setStringAllocator(MemoryLeakAllocator* allocator); static char* allocStringBuffer(size_t size); static void deallocStringBuffer(char* str); private: char *buffer_; static MemoryLeakAllocator* stringAllocator_; char* getEmptyString() const; }; class SimpleStringCollection { public: SimpleStringCollection(); ~SimpleStringCollection(); void allocate(size_t size); size_t size() const; SimpleString& operator[](size_t index); private: SimpleString* collection_; SimpleString empty_; size_t size_; void operator =(SimpleStringCollection&); SimpleStringCollection(SimpleStringCollection&); }; SimpleString StringFrom(bool value); SimpleString StringFrom(const void* value); SimpleString StringFrom(char value); SimpleString StringFrom(const char *value); SimpleString StringFromOrNull(const char * value); SimpleString StringFrom(long value); SimpleString StringFrom(int value); SimpleString HexStringFrom(long value); SimpleString StringFrom(double value, int precision = 6); SimpleString StringFrom(const SimpleString& other); SimpleString StringFromFormat(const char* format, ...); SimpleString VStringFromFormat(const char* format, va_list args); #if CPPUTEST_USE_STD_CPP_LIB #undef new #include <string> #if CPPUTEST_USE_NEW_MACROS #include "CppUTest/MemoryLeakDetectorNewMacros.h" #endif #include <stdint.h> SimpleString StringFrom(const std::string& other); SimpleString StringFrom(uint32_t); SimpleString StringFrom(uint16_t); SimpleString StringFrom(uint8_t); #endif #endif
null
338
cpp
blalor-cpputest
MemoryLeakDetector.h
include/CppUTest/MemoryLeakDetector.h
null
#ifndef D_MemoryLeakDetector_h #define D_MemoryLeakDetector_h #define MEM_LEAK_NONE "No memory leaks were detected." #define MEM_LEAK_HEADER "Memory leak(s) found.\n" #define MEM_LEAK_LEAK "Leak size: %d Allocated at: %s and line: %d. Type: \"%s\" Content: \"%.15s\"\n" #define MEM_LEAK_TOO_MUCH "\netc etc etc etc. !!!! Too much memory leaks to report. Bailing out\n" #define MEM_LEAK_FOOTER "Total number of leaks: " #define MEM_LEAK_ADDITION_MALLOC_WARNING "NOTE:\n" \ "\tMemory leak reports about malloc and free can be caused by allocating using the cpputest version of malloc,\n" \ "\tbut deallocate using the standard free.\n" \ "\tIf this is the case, check whether your malloc/free replacements are working (#define malloc cpputest_malloc etc).\n" #define MEM_LEAK_NORMAL_FOOTER_SIZE (sizeof(MEM_LEAK_FOOTER) + 10 + sizeof(MEM_LEAK_TOO_MUCH)) /* the number of leaks */ #define MEM_LEAK_NORMAL_MALLOC_FOOTER_SIZE (MEM_LEAK_NORMAL_FOOTER_SIZE + sizeof(MEM_LEAK_ADDITION_MALLOC_WARNING)) #define MEM_LEAK_ALLOC_DEALLOC_MISMATCH "Allocation/deallocation type mismatch\n" #define MEM_LEAK_MEMORY_CORRUPTION "Memory corruption (written out of bounds?)\n" #define MEM_LEAK_ALLOC_LOCATION " allocated at file: %s line: %d size: %d type: %s\n" #define MEM_LEAK_DEALLOC_LOCATION " deallocated at file: %s line: %d type: %s\n" #define MEM_LEAK_DEALLOC_NON_ALLOCATED "Deallocating non-allocated memory\n" enum MemLeakPeriod { mem_leak_period_all, mem_leak_period_disabled, mem_leak_period_enabled, mem_leak_period_checking }; class MemoryLeakAllocator; #include "StandardCLibrary.h" class MemoryLeakFailure { public: virtual ~MemoryLeakFailure() { } ; virtual void fail(char* fail_string)=0; }; struct SimpleStringBuffer { enum { SIMPLE_STRING_BUFFER_LEN = 4096 }; SimpleStringBuffer(); void clear(); void add(const char* format, ...); char* toString(); void setWriteLimit(int write_limit); void resetWriteLimit(); bool reachedItsCapacity(); private: char buffer_[SIMPLE_STRING_BUFFER_LEN]; int positions_filled_; int write_limit_; }; struct MemoryLeakDetectorNode { MemoryLeakDetectorNode() : size_(0), next_(0) { } void init(char* memory, size_t size, MemoryLeakAllocator* allocator, MemLeakPeriod period, const char* file, int line); size_t size_; char* memory_; const char* file_; int line_; MemoryLeakAllocator* allocator_; MemLeakPeriod period_; private: friend struct MemoryLeakDetectorList; MemoryLeakDetectorNode* next_; }; struct MemoryLeakDetectorList { MemoryLeakDetectorList() : head_(0) {} void addNewNode(MemoryLeakDetectorNode* node); MemoryLeakDetectorNode* retrieveNode(char* memory); MemoryLeakDetectorNode* removeNode(char* memory); MemoryLeakDetectorNode* getFirstLeak(MemLeakPeriod period); MemoryLeakDetectorNode* getNextLeak(MemoryLeakDetectorNode* node, MemLeakPeriod period); MemoryLeakDetectorNode* getLeakFrom(MemoryLeakDetectorNode* node, MemLeakPeriod period); int getTotalLeaks(MemLeakPeriod period); bool hasLeaks(MemLeakPeriod period); void clearAllAccounting(MemLeakPeriod period); bool isInPeriod(MemoryLeakDetectorNode* node, MemLeakPeriod period); private: MemoryLeakDetectorNode* head_; }; struct MemoryLeakDetectorTable { void clearAllAccounting(MemLeakPeriod period); void addNewNode(MemoryLeakDetectorNode* node); MemoryLeakDetectorNode* retrieveNode(char* memory); MemoryLeakDetectorNode* removeNode(char* memory); bool hasLeaks(MemLeakPeriod period); int getTotalLeaks(MemLeakPeriod period); MemoryLeakDetectorNode* getFirstLeak(MemLeakPeriod period); MemoryLeakDetectorNode* getNextLeak(MemoryLeakDetectorNode* leak, MemLeakPeriod period); private: unsigned long hash(char* memory); enum { hash_prime = MEMORY_LEAK_HASH_TABLE_SIZE }; MemoryLeakDetectorList table_[hash_prime]; }; class MemoryLeakDetector { public: MemoryLeakDetector(); ~MemoryLeakDetector() { } void init(MemoryLeakFailure* reporter); void enable(); void disable(); void disableAllocationTypeChecking(); void enableAllocationTypeChecking(); void startChecking(); void stopChecking(); const char* report(MemLeakPeriod period); void markCheckingPeriodLeaksAsNonCheckingPeriod(); int totalMemoryLeaks(MemLeakPeriod period); void clearAllAccounting(MemLeakPeriod period); char* allocMemory(MemoryLeakAllocator* allocator, size_t size); char* allocMemory(MemoryLeakAllocator* allocator, size_t size, const char* file, int line); void deallocMemory(MemoryLeakAllocator* allocator, void* memory); void deallocMemory(MemoryLeakAllocator* allocator, void* memory, const char* file, int line); char* reallocMemory(MemoryLeakAllocator* allocator, char* memory, size_t size, const char* file, int line); void invalidateMemory(char* memory); void removeMemoryLeakInformationWithoutCheckingOrDeallocating(void* memory); enum { memory_corruption_buffer_size = 3 }; private: MemoryLeakFailure* reporter_; MemLeakPeriod current_period_; SimpleStringBuffer output_buffer_; MemoryLeakDetectorTable memoryTable_; bool doAllocationTypeChecking_; bool validMemoryCorruptionInformation(char* memory); bool matchingAllocation(MemoryLeakAllocator *alloc_allocator, MemoryLeakAllocator *free_allocator); void storeLeakInformation(MemoryLeakDetectorNode *& node, char *new_memory, size_t size, MemoryLeakAllocator *allocator, const char *file, int line); void ConstructMemoryLeakReport(MemLeakPeriod period); void reportFailure(const char* message, const char* allocFile, int allocLine, size_t allocSize, MemoryLeakAllocator* allocAllocator, const char* freeFile, int freeLine, MemoryLeakAllocator* freeAllocator); size_t sizeOfMemoryWithCorruptionInfo(size_t size); MemoryLeakDetectorNode* getNodeFromMemoryPointer(char* memory, size_t size); char* reallocateMemoryAndLeakInformation(MemoryLeakAllocator* allocator, char* memory, size_t size, const char* file, int line); void addMemoryCorruptionInformation(char* memory); void checkForCorruption(MemoryLeakDetectorNode* node, const char* file, int line, MemoryLeakAllocator* allocator); }; #endif
null
339
cpp
blalor-cpputest
MockActualFunctionCall.h
include/CppUTestExt/MockActualFunctionCall.h
null
/* * 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_MockActualFunctionCall_h #define D_MockActualFunctionCall_h #include "CppUTestExt/MockFunctionCall.h" #include "CppUTestExt/MockExpectedFunctionsList.h" class MockFailureReporter; class MockFailure; class MockNamedValue; class MockActualFunctionCall : public MockFunctionCall { public: MockActualFunctionCall(int callOrder, MockFailureReporter* reporter, const MockExpectedFunctionsList& expectations); virtual ~MockActualFunctionCall(); virtual MockFunctionCall& withName(const SimpleString& name); virtual MockFunctionCall& withCallOrder(int); virtual MockFunctionCall& withParameter(const SimpleString& name, int value); virtual MockFunctionCall& withParameter(const SimpleString& name, double value); virtual MockFunctionCall& withParameter(const SimpleString& name, const char* value); virtual MockFunctionCall& withParameter(const SimpleString& name, void* value); virtual MockFunctionCall& withParameterOfType(const SimpleString& type, const SimpleString& name, void* value); virtual MockFunctionCall& andReturnValue(int value); virtual MockFunctionCall& andReturnValue(double value); virtual MockFunctionCall& andReturnValue(const char* value); virtual MockFunctionCall& andReturnValue(void* value); virtual bool hasReturnValue(); virtual MockNamedValue returnValue(); virtual MockFunctionCall& onObject(void* objectPtr); virtual bool isFulfilled() const; virtual bool hasFailed() const; virtual void checkExpectations(); virtual void setMockFailureReporter(MockFailureReporter* reporter); protected: virtual Utest* getTest() const; virtual void callHasSucceeded(); virtual void finnalizeCallWhenFulfilled(); virtual void failTest(const MockFailure& failure); virtual void checkActualParameter(const MockNamedValue& actualParameter); enum ActualCallState { CALL_IN_PROGESS, CALL_FAILED, CALL_SUCCEED }; virtual const char* stringFromState(ActualCallState state); virtual void setState(ActualCallState state); virtual void checkStateConsistency(ActualCallState oldState, ActualCallState newState); private: int callOrder_; MockFailureReporter* reporter_; ActualCallState state_; MockExpectedFunctionCall* _fulfilledExpectation; MockExpectedFunctionsList unfulfilledExpectations_; const MockExpectedFunctionsList& allExpectations_; }; #endif
null
340
cpp
blalor-cpputest
MockSupport_c.h
include/CppUTestExt/MockSupport_c.h
null
/* * 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 typedef enum { MOCKVALUETYPE_INTEGER, MOCKVALUETYPE_DOUBLE, MOCKVALUETYPE_STRING, MOCKVALUETYPE_POINTER, MOCKVALUETYPE_OBJECT } MockValueType_c; typedef struct SMockValue_c { MockValueType_c type; union { int intValue; double doubleValue; const char* stringValue; void* pointerValue; void* objectValue; } value; } MockValue_c; typedef struct SMockFunctionCall_c MockFunctionCall_c; struct SMockFunctionCall_c { MockFunctionCall_c* (*withIntParameters)(const char* name, int value); MockFunctionCall_c* (*withDoubleParameters)(const char* name, double value); MockFunctionCall_c* (*withStringParameters)(const char* name, const char* value); MockFunctionCall_c* (*withPointerParameters)(const char* name, void* value); MockFunctionCall_c* (*withParameterOfType)(const char* type, const char* name, void* value); MockFunctionCall_c* (*andReturnIntValue)(int value); MockFunctionCall_c* (*andReturnDoubleValue)(double value); MockFunctionCall_c* (*andReturnStringValue)(const char* value); MockFunctionCall_c* (*andReturnPointerValue)(void* value); MockValue_c (*returnValue)(); }; typedef int (*MockTypeEqualFunction_c)(void* object1, void* object2); typedef char* (*MockTypeValueToStringFunction_c)(void* object1); typedef struct SMockSupport_c MockSupport_c; struct SMockSupport_c { MockFunctionCall_c* (*expectOneCall)(const char* name); MockFunctionCall_c* (*actualCall)(const char* name); MockValue_c (*returnValue)(); void (*setIntData) (const char* name, int value); void (*setDoubleData) (const char* name, double value); void (*setStringData) (const char* name, const char* value); void (*setPointerData) (const char* name, void* value); void (*setDataObject) (const char* name, const char* type, void* value); MockValue_c (*getData)(const char* name); void (*checkExpectations)(); int (*expectedCallsLeft)(); void (*clear)(); void (*installComparator) (const char* typeName, MockTypeEqualFunction_c isEqual, MockTypeValueToStringFunction_c valueToString); void (*removeAllComparators)(); }; MockSupport_c* mock_c(); MockSupport_c* mock_scope_c(const char* scope); #endif
null
341
cpp
blalor-cpputest
MemoryReportFormatter.h
include/CppUTestExt/MemoryReportFormatter.h
null
/* * 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 Utest; class MemoryReportFormatter { public: virtual ~MemoryReportFormatter(){} virtual void report_testgroup_start(TestResult* result, Utest& test)=0; virtual void report_testgroup_end(TestResult* result, Utest& test)=0; virtual void report_test_start(TestResult* result, Utest& test)=0; virtual void report_test_end(TestResult* result, Utest& test)=0; virtual void report_alloc_memory(TestResult* result, MemoryLeakAllocator* allocator, size_t size, char* memory, const char* file, int line)=0; virtual void report_free_memory(TestResult* result, MemoryLeakAllocator* allocator, char* memory, const char* file, int line)=0; }; class NormalMemoryReportFormatter : public MemoryReportFormatter { public: NormalMemoryReportFormatter(); virtual ~NormalMemoryReportFormatter(); virtual void report_testgroup_start(TestResult* /*result*/, Utest& /*test*/); virtual void report_testgroup_end(TestResult* /*result*/, Utest& /*test*/){}; virtual void report_test_start(TestResult* result, Utest& test); virtual void report_test_end(TestResult* result, Utest& test); virtual void report_alloc_memory(TestResult* result, MemoryLeakAllocator* allocator, size_t size, char* memory, const char* file, int line); virtual void report_free_memory(TestResult* result, MemoryLeakAllocator* allocator, char* memory, const char* file, int line); }; #endif
null
342
cpp
blalor-cpputest
MockFunctionCall.h
include/CppUTestExt/MockFunctionCall.h
null
/* * 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_MockFunctionCall_h #define D_MockFunctionCall_h /* * MockFunctionCall is the main interface for recording and actualizing mock calls. * */ class MockNamedValueComparator; class MockNamedValueComparatorRepository; #include "CppUTestExt/MockNamedValue.h" class MockFunctionCall { public: MockFunctionCall(); virtual ~MockFunctionCall(); virtual MockFunctionCall& withName(const SimpleString& name)=0; virtual MockFunctionCall& withCallOrder(int)=0; virtual MockFunctionCall& withParameter(const SimpleString& name, int value)=0; virtual MockFunctionCall& withParameter(const SimpleString& name, double value)=0; virtual MockFunctionCall& withParameter(const SimpleString& name, const char* value)=0; virtual MockFunctionCall& withParameter(const SimpleString& name, void* value)=0; virtual MockFunctionCall& withParameterOfType(const SimpleString& typeName, const SimpleString& name, void* value)=0; virtual MockFunctionCall& ignoreOtherParameters() { return *this;}; virtual MockFunctionCall& andReturnValue(int value)=0; virtual MockFunctionCall& andReturnValue(double value)=0; virtual MockFunctionCall& andReturnValue(const char* value)=0; virtual MockFunctionCall& andReturnValue(void* value)=0; virtual bool hasReturnValue()=0; virtual MockNamedValue returnValue()=0; virtual MockFunctionCall& onObject(void* objectPtr)=0; virtual void setComparatorRepository(MockNamedValueComparatorRepository* repository); protected: void setName(const SimpleString& name); SimpleString getName() const; MockNamedValueComparator* getComparatorForType(const SimpleString& type) const; private: SimpleString functionName_; MockNamedValueComparatorRepository* comparatorRepository_; }; struct MockFunctionCallCompositeNode; class MockFunctionCallComposite : public MockFunctionCall { public: MockFunctionCallComposite(); virtual ~MockFunctionCallComposite(); virtual MockFunctionCall& withName(const SimpleString&); virtual MockFunctionCall& withCallOrder(int); virtual MockFunctionCall& withParameter(const SimpleString&, int); virtual MockFunctionCall& withParameter(const SimpleString&, double); virtual MockFunctionCall& withParameter(const SimpleString&, const char*); virtual MockFunctionCall& withParameter(const SimpleString& , void*); virtual MockFunctionCall& withParameterOfType(const SimpleString&, const SimpleString&, void*); virtual MockFunctionCall& ignoreOtherParameters(); virtual MockFunctionCall& andReturnValue(int); virtual MockFunctionCall& andReturnValue(double); virtual MockFunctionCall& andReturnValue(const char*); virtual MockFunctionCall& andReturnValue(void*); virtual bool hasReturnValue(); virtual MockNamedValue returnValue(); virtual MockFunctionCall& onObject(void* ); virtual void add(MockFunctionCall& call); virtual void clear(); private: MockFunctionCallCompositeNode* head_; }; class MockIgnoredCall : public MockFunctionCall { public: virtual MockFunctionCall& withName(const SimpleString&) { return *this;} virtual MockFunctionCall& withCallOrder(int) { return *this; } virtual MockFunctionCall& withParameter(const SimpleString&, int) { return *this; } virtual MockFunctionCall& withParameter(const SimpleString&, double) { return *this; } virtual MockFunctionCall& withParameter(const SimpleString&, const char*) { return *this; } virtual MockFunctionCall& withParameter(const SimpleString& , void*) { return *this; } virtual MockFunctionCall& withParameterOfType(const SimpleString&, const SimpleString&, void*) { return *this; } virtual MockFunctionCall& andReturnValue(int) { return *this; } virtual MockFunctionCall& andReturnValue(double) { return *this;} virtual MockFunctionCall& andReturnValue(const char*) { return *this; } virtual MockFunctionCall& andReturnValue(void*) { return *this; } virtual bool hasReturnValue() { return false; } virtual MockNamedValue returnValue() { return MockNamedValue(""); } virtual MockFunctionCall& onObject(void* ) { return *this; } static MockFunctionCall& instance() { static MockIgnoredCall call; return call; }; }; class MockFunctionCallTrace : public MockFunctionCall { public: MockFunctionCallTrace(); virtual ~MockFunctionCallTrace(); virtual MockFunctionCall& withName(const SimpleString& name); virtual MockFunctionCall& withCallOrder(int); virtual MockFunctionCall& withParameter(const SimpleString& name, int value); virtual MockFunctionCall& withParameter(const SimpleString& name, double value); virtual MockFunctionCall& withParameter(const SimpleString& name, const char* value); virtual MockFunctionCall& withParameter(const SimpleString& name, void* value); virtual MockFunctionCall& withParameterOfType(const SimpleString& typeName, const SimpleString& name, void* value); virtual MockFunctionCall& ignoreOtherParameters(); virtual MockFunctionCall& andReturnValue(int value); virtual MockFunctionCall& andReturnValue(double value); virtual MockFunctionCall& andReturnValue(const char* value); virtual MockFunctionCall& andReturnValue(void* value); virtual bool hasReturnValue(); virtual MockNamedValue returnValue(); virtual MockFunctionCall& onObject(void* objectPtr); const char* getTraceOutput(); void clear(); static MockFunctionCallTrace& instance(); private: SimpleString traceBuffer_; }; #endif
null
343
cpp
blalor-cpputest
MemoryReportAllocator.h
include/CppUTestExt/MemoryReportAllocator.h
null
/* * 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/MemoryLeakAllocator.h" class MemoryReportFormatter; class MemoryReportAllocator : public MemoryLeakAllocator { protected: TestResult* result_; MemoryLeakAllocator* realAllocator_; MemoryReportFormatter* formatter_; public: MemoryReportAllocator(); virtual ~MemoryReportAllocator(); virtual void setFormatter(MemoryReportFormatter* formatter); virtual void setTestResult(TestResult* result); virtual void setRealAllocator(MemoryLeakAllocator* allocator); virtual bool allocateMemoryLeakNodeSeparately(); virtual MemoryLeakAllocator* getRealAllocator(); virtual char* alloc_memory(size_t size, const char* file, int line); virtual void free_memory(char* memory, const char* file, int line); virtual const char* name(); virtual const char* alloc_name(); virtual const char* free_name(); }; #endif
null
344
cpp
blalor-cpputest
MockNamedValue.h
include/CppUTestExt/MockNamedValue.h
null
/* * 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 /* * MockParameterComparator 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(void* object1, void* object2)=0; virtual SimpleString valueToString(void* object)=0; }; class MockFunctionComparator : public MockNamedValueComparator { public: typedef bool (*isEqualFunction)(void*, void*); typedef SimpleString (*valueToStringFunction)(void*); MockFunctionComparator(isEqualFunction equal, valueToStringFunction valToString) : equal_(equal), valueToString_(valToString) {} virtual ~MockFunctionComparator(){}; virtual bool isEqual(void* object1, void* object2){ return equal_(object1, object2); } virtual SimpleString valueToString(void* object) { return valueToString_(object); } private: isEqualFunction equal_; valueToStringFunction valueToString_; }; /* * 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 MockNamedValue { public: MockNamedValue(const SimpleString& name); virtual ~MockNamedValue(); virtual void setValue(int value); virtual void setValue(double value); virtual void setValue(void* value); virtual void setValue(const char* value); virtual void setObjectPointer(const SimpleString& type, void* objectPtr); virtual void setComparator(MockNamedValueComparator* comparator); virtual void setName(const char* name); virtual bool equals(const MockNamedValue& p) const; virtual SimpleString toString() const; virtual SimpleString getName() const; virtual SimpleString getType() const; virtual int getIntValue() const; virtual double getDoubleValue() const; virtual const char* getStringValue() const; virtual void* getPointerValue() const; virtual void* getObjectPointer() const; private: SimpleString name_; SimpleString type_; union { int intValue_; double doubleValue_; const char* stringValue_; void* pointerValue_; void* objectPointerValue_; } value_; MockNamedValueComparator* comparator_; }; 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 which can be used for comparing non-native types * */ struct MockNamedValueComparatorRepositoryNode; class MockNamedValueComparatorRepository { MockNamedValueComparatorRepositoryNode* head_; public: MockNamedValueComparatorRepository(); virtual ~MockNamedValueComparatorRepository(); virtual void installComparator(const SimpleString& name, MockNamedValueComparator& comparator); virtual void installComparators(const MockNamedValueComparatorRepository& repository); virtual MockNamedValueComparator* getComparatorForType(const SimpleString& name); void clear(); }; #endif
null
345
cpp
blalor-cpputest
OrderedTest.h
include/CppUTestExt/OrderedTest.h
null
/* * 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 OrderedTest : public Utest { public: OrderedTest(); virtual ~OrderedTest(); virtual OrderedTest* addOrderedTest(OrderedTest* test); virtual OrderedTest* getNextOrderedTest(); int getLevel(); void setLevel(int level); static void addOrderedTestToHead(OrderedTest* test); static OrderedTest* getOrderedTestHead(); static bool firstOrderedTest(); static void setOrderedTestHead(OrderedTest* test); private: static OrderedTest* _orderedTestsHead; OrderedTest* _nextOrderedTest; int _level; }; class OrderedTestInstaller { public: explicit OrderedTestInstaller(OrderedTest* test, const char* groupName, const char* testName, const char* fileName, int lineNumber, int level); virtual ~OrderedTestInstaller(); private: void addOrderedTestInOrder(OrderedTest* test); void addOrderedTestInOrderNotAtHeadPosition(OrderedTest* test); }; #define TEST_ORDERED(testGroup, testName, testLevel) \ class TEST_##testGroup##_##testName##_Test : public TEST_GROUP_##CppUTestGroup##testGroup \ { public: TEST_##testGroup##_##testName##_Test () : TEST_GROUP_##CppUTestGroup##testGroup () {} \ void testBody(); } \ TEST_##testGroup##_##testName##_Instance; \ OrderedTestInstaller TEST_##testGroup##_##testName##_Installer(&TEST_##testGroup##_##testName##_Instance, #testGroup, #testName, __FILE__,__LINE__, testLevel); \ void TEST_##testGroup##_##testName##_Test::testBody() #endif
null
346
cpp
blalor-cpputest
CodeMemoryReportFormatter.h
include/CppUTestExt/CodeMemoryReportFormatter.h
null
/* * 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" class CodeReportingAllocationNode; class CodeMemoryReportFormatter : public MemoryReportFormatter { private: CodeReportingAllocationNode* codeReportingList_; MemoryLeakAllocator* internalAllocator_; public: CodeMemoryReportFormatter(MemoryLeakAllocator* internalAllocator); virtual ~CodeMemoryReportFormatter(); virtual void report_testgroup_start(TestResult* result, Utest& test); virtual void report_testgroup_end(TestResult* /*result*/, Utest& /*test*/){}; virtual void report_test_start(TestResult* result, Utest& test); virtual void report_test_end(TestResult* result, Utest& test); virtual void report_alloc_memory(TestResult* result, MemoryLeakAllocator* allocator, size_t size, char* memory, const char* file, int line); virtual void report_free_memory(TestResult* result, MemoryLeakAllocator* allocator, char* memory, const char* file, int line); private: void addNodeToList(const char* variableName, void* memory, CodeReportingAllocationNode* next); CodeReportingAllocationNode* findNode(void* memory); bool variableExists(const SimpleString& variableName); void clearReporting(); bool isNewAllocator(MemoryLeakAllocator* allocator); SimpleString createVariableNameFromFileLineInfo(const char *file, int line); SimpleString getAllocationString(MemoryLeakAllocator* allocator, const SimpleString& variableName, size_t size); SimpleString getDeallocationString(MemoryLeakAllocator* allocator, const SimpleString& variableName, const char* file, int line); }; #endif
null
347
cpp
blalor-cpputest
MockExpectedFunctionsList.h
include/CppUTestExt/MockExpectedFunctionsList.h
null
/* * 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_MockExpectedFunctionsList_h #define D_MockExpectedFunctionsList_h class MockExpectedFunctionCall; class MockNamedValue; class MockExpectedFunctionsList { public: MockExpectedFunctionsList(); virtual ~MockExpectedFunctionsList(); virtual void deleteAllExpectationsAndClearList(); virtual int size() const; virtual int amountOfExpectationsFor(const SimpleString& name) const; virtual int amountOfUnfulfilledExpectations() const; virtual bool hasUnfullfilledExpectations() const; virtual bool hasFulfilledExpectations() const; virtual bool hasUnfulfilledExpectationsBecauseOfMissingParameters() const; virtual bool hasExpectationWithName(const SimpleString& name) const; virtual bool hasCallsOutOfOrder() const; virtual bool isEmpty() const; virtual void addExpectedCall(MockExpectedFunctionCall* call); virtual void addExpectations(const MockExpectedFunctionsList& list); virtual void addExpectationsRelatedTo(const SimpleString& name, const MockExpectedFunctionsList& list); virtual void addUnfilfilledExpectations(const MockExpectedFunctionsList& list); virtual void onlyKeepExpectationsRelatedTo(const SimpleString& name); virtual void onlyKeepExpectationsWithParameter(const MockNamedValue& parameter); virtual void onlyKeepExpectationsWithParameterName(const SimpleString& name); virtual void onlyKeepExpectationsOnObject(void* objectPtr); virtual void onlyKeepUnfulfilledExpectations(); virtual void onlyKeepUnfulfilledExpectationsRelatedTo(const SimpleString& name); virtual void onlyKeepUnfulfilledExpectationsWithParameter(const MockNamedValue& parameter); virtual void onlyKeepUnfulfilledExpectationsOnObject(void* objectPtr); virtual MockExpectedFunctionCall* removeOneFulfilledExpectation(); virtual MockExpectedFunctionCall* removeOneFulfilledExpectationWithIgnoredParameters(); virtual void resetExpectations(); virtual void callWasMade(int callOrder); virtual void wasPassedToObject(); virtual void parameterWasPassed(const SimpleString& parameterName); virtual SimpleString unfulfilledFunctionsToString(const SimpleString& linePrefix = "") const; virtual SimpleString fulfilledFunctionsToString(const SimpleString& linePrefix = "") const; virtual SimpleString missingParametersToString() const; protected: virtual void pruneEmptyNodeFromList(); class MockExpectedFunctionsListNode { public: MockExpectedFunctionCall* expectedCall_; MockExpectedFunctionsListNode* next_; MockExpectedFunctionsListNode(MockExpectedFunctionCall* expectedCall) : expectedCall_(expectedCall), next_(NULL) {}; }; virtual MockExpectedFunctionsListNode* findNodeWithCallOrderOf(int callOrder) const; private: MockExpectedFunctionsListNode* head_; MockExpectedFunctionsList(const MockExpectedFunctionsList&); }; #endif
null
348
cpp
blalor-cpputest
MockFailure.h
include/CppUTestExt/MockFailure.h
null
/* * 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 MockExpectedFunctionsList; class MockActualFunctionCall; class MockNamedValue; class MockFailure; class MockFailureReporter { protected: bool crashOnFailure_; public: MockFailureReporter() : crashOnFailure_(false){}; virtual ~MockFailureReporter() {}; virtual void failTest(const MockFailure& failure); virtual Utest* getTestToFail(); virtual void crashOnFailure() {crashOnFailure_ = true; } }; class MockFailure : public TestFailure { public: MockFailure(Utest* test); virtual ~MockFailure(){}; protected: void addExpectationsAndCallHistory(const MockExpectedFunctionsList& expectations); void addExpectationsAndCallHistoryRelatedTo(const SimpleString& function, const MockExpectedFunctionsList& expectations); }; class MockExpectedCallsDidntHappenFailure : public MockFailure { public: MockExpectedCallsDidntHappenFailure(Utest* test, const MockExpectedFunctionsList& expectations); virtual ~MockExpectedCallsDidntHappenFailure(){}; }; class MockUnexpectedCallHappenedFailure : public MockFailure { public: MockUnexpectedCallHappenedFailure(Utest* test, const SimpleString& name, const MockExpectedFunctionsList& expectations); virtual ~MockUnexpectedCallHappenedFailure(){}; }; class MockCallOrderFailure : public MockFailure { public: MockCallOrderFailure(Utest* test, const MockExpectedFunctionsList& expectations); virtual ~MockCallOrderFailure(){}; }; class MockUnexpectedParameterFailure : public MockFailure { public: MockUnexpectedParameterFailure(Utest* test, const SimpleString& functionName, const MockNamedValue& parameter, const MockExpectedFunctionsList& expectations); virtual ~MockUnexpectedParameterFailure(){}; }; class MockExpectedParameterDidntHappenFailure : public MockFailure { public: MockExpectedParameterDidntHappenFailure(Utest* test, const SimpleString& functionName, const MockExpectedFunctionsList& expectations); virtual ~MockExpectedParameterDidntHappenFailure(){}; }; class MockNoWayToCompareCustomTypeFailure : public MockFailure { public: MockNoWayToCompareCustomTypeFailure(Utest* test, const SimpleString& typeName); virtual ~MockNoWayToCompareCustomTypeFailure(){}; }; class MockUnexpectedObjectFailure : public MockFailure { public: MockUnexpectedObjectFailure(Utest* test, const SimpleString& functionName, void* expected, const MockExpectedFunctionsList& expectations); virtual ~MockUnexpectedObjectFailure(){} }; class MockExpectedObjectDidntHappenFailure : public MockFailure { public: MockExpectedObjectDidntHappenFailure(Utest* test, const SimpleString& functionName, const MockExpectedFunctionsList& expectations); virtual ~MockExpectedObjectDidntHappenFailure(){} }; #endif
null
349
cpp
blalor-cpputest
MemoryReporterPlugin.h
include/CppUTestExt/MemoryReporterPlugin.h
null
/* * 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(); virtual void preTestAction(Utest & test, TestResult & result); virtual void postTestAction(Utest & test, TestResult & result); virtual bool parseArguments(int, const char**, int); protected: virtual MemoryReportFormatter* createMemoryFormatter(const SimpleString& type); private: void destroyMemoryFormatter(MemoryReportFormatter* formatter); void setGlobalMemoryReportAllocators(); void removeGlobalMemoryReportAllocators(); void initializeAllocator(MemoryReportAllocator* allocator, TestResult & result); }; #endif
null
350
cpp
blalor-cpputest
MockSupport.h
include/CppUTestExt/MockSupport.h
null
/* * 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/MockFunctionCall.h" #include "CppUTestExt/MockExpectedFunctionCall.h" #include "CppUTestExt/MockExpectedFunctionsList.h" class Utest; class MockSupport; /* This allows access to "the global" mocking support for easier testing */ MockSupport& mock(const SimpleString& mockName = ""); class MockSupport { public: MockSupport(); virtual ~MockSupport(); virtual void strictOrder(); virtual MockFunctionCall& expectOneCall(const SimpleString& functionName); virtual MockFunctionCall& expectNCalls(int amount, const SimpleString& functionName); virtual MockFunctionCall& actualCall(const SimpleString& functionName); virtual bool hasReturnValue(); virtual MockNamedValue returnValue(); virtual int intReturnValue(); virtual const char* stringReturnValue(); virtual double doubleReturnValue(); virtual void* pointerReturnValue(); bool hasData(const SimpleString& name); void setData(const SimpleString& name, 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 setDataObject(const SimpleString& name, const SimpleString& type, 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 setMockFailureReporter(MockFailureReporter* reporter); virtual void crashOnFailure(); virtual void installComparator(const SimpleString& typeName, MockNamedValueComparator& comparator); virtual void installComparators(const MockNamedValueComparatorRepository& repository); virtual void removeAllComparators(); protected: virtual MockActualFunctionCall *createActualFunctionCall(); private: static int callOrder_; static int expectedCallOrder_; bool strictOrdering_; MockFailureReporter *reporter_; MockFailureReporter defaultReporter_; MockExpectedFunctionsList expectations_; bool ignoreOtherCalls_; bool enabled_; MockActualFunctionCall *lastActualFunctionCall_; MockFunctionCallComposite compositeCalls_; MockNamedValueComparatorRepository comparatorRepository_; MockNamedValueList data_; bool tracing_; void checkExpectationsOfLastCall(); bool wasLastCallFulfilled(); void failTestWithUnexpectedCalls(); void failTestWithOutOfOrderCalls(); MockNamedValue* retrieveDataFromStore(const SimpleString& name); MockSupport* getMockSupport(MockNamedValueListNode* node); }; #endif
null
351
cpp
blalor-cpputest
MockExpectedFunctionCall.h
include/CppUTestExt/MockExpectedFunctionCall.h
null
/* * 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_MockExpectedFunctionCall_h #define D_MockExpectedFunctionCall_h #include "CppUTestExt/MockFunctionCall.h" #include "CppUTestExt/MockNamedValue.h" extern SimpleString StringFrom(const MockNamedValue& parameter); class MockExpectedFunctionCall : public MockFunctionCall { public: MockExpectedFunctionCall(); virtual ~MockExpectedFunctionCall(); virtual MockFunctionCall& withName(const SimpleString& name); virtual MockFunctionCall& withCallOrder(int); virtual MockFunctionCall& withParameter(const SimpleString& name, int value); virtual MockFunctionCall& withParameter(const SimpleString& name, double value); virtual MockFunctionCall& withParameter(const SimpleString& name, const char* value); virtual MockFunctionCall& withParameter(const SimpleString& name, void* value); virtual MockFunctionCall& withParameterOfType(const SimpleString& typeName, const SimpleString& name, void* value); virtual MockFunctionCall& ignoreOtherParameters(); virtual MockFunctionCall& andReturnValue(int value); virtual MockFunctionCall& andReturnValue(double value); virtual MockFunctionCall& andReturnValue(const char* value); virtual MockFunctionCall& andReturnValue(void* value); virtual bool hasReturnValue(); virtual MockNamedValue returnValue(); virtual MockFunctionCall& onObject(void* objectPtr); virtual MockNamedValue getParameter(const SimpleString& name); virtual SimpleString getParameterType(const SimpleString& name); virtual SimpleString getParameterValueString(const SimpleString& name); virtual bool hasParameterWithName(const SimpleString& name); virtual bool hasParameter(const MockNamedValue& parameter); virtual bool relatesTo(const SimpleString& functionName); virtual bool relatesToObject(void*objectPtr) const; virtual bool isFulfilled(); virtual bool isFulfilledWithoutIgnoredParameters(); virtual bool areParametersFulfilled(); virtual bool areIgnoredParametersFulfilled(); virtual bool isOutOfOrder() const; virtual void callWasMade(int callOrder); virtual void parameterWasPassed(const SimpleString& name); virtual void parametersWereIgnored(); virtual void wasPassedToObject(); virtual void resetExpectation(); virtual SimpleString callToString(); virtual SimpleString missingParametersToString(); enum { NOT_CALLED_YET = -1, NO_EXPECTED_CALL_ORDER = -1}; virtual int getCallOrder() const; private: class MockExpectedFunctionParameter : public MockNamedValue { public: MockExpectedFunctionParameter(const SimpleString& name); void setFulfilled(bool b); bool isFulfilled() const; private: bool fulfilled_; }; MockExpectedFunctionParameter* item(MockNamedValueListNode* node); bool ignoreOtherParameters_; bool parametersWereIgnored_; int callOrder_; int expectedCallOrder_; bool outOfOrder_; MockNamedValueList* parameters_; MockNamedValue returnValue_; void* objectPtr_; bool wasPassedToObject_; }; #endif
null
352
cpp
blalor-cpputest
MockSupportPlugin.h
include/CppUTestExt/MockSupportPlugin.h
null
/* * 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(); virtual void preTestAction(Utest&, TestResult&); virtual void postTestAction(Utest&, TestResult&); virtual void installComparator(const SimpleString& name, MockNamedValueComparator& comparator); private: MockNamedValueComparatorRepository repository_; }; #endif
null
353
cpp
blalor-cpputest
Platform.h
include/Platforms/Symbian/Platform.h
null
#ifndef PLATFORM_H_ #define PLATFORM_H_ #endif /*PLATFORM_H_*/
null
354
cpp
blalor-cpputest
Platform.h
include/Platforms/Gcc/Platform.h
null
/* * 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_Gcc_Platform_H #define D_Gcc_Platform_H #endif
null
355
cpp
blalor-cpputest
Platform.h
include/Platforms/VisualCpp/Platform.h
null
/* * 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. */ #ifdef _MSC_VER #pragma warning(disable:4786) #pragma warning(disable:4290) #pragma warning(disable:4996) #endif #ifdef WIN32 #ifdef _VC80_UPGRADE #pragma warning(disable:4996) #pragma warning(disable:4290) #else #define vsnprintf _vsnprintf #endif #endif
null
356
cpp
blalor-cpputest
stdint.h
include/Platforms/VisualCpp/stdint.h
null
/* ISO C9x 7.18 Integer types <stdint.h> * Based on ISO/IEC SC22/WG14 9899 Committee draft (SC22 N2794) * * THIS SOFTWARE IS NOT COPYRIGHTED * * Contributor: Danny Smith <[email protected]> * * This source code is offered for use in the public domain. You may * use, modify or distribute it freely. * * This code is distributed in the hope that it will be useful but * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY * DISCLAIMED. This includes but is not limited to warranties of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Date: 2000-12-02 */ #ifndef _STDINT_H #define _STDINT_H #define __need_wint_t #define __need_wchar_t #include <stddef.h> /* 7.18.1.1 Exact-width integer types */ typedef signed char int8_t; typedef unsigned char uint8_t; typedef short int16_t; typedef unsigned short uint16_t; typedef int int32_t; typedef unsigned uint32_t; //typedef long long int64_t; //typedef unsigned long long uint64_t; /* 7.18.1.2 Minimum-width integer types */ typedef signed char int_least8_t; typedef unsigned char uint_least8_t; typedef short int_least16_t; typedef unsigned short uint_least16_t; typedef int int_least32_t; typedef unsigned uint_least32_t; //typedef long long int_least64_t; //typedef unsigned long long uint_least64_t; /* 7.18.1.3 Fastest minimum-width integer types * Not actually guaranteed to be fastest for all purposes * Here we use the exact-width types for 8 and 16-bit ints. */ typedef signed char int_fast8_t; typedef unsigned char uint_fast8_t; typedef short int_fast16_t; typedef unsigned short uint_fast16_t; typedef int int_fast32_t; typedef unsigned int uint_fast32_t; //typedef long long int_fast64_t; //typedef unsigned long long uint_fast64_t; /* 7.18.1.4 Integer types capable of holding object pointers */ #ifndef _INTPTR_T_DEFINED #define _INTPTR_T_DEFINED #ifdef _WIN64 typedef __int64 intptr_t; #else typedef int intptr_t; #endif #endif #ifndef _UINTPTR_T_DEFINED #define _UINTPTR_T_DEFINED #ifdef _WIN64 typedef unsigned __int64 uintptr_t; #else typedef unsigned int uintptr_t; #endif #endif /* 7.18.1.5 Greatest-width integer types */ //typedef long long intmax_t; //typedef unsigned long long uintmax_t; /* 7.18.2 Limits of specified-width integer types */ #if !defined ( __cplusplus) || defined (__STDC_LIMIT_MACROS) /* 7.18.2.1 Limits of exact-width integer types */ #define INT8_MIN (-128) #define INT16_MIN (-32768) #define INT32_MIN (-2147483647 - 1) #define INT64_MIN (-9223372036854775807LL - 1) #define INT8_MAX 127 #define INT16_MAX 32767 #define INT32_MAX 2147483647 #define INT64_MAX 9223372036854775807LL #define UINT8_MAX 0xff /* 255U */ #define UINT16_MAX 0xffff /* 65535U */ #define UINT32_MAX 0xffffffff /* 4294967295U */ #define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */ /* 7.18.2.2 Limits of minimum-width integer types */ #define INT_LEAST8_MIN INT8_MIN #define INT_LEAST16_MIN INT16_MIN #define INT_LEAST32_MIN INT32_MIN #define INT_LEAST64_MIN INT64_MIN #define INT_LEAST8_MAX INT8_MAX #define INT_LEAST16_MAX INT16_MAX #define INT_LEAST32_MAX INT32_MAX #define INT_LEAST64_MAX INT64_MAX #define UINT_LEAST8_MAX UINT8_MAX #define UINT_LEAST16_MAX UINT16_MAX #define UINT_LEAST32_MAX UINT32_MAX #define UINT_LEAST64_MAX UINT64_MAX /* 7.18.2.3 Limits of fastest minimum-width integer types */ #define INT_FAST8_MIN INT8_MIN #define INT_FAST16_MIN INT16_MIN #define INT_FAST32_MIN INT32_MIN #define INT_FAST64_MIN INT64_MIN #define INT_FAST8_MAX INT8_MAX #define INT_FAST16_MAX INT16_MAX #define INT_FAST32_MAX INT32_MAX #define INT_FAST64_MAX INT64_MAX #define UINT_FAST8_MAX UINT8_MAX #define UINT_FAST16_MAX UINT16_MAX #define UINT_FAST32_MAX UINT32_MAX #define UINT_FAST64_MAX UINT64_MAX /* 7.18.2.4 Limits of integer types capable of holding object pointers */ #ifdef _WIN64 #define INTPTR_MIN INT64_MIN #define INTPTR_MAX INT64_MAX #define UINTPTR_MAX UINT64_MAX #else #define INTPTR_MIN INT32_MIN #define INTPTR_MAX INT32_MAX #define UINTPTR_MAX UINT32_MAX #endif /* 7.18.2.5 Limits of greatest-width integer types */ #define INTMAX_MIN INT64_MIN #define INTMAX_MAX INT64_MAX #define UINTMAX_MAX UINT64_MAX /* 7.18.3 Limits of other integer types */ #define PTRDIFF_MIN INTPTR_MIN #define PTRDIFF_MAX INTPTR_MAX #define SIG_ATOMIC_MIN INTPTR_MIN #define SIG_ATOMIC_MAX INTPTR_MAX #define SIZE_MAX UINTPTR_MAX #ifndef WCHAR_MIN /* also in wchar.h */ #define WCHAR_MIN 0 #define WCHAR_MAX 0xffff /* UINT16_MAX */ #endif /* * wint_t is unsigned short for compatibility with MS runtime */ #define WINT_MIN 0 #define WINT_MAX 0xffff /* UINT16_MAX */ #endif /* !defined ( __cplusplus) || defined __STDC_LIMIT_MACROS */ /* 7.18.4 Macros for integer constants */ #if !defined ( __cplusplus) || defined (__STDC_CONSTANT_MACROS) /* 7.18.4.1 Macros for minimum-width integer constants Accoding to Douglas Gwyn <[email protected]>: "This spec was changed in ISO/IEC 9899:1999 TC1; in ISO/IEC 9899:1999 as initially published, the expansion was required to be an integer constant of precisely matching type, which is impossible to accomplish for the shorter types on most platforms, because C99 provides no standard way to designate an integer constant with width less than that of type int. TC1 changed this to require just an integer constant *expression* with *promoted* type." */ #define INT8_C(val) val #define UINT8_C(val) val #define INT16_C(val) val #define UINT16_C(val) val #define INT32_C(val) val #define UINT32_C(val) val##U #define INT64_C(val) val##LL #define UINT64_C(val) val##ULL /* 7.18.4.2 Macros for greatest-width integer constants */ #define INTMAX_C(val) INT64_C(val) #define UINTMAX_C(val) UINT64_C(val) #endif /* !defined ( __cplusplus) || defined __STDC_CONSTANT_MACROS */ #endif
null
357
cpp
blalor-cpputest
Platform.h
include/Platforms/StarterKit/Platform.h
null
/* * 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_Gcc_Platform_H #define D_Gcc_Platform_H #endif
null
358
cpp
blalor-cpputest
ClassNameCTest.cpp
scripts/UnityTemplates/ClassNameCTest.cpp
null
extern "C" { #include "ClassName.h" } //CppUTest includes should be after your and system includes #include "CppUTest/TestHarness.h" TEST_GROUP(ClassName) { void setup() { ClassName_Create(); } void teardown() { ClassName_Destroy(); } }; TEST(ClassName, Create) { FAIL("Start here"); }
null
359
cpp
blalor-cpputest
FunctionNameCTest.cpp
scripts/UnityTemplates/FunctionNameCTest.cpp
null
extern "C" { #include "ClassName.h" } //CppUTest includes should be after your and system includes #include "CppUTest/TestHarness.h" TEST_GROUP(ClassName) { void setup() { } void teardown() { } }; TEST(ClassName, Create) { FAIL("Start here"); }
null
360
cpp
blalor-cpputest
InterfaceCTest.cpp
scripts/UnityTemplates/InterfaceCTest.cpp
null
extern "C" { #include "FakeClassName.h" } //CppUTest includes should be after your and system includes #include "CppUTest/TestHarness.h" TEST_GROUP(ClassName) { void setup() { ClassName_Create(); } void teardown() { ClassName_Destroy(); } }; TEST(ClassName, Create) { FAIL("Start here"); }
null
361
cpp
blalor-cpputest
ClassNameCIoDriverTest.cpp
scripts/UnityTemplates/ClassNameCIoDriverTest.cpp
null
extern "C" { #include "ClassName.h" #include "MockIO.h" } //CppUTest includes should be after your and system includes #include "CppUTest/TestHarness.h" TEST_GROUP(ClassName) { void setup() { Reset_Mock_IO(); ClassName_Create(); } void teardown() { ClassName_Destroy(); Assert_No_Unused_Expectations(); } }; TEST(ClassName, Create) { FAIL("Start here"); }
null
362
cpp
blalor-cpputest
ClassNameCMultipleInstanceTest.cpp
scripts/UnityTemplates/ClassNameCMultipleInstanceTest.cpp
null
extern "C" { #include "ClassName.h" } //CppUTest includes should be after your and system includes #include "CppUTest/TestHarness.h" TEST_GROUP(ClassName) { ClassName aClassName; void setup() { aClassName = ClassName_Create(); } void teardown() { ClassName_Destroy(aClassName); } }; TEST(ClassName, Create) { FAIL("Start here"); }
null
363
cpp
blalor-cpputest
MockClassName.h
scripts/CppUnitTemplates/MockClassName.h
null
#ifndef D_MockClassName_H #define D_MockClassName_H /////////////////////////////////////////////////////////////////////////////// // // MockClassName.h // // MockClassName is responsible for providing a test stub for ClassName // /////////////////////////////////////////////////////////////////////////////// #include "ClassName.h" class MockClassName : public ClassName { public: explicit MockClassName() {} virtual ~MockClassName() {} private: MockClassName(const MockClassName&); MockClassName& operator=(const MockClassName&); }; #endif // D_MockClassName_H
null
364
cpp
blalor-cpputest
ClassNameCTest.cpp
scripts/CppUnitTemplates/ClassNameCTest.cpp
null
#include "CppUTest/TestHarness.h" extern "C" { #include "ClassName.h" } TEST_GROUP(ClassName) { void setup() { ClassName_Create(); } void teardown() { ClassName_Destroy(); } }; TEST(ClassName, Create) { FAIL("Start here"); }
null
365
cpp
blalor-cpputest
ClassNameTest.cpp
scripts/CppUnitTemplates/ClassNameTest.cpp
null
#include <cppunit/config/SourcePrefix.h> #include <cppunit/extensions/HelperMacros.h> #include "ClassName.h" class ClassNameTest: public CPPUNIT_NS::TestFixture { CPPUNIT_TEST_SUITE(ClassNameTest); CPPUNIT_TEST(testCreate); CPPUNIT_TEST_SUITE_END(); ClassName* aClassName; public: void setUp() { aClassName = new ClassName(); } void tearDown() { delete aClassName; } void testCreate() { CPPUNIT_FAIL("Start here"); } }; CPPUNIT_TEST_SUITE_REGISTRATION(ClassNameTest);
null
366
cpp
blalor-cpputest
InterfaceCTest.cpp
scripts/CppUnitTemplates/InterfaceCTest.cpp
null
#include "CppUTest/TestHarness.h" extern "C" { #include "FakeClassName.h" } TEST_GROUP(FakeClassName) { void setup() { ClassName_Create(); } void teardown() { ClassName_Destroy(); } }; TEST(FakeClassName, Create) { FAIL("Start here"); }
null
367
cpp
blalor-cpputest
ClassName.cpp
scripts/CppUnitTemplates/ClassName.cpp
null
#include "ClassName.h" ClassName::ClassName() { } ClassName::~ClassName() { }
null
368
cpp
blalor-cpputest
ClassNameC.h
scripts/CppUnitTemplates/ClassNameC.h
null
#ifndef D_ClassName_H #define D_ClassName_H /////////////////////////////////////////////////////////////////////////////// // // ClassName is responsible for ... // /////////////////////////////////////////////////////////////////////////////// void ClassName_Create(void); void ClassName_Destroy(void); #endif // D_ClassName_H
null
369
cpp
blalor-cpputest
MockClassNameC.h
scripts/CppUnitTemplates/MockClassNameC.h
null
#ifndef D_FakeClassName_H #define D_FakeClassName_H /////////////////////////////////////////////////////////////////////////////// // // FakeClassName.h // // FakeClassName is responsible for providing a test stub for ClassName // /////////////////////////////////////////////////////////////////////////////// #include "ClassName.h" #endif // D_FakeClassName_H
null
370
cpp
blalor-cpputest
ClassName.h
scripts/CppUnitTemplates/ClassName.h
null
#ifndef D_ClassName_H #define D_ClassName_H /////////////////////////////////////////////////////////////////////////////// // // ClassName is responsible for ... // /////////////////////////////////////////////////////////////////////////////// class ClassName { public: explicit ClassName(); virtual ~ClassName(); private: ClassName(const ClassName&); ClassName& operator=(const ClassName&); }; #endif // D_ClassName_H
null
371
cpp
blalor-cpputest
ClassNameCMultipleInstance.h
scripts/CppUnitTemplates/ClassNameCMultipleInstance.h
null
#ifndef D_ClassName_H #define D_ClassName_H /////////////////////////////////////////////////////////////////////////////// // // ClassName is responsible for ... // /////////////////////////////////////////////////////////////////////////////// typedef struct _ClassName Classname; ClassName* ClassName_Create(void); void ClassName_Destroy(ClassName*); void ClassName_VirtualFunction_impl(ClassName*); #endif // D_ClassName_H
null
372
cpp
blalor-cpputest
ClassNameCMultipleInstanceTest.cpp
scripts/CppUnitTemplates/ClassNameCMultipleInstanceTest.cpp
null
#include "CppUTest/TestHarness.h" static int fakeRan = 0; extern "C" { #include "ClassName.h" void virtualFunction_renameThis_fake(ClassName*) { fakeRan = 1; } } TEST_GROUP(ClassName) { ClassName* aClassName; void setup() { aClassName = ClassName_Create(); fakeRan = 0; aClassName->virtualFunction_renameThis = virtualFunction_renameThis_fake; } void teardown() { ClassName_Destroy(aClassName); } }; TEST(ClassName, Fake) { aClassName->virtualFunction_renameThis(aClassName); LONGS_EQUAL(1, fakeRan); } TEST(ClassName, Create) { FAIL("Start here"); }
null
373
cpp
blalor-cpputest
ClassNameCPolymorphic.h
scripts/CppUnitTemplates/ClassNameCPolymorphic.h
null
#ifndef D_ClassName_H #define D_ClassName_H /////////////////////////////////////////////////////////////////////////////// // // ClassName is responsible for ... // /////////////////////////////////////////////////////////////////////////////// typedef struct _ClassName ClassnamePiml; ClassName* ClassName_Create(void); void ClassName_Destroy(ClassName*); void ClassName_VirtualFunction_impl(ClassName*); #endif // D_ClassName_H
null
374
cpp
blalor-cpputest
InterfaceTest.cpp
scripts/CppUnitTemplates/InterfaceTest.cpp
null
#include <cppunit/config/SourcePrefix.h> #include <cppunit/extensions/HelperMacros.h> #include "ClassName.h" #include "MockClassName.h" class MockClassNameTest: public CPPUNIT_NS::TestFixture { CPPUNIT_TEST_SUITE(MockClassNameTest); CPPUNIT_TEST(testCreate); CPPUNIT_TEST_SUITE_END(); ClassName* aClassName; MockClassName* mockClassName; public: void setUp() { mockClassName = new MockClassName(); aClassName = mockClassName; } void tearDown() { delete aClassName; } void testCreate() { CPPUNIT_FAIL("Start here"); } }; CPPUNIT_TEST_SUITE_REGISTRATION(MockClassNameTest);
null
375
cpp
blalor-cpputest
AllTests.cpp
scripts/CppUnitTemplates/ProjectTemplate/tests/AllTests.cpp
null
#include "CppUTest/CommandLineTestRunner.h" int main(int ac, char** av) { return CommandLineTestRunner::RunAllTests(ac, av); }
null
376
cpp
blalor-cpputest
ProjectBuildTimeTest.cpp
scripts/CppUnitTemplates/ProjectTemplate/tests/util/ProjectBuildTimeTest.cpp
null
#include "CppUTest/TestHarness.h" #include "ProjectBuildTime.h" TEST_GROUP(ProjectBuildTime) { ProjectBuildTime* projectBuildTime; void setup() { projectBuildTime = new ProjectBuildTime(); } void teardown() { delete projectBuildTime; } }; TEST(ProjectBuildTime, Create) { CHECK(0 != projectBuildTime->GetDateTime()); }
null
377
cpp
blalor-cpputest
ProjectBuildTime.h
scripts/CppUnitTemplates/ProjectTemplate/include/util/ProjectBuildTime.h
null
#ifndef D_ProjectBuildTime_H #define D_ProjectBuildTime_H /////////////////////////////////////////////////////////////////////////////// // // ProjectBuildTime is responsible for recording and reporting when // this project library was built // /////////////////////////////////////////////////////////////////////////////// class ProjectBuildTime { public: explicit ProjectBuildTime(); virtual ~ProjectBuildTime(); const char* GetDateTime(); private: const char* dateTime; ProjectBuildTime(const ProjectBuildTime&); ProjectBuildTime& operator=(const ProjectBuildTime&); }; #endif // D_ProjectBuildTime_H
null
378
cpp
blalor-cpputest
ProjectBuildTime.cpp
scripts/CppUnitTemplates/ProjectTemplate/src/util/ProjectBuildTime.cpp
null
#include "ProjectBuildTime.h" ProjectBuildTime::ProjectBuildTime() : dateTime(__DATE__ " " __TIME__) { } ProjectBuildTime::~ProjectBuildTime() { } const char* ProjectBuildTime::GetDateTime() { return dateTime; }
null
379
cpp
blalor-cpputest
ClassNameCIoDriver.h
scripts/templates/ClassNameCIoDriver.h
null
#ifndef D_ClassName_H #define D_ClassName_H /********************************************************** * * ClassName is responsible for ... * **********************************************************/ #include <stdint.h> void ClassName_Create(void); void ClassName_Destroy(void); #endif /* D_FakeClassName_H */
null
380
cpp
blalor-cpputest
MockClassName.h
scripts/templates/MockClassName.h
null
#ifndef D_MockClassName_H #define D_MockClassName_H /////////////////////////////////////////////////////////////////////////////// // // MockClassName.h // // MockClassName is responsible for providing a test stub for ClassName // /////////////////////////////////////////////////////////////////////////////// #include "ClassName.h" class MockClassName : public ClassName { public: explicit MockClassName() {} virtual ~MockClassName() {} private: MockClassName(const MockClassName&); MockClassName& operator=(const MockClassName&); }; #endif // D_MockClassName_H
null
381
cpp
blalor-cpputest
ClassNameCTest.cpp
scripts/templates/ClassNameCTest.cpp
null
extern "C" { #include "ClassName.h" } #include "CppUTest/TestHarness.h" TEST_GROUP(ClassName) { void setup() { ClassName_Create(); } void teardown() { ClassName_Destroy(); } }; TEST(ClassName, Create) { FAIL("Start here"); }
null
382
cpp
blalor-cpputest
ClassNameTest.cpp
scripts/templates/ClassNameTest.cpp
null
#include "ClassName.h" //CppUTest includes should be after your and system includes #include "CppUTest/TestHarness.h" TEST_GROUP(ClassName) { ClassName* aClassName; void setup() { aClassName = new ClassName(); } void teardown() { delete aClassName; } }; TEST(ClassName, Create) { FAIL("Start here"); }
null
383
cpp
blalor-cpputest
FunctionNameCTest.cpp
scripts/templates/FunctionNameCTest.cpp
null
extern "C" { #include "ClassName.h" } #include "CppUTest/TestHarness.h" TEST_GROUP(ClassName) { void setup() { } void teardown() { } }; TEST(ClassName, Create) { FAIL("Start here"); }
null
384
cpp
blalor-cpputest
InterfaceCTest.cpp
scripts/templates/InterfaceCTest.cpp
null
extern "C" { #include "FakeClassName.h" } //CppUTest includes should be after your and system includes #include "CppUTest/TestHarness.h" TEST_GROUP(ClassName) { void setup() { ClassName_Create(); } void teardown() { ClassName_Destroy(); } }; TEST(ClassName, Create) { FAIL("Start here"); }
null
385
cpp
blalor-cpputest
ClassName.cpp
scripts/templates/ClassName.cpp
null
#include "ClassName.h" ClassName::ClassName() { } ClassName::~ClassName() { }
null
386
cpp
blalor-cpputest
ClassNameC.h
scripts/templates/ClassNameC.h
null
#ifndef D_ClassName_H #define D_ClassName_H /********************************************************** * * ClassName is responsible for ... * **********************************************************/ void ClassName_Create(void); void ClassName_Destroy(void); #endif /* D_FakeClassName_H */
null
387
cpp
blalor-cpputest
MockClassNameC.h
scripts/templates/MockClassNameC.h
null
#ifndef D_FakeClassName_H #define D_FakeClassName_H /********************************************************** * * FakeClassName is responsible for providing a * test stub for ClassName * **********************************************************/ #include "ClassName.h" #endif /* D_FakeClassName_H */
null
388
cpp
blalor-cpputest
ClassNameCIoDriverTest.cpp
scripts/templates/ClassNameCIoDriverTest.cpp
null
extern "C" { #include "ClassName.h" #include "MockIO.h" } #include "CppUTest/TestHarness.h" TEST_GROUP(ClassName) { void setup() { Reset_Mock_IO(); ClassName_Create(); } void teardown() { ClassName_Destroy(); Assert_No_Unused_Expectations(); } }; TEST(ClassName, Create) { FAIL("Start here"); }
null
389
cpp
blalor-cpputest
ClassName.h
scripts/templates/ClassName.h
null
#ifndef D_ClassName_H #define D_ClassName_H /////////////////////////////////////////////////////////////////////////////// // // ClassName is responsible for ... // /////////////////////////////////////////////////////////////////////////////// class ClassName { public: explicit ClassName(); virtual ~ClassName(); private: ClassName(const ClassName&); ClassName& operator=(const ClassName&); }; #endif // D_ClassName_H
null
390
cpp
blalor-cpputest
ClassNameCMultipleInstance.h
scripts/templates/ClassNameCMultipleInstance.h
null
#ifndef D_ClassName_H #define D_ClassName_H /********************************************************************** * * ClassName is responsible for ... * **********************************************************************/ typedef struct ClassNameStruct * ClassName; ClassName ClassName_Create(void); void ClassName_Destroy(ClassName); #endif /* D_FakeClassName_H */
null
391
cpp
blalor-cpputest
FunctionNameC.h
scripts/templates/FunctionNameC.h
null
#ifndef D_ClassName_H #define D_ClassName_H /********************************************************** * * ClassName is responsible for ... * **********************************************************/ void ClassName(); #endif /* D_FakeClassName_H */
null
392
cpp
blalor-cpputest
ClassNameCMultipleInstanceTest.cpp
scripts/templates/ClassNameCMultipleInstanceTest.cpp
null
extern "C" { #include "ClassName.h" } #include "CppUTest/TestHarness.h" TEST_GROUP(ClassName) { ClassName aClassName; void setup() { aClassName = ClassName_Create(); } void teardown() { ClassName_Destroy(aClassName); } }; TEST(ClassName, Create) { FAIL("Start here"); }
null
393
cpp
blalor-cpputest
ClassNameCPolymorphic.h
scripts/templates/ClassNameCPolymorphic.h
null
#ifndef D_ClassName_H #define D_ClassName_H /********************************************************** * * ClassName is responsible for ... * **********************************************************/ typedef struct ClassName ClassNamePiml; ClassName* ClassName_Create(void); void ClassName_Destroy(ClassName*); void ClassName_VirtualFunction_impl(ClassName*); #endif /* D_FakeClassName_H */
null
394
cpp
blalor-cpputest
InterfaceTest.cpp
scripts/templates/InterfaceTest.cpp
null
#include "ClassName.h" #include "MockClassName.h" #include "CppUTest/TestHarness.h" TEST_GROUP(ClassName) { ClassName* aClassName; MockClassName* mockClassName; void setup() { mockClassName = new MockClassName(); aClassName = mockClassName; } void teardown() { delete aClassName; } }; TEST(ClassName, Create) { FAIL("Start here"); }
null
395
cpp
blalor-cpputest
AllTests.cpp
scripts/templates/ProjectTemplate/tests/AllTests.cpp
null
#include "CppUTest/CommandLineTestRunner.h" int main(int ac, char** av) { return CommandLineTestRunner::RunAllTests(ac, av); }
null
396
cpp
blalor-cpputest
ProjectBuildTimeTest.cpp
scripts/templates/ProjectTemplate/tests/util/ProjectBuildTimeTest.cpp
null
#include "CppUTest/TestHarness.h" #include "ProjectBuildTime.h" TEST_GROUP(ProjectBuildTime) { ProjectBuildTime* projectBuildTime; void setup() { projectBuildTime = new ProjectBuildTime(); } void teardown() { delete projectBuildTime; } }; TEST(ProjectBuildTime, Create) { CHECK(0 != projectBuildTime->GetDateTime()); }
null
397
cpp
blalor-cpputest
ProjectBuildTime.h
scripts/templates/ProjectTemplate/include/util/ProjectBuildTime.h
null
#ifndef D_ProjectBuildTime_H #define D_ProjectBuildTime_H /////////////////////////////////////////////////////////////////////////////// // // ProjectBuildTime is responsible for recording and reporting when // this project library was built // /////////////////////////////////////////////////////////////////////////////// class ProjectBuildTime { public: explicit ProjectBuildTime(); virtual ~ProjectBuildTime(); const char* GetDateTime(); private: const char* dateTime; ProjectBuildTime(const ProjectBuildTime&); ProjectBuildTime& operator=(const ProjectBuildTime&); }; #endif // D_ProjectBuildTime_H
null
398
cpp
blalor-cpputest
ProjectBuildTime.cpp
scripts/templates/ProjectTemplate/src/util/ProjectBuildTime.cpp
null
#include "ProjectBuildTime.h" ProjectBuildTime::ProjectBuildTime() : dateTime(__DATE__ " " __TIME__) { } ProjectBuildTime::~ProjectBuildTime() { } const char* ProjectBuildTime::GetDateTime() { return dateTime; }
null
399
cpp
blalor-cpputest
CommandLineTestRunner.cpp
src/CppUTest/CommandLineTestRunner.cpp
null
/* * 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. */ #include "CppUTest/TestHarness.h" #include "CppUTest/CommandLineTestRunner.h" #include "CppUTest/TestOutput.h" #include "CppUTest/JUnitTestOutput.h" #include "CppUTest/TestRegistry.h" CommandLineTestRunner::CommandLineTestRunner(int ac, const char** av, TestOutput* output) : output_(output), jUnitOutput_(new JUnitTestOutput) { arguments_ = new CommandLineArguments(ac, av); } CommandLineTestRunner::~CommandLineTestRunner() { delete arguments_; delete jUnitOutput_; } int CommandLineTestRunner::RunAllTests(int ac, char** av) { return RunAllTests(ac, const_cast<const char**> (av)); } int CommandLineTestRunner::RunAllTests(int ac, const char** av) { int result = 0; ConsoleTestOutput output; MemoryLeakWarningPlugin memLeakWarn(DEF_PLUGIN_MEM_LEAK); TestRegistry::getCurrentRegistry()->installPlugin(&memLeakWarn); { CommandLineTestRunner runner(ac, av, &output); result = runner.runAllTestsMain(); } if (result == 0) { output << memLeakWarn.FinalReport(0); } return result; } int CommandLineTestRunner::runAllTestsMain() { int testResult = 0; SetPointerPlugin pPlugin(DEF_PLUGIN_SET_POINTER); TestRegistry::getCurrentRegistry()->installPlugin(&pPlugin); if (!parseArguments(TestRegistry::getCurrentRegistry()->getFirstPlugin())) return 1; testResult = runAllTests(); TestRegistry::getCurrentRegistry()->cleanup(); return testResult; } void CommandLineTestRunner::initializeTestRun() { TestRegistry::getCurrentRegistry()->groupFilter(arguments_->getGroupFilter()); TestRegistry::getCurrentRegistry()->nameFilter(arguments_->getNameFilter()); if (arguments_->isVerbose()) output_->verbose(); } int CommandLineTestRunner::runAllTests() { initializeTestRun(); int loopCount = 0; int failureCount = 0; int repeat_ = arguments_->getRepeatCount(); while (loopCount++ < repeat_) { output_->printTestRun(loopCount, repeat_); TestResult tr(*output_); TestRegistry::getCurrentRegistry()->runAllTests(tr); failureCount += tr.getFailureCount(); } return failureCount; } bool CommandLineTestRunner::parseArguments(TestPlugin* plugin) { if (arguments_->parse(plugin)) { if (arguments_->isJUnitOutput()) { output_ = jUnitOutput_; } return true; } else { output_->print(arguments_->usage()); return false; } } bool CommandLineTestRunner::isVerbose() { return arguments_->isVerbose(); } int CommandLineTestRunner::getRepeatCount() { return arguments_->getRepeatCount(); } SimpleString CommandLineTestRunner::getGroupFilter() { return arguments_->getGroupFilter(); } SimpleString CommandLineTestRunner::getNameFilter() { return arguments_->getNameFilter(); }
null
400
cpp
blalor-cpputest
TestPlugin.cpp
src/CppUTest/TestPlugin.cpp
null
/* * 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. */ #include "CppUTest/TestHarness.h" #include "CppUTest/TestPlugin.h" TestPlugin::TestPlugin(const SimpleString& name) : next_(NullTestPlugin::instance()), name_(name), enabled_(true) { } TestPlugin::TestPlugin(TestPlugin* next) : next_(next), name_("null") { } TestPlugin::~TestPlugin() { } TestPlugin* TestPlugin::addPlugin(TestPlugin* plugin) { next_ = plugin; return this; } void TestPlugin::runAllPreTestAction(Utest& test, TestResult& result) { if (enabled_) preTestAction(test, result); next_->runAllPreTestAction(test, result); } void TestPlugin::runAllPostTestAction(Utest& test, TestResult& result) { next_ ->runAllPostTestAction(test, result); if (enabled_) postTestAction(test, result); } bool TestPlugin::parseAllArguments(int ac, char** av, int index) { return parseAllArguments(ac, const_cast<const char**> (av), index); } bool TestPlugin::parseAllArguments(int ac, const char** av, int index) { if (parseArguments(ac, av, index)) return true; if (next_) return next_->parseAllArguments(ac, av, index); return false; } const SimpleString& TestPlugin::getName() { return name_; } TestPlugin* TestPlugin::getPluginByName(const SimpleString& name) { if (name == name_) return this; if (next_) return next_->getPluginByName(name); return (next_); } TestPlugin* TestPlugin::getNext() { return next_; } TestPlugin* TestPlugin::removePluginByName(const SimpleString& name) { TestPlugin* removed = 0; if (next_ && next_->getName() == name) { removed = next_; next_ = next_->next_; } return removed; } void TestPlugin::disable() { enabled_ = false; } void TestPlugin::enable() { enabled_ = true; } bool TestPlugin::isEnabled() { return enabled_; } struct cpputest_pair { void **orig; void *orig_value; }; //////// SetPlugin static int pointerTableIndex; static cpputest_pair setlist[SetPointerPlugin::MAX_SET]; SetPointerPlugin::SetPointerPlugin(const SimpleString& name) : TestPlugin(name) { pointerTableIndex = 0; } SetPointerPlugin::~SetPointerPlugin() { } void CppUTestStore(void**function, void*value) { if (pointerTableIndex >= SetPointerPlugin::MAX_SET) { FAIL("Maximum number of function pointers installed!"); } setlist[pointerTableIndex].orig_value = value; setlist[pointerTableIndex].orig = function; pointerTableIndex++; } void SetPointerPlugin::postTestAction(Utest& /*test*/, TestResult& /*result*/) { for (int i = pointerTableIndex - 1; i >= 0; i--) *((void**) setlist[i].orig) = setlist[i].orig_value; pointerTableIndex = 0; } //////// NullPlugin NullTestPlugin::NullTestPlugin() : TestPlugin(0) { } NullTestPlugin* NullTestPlugin::instance() { static NullTestPlugin _instance; return &_instance; } void NullTestPlugin::runAllPreTestAction(Utest&, TestResult&) { } void NullTestPlugin::runAllPostTestAction(Utest&, TestResult&) { }
null