mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-21 09:14:47 +08:00
reducing the number of tests that have interactions with filesystem. writeDataToFile() saves filename and content in std::map. fileExistsHasSize() checks if file was previously written to virtualFileSystem loadDataFromVirtualFile() fetches data from std::map based on filename Related-To: NEO-7006 Signed-off-by: Marcel Skierkowski <marcel.skierkowski@intel.com>
44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
/*
|
|
* Copyright (C) 2018-2024 Intel Corporation
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*
|
|
*/
|
|
|
|
#include "shared/source/helpers/stdio.h"
|
|
#include "shared/test/common/helpers/mock_file_io.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include <cstdio>
|
|
|
|
TEST(FileIO, GivenNonEmptyFileWhenCheckingIfHasSizeThenReturnTrue) {
|
|
std::string fileName("fileIO.bin");
|
|
if (virtualFileExists(fileName)) {
|
|
removeVirtualFile(fileName);
|
|
}
|
|
|
|
ASSERT_FALSE(virtualFileExists(fileName.c_str()));
|
|
|
|
writeDataToFile(fileName.c_str(), "TEST", 4);
|
|
|
|
EXPECT_TRUE(virtualFileExists(fileName.c_str()));
|
|
EXPECT_TRUE(fileExistsHasSize(fileName.c_str()));
|
|
removeVirtualFile(fileName);
|
|
}
|
|
|
|
TEST(FileIO, GivenEmptyFileWhenCheckingIfHasSizeThenReturnFalse) {
|
|
std::string fileName("fileIO.bin");
|
|
if (virtualFileExists(fileName)) {
|
|
removeVirtualFile(fileName);
|
|
}
|
|
|
|
ASSERT_FALSE(virtualFileExists(fileName.c_str()));
|
|
|
|
writeDataToFile(fileName.c_str(), "", 0);
|
|
|
|
EXPECT_TRUE(virtualFileExists(fileName.c_str()));
|
|
EXPECT_FALSE(fileExistsHasSize(fileName.c_str()));
|
|
removeVirtualFile(fileName);
|
|
}
|