Add a PromotionManager.
[tagua/yd.git] / tests / test_weakset.cpp
blobcc43d11398ce8bc74f8aa903a90262f17ef14061
1 //#define WEAK_SET_DEBUG
2 #include "../src/weakset.h"
3 #include <boost/test/unit_test.hpp>
4 using boost::unit_test::test_suite;
6 template <typename T>
7 uint weak_set_size(weak_set<T>& w) {
8 uint c = 0;
9 for (typename weak_set<T>::iterator i = w.begin();
10 i != w.end(); ++i) {
11 ++c;
13 return c;
16 void test_insertion() {
17 boost::shared_ptr<int> n(new int(8));
18 boost::shared_ptr<int> m(new int(1));
19 weak_set<int> s;
20 s.insert(n);
21 s.insert(m);
23 BOOST_CHECK_EQUAL(2, weak_set_size(s));
26 void test_garbage_collection() {
27 #ifdef WEAK_SET_DEBUG
28 kDebug()() << "\n\ntesting garbage collection\n\n" << endl;
29 #endif // WEAK_SET_DEBUG
31 weak_set<int> s;
33 boost::shared_ptr<int> u(new int(37));
34 s.insert(u);
37 boost::shared_ptr<int> m(new int(1));
38 s.insert(m);
41 boost::shared_ptr<int> n(new int(8));
42 s.insert(n);
44 BOOST_CHECK_EQUAL(2, weak_set_size(s));
47 void test_get() {
48 weak_set<int> s;
49 boost::shared_ptr<int> n(new int(42));
51 s.insert(n);
53 BOOST_CHECK_EQUAL(42, *s.begin());
56 test_suite*
57 init_unit_test_suite(int, char*[]) {
58 test_suite* test= BOOST_TEST_SUITE( "Weak set test suite" );
60 test->add(BOOST_TEST_CASE(&test_insertion), 0);
61 test->add(BOOST_TEST_CASE(&test_garbage_collection), 0);
62 test->add(BOOST_TEST_CASE(&test_get), 0);
64 return test;