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

realm / realm-core / github_pull_request_292823

11 Apr 2024 09:48AM UTC coverage: 91.821% (+0.03%) from 91.792%
github_pull_request_292823

Pull #7579

Evergreen

nielsenko
Use the correct target conditional
Pull Request #7579: Use the correct target conditional

94862 of 175770 branches covered (53.97%)

0 of 1 new or added line in 1 file covered. (0.0%)

67 existing lines in 17 files now uncovered.

242956 of 264596 relevant lines covered (91.82%)

5761611.15 hits per line

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

98.61
/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
{
7,854✔
28
#ifdef REALM_DEBUG
7,854✔
29
    Array::verify();
7,854✔
30
    // We have to get parent until we reach the containing cluster
3,927✔
31
    auto parent = get_parent();
7,854✔
32
    size_t origin_obj_ndx;
7,854✔
33
    size_t origin_col_ndx = get_ndx_in_parent();
7,854✔
34
    Cluster* cluster = nullptr;
7,854✔
35
    do {
7,854✔
36
        REALM_ASSERT(parent);
7,854✔
37
        auto arr = dynamic_cast<Array*>(parent);
7,854✔
38
        REALM_ASSERT(arr);
7,854✔
39
        parent = arr->get_parent();
7,854✔
40
        // When we reach the cluster, the previous value of
3,927✔
41
        // origin_col_ndx will be the object index in the cluster.
3,927✔
42
        origin_obj_ndx = origin_col_ndx;
7,854✔
43
        // When we reach the cluster, arr will point to the ArrayRef leaf and the
3,927✔
44
        // origin_col_ndx will give the position in the cluster array.
3,927✔
45
        origin_col_ndx = arr->get_ndx_in_parent();
7,854✔
46
        cluster = dynamic_cast<Cluster*>(parent);
7,854✔
47
    } while (parent && !cluster);
7,854✔
48

3,927✔
49
    REALM_ASSERT(cluster);
7,854✔
50
    const Table* origin_table = cluster->get_owning_table();
7,854✔
51
    ObjKey origin_key = cluster->get_real_key(origin_obj_ndx);
7,854✔
52
    ColKey link_col_key = cluster->get_col_key(origin_col_ndx);
7,854✔
53

3,927✔
54
    TableRef target_table = origin_table->get_opposite_table(link_col_key);
7,854✔
55

3,927✔
56
    auto verify_link = [origin_table, link_col_key, origin_key](const Obj& target_obj) {
27,420✔
57
        auto cnt = target_obj.get_backlink_count(*origin_table, link_col_key);
27,420✔
58
        for (size_t i = 0; i < cnt; i++) {
9,018,375✔
59
            if (target_obj.get_backlink(*origin_table, link_col_key, i) == origin_key)
9,018,375✔
60
                return;
27,420✔
61
        }
9,018,375✔
62
        REALM_ASSERT(false);
13,710✔
UNCOV
63
    };
×
64

3,927✔
65
    // Verify that forward link has a corresponding backlink
3,927✔
66
    for (size_t i = 0; i < size(); ++i) {
35,274✔
67
        if (ObjKey target_key = get(i)) {
27,420✔
68
            auto target_obj = target_key.is_unresolved() ? target_table->try_get_tombstone(target_key)
13,767✔
69
                                                         : target_table->try_get_object(target_key);
27,363✔
70
            REALM_ASSERT(target_obj);
27,420✔
71
            verify_link(target_obj);
27,420✔
72
        }
27,420✔
73
    }
27,420✔
74
#endif
7,854✔
75
}
7,854✔
76

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

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

915✔
90
    // Verify that forward link has a corresponding backlink
915✔
91
    for (size_t i = 0; i < size(); ++i) {
145,794✔
92
        if (ObjKey target_key = get(i)) {
144,108✔
93
            ObjKey origin_key = cluster->get_real_key(i);
126,678✔
94

63,345✔
95
            auto target_obj = target_key.is_unresolved() ? target_table->try_get_tombstone(target_key)
63,360✔
96
                                                         : target_table->try_get_object(target_key);
126,663✔
97
            REALM_ASSERT(target_obj);
126,678✔
98
            target_obj.verify_backlink(*origin_table, link_col_key, origin_key);
126,678✔
99
        }
126,678✔
100
    }
144,108✔
101
#endif
1,686✔
102
}
1,686✔
103

104
} // 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