GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 57 / 0 / 57
Functions: 100.0% 4 / 0 / 4
Branches: 56.2% 18 / 0 / 32

tests/map.c
Line Branch Exec Source
1 #undef G_DISABLE_ASSERT
2
3 #include <gtk/gtk.h>
4 #include <shumate/shumate.h>
5
6 static void
7 2 emit_double_click (ShumateMap *map)
8 {
9 4 g_autoptr(GListModel) controllers = gtk_widget_observe_controllers (GTK_WIDGET (map));
10
2/2
✓ Branch 14 → 4 taken 16 times.
✓ Branch 14 → 15 taken 2 times.
20 for (guint i = 0; i < g_list_model_get_n_items (controllers); i++) {
11 32 g_autoptr(GtkEventController) controller = g_list_model_get_item (controllers, i);
12
13
5/8
✓ Branch 5 → 6 taken 16 times.
✗ Branch 5 → 10 not taken.
✓ Branch 6 → 7 taken 16 times.
✗ Branch 6 → 8 not taken.
✓ Branch 7 → 8 taken 14 times.
✓ Branch 7 → 9 taken 2 times.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 14 times.
16 if (GTK_IS_GESTURE_CLICK (controller)) {
14 // emit a double click
15 2 g_signal_emit_by_name (controller, "pressed", 2, 10.0, 20.0);
16 }
17 }
18 2 }
19
20 static void
21 1 test_map_add_layers (void)
22 {
23 1 ShumateMap *map = shumate_map_new ();
24 1 ShumateViewport *viewport = shumate_map_get_viewport (map);
25 1 ShumateLayer *layer1 = SHUMATE_LAYER (shumate_path_layer_new (viewport));
26 1 ShumateLayer *layer2 = SHUMATE_LAYER (shumate_path_layer_new (viewport));
27 1 ShumateLayer *layer3;
28
29 // Add layer1
30 1 shumate_map_add_layer (map, layer1);
31
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 1 time.
1 g_assert_true (gtk_widget_get_first_child (GTK_WIDGET (map)) == GTK_WIDGET (layer1));
32
33 // Add layer2, should end up on top
34 1 shumate_map_add_layer (map, layer2);
35
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 1 time.
1 g_assert_true (gtk_widget_get_last_child (GTK_WIDGET (map)) == GTK_WIDGET (layer2));
36
37 // Add layer3 above layer2
38 1 layer3 = SHUMATE_LAYER (shumate_path_layer_new (viewport));
39 1 shumate_map_insert_layer_above (map, layer3, layer2);
40
1/2
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 1 time.
1 g_assert_true (gtk_widget_get_last_child (GTK_WIDGET (map)) == GTK_WIDGET (layer3));
41
42 // Remove layer3
43 1 shumate_map_remove_layer (map, layer3);
44
1/2
✗ Branch 21 → 22 not taken.
✓ Branch 21 → 23 taken 1 time.
1 g_assert_true (gtk_widget_get_last_child (GTK_WIDGET (map)) == GTK_WIDGET (layer2));
45
46 // Add layer3 behind layer1
47 1 layer3 = SHUMATE_LAYER (shumate_path_layer_new (viewport));
48 1 shumate_map_insert_layer_behind (map, layer3, layer1);
49
1/2
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 28 taken 1 time.
1 g_assert_true (gtk_widget_get_first_child (GTK_WIDGET (map)) == GTK_WIDGET (layer3));
50
51 // Remove layer3
52 1 shumate_map_remove_layer (map, layer3);
53
1/2
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 32 taken 1 time.
1 g_assert_true (gtk_widget_get_first_child (GTK_WIDGET (map)) == GTK_WIDGET (layer1));
54
55 // Add layer3 behind NULL
56 1 layer3 = SHUMATE_LAYER (shumate_path_layer_new (viewport));
57 1 shumate_map_insert_layer_behind (map, layer3, NULL);
58
1/2
✗ Branch 35 → 36 not taken.
✓ Branch 35 → 37 taken 1 time.
1 g_assert_true (gtk_widget_get_last_child (GTK_WIDGET (map)) == GTK_WIDGET (layer3));
59 1 shumate_map_remove_layer (map, layer3);
60
61 // Add layer3 above NULL
62 1 layer3 = SHUMATE_LAYER (shumate_path_layer_new (viewport));
63 1 shumate_map_insert_layer_above (map, layer3, NULL);
64
1/2
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 43 taken 1 time.
1 g_assert_true (gtk_widget_get_first_child (GTK_WIDGET (map)) == GTK_WIDGET (layer3));
65 1 shumate_map_remove_layer (map, layer3);
66 1 }
67
68 static void
69 1 test_map_zoom_on_double_click_switch (void)
70 {
71 1 ShumateMap *map = shumate_map_new ();
72 1 ShumateViewport *viewport = shumate_map_get_viewport (map);
73 // initial zoom is 10
74 1 double initial = 10;
75
76 // test: zoom on double click should NOT work
77 1 shumate_viewport_set_zoom_level (viewport, initial);
78 1 shumate_map_set_zoom_on_double_click (map, FALSE);
79 1 emit_double_click (map);
80 1 double actual = shumate_viewport_get_zoom_level (viewport);
81
2/4
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 1 time.
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 1 time.
1 g_assert_cmpfloat_with_epsilon (actual, initial, 0.0001);
82
83 // test: zoom on double click should work
84 1 shumate_viewport_set_zoom_level (viewport, initial);
85 1 shumate_map_set_zoom_on_double_click (map, TRUE);
86 1 emit_double_click (map);
87 1 actual = shumate_viewport_get_zoom_level (viewport);
88
1/2
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 1 time.
1 g_assert_true (actual > initial);
89 1 }
90
91 int
92 1 main (int argc, char *argv[])
93 {
94 1 g_test_init (&argc, &argv, NULL);
95 1 gtk_init ();
96
97 1 g_test_add_func ("/map/add-layers", test_map_add_layers);
98 1 g_test_add_func ("/map/zoom_on_double_click_switch", test_map_zoom_on_double_click_switch);
99
100 1 return g_test_run ();
101 }
102