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
35 // C++0x isn't enabled by default.
36 // # define GLOG_STL_LOGGING_FOR_UNORDERED
37 # define GLOG_STL_LOGGING_FOR_TR1_UNORDERED
38 # define GLOG_STL_LOGGING_FOR_EXT_HASH
39 # define GLOG_STL_LOGGING_FOR_EXT_SLIST
42 #include "glog/stl_logging.h"
50 #include "glog/logging.h"
51 #include "googletest.h"
54 #ifdef GLOG_STL_LOGGING_FOR_EXT_HASH
55 using namespace __gnu_cxx;
59 size_t operator()(int x) const { return x; }
62 void TestSTLLogging() {
71 EXPECT_EQ(ss.str(), "10 20 30");
72 vector<int> copied_v(v);
73 CHECK_EQ(v, copied_v); // This must compile.
77 // Test a sorted pair associative container.
84 EXPECT_EQ(ss.str(), "(10, ten) (20, twenty) (30, thirty)");
85 map< int, string > copied_m(m);
86 CHECK_EQ(m, copied_m); // This must compile.
89 #ifdef GLOG_STL_LOGGING_FOR_EXT_HASH
91 // Test a hashed simple associative container.
98 EXPECT_EQ(ss.str(), "10 20 30");
99 hash_set<int> copied_hs(hs);
100 CHECK_EQ(hs, copied_hs); // This must compile.
104 #ifdef GLOG_STL_LOGGING_FOR_EXT_HASH
106 // Test a hashed pair associative container.
107 hash_map<int, string> hm;
113 EXPECT_EQ(ss.str(), "(10, ten) (20, twenty) (30, thirty)");
114 hash_map<int, string> copied_hm(hm);
115 CHECK_EQ(hm, copied_hm); // this must compile
120 // Test a long sequence.
123 for (int i = 0; i < 100; i++) {
125 if (i > 0) expected += ' ';
127 sprintf(buf, "%d", i);
134 CHECK_EQ(ss.str(), expected.c_str());
138 // Test a sorted pair associative container.
139 // Use a non-default comparison functor.
140 map< int, string, greater<int> > m;
146 EXPECT_EQ(ss.str(), "(30, thirty) (20, twenty) (10, ten)");
147 map< int, string, greater<int> > copied_m(m);
148 CHECK_EQ(m, copied_m); // This must compile.
151 #ifdef GLOG_STL_LOGGING_FOR_EXT_HASH
153 // Test a hashed simple associative container.
154 // Use a user defined hash function.
155 hash_set<int, user_hash> hs;
161 EXPECT_EQ(ss.str(), "10 20 30");
162 hash_set<int, user_hash> copied_hs(hs);
163 CHECK_EQ(hs, copied_hs); // This must compile.
168 int main(int, char**) {
170 std::cout << "PASS\n";
178 int main(int, char**) {
179 std::cout << "We don't support stl_logging for this compiler.\n"
180 << "(we need compiler support of 'using ::operator<<' "
181 << "for this feature.)\n";
185 #endif // HAVE_USING_OPERATOR