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
42 // C++0x isn't enabled by default in GCC and libc++ does not have
43 // non-standard ext/* and tr1/unordered_*.
44 # if defined(_LIBCPP_VERSION)
45 # ifndef GLOG_STL_LOGGING_FOR_UNORDERED
46 # define GLOG_STL_LOGGING_FOR_UNORDERED
49 # ifndef GLOG_STL_LOGGING_FOR_EXT_HASH
50 # define GLOG_STL_LOGGING_FOR_EXT_HASH
52 # ifndef GLOG_STL_LOGGING_FOR_EXT_SLIST
53 # define GLOG_STL_LOGGING_FOR_EXT_SLIST
55 # ifndef GLOG_STL_LOGGING_FOR_TR1_UNORDERED
56 # define GLOG_STL_LOGGING_FOR_TR1_UNORDERED
61 #include "glog/logging.h"
62 #include "glog/stl_logging.h"
63 #include "googletest.h"
66 #ifdef GLOG_STL_LOGGING_FOR_EXT_HASH
67 using namespace __gnu_cxx;
71 size_t operator()(int x) const { return x; }
74 void TestSTLLogging() {
83 EXPECT_EQ(ss.str(), "10 20 30");
84 vector<int> copied_v(v);
85 CHECK_EQ(v, copied_v); // This must compile.
89 // Test a sorted pair associative container.
96 EXPECT_EQ(ss.str(), "(10, ten) (20, twenty) (30, thirty)");
97 map< int, string > copied_m(m);
98 CHECK_EQ(m, copied_m); // This must compile.
101 #ifdef GLOG_STL_LOGGING_FOR_EXT_HASH
103 // Test a hashed simple associative container.
110 EXPECT_EQ(ss.str(), "10 20 30");
111 hash_set<int> copied_hs(hs);
112 CHECK_EQ(hs, copied_hs); // This must compile.
116 #ifdef GLOG_STL_LOGGING_FOR_EXT_HASH
118 // Test a hashed pair associative container.
119 hash_map<int, string> hm;
125 EXPECT_EQ(ss.str(), "(10, ten) (20, twenty) (30, thirty)");
126 hash_map<int, string> copied_hm(hm);
127 CHECK_EQ(hm, copied_hm); // this must compile
132 // Test a long sequence.
135 for (int i = 0; i < 100; i++) {
137 if (i > 0) expected += ' ';
139 sprintf(buf, "%d", i);
146 CHECK_EQ(ss.str(), expected.c_str());
150 // Test a sorted pair associative container.
151 // Use a non-default comparison functor.
152 map< int, string, greater<int> > m;
158 EXPECT_EQ(ss.str(), "(30, thirty) (20, twenty) (10, ten)");
159 map< int, string, greater<int> > copied_m(m);
160 CHECK_EQ(m, copied_m); // This must compile.
163 #ifdef GLOG_STL_LOGGING_FOR_EXT_HASH
165 // Test a hashed simple associative container.
166 // Use a user defined hash function.
167 hash_set<int, user_hash> hs;
173 EXPECT_EQ(ss.str(), "10 20 30");
174 hash_set<int, user_hash> copied_hs(hs);
175 CHECK_EQ(hs, copied_hs); // This must compile.
180 int main(int, char**) {
182 std::cout << "PASS\n";
190 int main(int, char**) {
191 std::cout << "We don't support stl_logging for this compiler.\n"
192 << "(we need compiler support of 'using ::operator<<' "
193 << "for this feature.)\n";
197 #endif // HAVE_USING_OPERATOR