Skip to content

Commit

Permalink
fix: test_record.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart-Steensma committed Jan 30, 2024
1 parent f258110 commit ef21cb6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,18 +413,21 @@ more information.
- [x] Add the remaining dynamic libs to the same directory tree as the
executable and using the script that is provided in the Qt
[docs](https://doc.qt.io/qt-6/linux-deployment.html) to run the app.
- [ ] Go through all the remaining dynamic libs using ldd and see which ones
- [x] Go through all the remaining dynamic libs using ldd and see which ones
can also be linked statically.
- [x] Publish the directory tree as an archive as a release. Other more
sophisticated release methods can be used later.

- [ ] Fix failing test -> see TODO

- [ ] Cross compile for raspberry pi

- [ ] Use ffmpeg 6.0, that is tested by Qt. If not possible, fix the version
instead of using the latest version.

- [ ] Does it also work when the user has an older version of libc installed
than ubuntu 22.04 has?
- [ ] Add to docs:
- How to build static and shared
- How to run the tar archive

- [ ] Add to FAQ:

Expand Down
2 changes: 0 additions & 2 deletions tests/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include <cstdlib>
#include <gtest/gtest.h>
#include <helpers/path.hpp>
#include <iostream>

using path = std::filesystem::path;

Expand Down
39 changes: 21 additions & 18 deletions tests/test_video/test_record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QApplication> app;

private slots:
Expand All @@ -28,10 +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";
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);
}

/**
Expand All @@ -41,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);
Expand All @@ -52,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);
}

/**
Expand All @@ -63,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);
Expand All @@ -82,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);
Expand Down Expand Up @@ -118,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);
Expand All @@ -128,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) {
Expand Down

0 comments on commit ef21cb6

Please sign in to comment.