Changeset View
Changeset View
Standalone View
Standalone View
plugins/perforce/test/test_perforce.cpp
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | * This file was inspired by KDevelop's git plugin * | ||||
3 | * Copyright 2008 Evgeniy Ivanov <powerfox@kde.ru> * | ||||
4 | * * | ||||
5 | * Adapted for Perforce * | ||||
6 | * Copyright 2011 Morten Danielsen Volden <mvolden2@gmail.com> * | ||||
7 | * * | ||||
8 | * This program is free software: you can redistribute it and/or modify * | ||||
9 | * it under the terms of the GNU General Public License as published by * | ||||
10 | * the Free Software Foundation, either version 2 of the License, or * | ||||
11 | * (at your option) any later version. * | ||||
12 | * * | ||||
13 | * This program is distributed in the hope that it will be useful, * | ||||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||||
16 | * GNU General Public License for more details. * | ||||
17 | * * | ||||
18 | * You should have received a copy of the GNU General Public License * | ||||
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. * | ||||
20 | ***************************************************************************/ | ||||
21 | | ||||
22 | #include "test_perforce.h" | ||||
23 | | ||||
24 | #include <QtTest/QtTest> | ||||
25 | | ||||
26 | #include <tests/autotestshell.h> | ||||
27 | #include <tests/testcore.h> | ||||
28 | | ||||
29 | #include <vcs/dvcs/dvcsjob.h> | ||||
30 | #include <vcs/vcsjob.h> | ||||
31 | #include <vcs/vcsannotation.h> | ||||
32 | | ||||
33 | #include <perforceplugin.h> | ||||
34 | | ||||
35 | #define VERIFYJOB(j) \ | ||||
36 | QVERIFY(j); QVERIFY(j->exec()); QVERIFY((j)->status() == VcsJob::JobSucceeded) | ||||
37 | | ||||
38 | const QString tempDir = QDir::tempPath(); | ||||
39 | const QString perforceTestBaseDirNoSlash(tempDir + "/kdevPerforce_testdir"); | ||||
40 | const QString perforceTestBaseDir(tempDir + "/kdevPerforce_testdir/"); | ||||
41 | const QString perforceTestBaseDir2(tempDir + "/kdevPerforce_testdir2/"); | ||||
42 | const QString perforceConfigFileName("p4config.txt"); | ||||
43 | | ||||
44 | const QString perforceSrcDir(perforceTestBaseDir + "src/"); | ||||
45 | const QString perforceTest_FileName("testfile"); | ||||
46 | const QString perforceTest_FileName2("foo"); | ||||
47 | const QString perforceTest_FileName3("bar"); | ||||
48 | | ||||
49 | using namespace KDevelop; | ||||
50 | | ||||
51 | void PerforcePluginTest::init() | ||||
52 | { | ||||
53 | AutoTestShell::init({"kdevperforce"}); | ||||
54 | m_core = new TestCore(); | ||||
55 | m_core->initialize(); | ||||
56 | m_plugin = new PerforcePlugin(m_core); | ||||
57 | /// During test we are setting the executable the plugin uses to our own stub | ||||
58 | m_plugin->m_perforceExecutable = P4_CLIENT_STUB_EXE; | ||||
59 | removeTempDirsIfAny(); | ||||
60 | createNewTempDirs(); | ||||
61 | } | ||||
62 | | ||||
63 | void PerforcePluginTest::createNewTempDirs() | ||||
64 | { | ||||
65 | // Now create the basic directory structure | ||||
66 | QDir tmpdir(tempDir); | ||||
67 | tmpdir.mkdir(perforceTestBaseDir); | ||||
68 | //we start it after repoInit, so we still have empty repo | ||||
69 | QFile f(perforceTestBaseDir + perforceConfigFileName); | ||||
70 | if (f.open(QIODevice::WriteOnly)) { | ||||
71 | QTextStream input(&f); | ||||
72 | input << "P4PORT=127.0.0.1:1666\n"; | ||||
73 | input << "P4USER=mvo\n"; | ||||
74 | input << "P4CLIENT=testbed\n"; | ||||
75 | } | ||||
76 | f.close(); | ||||
77 | | ||||
78 | //Put a file here because the annotate and update function will check for that | ||||
79 | QFile g(perforceTestBaseDir + perforceTest_FileName); | ||||
80 | if (g.open(QIODevice::WriteOnly)) { | ||||
81 | QTextStream input(&g); | ||||
82 | input << "HELLO WORLD"; | ||||
83 | } | ||||
84 | g.close(); | ||||
85 | | ||||
86 | | ||||
87 | tmpdir.mkdir(perforceSrcDir); | ||||
88 | tmpdir.mkdir(perforceTestBaseDir2); | ||||
89 | } | ||||
90 | | ||||
91 | | ||||
92 | void PerforcePluginTest::removeTempDirsIfAny() | ||||
93 | { | ||||
94 | QDir dir(perforceTestBaseDir); | ||||
95 | if (dir.exists() && !dir.removeRecursively()) | ||||
96 | qDebug() << "QDir::removeRecursively(" << perforceTestBaseDir << ") returned false"; | ||||
97 | | ||||
98 | QDir dir2(perforceTestBaseDir); | ||||
99 | if (dir2.exists() && !dir2.removeRecursively()) | ||||
100 | qDebug() << "QDir::removeRecursively(" << perforceTestBaseDir2 << ") returned false"; | ||||
101 | } | ||||
102 | | ||||
103 | | ||||
104 | void PerforcePluginTest::cleanup() | ||||
105 | { | ||||
106 | m_core->cleanup(); | ||||
107 | delete m_core; | ||||
108 | removeTempDirsIfAny(); | ||||
109 | } | ||||
110 | | ||||
111 | void PerforcePluginTest::testAdd() | ||||
112 | { | ||||
113 | VcsJob* j = m_plugin->add(QList<QUrl>({ QUrl::fromLocalFile(perforceTestBaseDir + perforceTest_FileName) } )); | ||||
114 | VERIFYJOB(j); | ||||
115 | } | ||||
116 | | ||||
117 | void PerforcePluginTest::testEdit() | ||||
118 | { | ||||
119 | VcsJob* j = m_plugin->edit(QList<QUrl>( { QUrl::fromLocalFile(perforceTestBaseDir + perforceTest_FileName) } )); | ||||
120 | VERIFYJOB(j); | ||||
121 | } | ||||
122 | | ||||
123 | void PerforcePluginTest::testEditMultipleFiles() | ||||
124 | { | ||||
125 | QList<QUrl> filesForEdit; | ||||
126 | filesForEdit.push_back(QUrl::fromLocalFile(perforceTestBaseDir + perforceTest_FileName)); | ||||
127 | filesForEdit.push_back(QUrl::fromLocalFile(perforceTestBaseDir + perforceTest_FileName2)); | ||||
128 | filesForEdit.push_back(QUrl::fromLocalFile(perforceTestBaseDir + perforceTest_FileName3)); | ||||
129 | VcsJob* j = m_plugin->edit(filesForEdit); | ||||
130 | VERIFYJOB(j); | ||||
131 | } | ||||
132 | | ||||
133 | | ||||
134 | void PerforcePluginTest::testStatus() | ||||
135 | { | ||||
136 | VcsJob* j = m_plugin->status(QList<QUrl>( { QUrl::fromLocalFile(perforceTestBaseDirNoSlash) } )); | ||||
137 | VERIFYJOB(j); | ||||
138 | } | ||||
139 | | ||||
140 | void PerforcePluginTest::testAnnotate() | ||||
141 | { | ||||
142 | VcsJob* j = m_plugin->annotate(QUrl( QUrl::fromLocalFile(perforceTestBaseDir + perforceTest_FileName) )); | ||||
143 | VERIFYJOB(j); | ||||
144 | } | ||||
145 | | ||||
146 | void PerforcePluginTest::testHistory() | ||||
147 | { | ||||
148 | VcsJob* j = m_plugin->log(QUrl( QUrl::fromLocalFile(perforceTestBaseDir + perforceTest_FileName) )); | ||||
149 | VERIFYJOB(j); | ||||
150 | } | ||||
151 | | ||||
152 | void PerforcePluginTest::testRevert() | ||||
153 | { | ||||
154 | VcsJob* j = m_plugin->revert(QList<QUrl>( { QUrl::fromLocalFile(perforceTestBaseDir + perforceTest_FileName) } )); | ||||
155 | VERIFYJOB(j); | ||||
156 | } | ||||
157 | | ||||
158 | void PerforcePluginTest::testUpdateFile() | ||||
159 | { | ||||
160 | VcsJob* j = m_plugin->update(QList<QUrl>( { QUrl::fromLocalFile(perforceTestBaseDir + perforceTest_FileName) } )); | ||||
161 | VERIFYJOB(j); | ||||
162 | } | ||||
163 | | ||||
164 | void PerforcePluginTest::testUpdateDir() | ||||
165 | { | ||||
166 | VcsJob* j = m_plugin->update(QList<QUrl>( { QUrl::fromLocalFile(perforceTestBaseDirNoSlash) } )); | ||||
167 | VERIFYJOB(j); | ||||
168 | } | ||||
169 | | ||||
170 | void PerforcePluginTest::testCommit() | ||||
171 | { | ||||
172 | QString commitMsg("this is the commit message"); | ||||
173 | VcsJob* j = m_plugin->commit(commitMsg, QList<QUrl>( { QUrl::fromLocalFile(perforceTestBaseDirNoSlash) } )); | ||||
174 | VERIFYJOB(j); | ||||
175 | } | ||||
176 | | ||||
177 | void PerforcePluginTest::testDiff() | ||||
178 | { | ||||
179 | VcsRevision srcRevision; | ||||
180 | srcRevision.setRevisionValue(QVariant(1), VcsRevision::GlobalNumber); | ||||
181 | VcsRevision dstRevision; | ||||
182 | dstRevision.setRevisionValue(QVariant(2), VcsRevision::GlobalNumber); | ||||
183 | | ||||
184 | VcsJob* j = m_plugin->diff( QUrl::fromLocalFile(perforceTestBaseDir + perforceTest_FileName), srcRevision, dstRevision, VcsDiff::Type::DiffUnified ); | ||||
185 | VERIFYJOB(j); | ||||
186 | } | ||||
187 | | ||||
188 | | ||||
189 | QTEST_MAIN(PerforcePluginTest) | ||||
190 | |