2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2024-12-12 15:55:13 +00:00
|
|
|
* Copyright (C) 2018-2024 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2019-02-27 11:39:32 +01:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/helpers/stdio.h"
|
2024-12-12 15:55:13 +00:00
|
|
|
#include "shared/test/common/helpers/mock_file_io.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
2020-04-02 17:46:26 +02:00
|
|
|
TEST(FileIO, GivenNonEmptyFileWhenCheckingIfHasSizeThenReturnTrue) {
|
2017-12-21 00:45:38 +01:00
|
|
|
std::string fileName("fileIO.bin");
|
2024-12-12 15:55:13 +00:00
|
|
|
if (virtualFileExists(fileName)) {
|
|
|
|
|
removeVirtualFile(fileName);
|
|
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2024-12-12 15:55:13 +00:00
|
|
|
ASSERT_FALSE(virtualFileExists(fileName.c_str()));
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2024-12-12 15:55:13 +00:00
|
|
|
writeDataToFile(fileName.c_str(), "TEST", 4);
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(virtualFileExists(fileName.c_str()));
|
2017-12-21 00:45:38 +01:00
|
|
|
EXPECT_TRUE(fileExistsHasSize(fileName.c_str()));
|
2024-12-12 15:55:13 +00:00
|
|
|
removeVirtualFile(fileName);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2020-04-02 17:46:26 +02:00
|
|
|
TEST(FileIO, GivenEmptyFileWhenCheckingIfHasSizeThenReturnFalse) {
|
2017-12-21 00:45:38 +01:00
|
|
|
std::string fileName("fileIO.bin");
|
2024-12-12 15:55:13 +00:00
|
|
|
if (virtualFileExists(fileName)) {
|
|
|
|
|
removeVirtualFile(fileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ASSERT_FALSE(virtualFileExists(fileName.c_str()));
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2024-12-12 15:55:13 +00:00
|
|
|
writeDataToFile(fileName.c_str(), "", 0);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2024-12-12 15:55:13 +00:00
|
|
|
EXPECT_TRUE(virtualFileExists(fileName.c_str()));
|
2017-12-21 00:45:38 +01:00
|
|
|
EXPECT_FALSE(fileExistsHasSize(fileName.c_str()));
|
2024-12-12 15:55:13 +00:00
|
|
|
removeVirtualFile(fileName);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|