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 | // test detach after changing B | ||||
100 | { | ||||
101 | VcsEvent eventA; | ||||
102 | setEvent(eventA, | ||||
103 | revision, author, date, message, items); | ||||
104 | | ||||
105 | VcsEvent eventB(eventA); | ||||
106 | // change a property of B | ||||
107 | eventB.setRevision(revisionNew); | ||||
108 | | ||||
109 | compareEvent(eventA, | ||||
110 | revision, author, date, message, items); | ||||
111 | compareEvent(eventB, | ||||
112 | revisionNew, author, date, message, items); | ||||
113 | } | ||||
114 | } | ||||
115 | | ||||
116 | void TestVcsEvent::testAssignOperator() | ||||
117 | { | ||||
118 | // test plain copy | ||||
119 | VcsRevision revision; | ||||
120 | revision.setRevisionValue("A", VcsRevision::GlobalNumber); | ||||
121 | const QString author("author"); | ||||
122 | const QDateTime date = QDateTime::fromString("2001-01-01T00:00:00+00:00", Qt::ISODate); | ||||
123 | const QString message("message"); | ||||
124 | const QList<VcsItemEvent> items({{}}); | ||||
125 | | ||||
126 | { | ||||
127 | VcsEvent eventA; | ||||
128 | setEvent(eventA, | ||||
129 | revision, author, date, message, items); | ||||
130 | | ||||
131 | VcsEvent eventB; | ||||
132 | eventB = eventA; | ||||
133 | | ||||
134 | compareEvent(eventA, | ||||
135 | revision, author, date, message, items); | ||||
136 | compareEvent(eventB, | ||||
137 | revision, author, date, message, items); | ||||
138 | } | ||||
139 | | ||||
140 | VcsRevision revisionNew; | ||||
141 | revisionNew.setRevisionValue(2, VcsRevision::FileNumber); | ||||
142 | | ||||
143 | // test detach after changing A | ||||
144 | { | ||||
145 | VcsEvent eventA; | ||||
146 | setEvent(eventA, | ||||
147 | revision, author, date, message, items); | ||||
148 | | ||||
149 | VcsEvent eventB; | ||||
150 | eventB = eventA; | ||||
151 | // change a property of A | ||||
152 | eventA.setRevision(revisionNew); | ||||
153 | | ||||
154 | compareEvent(eventA, | ||||
155 | revisionNew, author, date, message, items); | ||||
156 | compareEvent(eventB, | ||||
157 | revision, author, date, message, items); | ||||
158 | } | ||||
159 | | ||||
160 | // test detach after changing B | ||||
161 | { | ||||
162 | VcsEvent eventA; | ||||
163 | setEvent(eventA, | ||||
164 | revision, author, date, message, items); | ||||
165 | | ||||
166 | VcsEvent eventB; | ||||
167 | eventB = eventA; | ||||
168 | // change a property of B | ||||
169 | eventB.setRevision(revisionNew); | ||||
170 | | ||||
171 | compareEvent(eventA, | ||||
172 | revision, author, date, message, items); | ||||
173 | compareEvent(eventB, | ||||
174 | revisionNew, author, date, message, items); | ||||
175 | } | ||||
176 | } | ||||
177 | | ||||
178 | QTEST_GUILESS_MAIN(TestVcsEvent); |