Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
project_json_comparators.h
1// SPDX-FileCopyrightText: © 2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <array>
7#include <map>
8#include <string_view>
9
10#include <gtest/gtest.h>
11#include <nlohmann/json.hpp>
12
13namespace zrythm::test_helpers
14{
15
24inline void
25expect_registries_match (const nlohmann::json &j1, const nlohmann::json &j2)
26{
27 const auto &regs1 = j1["projectData"]["registries"];
28 const auto &regs2 = j2["projectData"]["registries"];
29
30 static constexpr std::array registry_names = {
31 "portRegistry", "paramRegistry", "pluginRegistry",
32 "trackRegistry", "arrangerObjectRegistry", "fileAudioSourceRegistry",
33 };
34
35 for (const auto name : registry_names)
36 {
37 const auto &reg1 = regs1[name];
38 const auto &reg2 = regs2[name];
39
40 EXPECT_EQ (reg1.size (), reg2.size ())
41 << "Registry " << name << " size mismatch";
42
43 // Build map of ID -> object for each registry
44 std::map<std::string, nlohmann::json> objs1, objs2;
45 for (const auto &obj : reg1)
46 objs1[obj["id"].get<std::string> ()] = obj;
47 for (const auto &obj : reg2)
48 objs2[obj["id"].get<std::string> ()] = obj;
49
50 // Find first mismatch
51 for (const auto &[id, obj] : objs1)
52 {
53 if (!objs2.contains (id))
54 {
55 FAIL ()
56 << "Registry " << name << ": object from j1 missing in j2:\n"
57 << obj.dump (2);
58 }
59 }
60 for (const auto &[id, obj] : objs2)
61 {
62 if (!objs1.contains (id))
63 {
64 FAIL ()
65 << "Registry " << name << ": object from j2 missing in j1:\n"
66 << obj.dump (2);
67 }
68 }
69 }
70}
71
72} // namespace zrythm::test_helpers