From: <sv...@op...> - 2024-08-15 12:26:58
|
Author: manx Date: Thu Aug 15 14:26:46 2024 New Revision: 21441 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=21441 Log: [Ref] Playback Test: Move gzip compression/decompression out into the caller. Modified: trunk/OpenMPT/common/BuildSettings.h trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/test/PlaybackTest.cpp trunk/OpenMPT/test/PlaybackTest.h Modified: trunk/OpenMPT/common/BuildSettings.h ============================================================================== --- trunk/OpenMPT/common/BuildSettings.h Thu Aug 15 12:30:30 2024 (r21440) +++ trunk/OpenMPT/common/BuildSettings.h Thu Aug 15 14:26:46 2024 (r21441) @@ -114,6 +114,10 @@ #define MPT_ENABLE_UPDATE +#if defined(MPT_BUILD_DEBUG) +#define MPT_ENABLE_PLAYBACK_TEST_MENU +#endif + // Disable unarchiving support //#define NO_ARCHIVE_SUPPORT Modified: trunk/OpenMPT/mptrack/MainFrm.cpp ============================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp Thu Aug 15 12:30:30 2024 (r21440) +++ trunk/OpenMPT/mptrack/MainFrm.cpp Thu Aug 15 14:26:46 2024 (r21441) @@ -56,6 +56,11 @@ #include "openmpt/sounddevice/SoundDeviceBuffer.hpp" #include "openmpt/sounddevice/SoundDeviceManager.hpp" +#ifdef MPT_ENABLE_PLAYBACK_TEST_MENU +#include "../unarchiver/ungzip.h" +#include "../common/GzipWriter.h" +#endif + #include <HtmlHelp.h> #include <Dbt.h> // device change messages @@ -67,10 +72,6 @@ static constexpr uint32 MPTTIMER_PERIOD = 100; -#if defined(MPT_BUILD_DEBUG) -#define MPT_ENABLE_PLAYBACK_TEST_MENU -#endif - ///////////////////////////////////////////////////////////////////////////// // CMainFrame @@ -3268,7 +3269,17 @@ auto playTest = sndFile->CreatePlaybackTest(PlaybackTestSettings{}); mpt::ofstream outFile(fileName + P_(".testdata.gz"), std::ios::binary | std::ios::trunc); if(outFile) - playTest.Serialize(outFile, fileName.GetFilename().ToUnicode() + U_(".testdata")); + { + std::ostringstream outStream; + playTest.Serialize(outStream); + #ifdef MPT_WITH_ZLIB + std::string outData = std::move(outStream).str(); + WriteGzip(outFile, outData, fileName.GetFilename().ToUnicode() + U_(".testdata")); + #else + // miniz doesn't have gzip convenience functions + outFile << std::move(outStream).str(); + #endif + } } } @@ -3299,7 +3310,16 @@ if(!modFile.IsValid()) throw std::runtime_error{"Cannot open module data file: " + modFileName.ToUTF8()}; - PlaybackTest playTest{GetFileReader(testFile)}; + FileReader testFileReader = GetFileReader(testFile); + CGzipArchive archive{testFileReader}; + if(archive.IsArchive()) + { + if(!archive.ExtractFile(0)) + throw std::runtime_error{"Cannot extract test data file!"}; + testFileReader = archive.GetOutputFile(); + } + + PlaybackTest playTest{testFileReader}; auto sndFile = std::make_unique<CSoundFile>(); sndFile->Create(GetFileReader(modFile)); Modified: trunk/OpenMPT/test/PlaybackTest.cpp ============================================================================== --- trunk/OpenMPT/test/PlaybackTest.cpp Thu Aug 15 12:30:30 2024 (r21440) +++ trunk/OpenMPT/test/PlaybackTest.cpp Thu Aug 15 14:26:46 2024 (r21441) @@ -10,11 +10,9 @@ #include "stdafx.h" #include "PlaybackTest.h" -#include "../common/GzipWriter.h" #include "../soundlib/OPL.h" #include "../soundlib/SampleIO.h" #include "../soundlib/Sndfile.h" -#include "../unarchiver/ungzip.h" #include "mpt/base/bit.hpp" #include "mpt/binary/hex.hpp" @@ -331,13 +329,6 @@ void PlaybackTest::Deserialize(FileReader file) noexcept(false) { - CGzipArchive archive{file}; - if(archive.IsArchive()) - { - if(!archive.ExtractFile(0)) - throw std::runtime_error{"Cannot extract test data file!"}; - file = archive.GetOutputFile(); - } file.Rewind(); @@ -377,26 +368,17 @@ } -void PlaybackTest::Serialize(std::ostream &output, const mpt::ustring &filename) const noexcept(false) +void PlaybackTest::Serialize(std::ostream &output) const noexcept(false) { - std::ostringstream outStream; - mpt::IO::Write(outStream, m_testData->header); - mpt::IO::Write(outStream, m_testData->sampleDataHashes); + mpt::IO::Write(output, m_testData->header); + mpt::IO::Write(output, m_testData->sampleDataHashes); for(const auto &row : m_testData->rows) { - mpt::IO::Write(outStream, row.header); - mpt::IO::Write(outStream, row.channels); - mpt::IO::WriteVarInt(outStream, row.oplRegisters.size()); - mpt::IO::Write(outStream, row.oplRegisters); + mpt::IO::Write(output, row.header); + mpt::IO::Write(output, row.channels); + mpt::IO::WriteVarInt(output, row.oplRegisters.size()); + mpt::IO::Write(output, row.oplRegisters); } - -#ifdef MPT_WITH_ZLIB - std::string outData = std::move(outStream).str(); - WriteGzip(output, outData, filename); -#else - // miniz doesn't have gzip convenience functions - output << std::move(outStream).str(); -#endif } Modified: trunk/OpenMPT/test/PlaybackTest.h ============================================================================== --- trunk/OpenMPT/test/PlaybackTest.h Thu Aug 15 12:30:30 2024 (r21440) +++ trunk/OpenMPT/test/PlaybackTest.h Thu Aug 15 14:26:46 2024 (r21441) @@ -34,7 +34,7 @@ PlaybackTest& operator=(const PlaybackTest &) = delete; void Deserialize(FileReader file) noexcept(false); - void Serialize(std::ostream &output, const mpt::ustring &filename) const noexcept(false); + void Serialize(std::ostream &output) const noexcept(false); void ToTSV(std::ostream &output) const noexcept(false); PlaybackTestSettings GetSettings() const noexcept; |