diff --git a/winml/test/api/LearningModelAPITest.cpp b/winml/test/api/LearningModelAPITest.cpp index 04167bd9cb..d7860a99b3 100644 --- a/winml/test/api/LearningModelAPITest.cpp +++ b/winml/test/api/LearningModelAPITest.cpp @@ -42,6 +42,18 @@ static void CreateModelFileNotFound() { }); } +static void CreateCorruptModel() { + LearningModel learningModel = nullptr; + + WINML_EXPECT_THROW_SPECIFIC( + APITest::LoadModel(L"corrupt-model.onnx", learningModel), + winrt::hresult_error, + [](const winrt::hresult_error& e) -> bool { + auto f = __HRESULT_FROM_WIN32(e.code()); + return e.code() == __HRESULT_FROM_WIN32(ERROR_FILE_CORRUPT); + }); +} + static void CreateModelFromIStorage() { std::wstring path = FileHelpers::GetModulePath() + L"squeezenet_modifiedforruntimestests.onnx"; auto storageFile = ws::StorageFile::GetFileFromPathAsync(path).get(); @@ -294,7 +306,8 @@ const LearningModelApiTestsApi& getapi() { CloseModelCheckMetadata, CloseModelCheckEval, CloseModelNoNewSessions, - CheckMetadataCaseInsensitive + CheckMetadataCaseInsensitive, + CreateCorruptModel }; return api; } \ No newline at end of file diff --git a/winml/test/api/LearningModelAPITest.h b/winml/test/api/LearningModelAPITest.h index 7658e5df3d..782c54a468 100644 --- a/winml/test/api/LearningModelAPITest.h +++ b/winml/test/api/LearningModelAPITest.h @@ -23,6 +23,7 @@ struct LearningModelApiTestsApi VoidTest CloseModelCheckEval; VoidTest CloseModelNoNewSessions; VoidTest CheckMetadataCaseInsensitive; + VoidTest CreateCorruptModel; }; const LearningModelApiTestsApi& getapi(); @@ -45,6 +46,7 @@ WINML_TEST(LearningModelAPITests, EnumerateOutputs) WINML_TEST(LearningModelAPITests, CloseModelCheckMetadata) WINML_TEST(LearningModelAPITests, CloseModelNoNewSessions) WINML_TEST(LearningModelAPITests, CheckMetadataCaseInsensitive) +WINML_TEST(LearningModelAPITests, CreateCorruptModel) WINML_TEST_CLASS_END() WINML_TEST_CLASS_BEGIN(LearningModelAPITestsGpu) diff --git a/winml/test/collateral/models/corrupt-model.onnx b/winml/test/collateral/models/corrupt-model.onnx new file mode 100644 index 0000000000..5ea96a7114 --- /dev/null +++ b/winml/test/collateral/models/corrupt-model.onnx @@ -0,0 +1 @@ +this is not a valid onnx model \ No newline at end of file