| 1 | /* |
| 2 | * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * * Neither the name of the <organization> nor the |
| 13 | * names of its contributors may be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY |
| 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY |
| 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #include "CppUTest/TestHarness.h" |
| 29 | #include "CppUTest/TestOutput.h" |
| 30 | #include "CppUTestExt/MemoryReportAllocator.h" |
| 31 | #include "CppUTestExt/MemoryReportFormatter.h" |
| 32 | |
| 33 | #define TESTOUTPUT_EQUAL(a) STRCMP_EQUAL_LOCATION(a, testOutput.getOutput().asCharString(), "", __FILE__, __LINE__) |
| 34 | |
| 35 | TEST_GROUP(NormalMemoryReportFormatter) |
| 36 | { |
| 37 | char* memory01; |
| 38 | |
| 39 | StringBufferTestOutput testOutput; |
| 40 | TestResult* testResult; |
| 41 | NormalMemoryReportFormatter formatter; |
| 42 | |
| 43 | void setup() |
| 44 | { |
| 45 | memory01 = (char*) 0x01; |
| 46 | testResult = new TestResult(testOutput); |
| 47 | } |
| 48 | |
| 49 | void teardown() |
| 50 | { |
| 51 | delete testResult; |
| 52 | } |
| 53 | }; |
| 54 | |
| 55 | |
| 56 | TEST(NormalMemoryReportFormatter, mallocCreatesAnMallocCall) |
| 57 | { |
| 58 | formatter.report_alloc_memory(testResult, defaultMallocAllocator(), 10, memory01, "file", 9); |
| 59 | TESTOUTPUT_EQUAL(StringFromFormat("\tAllocation using malloc of size: 10 pointer: %p at file:9\n", (void*) memory01).asCharString()); |
| 60 | } |
| 61 | |
| 62 | TEST(NormalMemoryReportFormatter, freeCreatesAnFreeCall) |
| 63 | { |
| 64 | formatter.report_free_memory(testResult, defaultMallocAllocator(), memory01, "boo", 6); |
| 65 | TESTOUTPUT_EQUAL(StringFromFormat("\tDeallocation using free of pointer: %p at boo:6\n", (void*) memory01).asCharString()); |
| 66 | } |
| 67 | |
| 68 | TEST(NormalMemoryReportFormatter, testStarts) |
| 69 | { |
| 70 | UtestShell test("groupName", "TestName", "file", 1); |
| 71 | formatter.report_test_start(testResult, test); |
| 72 | TESTOUTPUT_EQUAL("TEST(groupName, TestName)\n"); |
| 73 | } |
| 74 | |
| 75 | TEST(NormalMemoryReportFormatter, testEnds) |
| 76 | { |
| 77 | UtestShell test("groupName", "TestName", "file", 1); |
| 78 | formatter.report_test_end(testResult, test); |
| 79 | TESTOUTPUT_EQUAL("ENDTEST(groupName, TestName)\n"); |
| 80 | } |
| 81 | |
| 82 | TEST(NormalMemoryReportFormatter, testGroupStarts) |
| 83 | { |
| 84 | UtestShell test("groupName", "TestName", "file", 1); |
| 85 | formatter.report_testgroup_start(testResult, test); |
| 86 | TESTOUTPUT_EQUAL("------------------------------TEST GROUP(groupName)-----------------------------\n"); |
| 87 | } |