File: map.c

package info (click to toggle)
libshumate 1.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,816 kB
  • sloc: ansic: 21,802; xml: 38; makefile: 18; javascript: 10
file content (101 lines) | stat: -rw-r--r-- 3,550 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#undef G_DISABLE_ASSERT

#include <gtk/gtk.h>
#include <shumate/shumate.h>

static void
emit_double_click (ShumateMap *map)
{
  g_autoptr(GListModel) controllers = gtk_widget_observe_controllers (GTK_WIDGET (map));
  for (guint i = 0; i < g_list_model_get_n_items (controllers); i++) {
      g_autoptr(GtkEventController) controller = g_list_model_get_item (controllers, i);

      if (GTK_IS_GESTURE_CLICK (controller)) {
          // emit a double click
          g_signal_emit_by_name (controller, "pressed", 2, 10.0, 20.0);
      }
  }
}

static void
test_map_add_layers (void)
{
  ShumateMap *map = shumate_map_new ();
  ShumateViewport *viewport = shumate_map_get_viewport (map);
  ShumateLayer *layer1 = SHUMATE_LAYER (shumate_path_layer_new (viewport));
  ShumateLayer *layer2 = SHUMATE_LAYER (shumate_path_layer_new (viewport));
  ShumateLayer *layer3;

  // Add layer1
  shumate_map_add_layer (map, layer1);
  g_assert_true (gtk_widget_get_first_child (GTK_WIDGET (map)) == GTK_WIDGET (layer1));

  // Add layer2, should end up on top
  shumate_map_add_layer (map, layer2);
  g_assert_true (gtk_widget_get_last_child (GTK_WIDGET (map)) == GTK_WIDGET (layer2));

  // Add layer3 above layer2
  layer3 = SHUMATE_LAYER (shumate_path_layer_new (viewport));
  shumate_map_insert_layer_above (map, layer3, layer2);
  g_assert_true (gtk_widget_get_last_child (GTK_WIDGET (map)) == GTK_WIDGET (layer3));

  // Remove layer3
  shumate_map_remove_layer (map, layer3);
  g_assert_true (gtk_widget_get_last_child (GTK_WIDGET (map)) == GTK_WIDGET (layer2));

  // Add layer3 behind layer1
  layer3 = SHUMATE_LAYER (shumate_path_layer_new (viewport));
  shumate_map_insert_layer_behind (map, layer3, layer1);
  g_assert_true (gtk_widget_get_first_child (GTK_WIDGET (map)) == GTK_WIDGET (layer3));

  // Remove layer3
  shumate_map_remove_layer (map, layer3);
  g_assert_true (gtk_widget_get_first_child (GTK_WIDGET (map)) == GTK_WIDGET (layer1));

  // Add layer3 behind NULL
  layer3 = SHUMATE_LAYER (shumate_path_layer_new (viewport));
  shumate_map_insert_layer_behind (map, layer3, NULL);
  g_assert_true (gtk_widget_get_last_child (GTK_WIDGET (map)) == GTK_WIDGET (layer3));
  shumate_map_remove_layer (map, layer3);

  // Add layer3 above NULL
  layer3 = SHUMATE_LAYER (shumate_path_layer_new (viewport));
  shumate_map_insert_layer_above (map, layer3, NULL);
  g_assert_true (gtk_widget_get_first_child (GTK_WIDGET (map)) == GTK_WIDGET (layer3));
  shumate_map_remove_layer (map, layer3);
}

static void
test_map_zoom_on_double_click_switch (void)
{
  ShumateMap *map = shumate_map_new ();
  ShumateViewport *viewport = shumate_map_get_viewport (map);
  // initial zoom is 10
  double initial = 10;

  // test: zoom on double click should NOT work
  shumate_viewport_set_zoom_level (viewport, initial);
  shumate_map_set_zoom_on_double_click (map, FALSE);
  emit_double_click (map);
  double actual = shumate_viewport_get_zoom_level (viewport);
  g_assert_cmpfloat_with_epsilon (actual, initial, 0.0001);

  // test: zoom on double click should work
  shumate_viewport_set_zoom_level (viewport, initial);
  shumate_map_set_zoom_on_double_click (map, TRUE);
  emit_double_click (map);
  actual = shumate_viewport_get_zoom_level (viewport);
  g_assert_true (actual > initial);
}

int
main (int argc, char *argv[])
{
  g_test_init (&argc, &argv, NULL);
  gtk_init ();

  g_test_add_func ("/map/add-layers", test_map_add_layers);
  g_test_add_func ("/map/zoom_on_double_click_switch", test_map_zoom_on_double_click_switch);

  return g_test_run ();
}