/work/obj-fuzz/dist/include/gtest/gtest-message.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2005, Google Inc. |
2 | | // All rights reserved. |
3 | | // |
4 | | // Redistribution and use in source and binary forms, with or without |
5 | | // modification, are permitted provided that the following conditions are |
6 | | // met: |
7 | | // |
8 | | // * Redistributions of source code must retain the above copyright |
9 | | // notice, this list of conditions and the following disclaimer. |
10 | | // * Redistributions in binary form must reproduce the above |
11 | | // copyright notice, this list of conditions and the following disclaimer |
12 | | // in the documentation and/or other materials provided with the |
13 | | // distribution. |
14 | | // * Neither the name of Google Inc. nor the names of its |
15 | | // contributors may be used to endorse or promote products derived from |
16 | | // this software without specific prior written permission. |
17 | | // |
18 | | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 | | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 | | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 | | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 | | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 | | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 | | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 | | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 | | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 | | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 | | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | | // |
30 | | // Author: wan@google.com (Zhanyong Wan) |
31 | | // |
32 | | // The Google C++ Testing Framework (Google Test) |
33 | | // |
34 | | // This header file defines the Message class. |
35 | | // |
36 | | // IMPORTANT NOTE: Due to limitation of the C++ language, we have to |
37 | | // leave some internal implementation details in this header file. |
38 | | // They are clearly marked by comments like this: |
39 | | // |
40 | | // // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. |
41 | | // |
42 | | // Such code is NOT meant to be used by a user directly, and is subject |
43 | | // to CHANGE WITHOUT NOTICE. Therefore DO NOT DEPEND ON IT in a user |
44 | | // program! |
45 | | |
46 | | #ifndef GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_ |
47 | | #define GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_ |
48 | | |
49 | | #include <limits> |
50 | | |
51 | | #include "gtest/internal/gtest-port.h" |
52 | | |
53 | | // Ensures that there is at least one operator<< in the global namespace. |
54 | | // See Message& operator<<(...) below for why. |
55 | | void operator<<(const testing::internal::Secret&, int); |
56 | | |
57 | | namespace testing { |
58 | | |
59 | | // The Message class works like an ostream repeater. |
60 | | // |
61 | | // Typical usage: |
62 | | // |
63 | | // 1. You stream a bunch of values to a Message object. |
64 | | // It will remember the text in a stringstream. |
65 | | // 2. Then you stream the Message object to an ostream. |
66 | | // This causes the text in the Message to be streamed |
67 | | // to the ostream. |
68 | | // |
69 | | // For example; |
70 | | // |
71 | | // testing::Message foo; |
72 | | // foo << 1 << " != " << 2; |
73 | | // std::cout << foo; |
74 | | // |
75 | | // will print "1 != 2". |
76 | | // |
77 | | // Message is not intended to be inherited from. In particular, its |
78 | | // destructor is not virtual. |
79 | | // |
80 | | // Note that stringstream behaves differently in gcc and in MSVC. You |
81 | | // can stream a NULL char pointer to it in the former, but not in the |
82 | | // latter (it causes an access violation if you do). The Message |
83 | | // class hides this difference by treating a NULL char pointer as |
84 | | // "(null)". |
85 | | class GTEST_API_ Message { |
86 | | private: |
87 | | // The type of basic IO manipulators (endl, ends, and flush) for |
88 | | // narrow streams. |
89 | | typedef std::ostream& (*BasicNarrowIoManip)(std::ostream&); |
90 | | |
91 | | public: |
92 | | // Constructs an empty Message. |
93 | | Message(); |
94 | | |
95 | | // Copy constructor. |
96 | | Message(const Message& msg) : ss_(new ::std::stringstream) { // NOLINT |
97 | | *ss_ << msg.GetString(); |
98 | | } |
99 | | |
100 | | // Constructs a Message from a C-string. |
101 | 0 | explicit Message(const char* str) : ss_(new ::std::stringstream) { |
102 | 0 | *ss_ << str; |
103 | 0 | } |
104 | | |
105 | | #if GTEST_OS_SYMBIAN |
106 | | // Streams a value (either a pointer or not) to this object. |
107 | | template <typename T> |
108 | | inline Message& operator <<(const T& value) { |
109 | | StreamHelper(typename internal::is_pointer<T>::type(), value); |
110 | | return *this; |
111 | | } |
112 | | #else |
113 | | // Streams a non-pointer value to this object. |
114 | | template <typename T> |
115 | 72 | inline Message& operator <<(const T& val) { |
116 | 72 | // Some libraries overload << for STL containers. These |
117 | 72 | // overloads are defined in the global namespace instead of ::std. |
118 | 72 | // |
119 | 72 | // C++'s symbol lookup rule (i.e. Koenig lookup) says that these |
120 | 72 | // overloads are visible in either the std namespace or the global |
121 | 72 | // namespace, but not other namespaces, including the testing |
122 | 72 | // namespace which Google Test's Message class is in. |
123 | 72 | // |
124 | 72 | // To allow STL containers (and other types that has a << operator |
125 | 72 | // defined in the global namespace) to be used in Google Test |
126 | 72 | // assertions, testing::Message must access the custom << operator |
127 | 72 | // from the global namespace. With this using declaration, |
128 | 72 | // overloads of << defined in the global namespace and those |
129 | 72 | // visible via Koenig lookup are both exposed in this function. |
130 | 72 | using ::operator <<; |
131 | 72 | *ss_ << val; |
132 | 72 | return *this; |
133 | 72 | } Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [12]>(char const (&) [12]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [3]>(char const (&) [3]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [5]>(char const (&) [5]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [32]>(char const (&) [32]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [36]>(char const (&) [36]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [61]>(char const (&) [61]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [44]>(char const (&) [44]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [51]>(char const (&) [51]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [40]>(char const (&) [40]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [43]>(char const (&) [43]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [42]>(char const (&) [42]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [39]>(char const (&) [39]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [49]>(char const (&) [49]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [34]>(char const (&) [34]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [31]>(char const (&) [31]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [33]>(char const (&) [33]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [27]>(char const (&) [27]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [26]>(char const (&) [26]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [48]>(char const (&) [48]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [35]>(char const (&) [35]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [37]>(char const (&) [37]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [55]>(char const (&) [55]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [21]>(char const (&) [21]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [41]>(char const (&) [41]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [68]>(char const (&) [68]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [70]>(char const (&) [70]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [38]>(char const (&) [38]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [6]>(char const (&) [6]) testing::Message& testing::Message::operator<< <int>(int const&) Line | Count | Source | 115 | 24 | inline Message& operator <<(const T& val) { | 116 | 24 | // Some libraries overload << for STL containers. These | 117 | 24 | // overloads are defined in the global namespace instead of ::std. | 118 | 24 | // | 119 | 24 | // C++'s symbol lookup rule (i.e. Koenig lookup) says that these | 120 | 24 | // overloads are visible in either the std namespace or the global | 121 | 24 | // namespace, but not other namespaces, including the testing | 122 | 24 | // namespace which Google Test's Message class is in. | 123 | 24 | // | 124 | 24 | // To allow STL containers (and other types that has a << operator | 125 | 24 | // defined in the global namespace) to be used in Google Test | 126 | 24 | // assertions, testing::Message must access the custom << operator | 127 | 24 | // from the global namespace. With this using declaration, | 128 | 24 | // overloads of << defined in the global namespace and those | 129 | 24 | // visible via Koenig lookup are both exposed in this function. | 130 | 24 | using ::operator <<; | 131 | 24 | *ss_ << val; | 132 | 24 | return *this; | 133 | 24 | } |
Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [2]>(char const (&) [2]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [22]>(char const (&) [22]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [28]>(char const (&) [28]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [23]>(char const (&) [23]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [30]>(char const (&) [30]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [24]>(char const (&) [24]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [56]>(char const (&) [56]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <unsigned long>(unsigned long const&) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [62]>(char const (&) [62]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [69]>(char const (&) [69]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [15]>(char const (&) [15]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [16]>(char const (&) [16]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [20]>(char const (&) [20]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [19]>(char const (&) [19]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [11]>(char const (&) [11]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <std::__1::ios_base& (std::__1::ios_base&)>(std::__1::ios_base& ( const&)(std::__1::ios_base&)) Unexecuted instantiation: testing::Message& testing::Message::operator<< <unsigned int>(unsigned int const&) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [4]>(char const (&) [4]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [17]>(char const (&) [17]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [18]>(char const (&) [18]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [13]>(char const (&) [13]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [25]>(char const (&) [25]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [45]>(char const (&) [45]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [14]>(char const (&) [14]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [47]>(char const (&) [47]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [29]>(char const (&) [29]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [58]>(char const (&) [58]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [9]>(char const (&) [9]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [8]>(char const (&) [8]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [87]>(char const (&) [87]) testing::Message& testing::Message::operator<< <char [7]>(char const (&) [7]) Line | Count | Source | 115 | 48 | inline Message& operator <<(const T& val) { | 116 | 48 | // Some libraries overload << for STL containers. These | 117 | 48 | // overloads are defined in the global namespace instead of ::std. | 118 | 48 | // | 119 | 48 | // C++'s symbol lookup rule (i.e. Koenig lookup) says that these | 120 | 48 | // overloads are visible in either the std namespace or the global | 121 | 48 | // namespace, but not other namespaces, including the testing | 122 | 48 | // namespace which Google Test's Message class is in. | 123 | 48 | // | 124 | 48 | // To allow STL containers (and other types that has a << operator | 125 | 48 | // defined in the global namespace) to be used in Google Test | 126 | 48 | // assertions, testing::Message must access the custom << operator | 127 | 48 | // from the global namespace. With this using declaration, | 128 | 48 | // overloads of << defined in the global namespace and those | 129 | 48 | // visible via Koenig lookup are both exposed in this function. | 130 | 48 | using ::operator <<; | 131 | 48 | *ss_ << val; | 132 | 48 | return *this; | 133 | 48 | } |
Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [113]>(char const (&) [113]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [10]>(char const (&) [10]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [84]>(char const (&) [84]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [86]>(char const (&) [86]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [73]>(char const (&) [73]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [54]>(char const (&) [54]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [75]>(char const (&) [75]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [67]>(char const (&) [67]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [66]>(char const (&) [66]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [60]>(char const (&) [60]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [46]>(char const (&) [46]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [76]>(char const (&) [76]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <float>(float const&) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [57]>(char const (&) [57]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [1]>(char const (&) [1]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [65]>(char const (&) [65]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [83]>(char const (&) [83]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [82]>(char const (&) [82]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [90]>(char const (&) [90]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [89]>(char const (&) [89]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [71]>(char const (&) [71]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [81]>(char const (&) [81]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [85]>(char const (&) [85]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [80]>(char const (&) [80]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [97]>(char const (&) [97]) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char [139]>(char const (&) [139]) |
134 | | |
135 | | // Streams a pointer value to this object. |
136 | | // |
137 | | // This function is an overload of the previous one. When you |
138 | | // stream a pointer to a Message, this definition will be used as it |
139 | | // is more specialized. (The C++ Standard, section |
140 | | // [temp.func.order].) If you stream a non-pointer, then the |
141 | | // previous definition will be used. |
142 | | // |
143 | | // The reason for this overload is that streaming a NULL pointer to |
144 | | // ostream is undefined behavior. Depending on the compiler, you |
145 | | // may get "0", "(nil)", "(null)", or an access violation. To |
146 | | // ensure consistent result across compilers, we always treat NULL |
147 | | // as "(null)". |
148 | | template <typename T> |
149 | 48 | inline Message& operator <<(T* const& pointer) { // NOLINT |
150 | 48 | if (pointer == NULL) { |
151 | 0 | *ss_ << "(null)"; |
152 | 48 | } else { |
153 | 48 | *ss_ << pointer; |
154 | 48 | } |
155 | 48 | return *this; |
156 | 48 | } testing::Message& testing::Message::operator<< <char const>(char const* const&) Line | Count | Source | 149 | 48 | inline Message& operator <<(T* const& pointer) { // NOLINT | 150 | 48 | if (pointer == NULL) { | 151 | 0 | *ss_ << "(null)"; | 152 | 48 | } else { | 153 | 48 | *ss_ << pointer; | 154 | 48 | } | 155 | 48 | return *this; | 156 | 48 | } |
Unexecuted instantiation: testing::Message& testing::Message::operator<< <unsigned char const>(unsigned char const* const&) Unexecuted instantiation: testing::Message& testing::Message::operator<< <char16_t const>(char16_t const* const&) Unexecuted instantiation: testing::Message& testing::Message::operator<< <mozilla::NrIceMediaStream>(mozilla::NrIceMediaStream* const&) |
157 | | #endif // GTEST_OS_SYMBIAN |
158 | | |
159 | | // Since the basic IO manipulators are overloaded for both narrow |
160 | | // and wide streams, we have to provide this specialized definition |
161 | | // of operator <<, even though its body is the same as the |
162 | | // templatized version above. Without this definition, streaming |
163 | | // endl or other basic IO manipulators to Message will confuse the |
164 | | // compiler. |
165 | 0 | Message& operator <<(BasicNarrowIoManip val) { |
166 | 0 | *ss_ << val; |
167 | 0 | return *this; |
168 | 0 | } |
169 | | |
170 | | // Instead of 1/0, we want to see true/false for bool values. |
171 | 0 | Message& operator <<(bool b) { |
172 | 0 | return *this << (b ? "true" : "false"); |
173 | 0 | } |
174 | | |
175 | | // These two overloads allow streaming a wide C string to a Message |
176 | | // using the UTF-8 encoding. |
177 | | Message& operator <<(const wchar_t* wide_c_str); |
178 | | Message& operator <<(wchar_t* wide_c_str); |
179 | | |
180 | | #if GTEST_HAS_STD_WSTRING |
181 | | // Converts the given wide string to a narrow string using the UTF-8 |
182 | | // encoding, and streams the result to this Message object. |
183 | | Message& operator <<(const ::std::wstring& wstr); |
184 | | #endif // GTEST_HAS_STD_WSTRING |
185 | | |
186 | | #if GTEST_HAS_GLOBAL_WSTRING |
187 | | // Converts the given wide string to a narrow string using the UTF-8 |
188 | | // encoding, and streams the result to this Message object. |
189 | | Message& operator <<(const ::wstring& wstr); |
190 | | #endif // GTEST_HAS_GLOBAL_WSTRING |
191 | | |
192 | | // Gets the text streamed to this object so far as an std::string. |
193 | | // Each '\0' character in the buffer is replaced with "\\0". |
194 | | // |
195 | | // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. |
196 | | std::string GetString() const; |
197 | | |
198 | | private: |
199 | | |
200 | | #if GTEST_OS_SYMBIAN |
201 | | // These are needed as the Nokia Symbian Compiler cannot decide between |
202 | | // const T& and const T* in a function template. The Nokia compiler _can_ |
203 | | // decide between class template specializations for T and T*, so a |
204 | | // tr1::type_traits-like is_pointer works, and we can overload on that. |
205 | | template <typename T> |
206 | | inline void StreamHelper(internal::true_type /*is_pointer*/, T* pointer) { |
207 | | if (pointer == NULL) { |
208 | | *ss_ << "(null)"; |
209 | | } else { |
210 | | *ss_ << pointer; |
211 | | } |
212 | | } |
213 | | template <typename T> |
214 | | inline void StreamHelper(internal::false_type /*is_pointer*/, |
215 | | const T& value) { |
216 | | // See the comments in Message& operator <<(const T&) above for why |
217 | | // we need this using statement. |
218 | | using ::operator <<; |
219 | | *ss_ << value; |
220 | | } |
221 | | #endif // GTEST_OS_SYMBIAN |
222 | | |
223 | | // We'll hold the text streamed to this object here. |
224 | | const internal::scoped_ptr< ::std::stringstream> ss_; |
225 | | |
226 | | // We declare (but don't implement) this to prevent the compiler |
227 | | // from implementing the assignment operator. |
228 | | void operator=(const Message&); |
229 | | }; |
230 | | |
231 | | // Streams a Message to an ostream. |
232 | | inline std::ostream& operator <<(std::ostream& os, const Message& sb) { |
233 | | return os << sb.GetString(); |
234 | | } |
235 | | |
236 | | namespace internal { |
237 | | |
238 | | // Converts a streamable value to an std::string. A NULL pointer is |
239 | | // converted to "(null)". When the input value is a ::string, |
240 | | // ::std::string, ::wstring, or ::std::wstring object, each NUL |
241 | | // character in it is replaced with "\\0". |
242 | | template <typename T> |
243 | 24 | std::string StreamableToString(const T& streamable) { |
244 | 24 | return (Message() << streamable).GetString(); |
245 | 24 | } |
246 | | |
247 | | } // namespace internal |
248 | | } // namespace testing |
249 | | |
250 | | #endif // GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_ |