tests/vector-index.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #undef G_DISABLE_ASSERT | ||
| 2 | |||
| 3 | #include <shumate/shumate.h> | ||
| 4 | #include "shumate/vector/shumate-vector-index-private.h" | ||
| 5 | #include "shumate/vector/shumate-vector-render-scope-private.h" | ||
| 6 | #include "shumate/vector/shumate-vector-expression-private.h" | ||
| 7 | #include "shumate/shumate-vector-reader-iter-private.h" | ||
| 8 | |||
| 9 | static void | ||
| 10 | 2 | test_vector_index_bitset (void) | |
| 11 | { | ||
| 12 | 2 | g_autoptr(ShumateVectorIndexBitset) bitset = shumate_vector_index_bitset_new (100); | |
| 13 | 2 | g_autoptr(ShumateVectorIndexBitset) bitset2 = NULL; | |
| 14 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 2 times.
|
2 | g_assert_nonnull (bitset); |
| 15 |
1/2✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 2 times.
|
2 | g_assert_cmpint (bitset->len, ==, 100); |
| 16 |
1/2✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 2 times.
|
2 | g_assert_nonnull (bitset->bits); |
| 17 | |||
| 18 |
1/2✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 2 times.
|
2 | g_assert_cmpint (shumate_vector_index_bitset_next (bitset, -1), ==, -1); |
| 19 | |||
| 20 | 2 | shumate_vector_index_bitset_set (bitset, 0); | |
| 21 |
1/2✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 2 times.
|
2 | g_assert_cmpint (shumate_vector_index_bitset_next (bitset, -1), ==, 0); |
| 22 | |||
| 23 | 2 | shumate_vector_index_bitset_set (bitset, 32); | |
| 24 |
1/2✗ Branch 18 → 19 not taken.
✓ Branch 18 → 20 taken 2 times.
|
2 | g_assert_cmpint (shumate_vector_index_bitset_next (bitset, 0), ==, 32); |
| 25 | |||
| 26 | 2 | shumate_vector_index_bitset_clear (bitset, 32); | |
| 27 | 2 | shumate_vector_index_bitset_set (bitset, 50); | |
| 28 |
1/2✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 2 times.
|
2 | g_assert_cmpint (shumate_vector_index_bitset_next (bitset, 0), ==, 50); |
| 29 | |||
| 30 | 2 | shumate_vector_index_bitset_set (bitset, 99); | |
| 31 |
1/2✗ Branch 27 → 28 not taken.
✓ Branch 27 → 29 taken 2 times.
|
2 | g_assert_cmpint (shumate_vector_index_bitset_next (bitset, 98), ==, 99); |
| 32 |
1/2✗ Branch 30 → 31 not taken.
✓ Branch 30 → 32 taken 2 times.
|
2 | g_assert_cmpint (shumate_vector_index_bitset_next (bitset, 99), ==, -1); |
| 33 | |||
| 34 | 2 | bitset2 = shumate_vector_index_bitset_copy (bitset); | |
| 35 |
1/2✗ Branch 33 → 34 not taken.
✓ Branch 33 → 35 taken 2 times.
|
2 | g_assert_nonnull (bitset2); |
| 36 |
1/2✗ Branch 35 → 36 not taken.
✓ Branch 35 → 37 taken 2 times.
|
2 | g_assert_cmpint (bitset2->len, ==, 100); |
| 37 |
1/2✗ Branch 37 → 38 not taken.
✓ Branch 37 → 39 taken 2 times.
|
2 | g_assert_nonnull (bitset2->bits); |
| 38 |
1/2✗ Branch 40 → 41 not taken.
✓ Branch 40 → 42 taken 2 times.
|
2 | g_assert_cmpint (shumate_vector_index_bitset_next (bitset2, 0), ==, 50); |
| 39 | |||
| 40 | 2 | shumate_vector_index_bitset_set (bitset2, 49); | |
| 41 | 2 | shumate_vector_index_bitset_or (bitset, bitset2); | |
| 42 |
1/2✗ Branch 45 → 46 not taken.
✓ Branch 45 → 47 taken 2 times.
|
2 | g_assert_cmpint (shumate_vector_index_bitset_next (bitset, 0), ==, 49); |
| 43 | |||
| 44 | 2 | shumate_vector_index_bitset_clear (bitset2, 49); | |
| 45 | 2 | shumate_vector_index_bitset_and (bitset, bitset2); | |
| 46 |
1/2✗ Branch 50 → 51 not taken.
✓ Branch 50 → 52 taken 2 times.
|
2 | g_assert_cmpint (shumate_vector_index_bitset_next (bitset, 0), ==, 50); |
| 47 | 2 | } | |
| 48 | |||
| 49 | static void | ||
| 50 | 2 | test_vector_index_description (void) | |
| 51 | { | ||
| 52 | 2 | ShumateVectorIndexDescription *desc = shumate_vector_index_description_new (); | |
| 53 | 4 | g_auto(ShumateVectorValue) value = SHUMATE_VECTOR_VALUE_INIT; | |
| 54 | |||
| 55 | 2 | shumate_vector_value_set_string (&value, "Hello, world!"); | |
| 56 | |||
| 57 |
1/2✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 2 times.
|
2 | g_assert_nonnull (desc); |
| 58 | |||
| 59 |
1/2✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 2 times.
|
2 | g_assert_false (shumate_vector_index_description_has_layer (desc, "foo")); |
| 60 | |||
| 61 | 2 | shumate_vector_index_description_add_broad_geometry_type (desc, "foo"); | |
| 62 |
1/2✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 2 times.
|
2 | g_assert_true (shumate_vector_index_description_has_layer (desc, "foo")); |
| 63 |
1/2✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 2 times.
|
2 | g_assert_true (shumate_vector_index_description_has_broad_geometry_type (desc, "foo")); |
| 64 | |||
| 65 | 2 | shumate_vector_index_description_add_has_index (desc, "baz", "qux"); | |
| 66 |
1/2✗ Branch 18 → 19 not taken.
✓ Branch 18 → 20 taken 2 times.
|
2 | g_assert_true (shumate_vector_index_description_has_layer (desc, "baz")); |
| 67 |
1/2✗ Branch 21 → 22 not taken.
✓ Branch 21 → 23 taken 2 times.
|
2 | g_assert_true (shumate_vector_index_description_has_field (desc, "baz", "qux")); |
| 68 |
1/2✗ Branch 24 → 25 not taken.
✓ Branch 24 → 26 taken 2 times.
|
2 | g_assert_true (shumate_vector_index_description_has_field_has_index (desc, "baz", "qux")); |
| 69 |
1/2✗ Branch 27 → 28 not taken.
✓ Branch 27 → 29 taken 2 times.
|
2 | g_assert_false (shumate_vector_index_description_has_value (desc, "baz", "qux", &value)); |
| 70 | |||
| 71 | 2 | shumate_vector_index_description_add (desc, "baz", "aaa", &value); | |
| 72 |
1/2✗ Branch 31 → 32 not taken.
✓ Branch 31 → 33 taken 2 times.
|
2 | g_assert_true (shumate_vector_index_description_has_field (desc, "baz", "aaa")); |
| 73 |
1/2✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 2 times.
|
2 | g_assert_false (shumate_vector_index_description_has_field_has_index (desc, "baz", "aaa")); |
| 74 |
1/2✗ Branch 37 → 38 not taken.
✓ Branch 37 → 39 taken 2 times.
|
2 | g_assert_true (shumate_vector_index_description_has_value (desc, "baz", "aaa", &value)); |
| 75 | |||
| 76 | 2 | shumate_vector_index_description_free (desc); | |
| 77 | 2 | } | |
| 78 | |||
| 79 | static ShumateVectorIndexBitset * | ||
| 80 | 14 | compute_bitset (ShumateVectorReader *reader, char *json, const char *layer, ShumateVectorIndexDescription **index_description_out) | |
| 81 | { | ||
| 82 | 14 | GError *error = NULL; | |
| 83 | 14 | ShumateVectorRenderScope scope; | |
| 84 | 28 | g_autoptr(JsonNode) node1 = NULL; | |
| 85 |
1/2✓ Branch 28 → 29 taken 14 times.
✗ Branch 28 → 30 not taken.
|
14 | g_autoptr(ShumateVectorExpression) expr1 = NULL; |
| 86 |
1/2✓ Branch 26 → 27 taken 14 times.
✗ Branch 26 → 28 not taken.
|
14 | g_autoptr(ShumateVectorIndexBitset) bitset1 = NULL; |
| 87 | |||
| 88 | 14 | scope.reader = shumate_vector_reader_iterate (reader); | |
| 89 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 14 times.
|
14 | g_assert_nonnull (scope.reader); |
| 90 | |||
| 91 | 14 | scope.index = NULL; | |
| 92 | 14 | scope.index_description = shumate_vector_index_description_new (); | |
| 93 | |||
| 94 | 14 | scope.zoom_level = 12; | |
| 95 | |||
| 96 | 14 | node1 = json_from_string (json, &error); | |
| 97 |
1/2✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 14 times.
|
14 | g_assert_no_error (error); |
| 98 | 14 | expr1 = shumate_vector_expression_from_json (node1, &error); | |
| 99 |
1/2✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 14 times.
|
14 | g_assert_no_error (error); |
| 100 | |||
| 101 | 14 | shumate_vector_expression_collect_indexes (expr1, layer, scope.index_description); | |
| 102 | |||
| 103 | 14 | shumate_vector_reader_iter_read_layer_by_name (scope.reader, layer); | |
| 104 | 14 | scope.source_layer_idx = shumate_vector_reader_iter_get_layer_index (scope.reader); | |
| 105 | 14 | shumate_vector_render_scope_index_layer (&scope); | |
| 106 | 14 | bitset1 = shumate_vector_expression_eval_bitset (expr1, &scope, NULL); | |
| 107 |
1/2✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 14 times.
|
14 | g_assert_nonnull (bitset1); |
| 108 | |||
| 109 |
2/2✓ Branch 19 → 20 taken 4 times.
✓ Branch 19 → 21 taken 10 times.
|
14 | if (index_description_out) |
| 110 | 4 | *index_description_out = g_steal_pointer (&scope.index_description); | |
| 111 | else | ||
| 112 | 10 | shumate_vector_index_description_free (scope.index_description); | |
| 113 | |||
| 114 |
1/2✓ Branch 22 → 23 taken 14 times.
✗ Branch 22 → 24 not taken.
|
14 | g_clear_pointer (&scope.index, shumate_vector_index_free); |
| 115 |
1/2✓ Branch 24 → 25 taken 14 times.
✗ Branch 24 → 26 not taken.
|
14 | g_clear_object (&scope.reader); |
| 116 | |||
| 117 |
1/2✓ Branch 26 → 27 taken 14 times.
✗ Branch 26 → 28 not taken.
|
14 | return g_steal_pointer (&bitset1); |
| 118 | } | ||
| 119 | |||
| 120 | static void | ||
| 121 | 2 | test_vector_index_eval (void) | |
| 122 | { | ||
| 123 | 2 | GError *error = NULL; | |
| 124 | 4 | g_autoptr(GBytes) vector_data = NULL; | |
| 125 |
1/2✓ Branch 70 → 71 taken 2 times.
✗ Branch 70 → 72 not taken.
|
2 | g_autoptr(ShumateVectorReader) reader = NULL; |
| 126 | 2 | ShumateVectorIndexBitset *bitset = NULL; | |
| 127 | 2 | ShumateVectorIndexDescription *index_description = NULL; | |
| 128 | |||
| 129 | 2 | vector_data = g_resources_lookup_data ("/org/gnome/shumate/Tests/0.pbf", G_RESOURCE_LOOKUP_FLAGS_NONE, NULL); | |
| 130 | 2 | g_assert_no_error (error); | |
| 131 | |||
| 132 | 2 | reader = shumate_vector_reader_new (vector_data); | |
| 133 | |||
| 134 | /* Test literals in eval_bitset() */ | ||
| 135 | 2 | bitset = compute_bitset (reader, "[\"all\", true, false]", "lines", NULL); | |
| 136 |
1/2✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 2 times.
|
2 | g_assert_false (shumate_vector_index_bitset_get (bitset, 0)); |
| 137 |
1/2✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 2 times.
|
2 | g_assert_false (shumate_vector_index_bitset_get (bitset, 1)); |
| 138 | 2 | shumate_vector_index_bitset_free (bitset); | |
| 139 | |||
| 140 | 2 | bitset = compute_bitset (reader, "[\"any\", true, false]", "lines", NULL); | |
| 141 |
1/2✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 2 times.
|
2 | g_assert_true (shumate_vector_index_bitset_get (bitset, 0)); |
| 142 |
1/2✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 2 times.
|
2 | g_assert_true (shumate_vector_index_bitset_get (bitset, 1)); |
| 143 | 2 | shumate_vector_index_bitset_free (bitset); | |
| 144 | |||
| 145 | 2 | bitset = compute_bitset (reader, "[\"in\", [\"geometry-type\"], [\"literal\", [\"LineString\", \"MultiLineString\"]]]", "lines", &index_description); | |
| 146 |
1/2✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 2 times.
|
2 | g_assert_true (shumate_vector_index_bitset_get (bitset, 0)); |
| 147 |
1/2✗ Branch 25 → 26 not taken.
✓ Branch 25 → 27 taken 2 times.
|
2 | g_assert_true (shumate_vector_index_bitset_get (bitset, 1)); |
| 148 |
1/2✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 2 times.
|
2 | g_assert_true (shumate_vector_index_description_has_broad_geometry_type (index_description, "lines")); |
| 149 | 2 | shumate_vector_index_bitset_free (bitset); | |
| 150 | 2 | shumate_vector_index_description_free (index_description); | |
| 151 | |||
| 152 | 2 | bitset = compute_bitset (reader, "[\"==\", [\"geometry-type\"], \"LineString\"]", "lines", &index_description); | |
| 153 |
1/2✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 2 times.
|
2 | g_assert_true (shumate_vector_index_bitset_get (bitset, 0)); |
| 154 |
1/2✗ Branch 37 → 38 not taken.
✓ Branch 37 → 39 taken 2 times.
|
2 | g_assert_true (shumate_vector_index_bitset_get (bitset, 1)); |
| 155 |
1/2✗ Branch 40 → 41 not taken.
✓ Branch 40 → 42 taken 2 times.
|
2 | g_assert_true (shumate_vector_index_description_has_broad_geometry_type (index_description, "lines")); |
| 156 | 2 | shumate_vector_index_bitset_free (bitset); | |
| 157 | 2 | shumate_vector_index_description_free (index_description); | |
| 158 | |||
| 159 | 2 | bitset = compute_bitset (reader, "[\"in\", [\"get\", \"name\"], [\"literal\", [\"test1\", \"helloworld\"]]]", "lines", NULL); | |
| 160 |
1/2✗ Branch 46 → 47 not taken.
✓ Branch 46 → 48 taken 2 times.
|
2 | g_assert_true (shumate_vector_index_bitset_get (bitset, 0)); |
| 161 |
1/2✗ Branch 49 → 50 not taken.
✓ Branch 49 → 51 taken 2 times.
|
2 | g_assert_false (shumate_vector_index_bitset_get (bitset, 1)); |
| 162 | 2 | shumate_vector_index_bitset_free (bitset); | |
| 163 | |||
| 164 | 2 | bitset = compute_bitset (reader, "[\"has\", \"name\"]", "lines", NULL); | |
| 165 |
1/2✗ Branch 54 → 55 not taken.
✓ Branch 54 → 56 taken 2 times.
|
2 | g_assert_true (shumate_vector_index_bitset_get (bitset, 0)); |
| 166 |
1/2✗ Branch 57 → 58 not taken.
✓ Branch 57 → 59 taken 2 times.
|
2 | g_assert_false (shumate_vector_index_bitset_get (bitset, 1)); |
| 167 | 2 | shumate_vector_index_bitset_free (bitset); | |
| 168 | |||
| 169 | /* Test fallback with an expression that isn't indexed */ | ||
| 170 | 2 | bitset = compute_bitset (reader, "[\">=\", [\"get\", \"number\"], [\"zoom\"]]", "polygons", NULL); | |
| 171 |
1/2✗ Branch 62 → 63 not taken.
✓ Branch 62 → 64 taken 2 times.
|
2 | g_assert_true (shumate_vector_index_bitset_get (bitset, 0)); |
| 172 |
1/2✗ Branch 65 → 66 not taken.
✓ Branch 65 → 67 taken 2 times.
|
2 | g_assert_false (shumate_vector_index_bitset_get (bitset, 1)); |
| 173 |
1/2✓ Branch 68 → 69 taken 2 times.
✗ Branch 68 → 70 not taken.
|
2 | shumate_vector_index_bitset_free (bitset); |
| 174 | 2 | } | |
| 175 | |||
| 176 | int | ||
| 177 | 2 | main (int argc, char *argv[]) | |
| 178 | { | ||
| 179 | 2 | g_test_init (&argc, &argv, NULL); | |
| 180 | |||
| 181 | 2 | g_test_add_func ("/vector-index/bitset", test_vector_index_bitset); | |
| 182 | 2 | g_test_add_func ("/vector-index/description", test_vector_index_description); | |
| 183 | 2 | g_test_add_func ("/vector-index/eval", test_vector_index_eval); | |
| 184 | |||
| 185 | 2 | return g_test_run (); | |
| 186 | } | ||
| 187 |