ztring.c: A few important extension for <string.h>
 All Classes Files Functions Variables Enumerator Friends Macros
uUnit.h
Go to the documentation of this file.
1 /* uUnit.h (C) 2011 adolfo@di-mare.com */
2 
3 /** \file uUnit.h
4  \brief [u]Micro module for [Unit] program testing.
5 
6  \author Adolfo Di Mare <adolfo@di-mare.com>
7  \date 2011
8  \see http://www.di-mare.com/adolfo/p/BUnitXP.htm
9 
10 \code
11  #include "uUnit.h" // assertTrue() && assertFalse()
12 
13  // Example
14  int main( int argc , const char* argv[] ) {
15  std::cout << "TestCase [uUnit.h] yesYES" << std::endl;
16  assertTrue( 1==2 ); // ok?
17  assertFalse( 1==2 ); // ok!
18  return test_myImp(argc , argv);
19  }
20 \endcode
21 */
22 
23 #ifndef ADOLFO_UUNIT
24 #define ADOLFO_UUNIT
25 
26 /* #include "BUnit.h" // http://www.di-mare.com/adolfo/p/BUnit.htm */
27 /* #include "BUnit.h" // http://www.di-mare.com/adolfo/p/BUnitXP.htm */
28 
29 /** "C:/DIR/SubDir/file_name.ext" ==> "file_name.ext" */
30 static /* "static" avoids "function already defined" linkage error */
31 const char* remove_dir_name( const char* str )
32 {
33  const char *p = str; /* p = str+strlen(str); */
34  while ( *p != 0 ) { ++p; }
35  while ( *p != '/' && *p != '\\' && *p != ':' ) {
36  if ( p == str ) { return str; }
37  --p;
38  }
39  return p+1;
40 /*
41  Each object file will contain a local compiled copy of this function
42  because it is declared 'static'. This duplication is the price paid to
43  avoid using a uUnit.cpp file.
44 */
45 }
46 
47 #ifdef __cplusplus
48  #include <iostream> /* std::cout */
49  template <class T> inline /* inline avoids 'multiple definition' warning */
50  void testThis( bool cond, const T* label, const T* fname, long lineno );
51  template <> inline
53  bool cond, const char* label, const char* fname, long lineno
54  ) {
55  if (!cond) {
56  std::cout << "=\\_fail: " << label << " \n=/ (";
57  std::cout << lineno << ") " << remove_dir_name(fname) << "\n";
58  }
59  }
60 #else
61  #include <stdio.h> /* printf() */
62  static
63  void testThis(
64  int cond, const char* label, const char* fname, long lineno
65  ) {
66  if (!cond) {
67  printf( "%s%s%s", "=\\_fail: " , label , " \n=/ (" );
68  printf( "%ld%s%s%s", lineno , ") " , remove_dir_name(fname),"\n" );
69  }
70  }
71 #endif
72 
73 
74 #ifdef NDEBUG
75  #define assertTrue(x) ((void)0)
76  #define assertFalse(x) ((void)0)
77 #else /* debugging enabled */
78  /** (cond ? () : cout << "cond" ) */
79  #define assertTrue(cond) testThis(!!(cond), #cond, __FILE__,__LINE__ )
80  /** (!(cond) ? () : cout << "!" << (cond)" ) */
81  #define assertFalse(cond) testThis( !(cond),"!(" #cond ")", __FILE__,__LINE__ )
82 #endif
83 
84 #endif
85 
86 /* EOF: uUnit.h */
void testThis< char >(bool cond, const char *label, const char *fname, long lineno)
Definition: uUnit.h:52
void testThis(bool cond, const T *label, const T *fname, long lineno)
static const char * remove_dir_name(const char *str)
"C:/DIR/SubDir/file_name.ext" ==> "file_name.ext"
Definition: uUnit.h:31