File indexing completed on 2024-05-12 16:35:56

0001 /* This file is part of the KDE project
0002    Copyright 2012 Marijn Kruisselbrink <mkruisselbrink@kde.org>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; only
0007    version 2 of the License.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017    Boston, MA 02110-1301, USA.
0018 */
0019 #include "TestPasteCommand.h"
0020 
0021 #include <QTest>
0022 
0023 #include "MockPart.h"
0024 
0025 #include "part/CanvasItem.h"
0026 #include "part/Doc.h"
0027 #include "Map.h"
0028 #include "ui/Selection.h"
0029 #include "Sheet.h"
0030 #include <Value.h>
0031 #include "commands/PasteCommand.h"
0032 
0033 using namespace Calligra::Sheets;
0034 
0035 void PasteCommandTest::testKSpreadSnippet()
0036 {
0037     Doc doc(new MockPart);
0038     Map *map = doc.map();
0039     Sheet* sheet = new Sheet(map, "Sheet1");
0040     map->addSheet(sheet);
0041     CanvasItem canvas(&doc);
0042     Selection selection(&canvas);
0043     selection.setActiveSheet(sheet);
0044     selection.initialize(QPoint(2, 4), sheet);
0045 
0046     QMimeData *mimedata = new QMimeData();
0047     mimedata->setData("application/x-kspread-snippet",
0048                       "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
0049                       "<!DOCTYPE spreadsheet-snippet>\n"
0050                       "<spreadsheet-snippet rows=\"1\" columns=\"1\">\n"
0051                       " <cell row=\"1\" column=\"1\">\n"
0052                       "  <text outStr=\"3\" dataType=\"Num\">3</text>\n"
0053                       " </cell>\n"
0054                       "</spreadsheet-snippet>\n");
0055 
0056     PasteCommand *command = new PasteCommand();
0057     command->setSheet(selection.activeSheet());
0058     command->add(selection);
0059     command->setMimeData(mimedata);
0060     command->setPasteFC(true);
0061     command->execute(&canvas);
0062 
0063     qDebug() << Cell(sheet, 2, 4).value() << Cell(sheet, 1, 3).value() << Value(3);
0064     QCOMPARE(Cell(sheet, 2, 4).value(), Value(3));
0065 }
0066 
0067 QTEST_MAIN(PasteCommandTest)