|
15 | 15 | #include "c4ExceptionUtils.hh" |
16 | 16 | #include "fleece/InstanceCounted.hh" |
17 | 17 | #include "catch.hpp" |
| 18 | +#include "DatabaseImpl.hh" |
18 | 19 | #include "NumConversion.hh" |
19 | 20 | #include "Actor.hh" |
20 | 21 | #include "URLTransformer.hh" |
|
25 | 26 | # include "Error.hh" |
26 | 27 | # include <winerror.h> |
27 | 28 | #endif |
| 29 | +#include <sstream> |
28 | 30 |
|
29 | 31 | using namespace fleece; |
30 | 32 | using namespace std; |
@@ -138,6 +140,29 @@ TEST_CASE("C4Error Reporting Macros", "[Errors][C]") { |
138 | 140 | #endif |
139 | 141 | } |
140 | 142 |
|
| 143 | +TEST_CASE_METHOD(C4Test, "Database Flag FullSync", "[Database][C]") { |
| 144 | + // Ensure that, by default, diskSyncFull is false. |
| 145 | + CHECK(!litecore::asInternal(db)->dataFile()->options().diskSyncFull); |
| 146 | + |
| 147 | + C4DatabaseConfig2 config = *c4db_getConfig2(db); |
| 148 | + config.flags |= kC4DB_DiskSyncFull; |
| 149 | + |
| 150 | + std::stringstream ss; |
| 151 | + ss << std::string(c4db_getName(db)) << "_" << c4_now(); |
| 152 | + c4::ref<C4Database> dbWithFullSync = c4db_openNamed(slice(ss.str().c_str()), &config, ERROR_INFO()); |
| 153 | + // The flag in config is passed to DataFile options. |
| 154 | + CHECK(litecore::asInternal(dbWithFullSync)->dataFile()->options().diskSyncFull); |
| 155 | + |
| 156 | + config.flags &= ~kC4DB_DiskSyncFull; |
| 157 | + c4::ref<C4Database> otherConnection = c4db_openNamed(c4db_getName(dbWithFullSync), &config, ERROR_INFO()); |
| 158 | + // The flag applies per connection opened with the config. |
| 159 | + CHECK(!litecore::asInternal(otherConnection)->dataFile()->options().diskSyncFull); |
| 160 | + |
| 161 | + c4::ref<C4Database> againConnection = c4db_openAgain(dbWithFullSync, ERROR_INFO()); |
| 162 | + // The flag is passed to database opened by openAgain. |
| 163 | + CHECK(litecore::asInternal(againConnection)->dataFile()->options().diskSyncFull); |
| 164 | +} |
| 165 | + |
141 | 166 | #pragma mark - INSTANCECOUNTED: |
142 | 167 |
|
143 | 168 | namespace { |
|
0 commit comments