Skip to content

Commit

Permalink
Update file_size function to accept std::wstring and adjust related t…
Browse files Browse the repository at this point in the history
…ests
  • Loading branch information
barnasm1 committed Jan 29, 2025
1 parent 07f5a1b commit 3c90e81
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/common/util/include/openvino/util/file_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ inline bool file_exists(const char* path) {
* @param[in] path The file name
* @return file size
*/
inline int64_t file_size(const wchar_t* path) {
return ov::util::file_size(std::wstring(path));
inline int64_t file_size(const std::wstring path) {
return ov::util::file_size(ov::util::Path(path));
}

/**
Expand Down
17 changes: 8 additions & 9 deletions src/core/tests/file_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,8 @@ class FileUtilTest : public ::testing::Test {

TEST_F(FileUtilTest, FileSizeNonExistentFileTest) {
EXPECT_EQ(ov::util::file_size("non_existent_file.txt"s), -1);
EXPECT_EQ(ov::util::file_size(L"non_existent_file.txt"), -1);
EXPECT_EQ(ov::util::file_size(ov::util::Path("non_existent_file.txt")), -1);
EXPECT_EQ(ov::util::file_size(ov::util::make_path(L"non_existent_file.txt")), -1);
}

TEST_F(FileUtilTest, EmptyFileSizeTest) {
Expand All @@ -599,30 +599,30 @@ TEST_F(FileUtilTest, EmptyFileSizeTest) {
EXPECT_EQ(ov::util::file_size("test_file_0.txt"s), 0);
EXPECT_EQ(ov::util::file_size(u"test_file_0.txt"), 0);
EXPECT_EQ(ov::util::file_size(U"test_file_0.txt"), 0);
EXPECT_EQ(ov::util::file_size(L"test_file_0.txt"), 0);
EXPECT_EQ(ov::util::file_size(std::wstring(L"test_file_0.txt")), 0);
EXPECT_EQ(ov::util::file_size(ov::util::Path("test_file_0.txt")), 0);
EXPECT_EQ(ov::util::file_size(ov::util::Path(u8"test_file_0.txt")), 0);
EXPECT_EQ(ov::util::file_size(ov::util::Path(u"test_file_0.txt")), 0);
EXPECT_EQ(ov::util::file_size(ov::util::Path(U"test_file_0.txt")), 0);
EXPECT_EQ(ov::util::file_size(ov::util::Path(L"test_file_0.txt")), 0);
EXPECT_EQ(ov::util::file_size(ov::util::make_path(L"test_file_0.txt")), 0);
}

TEST_F(FileUtilTest, FileSizeTest) {
EXPECT_EQ(ov::util::file_size("test_file_21.txt"s), 21);
EXPECT_EQ(ov::util::file_size(L"test_file_21.txt"), 21);
EXPECT_EQ(ov::util::file_size(ov::util::make_path(L"test_file_21.txt")), 21);
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::make_path(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);
EXPECT_EQ(ov::util::file_size(ov::util::make_path(L"test_file_21x1000.txt")), 21 * 1000);
EXPECT_EQ(ov::util::file_size(ov::util::Path("test_file_21x1000.txt")), 21 * 1000);
}

Expand All @@ -634,7 +634,6 @@ TEST_F(FileUtilTest, u8FileSizeTest) {
EXPECT_EQ(ov::util::file_size("这是_u8_.txt"s), 21);
EXPECT_EQ(ov::util::file_size(u"这是_u8_.txt"), 21);
EXPECT_EQ(ov::util::file_size(U"这是_u8_.txt"), 21);
EXPECT_EQ(ov::util::file_size(L"这是_u8_.txt"), 21);
EXPECT_EQ(ov::util::file_size(std::wstring(L"这是_u8_.txt")), 21);
EXPECT_EQ(ov::util::file_size(ov::util::Path("这是_u8_.txt")), 21);
EXPECT_EQ(ov::util::file_size(ov::util::Path(u8"这是_u8_.txt")), 21);
Expand All @@ -646,20 +645,20 @@ TEST_F(FileUtilTest, u8FileSizeTest) {

TEST_F(FileUtilTest, u16FileSizeTest) {
EXPECT_EQ(ov::util::file_size("这是_u16_.txt"s), 21);
EXPECT_EQ(ov::util::file_size(L"这是_u16_.txt"), 21);
EXPECT_EQ(ov::util::file_size(ov::util::Path("这是_u16_.txt")), 21);
EXPECT_EQ(ov::util::file_size(ov::util::make_path(L"这是_u16_.txt")), 21);
}

TEST_F(FileUtilTest, u32FileSizeTest) {
EXPECT_EQ(ov::util::file_size("这是_u32_.txt"s), 21);
EXPECT_EQ(ov::util::file_size(L"这是_u32_.txt"), 21);
EXPECT_EQ(ov::util::file_size(ov::util::Path("这是_u32_.txt")), 21);
EXPECT_EQ(ov::util::file_size(ov::util::make_path(L"这是_u32_.txt")), 21);
}

TEST_F(FileUtilTest, wstringFileSizeTest) {
EXPECT_EQ(ov::util::file_size("这是_wstring_.txt"s), 21);
EXPECT_EQ(ov::util::file_size(L"这是_wstring_.txt"), 21);
EXPECT_EQ(ov::util::file_size(ov::util::Path("这是_wstring_.txt")), 21);
EXPECT_EQ(ov::util::file_size(ov::util::make_path(L"这是_wstring_.txt")), 21);
}
#endif

Expand Down

0 comments on commit 3c90e81

Please sign in to comment.