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

Function TEST_F

test/string_splitter_unittest.cpp:35–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33
34
35TEST_F(StringSplitterTest, sanity) {
36 const char* str = "hello there! man ";
37 butil::StringSplitter ss(str, ' ');
38 // "hello"
39 ASSERT_TRUE(ss != NULL);
40 ASSERT_EQ(5ul, ss.length());
41 ASSERT_EQ(ss.field(), str);
42
43 // "there!"
44 ++ss;
45 ASSERT_NE(ss, (void*)NULL);
46 ASSERT_EQ(6ul, ss.length());
47 ASSERT_EQ(ss.field(), str+6);
48
49 // "man"
50 ++ss;
51 ASSERT_TRUE(ss);
52 ASSERT_EQ(3ul, ss.length());
53 ASSERT_EQ(ss.field(), str+15);
54
55 ++ss;
56 ASSERT_FALSE(ss);
57 ASSERT_EQ(0ul, ss.length());
58 ASSERT_EQ(ss.field(), str + strlen(str));
59
60 // consecutive separators are treated as zero-length field inside
61 butil::StringSplitter ss2(str, ' ', butil::ALLOW_EMPTY_FIELD);
62
63 // "hello"
64 ASSERT_TRUE(ss2);
65 ASSERT_EQ(5ul, ss2.length());
66 ASSERT_FALSE(strncmp(ss2.field(), "hello", ss2.length()));
67
68 // "there!"
69 ++ss2;
70 ASSERT_TRUE(ss2);
71 ASSERT_EQ(6ul, ss2.length());
72 ASSERT_FALSE(strncmp(ss2.field(), "there!", ss2.length()));
73
74 // ""
75 ++ss2;
76 ASSERT_TRUE(ss2);
77 ASSERT_EQ(0ul, ss2.length());
78 ASSERT_EQ(ss2.field(), str+13);
79
80 // ""
81 ++ss2;
82 ASSERT_TRUE(ss2);
83 ASSERT_EQ(0ul, ss2.length());
84 ASSERT_EQ(ss2.field(), str+14);
85
86 // "man"
87 ++ss2;
88 ASSERT_TRUE(ss2);
89 ASSERT_EQ(3ul, ss2.length());
90 ASSERT_EQ(ss2.field(), str+15);
91
92 ++ss2;

Callers

nothing calls this directly

Calls 15

fieldMethod · 0.80
to_intMethod · 0.80
to_uintMethod · 0.80
to_longMethod · 0.80
to_ulongMethod · 0.80
to_longlongMethod · 0.80
to_ulonglongMethod · 0.80
to_floatMethod · 0.80
to_doubleMethod · 0.80
to_int8Method · 0.80
to_uint8Method · 0.80
lengthMethod · 0.45

Tested by

no test coverage detected