Library meant to simplify writing of tests. Very light-weight in the approach. Test syntax will be familiar to users of CUnit, however this is far more basic.

Dependents:   CircularBufferTest

Tests are expected to take the form of macro-based statements, such as:

// An empty buffer should yield getSize() of zero
TST_EQ( buffer.getSize(), 0, "Empty buffer: getSize()" );

You still have to do the hard work of coming up with the tests and writing code to implement them, but this library is intended to give you a "jump start" towards getting something with consistent output and keeping track of the number of passes/fails - just import the library, include the header and you're away.

See CircularBufferTest main.cpp for an example of how this library can be used

Committer:
johnb
Date:
Sun Jan 19 17:14:59 2014 +0000
Revision:
0:62a10b8392a4
Quick utility library to support testing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
johnb 0:62a10b8392a4 1 /**
johnb 0:62a10b8392a4 2 @file
johnb 0:62a10b8392a4 3 @brief Set up TestSupportLite for simple tests
johnb 0:62a10b8392a4 4
johnb 0:62a10b8392a4 5 @author John Bailey
johnb 0:62a10b8392a4 6
johnb 0:62a10b8392a4 7 @copyright Copyright 2014 John Bailey
johnb 0:62a10b8392a4 8
johnb 0:62a10b8392a4 9 @section LICENSE
johnb 0:62a10b8392a4 10
johnb 0:62a10b8392a4 11 Licensed under the Apache License, Version 2.0 (the "License");
johnb 0:62a10b8392a4 12 you may not use this file except in compliance with the License.
johnb 0:62a10b8392a4 13 You may obtain a copy of the License at
johnb 0:62a10b8392a4 14
johnb 0:62a10b8392a4 15 http://www.apache.org/licenses/LICENSE-2.0
johnb 0:62a10b8392a4 16
johnb 0:62a10b8392a4 17 Unless required by applicable law or agreed to in writing, software
johnb 0:62a10b8392a4 18 distributed under the License is distributed on an "AS IS" BASIS,
johnb 0:62a10b8392a4 19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
johnb 0:62a10b8392a4 20 See the License for the specific language governing permissions and
johnb 0:62a10b8392a4 21 limitations under the License.
johnb 0:62a10b8392a4 22
johnb 0:62a10b8392a4 23 */
johnb 0:62a10b8392a4 24
johnb 0:62a10b8392a4 25 #if !defined TESTSUPPORTSIMPLE_HPP
johnb 0:62a10b8392a4 26 #define TESTSUPPORTSIMPLE_HPP
johnb 0:62a10b8392a4 27
johnb 0:62a10b8392a4 28 #if defined __CC_ARM
johnb 0:62a10b8392a4 29 #include "mbed.h"
johnb 0:62a10b8392a4 30 extern Serial pc;
johnb 0:62a10b8392a4 31 #define TS_PRINTF( ... ) pc.printf(__VA_ARGS__)
johnb 0:62a10b8392a4 32 #else
johnb 0:62a10b8392a4 33 #include <stdio.h>
johnb 0:62a10b8392a4 34 #define TS_PRINTF( ... ) printf(__VA_ARGS__)
johnb 0:62a10b8392a4 35 #endif
johnb 0:62a10b8392a4 36
johnb 0:62a10b8392a4 37 #include "TestSupportLite.hpp"
johnb 0:62a10b8392a4 38
johnb 0:62a10b8392a4 39 extern TestResults tst_glob;
johnb 0:62a10b8392a4 40
johnb 0:62a10b8392a4 41 /** Text to be displayed for each test being run */
johnb 0:62a10b8392a4 42 #define TEST_TXT "[%03d] {%c} %s\r\n"
johnb 0:62a10b8392a4 43
johnb 0:62a10b8392a4 44 /** Text to be displayed at the end of the test run */
johnb 0:62a10b8392a4 45 #define DONE_TXT "----- [%d tests run, %d passed]\r\n"
johnb 0:62a10b8392a4 46
johnb 0:62a10b8392a4 47 /** Text to be displayed for failing tests */
johnb 0:62a10b8392a4 48 #define FAIL_TXT " Test at %s:%d\r\n"
johnb 0:62a10b8392a4 49
johnb 0:62a10b8392a4 50 #define TEST_OUT( _p, _t ) do { tst_glob.registerResult( _p ); TS_PRINTF( TEST_TXT, tst_glob.getCount(), _p?'X':' ', _t ); } while (0)
johnb 0:62a10b8392a4 51 #define DONE_OUT() do { TS_PRINTF( DONE_TXT, tst_glob.getCount(), tst_glob.getPassed() ); } while ( 0 )
johnb 0:62a10b8392a4 52 #define FAIL_OUT() do { TS_PRINTF( FAIL_TXT, __FILE__, __LINE__ ); } while ( 0 )
johnb 0:62a10b8392a4 53
johnb 0:62a10b8392a4 54 #endif