| 2913 | } |
| 2914 | |
| 2915 | void SpreadsheetTest::testLinkSpreadsheetRecalculate() { |
| 2916 | #ifdef __FreeBSD__ |
| 2917 | return; |
| 2918 | #endif |
| 2919 | Project project; |
| 2920 | auto* sheetData = new Spreadsheet(QStringLiteral("data"), false); |
| 2921 | project.addChild(sheetData); |
| 2922 | sheetData->setColumnCount(2); |
| 2923 | sheetData->setRowCount(10); |
| 2924 | auto* sheetDataColumn0 = sheetData->child<Column>(0); |
| 2925 | sheetDataColumn0->replaceValues(0, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}); |
| 2926 | QVERIFY(sheetDataColumn0); |
| 2927 | auto* sheetDataColumn1 = sheetData->child<Column>(1); |
| 2928 | QVERIFY(sheetDataColumn1); |
| 2929 | sheetDataColumn1->replaceValues(0, {1, 2, 1, 2, 1, 2, 1, 2, 1, 3}); |
| 2930 | |
| 2931 | auto* sheetCalculations = new Spreadsheet(QStringLiteral("calculations"), false); |
| 2932 | project.addChild(sheetCalculations); |
| 2933 | sheetCalculations->setColumnCount(1); |
| 2934 | sheetCalculations->setRowCount(2); |
| 2935 | auto* sheetCalculationsColumn0 = sheetCalculations->child<Column>(0); |
| 2936 | QVERIFY(sheetCalculationsColumn0); |
| 2937 | sheetCalculationsColumn0->setFormula(QStringLiteral("x + y"), {QStringLiteral("x"), QStringLiteral("y")}, {sheetDataColumn0, sheetDataColumn1}, true); |
| 2938 | sheetCalculationsColumn0->updateFormula(); |
| 2939 | |
| 2940 | { |
| 2941 | QVector<double> ref{2, 4, 4, 6, 6, 8, 8, 10, 10, 13}; |
| 2942 | QCOMPARE(sheetCalculationsColumn0->rowCount(), 10); // currently the update() triggers a resize |
| 2943 | for (int i = 0; i < 10; i++) |
| 2944 | VALUES_EQUAL(sheetCalculationsColumn0->doubleAt(i), ref.at(i)); |
| 2945 | } |
| 2946 | sheetCalculations->setLinking(true); |
| 2947 | sheetCalculations->setLinkedSpreadsheet(sheetData); |
| 2948 | |
| 2949 | QCOMPARE(sheetCalculations->linking(), true); |
| 2950 | QCOMPARE(sheetCalculations->linkedSpreadsheet(), sheetData); |
| 2951 | QCOMPARE(sheetCalculations->linkedSpreadsheetPath(), sheetData->path()); |
| 2952 | QCOMPARE(sheetCalculations->rowCount(), 10); |
| 2953 | |
| 2954 | sheetData->setRowCount(7); |
| 2955 | sheetDataColumn0->replaceValues(0, {3, 4, 6, 2, 1, 8, 5}); |
| 2956 | QCOMPARE(sheetDataColumn0->rowCount(), 7); |
| 2957 | |
| 2958 | { |
| 2959 | QVector<double> ref{4, 6, 7, 4, 2, 10, 6}; |
| 2960 | QCOMPARE(sheetCalculationsColumn0->rowCount(), ref.count()); |
| 2961 | for (int i = 0; i < ref.count(); i++) |
| 2962 | VALUES_EQUAL(sheetCalculationsColumn0->doubleAt(i), ref.at(i)); |
| 2963 | } |
| 2964 | } |
| 2965 | |
| 2966 | void SpreadsheetTest::testLinkSpreadsheetRecalculateRowCountChange() { |
| 2967 | #ifdef __FreeBSD__ |
nothing calls this directly
no test coverage detected