1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#include "weakset.h"
#include <boost/test/unit_test.hpp>
using boost::unit_test::test_suite;
template <typename T>
uint weak_set_size(weak_set<T>& w) {
uint c = 0;
for (typename weak_set<T>::iterator i = w.begin();
i != w.end(); ++i) {
++c;
}
return c;
}
void test_insertion() {
boost::shared_ptr<int> n(new int(8));
boost::shared_ptr<int> m(new int(1));
weak_set<int> s;
s.insert(n);
s.insert(m);
BOOST_CHECK_EQUAL(2, weak_set_size(s));
}
void test_garbage_collection() {
#ifdef WEAK_SET_DEBUG
kDebug()() << "\n\ntesting garbage collection\n\n" << endl;
#endif // WEAK_SET_DEBUG
weak_set<int> s;
boost::shared_ptr<int> u(new int(37));
s.insert(u);
{
boost::shared_ptr<int> m(new int(1));
s.insert(m);
}
boost::shared_ptr<int> n(new int(8));
s.insert(n);
BOOST_CHECK_EQUAL(2, weak_set_size(s));
}
void test_get() {
weak_set<int> s;
boost::shared_ptr<int> n(new int(42));
s.insert(n);
BOOST_CHECK_EQUAL(42, *s.begin());
}
void test_empty() {
weak_set<int> s;
{
boost::shared_ptr<int> m(new int(37));
s.insert(m);
}
BOOST_CHECK_EQUAL(0, weak_set_size(s));
}
test_suite*
init_unit_test_suite(int, char*[]) {
test_suite* test= BOOST_TEST_SUITE( "Weak set test suite" );
test->add(BOOST_TEST_CASE(&test_insertion), 0);
test->add(BOOST_TEST_CASE(&test_garbage_collection), 0);
test->add(BOOST_TEST_CASE(&test_get), 0);
test->add(BOOST_TEST_CASE(&test_empty), 0);
return test;
}
|