forked from microsoft/xlang
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved diagnostics for detecting direct allocations in C++/WinRT (m…
- Loading branch information
Showing
3 changed files
with
90 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// This test validates that defining WINRT_NO_MAKE_DETECTION actually | ||
// allows an implementation to be final and have a private destructor. | ||
// This is *not* recommended as there are no safeguards for direct and | ||
// invalid allocations, but is provided for compatibility. | ||
|
||
#define WINRT_NO_MAKE_DETECTION | ||
#include "catch.hpp" | ||
#include "winrt/Windows.Foundation.h" | ||
|
||
using namespace winrt; | ||
using namespace Windows::Foundation; | ||
|
||
namespace | ||
{ | ||
struct Stringable final : implements<Stringable, IStringable> | ||
{ | ||
hstring ToString() | ||
{ | ||
return L"Stringable"; | ||
} | ||
|
||
inline static bool Destroyed{}; | ||
|
||
private: | ||
|
||
~Stringable() | ||
{ | ||
Destroyed = true; | ||
} | ||
}; | ||
} | ||
|
||
TEST_CASE("no_make_detection") | ||
{ | ||
{ | ||
IStringable stringable{ (new Stringable())->get_abi<IStringable>(), take_ownership_from_abi }; | ||
REQUIRE(!Stringable::Destroyed); | ||
stringable = nullptr; | ||
REQUIRE(Stringable::Destroyed); | ||
} | ||
{ | ||
Stringable::Destroyed = false; | ||
IStringable stringable = make<Stringable>(); | ||
REQUIRE(!Stringable::Destroyed); | ||
stringable = nullptr; | ||
REQUIRE(Stringable::Destroyed); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters