| 1138 | } |
| 1139 | |
| 1140 | void GenericFileSystemTest::TestOpenInputFile(FileSystem* fs) { |
| 1141 | ASSERT_OK(fs->CreateDir("AB")); |
| 1142 | CreateFile(fs, "AB/abc", "some other data"); |
| 1143 | |
| 1144 | std::shared_ptr<io::RandomAccessFile> file; |
| 1145 | std::shared_ptr<Buffer> buffer; |
| 1146 | ASSERT_OK_AND_ASSIGN(file, fs->OpenInputFile("AB/abc")); |
| 1147 | ASSERT_OK_AND_EQ(0, file->Tell()); |
| 1148 | ASSERT_OK(file->Seek(10)); |
| 1149 | ASSERT_OK_AND_EQ(10, file->Tell()); |
| 1150 | ASSERT_OK_AND_ASSIGN(buffer, file->Read(6 /*Remaining + 1*/)); |
| 1151 | AssertBufferEqual(*buffer, " data"); |
| 1152 | ASSERT_OK_AND_ASSIGN(buffer, file->Read(1)); |
| 1153 | AssertBufferEqual(*buffer, ""); |
| 1154 | ASSERT_OK_AND_EQ(15, file->Tell()); |
| 1155 | ASSERT_OK(file->Seek(5)); |
| 1156 | ASSERT_OK_AND_EQ(5, file->Tell()); |
| 1157 | ASSERT_OK_AND_ASSIGN(buffer, file->Read(6)); |
| 1158 | AssertBufferEqual(*buffer, "other "); |
| 1159 | // Should return the same slice independent of the current position |
| 1160 | ASSERT_OK_AND_ASSIGN(buffer, file->ReadAt(2, 3)); |
| 1161 | AssertBufferEqual(*buffer, "me "); |
| 1162 | ASSERT_OK_AND_EQ(15, file->GetSize()); |
| 1163 | ASSERT_OK(file->Close()); |
| 1164 | ASSERT_RAISES(Invalid, file->ReadAt(1, 1)); // Stream is closed |
| 1165 | |
| 1166 | // Trailing slash rejected |
| 1167 | ASSERT_RAISES(IOError, fs->OpenInputFile("AB/abc/")); |
| 1168 | |
| 1169 | // File does not exist |
| 1170 | AssertRaisesWithErrno(ENOENT, fs->OpenInputFile("AB/def")); |
| 1171 | AssertRaisesWithErrno(ENOENT, fs->OpenInputFile("def")); |
| 1172 | |
| 1173 | // Cannot open directory |
| 1174 | if (!allow_read_dir_as_file()) { |
| 1175 | ASSERT_RAISES(IOError, fs->OpenInputFile("AB")); |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | void GenericFileSystemTest::TestOpenInputFileAsync(FileSystem* fs) { |
| 1180 | ASSERT_OK(fs->CreateDir("AB")); |
nothing calls this directly
no test coverage detected