From 70f3abeaff0640628eff9dc612f62527166a21b2 Mon Sep 17 00:00:00 2001 From: barts Date: Tue, 30 Jan 2024 21:32:17 +0100 Subject: [PATCH] fix: test_record.cpp --- tests/test_video/test_record.cpp | 42 ++++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/test_video/test_record.cpp b/tests/test_video/test_record.cpp index 5fccb0e..791e901 100644 --- a/tests/test_video/test_record.cpp +++ b/tests/test_video/test_record.cpp @@ -16,8 +16,8 @@ class TestRecorder : public QObject { private: Q_OBJECT - path tmp_dir; - QString debug_video_qstr; + path tmpDir; + QString debugVideo; std::unique_ptr app; private slots: @@ -28,13 +28,11 @@ class TestRecorder : public QObject { } void init() { - debug_video_qstr = QString::fromStdString(debug_video.string()); - tmp_dir = std::filesystem::temp_directory_path(); - tmp_dir /= "test_record"; - //TODO: the test sometimes fails because the tmp directory is not empty (i - //think). It is better if a new tmp directory is created with a unique - //name. - std::filesystem::remove_all(tmp_dir); + debugVideo = QString::fromStdString(debug_video.string()); + tmpDir = std::filesystem::temp_directory_path(); + tmpDir /= "test_record"; + std::filesystem::remove_all(tmpDir); + Path::mkdir(tmpDir); } /** @@ -44,9 +42,11 @@ class TestRecorder : public QObject { * the save method, 1 image should be saved in the temporary directory. */ void testImageSaverSave() { - MediaPlayer player(debug_video_qstr); + MediaPlayer player(debugVideo); QVideoSink *sink = player.getVideoSink(); - ImageSaver saver(sink, tmp_dir); + ImageSaver saver(sink, tmpDir); + int cntDir = Path::numberOfItems(tmpDir); + int cntFiles = Path::numberOfFilesRecursive(tmpDir); player.start(); QTest::qWait(250); @@ -55,8 +55,8 @@ class TestRecorder : public QObject { saver.save(); player.stop(); QCOMPARE(player.getState(), VideoState::Stop); - ASSERT_EQ(Path::numberOfItems(tmp_dir), 1); - ASSERT_EQ(Path::numberOfFilesRecursive(tmp_dir), 1); + ASSERT_EQ(Path::numberOfItems(tmpDir), cntDir + 1); + ASSERT_EQ(Path::numberOfFilesRecursive(tmpDir), cntFiles + 1); } /** @@ -66,9 +66,9 @@ class TestRecorder : public QObject { * is used to provide a QVideoSink with frames. */ void testRecorderStart() { - MediaPlayer player(debug_video_qstr); + MediaPlayer player(debugVideo); QVideoSink *sink = player.getVideoSink(); - Recorder recorder(sink, tmp_dir); + Recorder recorder(sink, tmpDir); player.start(); QTest::qWait(250); @@ -85,14 +85,14 @@ class TestRecorder : public QObject { QCOMPARE(player.getState(), VideoState::Stop); // 1 image should be saved in the temporary directory. - QCOMPARE(Path::numberOfItems(tmp_dir), 1); - ASSERT_EQ(Path::numberOfFilesRecursive(tmp_dir), 1); + QCOMPARE(Path::numberOfItems(tmpDir), 1); + ASSERT_EQ(Path::numberOfFilesRecursive(tmpDir), 1); } void testRecordStartStop() { - MediaPlayer player(debug_video_qstr); + MediaPlayer player(debugVideo); QVideoSink *sink = player.getVideoSink(); - Recorder recorder(sink, tmp_dir); + Recorder recorder(sink, tmpDir); player.start(); QTest::qWait(250); @@ -121,7 +121,7 @@ class TestRecorder : public QObject { * state. */ void testRecorderNullptr() { - Recorder recorder(nullptr, tmp_dir); + Recorder recorder(nullptr, tmpDir); recorder.start(ms(1000), ms(5000)); QCOMPARE(recorder.getState(), RecorderState::Start); @@ -131,7 +131,7 @@ class TestRecorder : public QObject { QCOMPARE(recorder.getState(), RecorderState::Stop); } - void cleanup() { std::filesystem::remove_all(tmp_dir); } + void cleanup() { std::filesystem::remove_all(tmpDir); } }; TEST(testRecord, testRecorder) {