| 28 | } |
| 29 | |
| 30 | void execute() override |
| 31 | { |
| 32 | const FlashString& FS_abstract = Resource::abstract_txt; |
| 33 | |
| 34 | MallocCount::setLogThreshold(0); |
| 35 | |
| 36 | TEST_CASE("MemoryDataStream::moveString") |
| 37 | { |
| 38 | FSTR::Stream src(FS_abstract); |
| 39 | MemoryDataStream dest; |
| 40 | dest.copyFrom(&src); |
| 41 | String s; |
| 42 | REQUIRE(dest.moveString(s) == true); |
| 43 | REQUIRE(FS_abstract == s); |
| 44 | } |
| 45 | |
| 46 | TEST_CASE("MemoryDataStream(String&&)") |
| 47 | { |
| 48 | // Move Stream into String |
| 49 | String s(FS_abstract); |
| 50 | MemoryDataStream stream(std::move(s)); |
| 51 | TEST_ASSERT(!s); |
| 52 | TEST_ASSERT(FS_abstract.length() == size_t(stream.available())); |
| 53 | // And back again |
| 54 | stream.moveString(s); |
| 55 | TEST_ASSERT(FS_abstract == s); |
| 56 | REQUIRE(strlen(s.c_str()) == s.length()); |
| 57 | } |
| 58 | |
| 59 | TEST_CASE("LimitedMemoryStream::moveString (1)") |
| 60 | { |
| 61 | FSTR::Stream src(FS_abstract); |
| 62 | REQUIRE(size_t(src.available()) == FS_abstract.length()); |
| 63 | LimitedMemoryStream dest(FS_abstract.length()); |
| 64 | // Operation will drop last character as this is converted to NUL |
| 65 | dest.copyFrom(&src); |
| 66 | String s; |
| 67 | REQUIRE(dest.moveString(s) == false); |
| 68 | debug_i("src length = %u, s length = %u", FS_abstract.length(), s.length()); |
| 69 | String s1(FS_abstract); |
| 70 | s1.remove(s1.length() - 1); |
| 71 | REQUIRE(s1 == s); |
| 72 | REQUIRE(strlen(s.c_str()) == s.length()); |
| 73 | } |
| 74 | |
| 75 | TEST_CASE("LimitedMemoryStream::moveString (2)") |
| 76 | { |
| 77 | FSTR::Stream src(FS_abstract); |
| 78 | REQUIRE(size_t(src.available()) == FS_abstract.length()); |
| 79 | LimitedMemoryStream dest(FS_abstract.length() + 10); |
| 80 | // Operation will drop last character as this is converted to NUL |
| 81 | dest.copyFrom(&src); |
| 82 | String s; |
| 83 | REQUIRE(dest.moveString(s) == true); |
| 84 | REQUIRE(FS_abstract == s); |
| 85 | REQUIRE(strlen(s.c_str()) == s.length()); |
| 86 | } |
| 87 |
nothing calls this directly
no test coverage detected