This repository was archived by the owner on Jan 31, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 358
Expand file tree
/
Copy pathMappingItemModelTest.cpp
More file actions
183 lines (135 loc) · 5.94 KB
/
Copy pathMappingItemModelTest.cpp
File metadata and controls
183 lines (135 loc) · 5.94 KB
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
// Copyright (c) 2021 The Orbit Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <QAbstractItemModelTester>
#include <QModelIndex>
#include <QVariant>
#include <Qt>
#include <filesystem>
#include <vector>
#include "QtUtils/AssertNoQtLogWarnings.h"
#include "SourcePathsMapping/Mapping.h"
#include "SourcePathsMapping/MappingItemModel.h"
namespace orbit_source_paths_mapping {
const Mapping mapping0{"/build/project", "/home/user/project"};
const Mapping mapping1{"/src/project2", "/home/user/project"};
const Mapping mapping2{"/src/project", "/home/user/project"};
const std::vector<Mapping> mappings{mapping0, mapping1, mapping2};
TEST(MappingItemModel, EmptyModel) {
orbit_qt_utils::AssertNoQtLogWarnings message_handler{};
MappingItemModel model{};
QAbstractItemModelTester{&model, QAbstractItemModelTester::FailureReportingMode::Warning};
}
TEST(MappingItemModel, FilledModel) {
orbit_qt_utils::AssertNoQtLogWarnings message_handler{};
MappingItemModel model{};
model.SetMappings(mappings);
QAbstractItemModelTester{&model, QAbstractItemModelTester::FailureReportingMode::Warning};
}
TEST(MappingItemModel, SetMappings) {
MappingItemModel model{};
EXPECT_EQ(model.rowCount(), 0);
model.SetMappings(mappings);
EXPECT_EQ(model.rowCount(), 3);
model.SetMappings({});
EXPECT_EQ(model.rowCount(), 0);
model.SetMappings(mappings);
EXPECT_EQ(model.rowCount(), 3);
}
TEST(MappingItemModel, GetMappings) {
MappingItemModel model{};
model.SetMappings(mappings);
EXPECT_THAT(model.GetMappings(), testing::ElementsAreArray(mappings));
model.SetMappings({});
EXPECT_THAT(model.GetMappings(), testing::IsEmpty());
}
TEST(MappingItemModel, RemoveFirstRow) {
MappingItemModel model{};
model.SetMappings(mappings);
EXPECT_TRUE(model.RemoveRows(0, 1));
EXPECT_EQ(model.rowCount(), 2);
ASSERT_TRUE(model.index(0, 0).data(Qt::UserRole).canConvert<const Mapping*>());
EXPECT_EQ(*model.index(0, 0).data(Qt::UserRole).value<const Mapping*>(), mapping1);
ASSERT_TRUE(model.index(1, 0).data(Qt::UserRole).canConvert<const Mapping*>());
EXPECT_EQ(*model.index(1, 0).data(Qt::UserRole).value<const Mapping*>(), mapping2);
}
TEST(MappingItemModel, RemoveMidRow) {
MappingItemModel model{};
model.SetMappings(mappings);
EXPECT_TRUE(model.RemoveRows(1, 1));
EXPECT_EQ(model.rowCount(), 2);
ASSERT_TRUE(model.index(0, 0).data(Qt::UserRole).canConvert<const Mapping*>());
EXPECT_EQ(*model.index(0, 0).data(Qt::UserRole).value<const Mapping*>(), mapping0);
ASSERT_TRUE(model.index(1, 0).data(Qt::UserRole).canConvert<const Mapping*>());
EXPECT_EQ(*model.index(1, 0).data(Qt::UserRole).value<const Mapping*>(), mapping2);
}
TEST(MappingItemModel, RemoveLastRow) {
MappingItemModel model{};
model.SetMappings(mappings);
EXPECT_TRUE(model.RemoveRows(2, 1));
EXPECT_EQ(model.rowCount(), 2);
ASSERT_TRUE(model.index(0, 0).data(Qt::UserRole).canConvert<const Mapping*>());
EXPECT_EQ(*model.index(0, 0).data(Qt::UserRole).value<const Mapping*>(), mapping0);
ASSERT_TRUE(model.index(1, 0).data(Qt::UserRole).canConvert<const Mapping*>());
EXPECT_EQ(*model.index(1, 0).data(Qt::UserRole).value<const Mapping*>(), mapping1);
}
TEST(MappingItemModel, RemoveMultipleRows) {
MappingItemModel model{};
model.SetMappings(mappings);
EXPECT_TRUE(model.RemoveRows(0, 2));
EXPECT_EQ(model.rowCount(), 1);
ASSERT_TRUE(model.index(0, 0).data(Qt::UserRole).canConvert<const Mapping*>());
EXPECT_EQ(*model.index(0, 0).data(Qt::UserRole).value<const Mapping*>(), mapping2);
}
TEST(MappingItemModel, RemoveAllRows) {
MappingItemModel model{};
model.SetMappings(mappings);
EXPECT_TRUE(model.RemoveRows(0, 3));
EXPECT_EQ(model.rowCount(), 0);
}
TEST(MappingItemModel, setData) {
MappingItemModel model{};
model.SetMappings(mappings);
Mapping other_mapping = mapping2;
other_mapping.target_path = std::filesystem::path{"/home/other/path"};
EXPECT_TRUE(model.setData(model.index(2, 0), QVariant::fromValue(other_mapping)));
ASSERT_TRUE(model.index(2, 0).data(Qt::UserRole).canConvert<const Mapping*>());
EXPECT_EQ(*model.index(2, 0).data(Qt::UserRole).value<const Mapping*>(), other_mapping);
}
TEST(MappingItemModel, moveRowsDown) {
MappingItemModel model{};
model.SetMappings(mappings);
// Move first row into last position
EXPECT_TRUE(model.moveRows({}, 0, 1, {}, 3));
EXPECT_EQ(model.rowCount(), 3);
ASSERT_TRUE(model.index(0, 0).data(Qt::UserRole).canConvert<const Mapping*>());
EXPECT_EQ(*model.index(0, 0).data(Qt::UserRole).value<const Mapping*>(), mapping1);
ASSERT_TRUE(model.index(1, 0).data(Qt::UserRole).canConvert<const Mapping*>());
EXPECT_EQ(*model.index(1, 0).data(Qt::UserRole).value<const Mapping*>(), mapping2);
ASSERT_TRUE(model.index(2, 0).data(Qt::UserRole).canConvert<const Mapping*>());
EXPECT_EQ(*model.index(2, 0).data(Qt::UserRole).value<const Mapping*>(), mapping0);
}
TEST(MappingItemModel, moveRowsUp) {
MappingItemModel model{};
model.SetMappings(mappings);
// Move last row into first position
EXPECT_TRUE(model.moveRows({}, 2, 1, {}, 0));
EXPECT_EQ(model.rowCount(), 3);
ASSERT_TRUE(model.index(0, 0).data(Qt::UserRole).canConvert<const Mapping*>());
EXPECT_EQ(*model.index(0, 0).data(Qt::UserRole).value<const Mapping*>(), mapping2);
ASSERT_TRUE(model.index(1, 0).data(Qt::UserRole).canConvert<const Mapping*>());
EXPECT_EQ(*model.index(1, 0).data(Qt::UserRole).value<const Mapping*>(), mapping0);
ASSERT_TRUE(model.index(2, 0).data(Qt::UserRole).canConvert<const Mapping*>());
EXPECT_EQ(*model.index(2, 0).data(Qt::UserRole).value<const Mapping*>(), mapping1);
}
TEST(MappingItemModel, AppendNewEmptyMapping) {
MappingItemModel model{};
EXPECT_EQ(model.rowCount(), 0);
model.AppendNewEmptyMapping();
EXPECT_EQ(model.rowCount(), 1);
model.AppendNewEmptyMapping();
EXPECT_EQ(model.rowCount(), 2);
}
} // namespace orbit_source_paths_mapping