Changeset View
Changeset View
Standalone View
Standalone View
tests/spreadsheet/SpreadsheetTest.cpp
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | File : SpreadsheetTest.cpp | ||||
3 | Project : LabPlot | ||||
4 | Description : Tests for the Spreadsheet | ||||
5 | -------------------------------------------------------------------- | ||||
6 | Copyright : (C) 2020 Alexander Semke (alexander.semke@web.de) | ||||
7 | ***************************************************************************/ | ||||
8 | | ||||
9 | /*************************************************************************** | ||||
10 | * * | ||||
11 | * This program is free software; you can redistribute it and/or modify * | ||||
12 | * it under the terms of the GNU General Public License as published by * | ||||
13 | * the Free Software Foundation; either version 2 of the License, or * | ||||
14 | * (at your option) any later version. * | ||||
15 | * * | ||||
16 | * This program is distributed in the hope that it will be useful, * | ||||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||||
19 | * GNU General Public License for more details. * | ||||
20 | * * | ||||
21 | * You should have received a copy of the GNU General Public License * | ||||
22 | * along with this program; if not, write to the Free Software * | ||||
23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, * | ||||
24 | * Boston, MA 02110-1301 USA * | ||||
25 | * * | ||||
26 | ***************************************************************************/ | ||||
27 | | ||||
28 | #include <QApplication> | ||||
29 | #include <QClipboard> | ||||
30 | | ||||
31 | #include "SpreadsheetTest.h" | ||||
32 | #include "backend/spreadsheet/Spreadsheet.h" | ||||
33 | #include "../src/commonfrontend/spreadsheet/SpreadsheetView.h" | ||||
34 | | ||||
35 | void SpreadsheetTest::initTestCase() { | ||||
36 | qRegisterMetaType<const AbstractAspect*>("const AbstractAspect*"); | ||||
37 | qRegisterMetaType<const AbstractColumn*>("const AbstractColumn*"); | ||||
38 | } | ||||
39 | | ||||
40 | /*! | ||||
41 | insert two columns with float values into an empty spreadsheet | ||||
42 | */ | ||||
43 | void SpreadsheetTest::testCopyPaste00() { | ||||
44 | Spreadsheet* sheet = new Spreadsheet("test", false); | ||||
45 | | ||||
46 | const QString str = "10.0 100.0\n20.0 200.0"; | ||||
47 | | ||||
48 | QApplication::clipboard()->setText(str); | ||||
49 | | ||||
50 | SpreadsheetView* view = new SpreadsheetView(sheet, false); | ||||
51 | view->pasteIntoSelection(); | ||||
52 | | ||||
53 | //column modes | ||||
54 | QCOMPARE(sheet->column(0)->columnMode(), AbstractColumn::Numeric); | ||||
55 | QCOMPARE(sheet->column(1)->columnMode(), AbstractColumn::Numeric); | ||||
56 | | ||||
57 | //values | ||||
58 | QCOMPARE(sheet->column(0)->valueAt(0), 10.0); | ||||
59 | QCOMPARE(sheet->column(1)->valueAt(0), 100.0); | ||||
60 | QCOMPARE(sheet->column(0)->valueAt(1), 20.0); | ||||
61 | QCOMPARE(sheet->column(1)->valueAt(1), 200.0); | ||||
62 | } | ||||
63 | | ||||
64 | /*! | ||||
65 | insert one column with integer values and one column with float numbers into an empty spreadsheet. | ||||
66 | the first column has to be converted to integer column. | ||||
67 | */ | ||||
68 | void SpreadsheetTest::testCopyPaste01() { | ||||
69 | Spreadsheet* sheet = new Spreadsheet("test", false); | ||||
70 | | ||||
71 | const QString str = "10 100.0\n20 200.0"; | ||||
72 | | ||||
73 | QApplication::clipboard()->setText(str); | ||||
74 | | ||||
75 | SpreadsheetView* view = new SpreadsheetView(sheet, false); | ||||
76 | view->pasteIntoSelection(); | ||||
77 | | ||||
78 | //column modes | ||||
79 | QCOMPARE(sheet->column(0)->columnMode(), AbstractColumn::Integer); | ||||
80 | QCOMPARE(sheet->column(1)->columnMode(), AbstractColumn::Numeric); | ||||
81 | | ||||
82 | //values | ||||
83 | QCOMPARE(sheet->column(0)->integerAt(0), 10); | ||||
84 | QCOMPARE(sheet->column(1)->valueAt(0), 100.0); | ||||
85 | QCOMPARE(sheet->column(0)->integerAt(1), 20); | ||||
86 | QCOMPARE(sheet->column(1)->valueAt(1), 200.0); | ||||
87 | } | ||||
88 | | ||||
89 | /*! | ||||
90 | insert irregular data, new columns should be added appropriately. | ||||
91 | */ | ||||
92 | void SpreadsheetTest::testCopyPaste02() { | ||||
93 | Spreadsheet* sheet = new Spreadsheet("test", false); | ||||
94 | | ||||
95 | const QString str = "0\n" | ||||
96 | "10 20\n" | ||||
97 | "11 21 31\n" | ||||
98 | "12 22 32 42\n" | ||||
99 | "13 23\n" | ||||
100 | "14"; | ||||
101 | | ||||
102 | QApplication::clipboard()->setText(str); | ||||
103 | | ||||
104 | int rows = sheet->rowCount(); | ||||
105 | | ||||
106 | SpreadsheetView* view = new SpreadsheetView(sheet, false); | ||||
107 | view->pasteIntoSelection(); | ||||
108 | | ||||
109 | //spreadsheet size | ||||
110 | QCOMPARE(sheet->columnCount(), 4); | ||||
111 | QCOMPARE(sheet->rowCount(), rows); | ||||
112 | | ||||
113 | //column modes | ||||
114 | QCOMPARE(sheet->column(0)->columnMode(), AbstractColumn::Integer); | ||||
115 | QCOMPARE(sheet->column(1)->columnMode(), AbstractColumn::Integer); | ||||
116 | QCOMPARE(sheet->column(2)->columnMode(), AbstractColumn::Integer); | ||||
117 | QCOMPARE(sheet->column(3)->columnMode(), AbstractColumn::Integer); | ||||
118 | | ||||
119 | //values | ||||
120 | QCOMPARE(sheet->column(0)->integerAt(0), 0); | ||||
121 | QCOMPARE(sheet->column(1)->integerAt(0), 0); | ||||
122 | QCOMPARE(sheet->column(2)->integerAt(0), 0); | ||||
123 | QCOMPARE(sheet->column(3)->integerAt(0), 0); | ||||
124 | | ||||
125 | QCOMPARE(sheet->column(0)->integerAt(1), 10); | ||||
126 | QCOMPARE(sheet->column(1)->integerAt(1), 20); | ||||
127 | QCOMPARE(sheet->column(2)->integerAt(1), 0); | ||||
128 | QCOMPARE(sheet->column(3)->integerAt(1), 0); | ||||
129 | | ||||
130 | QCOMPARE(sheet->column(0)->integerAt(2), 11); | ||||
131 | QCOMPARE(sheet->column(1)->integerAt(2), 21); | ||||
132 | QCOMPARE(sheet->column(2)->integerAt(2), 31); | ||||
133 | QCOMPARE(sheet->column(3)->integerAt(2), 0); | ||||
134 | | ||||
135 | QCOMPARE(sheet->column(0)->integerAt(3), 12); | ||||
136 | QCOMPARE(sheet->column(1)->integerAt(3), 22); | ||||
137 | QCOMPARE(sheet->column(2)->integerAt(3), 32); | ||||
138 | QCOMPARE(sheet->column(3)->integerAt(3), 42); | ||||
139 | | ||||
140 | QCOMPARE(sheet->column(0)->integerAt(4), 13); | ||||
141 | QCOMPARE(sheet->column(1)->integerAt(4), 23); | ||||
142 | QCOMPARE(sheet->column(2)->integerAt(4), 0); | ||||
143 | QCOMPARE(sheet->column(3)->integerAt(4), 0); | ||||
144 | | ||||
145 | QCOMPARE(sheet->column(0)->integerAt(5), 14); | ||||
146 | QCOMPARE(sheet->column(1)->integerAt(5), 0); | ||||
147 | QCOMPARE(sheet->column(2)->integerAt(5), 0); | ||||
148 | QCOMPARE(sheet->column(3)->integerAt(5), 0); | ||||
149 | } | ||||
150 | | ||||
151 | QTEST_MAIN(SpreadsheetTest) |