From 887dd2b2cb3b1616078338391361ccd6703953c7 Mon Sep 17 00:00:00 2001 From: Michal Barnas Date: Wed, 15 Jan 2025 14:27:03 +0000 Subject: [PATCH 01/21] move wide character string conversions to separate file --- src/common/util/CMakeLists.txt | 1 + .../util/include/openvino/util/file_util.hpp | 13 ----- .../openvino/util/wstring_cast_util.hpp | 31 ++++++++++++ src/common/util/src/file_util.cpp | 42 +--------------- src/common/util/src/wstring_cast_util.cpp | 48 +++++++++++++++++++ 5 files changed, 81 insertions(+), 54 deletions(-) create mode 100644 src/common/util/include/openvino/util/wstring_cast_util.hpp create mode 100644 src/common/util/src/wstring_cast_util.cpp diff --git a/src/common/util/CMakeLists.txt b/src/common/util/CMakeLists.txt index c539913968f7ee..fa91049738a687 100644 --- a/src/common/util/CMakeLists.txt +++ b/src/common/util/CMakeLists.txt @@ -26,6 +26,7 @@ endif() set_source_files_properties( "${CMAKE_CURRENT_SOURCE_DIR}/src/file_util.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/src/wstring_cast_util.cpp" PROPERTIES COMPILE_DEFINITIONS OpenVINO_VERSION="${OpenVINO_VERSION}") source_group("src" FILES ${LIBRARY_SRC}) diff --git a/src/common/util/include/openvino/util/file_util.hpp b/src/common/util/include/openvino/util/file_util.hpp index b4db4df774be9d..b3d937a04aec8b 100644 --- a/src/common/util/include/openvino/util/file_util.hpp +++ b/src/common/util/include/openvino/util/file_util.hpp @@ -89,19 +89,6 @@ const std::string& path_to_string(const Path& path) { } #ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT -/** - * @brief Conversion from wide character string to a single-byte chain. - * @param wstr A wide-char string - * @return A multi-byte string - */ -std::string wstring_to_string(const std::wstring& wstr); -/** - * @brief Conversion from single-byte chain to wide character string. - * @param str A null-terminated string - * @return A wide-char string - */ -std::wstring string_to_wstring(const std::string& str); - /** * @brief Convert path as wide character string to a single-byte chain. * @param path Path as wide-char string. diff --git a/src/common/util/include/openvino/util/wstring_cast_util.hpp b/src/common/util/include/openvino/util/wstring_cast_util.hpp new file mode 100644 index 00000000000000..4523016543b934 --- /dev/null +++ b/src/common/util/include/openvino/util/wstring_cast_util.hpp @@ -0,0 +1,31 @@ +// Copyright (C) 2018-2024 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include + +#include "openvino/util/util.hpp" + +namespace ov { +namespace util { + +#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT +/** + * @brief Conversion from wide character string to a single-byte chain. + * @param wstr A wide-char string + * @return A multi-byte string + */ +std::string wstring_to_string(const std::wstring& wstr); +/** + * @brief Conversion from single-byte chain to wide character string. + * @param str A null-terminated string + * @return A wide-char string + */ +std::wstring string_to_wstring(const std::string& str); + +#endif + +} // namespace util +} // namespace ov diff --git a/src/common/util/src/file_util.cpp b/src/common/util/src/file_util.cpp index 9e1c0c41cea415..b3bd4940387c8a 100644 --- a/src/common/util/src/file_util.cpp +++ b/src/common/util/src/file_util.cpp @@ -37,7 +37,7 @@ # endif // Copied from linux libc sys/stat.h: # if !defined(__MINGW32__) && !defined(__MINGW64__) -# define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) +# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) # endif #else # include @@ -338,46 +338,6 @@ void ov::util::convert_path_win_style(std::string& path) { std::replace(path.begin(), path.end(), '/', '\\'); } -#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT - -# ifdef __clang__ -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wdeprecated-declarations" -# endif - -std::string ov::util::wstring_to_string(const std::wstring& wstr) { -# ifdef _WIN32 - int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL); - std::string strTo(size_needed, 0); - WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL); - return strTo; -# else - std::wstring_convert> wstring_decoder; - return wstring_decoder.to_bytes(wstr); -# endif -} - -std::wstring ov::util::string_to_wstring(const std::string& string) { - const char* str = string.c_str(); -# ifdef _WIN32 - int strSize = static_cast(std::strlen(str)); - int size_needed = MultiByteToWideChar(CP_UTF8, 0, str, strSize, NULL, 0); - std::wstring wstrTo(size_needed, 0); - MultiByteToWideChar(CP_UTF8, 0, str, strSize, &wstrTo[0], size_needed); - return wstrTo; -# else - std::wstring_convert> wstring_encoder; - std::wstring result = wstring_encoder.from_bytes(str); - return result; -# endif -} - -# ifdef __clang__ -# pragma clang diagnostic pop -# endif - -#endif // OPENVINO_ENABLE_UNICODE_PATH_SUPPORT - std::string ov::util::get_absolute_file_path(const std::string& path) { std::string absolutePath; absolutePath.resize(MAX_ABS_PATH); diff --git a/src/common/util/src/wstring_cast_util.cpp b/src/common/util/src/wstring_cast_util.cpp new file mode 100644 index 00000000000000..a907185e316d28 --- /dev/null +++ b/src/common/util/src/wstring_cast_util.cpp @@ -0,0 +1,48 @@ +// Copyright (C) 2018-2025 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/util/wstring_cast_util.hpp" + +#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT + +# include +# include + +# ifdef __clang__ +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wdeprecated-declarations" +# endif + +std::string ov::util::wstring_to_string(const std::wstring& wstr) { +# ifdef _WIN32 + int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL); + std::string strTo(size_needed, 0); + WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL); + return strTo; +# else + std::wstring_convert> wstring_decoder; + return wstring_decoder.to_bytes(wstr); +# endif +} + +std::wstring ov::util::string_to_wstring(const std::string& string) { + const char* str = string.c_str(); +# ifdef _WIN32 + int strSize = static_cast(std::strlen(str)); + int size_needed = MultiByteToWideChar(CP_UTF8, 0, str, strSize, NULL, 0); + std::wstring wstrTo(size_needed, 0); + MultiByteToWideChar(CP_UTF8, 0, str, strSize, &wstrTo[0], size_needed); + return wstrTo; +# else + std::wstring_convert> wstring_encoder; + std::wstring result = wstring_encoder.from_bytes(str); + return result; +# endif +} + +# ifdef __clang__ +# pragma clang diagnostic pop +# endif + +#endif // OPENVINO_ENABLE_UNICODE_PATH_SUPPORT From 04671c7848bf229017877194acc6afddb505e55b Mon Sep 17 00:00:00 2001 From: Michal Barnas Date: Wed, 15 Jan 2025 14:34:57 +0000 Subject: [PATCH 02/21] refactor --- .../util/include/openvino/util/cpp_version.hpp | 16 ++++++++++++++++ .../util/include/openvino/util/file_path.hpp | 17 +++++++++++++++++ .../util/include/openvino/util/file_util.hpp | 1 + src/core/tests/file_util.cpp | 12 ------------ 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/common/util/include/openvino/util/cpp_version.hpp b/src/common/util/include/openvino/util/cpp_version.hpp index c0998588027c2a..4ee65a6d5c7a4b 100644 --- a/src/common/util/include/openvino/util/cpp_version.hpp +++ b/src/common/util/include/openvino/util/cpp_version.hpp @@ -33,3 +33,19 @@ # endif # endif #endif + +#if !defined(__GNUC__) || (__GNUC__ > 12 || __GNUC__ == 12 && __GNUC_MINOR__ >= 3) +# define GCC_NOT_USED_OR_VER_AT_LEAST_12_3 +#endif + +#if !defined(__clang__) || defined(__clang__) && __clang_major__ >= 17 +# define CLANG_NOT_USED_OR_VER_AT_LEAST_17 +#endif + +#if defined(__GNUC__) && (__GNUC__ < 12 || __GNUC__ == 12 && __GNUC_MINOR__ < 3) +# define GCC_VER_LESS_THEN_12_3 +#endif + +#if defined(__clang__) && __clang_major__ < 17 +# define CLANG_VER_LESS_THEN_17 +#endif diff --git a/src/common/util/include/openvino/util/file_path.hpp b/src/common/util/include/openvino/util/file_path.hpp index 9080ea5289a51e..790e0310939470 100644 --- a/src/common/util/include/openvino/util/file_path.hpp +++ b/src/common/util/include/openvino/util/file_path.hpp @@ -7,10 +7,17 @@ #include #include "openvino/util/filesystem.hpp" +#include "openvino/util/wstring_cast_util.hpp" + namespace ov { namespace util { #if defined(OPENVINO_HAS_FILESYSTEM) +// There are known issues related with usage of std::filesystem::path unocode represenataion: +// https://jira.devtools.intel.com/browse/CVS-160477 +// * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95048 +// * https://stackoverflow.com/questions/58521857/cross-platform-way-to-handle-stdstring-stdwstring-with-stdfilesystempath +// Working compiler versions has been designated with godbolt. using Path = std::filesystem::path; #elif defined(OPENVINO_HAS_EXP_FILESYSTEM) // Known issues: @@ -30,5 +37,15 @@ using Path = std::filesystem::path; using Path = std::experimental::filesystem::path; #endif +#if defined(GCC_VER_LESS_THEN_12_3) || defined(CLANG_VER_LESS_THEN_17) +inline ov::util::Path WPath(const std::wstring& wpath) { + return {ov::util::wstring_to_string(wpath)}; +} +#else +inline ov::util::Path WPath(const std::wstring& wpath) { + return {wpath}; +} +#endif + } // namespace util } // namespace ov diff --git a/src/common/util/include/openvino/util/file_util.hpp b/src/common/util/include/openvino/util/file_util.hpp index b3d937a04aec8b..c008b4c2f356f3 100644 --- a/src/common/util/include/openvino/util/file_util.hpp +++ b/src/common/util/include/openvino/util/file_util.hpp @@ -11,6 +11,7 @@ #include #include "openvino/util/util.hpp" +#include "openvino/util/wstring_cast_util.hpp" namespace ov { namespace util { diff --git a/src/core/tests/file_util.cpp b/src/core/tests/file_util.cpp index 33d5d7f9db2896..aecd16f46213ed 100644 --- a/src/core/tests/file_util.cpp +++ b/src/core/tests/file_util.cpp @@ -262,18 +262,6 @@ TEST(file_util, path_cast) { EXPECT_TRUE(std::u16string(u"C:\\Users\\file.txt") == ov::util::Path(U"C:\\Users\\file.txt").u16string()); } -// There are known issues related with usage of std::filesystem::path unocode represenataion: -// https://jira.devtools.intel.com/browse/CVS-160477 -// * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95048 -// * https://stackoverflow.com/questions/58521857/cross-platform-way-to-handle-stdstring-stdwstring-with-stdfilesystempath -#if !defined(__GNUC__) || (__GNUC__ > 12 || __GNUC__ == 12 && __GNUC_MINOR__ >= 3) -# define GCC_NOT_USED_OR_VER_AT_LEAST_12_3 -#endif - -#if !defined(__clang__) || defined(__clang__) && __clang_major__ >= 17 -# define CLANG_NOT_USED_OR_VER_AT_LEAST_17 -#endif - TEST(file_util, path_cast_unicode) { EXPECT_EQ("~/狗/ǡ୫ԩϗ/にほ/ąę/ど/௸ඊƷ/狗1.txt", ov::util::Path("~/狗/ǡ୫ԩϗ/にほ/ąę/ど/௸ඊƷ/狗1.txt").generic_string()); EXPECT_TRUE(std::u16string(u"~/狗/ǡ୫ԩϗ/にほ/ąę/ど/௸ඊƷ/狗6.txt") == From b3345289b563a4ccc003b7aac3433e334fcd4145 Mon Sep 17 00:00:00 2001 From: Michal Barnas Date: Wed, 15 Jan 2025 14:36:22 +0000 Subject: [PATCH 03/21] refactor file size functions to use ov::util::Path and handle Android paths --- .../util/include/openvino/util/file_util.hpp | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/src/common/util/include/openvino/util/file_util.hpp b/src/common/util/include/openvino/util/file_util.hpp index c008b4c2f356f3..e3461e5a81bc21 100644 --- a/src/common/util/include/openvino/util/file_util.hpp +++ b/src/common/util/include/openvino/util/file_util.hpp @@ -10,6 +10,7 @@ #include #include +#include "openvino/util/file_path.hpp" #include "openvino/util/util.hpp" #include "openvino/util/wstring_cast_util.hpp" @@ -160,23 +161,24 @@ bool directory_exists(const std::string& path); bool directory_exists(const std::wstring& path); #endif +inline ov::util::Path cut_android_path(const ov::util::Path& file_name) { + const auto& file_name_result = file_name.native(); + const auto pos = file_name_result.find('!'); + if (pos != std::decay_t::npos) { + return ov::util::Path(file_name_result.substr(0, pos)); + } + + return file_name; +} + /** * @brief Returns file size for file * @param[in] path The file name * @return file size */ -inline int64_t file_size(const char* path) { -#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) - std::wstring widefilename = ov::util::string_to_wstring(path); - const wchar_t* file_name = widefilename.c_str(); -#elif defined(__ANDROID__) || defined(ANDROID) - std::string file_name = path; - std::string::size_type pos = file_name.find('!'); - if (pos != std::string::npos) { - file_name = file_name.substr(0, pos); - } -#else - const char* file_name = path; +inline int64_t file_size(const ov::util::Path& file_name) { +#if defined(__ANDROID__) || defined(ANDROID) + const ov::util::Path& file_name = cut_android_path(file_name); #endif std::ifstream in(file_name, std::ios_base::binary | std::ios_base::ate); return in.tellg(); @@ -211,8 +213,11 @@ 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 file_size(wstring_to_string(path)); +} inline int64_t file_size(const std::wstring& path) { - return file_size(wstring_to_string(path).c_str()); + return file_size(wstring_to_string(path)); } /** @@ -225,15 +230,6 @@ inline bool file_exists(const std::wstring& path) { } #endif // OPENVINO_ENABLE_UNICODE_PATH_SUPPORT -/** - * @brief Returns file size for file - * @param[in] path The file name - * @return file size - */ -inline int64_t file_size(const std::string& path) { - return file_size(path.c_str()); -} - /** * @brief Returns true if file exists * @param[in] path The file name From c0ec93e8ce8d260df1a0a55eaa6a82f9a22b1272 Mon Sep 17 00:00:00 2001 From: Michal Barnas Date: Wed, 15 Jan 2025 14:38:08 +0000 Subject: [PATCH 04/21] add unit tests for cut_android_path function --- src/core/tests/file_util.cpp | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/core/tests/file_util.cpp b/src/core/tests/file_util.cpp index aecd16f46213ed..0987cf9c040679 100644 --- a/src/core/tests/file_util.cpp +++ b/src/core/tests/file_util.cpp @@ -457,3 +457,52 @@ TEST(file_util, unicode_path_cast_from_wstring_to_char8_t) { ov::util::Path(L"~/狗/ǡ୫ԩϗ/にほ/ąę/ど/௸ඊƷ/狗33.txt").generic_u8string()); #endif } + +class CutAndroidPathTests : public ::testing::TestWithParam> {}; + +TEST_P(CutAndroidPathTests, HandlesStringPaths) { + ov::util::Path file_name = std::get<0>(GetParam()); + ov::util::Path expected = std::get<1>(GetParam()); + ov::util::Path result = ov::util::cut_android_path(file_name); + EXPECT_EQ(result, expected); +} + +INSTANTIATE_TEST_SUITE_P( + WStringPathTests, + CutAndroidPathTests, + ::testing::Values( + std::make_tuple(ov::util::Path(L"path/to/file"), ov::util::Path(L"path/to/file")), + std::make_tuple(ov::util::Path(L"path/to/file!extra"), ov::util::Path(L"path/to/file")), + std::make_tuple(ov::util::Path(L""), ov::util::Path(L"")), + std::make_tuple(ov::util::Path(L"!"), ov::util::Path(L"")), + std::make_tuple(ov::util::Path(L"path/to/file!extra!more"), ov::util::Path(L"path/to/file")), + std::make_tuple(ov::util::WPath(L"狗"), ov::util::WPath(L"狗")), + std::make_tuple(ov::util::WPath(L"~/いろはにほへど/狗.txt"), ov::util::WPath(L"~/いろはにほへど/狗.txt")), + std::make_tuple(ov::util::WPath(L"~/いろはにほへど/狗.txt!"), ov::util::WPath(L"~/いろはにほへど/狗.txt")), + std::make_tuple(ov::util::WPath(L"!~/いろはにほへど/狗.txt"), ov::util::WPath(L"")), + std::make_tuple(ov::util::WPath(L"~/いろはにほへど/狗!.txt"), ov::util::WPath(L"~/いろはにほへど/狗")))); + +INSTANTIATE_TEST_SUITE_P( + StringPathTests, + CutAndroidPathTests, + ::testing::Values( + std::make_tuple(ov::util::Path(""), ov::util::Path("")), + std::make_tuple(ov::util::Path("!"), ov::util::Path("")), + std::make_tuple(ov::util::Path("My!/path/example.txt"), ov::util::Path("My")), + std::make_tuple(ov::util::Path("My/path!example.txt"), ov::util::Path("My/path")), + std::make_tuple(ov::util::Path("My/path/example.txt!"), ov::util::Path("My/path/example.txt")), + std::make_tuple(ov::util::Path("My/path/example.txt"), ov::util::Path("My/path/example.txt")), + std::make_tuple(ov::util::Path("!My/path/example.txt!"), ov::util::Path("")), + std::make_tuple(ov::util::Path(u8"~/いろはにほへど/狗.txt"), ov::util::Path(u8"~/いろはにほへど/狗.txt")), + std::make_tuple(ov::util::Path(u"~/いろはにほへど/狗.txt"), ov::util::Path(u"~/いろはにほへど/狗.txt")), + std::make_tuple(ov::util::Path(U"D:\\いろはにほへど\\猫.txt"), ov::util::Path(U"D:\\いろはにほへど\\猫.txt")), + std::make_tuple(ov::util::Path(u8"~/いろはにほへど/狗.txt!"), ov::util::Path(u8"~/いろはにほへど/狗.txt")), + std::make_tuple(ov::util::Path(u"~/いろはにほへど/狗.txt!"), ov::util::Path(u"~/いろはにほへど/狗.txt")), + std::make_tuple(ov::util::Path(U"D:\\いろはにほへど\\猫.txt!"), ov::util::Path(U"D:\\いろはにほへど\\猫.txt")), + std::make_tuple(ov::util::Path(u8"!~/いろはにほへど/狗.txt"), ov::util::Path(u8"")), + std::make_tuple(ov::util::Path(u"!~/いろはにほへど/狗.txt"), ov::util::Path(u"")), + std::make_tuple(ov::util::Path(U"!D:\\いろはにほへど\\猫.txt"), ov::util::Path(U"")), + std::make_tuple(ov::util::Path(u8"~/いろはにほへど/狗!.txt"), ov::util::Path(u8"~/いろはにほへど/狗")), + std::make_tuple(ov::util::Path(u"~/いろはにほへど/狗!.txt"), ov::util::Path(u"~/いろはにほへど/狗")), + std::make_tuple(ov::util::Path(U"D:\\いろはにほへど\\猫!.txt"), ov::util::Path(U"D:\\いろはにほへど\\猫")))); + From dce5d59f52a570f57b00f486cc17ddadbeb91d92 Mon Sep 17 00:00:00 2001 From: Michal Barnas Date: Wed, 15 Jan 2025 14:41:05 +0000 Subject: [PATCH 05/21] add unit tests for file size functions with various file types and encodings --- src/core/tests/file_util.cpp | 125 +++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/src/core/tests/file_util.cpp b/src/core/tests/file_util.cpp index 0987cf9c040679..0396a9f0655b1b 100644 --- a/src/core/tests/file_util.cpp +++ b/src/core/tests/file_util.cpp @@ -506,3 +506,128 @@ INSTANTIATE_TEST_SUITE_P( std::make_tuple(ov::util::Path(u"~/いろはにほへど/狗!.txt"), ov::util::Path(u"~/いろはにほへど/狗")), std::make_tuple(ov::util::Path(U"D:\\いろはにほへど\\猫!.txt"), ov::util::Path(U"D:\\いろはにほへど\\猫")))); +class FileUtilTest : public ::testing::Test { +protected: + void SetUp() override { + // Create a temporary files for testing + { + std::ofstream outfile("test_file_0.txt"); + outfile.close(); + } + { + std::ofstream outfile("test_file_21.txt"); + outfile << "This is a test file." << std::endl; + outfile.close(); + } + { + std::ofstream outfile("test_file_21x1000.txt"); + for (int i = 0; i < 1000; ++i) { + outfile << "This is a test file." << std::endl; + } + outfile.close(); + } + +#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT + { + std::ofstream outfile(u8"这是_u8_.txt"); + outfile << "This is a test file." << std::endl; + outfile.close(); + } + { + std::ofstream outfile(ov::util::Path(U"这是_u16_.txt")); + outfile << "This is a test file." << std::endl; + outfile.close(); + } + { + std::ofstream outfile(ov::util::Path(U"这是_u32_.txt")); + outfile << "This is a test file." << std::endl; + outfile.close(); + } + { + std::ofstream outfile(ov::util::WPath(L"这是_wstring_.txt")); + outfile << "This is a test file." << std::endl; + outfile.close(); + } +#endif + + } + + void TearDown() override { + // 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_21x1000.txt"); +#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT + std::filesystem::remove(u8"这是_u8_.txt"); + std::filesystem::remove(u"这是_u16_.txt"); + std::filesystem::remove(U"这是_u32_.txt"); + std::filesystem::remove(ov::util::WPath(L"这是_wstring_.txt")); +#endif + } +}; + +TEST_F(FileUtilTest, FileSizeNonExistentFileTest) { + EXPECT_EQ(ov::util::file_size("non_existent_file.txt"), -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); +} + +TEST_F(FileUtilTest, EmptyFileSizeTest) { + EXPECT_EQ(ov::util::file_size("test_file_0.txt"), 0); + EXPECT_EQ(ov::util::file_size(u8"test_file_0.txt"), 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::WPath(L"test_file_0.txt")), 0); +} + +TEST_F(FileUtilTest, FileSizeTest) { + EXPECT_EQ(ov::util::file_size("test_file_21.txt"), 21); + EXPECT_EQ(ov::util::file_size(L"test_file_21.txt"), 21); + EXPECT_EQ(ov::util::file_size(ov::util::Path("test_file_21.txt")), 21); +} + +TEST_F(FileUtilTest, LargeFileSizeTest) { + EXPECT_EQ(ov::util::file_size("test_file_21x1000.txt"), 21 * 1000); + EXPECT_EQ(ov::util::file_size(L"test_file_21x1000.txt"), 21 * 1000); + EXPECT_EQ(ov::util::file_size(ov::util::Path("test_file_21x1000.txt")), 21 * 1000); +} + +#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT +TEST_F(FileUtilTest, u8FileSizeTest) { + EXPECT_EQ(ov::util::file_size("这是_u8_.txt"), 21); + EXPECT_EQ(ov::util::file_size(u8"这是_u8_.txt"), 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); + EXPECT_EQ(ov::util::file_size(ov::util::Path(u"这是_u8_.txt")), 21); + EXPECT_EQ(ov::util::file_size(ov::util::Path(U"这是_u8_.txt")), 21); + EXPECT_EQ(ov::util::file_size(ov::util::WPath(L"这是_u8_.txt")), 21); +} + +TEST_F(FileUtilTest, u16FileSizeTest) { + EXPECT_EQ(ov::util::file_size("这是_u16_.txt"), 21); + EXPECT_EQ(ov::util::file_size(L"这是_u16_.txt"), 21); + EXPECT_EQ(ov::util::file_size(ov::util::Path("这是_u16_.txt")), 21); +} + +TEST_F(FileUtilTest, u32FileSizeTest) { + EXPECT_EQ(ov::util::file_size("这是_u32_.txt"), 21); + EXPECT_EQ(ov::util::file_size(L"这是_u32_.txt"), 21); + EXPECT_EQ(ov::util::file_size(ov::util::Path("这是_u32_.txt")), 21); +} + +TEST_F(FileUtilTest, wstringFileSizeTest) { + EXPECT_EQ(ov::util::file_size("这是_wstring_.txt"), 21); + EXPECT_EQ(ov::util::file_size(L"这是_wstring_.txt"), 21); + EXPECT_EQ(ov::util::file_size(ov::util::Path("这是_wstring_.txt")), 21); +} +#endif From 701cd96830fa5af35035e67e4db3fb8eb49cabb4 Mon Sep 17 00:00:00 2001 From: Michal Barnas Date: Wed, 15 Jan 2025 15:40:08 +0000 Subject: [PATCH 06/21] code format --- src/common/util/src/file_util.cpp | 2 +- src/core/tests/file_util.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/common/util/src/file_util.cpp b/src/common/util/src/file_util.cpp index b3bd4940387c8a..c454eacba7d680 100644 --- a/src/common/util/src/file_util.cpp +++ b/src/common/util/src/file_util.cpp @@ -37,7 +37,7 @@ # endif // Copied from linux libc sys/stat.h: # if !defined(__MINGW32__) && !defined(__MINGW64__) -# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +# define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) # endif #else # include diff --git a/src/core/tests/file_util.cpp b/src/core/tests/file_util.cpp index 0396a9f0655b1b..6da6a0b0370b33 100644 --- a/src/core/tests/file_util.cpp +++ b/src/core/tests/file_util.cpp @@ -549,7 +549,6 @@ class FileUtilTest : public ::testing::Test { outfile.close(); } #endif - } void TearDown() override { From 97f2a96dbdd02a4f45f3fb0ba62f25513fd12753 Mon Sep 17 00:00:00 2001 From: Michal Barnas Date: Wed, 15 Jan 2025 15:45:42 +0000 Subject: [PATCH 07/21] prevent variable redefinition for android --- src/common/util/include/openvino/util/file_util.hpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/common/util/include/openvino/util/file_util.hpp b/src/common/util/include/openvino/util/file_util.hpp index e3461e5a81bc21..ad6792c16e5940 100644 --- a/src/common/util/include/openvino/util/file_util.hpp +++ b/src/common/util/include/openvino/util/file_util.hpp @@ -176,12 +176,15 @@ inline ov::util::Path cut_android_path(const ov::util::Path& file_name) { * @param[in] path The file name * @return file size */ -inline int64_t file_size(const ov::util::Path& file_name) { +inline int64_t file_size(const ov::util::Path& path) { #if defined(__ANDROID__) || defined(ANDROID) - const ov::util::Path& file_name = cut_android_path(file_name); -#endif - std::ifstream in(file_name, std::ios_base::binary | std::ios_base::ate); + const ov::util::Path& cut_path = cut_android_path(path); + std::ifstream in(cut_path, std::ios_base::binary | std::ios_base::ate); return in.tellg(); +#else + std::ifstream in(path, std::ios_base::binary | std::ios_base::ate); + return in.tellg(); +#endif } /** From c0345b1fb696cb3023d72a3096eaad13e0b335cd Mon Sep 17 00:00:00 2001 From: Michal Barnas Date: Wed, 15 Jan 2025 17:36:09 +0000 Subject: [PATCH 08/21] refactor test to use ov::util::Path for Unicode file output --- src/core/tests/file_util.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/tests/file_util.cpp b/src/core/tests/file_util.cpp index 6da6a0b0370b33..e696ac59c2b74a 100644 --- a/src/core/tests/file_util.cpp +++ b/src/core/tests/file_util.cpp @@ -529,7 +529,7 @@ class FileUtilTest : public ::testing::Test { #ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT { - std::ofstream outfile(u8"这是_u8_.txt"); + std::ofstream outfile(ov::util::Path(u8"这是_u8_.txt")); outfile << "This is a test file." << std::endl; outfile.close(); } From a1e80532ad28bb42e4890e5a397f31f9ec78586f Mon Sep 17 00:00:00 2001 From: "Barnas, Michal" Date: Thu, 16 Jan 2025 10:28:58 +0100 Subject: [PATCH 09/21] add Windows-specific includes for wstring_cast_util --- src/common/util/src/wstring_cast_util.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/common/util/src/wstring_cast_util.cpp b/src/common/util/src/wstring_cast_util.cpp index a907185e316d28..9e9c4b4e6adbdf 100644 --- a/src/common/util/src/wstring_cast_util.cpp +++ b/src/common/util/src/wstring_cast_util.cpp @@ -9,6 +9,10 @@ # include # include +# ifdef _WIN32 +# include +# endif + # ifdef __clang__ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wdeprecated-declarations" From f34b2d2cb8573c224e33d8a42c9c592697082086 Mon Sep 17 00:00:00 2001 From: "Barnas, Michal" Date: Thu, 16 Jan 2025 12:26:14 +0100 Subject: [PATCH 10/21] fix comment typo --- src/common/util/include/openvino/util/file_path.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/common/util/include/openvino/util/file_path.hpp b/src/common/util/include/openvino/util/file_path.hpp index 790e0310939470..8da67a969510bc 100644 --- a/src/common/util/include/openvino/util/file_path.hpp +++ b/src/common/util/include/openvino/util/file_path.hpp @@ -13,8 +13,7 @@ namespace ov { namespace util { #if defined(OPENVINO_HAS_FILESYSTEM) -// There are known issues related with usage of std::filesystem::path unocode represenataion: -// https://jira.devtools.intel.com/browse/CVS-160477 +// There are known issues related with usage of std::filesystem::path unicode represenataion: // * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95048 // * https://stackoverflow.com/questions/58521857/cross-platform-way-to-handle-stdstring-stdwstring-with-stdfilesystempath // Working compiler versions has been designated with godbolt. From 2d071bffe0aba27a1f3a382dfbd98283f5e29d7d Mon Sep 17 00:00:00 2001 From: "Barnas, Michal" Date: Thu, 16 Jan 2025 12:31:51 +0100 Subject: [PATCH 11/21] refactor cpp_version.hpp and file_path.hpp for compiler version checks --- .../util/include/openvino/util/cpp_version.hpp | 16 ---------------- .../util/include/openvino/util/file_path.hpp | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/common/util/include/openvino/util/cpp_version.hpp b/src/common/util/include/openvino/util/cpp_version.hpp index 4ee65a6d5c7a4b..c0998588027c2a 100644 --- a/src/common/util/include/openvino/util/cpp_version.hpp +++ b/src/common/util/include/openvino/util/cpp_version.hpp @@ -33,19 +33,3 @@ # endif # endif #endif - -#if !defined(__GNUC__) || (__GNUC__ > 12 || __GNUC__ == 12 && __GNUC_MINOR__ >= 3) -# define GCC_NOT_USED_OR_VER_AT_LEAST_12_3 -#endif - -#if !defined(__clang__) || defined(__clang__) && __clang_major__ >= 17 -# define CLANG_NOT_USED_OR_VER_AT_LEAST_17 -#endif - -#if defined(__GNUC__) && (__GNUC__ < 12 || __GNUC__ == 12 && __GNUC_MINOR__ < 3) -# define GCC_VER_LESS_THEN_12_3 -#endif - -#if defined(__clang__) && __clang_major__ < 17 -# define CLANG_VER_LESS_THEN_17 -#endif diff --git a/src/common/util/include/openvino/util/file_path.hpp b/src/common/util/include/openvino/util/file_path.hpp index 8da67a969510bc..761b3d3c8e4837 100644 --- a/src/common/util/include/openvino/util/file_path.hpp +++ b/src/common/util/include/openvino/util/file_path.hpp @@ -36,6 +36,22 @@ using Path = std::filesystem::path; using Path = std::experimental::filesystem::path; #endif +#if !defined(__GNUC__) || (__GNUC__ > 12 || __GNUC__ == 12 && __GNUC_MINOR__ >= 3) +# define GCC_NOT_USED_OR_VER_AT_LEAST_12_3 +#endif + +#if !defined(__clang__) || defined(__clang__) && __clang_major__ >= 17 +# define CLANG_NOT_USED_OR_VER_AT_LEAST_17 +#endif + +#if defined(__GNUC__) && (__GNUC__ < 12 || __GNUC__ == 12 && __GNUC_MINOR__ < 3) +# define GCC_VER_LESS_THEN_12_3 +#endif + +#if defined(__clang__) && __clang_major__ < 17 +# define CLANG_VER_LESS_THEN_17 +#endif + #if defined(GCC_VER_LESS_THEN_12_3) || defined(CLANG_VER_LESS_THEN_17) inline ov::util::Path WPath(const std::wstring& wpath) { return {ov::util::wstring_to_string(wpath)}; From 3b2fbae346bb4f843786e7b35938c69b089c3a97 Mon Sep 17 00:00:00 2001 From: Michal Barnas Date: Thu, 16 Jan 2025 11:57:13 +0000 Subject: [PATCH 12/21] refactor WPath function to use lambda syntax, to meet Naming style check --- src/common/util/include/openvino/util/file_path.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/common/util/include/openvino/util/file_path.hpp b/src/common/util/include/openvino/util/file_path.hpp index 761b3d3c8e4837..47f1e3a623908f 100644 --- a/src/common/util/include/openvino/util/file_path.hpp +++ b/src/common/util/include/openvino/util/file_path.hpp @@ -53,13 +53,13 @@ using Path = std::experimental::filesystem::path; #endif #if defined(GCC_VER_LESS_THEN_12_3) || defined(CLANG_VER_LESS_THEN_17) -inline ov::util::Path WPath(const std::wstring& wpath) { - return {ov::util::wstring_to_string(wpath)}; -} +auto WPath = [](const std::wstring& wpath) { + return ov::util::Path{ov::util::wstring_to_string(wpath)}; +}; #else -inline ov::util::Path WPath(const std::wstring& wpath) { - return {wpath}; -} +auto WPath = [](const std::wstring& wpath) { + return ov::util::Path{wpath}; +}; #endif } // namespace util From eed127e1d8c2bcb2164ac4b753df9531f9470fa7 Mon Sep 17 00:00:00 2001 From: Michal Barnas Date: Thu, 16 Jan 2025 12:23:44 +0000 Subject: [PATCH 13/21] update copyright year to 2025, fix typos, refactor to use structured bindings --- .../util/include/openvino/util/file_path.hpp | 10 +++++----- .../include/openvino/util/wstring_cast_util.hpp | 2 +- src/core/tests/file_util.cpp | 14 ++------------ 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/common/util/include/openvino/util/file_path.hpp b/src/common/util/include/openvino/util/file_path.hpp index 47f1e3a623908f..4c6e6df56c2828 100644 --- a/src/common/util/include/openvino/util/file_path.hpp +++ b/src/common/util/include/openvino/util/file_path.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2018-2024 Intel Corporation +// Copyright (C) 2018-2025 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // @@ -13,7 +13,7 @@ namespace ov { namespace util { #if defined(OPENVINO_HAS_FILESYSTEM) -// There are known issues related with usage of std::filesystem::path unicode represenataion: +// There are known issues with usage of std::filesystem::path unicode represenataion: // * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95048 // * https://stackoverflow.com/questions/58521857/cross-platform-way-to-handle-stdstring-stdwstring-with-stdfilesystempath // Working compiler versions has been designated with godbolt. @@ -45,14 +45,14 @@ using Path = std::experimental::filesystem::path; #endif #if defined(__GNUC__) && (__GNUC__ < 12 || __GNUC__ == 12 && __GNUC_MINOR__ < 3) -# define GCC_VER_LESS_THEN_12_3 +# define GCC_VER_LESS_THAN_12_3 #endif #if defined(__clang__) && __clang_major__ < 17 -# define CLANG_VER_LESS_THEN_17 +# define CLANG_VER_LESS_THAN_17 #endif -#if defined(GCC_VER_LESS_THEN_12_3) || defined(CLANG_VER_LESS_THEN_17) +#if defined(GCC_VER_LESS_THAN_12_3) || defined(CLANG_VER_LESS_THAN_17) auto WPath = [](const std::wstring& wpath) { return ov::util::Path{ov::util::wstring_to_string(wpath)}; }; diff --git a/src/common/util/include/openvino/util/wstring_cast_util.hpp b/src/common/util/include/openvino/util/wstring_cast_util.hpp index 4523016543b934..042e2a2528621e 100644 --- a/src/common/util/include/openvino/util/wstring_cast_util.hpp +++ b/src/common/util/include/openvino/util/wstring_cast_util.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2018-2024 Intel Corporation +// Copyright (C) 2018-2025 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // diff --git a/src/core/tests/file_util.cpp b/src/core/tests/file_util.cpp index e696ac59c2b74a..55d14c88d48e76 100644 --- a/src/core/tests/file_util.cpp +++ b/src/core/tests/file_util.cpp @@ -461,8 +461,7 @@ TEST(file_util, unicode_path_cast_from_wstring_to_char8_t) { class CutAndroidPathTests : public ::testing::TestWithParam> {}; TEST_P(CutAndroidPathTests, HandlesStringPaths) { - ov::util::Path file_name = std::get<0>(GetParam()); - ov::util::Path expected = std::get<1>(GetParam()); + const auto& [file_name, expected] = GetParam(); ov::util::Path result = ov::util::cut_android_path(file_name); EXPECT_EQ(result, expected); } @@ -510,43 +509,34 @@ class FileUtilTest : public ::testing::Test { protected: void SetUp() override { // Create a temporary files for testing - { - std::ofstream outfile("test_file_0.txt"); - outfile.close(); - } + { std::ofstream outfile("test_file_0.txt"); } { std::ofstream outfile("test_file_21.txt"); outfile << "This is a test file." << std::endl; - outfile.close(); } { std::ofstream outfile("test_file_21x1000.txt"); for (int i = 0; i < 1000; ++i) { outfile << "This is a test file." << std::endl; } - outfile.close(); } #ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT { std::ofstream outfile(ov::util::Path(u8"这是_u8_.txt")); outfile << "This is a test file." << std::endl; - outfile.close(); } { std::ofstream outfile(ov::util::Path(U"这是_u16_.txt")); outfile << "This is a test file." << std::endl; - outfile.close(); } { std::ofstream outfile(ov::util::Path(U"这是_u32_.txt")); outfile << "This is a test file." << std::endl; - outfile.close(); } { std::ofstream outfile(ov::util::WPath(L"这是_wstring_.txt")); outfile << "This is a test file." << std::endl; - outfile.close(); } #endif } From 067224bd1b6d9d2221f2569ae36f76e1d9d00bae Mon Sep 17 00:00:00 2001 From: Michal Barnas Date: Thu, 16 Jan 2025 13:02:23 +0000 Subject: [PATCH 14/21] rename wstring_cast_util to wstring_convert_util and update includes --- src/common/util/CMakeLists.txt | 2 +- src/common/util/include/openvino/util/file_path.hpp | 2 +- src/common/util/include/openvino/util/file_util.hpp | 2 +- .../util/{wstring_cast_util.hpp => wstring_convert_util.hpp} | 0 .../src/{wstring_cast_util.cpp => wstring_convert_util.cpp} | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) rename src/common/util/include/openvino/util/{wstring_cast_util.hpp => wstring_convert_util.hpp} (100%) rename src/common/util/src/{wstring_cast_util.cpp => wstring_convert_util.cpp} (96%) diff --git a/src/common/util/CMakeLists.txt b/src/common/util/CMakeLists.txt index fa91049738a687..faedee20d7454c 100644 --- a/src/common/util/CMakeLists.txt +++ b/src/common/util/CMakeLists.txt @@ -26,7 +26,7 @@ endif() set_source_files_properties( "${CMAKE_CURRENT_SOURCE_DIR}/src/file_util.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/src/wstring_cast_util.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/src/wstring_cpnvert_util.cpp" PROPERTIES COMPILE_DEFINITIONS OpenVINO_VERSION="${OpenVINO_VERSION}") source_group("src" FILES ${LIBRARY_SRC}) diff --git a/src/common/util/include/openvino/util/file_path.hpp b/src/common/util/include/openvino/util/file_path.hpp index 4c6e6df56c2828..7a24f3bc92a31e 100644 --- a/src/common/util/include/openvino/util/file_path.hpp +++ b/src/common/util/include/openvino/util/file_path.hpp @@ -7,7 +7,7 @@ #include #include "openvino/util/filesystem.hpp" -#include "openvino/util/wstring_cast_util.hpp" +#include "openvino/util/wstring_convert_util.hpp" namespace ov { namespace util { diff --git a/src/common/util/include/openvino/util/file_util.hpp b/src/common/util/include/openvino/util/file_util.hpp index ad6792c16e5940..d4012a03820e5c 100644 --- a/src/common/util/include/openvino/util/file_util.hpp +++ b/src/common/util/include/openvino/util/file_util.hpp @@ -12,7 +12,7 @@ #include "openvino/util/file_path.hpp" #include "openvino/util/util.hpp" -#include "openvino/util/wstring_cast_util.hpp" +#include "openvino/util/wstring_convert_util.hpp" namespace ov { namespace util { diff --git a/src/common/util/include/openvino/util/wstring_cast_util.hpp b/src/common/util/include/openvino/util/wstring_convert_util.hpp similarity index 100% rename from src/common/util/include/openvino/util/wstring_cast_util.hpp rename to src/common/util/include/openvino/util/wstring_convert_util.hpp diff --git a/src/common/util/src/wstring_cast_util.cpp b/src/common/util/src/wstring_convert_util.cpp similarity index 96% rename from src/common/util/src/wstring_cast_util.cpp rename to src/common/util/src/wstring_convert_util.cpp index 9e9c4b4e6adbdf..de76e1134e150d 100644 --- a/src/common/util/src/wstring_cast_util.cpp +++ b/src/common/util/src/wstring_convert_util.cpp @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "openvino/util/wstring_cast_util.hpp" +#include "openvino/util/wstring_convert_util.hpp" #ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT From 22d671258245fbb8712594dc0531083b125efefd Mon Sep 17 00:00:00 2001 From: Michal Barnas Date: Thu, 16 Jan 2025 13:25:15 +0000 Subject: [PATCH 15/21] add Android-specific file size test --- src/core/tests/file_util.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/core/tests/file_util.cpp b/src/core/tests/file_util.cpp index 55d14c88d48e76..785748070dd809 100644 --- a/src/core/tests/file_util.cpp +++ b/src/core/tests/file_util.cpp @@ -538,6 +538,12 @@ class FileUtilTest : public ::testing::Test { std::ofstream outfile(ov::util::WPath(L"这是_wstring_.txt")); outfile << "This is a test file." << std::endl; } +#endif +#if defined(__ANDROID__) || defined(ANDROID) + { + std::ofstream outfile("android_test_file_21.txt"); + outfile << "This is a test file." << std::endl; + } #endif } @@ -551,6 +557,9 @@ class FileUtilTest : public ::testing::Test { std::filesystem::remove(u"这是_u16_.txt"); std::filesystem::remove(U"这是_u32_.txt"); std::filesystem::remove(ov::util::WPath(L"这是_wstring_.txt")); +#endif +#if defined(__ANDROID__) || defined(ANDROID) + std::filesystem::remove("android_test_file_21.txt"); #endif } }; @@ -620,3 +629,16 @@ TEST_F(FileUtilTest, wstringFileSizeTest) { EXPECT_EQ(ov::util::file_size(ov::util::Path("这是_wstring_.txt")), 21); } #endif + +#if defined(__ANDROID__) || defined(ANDROID) +TEST_F(FileUtilTest, androidFileSizeTest) { + EXPECT_EQ(ov::util::file_size("android_test_file_21.txt"), 21); + EXPECT_EQ(ov::util::file_size(L"android_test_file_21.txt"), 21); + EXPECT_EQ(ov::util::file_size(ov::util::Path("android_test_file_21.txt")), 21); +} +TEST_F(FileUtilTest, androidWithCutFileSizeTest) { + EXPECT_EQ(ov::util::file_size("android_test_file_21.txt!_to_cut.jar"), 21); + EXPECT_EQ(ov::util::file_size(L"android_test_file_21.txt!_to_cut.jar"), 21); + EXPECT_EQ(ov::util::file_size(ov::util::Path("android_test_file_21.txt!_to_cut.jar")), 21); +} +#endif From 2e7cf523d0deec637445055ca20a18b9a2ce7658 Mon Sep 17 00:00:00 2001 From: Michal Barnas Date: Thu, 16 Jan 2025 13:39:08 +0000 Subject: [PATCH 16/21] fix typo in CMakeLists.txt for wstring_convert_util source file path --- src/common/util/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/util/CMakeLists.txt b/src/common/util/CMakeLists.txt index faedee20d7454c..09fb2256644a5c 100644 --- a/src/common/util/CMakeLists.txt +++ b/src/common/util/CMakeLists.txt @@ -26,7 +26,7 @@ endif() set_source_files_properties( "${CMAKE_CURRENT_SOURCE_DIR}/src/file_util.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/src/wstring_cpnvert_util.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/src/wstring_convert_util.cpp" PROPERTIES COMPILE_DEFINITIONS OpenVINO_VERSION="${OpenVINO_VERSION}") source_group("src" FILES ${LIBRARY_SRC}) From e9c2ccaafd49e83d3ef00b2180d2c68c3a9ce4d3 Mon Sep 17 00:00:00 2001 From: Michal Barnas Date: Thu, 16 Jan 2025 14:30:53 +0000 Subject: [PATCH 17/21] deprecate old file_size function and provide alternative usage guidance --- .../util/include/openvino/util/file_util.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/common/util/include/openvino/util/file_util.hpp b/src/common/util/include/openvino/util/file_util.hpp index d4012a03820e5c..c737213c71c435 100644 --- a/src/common/util/include/openvino/util/file_util.hpp +++ b/src/common/util/include/openvino/util/file_util.hpp @@ -176,6 +176,25 @@ inline ov::util::Path cut_android_path(const ov::util::Path& file_name) { * @param[in] path The file name * @return file size */ +[[deprecated( + "This function is deprecated use file_size(const ov::util::Path& path) instead. Will be removed in 2026.0")]] +inline int64_t file_size(const char* path) { +#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) + std::wstring widefilename = ov::util::string_to_wstring(path); + const wchar_t* file_name = widefilename.c_str(); +#elif defined(__ANDROID__) || defined(ANDROID) + std::string file_name = path; + std::string::size_type pos = file_name.find('!'); + if (pos != std::string::npos) { + file_name = file_name.substr(0, pos); + } +#else + const char* file_name = path; +#endif + std::ifstream in(file_name, std::ios_base::binary | std::ios_base::ate); + return in.tellg(); +} + inline int64_t file_size(const ov::util::Path& path) { #if defined(__ANDROID__) || defined(ANDROID) const ov::util::Path& cut_path = cut_android_path(path); From 71e220633acb2b086ca9b8ee6cbb7e7602ef8a05 Mon Sep 17 00:00:00 2001 From: Michal Barnas Date: Thu, 16 Jan 2025 15:16:06 +0000 Subject: [PATCH 18/21] update file size tests to use string literals --- src/core/tests/file_util.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/core/tests/file_util.cpp b/src/core/tests/file_util.cpp index 785748070dd809..22fa54188e6d79 100644 --- a/src/core/tests/file_util.cpp +++ b/src/core/tests/file_util.cpp @@ -565,13 +565,13 @@ class FileUtilTest : public ::testing::Test { }; TEST_F(FileUtilTest, FileSizeNonExistentFileTest) { - EXPECT_EQ(ov::util::file_size("non_existent_file.txt"), -1); + 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); } TEST_F(FileUtilTest, EmptyFileSizeTest) { - EXPECT_EQ(ov::util::file_size("test_file_0.txt"), 0); + EXPECT_EQ(ov::util::file_size("test_file_0.txt"s), 0); EXPECT_EQ(ov::util::file_size(u8"test_file_0.txt"), 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); @@ -585,20 +585,20 @@ TEST_F(FileUtilTest, EmptyFileSizeTest) { } TEST_F(FileUtilTest, FileSizeTest) { - EXPECT_EQ(ov::util::file_size("test_file_21.txt"), 21); + 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::Path("test_file_21.txt")), 21); } TEST_F(FileUtilTest, LargeFileSizeTest) { - EXPECT_EQ(ov::util::file_size("test_file_21x1000.txt"), 21 * 1000); + 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::Path("test_file_21x1000.txt")), 21 * 1000); } #ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT TEST_F(FileUtilTest, u8FileSizeTest) { - EXPECT_EQ(ov::util::file_size("这是_u8_.txt"), 21); + EXPECT_EQ(ov::util::file_size("这是_u8_.txt"s), 21); EXPECT_EQ(ov::util::file_size(u8"这是_u8_.txt"), 21); EXPECT_EQ(ov::util::file_size(u"这是_u8_.txt"), 21); EXPECT_EQ(ov::util::file_size(U"这是_u8_.txt"), 21); @@ -612,19 +612,19 @@ TEST_F(FileUtilTest, u8FileSizeTest) { } TEST_F(FileUtilTest, u16FileSizeTest) { - EXPECT_EQ(ov::util::file_size("这是_u16_.txt"), 21); + 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); } TEST_F(FileUtilTest, u32FileSizeTest) { - EXPECT_EQ(ov::util::file_size("这是_u32_.txt"), 21); + 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); } TEST_F(FileUtilTest, wstringFileSizeTest) { - EXPECT_EQ(ov::util::file_size("这是_wstring_.txt"), 21); + 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); } @@ -632,12 +632,12 @@ TEST_F(FileUtilTest, wstringFileSizeTest) { #if defined(__ANDROID__) || defined(ANDROID) TEST_F(FileUtilTest, androidFileSizeTest) { - EXPECT_EQ(ov::util::file_size("android_test_file_21.txt"), 21); + EXPECT_EQ(ov::util::file_size("android_test_file_21.txt"s), 21); EXPECT_EQ(ov::util::file_size(L"android_test_file_21.txt"), 21); EXPECT_EQ(ov::util::file_size(ov::util::Path("android_test_file_21.txt")), 21); } TEST_F(FileUtilTest, androidWithCutFileSizeTest) { - EXPECT_EQ(ov::util::file_size("android_test_file_21.txt!_to_cut.jar"), 21); + EXPECT_EQ(ov::util::file_size("android_test_file_21.txt!_to_cut.jar"s), 21); EXPECT_EQ(ov::util::file_size(L"android_test_file_21.txt!_to_cut.jar"), 21); EXPECT_EQ(ov::util::file_size(ov::util::Path("android_test_file_21.txt!_to_cut.jar")), 21); } From c8bdb3b71ad50ae2b8aa4af4e31e90acfd2d1f9f Mon Sep 17 00:00:00 2001 From: Michal Barnas Date: Thu, 16 Jan 2025 16:12:52 +0000 Subject: [PATCH 19/21] skip file size tests based on C++ version --- src/core/tests/file_util.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/tests/file_util.cpp b/src/core/tests/file_util.cpp index 22fa54188e6d79..d051939daf4438 100644 --- a/src/core/tests/file_util.cpp +++ b/src/core/tests/file_util.cpp @@ -571,8 +571,10 @@ TEST_F(FileUtilTest, FileSizeNonExistentFileTest) { } TEST_F(FileUtilTest, EmptyFileSizeTest) { - EXPECT_EQ(ov::util::file_size("test_file_0.txt"s), 0); +#ifdef OPENVINO_CPP_VER_AT_LEAST_20 EXPECT_EQ(ov::util::file_size(u8"test_file_0.txt"), 0); +#endif + 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); @@ -598,8 +600,10 @@ TEST_F(FileUtilTest, LargeFileSizeTest) { #ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT TEST_F(FileUtilTest, u8FileSizeTest) { - EXPECT_EQ(ov::util::file_size("这是_u8_.txt"s), 21); +# ifdef OPENVINO_CPP_VER_AT_LEAST_20 EXPECT_EQ(ov::util::file_size(u8"这是_u8_.txt"), 21); +# endif + 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); From dd13c049a9664f0809df91150c1777311dcb6655 Mon Sep 17 00:00:00 2001 From: Michal Barnas Date: Thu, 16 Jan 2025 22:05:12 +0000 Subject: [PATCH 20/21] revert: refactor WPath function to use lambda syntax, to meet Naming style check --- src/common/util/include/openvino/util/file_path.hpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/common/util/include/openvino/util/file_path.hpp b/src/common/util/include/openvino/util/file_path.hpp index 7a24f3bc92a31e..a0fc98fe86d9e8 100644 --- a/src/common/util/include/openvino/util/file_path.hpp +++ b/src/common/util/include/openvino/util/file_path.hpp @@ -8,6 +8,7 @@ #include "openvino/util/filesystem.hpp" #include "openvino/util/wstring_convert_util.hpp" +//#include "openvino/util/util.hpp" namespace ov { namespace util { @@ -53,13 +54,13 @@ using Path = std::experimental::filesystem::path; #endif #if defined(GCC_VER_LESS_THAN_12_3) || defined(CLANG_VER_LESS_THAN_17) -auto WPath = [](const std::wstring& wpath) { - return ov::util::Path{ov::util::wstring_to_string(wpath)}; -}; +inline ov::util::Path WPath(const std::wstring& wpath) { + return {ov::util::wstring_to_string(wpath)}; +} #else -auto WPath = [](const std::wstring& wpath) { - return ov::util::Path{wpath}; -}; +inline ov::util::Path WPath(const std::wstring& wpath) { + return {wpath}; +} #endif } // namespace util From 0f2aa4a24cc8e866cb75ddd42fd5b803f4ae8739 Mon Sep 17 00:00:00 2001 From: Michal Barnas Date: Wed, 22 Jan 2025 08:50:53 +0000 Subject: [PATCH 21/21] clang format --- src/common/util/include/openvino/util/file_util.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/util/include/openvino/util/file_util.hpp b/src/common/util/include/openvino/util/file_util.hpp index c737213c71c435..b8d51316640864 100644 --- a/src/common/util/include/openvino/util/file_util.hpp +++ b/src/common/util/include/openvino/util/file_util.hpp @@ -176,9 +176,9 @@ inline ov::util::Path cut_android_path(const ov::util::Path& file_name) { * @param[in] path The file name * @return file size */ -[[deprecated( - "This function is deprecated use file_size(const ov::util::Path& path) instead. Will be removed in 2026.0")]] -inline int64_t file_size(const char* path) { +[[deprecated("This function is deprecated use file_size(const ov::util::Path& path) instead. Will be removed in " + "2026.0")]] inline int64_t +file_size(const char* path) { #if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) std::wstring widefilename = ov::util::string_to_wstring(path); const wchar_t* file_name = widefilename.c_str();