MCPcopy Create free account
hub / github.com/bytedance/sonic-cpp / TEST

Function TEST

tests/memcmp_test.cpp:50–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48}
49
50TEST(InlinedMemcmp, Basic) {
51 EXPECT_EQ(0, InlinedMemcmp("", "", 0));
52 EXPECT_EQ(0, InlinedMemcmp("123", "1", 0));
53 EXPECT_EQ(0, InlinedMemcmp("123", "1", 1));
54 EXPECT_EQ(-1, InlinedMemcmp("12345678901234567890123456789012345",
55 "22345678901234567890123456789012345", 35));
56 for (int i = 0; i < 1024; ++i) {
57 std::string str1 = random_string(i);
58 std::string str2 = random_string(i);
59 EXPECT_EQ(str1.size(), str2.size());
60 EXPECT_TRUE(
61 is_correct(std::memcmp(str1.data(), str2.data(), str1.size()),
62 InlinedMemcmp(str1.data(), str2.data(), str1.size())))
63 << "str1 is: " << str1 << std::endl
64 << "str2 is: " << str2 << std::endl
65 << "std::memcmp is: "
66 << std::memcmp(str1.data(), str2.data(), str1.size()) << std::endl
67 << "InlinedMemcmp is: "
68 << InlinedMemcmp(str1.data(), str2.data(), str1.size()) << std::endl;
69 }
70
71 for (int i = 1; i <= 1024; ++i) {
72 std::string str = random_string(i);
73 for (int j = 0; j < i; ++j) {
74 std::string str1 = str;
75 std::string str2 = str;
76 EXPECT_EQ(0, InlinedMemcmp(str1.data(), str2.data(), str1.size()));
77 str1[j] = '1';
78 str2[j] = '2';
79 EXPECT_TRUE(InlinedMemcmp(str1.data(), str2.data(), str1.size()) < 0);
80 str1[j] = '2';
81 str2[j] = '1';
82 EXPECT_TRUE(InlinedMemcmp(str1.data(), str2.data(), str1.size()) > 0);
83 }
84 }
85}
86
87TEST(InlinedMemcmp, CrossPage) {
88 for (int i = 1; i <= 1024; ++i) {

Callers

nothing calls this directly

Calls 5

random_stringFunction · 0.85
is_correctFunction · 0.85
success_helperFunction · 0.85
failed_helperFunction · 0.85
InlinedMemcmpFunction · 0.50

Tested by

no test coverage detected