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 | | ||||
98 | void TestVcsItemEvent::testAssignOperator() | ||||
99 | { | ||||
100 | // test plain assign | ||||
101 | const QString repositoryLocation("location"); | ||||
102 | const QString repositoryCopySourceLocation("copy source location"); | ||||
103 | VcsRevision repositoryCopySourceRevision; | ||||
104 | repositoryCopySourceRevision.setRevisionValue("A", VcsRevision::GlobalNumber); | ||||
105 | const VcsItemEvent::Actions actions = VcsItemEvent::Added; | ||||
106 | | ||||
107 | { | ||||
108 | VcsItemEvent itemEventA; | ||||
109 | setItemEvent(itemEventA, | ||||
110 | repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, actions); | ||||
111 | | ||||
112 | VcsItemEvent itemEventB; | ||||
113 | itemEventB = itemEventA; | ||||
114 | | ||||
115 | compareItemEvent(itemEventA, | ||||
116 | repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, | ||||
117 | actions); | ||||
118 | compareItemEvent(itemEventB, | ||||
119 | repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, | ||||
120 | actions); | ||||
121 | } | ||||
122 | | ||||
123 | const QString repositoryLocationNew("new location"); | ||||
124 | | ||||
125 | // test detach after changing A | ||||
126 | { | ||||
127 | VcsItemEvent itemEventA; | ||||
128 | setItemEvent(itemEventA, | ||||
129 | repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, actions); | ||||
130 | | ||||
131 | VcsItemEvent itemEventB; | ||||
132 | itemEventB = itemEventA; | ||||
133 | // change a property of A | ||||
134 | itemEventA.setRepositoryLocation(repositoryLocationNew); | ||||
135 | | ||||
136 | compareItemEvent(itemEventA, | ||||
137 | repositoryLocationNew, repositoryCopySourceLocation, repositoryCopySourceRevision, | ||||
138 | actions); | ||||
139 | compareItemEvent(itemEventB, | ||||
140 | repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, | ||||
141 | actions); | ||||
142 | } | ||||
143 | } | ||||
144 | | ||||
145 | QTEST_GUILESS_MAIN(TestVcsItemEvent); |