Skip to content

Commit

Permalink
Add test for file size calculation of raw byte files
Browse files Browse the repository at this point in the history
  • Loading branch information
barnasm1 committed Jan 29, 2025
1 parent 65cc6d5 commit bab5a77
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/core/tests/file_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,19 @@ class FileUtilTest : public ::testing::Test {
outfile << "This is a test file." << std::endl;
}
}
{
std::ofstream outfile("test_file_raw_bytes_746.txt", std::ios::binary);
std::vector<char> buffer(746, 0);
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(0, 255);

std::generate(buffer.begin(), buffer.end(), [&]() {
return static_cast<char>(dis(gen));
});

outfile.write(buffer.data(), buffer.size());
}

#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
{
Expand Down Expand Up @@ -584,6 +597,7 @@ class FileUtilTest : public ::testing::Test {
// Remove the temporary files after testing
std::filesystem::remove("test_file_0.txt");
std::filesystem::remove("test_file_21.txt");
std::filesystem::remove("test_file_raw_bytes_746.txt");
std::filesystem::remove("test_file_21x1000.txt");
#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
std::filesystem::remove(u8"这是_u8_.txt");
Expand Down Expand Up @@ -632,6 +646,12 @@ TEST_F(FileUtilTest, FileSizeTest) {
EXPECT_EQ(ov::util::file_size(ov::util::Path("test_file_21.txt")), 21);
}

TEST_F(FileUtilTest, FileSizeRawBytesTest) {
EXPECT_EQ(ov::util::file_size("test_file_raw_bytes_746.txt"s), 746);
EXPECT_EQ(ov::util::file_size(L"test_file_raw_bytes_746.txt"), 746);
EXPECT_EQ(ov::util::file_size(ov::util::Path("test_file_raw_bytes_746.txt")), 746);
}

TEST_F(FileUtilTest, LargeFileSizeTest) {
EXPECT_EQ(ov::util::file_size("test_file_21x1000.txt"s), 21 * 1000);
EXPECT_EQ(ov::util::file_size(L"test_file_21x1000.txt"), 21 * 1000);
Expand Down

0 comments on commit bab5a77

Please sign in to comment.