-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.cc
87 lines (75 loc) · 1.75 KB
/
main.cc
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
78
79
80
81
82
83
84
85
86
87
#include <iostream>
#include <cstdlib>
#include "IShape.h"
#include "Rectangle.h"
void test1() {
auto rect = std::make_shared<Rectangle>();
auto w = rect->GetWeakPtr();
assert(!w.expired()); // TRUE
}
void test2() {
auto rect_s = std::make_shared<Rectangle>();
auto rect_r = rect_s.get();
auto w = rect_r->GetWeakPtr();
assert(!w.expired()); // TRUE
}
void test3() {
auto rect = NewRectangle();
auto w = rect->GetWeakPtr();
assert(!w.expired()); // TRUE
}
void test4() {
auto rect = new Rectangle();
auto w = rect->GetWeakPtr();
// bad_weak_ptr
assert(w.expired()); // TRUE
delete rect;
}
void test5() {
auto rect = new Rectangle();
auto rect_s = std::shared_ptr<IShape>(rect);
auto w = rect->GetWeakPtr();
assert(!w.expired()); // TRUE
}
void test6() {
auto rect = new Rectangle();
std::shared_ptr<IShape> rect_s;
rect_s.reset(rect);
auto w = rect->GetWeakPtr();
assert(!w.expired()); // TRUE
}
void test7() {
auto rect = NewRectangleR();
std::shared_ptr<IShape> rect_s;
rect_s.reset(rect);
auto w = rect->GetWeakPtr();
// bad_weak_ptr
assert(w.expired()); // TRUE
}
void test8() {
auto rect = NewRectangleR();
std::shared_ptr<IShape> rect_s(rect);
auto w = rect->GetWeakPtr();
// bad_weak_ptr
assert(w.expired()); // TRUE
}
void test9() {
IShape *rect = new Rectangle();
std::shared_ptr<IShape> rect_s;
rect_s.reset(rect);
auto w = rect->GetWeakPtr();
// bad_weak_ptr
assert(w.expired()); // TRUE
}
int main(int argc, char const * argv[]) {
// test1();
// test2();
// test3();
// test4();
// test5();
// test6();
// test7();
// test8();
test9();
return EXIT_SUCCESS;
}