MCPcopy Create free account
hub / github.com/KDE/labplot / testInsertRowsSuppressUpdate

Method testInsertRowsSuppressUpdate

tests/spreadsheet/SpreadsheetTest.cpp:2572–2624  ·  view source on GitHub ↗

! * \brief testInsertRowsSuppressUpdate * It shall not crash * Testing if in the model begin and end are used properly */

Source from the content-addressed store, hash-verified

2570 * Testing if in the model begin and end are used properly
2571 */
2572void SpreadsheetTest::testInsertRowsSuppressUpdate() {
2573 Project project;
2574 auto* sheet = new Spreadsheet(QStringLiteral("test"), false);
2575 project.addChild(sheet);
2576
2577 auto* model = new SpreadsheetModel(sheet);
2578
2579 int rowsAboutToBeInsertedCounter = 0;
2580 connect(model, &SpreadsheetModel::rowsAboutToBeInserted, [&rowsAboutToBeInsertedCounter]() {
2581 rowsAboutToBeInsertedCounter++;
2582 });
2583 int rowsInsertedCounter = 0;
2584 connect(model, &SpreadsheetModel::rowsInserted, [&rowsInsertedCounter]() {
2585 rowsInsertedCounter++;
2586 });
2587 int rowsAboutToBeRemovedCounter = 0;
2588 connect(model, &SpreadsheetModel::rowsAboutToBeRemoved, [&rowsAboutToBeRemovedCounter]() {
2589 rowsAboutToBeRemovedCounter++;
2590 });
2591 int rowsRemovedCounter = 0;
2592 connect(model, &SpreadsheetModel::rowsRemoved, [&rowsRemovedCounter]() {
2593 rowsRemovedCounter++;
2594 });
2595
2596 int modelResetCounter = 0;
2597 connect(model, &SpreadsheetModel::modelReset, [&modelResetCounter]() {
2598 modelResetCounter++;
2599 });
2600 int modelAboutToResetCounter = 0;
2601 connect(model, &SpreadsheetModel::modelAboutToBeReset, [&modelAboutToResetCounter]() {
2602 modelAboutToResetCounter++;
2603 });
2604
2605 model->suppressSignals(true);
2606
2607 QCOMPARE(sheet->rowCount(), 100);
2608 sheet->setRowCount(101); // No crash shall happen
2609 QCOMPARE(sheet->rowCount(), 101);
2610
2611 sheet->undoStack()->undo();
2612 QCOMPARE(sheet->rowCount(), 100);
2613 sheet->undoStack()->redo();
2614 QCOMPARE(sheet->rowCount(), 101);
2615
2616 model->suppressSignals(false);
2617
2618 QCOMPARE(rowsAboutToBeInsertedCounter, 0);
2619 QCOMPARE(rowsInsertedCounter, 0);
2620 QCOMPARE(rowsAboutToBeRemovedCounter, 0);
2621 QCOMPARE(rowsRemovedCounter, 0);
2622 QCOMPARE(modelResetCounter, 1);
2623 QCOMPARE(modelAboutToResetCounter, 1);
2624}
2625
2626/*!
2627 * \brief testInsertColumnsSuppressUpdate

Callers

nothing calls this directly

Calls 7

suppressSignalsMethod · 0.80
addChildMethod · 0.45
rowCountMethod · 0.45
setRowCountMethod · 0.45
undoMethod · 0.45
undoStackMethod · 0.45
redoMethod · 0.45

Tested by

no test coverage detected