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

Round-trip regression test for the worksheet text styles. More...

#include <wx/app.h>
#include <wx/colour.h>
#include <wx/fileconf.h>
#include <wx/filefn.h>
#include <wx/filename.h>
#include <wx/font.h>
#include <wx/log.h>
#include "Configuration.h"
#include "cells/TextStyle.h"
#include <cstdint>
#include <cstdlib>
#include <catch2/catch.hpp>
Include dependency graph for test_StyleConfigRoundtrip.cpp:

Data Structures

class  TestApp
 

Functions

 SCENARIO ("Both the light and dark style sets round-trip through Write/ReadStyles")
 
 SCENARIO ("TS_ASCIIMATHS defaults to a genuinely fixed-pitch font")
 
 SCENARIO ("Style::Read() leaves the font name alone when nothing is persisted " "for it (GH: ASCII maths font default)")
 
 wxDECLARE_APP (TestApp)
 
int main (int argc, char **argv)
 

Detailed Description

Round-trip regression test for the worksheet text styles.

ReadStyles() and WriteStyles() used to carry two independent, hand-synced lists of TextStyle -> config-key-prefix mappings. If the two lists ever drifted (a typo, or a key renamed on only one side) the affected style silently stopped round-tripping through the configuration storage – a recurring source of "my style settings don't stick" bugs.

Both functions now iterate a single source of truth, Configuration::StyleConfigKeys(). This test guards that: it gives every persisted style a distinct, prefix-derived color, writes the styles to a temporary config file, reads them back into a fresh Configuration, and checks that each style comes back with the color stored under its own key. A future read/write key mismatch makes a style read back the wrong color (or a default) and fails the test instead of shipping as a silent settings bug.

Also guards a second, previously-undiscovered bug in the same area: TS_ ASCIIMATHS is supposed to default to a genuinely monospace font (Maxima's own ASCII-art 2D printer pads output with literal spaces on the assumption every character is the same width – see AGENTS.md's "ASCII-art 2D display" notes), and Styles::SetDefaults() does pick one. But Style::Read() used to have an "else SetFontName(wxNORMAL_FONT-> GetFaceName())" branch that fired whenever a style's fontname key was missing from the persisted config – which is the common case, true for every user who never explicitly changed a font in Options. Since ReadConfig() always calls ReadStyles() (reading the live config) right after SetDefaults() runs, this silently clobbered every style's carefully-chosen default font (ASCII maths' monospace font included) with one generic UI font, on every fresh install. Every other field in Style::Read() already followed the documented contract ("Only touches the attributes that were successfully read. Remaining attributes are unchanged.") – only fontname didn't.