From: Seunghun Lee Date: Fri, 14 Oct 2022 10:03:52 +0000 (+0900) Subject: video: Add tests for ds_tizen_video X-Git-Tag: accepted/tizen/unified/20230106.165108~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b1c912478e293695d37e6e91dc8965586017ce18;p=platform%2Fcore%2Fuifw%2Flibds-tizen.git video: Add tests for ds_tizen_video This adds tests for ds_tizen_video and ds_tizen_video_object except for tizen_viewport. The tests for tizen_viewport should be added with its implementation later. Change-Id: Ic49e8c90de49aced5aea44e8cb3f71d8af285ffb --- diff --git a/packaging/libds-tizen.spec b/packaging/libds-tizen.spec index 27104b4..19837eb 100644 --- a/packaging/libds-tizen.spec +++ b/packaging/libds-tizen.spec @@ -722,3 +722,4 @@ ninja -C builddir install %{_includedir}/libds-tizen/video.h %{_libdir}/pkgconfig/libds-tizen-video.pc %{_libdir}/libds-tizen-video.so +%{_bindir}/libds-tizen-video-tests diff --git a/tests/meson.build b/tests/meson.build index b933ced..bf9a9d8 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -363,3 +363,23 @@ executable('libds-tizen-scaler-tests', install_dir: libds_tizen_bindir, install : true ) + +tc_video_files = [ + 'tc_main.cpp', + 'tc_video.cpp', +] + +executable('libds-tizen-video-tests', + [ + tc_mock_files, + tc_video_files + ], + dependencies: [ + deps_test_common, + deps_libds_tizen_video, + dependency('tizen-extension-client', required: true), + dependency('libdrm', required: true), + ], + install_dir: libds_tizen_bindir, + install : true +) diff --git a/tests/tc_video.cpp b/tests/tc_video.cpp new file mode 100644 index 0000000..fc4891d --- /dev/null +++ b/tests/tc_video.cpp @@ -0,0 +1,284 @@ +#include "tc_main.h" +#include "mockclient.h" +#include "mockcompositor.h" + +#include +#include +#include +#include +#include +#include + +TEST(ScalerSimpleTest, CreateScaler) +{ + struct wl_display *display = wl_display_create(); + + struct ds_tizen_video *video = ds_tizen_video_create(display); + ASSERT_NE(video, nullptr); + + wl_display_destroy(display); +} + +class VideoCompositor : public MockCompositor, public ::testing::Test +{ +public: + VideoCompositor() : + MockCompositor(&VideoCompositor::SetUpComp, this) + { + /* We are only interested in test results. Let's silence libds log. */ + ds_log_init(DS_SILENT, nullptr); + + this->video = nullptr; + } + + static void SetUpComp(void *data) + { + VideoCompositor *comp = static_cast(data); + + comp->video = ds_tizen_video_create(comp->GetWlDisplay()); + ASSERT_NE(comp->video, nullptr); + } + + struct ds_tizen_video *video; +}; + +static void handle_global(void *data, struct wl_registry *registry, + uint32_t name, const char *interface, uint32_t version); +static void handle_global_remove(void *data, struct wl_registry *registry, + uint32_t name); + +static const struct wl_registry_listener registry_listener = { + .global = handle_global, + .global_remove = handle_global_remove, +}; + +class MockVideoClient : public MockClient +{ +public: + MockVideoClient() : MockClient(®istry_listener, this) + { + EXPECT_NE(this->compositor, nullptr); + EXPECT_NE(this->video, nullptr); + + surface = wl_compositor_create_surface(this->compositor); + EXPECT_NE(this->surface, nullptr); + } + + ~MockVideoClient() + { + wl_surface_destroy(this->surface); + tizen_video_destroy(this->video); + wl_compositor_destroy(this->compositor); + } + + struct wl_compositor *compositor; + struct tizen_video *video; + struct wl_surface *surface; +}; + +static void +handle_global(void *data, struct wl_registry *registry, + uint32_t name, const char *interface, uint32_t version) +{ + MockVideoClient *client = static_cast(data); + + if (strcmp(interface, "wl_compositor") == 0) { + client->compositor = static_cast( + wl_registry_bind(registry, name, &wl_compositor_interface, 4)); + } else if (strcmp(interface, "tizen_video") == 0) { + client->video = static_cast( + wl_registry_bind(registry, name, &tizen_video_interface, 1)); + } +} + +static void +handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) +{ +} + +static void +video_handle_format(void *data, struct tizen_video *video, uint32_t format) +{ + std::vector *ret_formats = + static_cast*>(data); + + ret_formats->push_back(format); +} + +static const struct +tizen_video_listener video_listener = { + .format = video_handle_format, +}; + +TEST_F(VideoCompositor, AddFormats) +{ + std::vector supported_format { + DRM_FORMAT_XRGB8888, DRM_FORMAT_ARGB8888, + }; + + for (uint32_t format : supported_format) + ds_tizen_video_add_format(this->video, format); + + std::vector ret_formats; + MockVideoClient *client = new MockVideoClient(); + tizen_video_add_listener(client->video, &video_listener, + static_cast(&ret_formats)); + client->RoundTrip(); + + ASSERT_EQ(supported_format.size(), ret_formats.size()); + + bool found; + for (uint32_t supported_format : supported_format) { + found = false; + for (uint32_t ret_format : ret_formats) { + if (supported_format == ret_format) { + found = true; + break; + } + } + ASSERT_EQ(found, true); + } + + delete client; +} + +TEST_F(VideoCompositor, CreateObject) +{ + MockVideoClient *client = new MockVideoClient(); + + struct tizen_video_object *object = tizen_video_get_object(client->video, + client->surface); + client->ExpectNoError(); + + tizen_video_object_destroy(object); + delete client; +} + +struct size_hint { + struct { int32_t width, height; } min; + struct { int32_t width, height; } max; + int32_t prefer_align; +}; + +static void +video_object_handle_size(void *data, struct tizen_video_object *object, + int32_t min_w, int32_t min_h, int32_t max_w, int32_t max_h, + int32_t prefer_align) +{ + size_hint *ret_size = static_cast(data); + ret_size->min.width = min_w; + ret_size->min.height = min_h; + ret_size->max.width = max_w; + ret_size->max.height = max_h; + ret_size->prefer_align = prefer_align; +} + +static const struct +tizen_video_object_listener object_size_hint_listener = { + .attribute = NULL, + .size = video_object_handle_size, +}; + +TEST_F(VideoCompositor, SetSizeHint) +{ + size_hint hint = { 100, 50, 1000, 500, 777 }; + + ds_tizen_video_set_size_hint(this->video, + hint.min.width, hint.min.height, + hint.max.width, hint.max.height, + hint.prefer_align); + + MockVideoClient *client = new MockVideoClient(); + + struct tizen_video_object *object = + tizen_video_get_object(client->video, client->surface); + + size_hint ret_hint; + tizen_video_object_add_listener(object, &object_size_hint_listener, + static_cast(&ret_hint)); + client->RoundTrip(); + + ASSERT_EQ(hint.min.width, ret_hint.min.width); + ASSERT_EQ(hint.min.height, ret_hint.min.height); + ASSERT_EQ(hint.max.width, ret_hint.max.width); + ASSERT_EQ(hint.max.height, ret_hint.max.height); + ASSERT_EQ(hint.prefer_align, ret_hint.prefer_align); + + tizen_video_object_destroy(object); + delete client; +} + +struct property { + std::string name; + uint32_t value; + + property(std::string name, uint32_t value) : name(name), value(value) {} +}; + +static void +video_object_handle_attribute(void *data, struct tizen_video_object *object, + const char *name, uint32_t value) +{ + std::vector *ret_properties = + static_cast*>(data); + + ret_properties->push_back(new property(std::string(name), value)); +} + +static void +video_object_dummy_handle_size(void *data, struct tizen_video_object *object, + int32_t min_w, int32_t min_h, int32_t max_w, int32_t max_h, + int32_t prefer_align) +{ + // This left blank intentionally. +} + +static const struct +tizen_video_object_listener object_attribute_listener = { + .attribute = video_object_handle_attribute, + .size = video_object_dummy_handle_size, +}; + +TEST_F(VideoCompositor, AddProperties) +{ + std::vector properties { + { "property0", 123 }, + { "property1", 987 }, + { "property2", 345 }, + { "property3", 777 }, + }; + + for (struct property prop : properties) + ds_tizen_video_add_property(this->video, prop.name.c_str(), prop.value); + + MockVideoClient *client = new MockVideoClient(); + + struct tizen_video_object *object = + tizen_video_get_object(client->video, client->surface); + + std::vector ret_properties; + tizen_video_object_add_listener(object, &object_attribute_listener, + static_cast(&ret_properties)); + client->RoundTrip(); + + ASSERT_EQ(properties.size(), ret_properties.size()); + + bool found; + for (property prop : properties) { + found = false; + for (property *ret_prop : ret_properties) { + if (prop.name == ret_prop->name && + prop.value == ret_prop->value) { + found = true; + break; + } + } + ASSERT_EQ(found, true); + } + + for (property *prop : ret_properties) + delete prop; + ret_properties.clear(); + tizen_video_object_destroy(object); + delete client; +}