Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/vcs/tests/test_vcsitemevent.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_vcsitemevent.h" | ||||
22 | | ||||
23 | #include <QTest> | ||||
24 | | ||||
25 | #include <vcs/vcsrevision.h> | ||||
26 | | ||||
27 | using namespace KDevelop; | ||||
28 | | ||||
29 | void TestVcsItemEvent::setItemEvent(VcsItemEvent& itemEvent, | ||||
30 | const QString& repositoryLocation, | ||||
31 | const QString& repositoryCopySourceLocation, | ||||
32 | const VcsRevision& repositoryCopySourceRevision, | ||||
33 | VcsItemEvent::Actions actions) | ||||
34 | { | ||||
35 | itemEvent.setRepositoryLocation(repositoryLocation); | ||||
36 | itemEvent.setRepositoryCopySourceLocation(repositoryCopySourceLocation); | ||||
37 | itemEvent.setRepositoryCopySourceRevision(repositoryCopySourceRevision); | ||||
38 | itemEvent.setActions(actions); | ||||
39 | } | ||||
40 | | ||||
41 | void TestVcsItemEvent::compareItemEvent(const VcsItemEvent& itemEvent, | ||||
42 | const QString& repositoryLocation, | ||||
43 | const QString& repositoryCopySourceLocation, | ||||
44 | const VcsRevision& repositoryCopySourceRevision, | ||||
45 | VcsItemEvent::Actions actions) | ||||
46 | { | ||||
47 | QCOMPARE(itemEvent.repositoryLocation(), repositoryLocation); | ||||
48 | QCOMPARE(itemEvent.repositoryCopySourceLocation(), repositoryCopySourceLocation); | ||||
49 | QCOMPARE(itemEvent.repositoryCopySourceRevision(), repositoryCopySourceRevision); | ||||
50 | QCOMPARE(itemEvent.actions(), actions); | ||||
51 | } | ||||
52 | | ||||
53 | void TestVcsItemEvent::testCopyConstructor() | ||||
54 | { | ||||
55 | // test plain copy | ||||
56 | const QString repositoryLocation("location"); | ||||
57 | const QString repositoryCopySourceLocation("copy source location"); | ||||
58 | VcsRevision repositoryCopySourceRevision; | ||||
59 | repositoryCopySourceRevision.setRevisionValue("A", VcsRevision::GlobalNumber); | ||||
60 | const VcsItemEvent::Actions actions = VcsItemEvent::Added; | ||||
61 | | ||||
62 | { | ||||
63 | VcsItemEvent itemEventA; | ||||
64 | setItemEvent(itemEventA, | ||||
65 | repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, actions); | ||||
66 | | ||||
67 | VcsItemEvent itemEventB(itemEventA); | ||||
68 | | ||||
69 | compareItemEvent(itemEventA, | ||||
70 | repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, | ||||
71 | actions); | ||||
72 | compareItemEvent(itemEventB, | ||||
73 | repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, | ||||
74 | actions); | ||||
75 | } | ||||
76 | | ||||
77 | const QString repositoryLocationNew("new location"); | ||||
78 | | ||||
79 | // test detach after changing A | ||||
80 | { | ||||
81 | VcsItemEvent itemEventA; | ||||
82 | setItemEvent(itemEventA, | ||||
83 | repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, actions); | ||||
84 | | ||||
85 | VcsItemEvent itemEventB(itemEventA); | ||||
86 | // change a property of A | ||||
87 | itemEventA.setRepositoryLocation(repositoryLocationNew); | ||||
88 | | ||||
89 | compareItemEvent(itemEventA, | ||||
90 | repositoryLocationNew, repositoryCopySourceLocation, repositoryCopySourceRevision, | ||||
91 | actions); | ||||
92 | compareItemEvent(itemEventB, | ||||
93 | repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, | ||||
94 | actions); | ||||
95 | } | ||||
96 | | ||||
97 | // test detach after changing B | ||||
98 | { | ||||
99 | VcsItemEvent itemEventA; | ||||
100 | setItemEvent(itemEventA, | ||||
101 | repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, actions); | ||||
102 | | ||||
103 | VcsItemEvent itemEventB(itemEventA); | ||||
104 | // change a property of B | ||||
105 | itemEventB.setRepositoryLocation(repositoryLocationNew); | ||||
106 | | ||||
107 | compareItemEvent(itemEventA, | ||||
108 | repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, | ||||
109 | actions); | ||||
110 | compareItemEvent(itemEventB, | ||||
111 | repositoryLocationNew, repositoryCopySourceLocation, repositoryCopySourceRevision, | ||||
112 | actions); | ||||
113 | } | ||||
114 | } | ||||
115 | | ||||
116 | void TestVcsItemEvent::testAssignOperator() | ||||
117 | { | ||||
118 | // test plain assign | ||||
119 | const QString repositoryLocation("location"); | ||||
120 | const QString repositoryCopySourceLocation("copy source location"); | ||||
121 | VcsRevision repositoryCopySourceRevision; | ||||
122 | repositoryCopySourceRevision.setRevisionValue("A", VcsRevision::GlobalNumber); | ||||
123 | const VcsItemEvent::Actions actions = VcsItemEvent::Added; | ||||
124 | | ||||
125 | { | ||||
126 | VcsItemEvent itemEventA; | ||||
127 | setItemEvent(itemEventA, | ||||
128 | repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, actions); | ||||
129 | | ||||
130 | VcsItemEvent itemEventB; | ||||
131 | itemEventB = itemEventA; | ||||
132 | | ||||
133 | compareItemEvent(itemEventA, | ||||
134 | repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, | ||||
135 | actions); | ||||
136 | compareItemEvent(itemEventB, | ||||
137 | repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, | ||||
138 | actions); | ||||
139 | } | ||||
140 | | ||||
141 | const QString repositoryLocationNew("new location"); | ||||
142 | | ||||
143 | // test detach after changing A | ||||
144 | { | ||||
145 | VcsItemEvent itemEventA; | ||||
146 | setItemEvent(itemEventA, | ||||
147 | repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, actions); | ||||
148 | | ||||
149 | VcsItemEvent itemEventB; | ||||
150 | itemEventB = itemEventA; | ||||
151 | // change a property of A | ||||
152 | itemEventA.setRepositoryLocation(repositoryLocationNew); | ||||
153 | | ||||
154 | compareItemEvent(itemEventA, | ||||
155 | repositoryLocationNew, repositoryCopySourceLocation, repositoryCopySourceRevision, | ||||
156 | actions); | ||||
157 | compareItemEvent(itemEventB, | ||||
158 | repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, | ||||
159 | actions); | ||||
160 | } | ||||
161 | | ||||
162 | // test detach after changing B | ||||
163 | { | ||||
164 | VcsItemEvent itemEventA; | ||||
165 | setItemEvent(itemEventA, | ||||
166 | repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, actions); | ||||
167 | | ||||
168 | VcsItemEvent itemEventB; | ||||
169 | itemEventB = itemEventA; | ||||
170 | // change a property of B | ||||
171 | itemEventB.setRepositoryLocation(repositoryLocationNew); | ||||
172 | | ||||
173 | compareItemEvent(itemEventA, | ||||
174 | repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, | ||||
175 | actions); | ||||
176 | compareItemEvent(itemEventB, | ||||
177 | repositoryLocationNew, repositoryCopySourceLocation, repositoryCopySourceRevision, | ||||
178 | actions); | ||||
179 | } | ||||
180 | } | ||||
181 | | ||||
182 | QTEST_GUILESS_MAIN(TestVcsItemEvent); |