mirror of
https://github.com/brl/mutter.git
synced 2024-11-22 08:00:42 -05:00
tests: Make testboxes an actual test
testboxes was a binary that did unit testing, but it wasn't integrated to the test system, so in effect, it was never run. Instead integrate it into the other mutter unit tests. This includes changing a few of meta_warning()s into g_warning()s so that the GTest framework can handle them.
This commit is contained in:
parent
8a03f1ad02
commit
92f4ffc0dd
@ -48,6 +48,8 @@ mutter_test_unit_tests_SOURCES = \
|
|||||||
tests/test-utils.c \
|
tests/test-utils.c \
|
||||||
tests/test-utils.h \
|
tests/test-utils.h \
|
||||||
tests/unit-tests.c \
|
tests/unit-tests.c \
|
||||||
|
tests/boxes-tests.c \
|
||||||
|
tests/boxes-tests.h \
|
||||||
tests/meta-backend-test.c \
|
tests/meta-backend-test.c \
|
||||||
tests/meta-backend-test.h \
|
tests/meta-backend-test.h \
|
||||||
tests/meta-monitor-manager-test.c \
|
tests/meta-monitor-manager-test.c \
|
||||||
@ -89,10 +91,3 @@ run-headless-start-test: mutter-test-headless-start-test
|
|||||||
run-tests: run-test-runner-tests run-unit-tests run-headless-start-test
|
run-tests: run-test-runner-tests run-unit-tests run-headless-start-test
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Some random test programs for bits of the code
|
|
||||||
|
|
||||||
testboxes_SOURCES = core/testboxes.c
|
|
||||||
testboxes_LDADD = $(MUTTER_LIBS) libmutter-$(LIBMUTTER_API_VERSION).la
|
|
||||||
|
|
||||||
noinst_PROGRAMS += testboxes
|
|
||||||
|
@ -437,7 +437,7 @@ merge_spanning_rects_in_region (GList *region)
|
|||||||
|
|
||||||
if (region == NULL)
|
if (region == NULL)
|
||||||
{
|
{
|
||||||
meta_warning ("Region to merge was empty! Either you have a some "
|
g_warning ("Region to merge was empty! Either you have a some "
|
||||||
"pathological STRUT list or there's a bug somewhere!\n");
|
"pathological STRUT list or there's a bug somewhere!\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -961,7 +961,7 @@ meta_rectangle_clamp_to_fit_into_region (const GList *spanning_rects,
|
|||||||
/* Clamp rect appropriately */
|
/* Clamp rect appropriately */
|
||||||
if (best_rect == NULL)
|
if (best_rect == NULL)
|
||||||
{
|
{
|
||||||
meta_warning ("No rect whose size to clamp to found!\n");
|
g_warning ("No rect whose size to clamp to found!\n");
|
||||||
|
|
||||||
/* If it doesn't fit, at least make it no bigger than it has to be */
|
/* If it doesn't fit, at least make it no bigger than it has to be */
|
||||||
if (!(fixed_directions & FIXED_DIRECTION_X))
|
if (!(fixed_directions & FIXED_DIRECTION_X))
|
||||||
@ -1024,7 +1024,9 @@ meta_rectangle_clip_to_region (const GList *spanning_rects,
|
|||||||
|
|
||||||
/* Clip rect appropriately */
|
/* Clip rect appropriately */
|
||||||
if (best_rect == NULL)
|
if (best_rect == NULL)
|
||||||
meta_warning ("No rect to clip to found!\n");
|
{
|
||||||
|
g_warning ("No rect to clip to found!\n");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Extra precaution with checking fixed direction shouldn't be needed
|
/* Extra precaution with checking fixed direction shouldn't be needed
|
||||||
@ -1120,7 +1122,9 @@ meta_rectangle_shove_into_region (const GList *spanning_rects,
|
|||||||
|
|
||||||
/* Shove rect appropriately */
|
/* Shove rect appropriately */
|
||||||
if (best_rect == NULL)
|
if (best_rect == NULL)
|
||||||
meta_warning ("No rect to shove into found!\n");
|
{
|
||||||
|
g_warning ("No rect to shove into found!\n");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Extra precaution with checking fixed direction shouldn't be needed
|
/* Extra precaution with checking fixed direction shouldn't be needed
|
||||||
|
@ -19,14 +19,17 @@
|
|||||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "boxes-private.h"
|
#include "tests/boxes-tests.h"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <X11/Xutil.h> /* Just for the definition of the various gravities */
|
#include <X11/Xutil.h>
|
||||||
#include <time.h> /* To initialize random seed */
|
#include <time.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "core/boxes-private.h"
|
||||||
|
|
||||||
#define NUM_RANDOM_RUNS 10000
|
#define NUM_RANDOM_RUNS 10000
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -111,8 +114,6 @@ test_area (void)
|
|||||||
|
|
||||||
temp = meta_rect (0, 0, 5, 7);
|
temp = meta_rect (0, 0, 5, 7);
|
||||||
g_assert (meta_rectangle_area (&temp) == 35);
|
g_assert (meta_rectangle_area (&temp) == 35);
|
||||||
|
|
||||||
printf ("%s passed.\n", G_STRFUNC);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -139,8 +140,6 @@ test_intersect (void)
|
|||||||
|
|
||||||
meta_rectangle_intersect (&b, &d, &b);
|
meta_rectangle_intersect (&b, &d, &b);
|
||||||
g_assert (meta_rectangle_equal (&b, &b_intersect_d));
|
g_assert (meta_rectangle_equal (&b, &b_intersect_d));
|
||||||
|
|
||||||
printf ("%s passed.\n", G_STRFUNC);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -158,8 +157,6 @@ test_equal (void)
|
|||||||
g_assert (!meta_rectangle_equal (&a, &d));
|
g_assert (!meta_rectangle_equal (&a, &d));
|
||||||
g_assert (!meta_rectangle_equal (&a, &e));
|
g_assert (!meta_rectangle_equal (&a, &e));
|
||||||
g_assert (!meta_rectangle_equal (&a, &f));
|
g_assert (!meta_rectangle_equal (&a, &f));
|
||||||
|
|
||||||
printf ("%s passed.\n", G_STRFUNC);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -181,8 +178,6 @@ test_overlap_funcs (void)
|
|||||||
g_assert (!meta_rectangle_overlap (&temp1, &temp2));
|
g_assert (!meta_rectangle_overlap (&temp1, &temp2));
|
||||||
g_assert (!meta_rectangle_horiz_overlap (&temp1, &temp2));
|
g_assert (!meta_rectangle_horiz_overlap (&temp1, &temp2));
|
||||||
g_assert ( meta_rectangle_vert_overlap (&temp1, &temp2));
|
g_assert ( meta_rectangle_vert_overlap (&temp1, &temp2));
|
||||||
|
|
||||||
printf ("%s passed.\n", G_STRFUNC);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -219,8 +214,6 @@ test_basic_fitting (void)
|
|||||||
g_assert (!meta_rectangle_contains_rect (&temp1, &temp3));
|
g_assert (!meta_rectangle_contains_rect (&temp1, &temp3));
|
||||||
g_assert ( meta_rectangle_could_fit_rect (&temp1, &temp3));
|
g_assert ( meta_rectangle_could_fit_rect (&temp1, &temp3));
|
||||||
g_assert (!meta_rectangle_could_fit_rect (&temp3, &temp2));
|
g_assert (!meta_rectangle_could_fit_rect (&temp3, &temp2));
|
||||||
|
|
||||||
printf ("%s passed.\n", G_STRFUNC);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -652,16 +645,16 @@ test_regions_okay (void)
|
|||||||
/*************************************************************/
|
/*************************************************************/
|
||||||
/* Make sure test region 5 has the right spanning rectangles */
|
/* Make sure test region 5 has the right spanning rectangles */
|
||||||
/*************************************************************/
|
/*************************************************************/
|
||||||
printf ("The next test intentionally causes a warning, "
|
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
|
||||||
"but it can be ignored.\n");
|
"Region to merge was empty!*");
|
||||||
region = get_screen_region (5);
|
region = get_screen_region (5);
|
||||||
|
g_test_assert_expected_messages ();
|
||||||
|
|
||||||
verify_lists_are_equal (region, NULL);
|
verify_lists_are_equal (region, NULL);
|
||||||
|
|
||||||
/* FIXME: Still to do:
|
/* FIXME: Still to do:
|
||||||
* - Create random struts and check the regions somehow
|
* - Create random struts and check the regions somehow
|
||||||
*/
|
*/
|
||||||
|
|
||||||
printf ("%s passed.\n", G_STRFUNC);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -704,8 +697,6 @@ test_region_fitting (void)
|
|||||||
g_assert (!meta_rectangle_contained_in_region (region, &rect));
|
g_assert (!meta_rectangle_contained_in_region (region, &rect));
|
||||||
|
|
||||||
meta_rectangle_free_list_and_elements (region);
|
meta_rectangle_free_list_and_elements (region);
|
||||||
|
|
||||||
printf ("%s passed.\n", G_STRFUNC);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -760,14 +751,17 @@ test_clamping_to_region (void)
|
|||||||
&min_size);
|
&min_size);
|
||||||
g_assert (rect.width == 400 && rect.height == 1180);
|
g_assert (rect.width == 400 && rect.height == 1180);
|
||||||
|
|
||||||
printf ("The next test intentionally causes a warning, "
|
|
||||||
"but it can be ignored.\n");
|
|
||||||
rect = meta_rect (50, 50, 10000, 10000);
|
rect = meta_rect (50, 50, 10000, 10000);
|
||||||
min_size.width = 600; min_size.height = 1170;
|
min_size.width = 600; min_size.height = 1170;
|
||||||
|
|
||||||
|
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
|
||||||
|
"No rect whose size to clamp to found*");
|
||||||
meta_rectangle_clamp_to_fit_into_region (region,
|
meta_rectangle_clamp_to_fit_into_region (region,
|
||||||
fixed_directions,
|
fixed_directions,
|
||||||
&rect,
|
&rect,
|
||||||
&min_size);
|
&min_size);
|
||||||
|
g_test_assert_expected_messages ();
|
||||||
|
|
||||||
g_assert (rect.width == 600 && rect.height == 1170);
|
g_assert (rect.width == 600 && rect.height == 1170);
|
||||||
|
|
||||||
rect = meta_rect (350, 50, 100, 1100);
|
rect = meta_rect (350, 50, 100, 1100);
|
||||||
@ -788,20 +782,21 @@ test_clamping_to_region (void)
|
|||||||
&min_size);
|
&min_size);
|
||||||
g_assert (rect.width == 400 && rect.height == 1100);
|
g_assert (rect.width == 400 && rect.height == 1100);
|
||||||
|
|
||||||
printf ("The next test intentionally causes a warning, "
|
|
||||||
"but it can be ignored.\n");
|
|
||||||
rect = meta_rect (300, 70, 999999, 999999);
|
rect = meta_rect (300, 70, 999999, 999999);
|
||||||
min_size.width = 100; min_size.height = 200;
|
min_size.width = 100; min_size.height = 200;
|
||||||
fixed_directions = FIXED_DIRECTION_Y;
|
fixed_directions = FIXED_DIRECTION_Y;
|
||||||
|
|
||||||
|
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
|
||||||
|
"No rect whose size to clamp to found*");
|
||||||
meta_rectangle_clamp_to_fit_into_region (region,
|
meta_rectangle_clamp_to_fit_into_region (region,
|
||||||
fixed_directions,
|
fixed_directions,
|
||||||
&rect,
|
&rect,
|
||||||
&min_size);
|
&min_size);
|
||||||
|
g_test_assert_expected_messages ();
|
||||||
|
|
||||||
g_assert (rect.width == 100 && rect.height == 999999);
|
g_assert (rect.width == 100 && rect.height == 999999);
|
||||||
|
|
||||||
meta_rectangle_free_list_and_elements (region);
|
meta_rectangle_free_list_and_elements (region);
|
||||||
|
|
||||||
printf ("%s passed.\n", G_STRFUNC);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -883,8 +878,6 @@ test_clipping_to_region (void)
|
|||||||
g_assert (meta_rectangle_equal (&rect, &temp));
|
g_assert (meta_rectangle_equal (&rect, &temp));
|
||||||
|
|
||||||
meta_rectangle_free_list_and_elements (region);
|
meta_rectangle_free_list_and_elements (region);
|
||||||
|
|
||||||
printf ("%s passed.\n", G_STRFUNC);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -953,8 +946,6 @@ test_shoving_into_region (void)
|
|||||||
g_assert (meta_rectangle_equal (&rect, &temp));
|
g_assert (meta_rectangle_equal (&rect, &temp));
|
||||||
|
|
||||||
meta_rectangle_free_list_and_elements (region);
|
meta_rectangle_free_list_and_elements (region);
|
||||||
|
|
||||||
printf ("%s passed.\n", G_STRFUNC);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1133,8 +1124,6 @@ test_find_onscreen_edges (void)
|
|||||||
verify_edge_lists_are_equal (edges, tmp);
|
verify_edge_lists_are_equal (edges, tmp);
|
||||||
meta_rectangle_free_list_and_elements (tmp);
|
meta_rectangle_free_list_and_elements (tmp);
|
||||||
meta_rectangle_free_list_and_elements (edges);
|
meta_rectangle_free_list_and_elements (edges);
|
||||||
|
|
||||||
printf ("%s passed.\n", G_STRFUNC);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1222,8 +1211,6 @@ test_find_nonintersected_monitor_edges (void)
|
|||||||
verify_edge_lists_are_equal (edges, tmp);
|
verify_edge_lists_are_equal (edges, tmp);
|
||||||
meta_rectangle_free_list_and_elements (tmp);
|
meta_rectangle_free_list_and_elements (tmp);
|
||||||
meta_rectangle_free_list_and_elements (edges);
|
meta_rectangle_free_list_and_elements (edges);
|
||||||
|
|
||||||
printf ("%s passed.\n", G_STRFUNC);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1323,8 +1310,6 @@ test_gravity_resize (void)
|
|||||||
430,
|
430,
|
||||||
211);
|
211);
|
||||||
g_assert (meta_rectangle_equal (&rect, &temp));
|
g_assert (meta_rectangle_equal (&rect, &temp));
|
||||||
|
|
||||||
printf ("%s passed.\n", G_STRFUNC);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define EPSILON 0.000000001
|
#define EPSILON 0.000000001
|
||||||
@ -1376,35 +1361,33 @@ test_find_closest_point_to_line (void)
|
|||||||
px, py,
|
px, py,
|
||||||
&rx, &ry);
|
&rx, &ry);
|
||||||
g_assert (fabs (rx - answer_x) < EPSILON && fabs (ry - answer_y) < EPSILON);
|
g_assert (fabs (rx - answer_x) < EPSILON && fabs (ry - answer_y) < EPSILON);
|
||||||
|
|
||||||
printf ("%s passed.\n", G_STRFUNC);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
void
|
||||||
main(void)
|
init_boxes_tests (void)
|
||||||
{
|
{
|
||||||
init_random_ness ();
|
init_random_ness ();
|
||||||
test_area ();
|
|
||||||
test_intersect ();
|
|
||||||
test_equal ();
|
|
||||||
test_overlap_funcs ();
|
|
||||||
test_basic_fitting ();
|
|
||||||
|
|
||||||
test_regions_okay ();
|
g_test_add_func ("/util/boxes/area", test_area);
|
||||||
test_region_fitting ();
|
g_test_add_func ("/util/boxes/intersect", test_intersect);
|
||||||
|
g_test_add_func ("/util/boxes/equal", test_equal);
|
||||||
|
g_test_add_func ("/util/boxes/overlap", test_overlap_funcs);
|
||||||
|
g_test_add_func ("/util/boxes/basic-fitting", test_basic_fitting);
|
||||||
|
|
||||||
test_clamping_to_region ();
|
g_test_add_func ("/util/boxes/regions-ok", test_regions_okay);
|
||||||
test_clipping_to_region ();
|
g_test_add_func ("/util/boxes/regions-fitting", test_region_fitting);
|
||||||
test_shoving_into_region ();
|
|
||||||
|
g_test_add_func ("/util/boxes/clamp-to-region", test_clamping_to_region);
|
||||||
|
g_test_add_func ("/util/boxes/clip-to-region", test_clipping_to_region);
|
||||||
|
g_test_add_func ("/util/boxes/shove-into-region", test_shoving_into_region);
|
||||||
|
|
||||||
/* And now the functions dealing with edges more than boxes */
|
/* And now the functions dealing with edges more than boxes */
|
||||||
test_find_onscreen_edges ();
|
g_test_add_func ("/util/boxes/onscreen-edges", test_find_onscreen_edges);
|
||||||
test_find_nonintersected_monitor_edges ();
|
g_test_add_func ("/util/boxes/nonintersected-monitor-edges",
|
||||||
|
test_find_nonintersected_monitor_edges);
|
||||||
|
|
||||||
/* And now the misfit functions that don't quite fit in anywhere else... */
|
/* And now the misfit functions that don't quite fit in anywhere else... */
|
||||||
test_gravity_resize ();
|
g_test_add_func ("/util/boxes/gravity-resize", test_gravity_resize);
|
||||||
test_find_closest_point_to_line ();
|
g_test_add_func ("/util/boxes/closest-point-to-line",
|
||||||
|
test_find_closest_point_to_line);
|
||||||
printf ("All tests passed.\n");
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
23
src/tests/boxes-tests.h
Normal file
23
src/tests/boxes-tests.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 Red Hat, Inc.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation; either version 2 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOXES_TESTS_H
|
||||||
|
#define BOXES_TESTS_H
|
||||||
|
|
||||||
|
void init_boxes_tests (void);
|
||||||
|
|
||||||
|
#endif /* BOXES_TESTS_H */
|
@ -28,6 +28,7 @@
|
|||||||
#include "compositor/meta-plugin-manager.h"
|
#include "compositor/meta-plugin-manager.h"
|
||||||
#include "core/boxes-private.h"
|
#include "core/boxes-private.h"
|
||||||
#include "core/main-private.h"
|
#include "core/main-private.h"
|
||||||
|
#include "tests/boxes-tests.h"
|
||||||
#include "tests/meta-backend-test.h"
|
#include "tests/meta-backend-test.h"
|
||||||
#include "tests/monitor-config-migration-unit-tests.h"
|
#include "tests/monitor-config-migration-unit-tests.h"
|
||||||
#include "tests/monitor-unit-tests.h"
|
#include "tests/monitor-unit-tests.h"
|
||||||
@ -252,6 +253,7 @@ init_tests (int argc, char **argv)
|
|||||||
init_monitor_store_tests ();
|
init_monitor_store_tests ();
|
||||||
init_monitor_config_migration_tests ();
|
init_monitor_config_migration_tests ();
|
||||||
init_monitor_tests ();
|
init_monitor_tests ();
|
||||||
|
init_boxes_tests ();
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
Reference in New Issue
Block a user