Replaced all std::cout with kDebug.
[tagua/yd.git] / tests / weak_set / test_weakset.cpp
blob7c11dfc204e6136e38dba44d4e788b699ec5dd8d
1 #include "weakset.h"
2 #include <boost/test/unit_test.hpp>
3 using boost::unit_test::test_suite;
5 template <typename T>
6 uint weak_set_size(weak_set<T>& w) {
7 uint c = 0;
8 for (typename weak_set<T>::iterator i = w.begin();
9 i != w.end(); ++i) {
10 ++c;
12 return c;
15 void test_insertion() {
16 boost::shared_ptr<int> n(new int(8));
17 boost::shared_ptr<int> m(new int(1));
18 weak_set<int> s;
19 s.insert(n);
20 s.insert(m);
22 BOOST_CHECK_EQUAL(2, weak_set_size(s));
25 void test_garbage_collection() {
26 #ifdef WEAK_SET_DEBUG
27 kDebug()() << "\n\ntesting garbage collection\n\n" << endl;
28 #endif // WEAK_SET_DEBUG
30 weak_set<int> s;
32 boost::shared_ptr<int> u(new int(37));
33 s.insert(u);
36 boost::shared_ptr<int> m(new int(1));
37 s.insert(m);
40 boost::shared_ptr<int> n(new int(8));
41 s.insert(n);
43 BOOST_CHECK_EQUAL(2, weak_set_size(s));
46 void test_get() {
47 weak_set<int> s;
48 boost::shared_ptr<int> n(new int(42));
50 s.insert(n);
52 BOOST_CHECK_EQUAL(42, *s.begin());
55 void test_empty() {
56 weak_set<int> s;
59 boost::shared_ptr<int> m(new int(37));
60 s.insert(m);
63 BOOST_CHECK_EQUAL(0, weak_set_size(s));
66 test_suite*
67 init_unit_test_suite(int, char*[]) {
68 test_suite* test= BOOST_TEST_SUITE( "Weak set test suite" );
70 test->add(BOOST_TEST_CASE(&test_insertion), 0);
71 test->add(BOOST_TEST_CASE(&test_garbage_collection), 0);
72 test->add(BOOST_TEST_CASE(&test_get), 0);
73 test->add(BOOST_TEST_CASE(&test_empty), 0);
75 return test;