1 // Copyright (c) 2003, Google Inc.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
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
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.
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.
32 #ifdef HAVE_USING_OPERATOR
41 // C++0x isn't enabled by default in GCC and libc++ does not have
42 // non-standard ext/* and tr1/unordered_*.
43 # if defined(_LIBCPP_VERSION)
44 # define GLOG_STL_LOGGING_FOR_UNORDERED
46 # define GLOG_STL_LOGGING_FOR_EXT_HASH
47 # define GLOG_STL_LOGGING_FOR_EXT_SLIST
48 # define GLOG_STL_LOGGING_FOR_TR1_UNORDERED
52 #include "glog/logging.h"
53 #include "glog/stl_logging.h"
54 #include "googletest.h"
57 #ifdef GLOG_STL_LOGGING_FOR_EXT_HASH
58 using namespace __gnu_cxx;
62 size_t operator()(int x) const { return x; }
65 void TestSTLLogging() {
74 EXPECT_EQ(ss.str(), "10 20 30");
75 vector<int> copied_v(v);
76 CHECK_EQ(v, copied_v); // This must compile.
80 // Test a sorted pair associative container.
87 EXPECT_EQ(ss.str(), "(10, ten) (20, twenty) (30, thirty)");
88 map< int, string > copied_m(m);
89 CHECK_EQ(m, copied_m); // This must compile.
92 #ifdef GLOG_STL_LOGGING_FOR_EXT_HASH
94 // Test a hashed simple associative container.
101 EXPECT_EQ(ss.str(), "10 20 30");
102 hash_set<int> copied_hs(hs);
103 CHECK_EQ(hs, copied_hs); // This must compile.
107 #ifdef GLOG_STL_LOGGING_FOR_EXT_HASH
109 // Test a hashed pair associative container.
110 hash_map<int, string> hm;
116 EXPECT_EQ(ss.str(), "(10, ten) (20, twenty) (30, thirty)");
117 hash_map<int, string> copied_hm(hm);
118 CHECK_EQ(hm, copied_hm); // this must compile
123 // Test a long sequence.
126 for (int i = 0; i < 100; i++) {
128 if (i > 0) expected += ' ';
130 sprintf(buf, "%d", i);
137 CHECK_EQ(ss.str(), expected.c_str());
141 // Test a sorted pair associative container.
142 // Use a non-default comparison functor.
143 map< int, string, greater<int> > m;
149 EXPECT_EQ(ss.str(), "(30, thirty) (20, twenty) (10, ten)");
150 map< int, string, greater<int> > copied_m(m);
151 CHECK_EQ(m, copied_m); // This must compile.
154 #ifdef GLOG_STL_LOGGING_FOR_EXT_HASH
156 // Test a hashed simple associative container.
157 // Use a user defined hash function.
158 hash_set<int, user_hash> hs;
164 EXPECT_EQ(ss.str(), "10 20 30");
165 hash_set<int, user_hash> copied_hs(hs);
166 CHECK_EQ(hs, copied_hs); // This must compile.
171 int main(int, char**) {
173 std::cout << "PASS\n";
181 int main(int, char**) {
182 std::cout << "We don't support stl_logging for this compiler.\n"
183 << "(we need compiler support of 'using ::operator<<' "
184 << "for this feature.)\n";
188 #endif // HAVE_USING_OPERATOR