GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 60.3% 35 / 0 / 58
Functions: 50.0% 5 / 0 / 10
Branches: 37.9% 25 / 0 / 66

shumate/vector/shumate-vector-symbol-info.c
Line Branch Exec Source
1 /*
2 * Copyright (C) 2021 James Westman <james@jwestman.net>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
16 */
17
18
19 #include "shumate-vector-symbol-info-private.h"
20
21
22 ✗ G_DEFINE_BOXED_TYPE (ShumateVectorSymbolInfo, shumate_vector_symbol_info, shumate_vector_symbol_info_ref, shumate_vector_symbol_info_unref)
23
24
25 static void
26 10 shumate_vector_symbol_details_free (ShumateVectorSymbolDetails *details)
27 {
28
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 10 times.
10 g_assert (details != NULL);
29
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 10 times.
10 g_assert_cmpint (details->ref_count, ==, 0);
30
31
1/2
✓ Branch 6 → 7 taken 10 times.
✗ Branch 6 → 8 not taken.
10 g_clear_pointer (&details->layer, g_free);
32
1/2
✓ Branch 8 → 9 taken 10 times.
✗ Branch 8 → 10 not taken.
10 g_clear_pointer (&details->feature_id, g_free);
33
1/2
✓ Branch 10 → 11 taken 10 times.
✗ Branch 10 → 12 not taken.
10 g_clear_pointer (&details->source_layer, g_free);
34
35
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 10 times.
10 g_clear_object (&details->icon_image);
36
37
1/2
✓ Branch 14 → 15 taken 10 times.
✗ Branch 14 → 16 not taken.
10 g_clear_pointer (&details->formatted_text, g_ptr_array_unref);
38
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 10 times.
10 g_clear_pointer (&details->text_font, g_free);
39
40
1/2
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 20 taken 10 times.
10 g_clear_pointer (&details->cursor, g_free);
41
42
1/2
✓ Branch 20 → 21 taken 10 times.
✗ Branch 20 → 22 not taken.
10 g_clear_pointer (&details->tags, g_hash_table_unref);
43
44
1/2
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 10 times.
10 g_free (details);
45 10 }
46
47 ShumateVectorSymbolDetails *
48 10 shumate_vector_symbol_details_ref (ShumateVectorSymbolDetails *details)
49 {
50
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 10 times.
10 g_return_val_if_fail (details, NULL);
51
1/2
✓ Branch 4 → 5 taken 10 times.
✗ Branch 4 → 6 not taken.
10 g_return_val_if_fail (details->ref_count, NULL);
52
53 10 g_atomic_int_inc (&details->ref_count);
54
55 10 return details;
56 }
57
58 void
59 20 shumate_vector_symbol_details_unref (ShumateVectorSymbolDetails *details)
60 {
61
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 20 times.
20 g_return_if_fail (details);
62
1/2
✓ Branch 4 → 5 taken 20 times.
✗ Branch 4 → 6 not taken.
20 g_return_if_fail (details->ref_count);
63
64
2/2
✓ Branch 5 → 7 taken 10 times.
✓ Branch 5 → 8 taken 10 times.
20 if (g_atomic_int_dec_and_test (&details->ref_count))
65 10 shumate_vector_symbol_details_free (details);
66 }
67
68 static void
69 10 shumate_vector_symbol_info_free (ShumateVectorSymbolInfo *self)
70 {
71
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 10 times.
10 g_assert (self != NULL);
72
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 10 times.
10 g_assert_cmpint (self->ref_count, ==, 0);
73
74
1/2
✓ Branch 6 → 7 taken 10 times.
✗ Branch 6 → 8 not taken.
10 g_clear_pointer (&self->details, shumate_vector_symbol_details_unref);
75
76
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 10 times.
10 g_clear_pointer (&self->line, shumate_vector_line_string_free);
77
78
1/2
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 10 times.
10 g_free (self);
79 10 }
80
81 ShumateVectorSymbolInfo *
82 ✗ shumate_vector_symbol_info_ref (ShumateVectorSymbolInfo *self)
83 {
84 ✗ g_return_val_if_fail (self, NULL);
85 ✗ g_return_val_if_fail (self->ref_count, NULL);
86
87 ✗ g_atomic_int_inc (&self->ref_count);
88
89 ✗ return self;
90 }
91
92 void
93 10 shumate_vector_symbol_info_unref (ShumateVectorSymbolInfo *self)
94 {
95
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 10 times.
10 g_return_if_fail (self);
96
1/2
✓ Branch 4 → 5 taken 10 times.
✗ Branch 4 → 6 not taken.
10 g_return_if_fail (self->ref_count);
97
98
1/2
✓ Branch 5 → 7 taken 10 times.
✗ Branch 5 → 8 not taken.
10 if (g_atomic_int_dec_and_test (&self->ref_count))
99 10 shumate_vector_symbol_info_free (self);
100 }
101
102
103 void
104 ✗ shumate_vector_symbol_info_set_line_points (ShumateVectorSymbolInfo *self,
105 ShumateVectorLineString *linestring,
106 float position)
107 {
108 ✗ ShumateVectorPoint center;
109 ✗ g_clear_pointer (&self->line, shumate_vector_line_string_free);
110 ✗ self->line = linestring;
111
112 ✗ shumate_vector_line_string_bounds (self->line, &self->line_size, &center);
113 ✗ self->x = center.x;
114 ✗ self->y = center.y;
115 ✗ self->line_length = shumate_vector_line_string_length (self->line);
116 ✗ self->line_position = position;
117 ✗ }
118
119 int
120 ✗ shumate_vector_symbol_info_compare (ShumateVectorSymbolInfo *a,
121 ShumateVectorSymbolInfo *b)
122 {
123 ✗ if (a->details->layer_idx < b->details->layer_idx)
124 return -1;
125 ✗ else if (a->details->layer_idx > b->details->layer_idx)
126 return 1;
127 ✗ else if (a->details->symbol_sort_key < b->details->symbol_sort_key)
128 return -1;
129 ✗ else if (a->details->symbol_sort_key > b->details->symbol_sort_key)
130 return 1;
131 else
132 ✗ return 0;
133 }
134