diff --git a/winml/adapter/winml_adapter_model.cpp b/winml/adapter/winml_adapter_model.cpp index 8203987215..9b5466c40a 100644 --- a/winml/adapter/winml_adapter_model.cpp +++ b/winml/adapter/winml_adapter_model.cpp @@ -14,8 +14,10 @@ #include #include +#include #include "google/protobuf/io/zero_copy_stream_impl.h" #include "core/framework/onnxruntime_typeinfo.h" +#include "StringHelpers.h" namespace winmla = Windows::AI::MachineLearning::Adapter; @@ -118,10 +120,11 @@ OrtModel::OrtModel(std::unique_ptr model_proto) : model_proto_ // factory methods for creating an ort model from a path static OrtStatus* CreateModelProto(const char* path, std::unique_ptr& out) { int file_descriptor; + auto wide_path = _winml::Strings::HStringFromUTF8(path); _set_errno(0); // clear errno - _sopen_s( + _wsopen_s( &file_descriptor, - path, + wide_path.c_str(), O_RDONLY | _O_SEQUENTIAL | _O_BINARY, _SH_DENYWR, _S_IREAD | _S_IWRITE); diff --git a/winml/test/api/LearningModelAPITest.cpp b/winml/test/api/LearningModelAPITest.cpp index d9a514e4be..04167bd9cb 100644 --- a/winml/test/api/LearningModelAPITest.cpp +++ b/winml/test/api/LearningModelAPITest.cpp @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #include "testPch.h" @@ -26,6 +26,11 @@ static void CreateModelFromFilePath() { WINML_EXPECT_NO_THROW(APITest::LoadModel(L"squeezenet_modifiedforruntimestests.onnx", learningModel)); } +static void CreateModelFromUnicodeFilePath() { + LearningModel learningModel = nullptr; + WINML_EXPECT_NO_THROW(APITest::LoadModel(L"UnicodePath\\こんにちは maçã\\foo.onnx", learningModel)); +} + static void CreateModelFileNotFound() { LearningModel learningModel = nullptr; @@ -274,6 +279,7 @@ const LearningModelApiTestsApi& getapi() { LearningModelAPITestsClassSetup, LearningModelAPITestsGpuMethodSetup, CreateModelFromFilePath, + CreateModelFromUnicodeFilePath, CreateModelFileNotFound, CreateModelFromIStorage, CreateModelFromIStorageOutsideCwd, diff --git a/winml/test/api/LearningModelAPITest.h b/winml/test/api/LearningModelAPITest.h index cd83624620..7658e5df3d 100644 --- a/winml/test/api/LearningModelAPITest.h +++ b/winml/test/api/LearningModelAPITest.h @@ -7,6 +7,7 @@ struct LearningModelApiTestsApi SetupClass LearningModelAPITestsClassSetup; SetupTest LearningModelAPITestsGpuMethodSetup; VoidTest CreateModelFromFilePath; + VoidTest CreateModelFromUnicodeFilePath; VoidTest CreateModelFileNotFound; VoidTest CreateModelFromIStorage; VoidTest CreateModelFromIStorageOutsideCwd; @@ -29,6 +30,7 @@ WINML_TEST_CLASS_BEGIN(LearningModelAPITests) WINML_TEST_CLASS_SETUP_CLASS(LearningModelAPITestsClassSetup) WINML_TEST_CLASS_BEGIN_TESTS WINML_TEST(LearningModelAPITests, CreateModelFromFilePath) +WINML_TEST(LearningModelAPITests, CreateModelFromUnicodeFilePath) WINML_TEST(LearningModelAPITests, CreateModelFileNotFound) WINML_TEST(LearningModelAPITests, CreateModelFromIStorage) WINML_TEST(LearningModelAPITests, CreateModelFromIStorageOutsideCwd) diff --git a/winml/test/collateral/models/UnicodePath/こんにちは maçã/foo.onnx b/winml/test/collateral/models/UnicodePath/こんにちは maçã/foo.onnx new file mode 100644 index 0000000000..f786e4ca75 Binary files /dev/null and b/winml/test/collateral/models/UnicodePath/こんにちは maçã/foo.onnx differ