MCPcopy Create free account
hub / github.com/ceph/ceph / TEST

Function TEST

src/test/bufferlist.cc:56–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54using ceph::buffer_instrumentation::instrumented_bptr;
55
56TEST(Buffer, constructors) {
57 unsigned len = 17;
58 //
59 // buffer::create
60 //
61 {
62 bufferptr ptr(buffer::create(len));
63 EXPECT_EQ(len, ptr.length());
64 }
65 //
66 // buffer::claim_char
67 //
68 {
69 char* str = new char[len];
70 ::memset(str, 'X', len);
71 bufferptr ptr(buffer::claim_char(len, str));
72 EXPECT_EQ(len, ptr.length());
73 EXPECT_EQ(str, ptr.c_str());
74 EXPECT_EQ(0, ::memcmp(str, ptr.c_str(), len));
75 delete [] str;
76 }
77 //
78 // buffer::create_static
79 //
80 {
81 char* str = new char[len];
82 bufferptr ptr(buffer::create_static(len, str));
83 EXPECT_EQ(len, ptr.length());
84 EXPECT_EQ(str, ptr.c_str());
85 delete [] str;
86 }
87 //
88 // buffer::create_malloc
89 //
90 {
91 bufferptr ptr(buffer::create_malloc(len));
92 EXPECT_EQ(len, ptr.length());
93 // this doesn't throw on my x86_64 wheezy box --sage
94 //EXPECT_THROW(buffer::create_malloc((unsigned)ULLONG_MAX), buffer::bad_alloc);
95 }
96 //
97 // buffer::claim_malloc
98 //
99 {
100 char* str = (char*)malloc(len);
101 ::memset(str, 'X', len);
102 bufferptr ptr(buffer::claim_malloc(len, str));
103 EXPECT_EQ(len, ptr.length());
104 EXPECT_EQ(str, ptr.c_str());
105 EXPECT_EQ(0, ::memcmp(str, ptr.c_str(), len));
106 }
107 //
108 // buffer::copy
109 //
110 {
111 const std::string expected(len, 'X');
112 bufferptr ptr(buffer::copy(expected.c_str(), expected.size()));
113 EXPECT_NE(expected.c_str(), ptr.c_str());

Callers

nothing calls this directly

Calls 15

bench_buffer_allocFunction · 0.85
ceph_clock_nowFunction · 0.85
bench_bufferlist_allocFunction · 0.85
systemFunction · 0.85
getuidFunction · 0.85
dencFunction · 0.85
randomFunction · 0.85
offsetMethod · 0.80
raw_lengthMethod · 0.80
raw_nrefMethod · 0.80
set_lengthMethod · 0.80

Tested by

no test coverage detected