1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
|
/*
This file is part of libdjinterop.
libdjinterop is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either schema 3 of the License, or
(at your option) any later version.
libdjinterop is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with libdjinterop. If not, see <http://www.gnu.org/licenses/>.
*/
#include <djinterop/database.hpp>
#define BOOST_TEST_MODULE database_test
#include <boost/test/data/test_case.hpp>
#include <boost/test/included/unit_test.hpp>
#include <string>
#include <vector>
#include <djinterop/crate.hpp>
#include <djinterop/engine/engine.hpp>
#include <djinterop/track.hpp>
#include <djinterop/track_snapshot.hpp>
#include "example_track_data.hpp"
#define STRINGIFY(x) STRINGIFY_(x)
#define STRINGIFY_(x) #x
namespace utf = boost::unit_test;
namespace e = djinterop::engine;
BOOST_TEST_DECORATOR(* utf::description(
"database::create_root_crate() for all supported schema versions"))
BOOST_DATA_TEST_CASE(
create_root_crate__supported_version__creates, e::supported_schemas, schema)
{
// Arrange
BOOST_TEST_CHECKPOINT("(" << schema << ") Creating temporary database...");
auto db = e::create_temporary_database(schema);
// Act
BOOST_TEST_CHECKPOINT("(" << schema << ") Creating root crate...");
auto crate = db.create_root_crate("Example Root Crate");
// Assert
BOOST_CHECK_NE(crate.id(), 0);
BOOST_CHECK(crate.parent() == std::nullopt);
}
BOOST_TEST_DECORATOR(* utf::description(
"database::create_root_crate_after() for all supported schema versions"))
BOOST_DATA_TEST_CASE(
create_root_crate_after__supported_version__creates, e::supported_v2_schemas,
schema)
{
// Arrange
BOOST_TEST_CHECKPOINT("(" << schema << ") Creating temporary database...");
auto db = e::create_temporary_database(schema);
auto crate_a = db.create_root_crate("Example Root Crate A");
auto crate_b = db.create_root_crate("Example Root Crate B");
auto crate_d = db.create_root_crate("Example Root Crate D");
auto crate_e = db.create_root_crate("Example Root Crate E");
// Act
BOOST_TEST_CHECKPOINT("(" << schema << ") Creating root crate after another...");
auto crate = db.create_root_crate_after("Example Root Crate C", crate_b);
// Assert
auto crates = db.root_crates();
BOOST_CHECK_EQUAL(5, crates.size());
BOOST_CHECK(crates[0].id() == crate_a.id());
BOOST_CHECK(crates[1].id() == crate_b.id());
BOOST_CHECK(crates[2].id() == crate.id());
BOOST_CHECK(crates[3].id() == crate_d.id());
BOOST_CHECK(crates[4].id() == crate_e.id());
}
BOOST_TEST_DECORATOR(* utf::description(
"database::create_track() for all supported schema versions"))
BOOST_DATA_TEST_CASE(
create_track__supported_version__creates, e::supported_schemas, schema)
{
// Arrange
BOOST_TEST_CHECKPOINT("(" << schema << ") Creating temporary database...");
auto db = e::create_temporary_database(schema);
djinterop::track_snapshot snapshot{};
populate_track_snapshot(
snapshot, example_track_data_variation::minimal_1,
example_track_data_usage::create, schema);
// Act
BOOST_TEST_CHECKPOINT("(" << schema << ") Creating track...");
auto track = db.create_track(snapshot);
// Assert
BOOST_CHECK_NE(track.id(), 0);
}
BOOST_TEST_DECORATOR(* utf::description(
"database::remove_track() for all supported schema versions"))
BOOST_DATA_TEST_CASE(
remove_track__supported_version__removes, e::supported_schemas, schema)
{
// Arrange
BOOST_TEST_CHECKPOINT("(" << schema << ") Creating temporary database...");
auto db = e::create_temporary_database(schema);
djinterop::track_snapshot snapshot{};
populate_track_snapshot(
snapshot, example_track_data_variation::minimal_1,
example_track_data_usage::create, schema);
BOOST_TEST_CHECKPOINT("(" << schema << ") Creating track...");
auto track = db.create_track(snapshot);
// Act
db.remove_track(track);
// Assert
auto tracks = db.tracks();
BOOST_CHECK_EQUAL(tracks.size(), 0);
}
BOOST_TEST_DECORATOR(* utf::description(
"database::verify() for all supported versions"))
BOOST_DATA_TEST_CASE(verify__no_throw, e::supported_schemas, schema)
{
// Arrange
BOOST_TEST_CHECKPOINT("(" << schema << ") Creating temporary database...");
auto db = e::create_temporary_database(schema);
// Act/Assert
BOOST_TEST_CHECKPOINT("(" << schema << ") Verifying DB...");
db.verify();
}
BOOST_TEST_DECORATOR(*utf::description("database::tracks(), all schema versions"))
BOOST_DATA_TEST_CASE(tracks__expected_ids, e::supported_schemas, schema)
{
// Arrange
BOOST_TEST_CHECKPOINT("(" << schema << ") Creating temporary database...");
auto db = e::create_temporary_database(schema);
djinterop::track_snapshot snapshot{};
populate_track_snapshot(
snapshot, example_track_data_variation::minimal_1,
example_track_data_usage::create, schema);
BOOST_TEST_CHECKPOINT("(" << schema << ") Creating track...");
auto track = db.create_track(snapshot);
// Act
BOOST_TEST_CHECKPOINT("(" << schema << ") Fetching tracks...");
auto results = db.tracks();
// Assert
BOOST_CHECK_EQUAL(results.size(), 1);
BOOST_CHECK_EQUAL(results[0].id(), track.id());
}
BOOST_TEST_DECORATOR(*utf::description("database::tracks_by_relative_path(), valid path, all schema versions"))
BOOST_DATA_TEST_CASE(tracks_by_relative_path__valid_path__expected_ids, e::supported_schemas, schema)
{
// Arrange
BOOST_TEST_CHECKPOINT("(" << schema << ") Creating temporary database...");
auto db = e::create_temporary_database(schema);
djinterop::track_snapshot snapshot{};
populate_track_snapshot(
snapshot, example_track_data_variation::minimal_1,
example_track_data_usage::create, schema);
BOOST_TEST_CHECKPOINT("(" << schema << ") Creating track...");
auto track = db.create_track(snapshot);
// Act
BOOST_TEST_CHECKPOINT("(" << schema << ") Fetching tracks...");
auto results = db.tracks_by_relative_path(*snapshot.relative_path);
// Assert
BOOST_CHECK_EQUAL(results.size(), 1);
BOOST_CHECK_EQUAL(results[0].id(), track.id());
}
BOOST_TEST_DECORATOR(*utf::description("database::tracks_by_relative_path(), invalid path, all schema versions"))
BOOST_DATA_TEST_CASE(tracks_by_relative_path__invalid_path__no_ids, e::supported_schemas, schema)
{
// Arrange
BOOST_TEST_CHECKPOINT("(" << schema << ") Creating temporary database...");
auto db = e::create_temporary_database(schema);
// Act
BOOST_TEST_CHECKPOINT("(" << schema << ") Fetching tracks...");
auto results = db.tracks_by_relative_path("Does Not Exist.mp3");
// Assert
BOOST_CHECK_EQUAL(results.size(), 0);
}
BOOST_TEST_DECORATOR(*utf::description("database::track_by_id(), valid id, all schema versions"))
BOOST_DATA_TEST_CASE(track_by_id__valid_id__expected_ids, e::supported_schemas, schema)
{
// Arrange
BOOST_TEST_CHECKPOINT("(" << schema << ") Creating temporary database...");
auto db = e::create_temporary_database(schema);
djinterop::track_snapshot snapshot{};
populate_track_snapshot(
snapshot, example_track_data_variation::minimal_1,
example_track_data_usage::create, schema);
BOOST_TEST_CHECKPOINT("(" << schema << ") Creating track...");
auto track = db.create_track(snapshot);
// Act
BOOST_TEST_CHECKPOINT("(" << schema << ") Fetching tracks...");
auto result = db.track_by_id(track.id());
// Assert
BOOST_CHECK(result);
BOOST_CHECK_EQUAL(result->id(), track.id());
}
BOOST_TEST_DECORATOR(*utf::description("database::track_by_id(), invalid id, all schema versions"))
BOOST_DATA_TEST_CASE(track_by_id__invalid_id__no_ids, e::supported_schemas, schema)
{
// Arrange
BOOST_TEST_CHECKPOINT("(" << schema << ") Creating temporary database...");
auto db = e::create_temporary_database(schema);
// Act
BOOST_TEST_CHECKPOINT("(" << schema << ") Fetching tracks...");
auto result = db.track_by_id(123);
// Assert
BOOST_CHECK(!result);
}
|