3 ==================================================================================
4 Copyright (c) 2020 AT&T Intellectual Property.
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
21 Mnemonic: ut_support.c
22 Abstract: Tools to make unit testing easier.
25 Author: E. Scott Daniels
30 static std::string test_name = "unknown";
33 Set the name of the current tester
35 extern void set_test_name( std::string name ) {
40 Returns 1 if the condition is true (not zero)
42 extern int fail_if( int cond, std::string reason ) {
44 fprintf( stderr, "<FAIL> %s: %s\n", test_name.c_str(), reason.c_str() );
52 Returns 1 if the condition is false.
54 extern int fail_if_false( int cond, std::string reason ) {
56 fprintf( stderr, "<FAIL> %s: %s\n", test_name.c_str(), reason.c_str() );
63 extern void announce_results( int errors ) {
65 fprintf( stderr, "<FAIL> %s: failed with %d errors\n", test_name.c_str(), errors );
67 fprintf( stderr, "<PASS> %s: passed with\n", test_name.c_str() );