| 58 | } |
| 59 | |
| 60 | void testTextResource(Module* module) |
| 61 | { |
| 62 | ModuleResource res = module->GetResource("foo.txt"); |
| 63 | #ifdef US_PLATFORM_WINDOWS |
| 64 | checkResourceInfo(res, "/", "foo", "foo", "txt", "txt", 16, false); |
| 65 | const std::streampos ssize(13); |
| 66 | const std::string fileData = "foo and\nbar\n\n"; |
| 67 | #else |
| 68 | checkResourceInfo(res, "/", "foo", "foo", "txt", "txt", 13, false); |
| 69 | const std::streampos ssize(12); |
| 70 | const std::string fileData = "foo and\nbar\n"; |
| 71 | #endif |
| 72 | |
| 73 | ModuleResourceStream rs(res); |
| 74 | |
| 75 | rs.seekg(0, std::ios::end); |
| 76 | US_TEST_CONDITION(rs.tellg() == ssize, "Stream content length"); |
| 77 | rs.seekg(0, std::ios::beg); |
| 78 | |
| 79 | std::string content; |
| 80 | content.reserve(res.GetSize()); |
| 81 | char buffer[1024]; |
| 82 | while (rs.read(buffer, sizeof(buffer))) |
| 83 | { |
| 84 | content.append(buffer, sizeof(buffer)); |
| 85 | } |
| 86 | content.append(buffer, static_cast<std::size_t>(rs.gcount())); |
| 87 | |
| 88 | US_TEST_CONDITION(rs.eof(), "EOF check"); |
| 89 | US_TEST_CONDITION(content == fileData, "Resource content"); |
| 90 | |
| 91 | rs.clear(); |
| 92 | rs.seekg(0); |
| 93 | |
| 94 | US_TEST_CONDITION_REQUIRED(rs.tellg() == std::streampos(0), "Move to start") |
| 95 | US_TEST_CONDITION_REQUIRED(rs.good(), "Start re-reading"); |
| 96 | |
| 97 | std::vector<std::string> lines; |
| 98 | std::string line; |
| 99 | while (std::getline(rs, line)) |
| 100 | { |
| 101 | lines.push_back(line); |
| 102 | } |
| 103 | US_TEST_CONDITION_REQUIRED(lines.size() > 1, "Number of lines") |
| 104 | US_TEST_CONDITION(lines[0] == "foo and", "Check first line") |
| 105 | US_TEST_CONDITION(lines[1] == "bar", "Check second line") |
| 106 | } |
| 107 | |
| 108 | void testTextResourceAsBinary(Module* module) |
| 109 | { |
no test coverage detected