Skip to content

Commit 450af52

Browse files
authored
WIP: Experimental Unit Tests without Display (#900)
* Experimental test for unit tests without display * Ignore unit tests running on an invalid QT Platform (i.e. offscreen - running as a test on GitHub) * Fix whitespace on Caption effect * Check for env variable for QT_QPA_PLATFORM == offscreen, and ignore Caption unit tests (for GitHub checks)
1 parent fbbe457 commit 450af52

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ jobs:
202202
203203
- name: Test libopenshot
204204
run: |
205+
# Allow unit tests which require a display screen
206+
export DISPLAY=:0.0
207+
export QT_QPA_PLATFORM=offscreen
205208
cmake --build build --target coverage -- VERBOSE=1
206209
207210
- name: Install libopenshot

src/effects/Caption.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,10 @@ std::shared_ptr<openshot::Frame> Caption::GetFrame(std::shared_ptr<openshot::Fra
204204
// Wrap languages which do not use spaces
205205
bool use_spaces = true;
206206
if (line.length() > 20 && words.length() == 1) {
207-
words = line.split("");
208-
use_spaces = false;
207+
words = line.split("");
208+
use_spaces = false;
209209
}
210-
int words_remaining = words.length();
210+
int words_remaining = words.length();
211211
while (words_remaining > 0) {
212212
bool words_displayed = false;
213213
for(int word_index = words.length(); word_index > 0; word_index--) {
@@ -222,11 +222,11 @@ std::shared_ptr<openshot::Frame> Caption::GetFrame(std::shared_ptr<openshot::Fra
222222

223223
// Create path and add text to it (for correct border and fill)
224224
QPainterPath path1;
225-
QString fitting_line;
225+
QString fitting_line;
226226
if (use_spaces) {
227-
fitting_line = words.mid(0, word_index).join(" ");
227+
fitting_line = words.mid(0, word_index).join(" ");
228228
} else {
229-
fitting_line = words.mid(0, word_index).join("");
229+
fitting_line = words.mid(0, word_index).join("");
230230
}
231231
path1.addText(p, font, fitting_line);
232232
text_paths.push_back(path1);

tests/Caption.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323

2424
TEST_CASE( "caption effect", "[libopenshot][caption]" )
2525
{
26+
// Check for QT Platform Environment variable - and ignore these tests if it's set to offscreen
27+
if (std::getenv("QT_QPA_PLATFORM") != nullptr) {
28+
std::string qt_platform_env = std::getenv("QT_QPA_PLATFORM");
29+
if (qt_platform_env == "offscreen") {
30+
std::cout << "Ignoring Caption unit tests due to invalid QT Platform: offscreen" << std::endl;
31+
return;
32+
}
33+
}
34+
2635
int argc;
2736
char* argv[2];
2837
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

0 commit comments

Comments
 (0)