LCOV - code coverage report
Current view: top level - tests - marker-layer.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 97 97 100.0 %
Date: 2024-05-11 21:41:31 Functions: 6 6 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 34 66 51.5 %

           Branch data     Line data    Source code
       1                 :            : #undef G_DISABLE_ASSERT
       2                 :            : 
       3                 :            : #include <gtk/gtk.h>
       4                 :            : #include <shumate/shumate.h>
       5                 :            : 
       6                 :            : static void
       7                 :          2 : test_marker_layer_new (void)
       8                 :            : {
       9                 :          2 :   ShumateMarkerLayer *marker_layer;
      10                 :          2 :   ShumateViewport *viewport;
      11                 :            : 
      12                 :          2 :   viewport = shumate_viewport_new ();
      13                 :          2 :   marker_layer = shumate_marker_layer_new (viewport);
      14         [ -  + ]:          2 :   g_assert_nonnull (marker_layer);
      15         [ -  + ]:          2 :   g_assert_true (SHUMATE_IS_MARKER_LAYER (marker_layer));
      16                 :            : 
      17                 :          2 :   g_object_unref (viewport);
      18                 :          2 : }
      19                 :            : 
      20                 :            : static void
      21                 :          2 : test_marker_layer_add_marker (void)
      22                 :            : {
      23                 :          2 :   ShumateMarkerLayer *marker_layer;
      24                 :          2 :   ShumateViewport *viewport;
      25                 :          2 :   ShumateMarker *point;
      26                 :            : 
      27                 :          2 :   viewport = shumate_viewport_new ();
      28                 :          2 :   marker_layer = shumate_marker_layer_new (viewport);
      29                 :            : 
      30                 :          2 :   point = shumate_point_new ();
      31         [ -  + ]:          2 :   g_assert_null (gtk_widget_get_parent (GTK_WIDGET (point)));
      32                 :            : 
      33                 :          2 :   shumate_marker_layer_add_marker (marker_layer, point);
      34         [ -  + ]:          2 :   g_assert_true (gtk_widget_get_parent (GTK_WIDGET (point)) == GTK_WIDGET (marker_layer));
      35                 :            : 
      36                 :          2 :   g_object_unref (viewport);
      37                 :          2 : }
      38                 :            : 
      39                 :            : static void
      40                 :          2 : test_marker_layer_remove_marker (void)
      41                 :            : {
      42                 :          2 :   ShumateMarkerLayer *marker_layer;
      43                 :          2 :   ShumateViewport *viewport;
      44                 :          2 :   ShumateMarker *point;
      45                 :            : 
      46                 :          2 :   viewport = shumate_viewport_new ();
      47                 :          2 :   marker_layer = shumate_marker_layer_new (viewport);
      48                 :            : 
      49                 :          2 :   point = shumate_point_new ();
      50                 :          2 :   shumate_marker_layer_add_marker (marker_layer, point);
      51         [ -  + ]:          2 :   g_assert_true (gtk_widget_get_parent (GTK_WIDGET (point)) == GTK_WIDGET (marker_layer));
      52                 :            : 
      53                 :            :   // Add a ref here so that point isn't completely destroyed before checking
      54                 :          2 :   g_object_ref_sink (point);
      55                 :            : 
      56                 :          2 :   shumate_marker_layer_remove_marker (marker_layer, point);
      57         [ -  + ]:          2 :   g_assert_null (gtk_widget_get_parent (GTK_WIDGET (point)));
      58                 :            : 
      59                 :          2 :   g_object_unref (point);
      60                 :            : 
      61                 :          2 :   g_object_unref (viewport);
      62                 :          2 : }
      63                 :            : 
      64                 :            : static void
      65                 :          2 : test_marker_layer_remove_all_markers (void)
      66                 :            : {
      67                 :          2 :   ShumateMarkerLayer *marker_layer;
      68                 :          2 :   ShumateViewport *viewport;
      69                 :          2 :   int i;
      70                 :            : 
      71                 :          2 :   viewport = shumate_viewport_new ();
      72                 :          2 :   marker_layer = shumate_marker_layer_new (viewport);
      73                 :            : 
      74         [ +  + ]:        204 :   for (i = 0; i < 100; i++)
      75                 :            :     {
      76                 :        200 :       ShumateMarker *point;
      77                 :            : 
      78                 :        200 :       point = shumate_point_new ();
      79                 :        200 :       shumate_marker_layer_add_marker (marker_layer, point);
      80         [ -  + ]:        200 :       g_assert_true (gtk_widget_get_parent (GTK_WIDGET (point)) == GTK_WIDGET (marker_layer));
      81                 :            :     }
      82                 :            : 
      83                 :          2 :   shumate_marker_layer_remove_all (marker_layer);
      84         [ -  + ]:          2 :   g_assert_null (gtk_widget_get_first_child (GTK_WIDGET (marker_layer)));
      85                 :            : 
      86                 :          2 :   g_object_unref (viewport);
      87                 :          2 : }
      88                 :            : 
      89                 :            : static void
      90                 :          2 : test_marker_layer_selection (void)
      91                 :            : {
      92                 :          2 :   g_autoptr(ShumateViewport) viewport = shumate_viewport_new ();
      93         [ +  - ]:          4 :   g_autoptr(ShumateMarkerLayer) layer = shumate_marker_layer_new (viewport);
      94                 :          2 :   ShumateMarker *marker1 = shumate_point_new ();
      95                 :          2 :   ShumateMarker *marker2 = shumate_point_new ();
      96                 :            : 
      97                 :          2 :   g_object_ref_sink (layer);
      98                 :            : 
      99                 :          2 :   shumate_marker_layer_add_marker (layer, marker1);
     100                 :          2 :   shumate_marker_layer_add_marker (layer, marker2);
     101                 :            : 
     102         [ -  + ]:          2 :   g_assert_true (shumate_marker_get_selectable (marker1));
     103                 :            : 
     104                 :            :   /* Test that no marker is selected initially */
     105         [ -  + ]:          2 :   g_assert_null (shumate_marker_layer_get_selected (layer));
     106                 :            : 
     107                 :            :   /* Default selection mode is NONE, so make sure nothing can be  selected */
     108         [ -  + ]:          2 :   g_assert_cmpint (shumate_marker_layer_get_selection_mode (layer), ==, GTK_SELECTION_NONE);
     109         [ -  + ]:          2 :   g_assert_false (shumate_marker_layer_select_marker (layer, marker1));
     110         [ -  + ]:          2 :   g_assert_null (shumate_marker_layer_get_selected (layer));
     111                 :            : 
     112                 :            :   /* Now test selection mode GTK_SELECTION_SINGLE */
     113                 :          2 :   shumate_marker_layer_set_selection_mode (layer, GTK_SELECTION_SINGLE);
     114                 :            : 
     115                 :            :   /* Test that selecting a marker works */
     116         [ -  + ]:          2 :   g_assert_true (shumate_marker_layer_select_marker (layer, marker1));
     117         [ -  + ]:          2 :   g_assert_true (shumate_marker_is_selected (marker1));
     118                 :            : 
     119                 :            :   /* Test that selecting a marker deselects other markers */
     120         [ -  + ]:          2 :   g_assert_true (shumate_marker_layer_select_marker (layer, marker2));
     121         [ -  + ]:          2 :   g_assert_false (shumate_marker_is_selected (marker1));
     122         [ -  + ]:          2 :   g_assert_true (shumate_marker_is_selected (marker2));
     123                 :            : 
     124                 :            :   /* Now test selection mode GTK_SELECTION_MULTIPLE */
     125                 :          2 :   shumate_marker_layer_set_selection_mode (layer, GTK_SELECTION_MULTIPLE);
     126                 :            : 
     127                 :            :   /* Test that marker2 is still selected */
     128         [ -  + ]:          2 :   g_assert_false (shumate_marker_is_selected (marker1));
     129         [ -  + ]:          2 :   g_assert_true (shumate_marker_is_selected (marker2));
     130                 :            : 
     131                 :            :   /* Test that selecting marker1 doesn't deselect marker2 */
     132         [ -  + ]:          2 :   g_assert_true (shumate_marker_layer_select_marker (layer, marker1));
     133         [ -  + ]:          2 :   g_assert_true (shumate_marker_is_selected (marker1));
     134         [ -  + ]:          2 :   g_assert_true (shumate_marker_is_selected (marker2));
     135                 :            : 
     136                 :            :   /* Test that switching back to GTK_SELECTION_NONE deselects everything */
     137                 :          2 :   shumate_marker_layer_set_selection_mode (layer, GTK_SELECTION_NONE);
     138         [ -  + ]:          2 :   g_assert_null (shumate_marker_layer_get_selected (layer));
     139                 :            : 
     140                 :            :   /* Test that you can't select anything in GTK_SELECTION_NONE mode */
     141         [ -  + ]:          2 :   g_assert_false (shumate_marker_layer_select_marker (layer, marker1));
     142         [ -  + ]:          2 :   g_assert_false (shumate_marker_is_selected (marker1));
     143                 :            : 
     144                 :            :   /* Test select_all and unselect_all */
     145                 :          2 :   shumate_marker_layer_set_selection_mode (layer, GTK_SELECTION_MULTIPLE);
     146                 :            : 
     147                 :          2 :   shumate_marker_layer_select_all_markers (layer);
     148         [ -  + ]:          2 :   g_assert_true (shumate_marker_is_selected (marker1));
     149         [ -  + ]:          2 :   g_assert_true (shumate_marker_is_selected (marker2));
     150                 :            : 
     151                 :          2 :   shumate_marker_layer_unselect_all_markers (layer);
     152         [ -  + ]:          2 :   g_assert_false (shumate_marker_is_selected (marker1));
     153   [ -  +  +  - ]:          2 :   g_assert_false (shumate_marker_is_selected (marker2));
     154                 :          2 : }
     155                 :            : 
     156                 :            : int
     157                 :          2 : main (int argc, char *argv[])
     158                 :            : {
     159                 :          2 :   g_test_init (&argc, &argv, NULL);
     160                 :          2 :   gtk_init ();
     161                 :            : 
     162                 :          2 :   g_test_add_func ("/marker-layer/new", test_marker_layer_new);
     163                 :          2 :   g_test_add_func ("/marker-layer/add-marker", test_marker_layer_add_marker);
     164                 :          2 :   g_test_add_func ("/marker-layer/remove-marker", test_marker_layer_remove_marker);
     165                 :          2 :   g_test_add_func ("/marker-layer/remove-all-markers", test_marker_layer_remove_all_markers);
     166                 :          2 :   g_test_add_func ("/marker-layer/selection", test_marker_layer_selection);
     167                 :            : 
     168                 :          2 :   return g_test_run ();
     169                 :            : }

Generated by: LCOV version 1.14