diff --git a/test/osx/test.mm b/test/osx/test.mm index f3ea6bfc9866d8e00531688b60abf44bb92aa400..df231ca06476119060da4023576432e63088b30f 100644 --- a/test/osx/test.mm +++ b/test/osx/test.mm @@ -18,19 +18,23 @@ static const int cy = 600; /* --------------------------------------------------- */ -using SourceContext = std::unique_ptr>; -static SourceContext autorelease(obs_source_t s) +template +struct OBSUniqueHandle : std::unique_ptr> { - return SourceContext(s, obs_source_release); -} + using base = std::unique_ptr>; + explicit OBSUniqueHandle(T *obj) : base(obj, D) {} + operator T*() { return base::get(); } +}; -using SceneContext = std::unique_ptr>; -static SceneContext autorelease(obs_scene_t s) -{ - return SceneContext(s, obs_scene_destroy); -} +#define DECLARE_DELETER(x) decltype(x), x + +using SourceContext = OBSUniqueHandle; + +using SceneContext = OBSUniqueHandle; + +#undef DECLARE_DELETER /* --------------------------------------------------- */ @@ -144,30 +148,30 @@ static void test() /* ------------------------------------------------------ */ /* create source */ - SourceContext source = autorelease(obs_source_create( - SOURCE_INPUT, "random", NULL)); + SourceContext source{obs_source_create(SOURCE_INPUT, + "random", NULL)}; if (!source) throw "Couldn't create random test source"; /* ------------------------------------------------------ */ /* create filter */ - SourceContext filter = autorelease(obs_source_create( - SOURCE_FILTER, "test", NULL)); + SourceContext filter{obs_source_create(SOURCE_FILTER, + "test", NULL)}; if (!filter) throw "Couldn't create test filter"; - obs_source_filter_add(source.get(), filter.get()); + obs_source_filter_add(source, filter); /* ------------------------------------------------------ */ /* create scene and add source to scene (twice) */ - SceneContext scene = autorelease(obs_scene_create()); + SceneContext scene{obs_scene_create()}; if (!scene) throw "Couldn't create scene"; - AddTestItems(scene.get(), source.get()); + AddTestItems(scene, source); /* ------------------------------------------------------ */ /* set the scene as the primary draw source and go */ - obs_set_output_source(0, obs_scene_getsource(scene.get())); + obs_set_output_source(0, obs_scene_getsource(scene)); [NSApp run];