Skip to content

Commit a76fed9

Browse files
committed
TEST: add regression test for persistent QFile handle in FiffRawData
FiffRawData/FiffStream borrows a non-owning QIODevice pointer, so the caller must keep the source QFile alive. This test verifies the correct pattern (persistent QFile) succeeds with read_raw_segment. Complements commit 2e2d941.
1 parent 2e2d941 commit a76fed9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/testframes/test_fiff_raw_io/test_fiff_raw_io.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,34 @@ private slots:
710710
QVERIFY(nm.data.isApprox(origData.transpose()));
711711
}
712712

713+
//=========================================================================
714+
// Regression: FiffRawData borrows a non-owning QIODevice* via
715+
// FiffStream. The caller MUST keep the QFile alive for the entire
716+
// lifetime of FiffRawData. This test verifies that doing so (the
717+
// correct pattern used by mainwindow.cpp after the fix) allows
718+
// read_raw_segment to succeed. See commit 2e2d941ac.
719+
//=========================================================================
720+
void fiffRawData_persistentFileHandleWorks()
721+
{
722+
if (!hasData()) QSKIP("No test data");
723+
724+
// Persistent QFile — mirrors the fixed application code
725+
QFile file(m_sDataPath + "/MEG/sample/sample_audvis_trunc_raw.fif");
726+
FiffRawData raw(file);
727+
QVERIFY(!raw.isEmpty());
728+
729+
// Read a 1-second segment
730+
MatrixXd data, times;
731+
fiff_int_t from = raw.first_samp;
732+
fiff_int_t to = qMin(raw.first_samp + (fiff_int_t)(raw.info.sfreq),
733+
raw.last_samp);
734+
bool ok = raw.read_raw_segment(data, times, from, to);
735+
736+
QVERIFY2(ok, "read_raw_segment failed with persistent QFile");
737+
QVERIFY(data.rows() > 0);
738+
QVERIFY(data.cols() > 0);
739+
}
740+
713741
//=========================================================================
714742
void cleanupTestCase() {}
715743
};

0 commit comments

Comments
 (0)