wxMaxima
Loading...
Searching...
No Matches
Data Structures | Macros | Functions
test_EditorCellInvariants.cpp File Reference

Hardening tests for EditorCell's text-editing core. More...

#include <wx/app.h>
#include <wx/bitmap.h>
#include <wx/dcmemory.h>
#include <wx/event.h>
#include <wx/frame.h>
#include <wx/log.h>
#include "Configuration.h"
#include "worksheet/Worksheet.h"
#include "cells/CellList.h"
#include "cells/GroupCell.h"
#include "cells/EditorCell.h"
#include <cstdlib>
#include <memory>
#include <random>
#include <stdexcept>
#include <unistd.h>
#include <catch2/catch.hpp>
Include dependency graph for test_EditorCellInvariants.cpp:

Data Structures

class  TestApp
 

Functions

 SCENARIO ("Typing characters inserts them in order")
 
 SCENARIO ("Backspace at the end of the text removes the last character")
 
 SCENARIO ("Backspace at the very start of the text is a harmless no-op")
 
 SCENARIO ("Cursor and selection positions are clamped to the text")
 
 SCENARIO ("Typing over a selection replaces it")
 
 SCENARIO ("Undo reverts the last edit and Redo re-applies it")
 
 SCENARIO ("Redo with nothing to redo does not crash")
 
 SCENARIO ("A long random edit sequence never corrupts the cursor or overruns the text")
 
int main (int argc, char **argv)
 

Detailed Description

Hardening tests for EditorCell's text-editing core.

EditorCell is large and its mutation paths (character input, Backspace/Delete, word/bracket motion, Tab, undo/redo) all compute indices into m_text by hand and then access it with at()/Mid()/SubString(). An off-by-one there is an out-of-bounds access that wxASSERTs in a Debug build and is undefined behaviour in Release.

Two kinds of test live here:

  1. Targeted scenarios with concrete expected results (typing, deletion, selection-replace, undo/redo round-trips, and the previously-unguarded "redo with an empty history" case).
  2. A randomized stress driver that fires long pseudo-random sequences of real key events at a real EditorCell and, after every single operation, checks the cursor/selection invariants. A wxWidgets assert handler that throws turns any internal out-of-bounds access into a named test failure (with the seed) instead of a headless hang, so the fuzz run is a genuine OOB probe.

These exercise the real EditorCell/GroupCell/Worksheet/Configuration code (linked via the wxmTestApp object library).