summaryrefslogtreecommitdiff
path: root/src/tests/xb_test_log.cpp
blob: 613b7dd207b85614a729abeb8eec4fd5fc0221aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*  xb_test_log.cpp

XBase64 Software Library

Copyright (c) 1997,2003,2014,2022 Gary A Kunkel

The xb64 software library is covered under the terms of the GPL Version 3, 2007 license.

Email Contact:

    XDB-devel@lists.sourceforge.net
    XDB-users@lists.sourceforge.net

*/

// This program tests the class xbLog

// usage:   xb_test_log QUITE|NORMAL|VERBOSE


#include "xbase.h"

using namespace xb;

#include "tstfuncs.cpp"



int main( int argCnt, char **av )
{
  int rc = 0;

#ifdef XB_LOGGING_SUPPORT


  int po = 1;          /* print option */
                       /* 0 - QUIET    */
                       /* 1 - NORMAL   */
                       /* 2 - VERBOSE  */

  if( argCnt > 1 ) {
    if( av[1][0] == 'Q' )
      po = 0;
    else if( av[1][0] == 'V' )
      po = 2;
  }

  xbXBase x;
  x.EnableMsgLogging();
  InitTime();
  if( po ){
    std::cout << "Logfile is [" << x.GetLogFqFileName().Str() << "]" << std::endl;
  }
  xbString sMsg;
  sMsg.Sprintf( "Program [%s] initializing...", av[0] );
  x.WriteLogMessage( sMsg );


  xbString sNewLogFileName = "Logfile2.txt";
  sMsg.Sprintf( "Switching to logfile [%s]", sNewLogFileName.Str() );
  x.WriteLogMessage( sMsg );


  x.DisableMsgLogging();
  rc += TestMethod( po, "Set/Get Log Status()", x.GetLogStatus(), xbFalse );
  x.SetLogFileName( sNewLogFileName );
  x.EnableMsgLogging();

  rc += TestMethod( po, "Set/Get Log Status()", x.GetLogStatus(), 1 );
  rc += TestMethod( po,"WriteLogMessage()", x.WriteLogMessage( "Test log message........" ), XB_NO_ERROR );


  sMsg.Sprintf( "Program [%s] terminating with [%d] errors...", av[0], rc * -1 );
  x.WriteLogMessage( sMsg );

  if( po > 0 || rc < 0 )
    fprintf( stdout, "Total Errors = %d\n", rc * -1 );


  #endif         /* XB_LOGGING_SUPPORT */


  return rc;
}