File: test_weakset.cpp

package info (click to toggle)
tagua 1.0~alpha2-15
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 8,028 kB
  • ctags: 7,178
  • sloc: cpp: 26,149; ansic: 13,039; makefile: 182; ruby: 87; sh: 39
file content (66 lines) | stat: -rw-r--r-- 1,341 bytes parent folder | download | duplicates (6)
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
//#define WEAK_SET_DEBUG
#include "../src/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());
}

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);

  return test;
}