The open source OpenXR runtime
1// Copyright 2021, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Miscellanous C++ wrapper tests.
6 * @author Rylie Pavlik <rylie.pavlik@collabora.com>
7 */
8
9#include <iostream>
10#include <xrt/xrt_device.hpp>
11
12#include "catch_amalgamated.hpp"
13
14
15struct silly_device
16{
17 xrt_device base{};
18 bool *destroyed;
19
20
21 silly_device(bool &destroyed_) : destroyed(&destroyed_)
22 {
23 base.destroy = [](xrt_device *xdev) { delete reinterpret_cast<silly_device *>(xdev); };
24 }
25 ~silly_device()
26 {
27 *destroyed = true;
28 }
29};
30
31TEST_CASE("unique_xrt_device")
32{
33
34 bool destroyed = false;
35 {
36 // make the device
37 auto specific = std::make_unique<silly_device>(destroyed);
38 CHECK_FALSE(destroyed);
39
40 // use the generic unique_ptr
41 xrt::unique_xrt_device generic(&(specific.release()->base));
42 CHECK_FALSE(destroyed);
43 }
44 // make sure it went away
45 CHECK(destroyed);
46}