Debian Codegraph @

tests/test-query.cc

raw symbols SCIP
1 /*
2 * test-query.cc
3 *
4 * Created on: 5 sie 2013
5 * Author: loganek
6 */
7
8 #include "mmtest.h"
9 #include <gstreamermm.h>
10 #include <functional>
11
12 using namespace Gst;
13 using Glib::RefPtr;
14
15 template<typename QType>
16 void CreatingQueryTest(std::function<RefPtr<QType>()> create_method, QueryType type)
17 {
18 RefPtr<QType> query = create_method();
19
20 MM_ASSERT_TRUE(query);
21 ASSERT_EQ(type, query->get_query_type());
22 }
23
24 template<typename QType>
25 void CreatingQueryTestStatic(std::function<RefPtr<Query>()> create_method, QueryType type)
26 {
27 RefPtr<Query> query = create_method();
28
29 MM_ASSERT_TRUE(query);
30 ASSERT_EQ(type, query->get_query_type());
31
32 RefPtr<QType> query_position = RefPtr<QType>::cast_static(query);
33
34 MM_ASSERT_TRUE(query_position);
35 }
36
37 TEST(QueryTest, CorrectCreatingQueryBuffering)
38 {
39 CreatingQueryTestStatic<QueryBuffering>(
40 std::bind(&Query::create_buffering, FORMAT_BUFFERS), QUERY_BUFFERING);
41 CreatingQueryTest<QueryBuffering>(
42 std::bind(&QueryBuffering::create, FORMAT_BUFFERS), QUERY_BUFFERING);
43 }
44
45 TEST(QueryTest, CorrectCreatingQueryPosition)
46 {
47 CreatingQueryTestStatic<QueryPosition>(
48 std::bind(&Query::create_position, FORMAT_PERCENT), QUERY_POSITION);
49 CreatingQueryTest<QueryPosition>(
50 std::bind(&QueryPosition::create, FORMAT_PERCENT), QUERY_POSITION);
51 }
52
53 TEST(QueryTest, CorrectCreatingQueryConvert)
54 {
55 CreatingQueryTestStatic<QueryConvert>(
56 std::bind(&Query::create_convert, FORMAT_PERCENT, 10, FORMAT_BYTES), QUERY_CONVERT);
57 CreatingQueryTest<QueryConvert>(
58 std::bind(&QueryConvert::create, FORMAT_PERCENT, 10, FORMAT_BYTES), QUERY_CONVERT);
59 }
60
61 TEST(QueryTest, CheckRefCountsDuringQueryCapsCreation)
62 {
63 RefPtr<Caps> filter = Caps::create_from_string("video/x-raw");
64 RefPtr<QueryCaps> query = QueryCaps::create(filter);
65
66 RefPtr<Caps> caps = query->parse();
67 ASSERT_EQ(caps, filter);
68 ASSERT_EQ(3, caps->gobj()->mini_object.refcount); // - 1 (caps object) + 1 (filter object) + 1 (owned by query) = 3
69 }
70
71 TEST(QueryTest, CheckStoringAllocationParams)
72 {
73 auto alloc_query = QueryAllocation::create(Caps::create_from_string("video/x-raw, format=RGB"), false);
74 RefPtr<Allocator> allocator = Allocator::get_default_allocator(), allocator2;
75 AllocationParams params, params2;
76 params.init(); params.set_align(10);
77 alloc_query->add_allocation_param(allocator, params);
78 alloc_query->parse_nth_allocation_param(0, allocator2, params2);
79 ASSERT_EQ(allocator, allocator2);
80 ASSERT_EQ(params.get_align(), params2.get_align());
81 }
82
83 void ogoloc(Glib::RefPtr<Gst::Query> &query)
84 {
85 Glib::RefPtr<Gst::QueryUri> query_uri(static_cast<Gst::QueryUri*>(query.release()));
86
87 }
88
89 TEST(QueryTest, ShouldCastToAnotherQueryTypeWithoutAdditionalReference)
90 {
91 Glib::RefPtr<Gst::Query> query = QueryUri::create();
92 Glib::ustring uri = "file:///some/uri";
93
94 {
95 Glib::RefPtr<Gst::QueryUri> query_uri(static_cast<Gst::QueryUri*>(query.release()));
96 MM_ASSERT_FALSE(query);
97 // QueryUri::set requires writable query object, so query object's refcount has to equal 1
98 MM_ASSERT_TRUE(query_uri->is_writable());
99 query_uri->set(uri);
100 ASSERT_STREQ(uri.c_str(), query_uri->parse().c_str());
101 query = std::move(query_uri);
102 MM_ASSERT_FALSE(query_uri);
103 }
104 ASSERT_EQ(1, query->get_refcount());
105 }