Debian Codegraph @

tests/plugins/test-plugin-pushsrc.cc

raw symbols SCIP
1 /*
2 * test-plugin-pushsrc.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 <string>
15 #include <gstreamermm/appsink.h>
16 #include <gstreamermm/private/pushsrc_p.h>
17
18 using namespace Gst;
19 using Glib::RefPtr;
20
21 class FooSrc : public Gst::PushSrc
22 {
23 int count_left;
24
25 public:
26 static const int COUNT = 5;
27 static void class_init(Gst::ElementClass<FooSrc> *klass)
28 {
29 klass->set_metadata("foosrc_longname",
30 "foosrc_classification", "foosrc_detail_description", "foosrc_detail_author");
31
32 klass->add_pad_template(Gst::PadTemplate::create("src", Gst::PAD_SRC, Gst::PAD_ALWAYS,
33 Gst::Caps::create_from_string("x-application/x-foo1")));
34 }
35
36 explicit FooSrc(GstPushSrc *gobj)
37 : Gst::PushSrc(gobj),
38 count_left(COUNT)
39 {
40 set_format(Gst::FORMAT_TIME);
41 }
42
43 Gst::FlowReturn create_vfunc(guint64 /* offset */, guint /* size */, Glib::RefPtr<Gst::Buffer>& buffer)
44 {
45 if (count_left-- <= 0)
46 return Gst::FLOW_EOS;
47
48 std::string s = std::to_string(COUNT - count_left);
49 buffer = Gst::Buffer::create(s.size());
50
51 MapInfo info;
52 buffer->map(info, MAP_WRITE);
53
54 std::copy(s.begin(), s.end(), info.get_data());
55 return Gst::FLOW_OK;
56 }
57
58 virtual bool negotiate_vfunc()
59 {
60 return true;
61 }
62
63 virtual bool start_vfunc()
64 {
65 count_left = COUNT;
66 return true;
67 }
68 };
69
70 bool register_foo(Glib::RefPtr<Gst::Plugin> plugin)
71 {
72 Gst::ElementFactory::register_element(plugin, "foosrcmm", 10, Gst::register_mm_type<FooSrc>("foosrcmm"));
73 return true;
74 }
75
76 class PushSrcPluginTest : public ::testing::Test
77 {
78 protected:
79 virtual void SetUp()
80 {
81 Plugin::register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR, "foo",
82 "foo is example of C++ element", sigc::ptr_fun(register_foo), "0.123",
83 "LGPL", "source?", "package?", "http://example.com");
84 }
85
86 RefPtr<Pipeline> CreatePipeline()
87 {
88 RefPtr<Pipeline> pipeline = Pipeline::create("my-pipeline");
89
90 EXPECT_TRUE(!!pipeline);
91
92 RefPtr<Element> source = ElementFactory::create_element("foosrcmm", "src");
93 RefPtr<AppSink> sink = AppSink::create("sink");
94
95 EXPECT_TRUE(!!source);
96 EXPECT_TRUE(!!sink);
97
98 pipeline->add(source)->add(sink);
99 source->link(sink);
100
101 return pipeline;
102 }
103 };
104
105 TEST_F(PushSrcPluginTest, CreateRegisteredElement)
106 {
107 Glib::RefPtr<Gst::Element> source = Gst::ElementFactory::create_element("foosrcmm", "src");
108
109 MM_ASSERT_TRUE(source);
110 }
111
112 TEST_F(PushSrcPluginTest, DISABLED_CreatePipelineWithRegisteredElement)
113 {
114 CreatePipeline();
115 }
116
117 #endif