2 #include "mockclient.h"
3 #include "mockcompositor.h"
7 #include <drm_fourcc.h>
9 #include <libds-tizen/video.h>
10 #include <tizen-extension-client-protocol.h>
12 TEST(ScalerSimpleTest, CreateScaler)
14 struct wl_display *display = wl_display_create();
16 struct ds_tizen_video *video = ds_tizen_video_create(display);
17 ASSERT_NE(video, nullptr);
19 wl_display_destroy(display);
22 class VideoCompositor : public MockCompositor, public ::testing::Test
26 MockCompositor(&VideoCompositor::SetUpComp, this)
28 /* We are only interested in test results. Let's silence libds log. */
29 ds_log_init(DS_SILENT, nullptr);
31 this->video = nullptr;
34 static void SetUpComp(void *data)
36 VideoCompositor *comp = static_cast<VideoCompositor*>(data);
38 comp->video = ds_tizen_video_create(comp->GetWlDisplay());
39 ASSERT_NE(comp->video, nullptr);
42 struct ds_tizen_video *video;
45 static void handle_global(void *data, struct wl_registry *registry,
46 uint32_t name, const char *interface, uint32_t version);
47 static void handle_global_remove(void *data, struct wl_registry *registry,
50 static const struct wl_registry_listener registry_listener = {
51 .global = handle_global,
52 .global_remove = handle_global_remove,
55 class MockVideoClient : public MockClient
58 MockVideoClient() : MockClient(®istry_listener, this)
60 EXPECT_NE(this->compositor, nullptr);
61 EXPECT_NE(this->video, nullptr);
63 surface = wl_compositor_create_surface(this->compositor);
64 EXPECT_NE(this->surface, nullptr);
69 wl_surface_destroy(this->surface);
70 tizen_video_destroy(this->video);
71 wl_compositor_destroy(this->compositor);
74 struct wl_compositor *compositor;
75 struct tizen_video *video;
76 struct wl_surface *surface;
80 handle_global(void *data, struct wl_registry *registry,
81 uint32_t name, const char *interface, uint32_t version)
83 MockVideoClient *client = static_cast<MockVideoClient*>(data);
85 if (strcmp(interface, "wl_compositor") == 0) {
86 client->compositor = static_cast<struct wl_compositor*>(
87 wl_registry_bind(registry, name, &wl_compositor_interface, 4));
88 } else if (strcmp(interface, "tizen_video") == 0) {
89 client->video = static_cast<struct tizen_video*>(
90 wl_registry_bind(registry, name, &tizen_video_interface, 1));
95 handle_global_remove(void *data, struct wl_registry *registry, uint32_t name)
100 video_handle_format(void *data, struct tizen_video *video, uint32_t format)
102 std::vector<uint32_t> *ret_formats =
103 static_cast<std::vector<uint32_t>*>(data);
105 ret_formats->push_back(format);
109 tizen_video_listener video_listener = {
110 .format = video_handle_format,
113 TEST_F(VideoCompositor, AddFormats)
115 std::vector<uint32_t> supported_format {
116 DRM_FORMAT_XRGB8888, DRM_FORMAT_ARGB8888,
119 for (uint32_t format : supported_format)
120 ds_tizen_video_add_format(this->video, format);
122 std::vector<uint32_t> ret_formats;
123 MockVideoClient *client = new MockVideoClient();
124 tizen_video_add_listener(client->video, &video_listener,
125 static_cast<void*>(&ret_formats));
128 ASSERT_EQ(supported_format.size(), ret_formats.size());
131 for (uint32_t format : supported_format) {
133 for (uint32_t ret_format : ret_formats) {
134 if (format == ret_format) {
139 ASSERT_EQ(found, true);
145 TEST_F(VideoCompositor, CreateObject)
147 MockVideoClient *client = new MockVideoClient();
149 struct tizen_video_object *object = tizen_video_get_object(client->video,
151 client->ExpectNoError();
153 tizen_video_object_destroy(object);
158 struct { int32_t width, height; } min;
159 struct { int32_t width, height; } max;
160 int32_t prefer_align;
164 video_object_handle_size(void *data, struct tizen_video_object *object,
165 int32_t min_w, int32_t min_h, int32_t max_w, int32_t max_h,
166 int32_t prefer_align)
168 size_hint *ret_size = static_cast<size_hint*>(data);
169 ret_size->min.width = min_w;
170 ret_size->min.height = min_h;
171 ret_size->max.width = max_w;
172 ret_size->max.height = max_h;
173 ret_size->prefer_align = prefer_align;
177 tizen_video_object_listener object_size_hint_listener = {
179 .size = video_object_handle_size,
182 TEST_F(VideoCompositor, SetSizeHint)
184 size_hint hint = { 100, 50, 1000, 500, 777 };
186 ds_tizen_video_set_size_hint(this->video,
187 hint.min.width, hint.min.height,
188 hint.max.width, hint.max.height,
191 MockVideoClient *client = new MockVideoClient();
193 struct tizen_video_object *object =
194 tizen_video_get_object(client->video, client->surface);
197 tizen_video_object_add_listener(object, &object_size_hint_listener,
198 static_cast<void*>(&ret_hint));
201 ASSERT_EQ(hint.min.width, ret_hint.min.width);
202 ASSERT_EQ(hint.min.height, ret_hint.min.height);
203 ASSERT_EQ(hint.max.width, ret_hint.max.width);
204 ASSERT_EQ(hint.max.height, ret_hint.max.height);
205 ASSERT_EQ(hint.prefer_align, ret_hint.prefer_align);
207 tizen_video_object_destroy(object);
215 property(std::string _name, uint32_t _value) : name(_name), value(_value) {}
219 video_object_handle_attribute(void *data, struct tizen_video_object *object,
220 const char *name, uint32_t value)
222 std::vector<property*> *ret_properties =
223 static_cast<std::vector<property*>*>(data);
225 ret_properties->push_back(new property(std::string(name), value));
229 video_object_dummy_handle_size(void *data, struct tizen_video_object *object,
230 int32_t min_w, int32_t min_h, int32_t max_w, int32_t max_h,
231 int32_t prefer_align)
233 // This left blank intentionally.
237 tizen_video_object_listener object_attribute_listener = {
238 .attribute = video_object_handle_attribute,
239 .size = video_object_dummy_handle_size,
242 TEST_F(VideoCompositor, AddProperties)
244 std::vector<property> properties {
245 { "property0", 123 },
246 { "property1", 987 },
247 { "property2", 345 },
248 { "property3", 777 },
251 for (struct property prop : properties)
252 ds_tizen_video_add_property(this->video, prop.name.c_str(), prop.value);
254 MockVideoClient *client = new MockVideoClient();
256 struct tizen_video_object *object =
257 tizen_video_get_object(client->video, client->surface);
259 std::vector<property*> ret_properties;
260 tizen_video_object_add_listener(object, &object_attribute_listener,
261 static_cast<void*>(&ret_properties));
264 ASSERT_EQ(properties.size(), ret_properties.size());
267 for (property prop : properties) {
269 for (property *ret_prop : ret_properties) {
270 if (prop.name == ret_prop->name &&
271 prop.value == ret_prop->value) {
276 ASSERT_EQ(found, true);
279 for (property *prop : ret_properties)
281 ret_properties.clear();
282 tizen_video_object_destroy(object);