MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / TEST

Function TEST

libraries/AP_Common/tests/test_expandingstring_failure.cpp:70–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68}
69
70TEST(ExpandingString, Tests)
71{
72 // Test print_vprintf failure.
73 ExpandingString *test_string = NEW_NOTHROW ExpandingString();
74 test_string->printf("Test\n");
75 EXPECT_STREQ("", test_string->get_string());
76 EXPECT_STREQ("", test_string->get_writeable_string());
77 EXPECT_EQ(0u, test_string->get_length());
78 EXPECT_FALSE(test_string->has_failed_allocation());
79 // test failure on second printf expand()
80 test_string = NEW_NOTHROW ExpandingString();
81 test_string->printf("Test\n");
82 EXPECT_STREQ("", test_string->get_string());
83 EXPECT_STREQ("", test_string->get_writeable_string());
84 EXPECT_EQ(0u, test_string->get_length());
85 EXPECT_TRUE(test_string->has_failed_allocation());
86 // Test realloc failure
87 test_string = NEW_NOTHROW ExpandingString();
88 test_string->printf("Test\n");
89 EXPECT_STREQ(nullptr, test_string->get_string());
90 EXPECT_STREQ(nullptr, test_string->get_writeable_string());
91 EXPECT_EQ(0u, test_string->get_length());
92 EXPECT_TRUE(test_string->has_failed_allocation());
93 // test append failure
94 EXPECT_FALSE(test_string->append("Test2\n", 6));
95 // test failure on first printf realloc
96 test_string->printf("Test\n");
97 EXPECT_STREQ(nullptr, test_string->get_string());
98 EXPECT_STREQ(nullptr, test_string->get_writeable_string());
99 EXPECT_EQ(0u, test_string->get_length());
100 EXPECT_TRUE(test_string->has_failed_allocation());
101 // test failure on append realloc
102 test_string = NEW_NOTHROW ExpandingString();
103 EXPECT_FALSE(test_string->append("Test2\n", 6));
104 EXPECT_TRUE(test_string->has_failed_allocation());
105 EXPECT_STREQ(nullptr, test_string->get_string());
106 EXPECT_EQ(0u, test_string->get_length());
107
108 test_string->~ExpandingString();
109 EXPECT_STRNE("Test\n", test_string->get_string());
110}
111
112TEST(ExpandingString, TestsFailure)
113{

Callers

nothing calls this directly

Calls 7

get_writeable_stringMethod · 0.80
get_lengthMethod · 0.80
has_failed_allocationMethod · 0.80
~ExpandingStringMethod · 0.80
printfMethod · 0.45
get_stringMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected