Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/vcs/tests/test_vcsannotation.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_vcsannotation.h" | ||||
22 | | ||||
23 | #include <QTest> | ||||
24 | | ||||
25 | #include <vcs/vcsannotation.h> | ||||
26 | #include <vcs/vcsrevision.h> | ||||
27 | | ||||
28 | using namespace KDevelop; | ||||
29 | | ||||
30 | static | ||||
31 | VcsAnnotationLine createAnnotationLine(int lineNumber, | ||||
32 | const QString& text, | ||||
33 | const QString& author, | ||||
34 | const VcsRevision& revision, | ||||
35 | const QDateTime& date, | ||||
36 | const QString& commitMessage) | ||||
37 | { | ||||
38 | VcsAnnotationLine annotationLine; | ||||
39 | annotationLine.setLineNumber(lineNumber); | ||||
40 | annotationLine.setText(text); | ||||
41 | annotationLine.setAuthor(author); | ||||
42 | annotationLine.setRevision(revision); | ||||
43 | annotationLine.setDate(date); | ||||
44 | annotationLine.setCommitMessage(commitMessage); | ||||
45 | return annotationLine; | ||||
46 | } | ||||
47 | | ||||
48 | void TestVcsAnnotation::testCopyConstructor() | ||||
49 | { | ||||
50 | const int lineNumber = 1; | ||||
51 | const QString text("Text A"); | ||||
52 | const QString author("Author A"); | ||||
53 | VcsRevision revision; | ||||
54 | revision.setRevisionValue("A", VcsRevision::GlobalNumber); | ||||
55 | const QDateTime date = QDateTime::fromString("2001-01-01T00:00:00+00:00", Qt::ISODate); | ||||
56 | const QString commitMessage("Commit A"); | ||||
57 | const VcsAnnotationLine annotationLine = createAnnotationLine(lineNumber, text, author, revision, date, commitMessage); | ||||
58 | const QUrl location(QStringLiteral("git://foo")); | ||||
59 | | ||||
60 | // test plain copy | ||||
61 | { | ||||
62 | VcsAnnotation annotationA; | ||||
63 | annotationA.setLocation(location); | ||||
64 | annotationA.insertLine(lineNumber, annotationLine); | ||||
65 | | ||||
66 | VcsAnnotation annotationB(annotationA); | ||||
67 | | ||||
68 | QCOMPARE(annotationA.location(), location); | ||||
69 | QCOMPARE(annotationA.lineCount(), 1); | ||||
70 | QVERIFY(annotationA.containsLine(lineNumber)); | ||||
71 | QCOMPARE(annotationB.location(), location); | ||||
72 | QCOMPARE(annotationB.lineCount(), 1); | ||||
73 | QVERIFY(annotationB.containsLine(lineNumber)); | ||||
74 | } | ||||
75 | | ||||
76 | const QUrl locationNew(QStringLiteral("svn://bar")); | ||||
77 | | ||||
78 | // test detach after changing A | ||||
79 | { | ||||
80 | VcsAnnotation annotationA; | ||||
81 | annotationA.setLocation(location); | ||||
82 | annotationA.insertLine(lineNumber, annotationLine); | ||||
83 | | ||||
84 | VcsAnnotation annotationB(annotationA); | ||||
85 | // change a property of A | ||||
86 | annotationA.setLocation(locationNew); | ||||
87 | | ||||
88 | QCOMPARE(annotationA.location(), locationNew); | ||||
89 | QCOMPARE(annotationA.lineCount(), 1); | ||||
90 | QVERIFY(annotationA.containsLine(lineNumber)); | ||||
91 | QCOMPARE(annotationB.location(), location); | ||||
92 | QCOMPARE(annotationB.lineCount(), 1); | ||||
93 | QVERIFY(annotationB.containsLine(lineNumber)); | ||||
94 | } | ||||
95 | } | ||||
96 | | ||||
97 | void TestVcsAnnotation::testAssignOperator() | ||||
98 | { | ||||
99 | const int lineNumber = 1; | ||||
100 | const QString text("Text A"); | ||||
101 | const QString author("Author A"); | ||||
102 | VcsRevision revision; | ||||
103 | revision.setRevisionValue("A", VcsRevision::GlobalNumber); | ||||
104 | const QDateTime date = QDateTime::fromString("2001-01-01T00:00:00+00:00", Qt::ISODate); | ||||
105 | const QString commitMessage("Commit A"); | ||||
106 | const VcsAnnotationLine annotationLine = createAnnotationLine(lineNumber, text, author, revision, date, commitMessage); | ||||
107 | const QUrl location(QStringLiteral("http://kdevelop.org")); | ||||
108 | | ||||
109 | // test plain copy | ||||
110 | { | ||||
111 | VcsAnnotation annotationA; | ||||
112 | annotationA.setLocation(location); | ||||
113 | annotationA.insertLine(lineNumber, annotationLine); | ||||
114 | | ||||
115 | VcsAnnotation annotationB; | ||||
116 | annotationB = annotationA; | ||||
117 | | ||||
118 | QCOMPARE(annotationA.location(), location); | ||||
119 | QCOMPARE(annotationA.lineCount(), 1); | ||||
120 | QVERIFY(annotationA.containsLine(lineNumber)); | ||||
121 | QCOMPARE(annotationB.location(), location); | ||||
122 | QCOMPARE(annotationB.lineCount(), 1); | ||||
123 | QVERIFY(annotationB.containsLine(lineNumber)); | ||||
124 | } | ||||
125 | | ||||
126 | const QUrl locationNew(QStringLiteral("http://kate-editor.org")); | ||||
127 | | ||||
128 | // test detach after changing A | ||||
129 | { | ||||
130 | VcsAnnotation annotationA; | ||||
131 | annotationA.setLocation(location); | ||||
132 | annotationA.insertLine(lineNumber, annotationLine); | ||||
133 | | ||||
134 | VcsAnnotation annotationB; | ||||
135 | annotationB = annotationA; | ||||
136 | // change a property of A | ||||
137 | annotationA.setLocation(locationNew); | ||||
138 | | ||||
139 | QCOMPARE(annotationA.location(), locationNew); | ||||
140 | QCOMPARE(annotationA.lineCount(), 1); | ||||
141 | QVERIFY(annotationA.containsLine(lineNumber)); | ||||
142 | QCOMPARE(annotationB.location(), location); | ||||
143 | QCOMPARE(annotationB.lineCount(), 1); | ||||
144 | QVERIFY(annotationB.containsLine(lineNumber)); | ||||
145 | } | ||||
146 | } | ||||
147 | | ||||
148 | QTEST_GUILESS_MAIN(TestVcsAnnotation); |