Implémentation de RipplingMath.h
[GPU.git] / WCudaMSE / API_CppTest / SRC / core / compileroutput.cpp
1 // ---
2 //
3 // $Id: compileroutput.cpp,v 1.3 2005/06/08 08:08:06 nilu Exp $
4 //
5 // CppTest - A C++ Unit Testing Framework
6 // Copyright (c) 2003 Niklas Lundell
7 //
8 // ---
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the
22 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 // Boston, MA 02111-1307, USA.
24 //
25 // ---
26
27 #include <cstring>
28 #include <sstream>
29
30 #include "cpptest-compileroutput.h"
31 #include "cpptest-source.h"
32
33 using namespace std;
34
35 namespace Test
36 {
37 namespace
38 {
39 // Checks for output format modifiers.
40 //
41 bool
42 check_format(const string& format,
43 string::size_type& pos,
44 const string& mod,
45 int& mod_cnt)
46 {
47 if (format.compare(pos, mod.size(), mod) == 0)
48 {
49 if (++mod_cnt > 1)
50 throw Test::CompilerOutput::InvalidFormat(format);
51 pos += mod.size();
52 return true;
53 }
54 return false;
55 }
56
57 } // anonymous namespace
58
59 /// Constructs a compiler output handler.
60 ///
61 /// \param format Pre-defined compiler output format.
62 /// \param stream Stream to output to.
63 ///
64 CompilerOutput::CompilerOutput(Format format, ostream& stream)
65 : Output(),
66 _stream(stream)
67 {
68 static const char* table[] =
69 {
70 "%file:%line: %text", // Generic
71 "Error cpptest %file %line: %text", // BCC
72 "%file:%line: %text", // GCC
73 "%file(%line) : %text" // MSVC
74 };
75
76 _format = table[format];
77 }
78
79 /// Constructs a compiler output handler.
80 ///
81 /// \param format %Output format to use.
82 /// \param stream Stream to output to.
83 ///
84 /// \exception InvalidFormat Invalid format specified.
85 ///
86 CompilerOutput::CompilerOutput(const string& format, ostream& stream)
87 : Output(),
88 _format(format),
89 _stream(stream)
90 {
91 int expr(0), file(0), line(0);
92
93 for (string::size_type pos = 0;
94 (pos = _format.find_first_of('%', pos)) != string::npos; )
95 {
96 ++pos;
97 if (check_format(_format, pos, "expr", expr)) ;
98 else if (check_format(_format, pos, "file", file)) ;
99 else if (check_format(_format, pos, "line", line)) ;
100 else
101 throw InvalidFormat(format);
102 }
103
104 if (!expr && !file && !line)
105 throw InvalidFormat(format);
106 }
107
108 void
109 CompilerOutput::assertment(const Source& s)
110 {
111 string fmt(_format);
112 string::size_type pos;
113
114 fmt.reserve(fmt.size() + 128);
115
116 if ((pos = fmt.find("%file")) != string::npos)
117 fmt.replace(pos, 5, s.file());
118
119 if ((pos = fmt.find("%text")) != string::npos)
120 fmt.replace(pos, 5, s.message());
121
122 if ((pos = fmt.find("%line")) != string::npos)
123 {
124 ostringstream ss;
125 ss << s.line();
126 fmt.replace(pos, 5, ss.str());
127 }
128
129 _stream << fmt << endl;
130 }
131
132 } // namespace Test
133