File: weakset_test.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 (62 lines) | stat: -rw-r--r-- 1,132 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
#include "weakset_test.h"
#include "weakset.h"

CPPUNIT_TEST_SUITE_REGISTRATION(WeaksetTest);

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 WeaksetTest::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);
  
  CPPUNIT_ASSERT_EQUAL(2U, weak_set_size(s));
}

void WeaksetTest::test_garbage_collection() {
  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);
  
  CPPUNIT_ASSERT_EQUAL(2U, weak_set_size(s));
}

void WeaksetTest::test_get() {
  weak_set<int> s;
  boost::shared_ptr<int> n(new int(42));
 
  s.insert(n);
  
  CPPUNIT_ASSERT_EQUAL(42, *s.begin());
}

void WeaksetTest::test_empty() {
  weak_set<int> s;
  
  {
    boost::shared_ptr<int> m(new int(37));
    s.insert(m);
  }
  
  CPPUNIT_ASSERT_EQUAL(0U, weak_set_size(s));
}