File: playlist_entity_table_test.cpp

package info (click to toggle)
libdjinterop 0.24.3%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,880 kB
  • sloc: cpp: 27,419; sql: 4,053; makefile: 3; sh: 2
file content (180 lines) | stat: -rw-r--r-- 6,912 bytes parent folder | download
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
/*
    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/>.
 */

#define BOOST_TEST_MODULE engine_v2_playlist_entity_table_test
#include <boost/test/data/test_case.hpp>
#include <boost/test/included/unit_test.hpp>

#include <cstdint>
#include <sstream>
#include <stdexcept>

#include <djinterop/engine/engine.hpp>
#include <djinterop/engine/v2/engine_library.hpp>

#include "../../boost_test_printable.hpp"
#include "../../boost_test_utils.hpp"
#include "../../temporary_directory.hpp"

namespace utf = boost::unit_test;
namespace e = djinterop::engine;
namespace ev2 = djinterop::engine::v2;

const constexpr int64_t EXAMPLE_TRACK_ID_1 = 12345;
const constexpr int64_t EXAMPLE_TRACK_ID_2 = 67890;

BOOST_TEST_DECORATOR(*utf::description("add_back() to empty playlist"))
BOOST_DATA_TEST_CASE(
    add_back__empty_playlist__adds, e::supported_v2_schemas, schema)
{
    // Arrange
    auto library = ev2::engine_library::create_temporary(schema);
    auto db_uuid = library.information().get().uuid;
    auto playlist_tbl = library.playlist();
    auto playlist_entity_tbl = library.playlist_entity();
    ev2::playlist_row p_row{
        ev2::PLAYLIST_ROW_ID_NONE, "Example playlist", ev2::PARENT_LIST_ID_NONE,
        true};
    auto p_id = playlist_tbl.add(p_row);
    ev2::playlist_entity_row pe_row{
        ev2::PLAYLIST_ENTITY_ROW_ID_NONE, p_id, EXAMPLE_TRACK_ID_1, db_uuid};

    // Act
    auto pe_id = playlist_entity_tbl.add_back(pe_row);

    // Assert
    auto entities = playlist_entity_tbl.get_for_list(p_id);
    auto iter = entities.begin();
    BOOST_REQUIRE(iter != entities.end());
    BOOST_CHECK_EQUAL(iter->id, pe_id);
    BOOST_CHECK_EQUAL(iter->list_id, p_id);
    BOOST_CHECK_EQUAL(iter->track_id, pe_row.track_id);
    BOOST_CHECK_EQUAL(iter->database_uuid, db_uuid);
    BOOST_CHECK_EQUAL(
        iter->next_entity_id, ev2::PLAYLIST_ENTITY_NO_NEXT_ENTITY_ID);
    BOOST_CHECK_EQUAL(iter->membership_reference, pe_row.membership_reference);
    ++iter;
    BOOST_REQUIRE(iter == entities.end());
}

BOOST_TEST_DECORATOR(*utf::description("add_back() to non-empty playlist"))
BOOST_DATA_TEST_CASE(
    add_back__nonempty_playlist__adds, e::supported_v2_schemas, schema)
{
    // Arrange
    auto library = ev2::engine_library::create_temporary(schema);
    auto db_uuid = library.information().get().uuid;
    auto playlist_tbl = library.playlist();
    auto playlist_entity_tbl = library.playlist_entity();
    ev2::playlist_row p_row{
        ev2::PLAYLIST_ROW_ID_NONE, "Example playlist", ev2::PARENT_LIST_ID_NONE,
        true};
    auto p_id = playlist_tbl.add(p_row);
    ev2::playlist_entity_row pe_row_1{
        ev2::PLAYLIST_ENTITY_ROW_ID_NONE, p_id, EXAMPLE_TRACK_ID_1, db_uuid};
    auto pe_id_1 = playlist_entity_tbl.add_back(pe_row_1);
    ev2::playlist_entity_row pe_row_2{
        ev2::PLAYLIST_ENTITY_ROW_ID_NONE, p_id, EXAMPLE_TRACK_ID_2, db_uuid};

    // Act
    auto pe_id_2 = playlist_entity_tbl.add_back(pe_row_2);

    // Assert
    auto entities = playlist_entity_tbl.get_for_list(p_id);
    auto iter = entities.begin();
    BOOST_REQUIRE(iter != entities.end());
    BOOST_CHECK_EQUAL(iter->id, pe_id_1);
    BOOST_CHECK_EQUAL(iter->list_id, p_id);
    BOOST_CHECK_EQUAL(iter->track_id, pe_row_1.track_id);
    BOOST_CHECK_EQUAL(iter->database_uuid, db_uuid);
    BOOST_CHECK_EQUAL(iter->next_entity_id, pe_id_2);
    BOOST_CHECK_EQUAL(
        iter->membership_reference, pe_row_1.membership_reference);
    ++iter;
    BOOST_REQUIRE(iter != entities.end());
    BOOST_CHECK_EQUAL(iter->id, pe_id_2);
    BOOST_CHECK_EQUAL(iter->list_id, p_id);
    BOOST_CHECK_EQUAL(iter->track_id, pe_row_2.track_id);
    BOOST_CHECK_EQUAL(iter->database_uuid, db_uuid);
    BOOST_CHECK_EQUAL(
        iter->next_entity_id, ev2::PLAYLIST_ENTITY_NO_NEXT_ENTITY_ID);
    BOOST_CHECK_EQUAL(
        iter->membership_reference, pe_row_2.membership_reference);
    ++iter;
    BOOST_REQUIRE(iter == entities.end());
}

BOOST_TEST_DECORATOR(
    *utf::description("add_back() same track multiple times idempotently"))
BOOST_DATA_TEST_CASE(
    add_back__same_track_multple_no_throw__idempotent, e::supported_v2_schemas,
    schema)
{
    // Arrange
    auto library = ev2::engine_library::create_temporary(schema);
    auto db_uuid = library.information().get().uuid;
    auto playlist_tbl = library.playlist();
    auto playlist_entity_tbl = library.playlist_entity();
    ev2::playlist_row p_row{
        ev2::PLAYLIST_ROW_ID_NONE, "Example playlist", ev2::PARENT_LIST_ID_NONE,
        true};
    auto p_id = playlist_tbl.add(p_row);
    ev2::playlist_entity_row pe_row{
        ev2::PLAYLIST_ENTITY_ROW_ID_NONE, p_id, EXAMPLE_TRACK_ID_1, db_uuid};
    auto pe_id = playlist_entity_tbl.add_back(pe_row);

    // Act
    playlist_entity_tbl.add_back(pe_row);

    // Assert
    auto entities = playlist_entity_tbl.get_for_list(p_id);
    auto iter = entities.begin();
    BOOST_REQUIRE(iter != entities.end());
    BOOST_CHECK_EQUAL(iter->id, pe_id);
    BOOST_CHECK_EQUAL(iter->list_id, p_id);
    BOOST_CHECK_EQUAL(iter->track_id, pe_row.track_id);
    BOOST_CHECK_EQUAL(iter->database_uuid, db_uuid);
    BOOST_CHECK_EQUAL(
        iter->next_entity_id, ev2::PLAYLIST_ENTITY_NO_NEXT_ENTITY_ID);
    BOOST_CHECK_EQUAL(iter->membership_reference, pe_row.membership_reference);
    ++iter;
    BOOST_REQUIRE(iter == entities.end());
}

BOOST_TEST_DECORATOR(
    *utf::description("add_back() same track multiple times with throw"))
BOOST_DATA_TEST_CASE(
    add_back__same_track_multple_throw__idempotent, e::supported_v2_schemas,
    schema)
{
    // Arrange
    auto library = ev2::engine_library::create_temporary(schema);
    auto db_uuid = library.information().get().uuid;
    auto playlist_tbl = library.playlist();
    auto playlist_entity_tbl = library.playlist_entity();
    ev2::playlist_row p_row{
        ev2::PLAYLIST_ROW_ID_NONE, "Example playlist", ev2::PARENT_LIST_ID_NONE,
        true};
    auto p_id = playlist_tbl.add(p_row);
    ev2::playlist_entity_row pe_row{
        ev2::PLAYLIST_ENTITY_ROW_ID_NONE, p_id, EXAMPLE_TRACK_ID_1, db_uuid};
    playlist_entity_tbl.add_back(pe_row);

    // Act/Assert
    BOOST_CHECK_THROW(
        playlist_entity_tbl.add_back(pe_row, true), std::invalid_argument);
}