File: TestLog.cpp

package info (click to toggle)
openclonk 8.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 169,656 kB
  • sloc: cpp: 180,484; ansic: 108,988; xml: 31,371; python: 1,223; php: 767; makefile: 148; sh: 101; javascript: 34
file content (69 lines) | stat: -rw-r--r-- 2,121 bytes parent folder | download | duplicates (5)
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
/*
* OpenClonk, http://www.openclonk.org
*
* Copyright (c) 2016, The OpenClonk Team and contributors
*
* Distributed under the terms of the ISC license; see accompanying file
* "COPYING" for details.
*
* "Clonk" is a registered trademark of Matthes Bender, used with permission.
* See accompanying file "TRADEMARK" for details.
*
* To redistribute this file separately, substitute the full license texts
* for the above references.
*/

// Proxies the logging functions into a class so we can test that something
// gets logged

#include "TestLog.h"

// Override ALL of the C4SimpleLog.cpp functions here because otherwise MSVC
// pulls the .obj in and will end up with multiple definitions of a symbol.
#define FORWARD_UNFORMATTED(func) bool func(const char *msg) { return TestLog::handler ? TestLog::handler->func(msg) : true; }
FORWARD_UNFORMATTED(Log)
FORWARD_UNFORMATTED(DebugLog)
FORWARD_UNFORMATTED(LogSilent)
FORWARD_UNFORMATTED(LogFatal)
#undef FORWARD_UNFORMATTED

#define FORWARD_FORMATTED(func) bool func(const char *msg, ...) \
	{ \
		va_list args; va_start(args, msg); \
		bool result = TestLog::handler ? TestLog::handler->func(msg, args) : true; \
		va_end(args); \
		return result; \
	}
FORWARD_FORMATTED(DebugLogF)
FORWARD_FORMATTED(LogF)
FORWARD_FORMATTED(LogSilentF)
#undef FORWARD_FORMATTED

TestLog *TestLog::handler = 0;

void TestLog::setHandler(TestLog *new_handler)
{
	handler = new_handler;
}

TestLog::TestLog()
{
	setHandler(this);
}

TestLog::~TestLog()
{
	// Make sure there's no deleted logging handler set
	if (handler == this)
		handler = 0;
}

// Default implementation does nothing
bool TestLog::Log(const char * /* msg */) { return true; }
bool TestLog::DebugLog(const char * /* msg */) { return true; }
bool TestLog::LogFatal(const char * /* msg */) { return true; }
bool TestLog::LogSilent(const char * /* msg */) { return true; }

bool TestLog::LogF(const char * /* msg */, va_list /* args */) { return true; }
bool TestLog::DebugLogF(const char * /* msg */, va_list /* args */) { return true; }
bool TestLog::LogSilentF(const char * /* msg */, va_list /* args */) { return true; }