]> git.ipfire.org Git - thirdparty/squid.git/blob - test-suite/test_tools.cc
Summary: debugs tweaks.
[thirdparty/squid.git] / test-suite / test_tools.cc
1
2 /*
3 * $Id: test_tools.cc,v 1.3 2003/07/08 23:01:47 robertc Exp $
4 *
5 * AUTHOR: Robert Collins
6 *
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
9 *
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
32 *
33 * Copyright (c) 2003 Robert Collins <robertc@squid-cache.org>
34 */
35
36 #define _SQUID_EXTERNNEW_
37 #include "squid.h"
38 #include <iostream>
39 #include <sstream>
40
41 void
42 xassert(const char *msg, const char *file, int line)
43 {
44 std::cout << "Assertion failed: (" << msg << ") at " << file << ":" << line << std::endl;
45 exit (1);
46 }
47 time_t squid_curtime = 0;
48
49 int Debug::Levels[MAX_DEBUG_SECTIONS];
50 int Debug::level;
51
52 static void
53 _db_print_stderr(const char *format, va_list args);
54
55 void
56 #if STDC_HEADERS
57 _db_print(const char *format,...)
58 {
59 #else
60 _db_print(va_alist)
61 va_dcl
62 {
63 const char *format = NULL;
64 #endif
65
66 LOCAL_ARRAY(char, f, BUFSIZ);
67 va_list args1;
68 #if STDC_HEADERS
69
70 va_list args2;
71 va_list args3;
72 #else
73 #define args2 args1
74 #define args3 args1
75 #endif
76
77 #if STDC_HEADERS
78
79 va_start(args1, format);
80
81 va_start(args2, format);
82
83 va_start(args3, format);
84
85 #else
86
87 format = va_arg(args1, const char *);
88
89 #endif
90
91 snprintf(f, BUFSIZ, "%s| %s",
92 "stub time", //debugLogTime(squid_curtime),
93 format);
94
95 _db_print_stderr(f, args2);
96
97 va_end(args1);
98
99 #if STDC_HEADERS
100
101 va_end(args2);
102
103 va_end(args3);
104
105 #endif
106 }
107
108 static void
109 _db_print_stderr(const char *format, va_list args) {
110 /* FIXME? */
111 // if (opt_debug_stderr < Debug::level)
112 if (1 < Debug::level)
113 return;
114
115 vfprintf(stderr, format, args);
116 }
117
118 void
119 fatal(const char *message) {
120 debug (0,0) ("Fatal: %s",message);
121 exit (1);
122 }
123
124 std::ostream &
125 Debug::getDebugOut()
126 {
127 assert (CurrentDebug == NULL);
128 CurrentDebug = new std::ostringstream();
129 return *CurrentDebug;
130 }
131
132 void
133 Debug::finishDebug()
134 {
135 _db_print("%s\n", CurrentDebug->str().c_str());
136 delete CurrentDebug;
137 CurrentDebug = NULL;
138 }
139
140 std::ostringstream *Debug::CurrentDebug (NULL);