| 1 | /* |
| 2 | * test-plugin-register.cc |
| 3 | * |
| 4 | * Created on: Aug 1, 2013 |
| 5 | * Author: m.kolny |
| 6 | */ |
| 7 | |
| 8 | #include "mmtest.h" |
| 9 | #include <gstreamermm.h> |
| 10 | |
| 11 | // TODO re-write this tests to not use AppSrc/AppSink |
| 12 | #ifndef GSTREAMERMM_DISABLE_DEPRECATED |
| 13 | |
| 14 | #include <gstreamermm/appsink.h> |
| 15 | #include <gstreamermm/appsrc.h> |
| 16 | #include <vector> |
| 17 | #include "foo.h" |
| 18 | |
| 19 | using namespace Gst; |
| 20 | using Glib::RefPtr; |
| 21 | |
| 22 | class RegisterPluginTest : public ::testing::Test |
| 23 | { |
| 24 | protected: |
| 25 | RefPtr<AppSrc> source; |
| 26 | RefPtr<Element> filter; |
| 27 | RefPtr<AppSink> sink; |
| 28 | RefPtr<Gst::Pipeline> pipeline; |
| 29 | |
| 30 | virtual void SetUp() |
| 31 | { |
| 32 | Plugin::register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR, "foo", |
| 33 | "foo is example of C++ element", sigc::ptr_fun(&Foo::register_foo), "0.123", |
| 34 | "LGPL", "source?", "package?", "http://example.com"); |
| 35 | } |
| 36 | |
| 37 | void CreatePipelineWithElements() |
| 38 | { |
| 39 | pipeline = Gst::Pipeline::create("my-pipeline"); |
| 40 | |
| 41 | source = AppSrc::create("source"); |
| 42 | filter = ElementFactory::create_element("foomm", "filter"); |
| 43 | sink = AppSink::create("sink"); |
| 44 | |
| 45 | MM_ASSERT_TRUE(source); |
| 46 | MM_ASSERT_TRUE(filter); |
| 47 | MM_ASSERT_TRUE(sink); |
| 48 | |
| 49 | EXPECT_NO_THROW(pipeline->add(source)->add(filter)->add(sink)); |
| 50 | EXPECT_NO_THROW(source->link(filter)->link(sink)); |
| 51 | } |
| 52 | }; |
| 53 | |
| 54 | TEST_F(RegisterPluginTest, CreateRegisteredElement) |
| 55 | { |
| 56 | filter = Gst::ElementFactory::create_element("foomm", "filter"); |
| 57 | |
| 58 | MM_ASSERT_TRUE(filter); |
| 59 | } |
| 60 | |
| 61 | TEST_F(RegisterPluginTest, CheckPropertyUsage) |
| 62 | { |
| 63 | filter = Gst::ElementFactory::create_element("foomm", "filter"); |
| 64 | |
| 65 | MM_ASSERT_TRUE(filter); |
| 66 | |
| 67 | Glib::ustring property_value; |
| 68 | filter->get_property("sample_property", property_value); |
| 69 | EXPECT_STREQ("def_val", property_value.c_str()); |
| 70 | |
| 71 | Glib::ustring expected_property_value = "second_property_test"; |
| 72 | filter->set_property("sample_property", expected_property_value); |
| 73 | filter->get_property("sample_property", property_value); |
| 74 | EXPECT_STREQ(expected_property_value.c_str(), property_value.c_str()); |
| 75 | } |
| 76 | |
| 77 | TEST_F(RegisterPluginTest, CreatePipelineWithRegisteredElement) |
| 78 | { |
| 79 | CreatePipelineWithElements(); |
| 80 | } |
| 81 | |
| 82 | TEST_F(RegisterPluginTest, CheckDataFlowThroughCreatedElement) |
| 83 | { |
| 84 | CreatePipelineWithElements(); |
| 85 | |
| 86 | EXPECT_EQ(STATE_CHANGE_ASYNC, pipeline->set_state(STATE_PLAYING)); |
| 87 | |
| 88 | std::vector<guint8> data = {4, 5, 2, 7, 1}; |
| 89 | RefPtr<Buffer> buf = Buffer::create(data.size()); |
| 90 | MM_ASSERT_TRUE(buf); |
| 91 | Gst::MapInfo mapinfo; |
| 92 | |
| 93 | MM_ASSERT_TRUE(buf->map(mapinfo, MAP_WRITE)); |
| 94 | std::copy(data.begin(), data.end(), mapinfo.get_data()); |
| 95 | EXPECT_EQ(FLOW_OK, source->push_buffer(buf)); |
| 96 | buf->unmap(mapinfo); |
| 97 | |
| 98 | RefPtr<Gst::Buffer> buf_out; |
| 99 | RefPtr<Gst::Sample> samp = sink->pull_preroll(); |
| 100 | |
| 101 | MM_ASSERT_TRUE(samp); |
| 102 | buf_out = samp->get_buffer(); |
| 103 | MM_ASSERT_TRUE(buf_out->map(mapinfo, MAP_READ)); |
| 104 | MM_ASSERT_TRUE(mapinfo.get_data()); |
| 105 | std::sort(data.begin(), data.end()); |
| 106 | MM_ASSERT_TRUE(std::equal(data.begin(), data.end(), mapinfo.get_data())); |
| 107 | buf_out->unmap(mapinfo); |
| 108 | EXPECT_EQ(FLOW_OK, source->end_of_stream()); |
| 109 | |
| 110 | EXPECT_EQ(STATE_CHANGE_SUCCESS, pipeline->set_state(Gst::STATE_NULL)); |
| 111 | } |
| 112 | |
| 113 | #endif |