MCPcopy Create free account
hub / github.com/KDE/kdevelop / testVcsFileChangesModel

Method testVcsFileChangesModel

kdevplatform/vcs/models/tests/test_models.cpp:28–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26}
27
28void TestModels::testVcsFileChangesModel()
29{
30 const auto indexForUrl = [](const VcsFileChangesModel* model, const QUrl& url) {
31 return VcsFileChangesModel::statusIndexForUrl(*model, QModelIndex{}, url);
32 };
33 const auto statusInfo = [](const QModelIndex& idx) {
34 return idx.data(VcsFileChangesModel::VcsStatusInfoRole).value<VcsStatusInfo>();
35 };
36
37 QScopedPointer<VcsFileChangesModel> model(new VcsFileChangesModel);
38
39 // Newly created model should be empty
40 QVERIFY(model->rowCount() == 0);
41
42 // Pull some files into
43 QUrl filenames[] = {
44 QUrl::fromLocalFile(QStringLiteral("foo")),
45 QUrl::fromLocalFile(QStringLiteral("bar")),
46 QUrl::fromLocalFile(QStringLiteral("pew")),
47 QUrl::fromLocalFile(QStringLiteral("trash"))
48 };
49 VcsStatusInfo::State states[] = {VcsStatusInfo::ItemAdded, VcsStatusInfo::ItemModified, VcsStatusInfo::ItemDeleted, VcsStatusInfo::ItemUpToDate};
50 VcsStatusInfo status;
51
52 for(int i = 0; i < 3; i++) {
53 status.setUrl(filenames[i]);
54 status.setState(states[i]);
55 model->updateState(status);
56 QCOMPARE(model->rowCount(), (i+1));
57 }
58
59 // Pulling up-to-date file doesn't change anything
60 {
61 status.setUrl(filenames[3]);
62 status.setState(states[3]);
63 model->updateState(status);
64 QCOMPARE(model->rowCount(), 3);
65 }
66
67 // Check that all OK
68 for(int i = 0; i < 3; i++) {
69 QModelIndex idx = indexForUrl(model.data(), filenames[i]);
70 QVERIFY(idx.isValid());
71 VcsStatusInfo info = statusInfo(idx);
72 QVERIFY(info.url().isValid());
73 QCOMPARE(info.url(), filenames[i]);
74 QCOMPARE(info.state(), states[i]);
75 }
76
77 // Pull it all again = nothing changed
78 for(int i = 0; i < 3; i++) {
79 status.setUrl(filenames[i]);
80 status.setState(states[i]);
81 model->updateState(status);
82 QCOMPARE(model->rowCount(), 3);
83 }
84
85 // Check that all OK

Callers

nothing calls this directly

Calls 9

dataMethod · 0.45
rowCountMethod · 0.45
setUrlMethod · 0.45
setStateMethod · 0.45
updateStateMethod · 0.45
isValidMethod · 0.45
urlMethod · 0.45
stateMethod · 0.45
removeRowsMethod · 0.45

Tested by

no test coverage detected