From efafb3fb4ce217bbfa0f62ccfb3d197b3e6d8f0e Mon Sep 17 00:00:00 2001 From: Seth Bashford Date: Thu, 30 Jun 2022 10:19:44 -0500 Subject: [PATCH 1/4] extract file --- test/OutputFilePath.cpp | 64 +++---------------------------------- test/TimeStampStub.hpp | 70 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 60 deletions(-) create mode 100644 test/TimeStampStub.hpp diff --git a/test/OutputFilePath.cpp b/test/OutputFilePath.cpp index 8aaf2aea..345e530f 100644 --- a/test/OutputFilePath.cpp +++ b/test/OutputFilePath.cpp @@ -1,68 +1,12 @@ -#include "LogString.hpp" +#include "TimeStampStub.hpp" #include "assert-utility.hpp" -#include + #include +#include + namespace av_speech_in_noise { namespace { -class TimeStampStub : public TimeStamp { - public: - void capture() override { insert(log_, "capture "); } - - auto log() const -> const std::stringstream & { return log_; } - - void setYear(int y) { year_ = y; } - - void setMonth(int y) { month_ = y; } - - void setDayOfMonth(int y) { dayOfMonth_ = y; } - - void setHour(int y) { hour_ = y; } - - void setMinute(int y) { minute_ = y; } - - void setSecond(int y) { second_ = y; } - - auto year() -> int override { - insert(log_, "year "); - return year_; - } - - auto month() -> int override { - insert(log_, "month "); - return month_; - } - - auto dayOfMonth() -> int override { - insert(log_, "dayOfMonth "); - return dayOfMonth_; - } - - auto hour() -> int override { - insert(log_, "hour "); - return hour_; - } - - auto minute() -> int override { - insert(log_, "minute "); - return minute_; - } - - auto second() -> int override { - insert(log_, "second "); - return second_; - } - - private: - std::stringstream log_{}; - int year_{}; - int month_{}; - int dayOfMonth_{}; - int hour_{}; - int minute_{}; - int second_{}; -}; - class FileSystemPathStub : public FileSystemPath { std::string homeDirectory_{}; std::string directoryCreated_{}; diff --git a/test/TimeStampStub.hpp b/test/TimeStampStub.hpp new file mode 100644 index 00000000..5af097b5 --- /dev/null +++ b/test/TimeStampStub.hpp @@ -0,0 +1,70 @@ +#ifndef AV_SPEECH_IN_NOISE_TESTS_TIMESTAMPSTUB_HPP_ +#define AV_SPEECH_IN_NOISE_TESTS_TIMESTAMPSTUB_HPP_ + +#include "LogString.hpp" + +#include + +#include + +namespace av_speech_in_noise { +class TimeStampStub : public TimeStamp { + public: + void capture() override { insert(log_, "capture "); } + + auto log() const -> const std::stringstream & { return log_; } + + void setYear(int y) { year_ = y; } + + void setMonth(int y) { month_ = y; } + + void setDayOfMonth(int y) { dayOfMonth_ = y; } + + void setHour(int y) { hour_ = y; } + + void setMinute(int y) { minute_ = y; } + + void setSecond(int y) { second_ = y; } + + auto year() -> int override { + insert(log_, "year "); + return year_; + } + + auto month() -> int override { + insert(log_, "month "); + return month_; + } + + auto dayOfMonth() -> int override { + insert(log_, "dayOfMonth "); + return dayOfMonth_; + } + + auto hour() -> int override { + insert(log_, "hour "); + return hour_; + } + + auto minute() -> int override { + insert(log_, "minute "); + return minute_; + } + + auto second() -> int override { + insert(log_, "second "); + return second_; + } + + private: + std::stringstream log_{}; + int year_{}; + int month_{}; + int dayOfMonth_{}; + int hour_{}; + int minute_{}; + int second_{}; +}; +} + +#endif From 3c1dd5c1028b8297e2567b8fb3d1fb322b1cf2f7 Mon Sep 17 00:00:00 2001 From: Seth Bashford Date: Thu, 30 Jun 2022 10:23:45 -0500 Subject: [PATCH 2/4] add test --- .../include/av-speech-in-noise/core/AudioRecording.hpp | 4 +++- lib/core/src/AudioRecording.cpp | 7 +++++-- test/AudioRecording.cpp | 9 ++++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/core/include/av-speech-in-noise/core/AudioRecording.hpp b/lib/core/include/av-speech-in-noise/core/AudioRecording.hpp index 145513e0..740f8253 100644 --- a/lib/core/include/av-speech-in-noise/core/AudioRecording.hpp +++ b/lib/core/include/av-speech-in-noise/core/AudioRecording.hpp @@ -3,6 +3,7 @@ #include "IRecognitionTestModel.hpp" #include "IOutputFile.hpp" +#include "FileSystemPath.hpp" #include @@ -19,7 +20,7 @@ class AudioRecorder { class AudioRecording : public RunningATest::Observer { public: - AudioRecording(AudioRecorder &, OutputFile &); + AudioRecording(AudioRecorder &, OutputFile &, TimeStamp &); void notifyThatNewTestIsReady(std::string_view session) override; void notifyThatTrialWillBegin(int trialNumber) override; void notifyThatTargetWillPlayAt(const PlayerTimeWithDelay &) override; @@ -30,6 +31,7 @@ class AudioRecording : public RunningATest::Observer { std::string session; AudioRecorder &audioRecorder; OutputFile &outputFile; + TimeStamp &timeStamp; }; } diff --git a/lib/core/src/AudioRecording.cpp b/lib/core/src/AudioRecording.cpp index 91ca539b..d7adbbf7 100644 --- a/lib/core/src/AudioRecording.cpp +++ b/lib/core/src/AudioRecording.cpp @@ -1,13 +1,16 @@ #include "AudioRecording.hpp" +#include "FileSystemPath.hpp" #include namespace av_speech_in_noise { AudioRecording::AudioRecording( - AudioRecorder &audioRecorder, OutputFile &outputFile) - : audioRecorder{audioRecorder}, outputFile{outputFile} {} + AudioRecorder &audioRecorder, OutputFile &outputFile, TimeStamp &timeStamp) + : audioRecorder{audioRecorder}, outputFile{outputFile}, timeStamp{ + timeStamp} {} void AudioRecording::notifyThatTrialWillBegin(int trialNumber) { + timeStamp.capture(); std::stringstream filename; filename << trialNumber << '-' << session << ".wav"; audioRecorder.initialize( diff --git a/test/AudioRecording.cpp b/test/AudioRecording.cpp index ae0cbd70..a2692d76 100644 --- a/test/AudioRecording.cpp +++ b/test/AudioRecording.cpp @@ -1,5 +1,6 @@ #include "AudioRecorderStub.hpp" #include "OutputFileStub.hpp" +#include "TimeStampStub.hpp" #include "assert-utility.hpp" #include @@ -11,7 +12,8 @@ class AudioRecordingTests : public ::testing::Test { protected: AudioRecorderStub audioRecorder; OutputFileStub outputFile; - AudioRecording audioRecording{audioRecorder, outputFile}; + TimeStampStub timeStamp; + AudioRecording audioRecording{audioRecorder, outputFile, timeStamp}; }; #define AUDIO_RECORDING_TEST(a) TEST_F(AudioRecordingTests, a) @@ -24,6 +26,11 @@ AUDIO_RECORDING_TEST(initializesRecorderWhenTrialWillBegin) { "/Users/user/data/3-smile.wav", audioRecorder.fileUrl().path); } +AUDIO_RECORDING_TEST(generateFileNameCapturesTimePriorToQueries) { + audioRecording.notifyThatTrialWillBegin(1); + AV_SPEECH_IN_NOISE_EXPECT_TRUE(beginsWith(timeStamp.log(), "capture")); +} + AUDIO_RECORDING_TEST(startsRecordingWhenStimulusEnds) { audioRecording.notifyThatStimulusHasEnded(); AV_SPEECH_IN_NOISE_EXPECT_TRUE(audioRecorder.started()); From c63278f23f80a45e4cd6f5903fdc54e85c37ab7d Mon Sep 17 00:00:00 2001 From: Seth Bashford Date: Thu, 30 Jun 2022 10:27:42 -0500 Subject: [PATCH 3/4] add to test --- lib/core/src/AudioRecording.cpp | 9 ++++++++- test/AudioRecording.cpp | 10 ++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/core/src/AudioRecording.cpp b/lib/core/src/AudioRecording.cpp index d7adbbf7..289f804f 100644 --- a/lib/core/src/AudioRecording.cpp +++ b/lib/core/src/AudioRecording.cpp @@ -12,7 +12,14 @@ AudioRecording::AudioRecording( void AudioRecording::notifyThatTrialWillBegin(int trialNumber) { timeStamp.capture(); std::stringstream filename; - filename << trialNumber << '-' << session << ".wav"; + filename << trialNumber << '-' << session; + filename << '-' << timeStamp.year(); + filename << '-' << timeStamp.month(); + filename << '-' << timeStamp.dayOfMonth(); + filename << '-' << timeStamp.hour(); + filename << '-' << timeStamp.minute(); + filename << '-' << timeStamp.second(); + filename << ".wav"; audioRecorder.initialize( LocalUrl{outputFile.parentPath() / filename.str()}); } diff --git a/test/AudioRecording.cpp b/test/AudioRecording.cpp index a2692d76..7c105671 100644 --- a/test/AudioRecording.cpp +++ b/test/AudioRecording.cpp @@ -21,9 +21,15 @@ class AudioRecordingTests : public ::testing::Test { AUDIO_RECORDING_TEST(initializesRecorderWhenTrialWillBegin) { outputFile.setParentPath("/Users/user/data"); audioRecording.notifyThatNewTestIsReady("smile"); + timeStamp.setYear(1); + timeStamp.setMonth(2); + timeStamp.setDayOfMonth(7); + timeStamp.setHour(4); + timeStamp.setMinute(5); + timeStamp.setSecond(6); audioRecording.notifyThatTrialWillBegin(3); - AV_SPEECH_IN_NOISE_EXPECT_EQUAL( - "/Users/user/data/3-smile.wav", audioRecorder.fileUrl().path); + AV_SPEECH_IN_NOISE_EXPECT_EQUAL("/Users/user/data/3-smile-1-2-7-4-5-6.wav", + audioRecorder.fileUrl().path); } AUDIO_RECORDING_TEST(generateFileNameCapturesTimePriorToQueries) { From dd30d4aeffbe800592c80656d8c7871ccc59bc47 Mon Sep 17 00:00:00 2001 From: Seth Bashford Date: Thu, 30 Jun 2022 10:29:54 -0500 Subject: [PATCH 4/4] fix main --- macos/run.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macos/run.mm b/macos/run.mm index 534fbdd1..893189ca 100644 --- a/macos/run.mm +++ b/macos/run.mm @@ -321,7 +321,7 @@ void initializeAppAndRunEventLoop(EyeTracker &eyeTracker, &cyclicTargetsFactory, &directoryReader}; static PredeterminedTargetPlaylist predeterminedTargetPlaylist{ textFileReader}; - static AudioRecording audioRecording{audioRecorder, outputFile}; + static AudioRecording audioRecording{audioRecorder, outputFile, timeStamp}; static EyeTracking eyeTracking{ eyeTracker, maskerPlayer, targetPlayer, outputFile}; static RunningATestFacadeImpl model{adaptiveMethod, fixedLevelMethod,