Zrythm v2.0.0-alpha.1
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
test_uuid_identifiable_qobjects.h
1// SPDX-FileCopyrightText: © 2025-2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "utils/uuid_identifiable_object.h"
7
8#include <gtest/gtest.h>
9#include <nlohmann/json.hpp>
10
11namespace zrythm
12{
13
14class BaseTestObject : public utils::UuidIdentifiableObject<BaseTestObject>
15{
16 Q_OBJECT
17public:
18 BaseTestObject (QObject * parent = nullptr)
20 {
21 }
22 explicit BaseTestObject (Uuid id, QObject * parent = nullptr)
24 {
25 }
26 ~BaseTestObject () override = default;
27 BaseTestObject (const BaseTestObject &) = delete;
28 BaseTestObject &operator= (const BaseTestObject &) = delete;
29 BaseTestObject (BaseTestObject &&) = delete;
30 BaseTestObject &operator= (BaseTestObject &&) = delete;
31
32 friend void to_json (nlohmann::json &json_value, const BaseTestObject &obj)
33 {
34 to_json (json_value, static_cast<const UuidIdentifiableObject &> (obj));
35 }
36 friend void from_json (const nlohmann::json &json_value, BaseTestObject &obj)
37 {
38 from_json (json_value, static_cast<UuidIdentifiableObject &> (obj));
39 }
40
41 BOOST_DESCRIBE_CLASS (BaseTestObject, (UuidIdentifiableObject), (), (), ())
42};
43
45
46}
47
48DEFINE_UUID_HASH_SPECIALIZATION (zrythm::BaseTestObject::Uuid);
49
50namespace zrythm
51{
52
53using TestUuid = BaseTestObject::Uuid;
54
55class DerivedTestObject : public BaseTestObject
56{
57 Q_OBJECT
58public:
59 // Used to test non-default constructable objects that require a dependency
60 // during deserialization
61 explicit DerivedTestObject (int some_dependency) { };
62 explicit DerivedTestObject (TestUuid id, std::string name)
63 : BaseTestObject (id), name_ (std::move (name))
64 {
65 }
66
67 [[nodiscard]] std::string name () const { return name_; }
68
69 friend void init_from (
70 DerivedTestObject &obj,
71 const DerivedTestObject &other,
72 utils::ObjectCloneType clone_type)
73 {
74 obj.name_ = other.name_;
75 }
76
77 NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE (DerivedTestObject, BaseTestObject, name_)
78
79private:
80 std::string name_;
81
82 BOOST_DESCRIBE_CLASS (DerivedTestObject, (BaseTestObject), (), (), (name_))
83};
84
85}
CRTP base that adds a typed UUID strong-typedef to a class hierarchy.
Concept: T has a UUID identity from a UuidIdentifiableObject hierarchy.