diff --git a/kdevplatform/vcs/CMakeLists.txt b/kdevplatform/vcs/CMakeLists.txt --- a/kdevplatform/vcs/CMakeLists.txt +++ b/kdevplatform/vcs/CMakeLists.txt @@ -1,6 +1,7 @@ add_definitions(-DTRANSLATION_DOMAIN=\"kdevplatform\") if(BUILD_TESTING) + add_subdirectory(tests) add_subdirectory(dvcs/tests) add_subdirectory(models/tests) endif() diff --git a/kdevplatform/vcs/tests/CMakeLists.txt b/kdevplatform/vcs/tests/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/kdevplatform/vcs/tests/CMakeLists.txt @@ -0,0 +1,27 @@ +ecm_add_test(test_vcsrevision + LINK_LIBRARIES Qt5::Test KDev::Vcs +) + +ecm_add_test(test_vcsannotationline + LINK_LIBRARIES Qt5::Test KDev::Vcs +) + +ecm_add_test(test_vcsannotation + LINK_LIBRARIES Qt5::Test KDev::Vcs +) + +ecm_add_test(test_vcsitemevent + LINK_LIBRARIES Qt5::Test KDev::Vcs +) + +ecm_add_test(test_vcsevent + LINK_LIBRARIES Qt5::Test KDev::Vcs +) + +ecm_add_test(test_vcsstatusinfo + LINK_LIBRARIES Qt5::Test KDev::Vcs +) + +ecm_add_test(test_vcsdiff + LINK_LIBRARIES Qt5::Test KDev::Vcs +) diff --git a/kdevplatform/vcs/tests/test_vcsannotation.h b/kdevplatform/vcs/tests/test_vcsannotation.h new file mode 100644 --- /dev/null +++ b/kdevplatform/vcs/tests/test_vcsannotation.h @@ -0,0 +1,35 @@ +/* This file is part of KDevelop + * + * Copyright 2017 Friedrich W. H. Kossebau + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef KDEVPLATFORM_TESTVCSANNOTATION_H +#define KDEVPLATFORM_TESTVCSANNOTATION_H + +#include + +class TestVcsAnnotation : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void testCopyConstructor(); + void testAssignOperator(); +}; + +#endif // KDEVPLATFORM_TESTVCSANNOTATION_H diff --git a/kdevplatform/vcs/tests/test_vcsannotation.cpp b/kdevplatform/vcs/tests/test_vcsannotation.cpp new file mode 100644 --- /dev/null +++ b/kdevplatform/vcs/tests/test_vcsannotation.cpp @@ -0,0 +1,148 @@ +/* This file is part of KDevelop + * + * Copyright 2017 Friedrich W. H. Kossebau + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include "test_vcsannotation.h" + +#include + +#include +#include + +using namespace KDevelop; + +static +VcsAnnotationLine createAnnotationLine(int lineNumber, + const QString& text, + const QString& author, + const VcsRevision& revision, + const QDateTime& date, + const QString& commitMessage) +{ + VcsAnnotationLine annotationLine; + annotationLine.setLineNumber(lineNumber); + annotationLine.setText(text); + annotationLine.setAuthor(author); + annotationLine.setRevision(revision); + annotationLine.setDate(date); + annotationLine.setCommitMessage(commitMessage); + return annotationLine; +} + +void TestVcsAnnotation::testCopyConstructor() +{ + const int lineNumber = 1; + const QString text("Text A"); + const QString author("Author A"); + VcsRevision revision; + revision.setRevisionValue("A", VcsRevision::GlobalNumber); + const QDateTime date = QDateTime::fromString("2001-01-01T00:00:00+00:00", Qt::ISODate); + const QString commitMessage("Commit A"); + const VcsAnnotationLine annotationLine = createAnnotationLine(lineNumber, text, author, revision, date, commitMessage); + const QUrl location(QStringLiteral("git://foo")); + + // test plain copy + { + VcsAnnotation annotationA; + annotationA.setLocation(location); + annotationA.insertLine(lineNumber, annotationLine); + + VcsAnnotation annotationB(annotationA); + + QCOMPARE(annotationA.location(), location); + QCOMPARE(annotationA.lineCount(), 1); + QVERIFY(annotationA.containsLine(lineNumber)); + QCOMPARE(annotationB.location(), location); + QCOMPARE(annotationB.lineCount(), 1); + QVERIFY(annotationB.containsLine(lineNumber)); + } + + const QUrl locationNew(QStringLiteral("svn://bar")); + + // test detach after changing A + { + VcsAnnotation annotationA; + annotationA.setLocation(location); + annotationA.insertLine(lineNumber, annotationLine); + + VcsAnnotation annotationB(annotationA); + // change a property of A + annotationA.setLocation(locationNew); + + QCOMPARE(annotationA.location(), locationNew); + QCOMPARE(annotationA.lineCount(), 1); + QVERIFY(annotationA.containsLine(lineNumber)); + QCOMPARE(annotationB.location(), location); + QCOMPARE(annotationB.lineCount(), 1); + QVERIFY(annotationB.containsLine(lineNumber)); + } +} + +void TestVcsAnnotation::testAssignOperator() +{ + const int lineNumber = 1; + const QString text("Text A"); + const QString author("Author A"); + VcsRevision revision; + revision.setRevisionValue("A", VcsRevision::GlobalNumber); + const QDateTime date = QDateTime::fromString("2001-01-01T00:00:00+00:00", Qt::ISODate); + const QString commitMessage("Commit A"); + const VcsAnnotationLine annotationLine = createAnnotationLine(lineNumber, text, author, revision, date, commitMessage); + const QUrl location(QStringLiteral("http://kdevelop.org")); + + // test plain copy + { + VcsAnnotation annotationA; + annotationA.setLocation(location); + annotationA.insertLine(lineNumber, annotationLine); + + VcsAnnotation annotationB; + annotationB = annotationA; + + QCOMPARE(annotationA.location(), location); + QCOMPARE(annotationA.lineCount(), 1); + QVERIFY(annotationA.containsLine(lineNumber)); + QCOMPARE(annotationB.location(), location); + QCOMPARE(annotationB.lineCount(), 1); + QVERIFY(annotationB.containsLine(lineNumber)); + } + + const QUrl locationNew(QStringLiteral("http://kate-editor.org")); + + // test detach after changing A + { + VcsAnnotation annotationA; + annotationA.setLocation(location); + annotationA.insertLine(lineNumber, annotationLine); + + VcsAnnotation annotationB; + annotationB = annotationA; + // change a property of A + annotationA.setLocation(locationNew); + + QCOMPARE(annotationA.location(), locationNew); + QCOMPARE(annotationA.lineCount(), 1); + QVERIFY(annotationA.containsLine(lineNumber)); + QCOMPARE(annotationB.location(), location); + QCOMPARE(annotationB.lineCount(), 1); + QVERIFY(annotationB.containsLine(lineNumber)); + } +} + +QTEST_GUILESS_MAIN(TestVcsAnnotation); diff --git a/kdevplatform/vcs/tests/test_vcsannotationline.h b/kdevplatform/vcs/tests/test_vcsannotationline.h new file mode 100644 --- /dev/null +++ b/kdevplatform/vcs/tests/test_vcsannotationline.h @@ -0,0 +1,58 @@ +/* This file is part of KDevelop + * + * Copyright 2017 Friedrich W. H. Kossebau + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef KDEVPLATFORM_TESTVCSANNOTATIONLINE_H +#define KDEVPLATFORM_TESTVCSANNOTATIONLINE_H + +#include + +namespace KDevelop { +class VcsAnnotationLine; +class VcsRevision; +} +class QDateTime; +class QString; + +class TestVcsAnnotationLine : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void testCopyConstructor(); + void testAssignOperator(); + +private: + void setAnnotationLine(KDevelop::VcsAnnotationLine& annotationLine, + int lineNumber, + const QString& text, + const QString& author, + const KDevelop::VcsRevision& revision, + const QDateTime& date, + const QString& commitMessage); + void compareAnnotationLine(const KDevelop::VcsAnnotationLine& annotationLine, + int lineNumber, + const QString& text, + const QString& author, + const KDevelop::VcsRevision& revision, + const QDateTime& date, + const QString& commitMessage); +}; + +#endif // KDEVPLATFORM_TESTVCSANNOTATIONLINE_H diff --git a/kdevplatform/vcs/tests/test_vcsannotationline.cpp b/kdevplatform/vcs/tests/test_vcsannotationline.cpp new file mode 100644 --- /dev/null +++ b/kdevplatform/vcs/tests/test_vcsannotationline.cpp @@ -0,0 +1,173 @@ +/* This file is part of KDevelop + * + * Copyright 2017 Friedrich W. H. Kossebau + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include "test_vcsannotationline.h" + +#include + +#include +#include + +using namespace KDevelop; + +void TestVcsAnnotationLine::setAnnotationLine(VcsAnnotationLine& annotationLine, + int lineNumber, + const QString& text, + const QString& author, + const VcsRevision& revision, + const QDateTime& date, + const QString& commitMessage) +{ + annotationLine.setLineNumber(lineNumber); + annotationLine.setText(text); + annotationLine.setAuthor(author); + annotationLine.setRevision(revision); + annotationLine.setDate(date); + annotationLine.setCommitMessage(commitMessage); +} + +void TestVcsAnnotationLine::compareAnnotationLine(const VcsAnnotationLine& annotationLine, + int lineNumber, + const QString& text, + const QString& author, + const VcsRevision& revision, + const QDateTime& date, + const QString& commitMessage) +{ + QCOMPARE(annotationLine.lineNumber(), lineNumber); + QCOMPARE(annotationLine.text(), text); + QCOMPARE(annotationLine.author(), author); + QCOMPARE(annotationLine.revision(), revision); + QCOMPARE(annotationLine.date(), date); + QCOMPARE(annotationLine.commitMessage(), commitMessage); +} + +void TestVcsAnnotationLine::testCopyConstructor() +{ + // copy invalid + { + VcsAnnotationLine annotationLineA; + + VcsAnnotationLine annotationLineB(annotationLineA); + QCOMPARE(annotationLineA.revision().revisionType(), VcsRevision::Invalid); + QCOMPARE(annotationLineB.revision().revisionType(), VcsRevision::Invalid); + } + + // test plain copy + const int lineNumber = 1; + const QString text("Text A"); + const QString author("Author A"); + VcsRevision revision; + revision.setRevisionValue("A", VcsRevision::GlobalNumber); + const QDateTime date = QDateTime::fromString("2001-01-01T00:00:00+00:00", Qt::ISODate); + const QString commitMessage("Commit A"); + + { + VcsAnnotationLine annotationLineA; + setAnnotationLine(annotationLineA, + lineNumber, text, author, revision, date, commitMessage); + + VcsAnnotationLine annotationLineB(annotationLineA); + compareAnnotationLine(annotationLineA, + lineNumber, text, author, revision, date, commitMessage); + compareAnnotationLine(annotationLineB, + lineNumber, text, author, revision, date, commitMessage); + } + + const int lineNumberNew = 10; + + // test detach after changing A + { + VcsAnnotationLine annotationLineA; + setAnnotationLine(annotationLineA, + lineNumber, text, author, revision, date, commitMessage); + + VcsAnnotationLine annotationLineB(annotationLineA); + // change a property of A + annotationLineA.setLineNumber(lineNumberNew); + + compareAnnotationLine(annotationLineA, + lineNumberNew, text, author, revision, date, commitMessage); + compareAnnotationLine(annotationLineB, + lineNumber, text, author, revision, date, commitMessage); + } +} + +void TestVcsAnnotationLine::testAssignOperator() +{ + // assign invalid + { + VcsAnnotationLine annotationLineA; + + VcsAnnotationLine annotationLineB; + VcsRevision revision; + revision.setRevisionValue(2, VcsRevision::FileNumber); + annotationLineB.setRevision(revision); + + annotationLineB = annotationLineA; + + QCOMPARE(annotationLineA.revision().revisionType(), VcsRevision::Invalid); + QCOMPARE(annotationLineB.revision().revisionType(), VcsRevision::Invalid); + } + + // test plain assign + const int lineNumber = 1; + const QString text("Text A"); + const QString author("Author A"); + VcsRevision revision; + revision.setRevisionValue("A", VcsRevision::GlobalNumber); + const QDateTime date = QDateTime::fromString("2001-01-01T00:00:00+00:00", Qt::ISODate); + const QString commitMessage("Commit A"); + + { + VcsAnnotationLine annotationLineA; + setAnnotationLine(annotationLineA, + lineNumber, text, author, revision, date, commitMessage); + + VcsAnnotationLine annotationLineB; + annotationLineB = annotationLineA; + + compareAnnotationLine(annotationLineA, + lineNumber, text, author, revision, date, commitMessage); + compareAnnotationLine(annotationLineB, + lineNumber, text, author, revision, date, commitMessage); + } + + const int lineNumberNew = 10; + + // test detach after changing A + { + VcsAnnotationLine annotationLineA; + setAnnotationLine(annotationLineA, + lineNumber, text, author, revision, date, commitMessage); + + VcsAnnotationLine annotationLineB; + annotationLineB = annotationLineA; + // change a property of A + annotationLineA.setLineNumber(lineNumberNew); + + compareAnnotationLine(annotationLineA, + lineNumberNew, text, author, revision, date, commitMessage); + compareAnnotationLine(annotationLineB, + lineNumber, text, author, revision, date, commitMessage); + } +} + +QTEST_GUILESS_MAIN(TestVcsAnnotationLine); diff --git a/kdevplatform/vcs/tests/test_vcsdiff.h b/kdevplatform/vcs/tests/test_vcsdiff.h new file mode 100644 --- /dev/null +++ b/kdevplatform/vcs/tests/test_vcsdiff.h @@ -0,0 +1,59 @@ +/* This file is part of KDevelop + * + * Copyright 2017 Friedrich W. H. Kossebau + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef KDEVPLATFORM_TESTVCSDIFF_H +#define KDEVPLATFORM_TESTVCSDIFF_H + +#include + +#include "vcsdiff.h" + +class TestVcsDiff : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void testCopyConstructor(); + void testAssignOperator(); + +private: + void setDiff(KDevelop::VcsDiff& diff, + KDevelop::VcsDiff::Type type, + KDevelop::VcsDiff::Content contentType, + const QString& diffString, + const QUrl& baseDiff, + uint depth, + const QHash& leftBinaries, + const QHash& rightBinaries, + const QHash& leftTexts, + const QHash& rightTexts); + void compareDiff(const KDevelop::VcsDiff& diff, + KDevelop::VcsDiff::Type type, + KDevelop::VcsDiff::Content contentType, + const QString& diffString, + const QUrl& baseDiff, + uint depth, + const QHash& leftBinaries, + const QHash& rightBinaries, + const QHash& leftTexts, + const QHash& rightTexts); +}; + +#endif // KDEVPLATFORM_TESTVCSDIFF_H diff --git a/kdevplatform/vcs/tests/test_vcsdiff.cpp b/kdevplatform/vcs/tests/test_vcsdiff.cpp new file mode 100644 --- /dev/null +++ b/kdevplatform/vcs/tests/test_vcsdiff.cpp @@ -0,0 +1,169 @@ +/* This file is part of KDevelop + * + * Copyright 2017 Friedrich W. H. Kossebau + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include "test_vcsdiff.h" + +#include + +#include + +using namespace KDevelop; + +void TestVcsDiff::setDiff(VcsDiff& diff, + VcsDiff::Type type, + VcsDiff::Content contentType, + const QString& diffString, + const QUrl& baseDiff, + uint depth, + const QHash& leftBinaries, + const QHash& rightBinaries, + const QHash& leftTexts, + const QHash& rightTexts) +{ + diff.setType(type); + diff.setContentType(contentType); + diff.setDiff(diffString); + diff.setBaseDiff(baseDiff); + diff.setDepth(depth); + for (auto it = leftBinaries.begin(); it != leftBinaries.end(); ++it) + diff.addLeftBinary(it.key(), it.value()); + for (auto it = rightBinaries.begin(); it != rightBinaries.end(); ++it) + diff.addRightBinary(it.key(), it.value()); + for (auto it = leftTexts.begin(); it != leftTexts.end(); ++it) + diff.addLeftText(it.key(), it.value()); + for (auto it = rightTexts.begin(); it != rightTexts.end(); ++it) + diff.addRightText(it.key(), it.value()); +} + +void TestVcsDiff::compareDiff(const VcsDiff& diff, + VcsDiff::Type type, + VcsDiff::Content contentType, + const QString& diffString, + const QUrl& baseDiff, + uint depth, + const QHash& leftBinaries, + const QHash& rightBinaries, + const QHash& leftTexts, + const QHash& rightTexts) +{ + QCOMPARE(diff.type(), type); + QCOMPARE(diff.contentType(), contentType); + QCOMPARE(diff.diff(), diffString); + QCOMPARE(diff.baseDiff(), baseDiff); + QCOMPARE(diff.depth(), depth); + QCOMPARE(diff.leftBinaries(), leftBinaries); + QCOMPARE(diff.rightBinaries(), rightBinaries); + QCOMPARE(diff.leftTexts(), leftTexts); + QCOMPARE(diff.rightTexts(), rightTexts); +} + +void TestVcsDiff::testCopyConstructor() +{ + // test plain copy + const VcsDiff::Type type = VcsDiff::DiffRaw; + const VcsDiff::Content contentType = VcsDiff::Binary; + const QString diffString("diff"); + const QUrl baseDiff("git://1"); + const uint depth = 1; + const VcsLocation location("server"); + const QHash leftBinaries({{location, "leftbinary"}}); + const QHash rightBinaries({{location, "rightbinary"}}); + const QHash leftTexts({{location, "lefttext"}}); + const QHash rightTexts({{location, "righttext"}}); + + { + VcsDiff diffA; + setDiff(diffA, + type, contentType, diffString, baseDiff, depth, leftBinaries, rightBinaries, leftTexts, rightTexts); + + VcsDiff diffB(diffA); + compareDiff(diffA, + type, contentType, diffString, baseDiff, depth, leftBinaries, rightBinaries, leftTexts, rightTexts); + compareDiff(diffB, + type, contentType, diffString, baseDiff, depth, leftBinaries, rightBinaries, leftTexts, rightTexts); + } + + const VcsDiff::Type typeNew = VcsDiff::DiffUnified; + + // test detach after changing A + { + VcsDiff diffA; + setDiff(diffA, + type, contentType, diffString, baseDiff, depth, leftBinaries, rightBinaries, leftTexts, rightTexts); + + VcsDiff diffB(diffA); + // change a property of A + diffA.setType(typeNew); + + compareDiff(diffA, + typeNew, contentType, diffString, baseDiff, depth, leftBinaries, rightBinaries, leftTexts, rightTexts); + compareDiff(diffB, + type, contentType, diffString, baseDiff, depth, leftBinaries, rightBinaries, leftTexts, rightTexts); + } +} + +void TestVcsDiff::testAssignOperator() +{ + // test plain copy + const VcsDiff::Type type = VcsDiff::DiffRaw; + const VcsDiff::Content contentType = VcsDiff::Binary; + const QString diffString("diff"); + const QUrl baseDiff("git://1"); + const uint depth = 1; + const VcsLocation location("server"); + const QHash leftBinaries({{location, "leftbinary"}}); + const QHash rightBinaries({{location, "rightbinary"}}); + const QHash leftTexts({{location, "lefttext"}}); + const QHash rightTexts({{location, "righttext"}}); + + { + VcsDiff diffA; + setDiff(diffA, + type, contentType, diffString, baseDiff, depth, leftBinaries, rightBinaries, leftTexts, rightTexts); + + VcsDiff diffB; + diffB = diffA; + compareDiff(diffA, + type, contentType, diffString, baseDiff, depth, leftBinaries, rightBinaries, leftTexts, rightTexts); + compareDiff(diffB, + type, contentType, diffString, baseDiff, depth, leftBinaries, rightBinaries, leftTexts, rightTexts); + } + + const VcsDiff::Type typeNew = VcsDiff::DiffUnified; + + // test detach after changing A + { + VcsDiff diffA; + setDiff(diffA, + type, contentType, diffString, baseDiff, depth, leftBinaries, rightBinaries, leftTexts, rightTexts); + + VcsDiff diffB; + diffB = diffA; + // change a property of A + diffA.setType(typeNew); + + compareDiff(diffA, + typeNew, contentType, diffString, baseDiff, depth, leftBinaries, rightBinaries, leftTexts, rightTexts); + compareDiff(diffB, + type, contentType, diffString, baseDiff, depth, leftBinaries, rightBinaries, leftTexts, rightTexts); + } +} + +QTEST_GUILESS_MAIN(TestVcsDiff); diff --git a/kdevplatform/vcs/tests/test_vcsevent.h b/kdevplatform/vcs/tests/test_vcsevent.h new file mode 100644 --- /dev/null +++ b/kdevplatform/vcs/tests/test_vcsevent.h @@ -0,0 +1,57 @@ +/* This file is part of KDevelop + * + * Copyright 2017 Friedrich W. H. Kossebau + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef KDEVPLATFORM_TESTVCSEVENT_H +#define KDEVPLATFORM_TESTVCSEVENT_H + +#include +#include +#include + +namespace KDevelop { +class VcsRevision; +} +class QDateTime; +class QString; + +class TestVcsEvent : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void testCopyConstructor(); + void testAssignOperator(); + +private: + void setEvent(KDevelop::VcsEvent& event, + const KDevelop::VcsRevision& revision, + const QString& author, + const QDateTime& date, + const QString& message, + const QList& items); + void compareEvent(const KDevelop::VcsEvent& event, + const KDevelop::VcsRevision& revision, + const QString& author, + const QDateTime& date, + const QString& message, + const QList& items); +}; + +#endif // KDEVPLATFORM_TESTVCSEVENT_H diff --git a/kdevplatform/vcs/tests/test_vcsevent.cpp b/kdevplatform/vcs/tests/test_vcsevent.cpp new file mode 100644 --- /dev/null +++ b/kdevplatform/vcs/tests/test_vcsevent.cpp @@ -0,0 +1,145 @@ +/* This file is part of KDevelop + * + * Copyright 2017 Friedrich W. H. Kossebau + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include "test_vcsevent.h" + +#include + +#include + +using namespace KDevelop; + +void TestVcsEvent::setEvent(VcsEvent& event, + const VcsRevision& revision, + const QString& author, + const QDateTime& date, + const QString& message, + const QList& items) +{ + event.setRevision(revision); + event.setAuthor(author); + event.setDate(date); + event.setMessage(message); + event.setItems(items); +} + +void TestVcsEvent::compareEvent(const VcsEvent& event, + const VcsRevision& revision, + const QString& author, + const QDateTime& date, + const QString& message, + const QList& items) +{ + QCOMPARE(event.revision(), revision); + QCOMPARE(event.author(), author); + QCOMPARE(event.date(), date); + QCOMPARE(event.message(), message); + QCOMPARE(event.items().count(), items.count()); +} + +void TestVcsEvent::testCopyConstructor() +{ + // test plain copy + VcsRevision revision; + revision.setRevisionValue("A", VcsRevision::GlobalNumber); + const QString author("author"); + const QDateTime date = QDateTime::fromString("2001-01-01T00:00:00+00:00", Qt::ISODate); + const QString message("message"); + const QList items({{}}); + + { + VcsEvent eventA; + setEvent(eventA, + revision, author, date, message, items); + + VcsEvent eventB(eventA); + + compareEvent(eventA, + revision, author, date, message, items); + compareEvent(eventB, + revision, author, date, message, items); + } + + VcsRevision revisionNew; + revisionNew.setRevisionValue(2, VcsRevision::FileNumber); + + // test detach after changing A + { + VcsEvent eventA; + setEvent(eventA, + revision, author, date, message, items); + + VcsEvent eventB(eventA); + // change a property of A + eventA.setRevision(revisionNew); + + compareEvent(eventA, + revisionNew, author, date, message, items); + compareEvent(eventB, + revision, author, date, message, items); + } +} + +void TestVcsEvent::testAssignOperator() +{ + // test plain copy + VcsRevision revision; + revision.setRevisionValue("A", VcsRevision::GlobalNumber); + const QString author("author"); + const QDateTime date = QDateTime::fromString("2001-01-01T00:00:00+00:00", Qt::ISODate); + const QString message("message"); + const QList items({{}}); + + { + VcsEvent eventA; + setEvent(eventA, + revision, author, date, message, items); + + VcsEvent eventB; + eventB = eventA; + + compareEvent(eventA, + revision, author, date, message, items); + compareEvent(eventB, + revision, author, date, message, items); + } + + VcsRevision revisionNew; + revisionNew.setRevisionValue(2, VcsRevision::FileNumber); + + // test detach after changing A + { + VcsEvent eventA; + setEvent(eventA, + revision, author, date, message, items); + + VcsEvent eventB; + eventB = eventA; + // change a property of A + eventA.setRevision(revisionNew); + + compareEvent(eventA, + revisionNew, author, date, message, items); + compareEvent(eventB, + revision, author, date, message, items); + } +} + +QTEST_GUILESS_MAIN(TestVcsEvent); diff --git a/kdevplatform/vcs/tests/test_vcsitemevent.h b/kdevplatform/vcs/tests/test_vcsitemevent.h new file mode 100644 --- /dev/null +++ b/kdevplatform/vcs/tests/test_vcsitemevent.h @@ -0,0 +1,53 @@ +/* This file is part of KDevelop + * + * Copyright 2017 Friedrich W. H. Kossebau + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef KDEVPLATFORM_TESTVCSITEMEVENT_H +#define KDEVPLATFORM_TESTVCSITEMEVENT_H + +#include +#include + +namespace KDevelop { +class VcsRevision; +} +class QString; + +class TestVcsItemEvent : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void testCopyConstructor(); + void testAssignOperator(); + +private: + void setItemEvent(KDevelop::VcsItemEvent& itemEvent, + const QString& repositoryLocation, + const QString& repositoryCopySourceLocation, + const KDevelop::VcsRevision& repositoryCopySourceRevision, + KDevelop::VcsItemEvent::Actions actions); + void compareItemEvent(const KDevelop::VcsItemEvent& itemEvent, + const QString& repositoryLocation, + const QString& repositoryCopySourceLocation, + const KDevelop::VcsRevision& repositoryCopySourceRevision, + KDevelop::VcsItemEvent::Actions actions); +}; + +#endif // KDEVPLATFORM_TESTVCSITEMEVENT_H diff --git a/kdevplatform/vcs/tests/test_vcsitemevent.cpp b/kdevplatform/vcs/tests/test_vcsitemevent.cpp new file mode 100644 --- /dev/null +++ b/kdevplatform/vcs/tests/test_vcsitemevent.cpp @@ -0,0 +1,145 @@ +/* This file is part of KDevelop + * + * Copyright 2017 Friedrich W. H. Kossebau + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include "test_vcsitemevent.h" + +#include + +#include + +using namespace KDevelop; + +void TestVcsItemEvent::setItemEvent(VcsItemEvent& itemEvent, + const QString& repositoryLocation, + const QString& repositoryCopySourceLocation, + const VcsRevision& repositoryCopySourceRevision, + VcsItemEvent::Actions actions) +{ + itemEvent.setRepositoryLocation(repositoryLocation); + itemEvent.setRepositoryCopySourceLocation(repositoryCopySourceLocation); + itemEvent.setRepositoryCopySourceRevision(repositoryCopySourceRevision); + itemEvent.setActions(actions); +} + +void TestVcsItemEvent::compareItemEvent(const VcsItemEvent& itemEvent, + const QString& repositoryLocation, + const QString& repositoryCopySourceLocation, + const VcsRevision& repositoryCopySourceRevision, + VcsItemEvent::Actions actions) +{ + QCOMPARE(itemEvent.repositoryLocation(), repositoryLocation); + QCOMPARE(itemEvent.repositoryCopySourceLocation(), repositoryCopySourceLocation); + QCOMPARE(itemEvent.repositoryCopySourceRevision(), repositoryCopySourceRevision); + QCOMPARE(itemEvent.actions(), actions); +} + +void TestVcsItemEvent::testCopyConstructor() +{ + // test plain copy + const QString repositoryLocation("location"); + const QString repositoryCopySourceLocation("copy source location"); + VcsRevision repositoryCopySourceRevision; + repositoryCopySourceRevision.setRevisionValue("A", VcsRevision::GlobalNumber); + const VcsItemEvent::Actions actions = VcsItemEvent::Added; + + { + VcsItemEvent itemEventA; + setItemEvent(itemEventA, + repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, actions); + + VcsItemEvent itemEventB(itemEventA); + + compareItemEvent(itemEventA, + repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, + actions); + compareItemEvent(itemEventB, + repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, + actions); + } + + const QString repositoryLocationNew("new location"); + + // test detach after changing A + { + VcsItemEvent itemEventA; + setItemEvent(itemEventA, + repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, actions); + + VcsItemEvent itemEventB(itemEventA); + // change a property of A + itemEventA.setRepositoryLocation(repositoryLocationNew); + + compareItemEvent(itemEventA, + repositoryLocationNew, repositoryCopySourceLocation, repositoryCopySourceRevision, + actions); + compareItemEvent(itemEventB, + repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, + actions); + } +} + +void TestVcsItemEvent::testAssignOperator() +{ + // test plain assign + const QString repositoryLocation("location"); + const QString repositoryCopySourceLocation("copy source location"); + VcsRevision repositoryCopySourceRevision; + repositoryCopySourceRevision.setRevisionValue("A", VcsRevision::GlobalNumber); + const VcsItemEvent::Actions actions = VcsItemEvent::Added; + + { + VcsItemEvent itemEventA; + setItemEvent(itemEventA, + repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, actions); + + VcsItemEvent itemEventB; + itemEventB = itemEventA; + + compareItemEvent(itemEventA, + repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, + actions); + compareItemEvent(itemEventB, + repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, + actions); + } + + const QString repositoryLocationNew("new location"); + + // test detach after changing A + { + VcsItemEvent itemEventA; + setItemEvent(itemEventA, + repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, actions); + + VcsItemEvent itemEventB; + itemEventB = itemEventA; + // change a property of A + itemEventA.setRepositoryLocation(repositoryLocationNew); + + compareItemEvent(itemEventA, + repositoryLocationNew, repositoryCopySourceLocation, repositoryCopySourceRevision, + actions); + compareItemEvent(itemEventB, + repositoryLocation, repositoryCopySourceLocation, repositoryCopySourceRevision, + actions); + } +} + +QTEST_GUILESS_MAIN(TestVcsItemEvent); diff --git a/kdevplatform/vcs/tests/test_vcsrevision.h b/kdevplatform/vcs/tests/test_vcsrevision.h new file mode 100644 --- /dev/null +++ b/kdevplatform/vcs/tests/test_vcsrevision.h @@ -0,0 +1,35 @@ +/* This file is part of KDevelop + * + * Copyright 2017 Friedrich W. H. Kossebau + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef KDEVPLATFORM_TESTVCSREVISION_H +#define KDEVPLATFORM_TESTVCSREVISION_H + +#include + +class TestVcsRevision : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void testCopyConstructor(); + void testAssignOperator(); +}; + +#endif // KDEVPLATFORM_TESTVCSREVISION_H diff --git a/kdevplatform/vcs/tests/test_vcsrevision.cpp b/kdevplatform/vcs/tests/test_vcsrevision.cpp new file mode 100644 --- /dev/null +++ b/kdevplatform/vcs/tests/test_vcsrevision.cpp @@ -0,0 +1,138 @@ +/* This file is part of KDevelop + * + * Copyright 2017 Friedrich W. H. Kossebau + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include "test_vcsrevision.h" + +#include + +#include + +using namespace KDevelop; + +void TestVcsRevision::testCopyConstructor() +{ + // copy invalid + { + VcsRevision revisionA; + VcsRevision revisionB(revisionA); + QCOMPARE(revisionA.revisionType(), VcsRevision::Invalid); + QCOMPARE(revisionB.revisionType(), VcsRevision::Invalid); + QVERIFY(revisionB == revisionA); + QVERIFY(revisionA == revisionB); + } + + const VcsRevision::RevisionType revisionType = VcsRevision::GlobalNumber; + const QString globalNumberValue("A"); + + // test plain copy + { + VcsRevision revisionA; + revisionA.setRevisionValue(globalNumberValue, revisionType); + + VcsRevision revisionB(revisionA); + QCOMPARE(revisionA.revisionType(), revisionType); + QCOMPARE(revisionA.revisionValue().toString(), globalNumberValue); + QCOMPARE(revisionB.revisionType(), revisionType); + QCOMPARE(revisionB.revisionValue().toString(), globalNumberValue); + QVERIFY(revisionB == revisionA); + QVERIFY(revisionA == revisionB); + } + + const VcsRevision::RevisionType revisionTypeNew = VcsRevision::FileNumber; + const qlonglong fileNumberValueNew = 2; + + // test detach after changing A + { + VcsRevision revisionA; + revisionA.setRevisionValue(globalNumberValue, revisionType); + + VcsRevision revisionB(revisionA); + revisionA.setRevisionValue(fileNumberValueNew, revisionTypeNew); + + QCOMPARE(revisionA.revisionType(), revisionTypeNew); + QCOMPARE(revisionA.revisionValue().toLongLong(), fileNumberValueNew); + QCOMPARE(revisionB.revisionType(), revisionType); + QCOMPARE(revisionB.revisionValue().toString(), globalNumberValue); + QVERIFY(!(revisionB == revisionA)); + QVERIFY(!(revisionA == revisionB)); + } +} + +void TestVcsRevision::testAssignOperator() +{ + // assign invalid + { + const VcsRevision::RevisionType typeB = VcsRevision::FileNumber; + const qlonglong fileNumberB = 2; + + VcsRevision revisionA; + + VcsRevision revisionB; + revisionB.setRevisionValue(fileNumberB, typeB); + + revisionB = revisionA; + + QCOMPARE(revisionA.revisionType(), VcsRevision::Invalid); + QCOMPARE(revisionB.revisionType(), VcsRevision::Invalid); + QVERIFY(revisionB == revisionA); + QVERIFY(revisionA == revisionB); + } + + const VcsRevision::RevisionType revisionType = VcsRevision::GlobalNumber; + const QString globalNumberValue("A"); + + // test plain assign + { + VcsRevision revisionA; + revisionA.setRevisionValue(globalNumberValue, revisionType); + + VcsRevision revisionB; + revisionB = revisionA; + + QCOMPARE(revisionA.revisionType(), revisionType); + QCOMPARE(revisionA.revisionValue().toString(), globalNumberValue); + QCOMPARE(revisionB.revisionType(), revisionType); + QCOMPARE(revisionB.revisionValue().toString(), globalNumberValue); + QVERIFY(revisionB == revisionA); + QVERIFY(revisionA == revisionB); + } + + const VcsRevision::RevisionType revisionTypeNew = VcsRevision::FileNumber; + const qlonglong fileNumberValueNew = 2; + + // test detach after changing A + { + VcsRevision revisionA; + revisionA.setRevisionValue(globalNumberValue, revisionType); + + VcsRevision revisionB; + revisionB = revisionA; + revisionA.setRevisionValue(fileNumberValueNew, revisionTypeNew); + + QCOMPARE(revisionA.revisionType(), revisionTypeNew); + QCOMPARE(revisionA.revisionValue().toLongLong(), fileNumberValueNew); + QCOMPARE(revisionB.revisionType(), revisionType); + QCOMPARE(revisionB.revisionValue().toString(), globalNumberValue); + QVERIFY(!(revisionB == revisionA)); + QVERIFY(!(revisionA == revisionB)); + } +} + +QTEST_GUILESS_MAIN(TestVcsRevision); diff --git a/kdevplatform/vcs/tests/test_vcsstatusinfo.h b/kdevplatform/vcs/tests/test_vcsstatusinfo.h new file mode 100644 --- /dev/null +++ b/kdevplatform/vcs/tests/test_vcsstatusinfo.h @@ -0,0 +1,37 @@ +/* This file is part of KDevelop + * + * Copyright 2017 Friedrich W. H. Kossebau + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef KDEVPLATFORM_TESTVCSSTATUSINFO_H +#define KDEVPLATFORM_TESTVCSSTATUSINFO_H + +#include + +#include + +class TestVcsStatusInfo : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void testCopyConstructor(); + void testAssignOperator(); +}; + +#endif // KDEVPLATFORM_TESTVCSSTATUSINFO_H diff --git a/kdevplatform/vcs/tests/test_vcsstatusinfo.cpp b/kdevplatform/vcs/tests/test_vcsstatusinfo.cpp new file mode 100644 --- /dev/null +++ b/kdevplatform/vcs/tests/test_vcsstatusinfo.cpp @@ -0,0 +1,113 @@ +/* This file is part of KDevelop + * + * Copyright 2017 Friedrich W. H. Kossebau + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include "test_vcsstatusinfo.h" + +#include + +using namespace KDevelop; + +void TestVcsStatusInfo::testCopyConstructor() +{ + // test plain copy + const QUrl url(QStringLiteral("git://foo")); + const VcsStatusInfo::State state = VcsStatusInfo::ItemUpToDate; + + { + VcsStatusInfo statusInfoA; + statusInfoA.setUrl(url); + statusInfoA.setState(state); + + VcsStatusInfo statusInfoB(statusInfoA); + + QCOMPARE(statusInfoA.url(), url); + QCOMPARE(statusInfoA.state(), state); + QCOMPARE(statusInfoB.url(), url); + QCOMPARE(statusInfoB.state(), state); + QVERIFY(statusInfoA == statusInfoB); + QVERIFY(statusInfoB == statusInfoA); + } + + const QUrl urlNew(QStringLiteral("svn://bar")); + + // test detach after changing A + { + VcsStatusInfo statusInfoA; + statusInfoA.setUrl(url); + statusInfoA.setState(state); + + VcsStatusInfo statusInfoB(statusInfoA); + // change a property of A + statusInfoA.setUrl(urlNew); + + QCOMPARE(statusInfoA.url(), urlNew); + QCOMPARE(statusInfoA.state(), state); + QCOMPARE(statusInfoB.url(), url); + QCOMPARE(statusInfoB.state(), state); + QVERIFY(statusInfoA != statusInfoB); + QVERIFY(statusInfoB != statusInfoA); + } +} + +void TestVcsStatusInfo::testAssignOperator() +{ + // test plain copy + const QUrl url(QStringLiteral("git://foo")); + const VcsStatusInfo::State state = VcsStatusInfo::ItemUpToDate; + + { + VcsStatusInfo statusInfoA; + statusInfoA.setUrl(url); + statusInfoA.setState(state); + + VcsStatusInfo statusInfoB; + statusInfoB = statusInfoA; + + QCOMPARE(statusInfoA.url(), url); + QCOMPARE(statusInfoA.state(), state); + QCOMPARE(statusInfoB.url(), url); + QCOMPARE(statusInfoB.state(), state); + QVERIFY(statusInfoA == statusInfoB); + QVERIFY(statusInfoB == statusInfoA); + } + + const QUrl urlNew(QStringLiteral("svn://bar")); + + // test detach after changing A + { + VcsStatusInfo statusInfoA; + statusInfoA.setUrl(url); + statusInfoA.setState(state); + + VcsStatusInfo statusInfoB; + statusInfoB = statusInfoA; + // change a property of A + statusInfoA.setUrl(urlNew); + + QCOMPARE(statusInfoA.url(), urlNew); + QCOMPARE(statusInfoA.state(), state); + QCOMPARE(statusInfoB.url(), url); + QCOMPARE(statusInfoB.state(), state); + QVERIFY(statusInfoA != statusInfoB); + QVERIFY(statusInfoB != statusInfoA); + } +} + +QTEST_GUILESS_MAIN(TestVcsStatusInfo); diff --git a/kdevplatform/vcs/vcsannotation.h b/kdevplatform/vcs/vcsannotation.h --- a/kdevplatform/vcs/vcsannotation.h +++ b/kdevplatform/vcs/vcsannotation.h @@ -24,7 +24,7 @@ #include "vcsexport.h" #include -#include +#include class QString; class QDateTime; @@ -102,7 +102,7 @@ VcsAnnotationLine& operator=( const VcsAnnotationLine& rhs); private: - const QScopedPointer d; + QSharedDataPointer d; }; /** @@ -152,13 +152,15 @@ VcsAnnotation& operator=( const VcsAnnotation& rhs); private: - const QScopedPointer d; + QSharedDataPointer d; }; } Q_DECLARE_METATYPE( KDevelop::VcsAnnotation ) +Q_DECLARE_TYPEINFO( KDevelop::VcsAnnotation, Q_MOVABLE_TYPE ); Q_DECLARE_METATYPE( KDevelop::VcsAnnotationLine ) +Q_DECLARE_TYPEINFO( KDevelop::VcsAnnotationLine, Q_MOVABLE_TYPE); #endif diff --git a/kdevplatform/vcs/vcsannotation.cpp b/kdevplatform/vcs/vcsannotation.cpp --- a/kdevplatform/vcs/vcsannotation.cpp +++ b/kdevplatform/vcs/vcsannotation.cpp @@ -20,6 +20,7 @@ #include "vcsannotation.h" +#include #include #include #include @@ -29,14 +30,14 @@ namespace KDevelop { -class VcsAnnotationPrivate +class VcsAnnotationPrivate : public QSharedData { public: QHash lines; QUrl location; }; -class VcsAnnotationLinePrivate +class VcsAnnotationLinePrivate : public QSharedData { public: QString author; @@ -55,15 +56,8 @@ } VcsAnnotationLine::VcsAnnotationLine( const VcsAnnotationLine& rhs ) - : d( new VcsAnnotationLinePrivate ) + : d(rhs.d) { - d->author = rhs.d->author; - d->line = rhs.d->line; - d->revision = rhs.d->revision; - d->lineno = rhs.d->lineno; - d->date = rhs.d->date; - d->text = rhs.d->text; - d->message = rhs.d->message; } VcsAnnotationLine::~VcsAnnotationLine() = default; @@ -120,15 +114,7 @@ VcsAnnotationLine& VcsAnnotationLine::operator=( const VcsAnnotationLine& rhs) { - if(this == &rhs) - return *this; - d->author = rhs.d->author; - d->line = rhs.d->line; - d->revision = rhs.d->revision; - d->lineno = rhs.d->lineno; - d->date = rhs.d->date; - d->text = rhs.d->text; - d->message = rhs.d->message; + d = rhs.d; return *this; } @@ -149,10 +135,8 @@ } VcsAnnotation::VcsAnnotation( const VcsAnnotation& rhs ) - : d(new VcsAnnotationPrivate) + : d(rhs.d) { - d->lines = rhs.d->lines; - d->location = rhs.d->location; } VcsAnnotation::~VcsAnnotation() = default; @@ -188,10 +172,7 @@ VcsAnnotation& VcsAnnotation::operator=( const VcsAnnotation& rhs) { - if(this == &rhs) - return *this; - d->location = rhs.d->location; - d->lines = rhs.d->lines; + d = rhs.d; return *this; } diff --git a/kdevplatform/vcs/vcsdiff.h b/kdevplatform/vcs/vcsdiff.h --- a/kdevplatform/vcs/vcsdiff.h +++ b/kdevplatform/vcs/vcsdiff.h @@ -26,6 +26,7 @@ #include "vcslocation.h" #include +#include #include "vcsexport.h" @@ -134,12 +135,13 @@ bool isEmpty() const; private: - const QScopedPointer d; + QSharedDataPointer d; }; } Q_DECLARE_METATYPE( KDevelop::VcsDiff ) +Q_DECLARE_TYPEINFO( KDevelop::VcsDiff, Q_MOVABLE_TYPE ); #endif diff --git a/kdevplatform/vcs/vcsdiff.cpp b/kdevplatform/vcs/vcsdiff.cpp --- a/kdevplatform/vcs/vcsdiff.cpp +++ b/kdevplatform/vcs/vcsdiff.cpp @@ -22,12 +22,12 @@ #include #include -#include +#include namespace KDevelop { -class VcsDiffPrivate +class VcsDiffPrivate : public QSharedData { public: QHash leftBinaries; @@ -49,9 +49,8 @@ VcsDiff::~VcsDiff() = default; VcsDiff::VcsDiff( const VcsDiff& rhs ) - : d(new VcsDiffPrivate) + : d(rhs.d) { - *d = *rhs.d; } bool VcsDiff::isEmpty() const @@ -154,9 +153,7 @@ VcsDiff& VcsDiff::operator=( const VcsDiff& rhs) { - if (this != &rhs) { - *d = *rhs.d; - } + d = rhs.d; return *this; } diff --git a/kdevplatform/vcs/vcsevent.h b/kdevplatform/vcs/vcsevent.h --- a/kdevplatform/vcs/vcsevent.h +++ b/kdevplatform/vcs/vcsevent.h @@ -22,7 +22,8 @@ #ifndef KDEVPLATFORM_VCSEVENT_H #define KDEVPLATFORM_VCSEVENT_H -#include +#include +#include #include "vcsexport.h" @@ -77,7 +78,7 @@ VcsItemEvent& operator=( const VcsItemEvent& rhs); private: - const QScopedPointer d; + QSharedDataPointer d; }; /** @@ -110,13 +111,15 @@ VcsEvent& operator=( const VcsEvent& rhs); private: - const QScopedPointer d; + QSharedDataPointer d; }; } Q_DECLARE_OPERATORS_FOR_FLAGS( KDevelop::VcsItemEvent::Actions ) Q_DECLARE_METATYPE( KDevelop::VcsEvent ) +Q_DECLARE_TYPEINFO( KDevelop::VcsEvent, Q_MOVABLE_TYPE ); Q_DECLARE_METATYPE( KDevelop::VcsItemEvent ) +Q_DECLARE_TYPEINFO( KDevelop::VcsItemEvent, Q_MOVABLE_TYPE ); #endif diff --git a/kdevplatform/vcs/vcsevent.cpp b/kdevplatform/vcs/vcsevent.cpp --- a/kdevplatform/vcs/vcsevent.cpp +++ b/kdevplatform/vcs/vcsevent.cpp @@ -23,12 +23,13 @@ #include #include #include +#include #include "vcsrevision.h" namespace KDevelop { -class VcsItemEventPrivate +class VcsItemEventPrivate : public QSharedData { public: QString location; @@ -45,12 +46,8 @@ VcsItemEvent::~VcsItemEvent() = default; VcsItemEvent::VcsItemEvent(const VcsItemEvent& rhs ) - : d(new VcsItemEventPrivate) + : d(rhs.d) { - d->actions = rhs.d->actions; - d->sourceRevision = rhs.d->sourceRevision; - d->sourceLocation = rhs.d->sourceLocation; - d->location = rhs.d->location; } QString VcsItemEvent::repositoryLocation() const @@ -95,16 +92,11 @@ VcsItemEvent& VcsItemEvent::operator=( const VcsItemEvent& rhs) { - if(this == &rhs) - return *this; - d->actions = rhs.d->actions; - d->sourceRevision = rhs.d->sourceRevision; - d->sourceLocation = rhs.d->sourceLocation; - d->location = rhs.d->location; + d = rhs.d; return *this; } -class VcsEventPrivate +class VcsEventPrivate : public QSharedData { public: VcsRevision revision; @@ -122,13 +114,8 @@ VcsEvent::~VcsEvent() = default; VcsEvent::VcsEvent( const VcsEvent& rhs ) - : d(new VcsEventPrivate) + : d(rhs.d) { - d->revision = rhs.d->revision; - d->author = rhs.d->author; - d->message = rhs.d->message; - d->date = rhs.d->date; - d->items = rhs.d->items; } VcsRevision VcsEvent::revision() const @@ -188,13 +175,7 @@ VcsEvent& VcsEvent::operator=( const VcsEvent& rhs) { - if(this == &rhs) - return *this; - d->revision = rhs.d->revision; - d->message = rhs.d->message; - d->items = rhs.d->items; - d->date = rhs.d->date; - d->author = rhs.d->author; + d = rhs.d; return *this; } diff --git a/kdevplatform/vcs/vcsrevision.h b/kdevplatform/vcs/vcsrevision.h --- a/kdevplatform/vcs/vcsrevision.h +++ b/kdevplatform/vcs/vcsrevision.h @@ -24,6 +24,7 @@ #include "vcsexport.h" #include +#include class QStringList; class QString; @@ -91,6 +92,9 @@ UserSpecialType = 1000 /**< This should be used by subclasses as base for their own special types. */ }; + /** + * Creates an invalid revision. + */ VcsRevision(); virtual ~VcsRevision(); @@ -155,14 +159,15 @@ private: - const QScopedPointer d; + QSharedDataPointer d; }; KDEVPLATFORMVCS_EXPORT uint qHash( const KDevelop::VcsRevision& rev); } Q_DECLARE_METATYPE(KDevelop::VcsRevision) +Q_DECLARE_TYPEINFO(KDevelop::VcsRevision, Q_MOVABLE_TYPE); Q_DECLARE_METATYPE(KDevelop::VcsRevision::RevisionSpecialType) diff --git a/kdevplatform/vcs/vcsrevision.cpp b/kdevplatform/vcs/vcsrevision.cpp --- a/kdevplatform/vcs/vcsrevision.cpp +++ b/kdevplatform/vcs/vcsrevision.cpp @@ -36,7 +36,7 @@ return rev; } -class VcsRevisionPrivate +class VcsRevisionPrivate : public QSharedData { public: QVariant value; @@ -51,22 +51,15 @@ } VcsRevision::VcsRevision( const VcsRevision& rhs ) - : d(new VcsRevisionPrivate) + : d(rhs.d) { - d->value = rhs.d->value; - d->internalValues = rhs.d->internalValues; - d->type = rhs.d->type; } VcsRevision::~VcsRevision() = default; VcsRevision& VcsRevision::operator=( const VcsRevision& rhs) { - if(this == &rhs) - return *this; - d->value = rhs.d->value; - d->type = rhs.d->type; - d->internalValues = rhs.d->internalValues; + d = rhs.d; return *this; } diff --git a/kdevplatform/vcs/vcsstatusinfo.h b/kdevplatform/vcs/vcsstatusinfo.h --- a/kdevplatform/vcs/vcsstatusinfo.h +++ b/kdevplatform/vcs/vcsstatusinfo.h @@ -24,7 +24,7 @@ #include "vcsexport.h" #include -#include +#include class QUrl; @@ -87,12 +87,13 @@ bool operator!=( const KDevelop::VcsStatusInfo& rhs) const; private: - const QScopedPointer d; + QSharedDataPointer d; }; } Q_DECLARE_METATYPE( KDevelop::VcsStatusInfo ) +Q_DECLARE_TYPEINFO( KDevelop::VcsStatusInfo, Q_MOVABLE_TYPE ); KDEVPLATFORMVCS_EXPORT QDebug operator<<(QDebug s, const KDevelop::VcsStatusInfo& statusInfo); diff --git a/kdevplatform/vcs/vcsstatusinfo.cpp b/kdevplatform/vcs/vcsstatusinfo.cpp --- a/kdevplatform/vcs/vcsstatusinfo.cpp +++ b/kdevplatform/vcs/vcsstatusinfo.cpp @@ -22,11 +22,12 @@ #include #include +#include namespace KDevelop { -class VcsStatusInfoPrivate +class VcsStatusInfoPrivate : public QSharedData { public: int state; @@ -42,18 +43,13 @@ VcsStatusInfo::~VcsStatusInfo() = default; VcsStatusInfo::VcsStatusInfo( const VcsStatusInfo& rhs ) - : d(new VcsStatusInfoPrivate) + : d(rhs.d) { - d->state = rhs.d->state; - d->url = rhs.d->url; } VcsStatusInfo& VcsStatusInfo::operator=( const VcsStatusInfo& rhs) { - if(this == &rhs) - return *this; - d->state = rhs.d->state; - d->url = rhs.d->url; + d = rhs.d; return *this; }