Skip to content
Merged
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ jobs:
run: |
mkdir build
cd build
cmake ../ -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug
cmake --build . --target cppwinrt
cmake ../ -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug -DDOWNLOAD_WINDOWSNUMERICS=TRUE
cmake --build . -j2 --target cppwinrt

- name: Upload cppwinrt.exe
uses: actions/upload-artifact@v3
Expand All @@ -307,7 +307,7 @@ jobs:
- name: Build tests
run: |
cd build
cmake --build . --target test-vanilla test_win7
cmake --build . -j2 --target test-vanilla test_cpp20 test_win7 test_old

- name: Upload test binaries
uses: actions/upload-artifact@v3
Expand Down
4 changes: 2 additions & 2 deletions cppwinrt/cmd_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#include <filesystem>
#include <fstream>
#include <regex>
#include <Windows.h>
#include <windows.h>
#include <shlwapi.h>
#include <XmlLite.h>
#include <xmllite.h>

namespace cppwinrt
{
Expand Down
2 changes: 1 addition & 1 deletion strings/base_includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <utility>
#include <vector>

#if __has_include(<WindowsNumerics.impl.h>)
#if __has_include(<windowsnumerics.impl.h>)
#define WINRT_IMPL_NUMERICS
#include <directxmath.h>
#endif
Expand Down
2 changes: 1 addition & 1 deletion strings/base_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#define _WINDOWS_NUMERICS_NAMESPACE_ winrt::Windows::Foundation::Numerics
#define _WINDOWS_NUMERICS_BEGIN_NAMESPACE_ WINRT_EXPORT namespace winrt::Windows::Foundation::Numerics
#define _WINDOWS_NUMERICS_END_NAMESPACE_
#include <WindowsNumerics.impl.h>
#include <windowsnumerics.impl.h>
#undef _WINDOWS_NUMERICS_NAMESPACE_
#undef _WINDOWS_NUMERICS_BEGIN_NAMESPACE_
#undef _WINDOWS_NUMERICS_END_NAMESPACE_
Expand Down
34 changes: 34 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,35 @@ if(TARGET_IS_X64)
endif()


# Some tests requires windowsnumerics.impl.h, but mingw-w64 didn't have this
# header until very recently. In case it is not present, download a copy if
# DOWNLOAD_WINDOWSNUMERICS is true, otherwise skip the tests which depend on
# this header.
function(TestHasWindowsnumerics OUTPUT_VARNAME)
include(CheckCXXSourceCompiles)
check_cxx_source_compiles("
#define _WINDOWS_NUMERICS_NAMESPACE_ winrt::Windows::Foundation::Numerics
#define _WINDOWS_NUMERICS_BEGIN_NAMESPACE_ WINRT_EXPORT namespace winrt::Windows::Foundation::Numerics
#define _WINDOWS_NUMERICS_END_NAMESPACE_
#include <windowsnumerics.impl.h>
int main() {}
" ${OUTPUT_VARNAME})
endfunction()
TestHasWindowsnumerics(HAS_WINDOWSNUMERICS)
set(DOWNLOAD_WINDOWSNUMERICS FALSE CACHE BOOL "Whether to download a copy of mingw-w64's windowsnumerics.impl.h if not available.")
if(NOT HAS_WINDOWSNUMERICS AND DOWNLOAD_WINDOWSNUMERICS)
file(
DOWNLOAD https://github.com/mingw-w64/mingw-w64/raw/2b6272b31132e156dd1fc3722c1aa96b705a90dd/mingw-w64-headers/include/windowsnumerics.impl.h
"${CMAKE_CURRENT_BINARY_DIR}/windowsnumerics/windowsnumerics.impl.h"
EXPECTED_HASH SHA256=aff42491e57583c8ad8ca8e71d417a553bd1215ee9a71378679400ecded4b1ab
SHOW_PROGRESS
)
include_directories("${CMAKE_CURRENT_BINARY_DIR}/windowsnumerics")
set(HAS_WINDOWSNUMERICS TRUE)
message(STATUS "Using windowsnumerics.impl.h downloaded from mingw-w64")
endif()


add_custom_command(
OUTPUT
"${CMAKE_CURRENT_BINARY_DIR}/cppwinrt/winrt/base.h"
Expand All @@ -37,4 +66,9 @@ add_custom_target(build-cppwinrt-projection


add_subdirectory(test)
add_subdirectory(test_cpp20)
add_subdirectory(test_win7)

if(HAS_WINDOWSNUMERICS)
add_subdirectory(old_tests)
endif()
1 change: 1 addition & 0 deletions test/old_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(UnitTests)
61 changes: 61 additions & 0 deletions test/old_tests/UnitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
file(GLOB TEST_SRCS
LIST_DIRECTORIES false
CONFIGURE_DEPENDS
*.cpp
)
list(FILTER TEST_SRCS EXCLUDE REGEX "/(Main|pch)\\.cpp")


# We can't build custom Component for mingw-w64 because it doesn't have an
# alternative to midl that can produce winmd files.
list(APPEND BROKEN_TESTS
Boxing2
Composable
Errors
Events
FastInput
Parameters
StructCodeGen
Structures
delegate_weak_strong
factory_cache
get_activation_factory
smart_pointers
)

list(APPEND BROKEN_TESTS
# Missing `Windows.Applicationmodel.Activation.h`
constexpr

# Missing `Windows.ApplicationModel.Appointments.h`
enum_flags

# Missing component `Reflect`.
# Test is also not included in the VS project.
reflect

# Segfault in winrt::impl::natvis::abi_val.
# Test is also not included in the VS project.
natvis
)

# Exclude broken tests
foreach(TEST_SRCS_EXCLUDE_ITEM IN LISTS BROKEN_TESTS)
list(FILTER TEST_SRCS EXCLUDE REGEX "/${TEST_SRCS_EXCLUDE_ITEM}\\.cpp")
endforeach()

add_executable(test_old Main.cpp ${TEST_SRCS})
target_link_libraries(test_old runtimeobject synchronization)

target_precompile_headers(test_old PRIVATE pch.h)
set_source_files_properties(
conditional_implements_pure.cpp
PROPERTIES SKIP_PRECOMPILE_HEADERS true
)

add_dependencies(test_old build-cppwinrt-projection)

add_test(
NAME test_old
COMMAND "$<TARGET_FILE:test_old>"
)
5 changes: 5 additions & 0 deletions test/old_tests/UnitTests/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#include "pch.h"

#define CATCH_CONFIG_RUNNER

// Force reportFatal to be available on mingw-w64
#define CATCH_CONFIG_WINDOWS_SEH

#include "catch.hpp"

int main(int argc, char * argv[])
Expand All @@ -14,6 +18,7 @@ int main(int argc, char * argv[])
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
SetThreadUILanguage(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
int const result = Catch::Session().run(argc, argv);

// Completely unnecessary in an app, but useful for testing clear_factory_cache behavior.
Expand Down
4 changes: 2 additions & 2 deletions test/old_tests/UnitTests/VariadicDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ TEST_CASE("Variadic delegate - event")

TEST_CASE("Variadic delegate - exception")
{
delegate<> d = [] { throw std::exception("what"); };
delegate<> d = [] { throw std::runtime_error("what"); };
REQUIRE_THROWS_AS(d(), std::exception);
}

Expand All @@ -120,4 +120,4 @@ TEST_CASE("Variadic delegate - object")
REQUIRE(object.m_state == 0);
d(123);
REQUIRE(object.m_state == 123);
}
}
4 changes: 2 additions & 2 deletions test/old_tests/UnitTests/agile_ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ IAsyncAction test_agile_ref()
});
}

#if defined(__clang__) && (defined(_M_IX86) || defined(__i386__))
// FIXME: Test is known to crash with exit code 0x80000003 (breakpoint?) on x86 when built with Clang.
#if defined(__clang__) && defined(_MSC_VER) && (defined(_M_IX86) || defined(__i386__))
// FIXME: Test is known to crash from calling invalid address on x86 when built with Clang.
TEST_CASE("agile_ref", "[.clang-crash]")
#else
TEST_CASE("agile_ref")
Expand Down
21 changes: 20 additions & 1 deletion test/old_tests/UnitTests/apartment_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ namespace
co_await context;
}

// Not yet buildable on mingw-w64. The lambda needs to have __stdcall
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this lambda has no captures, it can be converted to a normal function with __stdcall.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That can work though it's not as clean as it currently is. However, the test that actually requires this code cannot be built due to missing __uuidof(IContextCallback) (which has been fixed on mingw-w64 upstream, but the current llvm-mingw 15 toolchain doesn't have the fix), so there is no harm just leaving this out for now.

// specified on it but there is a Clang crash bug blocking this:
// https://github.com/llvm/llvm-project/issues/58366
#if !defined(__MINGW32__)

template<typename TLambda>
void InvokeInContext(IContextCallback* context, TLambda&& lambda)
{
Expand All @@ -69,6 +74,8 @@ namespace
return context;
}

#endif

bool is_nta_on_mta()
{
APTTYPE type;
Expand All @@ -90,6 +97,10 @@ namespace
return (hr == RPC_E_SERVER_DIED_DNE) || (hr == RPC_E_DISCONNECTED);
}

// Not yet buildable on mingw-w64.
// Missing __uuidof(IContextCallback).
#if !defined(__MINGW32__)

IAsyncAction TestNeutralApartmentContext()
{
auto controller = DispatcherQueueController::CreateOnDedicatedThread();
Expand All @@ -102,6 +113,8 @@ namespace
REQUIRE(is_nta_on_mta());
}

#endif

IAsyncAction TestStaToStaApartmentContext()
{
bool pass = false;
Expand Down Expand Up @@ -245,17 +258,23 @@ TEST_CASE("apartment_context coverage")
Async().get();
}

// Not yet buildable on mingw-w64.
// Missing __uuidof(IContextCallback).
#if !defined(__MINGW32__)

TEST_CASE("apartment_context nta")
{
TestNeutralApartmentContext().get();
}

#endif

TEST_CASE("apartment_context sta")
{
TestStaToStaApartmentContext().get();
}

#if defined(__clang__) && (defined(_M_IX86) || defined(__i386__))
#if defined(__clang__) && defined(_MSC_VER) && (defined(_M_IX86) || defined(__i386__))
// FIXME: Test is known to segfault on x86 when built with Clang.
TEST_CASE("apartment_context disconnected", "[.clang-crash]")
#else
Expand Down
7 changes: 7 additions & 0 deletions test/old_tests/UnitTests/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,13 +941,20 @@ TEST_CASE("array_view,cv array_view")
array_view<volatile int> a2 = a;
REQUIRE(a2.data() == a.data());
REQUIRE(a2.size() == 3);
// For libc++ as of LLVM 15, std::equal is unable to compare between
// volatile and non-volatile elements of ranges.
// https://github.com/llvm/llvm-project/issues/59021
#if !defined(_LIBCPP_VERSION) || _LIBCPP_VERSION >= 160000
REQUIRE(a2 == a);
#endif
}
{
array_view<const volatile int> a2 = a;
REQUIRE(a2.data() == a.data());
REQUIRE(a2.size() == 3);
#if !defined(_LIBCPP_VERSION) || _LIBCPP_VERSION >= 160000
REQUIRE(a2 == a);
#endif
}
}

Expand Down
Loading