1 // Copyright 2003 Google, Inc.
2 // All Rights Reserved.
6 #ifdef HAVE_USING_OPERATOR
8 #include "glog/stl_logging.h"
17 # include <ext/hash_map>
18 # include <ext/hash_set>
21 #include "glog/logging.h"
22 #include "googletest.h"
26 using namespace __gnu_cxx;
30 size_t operator()(int x) const { return x; }
33 void TestSTLLogging() {
41 ostrstream ss(ss_buf, sizeof(ss_buf));
42 // Just ostrstream s1; leaks heap.
44 CHECK_STREQ(ss.str(), "10 20 30");
45 vector<int> copied_v(v);
46 CHECK_EQ(v, copied_v); // This must compile.
50 // Test a sorted pair associative container.
56 ostrstream ss(ss_buf, sizeof(ss_buf));
58 CHECK_STREQ(ss.str(), "(10, ten) (20, twenty) (30, thirty)");
59 map< int, string > copied_m(m);
60 CHECK_EQ(m, copied_m); // This must compile.
65 // Test a hashed simple associative container.
71 ostrstream ss(ss_buf, sizeof(ss_buf));
73 CHECK_STREQ(ss.str(), "10 20 30");
74 hash_set<int> copied_hs(hs);
75 CHECK_EQ(hs, copied_hs); // This must compile.
81 // Test a hashed pair associative container.
82 hash_map<int, string> hm;
87 ostrstream ss(ss_buf, sizeof(ss_buf));
89 CHECK_STREQ(ss.str(), "(10, ten) (20, twenty) (30, thirty)");
90 hash_map<int, string> copied_hm(hm);
91 CHECK_EQ(hm, copied_hm); // this must compile
96 // Test a long sequence.
99 for (int i = 0; i < 100; i++) {
101 if (i > 0) expected += ' ';
103 sprintf(buf, "%d", i);
109 ostrstream ss(ss_buf, sizeof(ss_buf));
111 CHECK_STREQ(ss.str(), expected.c_str());
115 // Test a sorted pair associative container.
116 // Use a non-default comparison functor.
117 map< int, string, greater<int> > m;
122 ostrstream ss(ss_buf, sizeof(ss_buf));
124 CHECK_STREQ(ss.str(), "(30, thirty) (20, twenty) (10, ten)");
125 map< int, string, greater<int> > copied_m(m);
126 CHECK_EQ(m, copied_m); // This must compile.
131 // Test a hashed simple associative container.
132 // Use a user defined hash function.
133 hash_set<int, user_hash> hs;
138 ostrstream ss(ss_buf, sizeof(ss_buf));
140 CHECK_STREQ(ss.str(), "10 20 30");
141 hash_set<int, user_hash> copied_hs(hs);
142 CHECK_EQ(hs, copied_hs); // This must compile.
147 int main(int argc, char** argv) {
149 std::cout << "PASS\n";
157 int main(int argc, char** argv) {
158 std::cout << "We don't support stl_logging for this compiler.\n"
159 << "(we need compiler support of 'using ::operator<<' "
160 << "for this feature.)\n";
164 #endif // HAVE_USING_OPERATOR