test: file: Add file creation test
Add a test to verify file creation with File::open(). The test is expected to fail as the File::open() implementation is not correct. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
parent
7e1c153c22
commit
aca22bc73a
1 changed files with 26 additions and 2 deletions
|
@ -31,6 +31,7 @@ protected:
|
||||||
return TestFail;
|
return TestFail;
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
unlink(fileName_.c_str());
|
||||||
|
|
||||||
return TestPass;
|
return TestPass;
|
||||||
}
|
}
|
||||||
|
@ -191,14 +192,37 @@ protected:
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
|
/* Test file creation. */
|
||||||
|
file.setFileName(fileName_);
|
||||||
|
|
||||||
|
if (file.exists()) {
|
||||||
|
cerr << "Temporary file already exists" << endl;
|
||||||
|
return TestFail;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file.open(File::ReadOnly)) {
|
||||||
|
cerr << "Read-only open succeeded on nonexistent file" << endl;
|
||||||
|
return TestFail;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file.open(File::WriteOnly)) {
|
||||||
|
cerr << "Write-only open failed on nonexistent file" << endl;
|
||||||
|
return TestFail;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file.exists()) {
|
||||||
|
cerr << "Write-only open failed to create file" << endl;
|
||||||
|
return TestFail;
|
||||||
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
|
||||||
/* Test read and write. */
|
/* Test read and write. */
|
||||||
std::array<uint8_t, 256> buffer = { 0 };
|
std::array<uint8_t, 256> buffer = { 0 };
|
||||||
|
|
||||||
strncpy(reinterpret_cast<char *>(buffer.data()), "libcamera",
|
strncpy(reinterpret_cast<char *>(buffer.data()), "libcamera",
|
||||||
buffer.size());
|
buffer.size());
|
||||||
|
|
||||||
file.setFileName(fileName_);
|
|
||||||
|
|
||||||
if (file.read(buffer) >= 0) {
|
if (file.read(buffer) >= 0) {
|
||||||
cerr << "Read succeeded on closed file" << endl;
|
cerr << "Read succeeded on closed file" << endl;
|
||||||
return TestFail;
|
return TestFail;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue