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

realm / realm-core / 2032

13 Feb 2024 12:49PM UTC coverage: 91.866% (+0.02%) from 91.844%
2032

push

Evergreen

web-flow
Add RealmConfig::needs_file_format_upgrade (#7336)

93052 of 171506 branches covered (54.26%)

36 of 45 new or added lines in 6 files covered. (80.0%)

79 existing lines in 15 files now uncovered.

235424 of 256268 relevant lines covered (91.87%)

6438906.58 hits per line

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

89.16
/src/realm/object-store/c_api/config.cpp
1
#include <realm/object-store/c_api/types.hpp>
2
#include <realm/object-store/c_api/util.hpp>
3

4
using namespace realm;
5
using namespace realm::c_api;
6

7
RLM_API realm_config_t* realm_config_new()
8
{
406✔
9
    return new realm_config_t{};
406✔
10
}
406✔
11

12
RLM_API const char* realm_config_get_path(const realm_config_t* config)
13
{
2✔
14
    return config->path.c_str();
2✔
15
}
2✔
16

17
RLM_API void realm_config_set_path(realm_config_t* config, const char* path)
18
{
372✔
19
    config->path = path;
372✔
20
}
372✔
21

22
RLM_API size_t realm_config_get_encryption_key(const realm_config_t* config, uint8_t* out_key)
23
{
2✔
24
    if (out_key) {
2✔
25
        std::copy(config->encryption_key.begin(), config->encryption_key.end(), out_key);
2✔
26
    }
2✔
27
    return config->encryption_key.size();
2✔
28
}
2✔
29

30
RLM_API bool realm_config_set_encryption_key(realm_config_t* config, const uint8_t* key, size_t key_size)
31
{
4✔
32
    return wrap_err([=]() {
4✔
33
        if (key_size != 0 && key_size != 64) {
4✔
34
            throw InvalidEncryptionKey();
2✔
35
        }
2✔
36

1✔
37
        config->encryption_key.clear();
2✔
38
        std::copy(key, key + key_size, std::back_inserter(config->encryption_key));
2✔
39
        return true;
2✔
40
    });
2✔
41
}
4✔
42

43
RLM_API realm_schema_t* realm_config_get_schema(const realm_config_t* config)
44
{
4✔
45
    return wrap_err([=]() -> realm_schema_t* {
4✔
46
        if (config->schema) {
4✔
47
            return new realm_schema_t{std::make_unique<Schema>(*config->schema)};
2✔
48
        }
2✔
49
        else {
2✔
50
            return nullptr;
2✔
51
        }
2✔
52
    });
4✔
53
}
4✔
54

55
RLM_API void realm_config_set_schema(realm_config_t* config, const realm_schema_t* schema)
56
{
44✔
57
    if (schema) {
44✔
58
        config->schema = *schema->ptr;
42✔
59
    }
42✔
60
    else {
2✔
61
        config->schema = util::none;
2✔
62
    }
2✔
63
}
44✔
64

65
RLM_API uint64_t realm_config_get_schema_version(const realm_config_t* config)
66
{
2✔
67
    return config->schema_version;
2✔
68
}
2✔
69

70
RLM_API void realm_config_set_schema_version(realm_config_t* config, uint64_t version)
71
{
46✔
72
    config->schema_version = version;
46✔
73
}
46✔
74

75
RLM_API realm_schema_mode_e realm_config_get_schema_mode(const realm_config_t* config)
76
{
16✔
77
    return to_capi(config->schema_mode);
16✔
78
}
16✔
79

80
RLM_API void realm_config_set_schema_mode(realm_config_t* config, realm_schema_mode_e mode)
81
{
382✔
82
    config->schema_mode = from_capi(mode);
382✔
83
}
382✔
84

85
RLM_API realm_schema_subset_mode_e realm_config_get_schema_subset_mode(const realm_config_t* config)
86
{
8✔
87
    return to_capi(config->schema_subset_mode);
8✔
88
}
8✔
89

90
RLM_API void realm_config_set_schema_subset_mode(realm_config_t* config, realm_schema_subset_mode_e subset_mode)
91
{
8✔
92
    config->schema_subset_mode = from_capi(subset_mode);
8✔
93
}
8✔
94

95
RLM_API void realm_config_set_migration_function(realm_config_t* config, realm_migration_func_t func,
96
                                                 realm_userdata_t userdata, realm_free_userdata_func_t callback)
97
{
16✔
98
    if (func) {
16✔
99
        auto migration_func = [=](SharedRealm old_realm, SharedRealm new_realm, Schema& schema) {
13✔
100
            realm_t r1{old_realm};
10✔
101
            realm_t r2{new_realm};
10✔
102
            realm_schema_t sch{&schema};
10✔
103
            if (!(func)(userdata, &r1, &r2, &sch)) {
10✔
104
                throw CallbackFailed{ErrorStorage::get_thread_local()->get_and_clear_user_code_error()};
4✔
105
            }
4✔
106
        };
10✔
107
        config->migration_function = std::move(migration_func);
16✔
108
    }
16✔
109
    else {
×
110
        config->migration_function = nullptr;
×
111
    }
×
112
    if (callback) {
16✔
113
        config->free_functions.emplace(userdata, callback);
×
114
    }
×
115
}
16✔
116

117
RLM_API void realm_config_set_data_initialization_function(realm_config_t* config,
118
                                                           realm_data_initialization_func_t func,
119
                                                           realm_userdata_t userdata,
120
                                                           realm_free_userdata_func_t callback)
121
{
6✔
122
    if (func) {
6✔
123
        auto init_func = [=](SharedRealm realm) {
6✔
124
            realm_t r{realm};
6✔
125
            if (!(func)(userdata, &r)) {
6✔
126
                throw CallbackFailed{ErrorStorage::get_thread_local()->get_and_clear_user_code_error()};
2✔
127
            }
2✔
128
        };
6✔
129
        config->initialization_function = std::move(init_func);
6✔
130
    }
6✔
131
    else {
×
132
        config->initialization_function = nullptr;
×
133
    }
×
134
    if (callback) {
6✔
135
        config->free_functions.emplace(userdata, callback);
4✔
136
    }
4✔
137
}
6✔
138

139
RLM_API void realm_config_set_should_compact_on_launch_function(realm_config_t* config,
140
                                                                realm_should_compact_on_launch_func_t func,
141
                                                                realm_userdata_t userdata,
142
                                                                realm_free_userdata_func_t callback)
143
{
4✔
144
    if (func) {
4✔
145
        auto should_func = [=](uint64_t total_bytes, uint64_t used_bytes) -> bool {
4✔
146
            auto result = func(userdata, total_bytes, used_bytes);
4✔
147
            if (auto user_code_error = ErrorStorage::get_thread_local()->get_and_clear_user_code_error())
4✔
148
                throw CallbackFailed{user_code_error};
×
149
            return result;
4✔
150
        };
4✔
151
        config->should_compact_on_launch_function = std::move(should_func);
4✔
152
    }
4✔
153
    else {
×
154
        config->should_compact_on_launch_function = nullptr;
×
155
    }
×
156
    if (callback) {
4✔
157
        config->free_functions.emplace(userdata, callback);
4✔
158
    }
4✔
159
}
4✔
160

161
RLM_API bool realm_config_get_disable_format_upgrade(const realm_config_t* config)
162
{
4✔
163
    return config->disable_format_upgrade;
4✔
164
}
4✔
165

166
RLM_API bool realm_config_needs_file_format_upgrade(const realm_config_t* config)
NEW
167
{
×
NEW
168
    return config->needs_file_format_upgrade();
×
NEW
169
}
×
170

171
RLM_API void realm_config_set_disable_format_upgrade(realm_config_t* config, bool b)
172
{
4✔
173
    config->disable_format_upgrade = b;
4✔
174
}
4✔
175

176
RLM_API bool realm_config_get_force_sync_history(const realm_config_t* config)
177
{
4✔
178
    return config->force_sync_history;
4✔
179
}
4✔
180

181
RLM_API void realm_config_set_force_sync_history(realm_config_t* config, bool b)
182
{
4✔
183
    config->force_sync_history = b;
4✔
184
}
4✔
185

186
RLM_API bool realm_config_get_automatic_change_notifications(const realm_config_t* config)
187
{
4✔
188
    return config->automatic_change_notifications;
4✔
189
}
4✔
190

191
RLM_API void realm_config_set_automatic_change_notifications(realm_config_t* config, bool b)
192
{
334✔
193
    config->automatic_change_notifications = b;
334✔
194
}
334✔
195

196
RLM_API void realm_config_set_scheduler(realm_config_t* config, const realm_scheduler_t* scheduler)
197
{
2✔
198
    config->scheduler = *scheduler;
2✔
199
}
2✔
200

201
RLM_API uint64_t realm_config_get_max_number_of_active_versions(const realm_config_t* config)
202
{
2✔
203
    return uint64_t(config->max_number_of_active_versions);
2✔
204
}
2✔
205

206
RLM_API void realm_config_set_max_number_of_active_versions(realm_config_t* config, uint64_t n)
207
{
332✔
208
    config->max_number_of_active_versions = uint_fast64_t(n);
332✔
209
}
332✔
210

211
RLM_API void realm_config_set_in_memory(realm_config_t* realm_config, bool value) noexcept
212
{
2✔
213
    realm_config->in_memory = value;
2✔
214
}
2✔
215

216
RLM_API bool realm_config_get_in_memory(realm_config_t* realm_config) noexcept
217
{
2✔
218
    return realm_config->in_memory;
2✔
219
}
2✔
220

221
RLM_API void realm_config_set_fifo_path(realm_config_t* realm_config, const char* fifo_path)
222
{
2✔
223
    realm_config->fifo_files_fallback_path = fifo_path;
2✔
224
}
2✔
225

226
RLM_API const char* realm_config_get_fifo_path(realm_config_t* realm_config) noexcept
227
{
2✔
228
    return realm_config->fifo_files_fallback_path.c_str();
2✔
229
}
2✔
230

231
RLM_API void realm_config_set_cached(realm_config_t* realm_config, bool cached) noexcept
232
{
2✔
233
    realm_config->cache = cached;
2✔
234
}
2✔
235

236
RLM_API bool realm_config_get_cached(realm_config_t* realm_config) noexcept
237
{
2✔
238
    return realm_config->cache;
2✔
239
}
2✔
240

241
RLM_API void realm_config_set_automatic_backlink_handling(realm_config_t* realm_config,
242
                                                          bool enable_automatic_handling) noexcept
243
{
×
244
    realm_config->automatically_handle_backlinks_in_migrations = enable_automatic_handling;
×
245
}
×
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

© 2026 Coveralls, Inc