Zrythm v2.0.0-alpha.1
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
uuid_reference_test.h
1// SPDX-FileCopyrightText: © 2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "utils/object_registry.h"
7#include "utils/registry_utils.h"
8#include "utils/typed_uuid_reference.h"
9#include "utils/uuid_identifiable_object.h"
10#include "utils/uuid_reference.h"
11
12#include <gmock/gmock.h>
13#include <gtest/gtest.h>
14#include <nlohmann/json.hpp>
15
16namespace zrythm::utils
17{
18
23class TestObject : public utils::UuidIdentifiableObject<TestObject>
24{
25 Q_OBJECT
26public:
27 TestObject (QObject * parent = nullptr)
29 {
30 }
31 TestObject (Uuid id, std::string name, QObject * parent = nullptr)
33 name_ (std::move (name))
34 {
35 }
36 ~TestObject () override = default;
37
38 [[nodiscard]] std::string name () const { return name_; }
39
40 friend void
41 init_from (TestObject &obj, const TestObject &other, ObjectCloneType)
42 {
43 obj.name_ = other.name_;
44 }
45
46 NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE (
47 TestObject,
48 UuidIdentifiableObject,
49 name_)
50
51private:
52 std::string name_;
53
54 BOOST_DESCRIBE_CLASS (TestObject, (UuidIdentifiableObject), (), (), (name_))
55};
56
57static_assert (UuidIdentifiable<TestObject>);
58
59class DerivedTestObject : public TestObject
60{
61 Q_OBJECT
62public:
63 using TestObject::TestObject;
64};
66
74{
75public:
76 MOCK_METHOD (
77 void,
78 register_object_impl,
80 (override));
81 MOCK_METHOD (void, acquire_reference_impl, (const QUuid &), (override));
82 MOCK_METHOD (void, release_reference_impl, (const QUuid &), (override));
83 MOCK_METHOD (
85 find_by_raw_uuid_impl,
86 (const QUuid &),
87 (const, override));
88 MOCK_METHOD (bool, contains_impl, (const QUuid &), (const, override));
89
90protected:
91 MOCK_METHOD (
92 void,
93 for_each_matching_impl,
94 (const QMetaObject &, ObjectVisitor),
95 (const, override));
96};
97
104class ContainerTestObject
105 : public utils::UuidIdentifiableObject<ContainerTestObject>
106{
107 Q_OBJECT
108public:
109 ContainerTestObject (QObject * parent = nullptr)
111 {
112 }
113 ContainerTestObject (Uuid id, std::string name, QObject * parent = nullptr)
115 name_ (std::move (name))
116 {
117 }
118
120 void set_contained_ref (UuidRef ref) { contained_ref_ = std::move (ref); }
121 [[nodiscard]] std::string name () const { return name_; }
122
123 friend void init_from (
124 ContainerTestObject &obj,
125 const ContainerTestObject &other,
127 {
128 obj.name_ = other.name_;
129 }
130
131 NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE (
132 ContainerTestObject,
134 name_)
135
136private:
137 std::string name_;
138 std::optional<TypedUuidReference<ContainerTestObject>> contained_ref_;
139
140 BOOST_DESCRIBE_CLASS (
141 ContainerTestObject,
143 (),
144 (),
145 (name_))
146};
147
149}
150
151DEFINE_UUID_HASH_SPECIALIZATION (zrythm::utils::TestObject::Uuid)
152
153DEFINE_UUID_HASH_SPECIALIZATION (zrythm::utils::ContainerTestObject::Uuid)
Abstract interface for a UUID-keyed object registry.
Mock IObjectRegistry for testing reference behavior in isolation.
Typed, reference-counted UUID reference into an IObjectRegistry.
QObject-based base for all UUID-identifiable objects.
CRTP base that adds a typed UUID strong-typedef to a class hierarchy.
Concept: T has a UUID identity from a UuidIdentifiableObject hierarchy.
String utilities.