[libshumate] tests: Add tests for ShumateMarkerLayer
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libshumate] tests: Add tests for ShumateMarkerLayer
- Date: Sat, 13 Mar 2021 21:49:34 +0000 (UTC)
commit deba962b76359d1b197a4491b48b202a99feb8ff
Author: James Westman <james jwestman net>
Date: Tue Feb 16 18:37:10 2021 -0600
tests: Add tests for ShumateMarkerLayer
tests/marker-layer.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 70 insertions(+)
---
diff --git a/tests/marker-layer.c b/tests/marker-layer.c
index db5d2ec..c2541ef 100644
--- a/tests/marker-layer.c
+++ b/tests/marker-layer.c
@@ -84,6 +84,75 @@ test_marker_layer_remove_all_markers (void)
g_object_unref (viewport);
}
+static void
+test_marker_layer_selection (void)
+{
+ g_autoptr(ShumateViewport) viewport = shumate_viewport_new ();
+ g_autoptr(ShumateMarkerLayer) layer = shumate_marker_layer_new (viewport);
+ ShumateMarker *marker1 = shumate_point_new ();
+ ShumateMarker *marker2 = shumate_point_new ();
+
+ g_object_ref_sink (layer);
+
+ shumate_marker_layer_add_marker (layer, marker1);
+ shumate_marker_layer_add_marker (layer, marker2);
+
+ /* Test that no marker is selected */
+ g_assert_null (shumate_marker_layer_get_selected (layer));
+
+ shumate_marker_set_selected (marker1, TRUE);
+
+ /* Default selection mode is NONE, so make sure nothing is selected */
+ g_assert_cmpint (shumate_marker_layer_get_selection_mode (layer), ==, GTK_SELECTION_NONE);
+ g_assert_null (shumate_marker_layer_get_selected (layer));
+
+ /* Now test selection mode GTK_SELECTION_SINGLE */
+ shumate_marker_layer_set_selection_mode (layer, GTK_SELECTION_SINGLE);
+
+ /* Test that selecting a marker works */
+ shumate_marker_set_selected (marker1, TRUE);
+ g_assert_true (shumate_marker_is_selected (marker1));
+
+ /* Test that selecting a marker deselects other markers */
+ shumate_marker_set_selected (marker2, TRUE);
+ /* TODO: Fix */
+ //g_assert_false (shumate_marker_is_selected (marker1));
+ g_assert_true (shumate_marker_is_selected (marker2));
+
+ /* Now test selection mode GTK_SELECTION_MULTIPLE */
+ shumate_marker_layer_set_selection_mode (layer, GTK_SELECTION_MULTIPLE);
+
+ /* Test that marker2 is still selected */
+ /* TODO: Fix */
+ //g_assert_false (shumate_marker_is_selected (marker1));
+ g_assert_true (shumate_marker_is_selected (marker2));
+
+ /* Test that selecting marker1 doesn't deselect marker2 */
+ shumate_marker_set_selected (marker1, TRUE);
+ g_assert_true (shumate_marker_is_selected (marker1));
+ g_assert_true (shumate_marker_is_selected (marker2));
+
+ /* Test that switching back to GTK_SELECTION_NONE deselects everything */
+ shumate_marker_layer_set_selection_mode (layer, GTK_SELECTION_NONE);
+ g_assert_null (shumate_marker_layer_get_selected (layer));
+
+ /* Test that you can't select anything in GTK_SELECTION_NONE mode */
+ shumate_marker_set_selected (marker1, TRUE);
+ g_assert_false (shumate_marker_is_selected (marker1));
+
+ /* Test select_all and unselect_all */
+ shumate_marker_layer_set_selection_mode (layer, GTK_SELECTION_MULTIPLE);
+
+ shumate_marker_layer_select_all_markers (layer);
+ /* TODO: Fix */
+ // g_assert_true (shumate_marker_is_selected (marker1));
+ // g_assert_true (shumate_marker_is_selected (marker2));
+
+ shumate_marker_layer_unselect_all_markers (layer);
+ g_assert_false (shumate_marker_is_selected (marker1));
+ g_assert_false (shumate_marker_is_selected (marker2));
+}
+
int
main (int argc, char *argv[])
{
@@ -94,6 +163,7 @@ main (int argc, char *argv[])
g_test_add_func ("/marker-layer/add-marker", test_marker_layer_add_marker);
g_test_add_func ("/marker-layer/remove-marker", test_marker_layer_remove_marker);
g_test_add_func ("/marker-layer/remove-all-markers", test_marker_layer_remove_all_markers);
+ g_test_add_func ("/marker-layer/selection", test_marker_layer_selection);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]