OpendTect  6.3
testprog.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*+
4 ________________________________________________________________________
5 
6  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
7  Author: A.H. Bril
8  Date: Dec 2013
9 ________________________________________________________________________
10 
11  Single include getting many of the tools you need for test programs.
12 
13  The macro mInitTestProg() will take care of:
14  1) Initialisation of program args
15  2) A file-scope variable 'bool quiet': whether progress info is required
16  3) A command line parser 'CommandLineParser clparser'
17 
18 -*/
19 
20 #include "commandlineparser.h"
21 #include "keystrs.h"
22 #include "debug.h"
23 #include "ptrman.h"
24 #include "od_ostream.h"
25 
26 # ifdef __win__
27 # include "winmain.h"
28 # endif
29 
30 int testMain( int argc, char** argv );
31 
32 #ifndef mMainIsDefined
33 #define mMainIsDefined
34 int main(int argc, char** argv)
35 {
36  ExitProgram( testMain( argc, argv ) );
37 }
38 #endif
39 
40 static mUsedVar bool quiet = true;
42 
43 static inline mUsedVar od_ostream& tstStream( bool err=false )
44 {
45  if ( !quiet || err )
46  {
47  if ( err )
48  od_ostream::logStream() << "[FAIL] ";
49  return od_ostream::logStream();
50  }
51  return od_ostream::nullStream();
52 }
53 
54 
55 #define mInitTestProg() \
56  od_init_test_program( argc, argv ); \
57  theparser = new CommandLineParser; \
58  CommandLineParser& clparser = *theparser; \
59  quiet = clparser.hasKey( sKey::Quiet() )
60 
61 #define mExitTestProg( var )
62 
63 #define mInitBatchTestProg() \
64  int argc = GetArgC(); char** argv = GetArgV(); \
65  mInitTestProg()
66 
67 #define mRunStandardTestWithError( test, desc, err ) \
68 if ( !quiet ) \
69  od_ostream::logStream() << desc; \
70 if ( (test) ) \
71 { \
72  if ( !quiet ) \
73  od_ostream::logStream() << " - SUCCESS\n"; \
74 } \
75 else \
76 { \
77  if ( quiet ) \
78  od_ostream::logStream() << desc; \
79  od_ostream::logStream() << " - FAIL"; \
80  if ( err ) \
81  od_ostream::logStream() << ": " << err << "\n"; \
82 \
83  return false; \
84 }
85 
86 #define mRunStandardTest( test, desc ) \
87  mRunStandardTestWithError( test, desc, BufferString().str() )
int testMain(int argc, char **argv)
OD class for stream write common access to the user log file, or std::cout in batch progs...
Definition: od_ostream.h:25
Definition: ptrman.h:115
static od_ostream & logStream()
used by ErrMsg and UsrMsg
static mUsedVar PtrMan< CommandLineParser > theparser
Definition: testprog.h:41
static mUsedVar od_ostream & tstStream(bool err=false)
Definition: testprog.h:43
static mUsedVar bool quiet
Definition: testprog.h:40
int main(int argc, char **argv)
Definition: testprog.h:34
int ExitProgram(int ret)
static od_ostream & nullStream()

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2017