diff --git a/cppwinrt/main.cpp b/cppwinrt/main.cpp index 1c6aadc36..1e39767c1 100644 --- a/cppwinrt/main.cpp +++ b/cppwinrt/main.cpp @@ -680,10 +680,6 @@ R"( local Local ^%WinDir^%\System32\WinMetadata folder write_module_h(); } write_base_h(); - if (!settings.modules) - { - ixx.flush_to_file(settings.output_folder + "winrt/winrt.ixx"); - } } if (settings.component) diff --git a/test/test_component/test_component.vcxproj b/test/test_component/test_component.vcxproj index fcd32a79d..084ad0d40 100644 --- a/test/test_component/test_component.vcxproj +++ b/test/test_component/test_component.vcxproj @@ -383,7 +383,7 @@ - $(CppWinRTDir)cppwinrt -in local -out $(OutputPath) -verbose + $(CppWinRTDir)cppwinrt -in local -out $(OutputPath) -verbose -modules $(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 Projecting Windows and component metadata into $(OutputPath) diff --git a/test/test_cpp20/array_span.cpp b/test/test_cpp20/array_span.cpp index 69fd7aa36..dd27d6358 100644 --- a/test/test_cpp20/array_span.cpp +++ b/test/test_cpp20/array_span.cpp @@ -1,6 +1,10 @@ -#include "pch.h" +#include #include "catch.hpp" -#include + +import std; +import Windows.Foundation; +import Windows.Storage.Streams; +import Windows.Data.Json; using namespace winrt; using namespace Windows::Foundation; @@ -10,7 +14,7 @@ using namespace Windows::Data::Json; // // This is a helper to create a data reader for use in testing arrays. // -static IAsyncOperation CreateDataReader(std::initializer_list /*values*/) +static IAsyncOperation CreateDataReader(std::initializer_list /*values*/) { InMemoryRandomAccessStream stream; DataWriter writer(stream); @@ -32,8 +36,8 @@ TEST_CASE("array,DataReader,std::span") { auto reader = CreateDataReader({ 1, 2, 3 }).get(); - std::array a{}; - std::span sp(a); + std::array a{}; + std::span sp(a); reader.ReadBytes(sp); // FillArray pattern REQUIRE(a.size() == 3); @@ -49,7 +53,7 @@ TEST_CASE("array,DataReader,std::span,direct") { auto reader = CreateDataReader({ 1, 2, 3 }).get(); - std::array a{}; + std::array a{}; reader.ReadBytes(a); // FillArray pattern REQUIRE(a.size() == 3); @@ -154,7 +158,7 @@ TEST_CASE("array_view,span,ctad") #define REQUIRE_DEDUCED_AS(T, ...) \ static_assert(std::is_same_v, decltype(array_view(__VA_ARGS__))>) - std::uint8_t a[] = {1, 2, 3}; + std::uint8_t a[] = { 1, 2, 3 }; std::span sp{ a }; REQUIRE_DEDUCED_AS(std::uint8_t, sp); diff --git a/test/test_cpp20/async.cpp b/test/test_cpp20/async.cpp new file mode 100644 index 000000000..978825868 --- /dev/null +++ b/test/test_cpp20/async.cpp @@ -0,0 +1,92 @@ +#include +#include "catch.hpp" + +import std; +import Windows.Foundation; + +using namespace winrt; +using namespace Windows::Foundation; +using namespace std::chrono_literals; + +namespace +{ + // + // Just some quick tests to make sure that coroutines compile and work with C++20 modules. + // Taken from async_throw in test + // + // TODO: make a new project for this + + IAsyncAction Action() + { + co_await 10ms; + throw hresult_invalid_argument(L"Async"); + } + + IAsyncActionWithProgress ActionWithProgress() + { + co_await 10ms; + throw hresult_invalid_argument(L"Async"); + } + + IAsyncOperation Operation() + { + co_await 10ms; + throw hresult_invalid_argument(L"Async"); + co_return 1; + } + + IAsyncOperationWithProgress OperationWithProgress() + { + co_await 10ms; + throw hresult_invalid_argument(L"Async"); + co_return 1; + } + + template + void Check(F make) + { + try + { + make().get(); + REQUIRE(false); + } + catch (hresult_invalid_argument const& e) + { + REQUIRE(e.message() == L"Async"); + } + + handle completed{ CreateEvent(nullptr, true, false, nullptr) }; + auto async = make(); + + async.Completed([&](auto&& sender, AsyncStatus status) + { + REQUIRE(async == sender); + REQUIRE(status == AsyncStatus::Error); + SetEvent(completed.get()); + }); + + REQUIRE(WaitForSingleObject(completed.get(), 1000) == WAIT_OBJECT_0); + REQUIRE(async.Status() == AsyncStatus::Error); + + hresult_error e(async.ErrorCode(), take_ownership_from_abi); + REQUIRE(e.message() == L"Async"); + + try + { + async.GetResults(); + REQUIRE(false); + } + catch (hresult_invalid_argument const& e) + { + REQUIRE(e.message() == L"Async"); + } + } +} + +TEST_CASE("async_throw") +{ + Check(Action); + Check(ActionWithProgress); + Check(Operation); + Check(OperationWithProgress); +} \ No newline at end of file diff --git a/test/test_cpp20/await_completed.cpp b/test/test_cpp20/await_completed.cpp index b1ba9e209..779f6d15c 100644 --- a/test/test_cpp20/await_completed.cpp +++ b/test/test_cpp20/await_completed.cpp @@ -1,4 +1,9 @@ -#include "pch.h" +#include + +#include "catch.hpp" + +import std; +import Windows.Foundation; using namespace winrt; using namespace Windows::Foundation; diff --git a/test/test_cpp20/clang_only.cpp b/test/test_cpp20/clang_only.cpp index 45aa4b380..88b90d71b 100644 --- a/test/test_cpp20/clang_only.cpp +++ b/test/test_cpp20/clang_only.cpp @@ -1,4 +1,4 @@ -#include "pch.h" +#include #include #ifdef __clang__ diff --git a/test/test_cpp20/custom_error.cpp b/test/test_cpp20/custom_error.cpp index fbaf407f9..08f5c6eb9 100644 --- a/test/test_cpp20/custom_error.cpp +++ b/test/test_cpp20/custom_error.cpp @@ -1,4 +1,9 @@ -#include "pch.h" +#include "catch.hpp" +#include + +import std; +import winrt.base; +import Windows.Foundation; using namespace winrt; using namespace Windows::Foundation; @@ -35,12 +40,7 @@ namespace } } -#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 170000 -// not available in libc++ before LLVM 16 -TEST_CASE("custom_error_logger_on_throw", "[!shouldfail]") -#else TEST_CASE("custom_error_logger_on_throw") -#endif { // Set up global handler REQUIRE(!s_loggerCalled); @@ -80,12 +80,7 @@ void HresultOnLine80(Args... args) winrt::hresult_canceled(std::forward(args)...); } -#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 170000 -// not available in libc++ before LLVM 16 -TEST_CASE("custom_error_logger_on_originate", "[!shouldfail]") -#else TEST_CASE("custom_error_logger_on_originate") -#endif { // Set up global handler REQUIRE(!s_loggerCalled); diff --git a/test/test_cpp20/format.cpp b/test/test_cpp20/format.cpp index d16193328..f7c59da39 100644 --- a/test/test_cpp20/format.cpp +++ b/test/test_cpp20/format.cpp @@ -1,7 +1,9 @@ -#include "pch.h" +#include "catch.hpp" -#ifdef __cpp_lib_format -#include +import std; +import winrt.base; +import Windows.Foundation; +import Windows.Data.Json; struct stringable : winrt::implements { @@ -37,7 +39,6 @@ TEST_CASE("format_json") TEST_CASE("format_wstring") { -#if __cpp_lib_format >= 202207L { std::wstring str = L"World"; REQUIRE(winrt::format(L"Hello {}", str) == L"Hello World"); @@ -46,6 +47,4 @@ TEST_CASE("format_wstring") { REQUIRE(winrt::format(L"C++/WinRT #{:d}", 1) == L"C++/WinRT #1"); } -#endif } -#endif diff --git a/test/test_cpp20/hstring.cpp b/test/test_cpp20/hstring.cpp index 57d145fbb..f81ae641a 100644 --- a/test/test_cpp20/hstring.cpp +++ b/test/test_cpp20/hstring.cpp @@ -1,4 +1,7 @@ -#include "pch.h" +#include "catch.hpp" + +import std; +import winrt.base; TEST_CASE("hstring") { diff --git a/test/test_cpp20/main.cpp b/test/test_cpp20/main.cpp index 30687e00c..a6ff65c63 100644 --- a/test/test_cpp20/main.cpp +++ b/test/test_cpp20/main.cpp @@ -5,7 +5,8 @@ #define CATCH_CONFIG_WINDOWS_SEH #include "catch.hpp" -#include "winrt/base.h" +import std; +import winrt.base; using namespace winrt; diff --git a/test/test_cpp20/pch.cpp b/test/test_cpp20/pch.cpp deleted file mode 100644 index 1d9f38c57..000000000 --- a/test/test_cpp20/pch.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "pch.h" diff --git a/test/test_cpp20/pch.h b/test/test_cpp20/pch.h deleted file mode 100644 index c1a8f5ff3..000000000 --- a/test/test_cpp20/pch.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#pragma warning(4: 4458) // ensure we compile clean with this warning enabled - -#define WINRT_LEAN_AND_MEAN -#include -#include "winrt/Windows.Data.Json.h" -#include "winrt/Windows.Foundation.h" -#include "winrt/Windows.Foundation.Collections.h" -#include "winrt/Windows.Foundation.Numerics.h" -#include "winrt/Windows.Storage.Streams.h" -#include -#include "catch.hpp" - -#include - -using namespace std::literals; diff --git a/test/test_cpp20/ranges.cpp b/test/test_cpp20/ranges.cpp index 9df542696..8ef0b2ba5 100644 --- a/test/test_cpp20/ranges.cpp +++ b/test/test_cpp20/ranges.cpp @@ -1,8 +1,7 @@ -#include "pch.h" +#include "catch.hpp" -#ifdef __cpp_lib_ranges -#include -#include +import std; +import Windows.Foundation.Collections; TEST_CASE("ranges") { @@ -48,4 +47,3 @@ TEST_CASE("ranges") REQUIRE((result == std::vector{ 2, 4, 6 })); } } -#endif diff --git a/test/test_cpp20/test_cpp20.vcxproj b/test/test_cpp20/test_cpp20.vcxproj index f8eacff83..82cd7eb5c 100644 --- a/test/test_cpp20/test_cpp20.vcxproj +++ b/test/test_cpp20/test_cpp20.vcxproj @@ -32,6 +32,7 @@ unittests test_cpp20 20 + true @@ -99,6 +100,7 @@ $(OutputPath);Generated Files;..\ NOMINMAX;_MBCS;%(PreprocessorDefinitions) MultiThreaded + NotUsing Level4 true %(AdditionalOptions) -O3 -flto -fwhole-program-vtables @@ -122,6 +124,7 @@ Disabled $(OutputPath);Generated Files;..\ NOMINMAX;_MBCS;%(PreprocessorDefinitions) + NotUsing MultiThreadedDebug Level4 true @@ -144,6 +147,7 @@ Disabled $(OutputPath);Generated Files;..\ NOMINMAX;_MBCS;%(PreprocessorDefinitions) + NotUsing MultiThreadedDebug Level4 true @@ -166,6 +170,7 @@ Disabled $(OutputPath);Generated Files;..\ NOMINMAX;_MBCS;%(PreprocessorDefinitions) + NotUsing MultiThreadedDebug Level4 true @@ -190,6 +195,7 @@ true $(OutputPath);Generated Files;..\ NOMINMAX;_MBCS;%(PreprocessorDefinitions) + NotUsing MultiThreaded Level4 true @@ -216,6 +222,7 @@ true $(OutputPath);Generated Files;..\ NOMINMAX;_MBCS;%(PreprocessorDefinitions) + NotUsing MultiThreaded Level4 true @@ -236,21 +243,15 @@ - - - + + - - NotUsing - - - Create - +