-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy patherror_info.cpp
More file actions
87 lines (76 loc) · 1.99 KB
/
error_info.cpp
File metadata and controls
87 lines (76 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "pch.h"
#include "winrt/Windows.Data.Xml.Dom.h"
using namespace winrt;
namespace
{
HRESULT winrt_error_info() noexcept
{
return hresult_invalid_argument(L"winrt_error_info").to_abi();
}
HRESULT com_error_info() noexcept
{
com_ptr<ICreateErrorInfo> creator;
CreateErrorInfo(creator.put());
creator->SetDescription(const_cast<wchar_t*>(L"com_error_info"));
SetErrorInfo(0, creator.as<IErrorInfo>().get());
return E_INVALIDARG;
}
HRESULT no_error_info() noexcept
{
// This just makes sure there's no error info connected to the thread.
com_ptr<IErrorInfo> info;
GetErrorInfo(0, info.put());
return E_INVALIDARG;
}
}
TEST_CASE("error_info")
{
try
{
check_hresult(winrt_error_info());
FAIL("Previous line should throw");
}
catch (hresult_invalid_argument const& e)
{
REQUIRE(e.message() == L"winrt_error_info");
}
try
{
check_hresult(com_error_info());
FAIL("Previous line should throw");
}
catch (hresult_invalid_argument const& e)
{
REQUIRE(e.message() == L"com_error_info");
}
try
{
check_hresult(no_error_info());
FAIL("Previous line should throw");
}
catch (hresult_invalid_argument const& e)
{
REQUIRE(e.message() == L"The parameter is incorrect.");
}
try
{
// This API reports using WinRT error info.
Windows::Foundation::Uri(L"bad");
FAIL("Previous line should throw");
}
catch (hresult_invalid_argument const& e)
{
REQUIRE(e.message() == L"bad is not a valid absolute URI.");
}
try
{
// This API reports using COM error info.
Windows::Data::Xml::Dom::XmlDocument doc;
doc.LoadXml(L"bad");
FAIL("Previous line should throw");
}
catch (hresult_error const& e)
{
REQUIRE(e.message() == L"Invalid at the top level of the document.");
}
}