MCPcopy Create free account
hub / github.com/davisking/dlib / smart_pointers_test

Function smart_pointers_test

dlib/test/smart_pointers.cpp:71–426  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69 typedef void (*Db)(base*);
70
71 void smart_pointers_test (
72 )
73 /*!
74 ensures
75 - runs tests on the smart pointers for compliance with the specs
76 !*/
77 {
78 counter = 0;
79 deleter_called = 0;
80
81 {
82 DLIB_TEST_MSG(counter == 0,counter);
83 scoped_ptr<base> p1(new derived);
84 scoped_ptr<derived> p2(new derived);
85 scoped_ptr<derived> p3;
86 DLIB_TEST_MSG(counter == 2,counter);
87 DLIB_TEST(!p3);
88
89 p1->num = 1;
90 p2->num = 2;
91 DLIB_TEST(p1->num == 1);
92 DLIB_TEST(p2->num == 2);
93
94 (*p1).num = 3;
95 (*p2).num = 4;
96 DLIB_TEST(p1->num == 3);
97 DLIB_TEST(p2->num == 4);
98
99 DLIB_TEST_MSG(counter == 2,counter);
100
101 DLIB_TEST(p1);
102 DLIB_TEST(p2);
103
104 DLIB_TEST_MSG(counter == 2,counter);
105 p1.reset();
106 DLIB_TEST_MSG(counter == 1,counter);
107 DLIB_TEST(!p1);
108 DLIB_TEST(p2);
109 p1.reset(new derived);
110 DLIB_TEST_MSG(counter == 2,counter);
111 DLIB_TEST(p1);
112
113
114 DLIB_TEST_MSG(counter == 2,counter);
115 p2.reset();
116 DLIB_TEST_MSG(counter == 1,counter);
117 DLIB_TEST(!p2);
118 derived* d = new derived;
119 p2.reset(d);
120 DLIB_TEST(p2.get() == d);
121 DLIB_TEST_MSG(counter == 2,counter);
122 DLIB_TEST(p2);
123 DLIB_TEST(!p3);
124 p2->num = 9;
125 swap(p2,p3);
126 DLIB_TEST(!p2);
127 DLIB_TEST(p3);
128 DLIB_TEST(p3->num == 9);

Callers 1

perform_testMethod · 0.85

Calls 8

expiredMethod · 0.80
swapFunction · 0.70
resetMethod · 0.45
getMethod · 0.45
swapMethod · 0.45
uniqueMethod · 0.45
use_countMethod · 0.45
lockMethod · 0.45

Tested by

no test coverage detected