MCPcopy Create free account
hub / github.com/apache/brpc / TEST

Function TEST

test/scoped_generic_unittest.cc:31–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29} // namespace
30
31TEST(ScopedGenericTest, ScopedGeneric) {
32 std::vector<int> values_freed;
33 IntTraits traits(&values_freed);
34
35 // Invalid case, delete should not be called.
36 {
37 ScopedInt a(IntTraits::InvalidValue(), traits);
38 }
39 EXPECT_TRUE(values_freed.empty());
40
41 // Simple deleting case.
42 static const int kFirst = 0;
43 {
44 ScopedInt a(kFirst, traits);
45 }
46 ASSERT_EQ(1u, values_freed.size());
47 ASSERT_EQ(kFirst, values_freed[0]);
48 values_freed.clear();
49
50 // Release should return the right value and leave the object empty.
51 {
52 ScopedInt a(kFirst, traits);
53 EXPECT_EQ(kFirst, a.release());
54
55 ScopedInt b(IntTraits::InvalidValue(), traits);
56 EXPECT_EQ(IntTraits::InvalidValue(), b.release());
57 }
58 ASSERT_TRUE(values_freed.empty());
59
60 // Reset should free the old value, then the new one should go away when
61 // it goes out of scope.
62 static const int kSecond = 1;
63 {
64 ScopedInt b(kFirst, traits);
65 b.reset(kSecond);
66 ASSERT_EQ(1u, values_freed.size());
67 ASSERT_EQ(kFirst, values_freed[0]);
68 }
69 ASSERT_EQ(2u, values_freed.size());
70 ASSERT_EQ(kSecond, values_freed[1]);
71 values_freed.clear();
72
73 // Swap.
74 {
75 ScopedInt a(kFirst, traits);
76 ScopedInt b(kSecond, traits);
77 a.swap(b);
78 EXPECT_TRUE(values_freed.empty()); // Nothing should be freed.
79 EXPECT_EQ(kSecond, a.get());
80 EXPECT_EQ(kFirst, b.get());
81 }
82 // Values should be deleted in the opposite order.
83 ASSERT_EQ(2u, values_freed.size());
84 EXPECT_EQ(kFirst, values_freed[0]);
85 EXPECT_EQ(kSecond, values_freed[1]);
86 values_freed.clear();
87
88 // Pass.

Callers

nothing calls this directly

Calls 9

InvalidValueFunction · 0.85
emptyMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45
releaseMethod · 0.45
resetMethod · 0.45
swapMethod · 0.45
getMethod · 0.45
is_validMethod · 0.45

Tested by

no test coverage detected