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..289f804f 100644 --- a/lib/core/src/AudioRecording.cpp +++ b/lib/core/src/AudioRecording.cpp @@ -1,15 +1,25 @@ #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"; + 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/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, diff --git a/test/AudioRecording.cpp b/test/AudioRecording.cpp index ae0cbd70..7c105671 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) @@ -19,9 +21,20 @@ 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) { + audioRecording.notifyThatTrialWillBegin(1); + AV_SPEECH_IN_NOISE_EXPECT_TRUE(beginsWith(timeStamp.log(), "capture")); } AUDIO_RECORDING_TEST(startsRecordingWhenStimulusEnds) { 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