Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/vcs/tests/test_vcsevent.cpp
- This file was added.
1 | /* This file is part of KDevelop | ||||
---|---|---|---|---|---|
2 | * | ||||
3 | * Copyright 2017 Friedrich W. H. Kossebau <kossebau@kde.org> | ||||
4 | * | ||||
5 | * This program is free software; you can redistribute it and/or | ||||
6 | * modify it under the terms of the GNU General Public License | ||||
7 | * as published by the Free Software Foundation; either version 2 | ||||
8 | * of the License, or (at your option) any later version. | ||||
9 | * | ||||
10 | * This program is distributed in the hope that it will be useful, | ||||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
13 | * GNU General Public License for more details. | ||||
14 | * | ||||
15 | * You should have received a copy of the GNU General Public License | ||||
16 | * along with this program; if not, write to the Free Software | ||||
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||||
18 | * 02110-1301, USA. | ||||
19 | */ | ||||
20 | | ||||
21 | #include "test_vcsevent.h" | ||||
22 | | ||||
23 | #include <QTest> | ||||
24 | | ||||
25 | #include <vcs/vcsrevision.h> | ||||
26 | | ||||
27 | using namespace KDevelop; | ||||
28 | | ||||
29 | void TestVcsEvent::setEvent(VcsEvent& event, | ||||
30 | const VcsRevision& revision, | ||||
31 | const QString& author, | ||||
32 | const QDateTime& date, | ||||
33 | const QString& message, | ||||
34 | const QList<VcsItemEvent>& items) | ||||
35 | { | ||||
36 | event.setRevision(revision); | ||||
37 | event.setAuthor(author); | ||||
38 | event.setDate(date); | ||||
39 | event.setMessage(message); | ||||
40 | event.setItems(items); | ||||
41 | } | ||||
42 | | ||||
43 | void TestVcsEvent::compareEvent(const VcsEvent& event, | ||||
44 | const VcsRevision& revision, | ||||
45 | const QString& author, | ||||
46 | const QDateTime& date, | ||||
47 | const QString& message, | ||||
48 | const QList<VcsItemEvent>& items) | ||||
49 | { | ||||
50 | QCOMPARE(event.revision(), revision); | ||||
51 | QCOMPARE(event.author(), author); | ||||
52 | QCOMPARE(event.date(), date); | ||||
53 | QCOMPARE(event.message(), message); | ||||
54 | QCOMPARE(event.items().count(), items.count()); | ||||
55 | } | ||||
56 | | ||||
57 | void TestVcsEvent::testCopyConstructor() | ||||
58 | { | ||||
59 | // test plain copy | ||||
60 | VcsRevision revision; | ||||
61 | revision.setRevisionValue("A", VcsRevision::GlobalNumber); | ||||
62 | const QString author("author"); | ||||
63 | const QDateTime date = QDateTime::fromString("2001-01-01T00:00:00+00:00", Qt::ISODate); | ||||
64 | const QString message("message"); | ||||
65 | const QList<VcsItemEvent> items({{}}); | ||||
66 | | ||||
67 | { | ||||
68 | VcsEvent eventA; | ||||
69 | setEvent(eventA, | ||||
70 | revision, author, date, message, items); | ||||
71 | | ||||
72 | VcsEvent eventB(eventA); | ||||
73 | | ||||
74 | compareEvent(eventA, | ||||
75 | revision, author, date, message, items); | ||||
76 | compareEvent(eventB, | ||||
77 | revision, author, date, message, items); | ||||
78 | } | ||||
79 | | ||||
80 | VcsRevision revisionNew; | ||||
81 | revisionNew.setRevisionValue(2, VcsRevision::FileNumber); | ||||
82 | | ||||
83 | // test detach after changing A | ||||
84 | { | ||||
85 | VcsEvent eventA; | ||||
86 | setEvent(eventA, | ||||
87 | revision, author, date, message, items); | ||||
88 | | ||||
89 | VcsEvent eventB(eventA); | ||||
90 | // change a property of A | ||||
91 | eventA.setRevision(revisionNew); | ||||
92 | | ||||
93 | compareEvent(eventA, | ||||
94 | revisionNew, author, date, message, items); | ||||
95 | compareEvent(eventB, | ||||
96 | revision, author, date, message, items); | ||||
97 | } | ||||
98 | } | ||||
99 | | ||||
100 | void TestVcsEvent::testAssignOperator() | ||||
101 | { | ||||
102 | // test plain copy | ||||
103 | VcsRevision revision; | ||||
104 | revision.setRevisionValue("A", VcsRevision::GlobalNumber); | ||||
105 | const QString author("author"); | ||||
106 | const QDateTime date = QDateTime::fromString("2001-01-01T00:00:00+00:00", Qt::ISODate); | ||||
107 | const QString message("message"); | ||||
108 | const QList<VcsItemEvent> items({{}}); | ||||
109 | | ||||
110 | { | ||||
111 | VcsEvent eventA; | ||||
112 | setEvent(eventA, | ||||
113 | revision, author, date, message, items); | ||||
114 | | ||||
115 | VcsEvent eventB; | ||||
116 | eventB = eventA; | ||||
117 | | ||||
118 | compareEvent(eventA, | ||||
119 | revision, author, date, message, items); | ||||
120 | compareEvent(eventB, | ||||
121 | revision, author, date, message, items); | ||||
122 | } | ||||
123 | | ||||
124 | VcsRevision revisionNew; | ||||
125 | revisionNew.setRevisionValue(2, VcsRevision::FileNumber); | ||||
126 | | ||||
127 | // test detach after changing A | ||||
128 | { | ||||
129 | VcsEvent eventA; | ||||
130 | setEvent(eventA, | ||||
131 | revision, author, date, message, items); | ||||
132 | | ||||
133 | VcsEvent eventB; | ||||
134 | eventB = eventA; | ||||
135 | // change a property of A | ||||
136 | eventA.setRevision(revisionNew); | ||||
137 | | ||||
138 | compareEvent(eventA, | ||||
139 | revisionNew, author, date, message, items); | ||||
140 | compareEvent(eventB, | ||||
141 | revision, author, date, message, items); | ||||
142 | } | ||||
143 | } | ||||
144 | | ||||
145 | QTEST_GUILESS_MAIN(TestVcsEvent); |