Skip to content

Commit a409585

Browse files
committed
Port tests from the upstream PR
1 parent 02724b9 commit a409585

13 files changed

Lines changed: 142 additions & 62 deletions

test/test_component/test_component.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,8 @@
383383
<ItemDefinitionGroup>
384384
<CustomBuildStep>
385385
<Command>
386-
$(CppWinRTDir)cppwinrt -in local -out $(OutputPath) -verbose
387-
$(CppWinRTDir)cppwinrt -input $(OutputPath)test_component.winmd -comp "$(ProjectDir)Generated Files" -out "$(ProjectDir)Generated Files" -include test_component -ref sdk -verbose -prefix -opt -lib test -fastabi -overwrite -name test_component
386+
$(CppWinRTDir)cppwinrt -in local -out $(OutputPath) -verbose -modules
387+
$(CppWinRTDir)cppwinrt -input $(OutputPath)test_component.winmd -comp "$(ProjectDir)Generated Files" -out "$(ProjectDir)Generated Files" -include test_component -ref sdk -verbose -prefix -opt -lib test -fastabi -overwrite -name test_component -modules
388388
</Command>
389389
<Message>Projecting Windows and component metadata into $(OutputPath)</Message>
390390
<Outputs>$(OutputPath)\winrt\base.h;Generated Files\module.g.cpp</Outputs>

test/test_cpp20/array_span.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
#include "pch.h"
1+
#include <Windows.h>
22
#include "catch.hpp"
3-
#include <array>
3+
4+
import std;
5+
import Windows.Foundation;
6+
import Windows.Storage.Streams;
7+
import Windows.Data.Json;
48

59
using namespace winrt;
610
using namespace Windows::Foundation;
@@ -10,7 +14,7 @@ using namespace Windows::Data::Json;
1014
//
1115
// This is a helper to create a data reader for use in testing arrays.
1216
//
13-
static IAsyncOperation<IDataReader> CreateDataReader(std::initializer_list<byte> /*values*/)
17+
static IAsyncOperation<IDataReader> CreateDataReader(std::initializer_list<std::uint8_t> /*values*/)
1418
{
1519
InMemoryRandomAccessStream stream;
1620
DataWriter writer(stream);
@@ -32,8 +36,8 @@ TEST_CASE("array,DataReader,std::span")
3236
{
3337
auto reader = CreateDataReader({ 1, 2, 3 }).get();
3438

35-
std::array<byte, 3> a{};
36-
std::span<byte> sp(a);
39+
std::array<std::uint8_t, 3> a{};
40+
std::span<std::uint8_t> sp(a);
3741
reader.ReadBytes(sp); // FillArray pattern
3842

3943
REQUIRE(a.size() == 3);
@@ -49,7 +53,7 @@ TEST_CASE("array,DataReader,std::span,direct")
4953
{
5054
auto reader = CreateDataReader({ 1, 2, 3 }).get();
5155

52-
std::array<byte, 3> a{};
56+
std::array<std::uint8_t, 3> a{};
5357
reader.ReadBytes(a); // FillArray pattern
5458

5559
REQUIRE(a.size() == 3);
@@ -154,7 +158,7 @@ TEST_CASE("array_view,span,ctad")
154158
#define REQUIRE_DEDUCED_AS(T, ...) \
155159
static_assert(std::is_same_v<array_view<T>, decltype(array_view(__VA_ARGS__))>)
156160

157-
std::uint8_t a[] = {1, 2, 3};
161+
std::uint8_t a[] = { 1, 2, 3 };
158162
std::span<std::uint8_t, 3> sp{ a };
159163

160164
REQUIRE_DEDUCED_AS(std::uint8_t, sp);

test/test_cpp20/async.cpp

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#include <Windows.h>
2+
#include "catch.hpp"
3+
4+
import std;
5+
import Windows.Foundation;
6+
7+
using namespace winrt;
8+
using namespace Windows::Foundation;
9+
using namespace std::chrono_literals;
10+
11+
namespace
12+
{
13+
//
14+
// Just some quick tests to make sure that coroutines compile and work with C++20 modules.
15+
// Taken from async_throw in test
16+
//
17+
// TODO: make a new project for this
18+
19+
IAsyncAction Action()
20+
{
21+
co_await 10ms;
22+
throw hresult_invalid_argument(L"Async");
23+
}
24+
25+
IAsyncActionWithProgress<int> ActionWithProgress()
26+
{
27+
co_await 10ms;
28+
throw hresult_invalid_argument(L"Async");
29+
}
30+
31+
IAsyncOperation<int> Operation()
32+
{
33+
co_await 10ms;
34+
throw hresult_invalid_argument(L"Async");
35+
co_return 1;
36+
}
37+
38+
IAsyncOperationWithProgress<int, int> OperationWithProgress()
39+
{
40+
co_await 10ms;
41+
throw hresult_invalid_argument(L"Async");
42+
co_return 1;
43+
}
44+
45+
template <typename F>
46+
void Check(F make)
47+
{
48+
try
49+
{
50+
make().get();
51+
REQUIRE(false);
52+
}
53+
catch (hresult_invalid_argument const& e)
54+
{
55+
REQUIRE(e.message() == L"Async");
56+
}
57+
58+
handle completed{ CreateEvent(nullptr, true, false, nullptr) };
59+
auto async = make();
60+
61+
async.Completed([&](auto&& sender, AsyncStatus status)
62+
{
63+
REQUIRE(async == sender);
64+
REQUIRE(status == AsyncStatus::Error);
65+
SetEvent(completed.get());
66+
});
67+
68+
REQUIRE(WaitForSingleObject(completed.get(), 1000) == WAIT_OBJECT_0);
69+
REQUIRE(async.Status() == AsyncStatus::Error);
70+
71+
hresult_error e(async.ErrorCode(), take_ownership_from_abi);
72+
REQUIRE(e.message() == L"Async");
73+
74+
try
75+
{
76+
async.GetResults();
77+
REQUIRE(false);
78+
}
79+
catch (hresult_invalid_argument const& e)
80+
{
81+
REQUIRE(e.message() == L"Async");
82+
}
83+
}
84+
}
85+
86+
TEST_CASE("async_throw")
87+
{
88+
Check(Action);
89+
Check(ActionWithProgress);
90+
Check(Operation);
91+
Check(OperationWithProgress);
92+
}

test/test_cpp20/await_completed.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
#include "pch.h"
1+
#include <intrin.h>
2+
3+
#include "catch.hpp"
4+
5+
import std;
6+
import Windows.Foundation;
27

38
using namespace winrt;
49
using namespace Windows::Foundation;

test/test_cpp20/clang_only.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "pch.h"
1+
#include <winrt/Windows.Foundation.h>
22
#include <winrt/Windows.Storage.Pickers.h>
33

44
#ifdef __clang__

test/test_cpp20/custom_error.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
#include "pch.h"
1+
#include "catch.hpp"
2+
#include <Windows.h>
3+
4+
import std;
5+
import winrt.base;
6+
import Windows.Foundation;
27

38
using namespace winrt;
49
using namespace Windows::Foundation;
@@ -35,12 +40,7 @@ namespace
3540
}
3641
}
3742

38-
#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 170000
39-
// <source_location> not available in libc++ before LLVM 16
40-
TEST_CASE("custom_error_logger_on_throw", "[!shouldfail]")
41-
#else
4243
TEST_CASE("custom_error_logger_on_throw")
43-
#endif
4444
{
4545
// Set up global handler
4646
REQUIRE(!s_loggerCalled);
@@ -80,12 +80,7 @@ void HresultOnLine80(Args... args)
8080
winrt::hresult_canceled(std::forward<Args>(args)...);
8181
}
8282

83-
#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 170000
84-
// <source_location> not available in libc++ before LLVM 16
85-
TEST_CASE("custom_error_logger_on_originate", "[!shouldfail]")
86-
#else
8783
TEST_CASE("custom_error_logger_on_originate")
88-
#endif
8984
{
9085
// Set up global handler
9186
REQUIRE(!s_loggerCalled);

test/test_cpp20/format.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
#include "pch.h"
1+
#include "catch.hpp"
22

3-
#ifdef __cpp_lib_format
4-
#include <format>
3+
import std;
4+
import winrt.base;
5+
import Windows.Foundation;
6+
import Windows.Data.Json;
57

68
struct stringable : winrt::implements<stringable, winrt::Windows::Foundation::IStringable>
79
{
@@ -37,7 +39,6 @@ TEST_CASE("format_json")
3739

3840
TEST_CASE("format_wstring")
3941
{
40-
#if __cpp_lib_format >= 202207L
4142
{
4243
std::wstring str = L"World";
4344
REQUIRE(winrt::format(L"Hello {}", str) == L"Hello World");
@@ -46,6 +47,4 @@ TEST_CASE("format_wstring")
4647
{
4748
REQUIRE(winrt::format(L"C++/WinRT #{:d}", 1) == L"C++/WinRT #1");
4849
}
49-
#endif
5050
}
51-
#endif

test/test_cpp20/hstring.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
#include "pch.h"
1+
#include "catch.hpp"
2+
3+
import std;
4+
import winrt.base;
25

36
TEST_CASE("hstring")
47
{

test/test_cpp20/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#define CATCH_CONFIG_WINDOWS_SEH
66

77
#include "catch.hpp"
8-
#include "winrt/base.h"
8+
import std;
9+
import winrt.base;
910

1011
using namespace winrt;
1112

test/test_cpp20/pch.cpp

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)