Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/vcs/tests/test_vcsdiff.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_vcsdiff.h" | ||||
22 | | ||||
23 | #include <QTest> | ||||
24 | | ||||
25 | #include <vcs/vcslocation.h> | ||||
26 | | ||||
27 | using namespace KDevelop; | ||||
28 | | ||||
29 | void TestVcsDiff::setDiff(VcsDiff& diff, | ||||
30 | VcsDiff::Type type, | ||||
31 | VcsDiff::Content contentType, | ||||
32 | const QString& diffString, | ||||
33 | const QUrl& baseDiff, | ||||
34 | uint depth, | ||||
35 | const QHash<VcsLocation,QByteArray>& leftBinaries, | ||||
36 | const QHash<VcsLocation,QByteArray>& rightBinaries, | ||||
37 | const QHash<VcsLocation,QString>& leftTexts, | ||||
38 | const QHash<VcsLocation,QString>& rightTexts) | ||||
39 | { | ||||
40 | diff.setType(type); | ||||
41 | diff.setContentType(contentType); | ||||
42 | diff.setDiff(diffString); | ||||
43 | diff.setBaseDiff(baseDiff); | ||||
44 | diff.setDepth(depth); | ||||
45 | for (auto it = leftBinaries.begin(); it != leftBinaries.end(); ++it) | ||||
46 | diff.addLeftBinary(it.key(), it.value()); | ||||
47 | for (auto it = rightBinaries.begin(); it != rightBinaries.end(); ++it) | ||||
48 | diff.addRightBinary(it.key(), it.value()); | ||||
49 | for (auto it = leftTexts.begin(); it != leftTexts.end(); ++it) | ||||
50 | diff.addLeftText(it.key(), it.value()); | ||||
51 | for (auto it = rightTexts.begin(); it != rightTexts.end(); ++it) | ||||
52 | diff.addRightText(it.key(), it.value()); | ||||
53 | } | ||||
54 | | ||||
55 | void TestVcsDiff::compareDiff(const VcsDiff& diff, | ||||
56 | VcsDiff::Type type, | ||||
57 | VcsDiff::Content contentType, | ||||
58 | const QString& diffString, | ||||
59 | const QUrl& baseDiff, | ||||
60 | uint depth, | ||||
61 | const QHash<VcsLocation,QByteArray>& leftBinaries, | ||||
62 | const QHash<VcsLocation,QByteArray>& rightBinaries, | ||||
63 | const QHash<VcsLocation,QString>& leftTexts, | ||||
64 | const QHash<VcsLocation,QString>& rightTexts) | ||||
65 | { | ||||
66 | QCOMPARE(diff.type(), type); | ||||
67 | QCOMPARE(diff.contentType(), contentType); | ||||
68 | QCOMPARE(diff.diff(), diffString); | ||||
69 | QCOMPARE(diff.baseDiff(), baseDiff); | ||||
70 | QCOMPARE(diff.depth(), depth); | ||||
71 | QCOMPARE(diff.leftBinaries(), leftBinaries); | ||||
72 | QCOMPARE(diff.rightBinaries(), rightBinaries); | ||||
73 | QCOMPARE(diff.leftTexts(), leftTexts); | ||||
74 | QCOMPARE(diff.rightTexts(), rightTexts); | ||||
75 | } | ||||
76 | | ||||
77 | void TestVcsDiff::testCopyConstructor() | ||||
78 | { | ||||
79 | // test plain copy | ||||
80 | const VcsDiff::Type type = VcsDiff::DiffRaw; | ||||
81 | const VcsDiff::Content contentType = VcsDiff::Binary; | ||||
82 | const QString diffString("diff"); | ||||
83 | const QUrl baseDiff("git://1"); | ||||
84 | const uint depth = 1; | ||||
85 | const VcsLocation location("server"); | ||||
86 | const QHash<VcsLocation,QByteArray> leftBinaries({{location, "leftbinary"}}); | ||||
87 | const QHash<VcsLocation,QByteArray> rightBinaries({{location, "rightbinary"}}); | ||||
88 | const QHash<VcsLocation,QString> leftTexts({{location, "lefttext"}}); | ||||
89 | const QHash<VcsLocation,QString> rightTexts({{location, "righttext"}}); | ||||
90 | | ||||
91 | { | ||||
92 | VcsDiff diffA; | ||||
93 | setDiff(diffA, | ||||
94 | type, contentType, diffString, baseDiff, depth, leftBinaries, rightBinaries, leftTexts, rightTexts); | ||||
95 | | ||||
96 | VcsDiff diffB(diffA); | ||||
97 | compareDiff(diffA, | ||||
98 | type, contentType, diffString, baseDiff, depth, leftBinaries, rightBinaries, leftTexts, rightTexts); | ||||
99 | compareDiff(diffB, | ||||
100 | type, contentType, diffString, baseDiff, depth, leftBinaries, rightBinaries, leftTexts, rightTexts); | ||||
101 | } | ||||
102 | | ||||
103 | const VcsDiff::Type typeNew = VcsDiff::DiffUnified; | ||||
104 | | ||||
105 | // test detach after changing A | ||||
106 | { | ||||
107 | VcsDiff diffA; | ||||
108 | setDiff(diffA, | ||||
109 | type, contentType, diffString, baseDiff, depth, leftBinaries, rightBinaries, leftTexts, rightTexts); | ||||
110 | | ||||
111 | VcsDiff diffB(diffA); | ||||
112 | // change a property of A | ||||
113 | diffA.setType(typeNew); | ||||
114 | | ||||
115 | compareDiff(diffA, | ||||
116 | typeNew, contentType, diffString, baseDiff, depth, leftBinaries, rightBinaries, leftTexts, rightTexts); | ||||
117 | compareDiff(diffB, | ||||
118 | type, contentType, diffString, baseDiff, depth, leftBinaries, rightBinaries, leftTexts, rightTexts); | ||||
119 | } | ||||
120 | } | ||||
121 | | ||||
122 | void TestVcsDiff::testAssignOperator() | ||||
123 | { | ||||
124 | // test plain copy | ||||
125 | const VcsDiff::Type type = VcsDiff::DiffRaw; | ||||
126 | const VcsDiff::Content contentType = VcsDiff::Binary; | ||||
127 | const QString diffString("diff"); | ||||
128 | const QUrl baseDiff("git://1"); | ||||
129 | const uint depth = 1; | ||||
130 | const VcsLocation location("server"); | ||||
131 | const QHash<VcsLocation,QByteArray> leftBinaries({{location, "leftbinary"}}); | ||||
132 | const QHash<VcsLocation,QByteArray> rightBinaries({{location, "rightbinary"}}); | ||||
133 | const QHash<VcsLocation,QString> leftTexts({{location, "lefttext"}}); | ||||
134 | const QHash<VcsLocation,QString> rightTexts({{location, "righttext"}}); | ||||
135 | | ||||
136 | { | ||||
137 | VcsDiff diffA; | ||||
138 | setDiff(diffA, | ||||
139 | type, contentType, diffString, baseDiff, depth, leftBinaries, rightBinaries, leftTexts, rightTexts); | ||||
140 | | ||||
141 | VcsDiff diffB; | ||||
142 | diffB = diffA; | ||||
143 | compareDiff(diffA, | ||||
144 | type, contentType, diffString, baseDiff, depth, leftBinaries, rightBinaries, leftTexts, rightTexts); | ||||
145 | compareDiff(diffB, | ||||
146 | type, contentType, diffString, baseDiff, depth, leftBinaries, rightBinaries, leftTexts, rightTexts); | ||||
147 | } | ||||
148 | | ||||
149 | const VcsDiff::Type typeNew = VcsDiff::DiffUnified; | ||||
150 | | ||||
151 | // test detach after changing A | ||||
152 | { | ||||
153 | VcsDiff diffA; | ||||
154 | setDiff(diffA, | ||||
155 | type, contentType, diffString, baseDiff, depth, leftBinaries, rightBinaries, leftTexts, rightTexts); | ||||
156 | | ||||
157 | VcsDiff diffB; | ||||
158 | diffB = diffA; | ||||
159 | // change a property of A | ||||
160 | diffA.setType(typeNew); | ||||
161 | | ||||
162 | compareDiff(diffA, | ||||
163 | typeNew, contentType, diffString, baseDiff, depth, leftBinaries, rightBinaries, leftTexts, rightTexts); | ||||
164 | compareDiff(diffB, | ||||
165 | type, contentType, diffString, baseDiff, depth, leftBinaries, rightBinaries, leftTexts, rightTexts); | ||||
166 | } | ||||
167 | } | ||||
168 | | ||||
169 | QTEST_GUILESS_MAIN(TestVcsDiff); |