File indexing completed on 2024-05-12 04:37:36

0001 /*
0002  *  SPDX-FileCopyrightText: 2023 JATothrim <jarmo.tiitto@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #ifndef KDEVPLATFORM_TEST_BREAKPOINTMODEL_H
0008 #define KDEVPLATFORM_TEST_BREAKPOINTMODEL_H
0009 
0010 #include <debugger/breakpoint/breakpoint.h>
0011 #include <debugger/breakpoint/breakpointmodel.h>
0012 #include <interfaces/idocument.h>
0013 
0014 #include <QHash>
0015 #include <QObject>
0016 #include <QTemporaryDir>
0017 #include <QUrl>
0018 
0019 #include <memory>
0020 #include <tuple>
0021 
0022 /**
0023  * Tests with BreakpointModel and IDocumentController.
0024  *
0025  * Check BreakpointModel behaviour of Editing, Saving,
0026  * Discarding, Reloading, Renaming documents
0027  * with source line breakpoints set in them.
0028  */
0029 class TestBreakpointModel : public QObject
0030 {
0031     Q_OBJECT
0032 public:
0033     explicit TestBreakpointModel(QObject* parent = nullptr);
0034 
0035 private Q_SLOTS:
0036     void initTestCase();
0037     void init();
0038     void cleanup();
0039     void cleanupTestCase();
0040 
0041     void testDocumentSave();
0042     void testDocumentEditAndSave();
0043     void testDocumentEditAndDiscard();
0044 
0045 private:
0046     using DocumentMarks = QHash<int, KDevelop::BreakpointModel::MarkType>;
0047     static DocumentMarks documentMarks(const KDevelop::IDocument* doc);
0048     static void printLines(int from, int count, const KDevelop::IDocument* doc);
0049     static void verifyBreakpoint(KDevelop::Breakpoint* breakpoint, int expectedLine, const DocumentMarks& marks);
0050 
0051     QUrl testFileUrl(const QString& fileName) const;
0052 
0053     using DocumentAndBreakpoint = std::tuple<QUrl, KDevelop::IDocument*, KDevelop::Breakpoint*>;
0054     DocumentAndBreakpoint setupPrimaryDocumentAndBreakpoint();
0055 
0056     using DocumentAndTwoBreakpoints =
0057         std::tuple<QUrl, KDevelop::IDocument*, KDevelop::Breakpoint*, KDevelop::Breakpoint*>;
0058     DocumentAndTwoBreakpoints setupEditAndCheckPrimaryDocumentAndBreakpoints();
0059 
0060     std::unique_ptr<QTemporaryDir> m_tempDir; ///< Test working directory
0061 };
0062 
0063 #endif // KDEVPLATFORM_TEST_BREAKPOINTMODEL_H