EmbUnit library for mbed. EmbUnit is a unit testing framework for embedded software. (more info: http://embunit.sourceforge.net/ )
TestRunner.cpp@0:bbc0d658b7eb, 2011-01-18 (annotated)
- Committer:
- sillevl
- Date:
- Tue Jan 18 16:39:49 2011 +0000
- Revision:
- 0:bbc0d658b7eb
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sillevl | 0:bbc0d658b7eb | 1 | /* |
sillevl | 0:bbc0d658b7eb | 2 | * COPYRIGHT AND PERMISSION NOTICE |
sillevl | 0:bbc0d658b7eb | 3 | * |
sillevl | 0:bbc0d658b7eb | 4 | * Copyright (c) 2003 Embedded Unit Project |
sillevl | 0:bbc0d658b7eb | 5 | * |
sillevl | 0:bbc0d658b7eb | 6 | * All rights reserved. |
sillevl | 0:bbc0d658b7eb | 7 | * |
sillevl | 0:bbc0d658b7eb | 8 | * Permission is hereby granted, free of charge, to any person obtaining |
sillevl | 0:bbc0d658b7eb | 9 | * a copy of this software and associated documentation files (the |
sillevl | 0:bbc0d658b7eb | 10 | * "Software"), to deal in the Software without restriction, including |
sillevl | 0:bbc0d658b7eb | 11 | * without limitation the rights to use, copy, modify, merge, publish, |
sillevl | 0:bbc0d658b7eb | 12 | * distribute, and/or sell copies of the Software, and to permit persons |
sillevl | 0:bbc0d658b7eb | 13 | * to whom the Software is furnished to do so, provided that the above |
sillevl | 0:bbc0d658b7eb | 14 | * copyright notice(s) and this permission notice appear in all copies |
sillevl | 0:bbc0d658b7eb | 15 | * of the Software and that both the above copyright notice(s) and this |
sillevl | 0:bbc0d658b7eb | 16 | * permission notice appear in supporting documentation. |
sillevl | 0:bbc0d658b7eb | 17 | * |
sillevl | 0:bbc0d658b7eb | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
sillevl | 0:bbc0d658b7eb | 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
sillevl | 0:bbc0d658b7eb | 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT |
sillevl | 0:bbc0d658b7eb | 21 | * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
sillevl | 0:bbc0d658b7eb | 22 | * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY |
sillevl | 0:bbc0d658b7eb | 23 | * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER |
sillevl | 0:bbc0d658b7eb | 24 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
sillevl | 0:bbc0d658b7eb | 25 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
sillevl | 0:bbc0d658b7eb | 26 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
sillevl | 0:bbc0d658b7eb | 27 | * |
sillevl | 0:bbc0d658b7eb | 28 | * Except as contained in this notice, the name of a copyright holder |
sillevl | 0:bbc0d658b7eb | 29 | * shall not be used in advertising or otherwise to promote the sale, |
sillevl | 0:bbc0d658b7eb | 30 | * use or other dealings in this Software without prior written |
sillevl | 0:bbc0d658b7eb | 31 | * authorization of the copyright holder. |
sillevl | 0:bbc0d658b7eb | 32 | * |
sillevl | 0:bbc0d658b7eb | 33 | * $Id: TestRunner.c,v 1.6 2004/02/10 16:19:29 arms22 Exp $ |
sillevl | 0:bbc0d658b7eb | 34 | */ |
sillevl | 0:bbc0d658b7eb | 35 | #include "config.h" |
sillevl | 0:bbc0d658b7eb | 36 | #include "stdImpl.h" |
sillevl | 0:bbc0d658b7eb | 37 | #include "Test.h" |
sillevl | 0:bbc0d658b7eb | 38 | #include "TestListener.h" |
sillevl | 0:bbc0d658b7eb | 39 | #include "TestResult.h" |
sillevl | 0:bbc0d658b7eb | 40 | #include "TestRunner.h" |
sillevl | 0:bbc0d658b7eb | 41 | |
sillevl | 0:bbc0d658b7eb | 42 | static TestResult result_; |
sillevl | 0:bbc0d658b7eb | 43 | static Test* root_; |
sillevl | 0:bbc0d658b7eb | 44 | |
sillevl | 0:bbc0d658b7eb | 45 | static void TestRunner_startTest(TestListner* self,Test* test) |
sillevl | 0:bbc0d658b7eb | 46 | { |
sillevl | 0:bbc0d658b7eb | 47 | stdimpl_print("."); |
sillevl | 0:bbc0d658b7eb | 48 | } |
sillevl | 0:bbc0d658b7eb | 49 | |
sillevl | 0:bbc0d658b7eb | 50 | static void TestRunner_endTest(TestListner* self,Test* test) |
sillevl | 0:bbc0d658b7eb | 51 | { |
sillevl | 0:bbc0d658b7eb | 52 | } |
sillevl | 0:bbc0d658b7eb | 53 | |
sillevl | 0:bbc0d658b7eb | 54 | static void TestRunner_addFailure(TestListner* self,Test* test,char* msg,int line,char* file) |
sillevl | 0:bbc0d658b7eb | 55 | { |
sillevl | 0:bbc0d658b7eb | 56 | stdimpl_print("\r\n"); |
sillevl | 0:bbc0d658b7eb | 57 | stdimpl_print(Test_name(root_)); |
sillevl | 0:bbc0d658b7eb | 58 | stdimpl_print("."); |
sillevl | 0:bbc0d658b7eb | 59 | stdimpl_print(Test_name(test)); |
sillevl | 0:bbc0d658b7eb | 60 | { |
sillevl | 0:bbc0d658b7eb | 61 | char buf[16]; |
sillevl | 0:bbc0d658b7eb | 62 | stdimpl_print(" ("); |
sillevl | 0:bbc0d658b7eb | 63 | stdimpl_print(file); |
sillevl | 0:bbc0d658b7eb | 64 | stdimpl_print(" "); |
sillevl | 0:bbc0d658b7eb | 65 | stdimpl_itoa(line, buf, 10); |
sillevl | 0:bbc0d658b7eb | 66 | stdimpl_print(buf); |
sillevl | 0:bbc0d658b7eb | 67 | stdimpl_print(") "); |
sillevl | 0:bbc0d658b7eb | 68 | } |
sillevl | 0:bbc0d658b7eb | 69 | stdimpl_print(msg); |
sillevl | 0:bbc0d658b7eb | 70 | stdimpl_print("\r\n"); |
sillevl | 0:bbc0d658b7eb | 71 | } |
sillevl | 0:bbc0d658b7eb | 72 | |
sillevl | 0:bbc0d658b7eb | 73 | static const TestListnerImplement TestRunnerImplement = { |
sillevl | 0:bbc0d658b7eb | 74 | (TestListnerStartTestCallBack) TestRunner_startTest, |
sillevl | 0:bbc0d658b7eb | 75 | (TestListnerEndTestCallBack) TestRunner_endTest, |
sillevl | 0:bbc0d658b7eb | 76 | (TestListnerAddFailureCallBack) TestRunner_addFailure, |
sillevl | 0:bbc0d658b7eb | 77 | }; |
sillevl | 0:bbc0d658b7eb | 78 | |
sillevl | 0:bbc0d658b7eb | 79 | static const TestListner testrunner_ = { |
sillevl | 0:bbc0d658b7eb | 80 | (TestListnerImplement*)&TestRunnerImplement, |
sillevl | 0:bbc0d658b7eb | 81 | }; |
sillevl | 0:bbc0d658b7eb | 82 | |
sillevl | 0:bbc0d658b7eb | 83 | void TestRunner_start(void) |
sillevl | 0:bbc0d658b7eb | 84 | { |
sillevl | 0:bbc0d658b7eb | 85 | stdimpl_print("---Start EmbUnit---\r\n"); |
sillevl | 0:bbc0d658b7eb | 86 | TestResult_init(&result_, (TestListner*)&testrunner_); |
sillevl | 0:bbc0d658b7eb | 87 | } |
sillevl | 0:bbc0d658b7eb | 88 | |
sillevl | 0:bbc0d658b7eb | 89 | void TestRunner_runTest(Test* test) |
sillevl | 0:bbc0d658b7eb | 90 | { |
sillevl | 0:bbc0d658b7eb | 91 | root_ = test; |
sillevl | 0:bbc0d658b7eb | 92 | Test_run(test, &result_); |
sillevl | 0:bbc0d658b7eb | 93 | } |
sillevl | 0:bbc0d658b7eb | 94 | |
sillevl | 0:bbc0d658b7eb | 95 | void TestRunner_end(void) |
sillevl | 0:bbc0d658b7eb | 96 | { |
sillevl | 0:bbc0d658b7eb | 97 | char buf[16]; |
sillevl | 0:bbc0d658b7eb | 98 | if (result_.failureCount) { |
sillevl | 0:bbc0d658b7eb | 99 | stdimpl_print("\r\nrun "); |
sillevl | 0:bbc0d658b7eb | 100 | stdimpl_itoa(result_.runCount, buf, 10); |
sillevl | 0:bbc0d658b7eb | 101 | stdimpl_print(buf); |
sillevl | 0:bbc0d658b7eb | 102 | stdimpl_print(" failures "); |
sillevl | 0:bbc0d658b7eb | 103 | stdimpl_itoa(result_.failureCount, buf, 10); |
sillevl | 0:bbc0d658b7eb | 104 | stdimpl_print(buf); |
sillevl | 0:bbc0d658b7eb | 105 | stdimpl_print("\r\n"); |
sillevl | 0:bbc0d658b7eb | 106 | } else { |
sillevl | 0:bbc0d658b7eb | 107 | stdimpl_print("\r\nOK ("); |
sillevl | 0:bbc0d658b7eb | 108 | stdimpl_itoa(result_.runCount, buf, 10); |
sillevl | 0:bbc0d658b7eb | 109 | stdimpl_print(buf); |
sillevl | 0:bbc0d658b7eb | 110 | stdimpl_print(" tests)\r\n"); |
sillevl | 0:bbc0d658b7eb | 111 | } |
sillevl | 0:bbc0d658b7eb | 112 | } |