• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

realm / realm-core / nicola.cabiddu_1344

01 Feb 2024 09:26AM UTC coverage: 91.855% (-0.01%) from 91.865%
nicola.cabiddu_1344

Pull #7302

Evergreen

nicola-cab
lint
Pull Request #7302: expose sync user subscribe in the c-api

93022 of 171470 branches covered (0.0%)

22 of 22 new or added lines in 4 files covered. (100.0%)

81 existing lines in 12 files now uncovered.

235334 of 256203 relevant lines covered (91.85%)

6358312.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.53
/src/realm/array_key.cpp
1
/*************************************************************************
2
 *
3
 * Copyright 2016 Realm Inc.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 **************************************************************************/
18

19
#include <realm/array_key.hpp>
20
#include <realm/table.hpp>
21

22
namespace realm {
23

24
// This is used for linklists
25
template <>
26
void ArrayKeyBase<0>::verify() const
27
{
8,016✔
28
#ifdef REALM_DEBUG
8,016✔
29
    Array::verify();
8,016✔
30
    // We have to get parent until we reach the containing cluster
4,008✔
31
    auto parent = get_parent();
8,016✔
32
    size_t origin_obj_ndx;
8,016✔
33
    size_t origin_col_ndx = get_ndx_in_parent();
8,016✔
34
    Cluster* cluster = nullptr;
8,016✔
35
    do {
8,016✔
36
        REALM_ASSERT(parent);
8,016✔
37
        auto arr = dynamic_cast<Array*>(parent);
8,016✔
38
        REALM_ASSERT(arr);
8,016✔
39
        parent = arr->get_parent();
8,016✔
40
        // When we reach the cluster, the previous value of
4,008✔
41
        // origin_col_ndx will be the object index in the cluster.
4,008✔
42
        origin_obj_ndx = origin_col_ndx;
8,016✔
43
        // When we reach the cluster, arr will point to the ArrayRef leaf and the
4,008✔
44
        // origin_col_ndx will give the position in the cluster array.
4,008✔
45
        origin_col_ndx = arr->get_ndx_in_parent();
8,016✔
46
        cluster = dynamic_cast<Cluster*>(parent);
8,016✔
47
    } while (parent && !cluster);
8,016✔
48

4,008✔
49
    REALM_ASSERT(cluster);
8,016✔
50
    const Table* origin_table = cluster->get_owning_table();
8,016✔
51
    ObjKey origin_key = cluster->get_real_key(origin_obj_ndx);
8,016✔
52
    ColKey link_col_key = cluster->get_col_key(origin_col_ndx);
8,016✔
53

4,008✔
54
    TableRef target_table = origin_table->get_opposite_table(link_col_key);
8,016✔
55

4,008✔
56
    auto verify_link = [origin_table, link_col_key, origin_key](const Obj& target_obj) {
28,092✔
57
        auto cnt = target_obj.get_backlink_count(*origin_table, link_col_key);
28,092✔
58
        for (size_t i = 0; i < cnt; i++) {
9,019,671✔
59
            if (target_obj.get_backlink(*origin_table, link_col_key, i) == origin_key)
9,019,671✔
60
                return;
28,092✔
61
        }
9,019,671✔
62
        REALM_ASSERT(false);
14,046✔
UNCOV
63
    };
×
64

4,008✔
65
    // Verify that forward link has a corresponding backlink
4,008✔
66
    for (size_t i = 0; i < size(); ++i) {
36,108✔
67
        if (ObjKey target_key = get(i)) {
28,092✔
68
            auto target_obj = target_key.is_unresolved() ? target_table->try_get_tombstone(target_key)
14,103✔
69
                                                         : target_table->try_get_object(target_key);
28,035✔
70
            REALM_ASSERT(target_obj);
28,092✔
71
            verify_link(target_obj);
28,092✔
72
        }
28,092✔
73
    }
28,092✔
74
#endif
8,016✔
75
}
8,016✔
76

77
// This is used for single links
78
template <>
79
void ArrayKeyBase<1>::verify() const
80
{
1,158✔
81
#ifdef REALM_DEBUG
1,158✔
82
    Array::verify();
1,158✔
83
    REALM_ASSERT(dynamic_cast<Cluster*>(get_parent()));
1,158✔
84
    auto cluster = static_cast<Cluster*>(get_parent());
1,158✔
85
    const Table* origin_table = cluster->get_owning_table();
1,158✔
86
    ColKey link_col_key = cluster->get_col_key(get_ndx_in_parent());
1,158✔
87

564✔
88
    ConstTableRef target_table = origin_table->get_opposite_table(link_col_key);
1,158✔
89

564✔
90
    auto verify_link = [origin_table, link_col_key](const Obj& target_obj, ObjKey origin_key) {
6,888✔
91
        auto cnt = target_obj.get_backlink_count(*origin_table, link_col_key);
6,888✔
92
        for (size_t i = 0; i < cnt; i++) {
3,003,942✔
93
            if (target_obj.get_backlink(*origin_table, link_col_key, i) == origin_key)
3,003,942✔
94
                return;
6,888✔
95
        }
3,003,942✔
96
        REALM_ASSERT(false);
3,444✔
97
    };
×
98

564✔
99
    // Verify that forward link has a corresponding backlink
564✔
100
    for (size_t i = 0; i < size(); ++i) {
17,742✔
101
        if (ObjKey target_key = get(i)) {
16,584✔
102
            ObjKey origin_key = cluster->get_real_key(i);
6,888✔
103

3,444✔
104
            auto target_obj = target_key.is_unresolved() ? target_table->try_get_tombstone(target_key)
3,459✔
105
                                                         : target_table->try_get_object(target_key);
6,873✔
106
            REALM_ASSERT(target_obj);
6,888✔
107
            verify_link(target_obj, origin_key);
6,888✔
108
        }
6,888✔
109
    }
16,584✔
110
#endif
1,158✔
111
}
1,158✔
112

113
} // namespace realm
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc