| 68 | } |
| 69 | |
| 70 | TEST(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 | |
| 112 | TEST(ExpandingString, TestsFailure) |
| 113 | { |
nothing calls this directly
no test coverage detected