[go: up one dir, main page]

File: test.cpp

package info (click to toggle)
rlog 1.3.7-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,440 kB
  • ctags: 3,785
  • sloc: sh: 11,016; cpp: 1,533; makefile: 127
file content (131 lines) | stat: -rw-r--r-- 3,595 bytes parent folder | download | duplicates (2)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*****************************************************************************
 * Author:   Valient Gough <vgough@pobox.com>
 *
 *****************************************************************************
 * Copyright (c) 2003-2004, Valient Gough
 * Copyright (c) 2004, Vadim Zeitlin (Win32)
 *
 * This library is free software; you can distribute it and/or modify it under
 * the terms of the GNU Lesser General Public License (LGPL), as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the LGPL in the file COPYING for more
 * details.
 *
 */
		                                                                                
                             
#include "rlog.h"
#include "rloglocation.h"
#include "Error.h"
#include "RLogChannel.h"
#include "StdioNode.h"
#include "RLogTime.h"

#include <stdio.h>
#include <memory.h>

using namespace rlog;
using namespace std;

static RLogChannel *RLTest = RLOG_CHANNEL( "test/heartbeat" );

rlog_time_interval sleepTime(int seconds)
{
    rlog_time start, end;

    rlog_get_time( &start );
    sleep(seconds);
    rlog_get_time( &end );

    return rlog_time_diff( end, start );
}

void testFunc()
{
    bool testAssert = false;
    rAssertSilent( testAssert == true );
}

int main(int argc, char **argv)
{
    RLogInit( argc, argv );

    StdioNode stdLog;

    rlog_time start, end;
    rlog_get_time( &start );

    // subscribe to various things individually
    stdLog.subscribeTo( RLOG_CHANNEL("debug") );
    stdLog.subscribeTo( GetGlobalChannel("warning") );
    stdLog.subscribeTo( RLOG_CHANNEL("error") );
    stdLog.subscribeTo( GetGlobalChannel("test") );

    // subscribe to *everything* (root type node corresponds to all types, and
    // all publications belong to a type)
    //stdLog.subscribeTo( RLOG_CHANNEL("") );

    // subscribe to all messages from this file
    //stdLog.subscribeTo( FileNode::Lookup( __FILE__ ));
    
    rlog_get_time( &end );
    rDebug("time for StdioNode subscription setup: %i " RLOG_TIME_UNIT, 
	    (int)rlog_time_diff(end, start));

    rDebug("in main()");
    rWarning("testing rWarning");
    rError("testing rError");

    // test assert
    rDebug("the following assert failure is just a test");
    try
    {
	testFunc();
    } catch( Error &err )
    {
	rDebug("caught assert failure from %s line %i",
		err.file(), err.line());
        rDebug("failure in function %s, component %s",
		err.function(), err.component());
    }


    rlog_get_time( &start );

    /*
	Example of short circuting data.  If there are no subscribers to the
	following rLog() calls, then sleepTime() will not be called.  Since we
	subscribed above, it will report how long we slept for..
    */
    const int maxLoop = 4;
    for(int i=0; i<maxLoop; ++i)
    {
	//cerr << "in test loop" << endl;
	rLog( RLTest, "loop %i of %i, sleepTime(1) = %i " RLOG_TIME_UNIT, 
		i, maxLoop, static_cast<int>(sleepTime(1)));
    }
    
    rlog_get_time( &end );

    rlog_time_interval totalTime = rlog_time_diff(end, start);

    /*
        Braces are needed as otherwise the code can't be compiled with
        compilers not supporting variadic macros.
     */
    if(totalTime == -1L)
    {
	rWarning("This message should never be seen!!");
    }

    rDebug("leaving main(), total time = %lli " RLOG_TIME_UNIT, totalTime);

    return 0;
}