From dff2150855044a9f557222e6117221488a7ff4f2 Mon Sep 17 00:00:00 2001 From: Roman Marchenko Date: Wed, 8 Nov 2017 10:36:45 +0200 Subject: [PATCH] utests: covered the API funcs from the tbm_surface.h file Change-Id: I51583aafcb3c1f0c074b38e6a6e565ea0ed8aed4 Signed-off-by: Roman Marchenko --- utests/Makefile.am | 3 +- utests/ut.cpp | 45 ++++++++- utests/ut.h | 22 +++++ utests/ut_tbm_surface.cpp | 228 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 296 insertions(+), 2 deletions(-) create mode 100644 utests/ut_tbm_surface.cpp diff --git a/utests/Makefile.am b/utests/Makefile.am index d042b1f..8e67f5f 100644 --- a/utests/Makefile.am +++ b/utests/Makefile.am @@ -3,7 +3,8 @@ bin_PROGRAMS = tbm-utests tbm_utests_SOURCES = \ ut.cpp \ ut_main.cpp \ - ut_tbm_bufmgr.cpp + ut_tbm_bufmgr.cpp \ + ut_tbm_surface.cpp tbm_utests_CXXFLAGS = \ ${CXXFLAGS} \ diff --git a/utests/ut.cpp b/utests/ut.cpp index e2036ba..4effef1 100644 --- a/utests/ut.cpp +++ b/utests/ut.cpp @@ -8,9 +8,15 @@ void UtInit::UtBufmgrInit() ASSERT_TRUE(bufmgr != NULL); } +void UtInit::SetUp() +{ + bufmgr = NULL; +} + void UtInit::TearDown() { - tbm_bufmgr_deinit(bufmgr); + if (bufmgr) + tbm_bufmgr_deinit(bufmgr); } void UtBufmgrInit::SetUp() @@ -55,3 +61,40 @@ void ut_set_default_tbm_env() setenv("XDG_RUNTIME_DIR", "/run", 1); setenv("TBM_DISPLAY_SERVER", "1", 1); } + +int UtSurfaceInit::width = 720; +int UtSurfaceInit::height = 1024; +tbm_format UtSurfaceInit::format; +int UtSurfaceInit::num_formats; +tbm_format *UtSurfaceInit::formats; + +void UtSurfaceInit::SetUpTestCase() +{ + tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE; + + ut_set_default_tbm_env(); + + result = tbm_surface_query_formats(&formats, &num_formats); + ASSERT_EQ(TBM_SURFACE_ERROR_NONE, result); + + for (int i = 0; i < num_formats; i++) + if (formats[i] == TBM_FORMAT_ARGB8888) + format = TBM_FORMAT_ARGB8888; + + /* if TBM_FORMAT_ARGB8888 isn't supported take the first */ + if (format == 0) + format = formats[0]; +} + +void UtSurfaceInit::SetUp() +{ + surface = tbm_surface_create(width, height, format); + ASSERT_TRUE(surface != NULL); +} + +void UtSurfaceInit::TearDown() +{ + if (surface) + tbm_surface_destroy(surface); +} + diff --git a/utests/ut.h b/utests/ut.h index 4a078f4..07486e7 100644 --- a/utests/ut.h +++ b/utests/ut.h @@ -3,6 +3,7 @@ #include "gtest/gtest.h" #include +#include /* The test fixture class, which deinitializes bufmgr after the test is finished. To init bufmgr you need to call UtBufmgrInit() func. Do not call tbm_bufmgr_init() @@ -10,6 +11,7 @@ directly because deinitialization won't be called if test is failed */ class UtInit : public ::testing::Test { protected: + void SetUp(); void TearDown(); public: void UtBufmgrInit(); @@ -45,4 +47,24 @@ public: void ut_set_default_tbm_env(); +/* test fixture class, which initializes bufmgr and allocate the tbm surface before the tests and + * deinitializes bufmgr after tests which use the test fixture with this class */ +class UtSurfaceInit : public ::testing::Test +{ +protected: + static void SetUpTestCase(); + void SetUp(); + void TearDown(); +public: + static int width; + static int height; + static tbm_format format; + + static int num_formats; + static tbm_format *formats; + + tbm_surface_h surface; +}; + + #endif // UT_H diff --git a/utests/ut_tbm_surface.cpp b/utests/ut_tbm_surface.cpp new file mode 100644 index 0000000..64366c7 --- /dev/null +++ b/utests/ut_tbm_surface.cpp @@ -0,0 +1,228 @@ +#include +#include + +#include +#include +#include "ut.h" + +TEST_F(UtInit, SurfaceQueryFormatsFailNull) +{ + int num = 0; + tbm_format *formats = NULL; + tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE; + + ut_set_default_tbm_env(); + + result = tbm_surface_query_formats(&formats, NULL); + ASSERT_EQ(TBM_SURFACE_ERROR_INVALID_PARAMETER, result); + + result = tbm_surface_query_formats(NULL, &num); + ASSERT_EQ(TBM_SURFACE_ERROR_INVALID_PARAMETER, result); +} + +TEST_F(UtInit, SurfaceQueryFormatSuccess) +{ + int num = 0; + tbm_format *formats = NULL; + tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE; + + ut_set_default_tbm_env(); + + result = tbm_surface_query_formats(&formats, &num); + ASSERT_EQ(TBM_SURFACE_ERROR_NONE, result); + ASSERT_NE(0, num); + ASSERT_NE(NULL, formats); + for (int i = 0; i < num; i++) + ASSERT_NE(0, formats[i]); + +} + +TEST_F(UtInit, SurfaceCeateFailInvalidGeometry) +{ + tbm_surface_h surface = NULL; + + ut_set_default_tbm_env(); + + surface = tbm_surface_create(-1, 1024, TBM_FORMAT_ARGB8888); + ASSERT_EQ(NULL, surface); // Expected Value: NULL + + surface = tbm_surface_create(720, -1, TBM_FORMAT_ARGB8888); + ASSERT_EQ(NULL, surface); + + surface = tbm_surface_create(720, 1024, 0); + ASSERT_EQ(NULL, surface); +} + +TEST_F(UtInit, SurfaceCeateSuccess) +{ + tbm_surface_h surface = NULL; + int num = 0; + tbm_format *formats = NULL; + tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE; + + ut_set_default_tbm_env(); + + result = tbm_surface_query_formats(&formats, &num); + ASSERT_EQ(TBM_SURFACE_ERROR_NONE, result); + + for (int i = 0; i < num; i++) { + surface = tbm_surface_create(720, 1024, formats[i]); + ASSERT_NE(NULL, surface); + result = tbm_surface_destroy(surface); + ASSERT_EQ(TBM_SURFACE_ERROR_NONE, result); + } +} + +TEST_F(UtSurfaceInit, SurfaceGetFormatFailInvalideInput) +{ + tbm_surface_h invalide_surface = (tbm_surface_h)1; + tbm_format fmt = tbm_surface_get_format(invalide_surface); + ASSERT_EQ(0, fmt); +} + +TEST_F(UtSurfaceInit, SurfaceGetFormatFailNull) +{ + tbm_format fmt = tbm_surface_get_format(NULL); + ASSERT_EQ(0, fmt); +} + +TEST_F(UtSurfaceInit, SurfaceGetFormatSuccess) +{ + tbm_format fmt = tbm_surface_get_format(surface); + ASSERT_EQ(this->format, fmt); +} + +TEST_F(UtSurfaceInit, SurfaceGetWidthFailInvalideInput) +{ + tbm_surface_h invalide_surface = (tbm_surface_h)1; + int width = tbm_surface_get_width(invalide_surface); + ASSERT_EQ(0, width); +} + +TEST_F(UtSurfaceInit, SurfaceGetWidthFailNull) +{ + int width = tbm_surface_get_width(NULL); + ASSERT_EQ(TBM_SURFACE_ERROR_INVALID_PARAMETER, width); +} + +TEST_F(UtSurfaceInit, SurfaceGetWidthSuccess) +{ + int width = tbm_surface_get_width(surface); + ASSERT_EQ(this->width, width); +} + +TEST_F(UtSurfaceInit, SurfaceGetHeightFailInvalideInput) +{ + tbm_surface_h invalide_surface = (tbm_surface_h)1; + int height = tbm_surface_get_height(invalide_surface); + ASSERT_EQ(0, height); +} + +TEST_F(UtSurfaceInit, SurfaceGetHeightFailNull) +{ + int height = tbm_surface_get_height(NULL); + ASSERT_EQ(TBM_SURFACE_ERROR_INVALID_PARAMETER, height); +} + +TEST_F(UtSurfaceInit, SurfaceGetHeightSuccess) +{ + int height = tbm_surface_get_height(surface); + ASSERT_EQ(this->height, height); +} + +TEST_F(UtSurfaceInit, SurfaceGetInfoInvalideInput) +{ + tbm_surface_h invalide_surface = (tbm_surface_h)1; + tbm_surface_info_s info; + tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE; + + result = tbm_surface_get_info(invalide_surface, &info); + ASSERT_EQ(TBM_SURFACE_ERROR_INVALID_OPERATION, result); +} + +TEST_F(UtSurfaceInit, SurfaceGetInfoFailNull) +{ + tbm_surface_info_s info; + tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE; + + result = tbm_surface_get_info(surface, NULL); + ASSERT_EQ(TBM_SURFACE_ERROR_INVALID_PARAMETER, result); + + result = tbm_surface_get_info(NULL, &info); + ASSERT_EQ(TBM_SURFACE_ERROR_INVALID_PARAMETER, result); + + result = tbm_surface_get_info(NULL, NULL); + ASSERT_EQ(TBM_SURFACE_ERROR_INVALID_PARAMETER, result); +} + +TEST_F(UtSurfaceInit, SurfaceGetInfoSuccess) +{ + tbm_surface_info_s info; + tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE; + + result = tbm_surface_get_info(surface, &info); + ASSERT_EQ(TBM_SURFACE_ERROR_NONE, result); + ASSERT_EQ(this->format, info.format); + ASSERT_EQ(this->height, info.height); + ASSERT_EQ(this->width, info.width); + ASSERT_GT(info.num_planes, 0); + ASSERT_GT(info.bpp, 0); + ASSERT_GT(info.size, 0); +} + +TEST_F(UtSurfaceInit, SurfaceMapFailInvalideInput) +{ + tbm_surface_info_s info; + tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE; + tbm_surface_h invalide_surface = (tbm_surface_h)1; + + result = tbm_surface_map(invalide_surface, 0, &info); + ASSERT_EQ(TBM_SURFACE_ERROR_INVALID_OPERATION, result); +} + +TEST_F(UtSurfaceInit, SurfaceMapFailNull) +{ + tbm_surface_info_s info; + tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE; + + result = tbm_surface_map(surface, 0, NULL); + ASSERT_EQ(TBM_SURFACE_ERROR_INVALID_PARAMETER, result); + + result = tbm_surface_map(NULL, 0, &info); + ASSERT_EQ(TBM_SURFACE_ERROR_INVALID_PARAMETER, result); +} + +TEST_F(UtSurfaceInit, SurfaceMapSuccess) +{ + tbm_surface_info_s info; + tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE; + + result = tbm_surface_map(surface, 0, &info); + ASSERT_EQ(TBM_SURFACE_ERROR_NONE, result); + ASSERT_EQ(this->format, info.format); + ASSERT_EQ(this->height, info.height); + ASSERT_EQ(this->width, info.width); + ASSERT_GT(info.num_planes, 0); + ASSERT_GT(info.bpp, 0); + ASSERT_GT(info.size, 0); + + result = tbm_surface_unmap(surface); + ASSERT_EQ(TBM_SURFACE_ERROR_NONE, result); +} + +TEST_F(UtSurfaceInit, SurfaceUnmapFailInvalideInput) +{ + tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE; + tbm_surface_h invalide_surface = (tbm_surface_h)1; + result = tbm_surface_unmap(invalide_surface); + ASSERT_EQ(TBM_SURFACE_ERROR_NONE, result); +} + +TEST_F(UtSurfaceInit, SurfaceUnmapFailNull) +{ + tbm_surface_error_e result = TBM_SURFACE_ERROR_NONE; + + result = tbm_surface_unmap(NULL); + ASSERT_EQ(TBM_SURFACE_ERROR_INVALID_PARAMETER, result); +} + -- 2.7.4