diff --git a/src/commonfrontend/spreadsheet/SpreadsheetView.h b/src/commonfrontend/spreadsheet/SpreadsheetView.h --- a/src/commonfrontend/spreadsheet/SpreadsheetView.h +++ b/src/commonfrontend/spreadsheet/SpreadsheetView.h @@ -216,6 +216,7 @@ void fillTouchBar(KDMacTouchBar*); #endif void print(QPrinter*) const; + void pasteIntoSelection(); private slots: void createColumnContextMenu(QMenu*); @@ -229,7 +230,6 @@ void cutSelection(); void copySelection(); - void pasteIntoSelection(); void clearSelectedCells(); void maskSelection(); void unmaskSelection(); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -4,3 +4,4 @@ add_subdirectory(analysis) add_subdirectory(import_export) add_subdirectory(nsl) +add_subdirectory(spreadsheet) diff --git a/tests/spreadsheet/CMakeLists.txt b/tests/spreadsheet/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/tests/spreadsheet/CMakeLists.txt @@ -0,0 +1,9 @@ +INCLUDE_DIRECTORIES(${GSL_INCLUDE_DIR}) + +add_executable (copypastetest CopyPasteTest.cpp) + +target_link_libraries(copypastetest Qt5::Test) +target_link_libraries(copypastetest ${GSL_LIBRARIES} ${GSL_CBLAS_LIBRARIES}) +target_link_libraries(copypastetest labplot2lib) + +add_test(NAME copypastetest COMMAND copypastetest) diff --git a/tests/spreadsheet/CopyPasteTest.h b/tests/spreadsheet/CopyPasteTest.h new file mode 100644 --- /dev/null +++ b/tests/spreadsheet/CopyPasteTest.h @@ -0,0 +1,41 @@ +/*************************************************************************** + File : CopyPasteTest.h + Project : LabPlot + Description : Tests for the Spreadsheet copy paste feature + -------------------------------------------------------------------- + Copyright : (C) 2020 Shubham (aryan100jangid@gmail.com) + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 COPYPASTETEST_H +#define COPYPASTETEST_H + +#include + +class CopyPasteTest : public QObject { + Q_OBJECT + +private slots: + void initTestCase(); + void testCopyPaste(); +}; + +#endif diff --git a/tests/spreadsheet/CopyPasteTest.cpp b/tests/spreadsheet/CopyPasteTest.cpp new file mode 100644 --- /dev/null +++ b/tests/spreadsheet/CopyPasteTest.cpp @@ -0,0 +1,62 @@ +/*************************************************************************** + File : CopyPasteTest.cpp + Project : LabPlot + Description : Tests for the Spreadsheet copy paste feature + -------------------------------------------------------------------- + Copyright : (C) 2020 Shubham (aryan100jangid@gmail.com) + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 +#include + +#include "CopyPasteTest.h" +#include "backend/spreadsheet/Spreadsheet.h" +#include "../src/commonfrontend/spreadsheet/SpreadsheetView.h" + +void CopyPasteTest::initTestCase() { + qRegisterMetaType("const AbstractAspect*"); + qRegisterMetaType("const AbstractColumn*"); +} + +void CopyPasteTest::testCopyPaste() { + Spreadsheet *sheet = new Spreadsheet("test", false); + + sheet->column(0)->setValueAt(0, 10.0); + sheet->column(0)->setValueAt(1, 20.0); + sheet->column(0)->setValueAt(2, 30.0); + + sheet->column(1)->setValueAt(0, 100.0); + sheet->column(1)->setValueAt(1, 200.0); + sheet->column(1)->setValueAt(2, 300.0); + + const QString str = "10.0 100.0 \n 20.0 200.0 \n 30.0 300.0"; + + QApplication::clipboard()->setText(str); + + SpreadsheetView *view = new SpreadsheetView(sheet, false); + view->pasteIntoSelection(); + + QCOMPARE(sheet->column(0)->valueAt(0), 10.0); + QCOMPARE(sheet->column(1)->valueAt(0), 200.0); +} + +QTEST_MAIN(CopyPasteTest)