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

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