1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-31 03:27:40 +01:00

Test we can load various popular file formats

This commit is contained in:
David Sansome 2010-04-20 22:00:02 +00:00
parent 8b51f90a6e
commit 0656330548
11 changed files with 126 additions and 24 deletions

View File

@ -53,10 +53,7 @@ GstEngine::GstEngine()
: Engine::Base(),
delayq_(g_queue_new()),
current_sample_(0),
equalizer_enabled_(false),
can_decode_pipeline_(NULL),
can_decode_src_(NULL),
can_decode_bin_(NULL)
equalizer_enabled_(false)
{
ReloadSettings();
}
@ -64,9 +61,6 @@ GstEngine::GstEngine()
GstEngine::~GstEngine() {
current_pipeline_.reset();
if (can_decode_pipeline_)
gst_object_unref(GST_OBJECT(can_decode_pipeline_));
// Destroy scope delay queue
ClearScopeBuffers();
g_queue_free(delayq_);
@ -117,21 +111,19 @@ bool GstEngine::CanDecode(const QUrl &url) {
can_decode_last_ = false;
// Create the pipeline
if (!can_decode_pipeline_) {
can_decode_pipeline_ = CreateElement("pipeline");
can_decode_src_ = CreateElement("giosrc", can_decode_pipeline_);
can_decode_bin_ = CreateElement("decodebin", can_decode_pipeline_);
GstElement* pipeline = CreateElement("pipeline");
GstElement* src = CreateElement("giosrc", pipeline);
GstElement* bin = CreateElement("decodebin", pipeline);
gst_element_link(can_decode_src_, can_decode_bin_);
g_signal_connect(G_OBJECT(can_decode_bin_), "new-decoded-pad", G_CALLBACK(CanDecodeNewPadCallback), this);
g_signal_connect(G_OBJECT(can_decode_bin_), "no-more-pads", G_CALLBACK(CanDecodeLastCallback), this);
}
gst_element_link(src, bin);
g_signal_connect(G_OBJECT(bin), "new-decoded-pad", G_CALLBACK(CanDecodeNewPadCallback), this);
g_signal_connect(G_OBJECT(bin), "no-more-pads", G_CALLBACK(CanDecodeLastCallback), this);
// Set the file we're testing
g_object_set(G_OBJECT(can_decode_src_), "location", url.toEncoded().constData(), NULL);
g_object_set(G_OBJECT(src), "location", url.toEncoded().constData(), NULL);
// Start the pipeline playing
gst_element_set_state(can_decode_pipeline_, GST_STATE_PLAYING);
gst_element_set_state(pipeline, GST_STATE_PLAYING);
// Wait until found audio stream
int count = 0;
@ -141,7 +133,8 @@ bool GstEngine::CanDecode(const QUrl &url) {
}
// Stop playing
gst_element_set_state(can_decode_pipeline_, GST_STATE_NULL);
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_object_unref(pipeline);
return can_decode_success_;
}

View File

@ -136,10 +136,6 @@ class GstEngine : public Engine::Base {
mutable bool can_decode_success_;
mutable bool can_decode_last_;
GstElement* can_decode_pipeline_;
GstElement* can_decode_src_;
GstElement* can_decode_bin_;
};

View File

@ -54,11 +54,13 @@ add_custom_target(build_tests
)
add_dependencies(test build_tests)
add_library(test_gui_main EXCLUDE_FROM_ALL main.cpp)
qt4_add_resources(TEST-RESOURCE-SOURCES data/testdata.qrc)
add_library(test_gui_main EXCLUDE_FROM_ALL ${TEST-RESOURCE-SOURCES} main.cpp)
target_link_libraries(test_gui_main clementine_lib)
set_target_properties(test_gui_main PROPERTIES COMPILE_DEFINITIONS GUI)
add_library(test_main EXCLUDE_FROM_ALL main.cpp)
add_library(test_main EXCLUDE_FROM_ALL ${TEST-RESOURCE-SOURCES} main.cpp)
target_link_libraries(test_main clementine_lib)
# Given a file foo_test.cpp, creates a target foo_test and adds it to the test target.
@ -98,3 +100,4 @@ add_test_file(songplaylistitem_test.cpp false)
add_test_file(translations_test.cpp false)
add_test_file(playlist_test.cpp true)
add_test_file(scopedtransaction_test.cpp true)
add_test_file(fileformats_test.cpp true)

BIN
tests/data/beep.flac Normal file

Binary file not shown.

BIN
tests/data/beep.mp3 Normal file

Binary file not shown.

BIN
tests/data/beep.ogg Normal file

Binary file not shown.

BIN
tests/data/beep.spx Normal file

Binary file not shown.

BIN
tests/data/beep.wav Normal file

Binary file not shown.

9
tests/data/testdata.qrc Normal file
View File

@ -0,0 +1,9 @@
<RCC>
<qresource prefix="/testdata">
<file>beep.flac</file>
<file>beep.mp3</file>
<file>beep.ogg</file>
<file>beep.spx</file>
<file>beep.wav</file>
</qresource>
</RCC>

100
tests/fileformats_test.cpp Normal file
View File

@ -0,0 +1,100 @@
/* This file is part of Clementine.
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clementine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "song.h"
#include "engines/gstengine.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "test_utils.h"
#include <QTemporaryFile>
#include <QResource>
#include <QDir>
#include <QSet>
namespace {
class FileformatsTest : public ::testing::TestWithParam<const char*> {
public:
static void SetUpTestCase() {
sGstEngine = new GstEngine;
ASSERT_TRUE(sGstEngine->Init());
}
static void TearDownTestCase() {
delete sGstEngine;
sGstEngine = NULL;
}
protected:
FileformatsTest() {
kFormatsWithoutMetadata.insert("wav");
}
void SetUp() {
format_ = GetParam();
resource_filename_ = ":/testdata/beep." + format_;
temp_filetemplate_ = QDir::tempPath() + "/fileformatstest-XXXXXX." + format_;
}
void SaveToTempFile(QTemporaryFile* file) {
QResource resource(resource_filename_);
file->open();
file->write(reinterpret_cast<const char*>(resource.data()), resource.size());
file->flush();
}
static GstEngine* sGstEngine;
QSet<QString> kFormatsWithoutMetadata;
QString format_;
QString resource_filename_;
QString temp_filetemplate_;
};
GstEngine* FileformatsTest::sGstEngine = NULL;
TEST_P(FileformatsTest, Exists) {
EXPECT_TRUE(QFile::exists(resource_filename_));
}
TEST_P(FileformatsTest, LoadsTags) {
QTemporaryFile temp(temp_filetemplate_);
SaveToTempFile(&temp);
Song song;
song.InitFromFile(temp.fileName(), -1);
ASSERT_TRUE(song.is_valid());
if (!kFormatsWithoutMetadata.contains(format_)) {
EXPECT_EQ("Beep " + format_, song.title());
}
}
TEST_P(FileformatsTest, GstCanDecode) {
QTemporaryFile temp(temp_filetemplate_);
SaveToTempFile(&temp);
EXPECT_TRUE(sGstEngine->CanDecode(QUrl::fromLocalFile(temp.fileName())));
}
INSTANTIATE_TEST_CASE_P(Formats, FileformatsTest, ::testing::Values(
"flac", "mp3", "ogg", "spx", "wav"));
} // namespace

View File

@ -26,6 +26,7 @@ public:
void SetUp() {
Q_INIT_RESOURCE(data);
Q_INIT_RESOURCE(translations);
Q_INIT_RESOURCE(testdata);
}
};