Mercurial > hg > svcore
diff data/fileio/test/CSVFormatTest.h @ 1874:48f50a4a82ea
Merge from branch csv-import-headers
author | Chris Cannam |
---|---|
date | Thu, 18 Jun 2020 13:43:20 +0100 |
parents | 1d44fdc8196c |
children |
line wrap: on
line diff
--- a/data/fileio/test/CSVFormatTest.h Tue Jun 16 15:15:57 2020 +0100 +++ b/data/fileio/test/CSVFormatTest.h Thu Jun 18 13:43:20 2020 +0100 @@ -105,6 +105,7 @@ void comment() { CSVFormat f; + f.setHeaderStatus(CSVFormat::HeaderAbsent); QVERIFY(f.guessFormatFor(csvDir.filePath("comment.csv"))); QCOMPARE(f.getSeparator(), QChar(',')); QCOMPARE(f.getColumnCount(), 4); @@ -142,6 +143,18 @@ CSVFormat f; QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-1d-samples.csv"))); QCOMPARE(f.getColumnCount(), 1); + QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderAbsent); + QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); + QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming); + QCOMPARE(f.getTimeUnits(), CSVFormat::TimeAudioFrames); + QCOMPARE(f.getModelType(), CSVFormat::OneDimensionalModel); + } + + void modelType1DSamplesWithHeader() { + CSVFormat f; + QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-1d-samples-header.csv"))); + QCOMPARE(f.getColumnCount(), 1); + QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderPresent); QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming); QCOMPARE(f.getTimeUnits(), CSVFormat::TimeAudioFrames); @@ -152,6 +165,19 @@ CSVFormat f; QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-1d-seconds.csv"))); QCOMPARE(f.getColumnCount(), 2); + QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderAbsent); + QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); + QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnLabel); + QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming); + QCOMPARE(f.getTimeUnits(), CSVFormat::TimeSeconds); + QCOMPARE(f.getModelType(), CSVFormat::OneDimensionalModel); + } + + void modelType1DSecondsWithHeader() { + CSVFormat f; + QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-1d-seconds-header.csv"))); + QCOMPARE(f.getColumnCount(), 2); + QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderPresent); QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnLabel); QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming); @@ -163,6 +189,19 @@ CSVFormat f; QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-samples.csv"))); QCOMPARE(f.getColumnCount(), 2); + QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderAbsent); + QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); + QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnValue); + QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming); + QCOMPARE(f.getTimeUnits(), CSVFormat::TimeAudioFrames); + QCOMPARE(f.getModelType(), CSVFormat::TwoDimensionalModel); + } + + void modelType2DSamplesWithHeader() { + CSVFormat f; + QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-samples-header.csv"))); + QCOMPARE(f.getColumnCount(), 2); + QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderPresent); QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnValue); QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming); @@ -174,6 +213,19 @@ CSVFormat f; QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-seconds.csv"))); QCOMPARE(f.getColumnCount(), 2); + QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderAbsent); + QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); + QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnValue); + QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming); + QCOMPARE(f.getTimeUnits(), CSVFormat::TimeSeconds); + QCOMPARE(f.getModelType(), CSVFormat::TwoDimensionalModel); + } + + void modelType2DSecondsWithHeader() { + CSVFormat f; + QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-seconds-header.csv"))); + QCOMPARE(f.getColumnCount(), 2); + QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderPresent); QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnValue); QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming); @@ -184,8 +236,20 @@ void modelType2DImplicit() { CSVFormat f; QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-implicit.csv"))); - QCOMPARE(f.getColumnCount(), 1); + QCOMPARE(f.getColumnCount(), 2); + QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderAbsent); QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnLabel); + QCOMPARE(f.getTimingType(), CSVFormat::ImplicitTiming); + } + + void modelType2DImplicitWithHeader() { + CSVFormat f; + QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-implicit-header.csv"))); + QCOMPARE(f.getColumnCount(), 2); + QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderPresent); + QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnLabel); QCOMPARE(f.getTimingType(), CSVFormat::ImplicitTiming); } @@ -193,6 +257,7 @@ CSVFormat f; QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-endtime-samples.csv"))); QCOMPARE(f.getColumnCount(), 3); + QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderAbsent); QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnEndTime); QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnValue); @@ -201,10 +266,24 @@ QCOMPARE(f.getModelType(), CSVFormat::TwoDimensionalModelWithDuration); } + void modelType2DEndTimeSamplesWithHeader() { + CSVFormat f; + QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-endtime-samples-header.csv"))); + QCOMPARE(f.getColumnCount(), 3); + QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderPresent); + QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); + QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnEndTime); + QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming); + QCOMPARE(f.getTimeUnits(), CSVFormat::TimeAudioFrames); + QCOMPARE(f.getModelType(), CSVFormat::TwoDimensionalModelWithDuration); + } + void modelType2DEndTimeSeconds() { CSVFormat f; QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-endtime-seconds.csv"))); QCOMPARE(f.getColumnCount(), 3); + QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderAbsent); QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnEndTime); QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnValue); @@ -213,10 +292,24 @@ QCOMPARE(f.getModelType(), CSVFormat::TwoDimensionalModelWithDuration); } + void modelType2DEndTimeSecondsWithHeader() { + CSVFormat f; + QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-endtime-seconds-header.csv"))); + QCOMPARE(f.getColumnCount(), 3); + QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderPresent); + QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); + QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnEndTime); + QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming); + QCOMPARE(f.getTimeUnits(), CSVFormat::TimeSeconds); + QCOMPARE(f.getModelType(), CSVFormat::TwoDimensionalModelWithDuration); + } + void modelType2DDurationSamples() { CSVFormat f; QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-duration-samples.csv"))); QCOMPARE(f.getColumnCount(), 3); + QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderAbsent); QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnDuration); QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnValue); @@ -224,11 +317,25 @@ QCOMPARE(f.getTimeUnits(), CSVFormat::TimeAudioFrames); QCOMPARE(f.getModelType(), CSVFormat::TwoDimensionalModelWithDuration); } + + void modelType2DDurationSamplesWithHeader() { + CSVFormat f; + QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-duration-samples-header.csv"))); + QCOMPARE(f.getColumnCount(), 3); + QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderPresent); + QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); + QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnDuration); + QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming); + QCOMPARE(f.getTimeUnits(), CSVFormat::TimeAudioFrames); + QCOMPARE(f.getModelType(), CSVFormat::TwoDimensionalModelWithDuration); + } void modelType2DDurationSeconds() { CSVFormat f; QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-duration-seconds.csv"))); QCOMPARE(f.getColumnCount(), 3); + QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderAbsent); QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnDuration); QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnValue); @@ -237,10 +344,41 @@ QCOMPARE(f.getModelType(), CSVFormat::TwoDimensionalModelWithDuration); } + void modelType2DDurationSecondsWithHeader() { + CSVFormat f; + QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-duration-seconds-header.csv"))); + QCOMPARE(f.getColumnCount(), 3); + QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderPresent); + QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); + QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnDuration); + QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming); + QCOMPARE(f.getTimeUnits(), CSVFormat::TimeSeconds); + QCOMPARE(f.getModelType(), CSVFormat::TwoDimensionalModelWithDuration); + } + void modelType3DSamples() { CSVFormat f; QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-3d-samples.csv"))); QCOMPARE(f.getColumnCount(), 7); + QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderAbsent); + QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); + QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(3), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(4), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(5), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(6), CSVFormat::ColumnValue); + QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming); + QCOMPARE(f.getTimeUnits(), CSVFormat::TimeAudioFrames); + QCOMPARE(f.getModelType(), CSVFormat::ThreeDimensionalModel); + } + + void modelType3DSamplesWithHeader() { + CSVFormat f; + QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-3d-samples-header.csv"))); + QCOMPARE(f.getColumnCount(), 7); + QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderPresent); QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnValue); QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnValue); @@ -257,6 +395,24 @@ CSVFormat f; QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-3d-seconds.csv"))); QCOMPARE(f.getColumnCount(), 7); + QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderAbsent); + QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); + QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(3), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(4), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(5), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(6), CSVFormat::ColumnValue); + QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming); + QCOMPARE(f.getTimeUnits(), CSVFormat::TimeSeconds); + QCOMPARE(f.getModelType(), CSVFormat::ThreeDimensionalModel); + } + + void modelType3DSecondsWithHeader() { + CSVFormat f; + QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-3d-seconds-header.csv"))); + QCOMPARE(f.getColumnCount(), 7); + QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderPresent); QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnValue); QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnValue); @@ -273,6 +429,22 @@ CSVFormat f; QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-3d-implicit.csv"))); QCOMPARE(f.getColumnCount(), 6); + QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderAbsent); + QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(3), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(4), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(5), CSVFormat::ColumnValue); + QCOMPARE(f.getTimingType(), CSVFormat::ImplicitTiming); + QCOMPARE(f.getModelType(), CSVFormat::ThreeDimensionalModel); + } + + void modelType3DImplicitWithHeader() { + CSVFormat f; + QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-3d-implicit-header.csv"))); + QCOMPARE(f.getColumnCount(), 6); + QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderPresent); QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnValue); QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnValue); QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnValue);