Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions cppwinrt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/test_component/test_component.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@
<ItemDefinitionGroup>
<CustomBuildStep>
<Command>
$(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
</Command>
<Message>Projecting Windows and component metadata into $(OutputPath)</Message>
Expand Down
18 changes: 11 additions & 7 deletions test/test_cpp20/array_span.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include "pch.h"
#include <Windows.h>
#include "catch.hpp"
#include <array>

import std;
import Windows.Foundation;
import Windows.Storage.Streams;
import Windows.Data.Json;

using namespace winrt;
using namespace Windows::Foundation;
Expand All @@ -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<IDataReader> CreateDataReader(std::initializer_list<byte> /*values*/)
static IAsyncOperation<IDataReader> CreateDataReader(std::initializer_list<std::uint8_t> /*values*/)
{
InMemoryRandomAccessStream stream;
DataWriter writer(stream);
Expand All @@ -32,8 +36,8 @@ TEST_CASE("array,DataReader,std::span")
{
auto reader = CreateDataReader({ 1, 2, 3 }).get();

std::array<byte, 3> a{};
std::span<byte> sp(a);
std::array<std::uint8_t, 3> a{};
std::span<std::uint8_t> sp(a);
reader.ReadBytes(sp); // FillArray pattern

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

std::array<byte, 3> a{};
std::array<std::uint8_t, 3> a{};
reader.ReadBytes(a); // FillArray pattern

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

std::uint8_t a[] = {1, 2, 3};
std::uint8_t a[] = { 1, 2, 3 };
std::span<std::uint8_t, 3> sp{ a };

REQUIRE_DEDUCED_AS(std::uint8_t, sp);
Expand Down
92 changes: 92 additions & 0 deletions test/test_cpp20/async.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include <Windows.h>
#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<int> ActionWithProgress()
{
co_await 10ms;
throw hresult_invalid_argument(L"Async");
}

IAsyncOperation<int> Operation()
{
co_await 10ms;
throw hresult_invalid_argument(L"Async");
co_return 1;
}

IAsyncOperationWithProgress<int, int> OperationWithProgress()
{
co_await 10ms;
throw hresult_invalid_argument(L"Async");
co_return 1;
}

template <typename F>
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);
}
7 changes: 6 additions & 1 deletion test/test_cpp20/await_completed.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#include "pch.h"
#include <intrin.h>

#include "catch.hpp"

import std;
import Windows.Foundation;

using namespace winrt;
using namespace Windows::Foundation;
Expand Down
2 changes: 1 addition & 1 deletion test/test_cpp20/clang_only.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "pch.h"
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Storage.Pickers.h>

#ifdef __clang__
Expand Down
17 changes: 6 additions & 11 deletions test/test_cpp20/custom_error.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#include "pch.h"
#include "catch.hpp"
#include <Windows.h>

import std;
import winrt.base;
import Windows.Foundation;

using namespace winrt;
using namespace Windows::Foundation;
Expand Down Expand Up @@ -35,12 +40,7 @@ namespace
}
}

#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 170000
// <source_location> 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);
Expand Down Expand Up @@ -80,12 +80,7 @@ void HresultOnLine80(Args... args)
winrt::hresult_canceled(std::forward<Args>(args)...);
}

#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 170000
// <source_location> 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);
Expand Down
11 changes: 5 additions & 6 deletions test/test_cpp20/format.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "pch.h"
#include "catch.hpp"

#ifdef __cpp_lib_format
#include <format>
import std;
import winrt.base;
import Windows.Foundation;
import Windows.Data.Json;

struct stringable : winrt::implements<stringable, winrt::Windows::Foundation::IStringable>
{
Expand Down Expand Up @@ -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");
Expand All @@ -46,6 +47,4 @@ TEST_CASE("format_wstring")
{
REQUIRE(winrt::format(L"C++/WinRT #{:d}", 1) == L"C++/WinRT #1");
}
#endif
}
#endif
5 changes: 4 additions & 1 deletion test/test_cpp20/hstring.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include "pch.h"
#include "catch.hpp"

import std;
import winrt.base;

TEST_CASE("hstring")
{
Expand Down
3 changes: 2 additions & 1 deletion test/test_cpp20/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#define CATCH_CONFIG_WINDOWS_SEH

#include "catch.hpp"
#include "winrt/base.h"
import std;
import winrt.base;

using namespace winrt;

Expand Down
1 change: 0 additions & 1 deletion test/test_cpp20/pch.cpp

This file was deleted.

17 changes: 0 additions & 17 deletions test/test_cpp20/pch.h

This file was deleted.

8 changes: 3 additions & 5 deletions test/test_cpp20/ranges.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "pch.h"
#include "catch.hpp"

#ifdef __cpp_lib_ranges
#include <algorithm>
#include <ranges>
import std;
import Windows.Foundation.Collections;

TEST_CASE("ranges")
{
Expand Down Expand Up @@ -48,4 +47,3 @@ TEST_CASE("ranges")
REQUIRE((result == std::vector{ 2, 4, 6 }));
}
}
#endif
19 changes: 10 additions & 9 deletions test/test_cpp20/test_cpp20.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<RootNamespace>unittests</RootNamespace>
<ProjectName>test_cpp20</ProjectName>
<CppWinRTLanguageStandard>20</CppWinRTLanguageStandard>
<BuildStlModules>true</BuildStlModules>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand Down Expand Up @@ -99,6 +100,7 @@
<AdditionalIncludeDirectories>$(OutputPath);Generated Files;..\</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NOMINMAX;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
<AdditionalOptions Condition="'$(Clang)'=='1'">%(AdditionalOptions) -O3 -flto -fwhole-program-vtables</AdditionalOptions>
Expand All @@ -122,6 +124,7 @@
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>$(OutputPath);Generated Files;..\</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NOMINMAX;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
Expand All @@ -144,6 +147,7 @@
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>$(OutputPath);Generated Files;..\</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NOMINMAX;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
Expand All @@ -166,6 +170,7 @@
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>$(OutputPath);Generated Files;..\</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NOMINMAX;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
Expand All @@ -190,6 +195,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>$(OutputPath);Generated Files;..\</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NOMINMAX;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
Expand All @@ -216,6 +222,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>$(OutputPath);Generated Files;..\</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NOMINMAX;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
Expand All @@ -236,21 +243,15 @@
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(CppWinRTDir)winrt\*.ixx" />
<ClCompile Include="async.cpp" />
<ClCompile Include="array_span.cpp" />
<ClCompile Include="await_completed.cpp" />
<ClCompile Include="clang_only.cpp" />
<ClCompile Include="custom_error.cpp" />
<ClCompile Include="format.cpp" />
<ClCompile Include="hstring.cpp" />
<ClCompile Include="main.cpp">
<PrecompiledHeader>NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="pch.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="main.cpp" />
<ClCompile Include="ranges.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
Loading