**************************************************************************/
#include "gtest/gtest.h"
+extern "C" {
#include "tdm.h"
+#include "tbm_bufmgr.h"
+#include "tbm_drm_helper.h"
+}
class TDMInit : public ::testing::Test {
protected:
void SetUp(void)
{
setenv("TDM_DLOG", "1", 1);
- setenv("XDG_RUNTIME_DIR", ".", 1);
+ setenv("XDG_RUNTIME_DIR", "/tmp", 1);
setenv("TBM_DLOG", "1", 1);
+ setenv("TBM_DISPLAY_SERVER", "1", 1);
}
void TearDown(void)
{
+ unsetenv("TDM_DLOG");
+ unsetenv("XDG_RUNTIME_DIR");
+ unsetenv("TBM_DLOG");
+ unsetenv("TBM_DISPLAY_SERVER");
}
};
class TDMDefault : public ::testing::Test {
protected:
tdm_display *dpy = NULL;
+ tbm_bufmgr tbm_bufmgr = NULL;
void SetUp(void)
{
setenv("TDM_DLOG", "1", 1);
- setenv("XDG_RUNTIME_DIR", ".", 1);
+ setenv("XDG_RUNTIME_DIR", "/tmp", 1);
setenv("TBM_DLOG", "1", 1);
+ setenv("TBM_DISPLAY_SERVER", "1", 1);
+ tbm_bufmgr = tbm_bufmgr_init(-1);
+ ASSERT_FALSE(tbm_bufmgr == NULL);
tdm_error error = TDM_ERROR_NONE;
dpy = tdm_display_init(&error);
ASSERT_TRUE(error == TDM_ERROR_NONE);
void TearDown(void)
{
tdm_display_deinit(dpy);
+ tbm_bufmgr_deinit(tbm_bufmgr);
+ tbm_bufmgr = NULL;
dpy = NULL;
+ unsetenv("TDM_DLOG");
+ unsetenv("XDG_RUNTIME_DIR");
+ unsetenv("TBM_DLOG");
+ unsetenv("TBM_DISPLAY_SERVER");
}
};
-TEST_F(TDMInit, DisplayInitDeinitSuccessful)
+TEST_F(TDMInit, DisplayInitDeinitSuccessfulWithoutTBM)
+{
+ tdm_error error = TDM_ERROR_NONE;
+ tdm_display *dpy = tdm_display_init(&error);
+ ASSERT_TRUE(error == TDM_ERROR_NONE);
+ ASSERT_FALSE(dpy == NULL);
+ tdm_display_deinit(dpy);
+ dpy = NULL;
+ ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1);
+ ASSERT_TRUE(tbm_drm_helper_get_fd() == -1);
+}
+
+TEST_F(TDMInit, DisplayInitFewTimesSuccessfulWithTBM)
+{
+ tdm_error error = TDM_ERROR_NONE;
+ tdm_display *dpy[20] = {NULL};
+ tbm_bufmgr tbm_bufmgr = NULL;
+ tbm_bufmgr = tbm_bufmgr_init(-1);
+ ASSERT_FALSE(tbm_bufmgr == NULL);
+ for (int i = 0; i < 20; i++) {
+ dpy[i] = tdm_display_init(&error);
+ EXPECT_TRUE(error == TDM_ERROR_NONE);
+ EXPECT_FALSE(dpy[i] == NULL);
+ EXPECT_EQ(dpy[0], dpy[i]);
+ }
+ for (int i = 19; i > 0; i--) {
+ tdm_display_deinit(dpy[i]);
+ EXPECT_FALSE(tbm_drm_helper_get_master_fd() == -1);
+ EXPECT_FALSE(tbm_drm_helper_get_fd() == -1);
+ }
+ tdm_display_deinit(dpy[0]);
+ tbm_bufmgr_deinit(tbm_bufmgr);
+ tbm_bufmgr = NULL;
+ ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1);
+ ASSERT_TRUE(tbm_drm_helper_get_fd() == -1);
+}
+
+TEST_F(TDMInit, DisplayInitDeinitSuccessfulWithTBM)
{
+ tbm_bufmgr tbm_bufmgr = NULL;
+ tbm_bufmgr = tbm_bufmgr_init(-1);
+ ASSERT_FALSE(tbm_bufmgr == NULL);
tdm_error error = TDM_ERROR_NONE;
tdm_display *dpy = tdm_display_init(&error);
ASSERT_TRUE(error == TDM_ERROR_NONE);
ASSERT_FALSE(dpy == NULL);
tdm_display_deinit(dpy);
dpy = NULL;
+ tbm_bufmgr_deinit(tbm_bufmgr);
+ tbm_bufmgr = NULL;
+ ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1);
+ ASSERT_TRUE(tbm_drm_helper_get_fd() == -1);
}
-TEST_F(TDMInit, DisplayInitDeinitSuccessfulNullError)
+TEST_F(TDMInit, DisplayInitDeinitSuccessfulNullErrorWithTBM)
{
+ tbm_bufmgr tbm_bufmgr = NULL;
+ tbm_bufmgr = tbm_bufmgr_init(-1);
+ ASSERT_FALSE(tbm_bufmgr == NULL);
tdm_error error = TDM_ERROR_NONE;
tdm_display *dpy = tdm_display_init(NULL);
ASSERT_TRUE(error == TDM_ERROR_NONE);
ASSERT_FALSE(dpy == NULL);
tdm_display_deinit(dpy);
dpy = NULL;
+ tbm_bufmgr_deinit(tbm_bufmgr);
+ tbm_bufmgr = NULL;
+ ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1);
+ ASSERT_TRUE(tbm_drm_helper_get_fd() == -1);
}
-TEST_F(TDMInit, DisplayInitDeinitSuccessfulFewTimes)
+TEST_F(TDMInit, DisplayInitDeinitSuccessfulFewTimesWithTBM)
{
for (int i = 0; i < 20; ++i) {
+ tbm_bufmgr tbm_bufmgr = NULL;
+ tbm_bufmgr = tbm_bufmgr_init(-1);
+ ASSERT_FALSE(tbm_bufmgr == NULL);
tdm_error error = TDM_ERROR_NONE;
tdm_display *dpy = tdm_display_init(&error);
ASSERT_TRUE(error == TDM_ERROR_NONE);
ASSERT_FALSE(dpy == NULL);
tdm_display_deinit(dpy);
dpy = NULL;
+ tbm_bufmgr_deinit(tbm_bufmgr);
+ tbm_bufmgr = NULL;
}
+ ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1);
+ ASSERT_TRUE(tbm_drm_helper_get_fd() == -1);
}
TEST_F(TDMInit, DisplayDeinitSuccessfulNullDpy)
tdm_display_deinit(NULL);
tdm_display_deinit(dpy);
dpy = NULL;
+ ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1);
+ ASSERT_TRUE(tbm_drm_helper_get_fd() == -1);
}
TEST_F(TDMInit, DisplayDeinitDeathWrongDpy)
tdm_display *dpy = tdm_display_init(&error);
ASSERT_TRUE(error == TDM_ERROR_NONE);
ASSERT_FALSE(dpy == NULL);
- tdm_display *wrong_dpy = 0xBEAF;
- EXPECT_DEATH(tdm_display_deinit(wrong_dpy), "");
+ EXPECT_EXIT({tdm_display *wrong_dpy = 0xBEAF;
+ tdm_display_deinit(wrong_dpy);
+ exit(0); }, ::testing::ExitedWithCode(0), "");
tdm_display_deinit(dpy);
dpy = NULL;
+ ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1);
+ ASSERT_TRUE(tbm_drm_helper_get_fd() == -1);
}
TEST_F(TDMDefault, DisplayUpdateSuccessful)
ASSERT_TRUE(tdm_display_update(dpy) == TDM_ERROR_NONE);
}
+TEST_F(TDMDefault, DisplayUpdateFailWrongDpy)
+{
+ ASSERT_EXIT({tdm_display *wrong_dpy = 0xBEAF;
+ tdm_display_update(wrong_dpy);
+ exit(0);}, ::testing::ExitedWithCode(0), "");
+}
+
TEST_F(TDMDefault, DisplayUpdateFailNullDpy)
{
ASSERT_FALSE(tdm_display_update(NULL) == TDM_ERROR_NONE);
ASSERT_FALSE(tdm_display_get_fd(NULL, &fd) == TDM_ERROR_NONE);
}
+TEST_F(TDMDefault, DisplayGetFDFailWrongDpy)
+{
+ ASSERT_EXIT({tdm_display *wrong_dpy = 0xBEAF; int fd = -42;
+ tdm_display_get_fd(wrong_dpy, &fd);
+ exit(0);}, ::testing::ExitedWithCode(0), "");
+}
+
TEST_F(TDMDefault, DISABLED_DisplayHandleEventsSuccessful)
{
/* TODO Generate events*/
**************************************************************************/
#include "gtest/gtest.h"
-#include "tdm.h"
#include "ut_common.h"
+#include <climits>
+extern "C" {
+#include "tdm.h"
+#include "tbm_bufmgr.h"
+#include "tbm_drm_helper.h"
+}
class TDMOutput : public ::testing::Test {
protected:
tdm_display *dpy = NULL;
int output_count = -42;
bool has_output = false;
+ tbm_bufmgr tbm_bufmgr = NULL;
+ static unsigned int handle_call;
+ static void tdm_output_change_handler_test_func(tdm_output *output,
+ tdm_output_change_type type,
+ tdm_value value,
+ void *u_data)
+ {
+ if ( ((int) u_data) < -100) {
+ TDMOutput::handle_call++;
+ }
+ }
void SetUp(void)
{
setenv("TDM_DLOG", "1", 1);
setenv("XDG_RUNTIME_DIR", ".", 1);
setenv("TBM_DLOG", "1", 1);
+ setenv("TBM_DISPLAY_SERVER", "1", 1);
+ tbm_bufmgr = tbm_bufmgr_init(-1);
+ ASSERT_FALSE(tbm_bufmgr == NULL);
tdm_error error = TDM_ERROR_NONE;
dpy = tdm_display_init(&error);
ASSERT_TRUE(error == TDM_ERROR_NONE);
#endif
if (output_count > 0)
has_output = true;
+ handle_call = 0;
}
void TearDown(void)
{
tdm_display_deinit(dpy);
dpy = NULL;
+ tbm_bufmgr_deinit(tbm_bufmgr);
+ tbm_bufmgr = NULL;
+ unsetenv("TDM_DLOG");
+ unsetenv("XDG_RUNTIME_DIR");
+ unsetenv("TBM_DLOG");
+ unsetenv("TBM_DISPLAY_SERVER");
}
};
+unsigned int TDMOutput::handle_call = 0;
+
TEST_F(TDMOutput, DisplayGetOutputSuccessful)
{
- CHECK_FLAG(has_output);
+ SKIP_FLAG(has_output);
for (int i = 0; i < output_count; i++) {
tdm_error error = TDM_ERROR_NONE;
ASSERT_FALSE(NULL == tdm_display_get_output(dpy, i, &error));
ASSERT_TRUE(TDM_ERROR_NONE == error);
}
}
+
+TEST_F(TDMOutput, DisplayGetOutputSuccessfulWrongIndex)
+{
+ SKIP_FLAG(has_output);
+ tdm_error error = TDM_ERROR_NONE;
+ ASSERT_TRUE(NULL == tdm_display_get_output(dpy, -1, &error));
+ ASSERT_TRUE(TDM_ERROR_NONE == error);
+}
+
+TEST_F(TDMOutput, DisplayGetOutputSuccessfulBigIndex)
+{
+ SKIP_FLAG(has_output);
+ tdm_error error = TDM_ERROR_NONE;
+ ASSERT_TRUE(NULL == tdm_display_get_output(dpy, INT_MAX, &error));
+ ASSERT_TRUE(TDM_ERROR_NONE == error);
+}
+
+TEST_F(TDMOutput, DisplayGetOutputSuccessfulSmallIndex)
+{
+ SKIP_FLAG(has_output);
+ tdm_error error = TDM_ERROR_NONE;
+ ASSERT_TRUE(NULL == tdm_display_get_output(dpy, INT_MIN, &error));
+ ASSERT_TRUE(TDM_ERROR_NONE == error);
+}
+
+TEST_F(TDMOutput, DisplayGetOutputSuccessfulErrorNull)
+{
+ SKIP_FLAG(has_output);
+ ASSERT_FALSE(NULL == tdm_display_get_output(dpy, 0, NULL));
+}
+
+TEST_F(TDMOutput, DisplayOutputGetCapabilitiesSuccessful)
+{
+ SKIP_FLAG(has_output);
+ for (int i = 0; i < output_count; i++) {
+ tdm_error error = TDM_ERROR_NONE;
+ tdm_output_capability capabilities = -42;
+ tdm_output * output = tdm_display_get_output(dpy, i, &error);
+ ASSERT_FALSE(NULL == output);
+ ASSERT_TRUE(TDM_ERROR_NONE == error);
+ ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_capabilities(output, &capabilities));
+ ASSERT_FALSE(-42 == capabilities);
+ }
+}
+
+TEST_F(TDMOutput, DisplayOutputGetCapabilitiesFailAllNull)
+{
+ SKIP_FLAG(has_output);
+ ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_capabilities(NULL, NULL));
+}
+
+TEST_F(TDMOutput, DisplayOutputGetCapabilitiesFailOnlyOutput)
+{
+ SKIP_FLAG(has_output);
+ for (int i = 0; i < output_count; i++) {
+ tdm_error error = TDM_ERROR_NONE;
+ tdm_output * output = tdm_display_get_output(dpy, i, &error);
+ ASSERT_FALSE(NULL == output);
+ ASSERT_TRUE(TDM_ERROR_NONE == error);
+ ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_capabilities(output, NULL));
+ }
+}
+
+TEST_F(TDMOutput, OutputGetModelInfoSuccessful)
+{
+ SKIP_FLAG(has_output);
+ for (int i = 0; i < output_count; i++) {
+ tdm_error error = TDM_ERROR_NONE;
+ const char * maker = NULL, * model = NULL, * name = NULL;
+ tdm_output * output = tdm_display_get_output(dpy, i, &error);
+ ASSERT_FALSE(NULL == output);
+ ASSERT_TRUE(TDM_ERROR_NONE == error);
+ ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_model_info(output, &maker, &model, &name));
+ ASSERT_FALSE(NULL == maker);
+ ASSERT_FALSE(NULL == model);
+ ASSERT_FALSE(NULL == name);
+ }
+}
+
+TEST_F(TDMOutput, OutputGetModelInfoFailAllNull)
+{
+ SKIP_FLAG(has_output);
+ ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_model_info(NULL, NULL, NULL, NULL));
+}
+
+TEST_F(TDMOutput, OutputGetModelInfoSuccessfulOnlyOutput)
+{
+ SKIP_FLAG(has_output);
+ for (int i = 0; i < output_count; i++) {
+ tdm_error error = TDM_ERROR_NONE;
+ tdm_output * output = tdm_display_get_output(dpy, i, &error);
+ ASSERT_FALSE(NULL == output);
+ ASSERT_TRUE(TDM_ERROR_NONE == error);
+ ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_model_info(output, NULL, NULL, NULL));
+ }
+}
+
+TEST_F(TDMOutput, OutputGetConnStatusSuccessful)
+{
+ SKIP_FLAG(has_output);
+ for (int i = 0; i < output_count; i++) {
+ tdm_error error = TDM_ERROR_NONE;
+ tdm_output_conn_status status = -42;
+ tdm_output * output = tdm_display_get_output(dpy, i, &error);
+ ASSERT_FALSE(NULL == output);
+ ASSERT_TRUE(TDM_ERROR_NONE == error);
+ ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, &status));
+ ASSERT_FALSE(-42 == status);
+ }
+}
+
+TEST_F(TDMOutput, OutputGetConnStatusFailAllNull)
+{
+ SKIP_FLAG(has_output);
+ ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_conn_status(NULL, NULL));
+}
+
+TEST_F(TDMOutput, OutputGetConnStatusFailOnlyOutput)
+{
+ SKIP_FLAG(has_output);
+ for (int i = 0; i < output_count; i++) {
+ tdm_error error = TDM_ERROR_NONE;
+ tdm_output * output = tdm_display_get_output(dpy, i, &error);
+ ASSERT_FALSE(NULL == output);
+ ASSERT_TRUE(TDM_ERROR_NONE == error);
+ ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, NULL));
+ }
+}
+
+TEST_F(TDMOutput, OutputSetDPMSSuccessful)
+{
+ SKIP_FLAG(has_output);
+ for (int i = 0; i < output_count; i++) {
+ tdm_error error = TDM_ERROR_NONE;
+ tdm_output * output = tdm_display_get_output(dpy, i, &error);
+ ASSERT_FALSE(NULL == output);
+ ASSERT_TRUE(TDM_ERROR_NONE == error);
+ ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
+ ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_STANDBY));
+ ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_SUSPEND));
+ ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
+ }
+}
+
+TEST_F(TDMOutput, OutputAddChangeHandlerSuccessful)
+{
+ SKIP_FLAG(has_output);
+ for (int i = 0; i < output_count; i++) {
+ tdm_error error = TDM_ERROR_NONE;
+ tdm_output * output = tdm_display_get_output(dpy, i, &error);
+ ASSERT_FALSE(NULL == output);
+ ASSERT_TRUE(TDM_ERROR_NONE == error);
+ ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output,
+ tdm_output_change_handler_test_func,
+ -101));
+ ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
+ ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
+ ASSERT_GT(handle_call, 0);
+ }
+}
+
+TEST_F(TDMOutput, OutputAddChangeHandlerSuccessfulFewFuncs)
+{
+ SKIP_FLAG(has_output);
+ for (int i = 0; i < output_count; i++) {
+ tdm_error error = TDM_ERROR_NONE;
+ tdm_output * output = tdm_display_get_output(dpy, i, &error);
+ ASSERT_FALSE(NULL == output);
+ ASSERT_TRUE(TDM_ERROR_NONE == error);
+ for (int k = 0; k < 20; k++) {
+ ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output,
+ tdm_output_change_handler_test_func,
+ (-101-k)));
+ }
+ ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
+ ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
+ ASSERT_GT(handle_call, 20);
+ }
+}
+
+
+TEST_F(TDMOutput, OutputAddChangeHandlerFailAllNull)
+{
+ SKIP_FLAG(has_output);
+ ASSERT_FALSE(TDM_ERROR_NONE ==tdm_output_add_change_handler(NULL, NULL, NULL));
+}
+
+TEST_F(TDMOutput, OutputAddChangeHandlerFailOnlyOutput)
+{
+ SKIP_FLAG(has_output);
+ for (int i = 0; i < output_count; i++) {
+ tdm_error error = TDM_ERROR_NONE;
+ tdm_output * output = tdm_display_get_output(dpy, i, &error);
+ ASSERT_FALSE(NULL == output);
+ ASSERT_TRUE(TDM_ERROR_NONE == error);
+ ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_add_change_handler(output, NULL, NULL));
+ }
+}
+
+TEST_F(TDMOutput, OutputAddChangeHandlerFailWrongOutput)
+{
+ SKIP_FLAG(has_output);
+ ASSERT_EXIT({tdm_output *output = 0xBEAF;
+ tdm_output_add_change_handler(output,
+ tdm_output_change_handler_test_func,
+ -101);
+ exit(0);}, ::testing::ExitedWithCode(0), "");
+}
+
+TEST_F(TDMOutput, OutputRemoveChangeHandlerSuccessful)
+{
+ for (int i = 0; i < output_count; i++) {
+ tdm_error error = TDM_ERROR_NONE;
+ tdm_output * output = tdm_display_get_output(dpy, i, &error);
+ ASSERT_FALSE(NULL == output);
+ ASSERT_TRUE(TDM_ERROR_NONE == error);
+ ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output,
+ tdm_output_change_handler_test_func,
+ -101));
+ ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
+ ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
+ ASSERT_GT(handle_call, 0);
+ handle_call = 0;
+ tdm_output_remove_change_handler(output, tdm_output_change_handler_test_func, -101);
+ ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
+ ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
+ ASSERT_EQ(handle_call, 0);
+ }
+}
+
+TEST_F(TDMOutput, OutputRemoveChangeHandlerSuccessfulFewFuncs)
+{
+ for (int i = 0; i < output_count; i++) {
+ tdm_error error = TDM_ERROR_NONE;
+ tdm_output * output = tdm_display_get_output(dpy, i, &error);
+ ASSERT_FALSE(NULL == output);
+ ASSERT_TRUE(TDM_ERROR_NONE == error);
+ for (int k = 0; k < 20; k++) {
+ ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output,
+ tdm_output_change_handler_test_func,
+ (-101-k)));
+ }
+ ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
+ ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
+ ASSERT_GT(handle_call, 20);
+ handle_call = 0;
+ for (int k = 0; k < 20; k++) {
+ tdm_output_remove_change_handler(output, tdm_output_change_handler_test_func, (-101-k));
+ }
+ ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
+ ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
+ ASSERT_EQ(handle_call, 0);
+ }
+}