From 7c1082ef121ac96c0a7eb63123113e167942d0f5 Mon Sep 17 00:00:00 2001 From: callumbirks <73551885+callumbirks@users.noreply.github.com> Date: Fri, 7 Jul 2023 17:12:46 +0100 Subject: [PATCH 1/6] CBL-4471: Xcode 14.3 unqualified calls to std::move --- LiteCore/Storage/Record.hh | 4 ++-- LiteCore/Support/Batcher.hh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LiteCore/Storage/Record.hh b/LiteCore/Storage/Record.hh index 5dcf5e7d3..2147bed81 100644 --- a/LiteCore/Storage/Record.hh +++ b/LiteCore/Storage/Record.hh @@ -100,7 +100,7 @@ namespace litecore { // Leave _body alone if the new body is identical; this prevents a doc's body from // being swapped out when clients are using Fleece values pointing into it. if ( slice(body) != _body || !_body ) { - _body = move(body); + _body = std::move(body); _bodySize = _body.size; } } @@ -109,7 +109,7 @@ namespace litecore { void setExtra(SLICE extra) { // Same thing as setBody: there may be Fleece objects (other revs) in _extra. if ( slice(extra) != _extra || !_extra ) { - _extra = move(extra); + _extra = std::move(extra); _extraSize = _extra.size; } } diff --git a/LiteCore/Support/Batcher.hh b/LiteCore/Support/Batcher.hh index 44e18f890..fed15fe6a 100644 --- a/LiteCore/Support/Batcher.hh +++ b/LiteCore/Support/Batcher.hh @@ -69,7 +69,7 @@ namespace litecore::actor { if ( gen < _generation ) return {}; _scheduled = false; ++_generation; - return move(_items); + return std::move(_items); } private: From 9a09543593adbae26469a14ca685f66163fcb615 Mon Sep 17 00:00:00 2001 From: jianminzhao <76990468+jianminzhao@users.noreply.github.com> Date: Mon, 10 Jul 2023 20:53:22 -0700 Subject: [PATCH 2/6] CBL-4638: Decoded timestamps appear incorrect (#1832) * CBL-4638: Decoded timestamps appear incorrect 1. There is no change in the binary loggers. 2. In the header of the decoded log file, we converted the timestamp into the UTC time, instead of the local time, to make it independent of where the binary is decoded. 3. Fixed a mistaken application of the time zone offset when we decode the timestamp into the local time for the console log. 4. Informally, we insert the timestamp to the name of log file. Meanwhile, as noted by above (2), the header of the log file includes the timestamp. We added test to ensure they are consistent. --- LiteCore/Support/LogDecoder.cc | 22 +++++++++--------- LiteCore/Support/LogDecoder.hh | 2 +- LiteCore/Support/Logging.cc | 3 +++ LiteCore/Support/Logging.hh | 3 +++ LiteCore/tests/LogEncoderTest.cc | 38 ++++++++++++++++++++++++++++++-- 5 files changed, 55 insertions(+), 13 deletions(-) diff --git a/LiteCore/Support/LogDecoder.cc b/LiteCore/Support/LogDecoder.cc index 8252e7cdd..49ae0a17e 100644 --- a/LiteCore/Support/LogDecoder.cc +++ b/LiteCore/Support/LogDecoder.cc @@ -51,11 +51,15 @@ namespace litecore { return {secs, microsecs}; } - void LogIterator::writeTimestamp(Timestamp t, ostream& out) { + void LogIterator::writeTimestamp(Timestamp t, ostream& out, bool inUtcTime) { local_time tp{seconds(t.secs) + microseconds(t.microsecs)}; - struct tm tmpTime = FromTimestamp(duration_cast(tp.time_since_epoch())); - tp -= GetLocalTZOffset(&tmpTime, true); - out << format("%T| ", tp); + const char* fmt = "%TZ| "; + if ( !inUtcTime ) { + struct tm tmpTime = FromTimestamp(duration_cast(tp.time_since_epoch())); + tp += GetLocalTZOffset(&tmpTime, true); + fmt = "%T| "; + } + out << format(fmt, tp); } void LogIterator::writeISO8601DateTime(Timestamp t, std::ostream& out) { @@ -66,7 +70,7 @@ namespace litecore { string LogIterator::formatDate(Timestamp t) { local_time tp(seconds(t.secs) + microseconds(t.microsecs)); struct tm tmpTime = FromTimestamp(duration_cast(tp.time_since_epoch())); - tp -= GetLocalTZOffset(&tmpTime, true); + tp += GetLocalTZOffset(&tmpTime, true); stringstream out; out << format("%c", tp); return out.str(); @@ -91,7 +95,7 @@ namespace litecore { while ( next() ) { auto ts = timestamp(); if ( start && ts < *start ) continue; - writeTimestamp(ts, out); + writeTimestamp(ts, out, true); string levelName; if ( level() >= 0 && level() < levelNames.size() ) levelName = levelNames[level()]; @@ -149,11 +153,9 @@ namespace litecore { void LogDecoder::decodeTo(ostream& out, const std::vector& levelNames, std::optional startingAt) { if ( !startingAt || *startingAt < Timestamp{_startTime, 0} ) { - writeTimestamp({_startTime, 0}, out); + writeTimestamp({_startTime, 0}, out, true); local_time tp{seconds(_startTime)}; - struct tm tmpTime = FromTimestamp(duration_cast(tp.time_since_epoch())); - tp -= GetLocalTZOffset(&tmpTime, true); - out << "---- Logging begins on " << format("%A, %x", tp) << " ----" << endl; + out << "---- Logging begins on " << format("%A %FT%TZ", tp) << " ----" << endl; } LogIterator::decodeTo(out, levelNames, startingAt); diff --git a/LiteCore/Support/LogDecoder.hh b/LiteCore/Support/LogDecoder.hh index 44e7d71c0..187bcc22c 100644 --- a/LiteCore/Support/LogDecoder.hh +++ b/LiteCore/Support/LogDecoder.hh @@ -68,7 +68,7 @@ namespace litecore { static Timestamp now(); static std::string formatDate(Timestamp); static void writeISO8601DateTime(Timestamp, std::ostream&); - static void writeTimestamp(Timestamp, std::ostream&); + static void writeTimestamp(Timestamp, std::ostream&, bool inUtcTime = false); static void writeHeader(const std::string& levelName, const std::string& domainName, std::ostream&); }; diff --git a/LiteCore/Support/Logging.cc b/LiteCore/Support/Logging.cc index ccb3e89f9..94990da7f 100644 --- a/LiteCore/Support/Logging.cc +++ b/LiteCore/Support/Logging.cc @@ -92,6 +92,9 @@ namespace litecore { << CBL_LOG_EXTENSION; return ss.str(); } +#ifdef LITECORE_CPPTEST + string createLogPath_forUnitTest(LogLevel level) { return createLogPath(level); } +#endif static void setupFileOut() { for ( int i = 0; kLevelNames[i]; i++ ) { diff --git a/LiteCore/Support/Logging.hh b/LiteCore/Support/Logging.hh index 1f81eb670..9b5760b08 100644 --- a/LiteCore/Support/Logging.hh +++ b/LiteCore/Support/Logging.hh @@ -271,4 +271,7 @@ namespace litecore { mutable unsigned _objectRef{0}; }; +#ifdef LITECORE_CPPTEST + std::string createLogPath_forUnitTest(LogLevel level); +#endif } // namespace litecore diff --git a/LiteCore/tests/LogEncoderTest.cc b/LiteCore/tests/LogEncoderTest.cc index 74a231d69..ecc922c60 100644 --- a/LiteCore/tests/LogEncoderTest.cc +++ b/LiteCore/tests/LogEncoderTest.cc @@ -15,6 +15,7 @@ #include "LogDecoder.hh" #include "LiteCoreTest.hh" #include "StringUtil.hh" +#include "ParseDate.hh" #include "fleece/PlatformCompat.hh" #include #include @@ -22,8 +23,9 @@ using namespace std; -#define DATESTAMP "\\w+, \\d{2}/\\d{2}/\\d{2}" -#define TIMESTAMP "\\d{2}:\\d{2}:\\d{2}\\.\\d{6}\\| " +// These formats are used in the decoded log files. They are UTC times. +#define DATESTAMP "\\w+ \\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z" +#define TIMESTAMP "\\d{2}:\\d{2}:\\d{2}\\.\\d{6}Z\\| " constexpr size_t kFolderBufSize = 64; @@ -55,6 +57,10 @@ static string dumpLog(const string& encoded, const vector& levelNames) { } TEST_CASE("LogEncoder formatting", "[Log]") { + // For checking the timestamp in the path to the binary log file. +#ifdef LITECORE_CPPTEST + string logPath = litecore::createLogPath_forUnitTest(LogLevel::Info); +#endif stringstream out; { LogEncoder logger(out, LogLevel::Info); @@ -84,6 +90,34 @@ TEST_CASE("LogEncoder formatting", "[Log]") { "Int 1234567890, Long 234567890, LongLong 123456789123456789, Size 1234567890, Char @\\n" TIMESTAMP "String is 'C string', slice is 'hello' \\(hex 68656c6c6f\\)\\n"); CHECK(regex_match(result, expected)); + +#ifdef LITECORE_CPPTEST + // We insert timestamp in milliseconds (w.r.t. UTC) in the path to the binary log files. + // We also add the timestamp inside the log. When decoded to string, it is + // represented as UTC time, like, "Monday 2023-07-03T19:25:01Z" + // We want to ensure they are consistent. + regex catchUTCTimeTag{"^" TIMESTAMP "---- Logging begins on (" DATESTAMP ")"}; + smatch m; + REQUIRE(regex_search(result, m, catchUTCTimeTag)); + CHECK(m.size() == 2); + string utcTimeTag = m[1].str(); + // Remove the weekday name + REQUIRE(regex_search(utcTimeTag, m, regex{"[^0-9]*"})); + string utctime = m.suffix().str(); + auto utctimestampInLog = fleece::ParseISO8601Date(slice(utctime)); + // From milliseconds to seconds + utctimestampInLog /= 1000; + + REQUIRE(regex_search(logPath, m, regex{"cbl_info_([0-9]*)\\.cbllog$"})); + string timestampOnLogFilePath = m[1].str(); + // chomp it to seconds + REQUIRE(timestampOnLogFilePath.length() > 3); + timestampOnLogFilePath = timestampOnLogFilePath.substr(0, timestampOnLogFilePath.length() - 3); + + stringstream ss; + ss << utctimestampInLog; + CHECK(ss.str() == timestampOnLogFilePath); +#endif } TEST_CASE("LogEncoder levels/domains", "[Log]") { From 627ab83d3deb655fdbd3a67db463e95003d842f0 Mon Sep 17 00:00:00 2001 From: jianminzhao <76990468+jianminzhao@users.noreply.github.com> Date: Tue, 11 Jul 2023 23:03:05 -0700 Subject: [PATCH 3/6] CBL-4687: Add Test_CE to Xcode configuration for unit tests (#1837) GitHub action, "Xcode Build," builds scheme "LiteCore C++ Tests." We will build it with this new config, Test_CE, which is duplicated from Debug but has the c++ preprocessor, LITECORE_CPPTEST, defined. --- .github/workflows/xcodebuild.yml | 4 +- Xcode/LiteCore.xcodeproj/project.pbxproj | 296 ++++++++++++++++++ .../xcschemes/LiteCore C++ Tests.xcscheme | 4 +- Xcode/xcconfigs/CppTests.xcconfig | 1 + Xcode/xcconfigs/LiteCore static.xcconfig | 1 + vendor/fleece | 2 +- 6 files changed, 304 insertions(+), 4 deletions(-) diff --git a/.github/workflows/xcodebuild.yml b/.github/workflows/xcodebuild.yml index 0e8a8d797..2e8ce363d 100644 --- a/.github/workflows/xcodebuild.yml +++ b/.github/workflows/xcodebuild.yml @@ -21,7 +21,9 @@ on: env: # Customize the Xcode configuration here (Release or Debug) # NOTE: If we decide to archive the build products we should build with RelWithDebInfo instead. + # Test_CE is a dupplicate of Debug except it has the c++ define, LITECORE_CPPTEST, activated. CONFIGURATION: Debug + CONFIGURATION_CPP: Test_CE jobs: build: @@ -40,7 +42,7 @@ jobs: project: Xcode/LiteCore.xcodeproj scheme: LiteCore C++ Tests destination: platform=macOS - configuration: $CONFIGURATION + configuration: $CONFIGURATION_CPP action: build - name: "Build C4Tests" diff --git a/Xcode/LiteCore.xcodeproj/project.pbxproj b/Xcode/LiteCore.xcodeproj/project.pbxproj index 93864317f..99d8b7747 100644 --- a/Xcode/LiteCore.xcodeproj/project.pbxproj +++ b/Xcode/LiteCore.xcodeproj/project.pbxproj @@ -5671,6 +5671,285 @@ }; name = Release; }; + D6200BF62A57441D00790C0F /* Test_CE */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 273E9FBA1C519A1B003115A6 /* Project_Debug.xcconfig */; + buildSettings = { + HEADER_SEARCH_PATHS = ( + "$(SRCROOT)/../vendor/SQLiteCpp/sqlite3/", + "$(SOCKPP)/include", + "$(MBEDTLS)/include", + "$(MBEDCRYPTO)/include", + "$(inherited)", + ); + PATH = "${PATH}:/opt/homebrew/bin:/opt/homebrew/sbin"; + }; + name = Test_CE; + }; + D6200BF72A57441D00790C0F /* Test_CE */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 273E9FAA1C519A1B003115A6 /* LiteCore static.xcconfig */; + buildSettings = { + }; + name = Test_CE; + }; + D6200BF82A57441D00790C0F /* Test_CE */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 273E9FB01C519A1B003115A6 /* LiteCore-dylib.xcconfig */; + buildSettings = { + }; + name = Test_CE; + }; + D6200BF92A57441D00790C0F /* Test_CE */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 27B649592069731B00FC12F7 /* LiteCore-framework.xcconfig */; + buildSettings = { + CURRENT_PROJECT_VERSION = 1; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Test_CE; + }; + D6200BFA2A57441D00790C0F /* Test_CE */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 27FC81F31EAAB1000028E38E /* REST-static.xcconfig */; + buildSettings = { + }; + name = Test_CE; + }; + D6200BFB2A57441D00790C0F /* Test_CE */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 2771A0A5228624DE00B18E0A /* LiteCoreWebSocket.xcconfig */; + buildSettings = { + }; + name = Test_CE; + }; + D6200BFC2A57441D00790C0F /* Test_CE */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 272850EC1E9D4B7D009CA22F /* CppTests.xcconfig */; + buildSettings = { + }; + name = Test_CE; + }; + D6200BFD2A57441D00790C0F /* Test_CE */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 273E9FB61C519A1B003115A6 /* C4Tests.xcconfig */; + buildSettings = { + }; + name = Test_CE; + }; + D6200BFE2A57441D00790C0F /* Test_CE */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 273E9FAD1C519A1B003115A6 /* LiteCore XCTests.xcconfig */; + buildSettings = { + }; + name = Test_CE; + }; + D6200BFF2A57441D00790C0F /* Test_CE */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 27DF7D6C1F42399E0022F3DF /* SQLite_Debug.xcconfig */; + buildSettings = { + }; + name = Test_CE; + }; + D6200C002A57441D00790C0F /* Test_CE */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 273E9FBF1C519A1B003115A6 /* Tokenizer.xcconfig */; + buildSettings = { + }; + name = Test_CE; + }; + D6200C012A57441D00790C0F /* Test_CE */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 2777146C1C5D6BDB003C0287 /* static_lib.xcconfig */; + buildSettings = { + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_STYLE = Automatic; + COPY_PHASE_STRIP = NO; + DEBUGGING_SYMBOLS = YES; + DEBUG_INFORMATION_FORMAT = dwarf; + DEVELOPMENT_TEAM = N2Q372V7W2; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_GENERATE_DEBUGGING_SYMBOLS = YES; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + OTHER_CFLAGS = ""; + OTHER_LDFLAGS = ""; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Test_CE; + }; + D6200C022A57441D00790C0F /* Test_CE */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 272850EC1E9D4B7D009CA22F /* CppTests.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + DEBUG_INFORMATION_FORMAT = dwarf; + DEVELOPMENT_TEAM = N2Q372V7W2; + GCC_C_LANGUAGE_STANDARD = gnu99; + INFOPLIST_FILE = "LiteCore-iOS shell copy-Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@executable_path", + ); + ONLY_ACTIVE_ARCH = YES; + PRODUCT_BUNDLE_IDENTIFIER = org.couchbase.LiteCoreTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Test_CE; + }; + D6200C032A57441D00790C0F /* Test_CE */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + DEBUG_INFORMATION_FORMAT = dwarf; + DEVELOPMENT_TEAM = N2Q372V7W2; + GCC_C_LANGUAGE_STANDARD = gnu99; + HEADER_SEARCH_PATHS = ( + "$(SRCROOT)/../vendor/SQLiteCpp/sqlite3/", + "$(SOCKPP)/include", + "$(MBEDTLS)/include", + "$(MBEDCRYPTO)/include", + "$(inherited)", + "$(SRCROOT)/../vendor/fleece/vendor/catch/", + "$(SRCROOT)/../vendor/fleece/Fleece/Support", + ); + INFOPLIST_FILE = "LiteCore-iOS/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@executable_path", + ); + ONLY_ACTIVE_ARCH = YES; + PRODUCT_BUNDLE_IDENTIFIER = "com.couchbase.LiteCore-iOS"; + PRODUCT_NAME = "LiteCore-iOS"; + SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Test_CE; + }; + D6200C042A57441D00790C0F /* Test_CE */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 273E9FAD1C519A1B003115A6 /* LiteCore XCTests.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + BUNDLE_LOADER = "$(TEST_HOST)"; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + DEVELOPMENT_TEAM = N2Q372V7W2; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + INFOPLIST_FILE = "LiteCore-iOS Tests/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + "@executable_path/../..", + ); + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + PRODUCT_BUNDLE_IDENTIFIER = org.couchbase.LiteCoreTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = iphoneos; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/LiteCore-iOS.app/LiteCore-iOS"; + }; + name = Test_CE; + }; + D6200C052A57441D00790C0F /* Test_CE */ = { + isa = XCBuildConfiguration; + buildSettings = { + }; + name = Test_CE; + }; + D6200C062A57441D00790C0F /* Test_CE */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Test_CE; + }; D6D93DE42A2ACD9D00E30981 /* Test_EE */ = { isa = XCBuildConfiguration; baseConfigurationReference = 2791EA192032732500BD813C /* Project_Debug_EE.xcconfig */; @@ -5988,6 +6267,7 @@ isa = XCConfigurationList; buildConfigurations = ( 2708FE501CF4CC880022F721 /* Debug */, + D6200BFC2A57441D00790C0F /* Test_CE */, 2791EA212032745700BD813C /* Debug_EE */, D6D93DEA2A2ACD9D00E30981 /* Test_EE */, 2708FE511CF4CC880022F721 /* Release */, @@ -6000,6 +6280,7 @@ isa = XCConfigurationList; buildConfigurations = ( 27139B4218F8E9750021A9A3 /* Debug */, + D6200BFE2A57441D00790C0F /* Test_CE */, 2791EA2A2032745700BD813C /* Debug_EE */, D6D93DEC2A2ACD9D00E30981 /* Test_EE */, 27139B4318F8E9750021A9A3 /* Release */, @@ -6012,6 +6293,7 @@ isa = XCConfigurationList; buildConfigurations = ( 274D040D1BA75E1C00FF7C35 /* Debug */, + D6200BFD2A57441D00790C0F /* Test_CE */, 2791EA222032745700BD813C /* Debug_EE */, D6D93DEB2A2ACD9D00E30981 /* Test_EE */, 274D040E1BA75E1C00FF7C35 /* Release */, @@ -6024,6 +6306,7 @@ isa = XCConfigurationList; buildConfigurations = ( 2750724718E3E52800A80C5A /* Debug */, + D6200BF62A57441D00790C0F /* Test_CE */, 2791EA1B2032745700BD813C /* Debug_EE */, D6D93DE42A2ACD9D00E30981 /* Test_EE */, 2750724818E3E52800A80C5A /* Release */, @@ -6036,6 +6319,7 @@ isa = XCConfigurationList; buildConfigurations = ( 2752B26B233D76010014AD9D /* Debug */, + D6200C012A57441D00790C0F /* Test_CE */, 2752B26C233D76010014AD9D /* Debug_EE */, D6D93DEF2A2ACD9D00E30981 /* Test_EE */, 2752B26D233D76010014AD9D /* Release */, @@ -6048,6 +6332,7 @@ isa = XCConfigurationList; buildConfigurations = ( 2771A0A1228624C100B18E0A /* Debug */, + D6200BFB2A57441D00790C0F /* Test_CE */, 2771A0A2228624C100B18E0A /* Debug_EE */, D6D93DE92A2ACD9D00E30981 /* Test_EE */, 2771A0A3228624C100B18E0A /* Release */, @@ -6060,6 +6345,7 @@ isa = XCConfigurationList; buildConfigurations = ( 278F476324C9131000E1CA7A /* Debug */, + D6200C022A57441D00790C0F /* Test_CE */, 278F476424C9131000E1CA7A /* Debug_EE */, D6D93DF02A2ACD9D00E30981 /* Test_EE */, 278F476524C9131000E1CA7A /* Release */, @@ -6072,6 +6358,7 @@ isa = XCConfigurationList; buildConfigurations = ( 27A924B41D9B316D00086206 /* Debug */, + D6200C032A57441D00790C0F /* Test_CE */, 2791EA2B2032745700BD813C /* Debug_EE */, D6D93DF12A2ACD9D00E30981 /* Test_EE */, 27A924B51D9B316D00086206 /* Release */, @@ -6084,6 +6371,7 @@ isa = XCConfigurationList; buildConfigurations = ( 27A924B71D9B316D00086206 /* Debug */, + D6200C042A57441D00790C0F /* Test_CE */, 2791EA2D2032745700BD813C /* Debug_EE */, D6D93DF22A2ACD9D00E30981 /* Test_EE */, 27A924B81D9B316D00086206 /* Release */, @@ -6096,6 +6384,7 @@ isa = XCConfigurationList; buildConfigurations = ( 27B6493D206971FC00FC12F7 /* Debug */, + D6200BF92A57441D00790C0F /* Test_CE */, 27B6493E206971FC00FC12F7 /* Debug_EE */, D6D93DE72A2ACD9D00E30981 /* Test_EE */, 27B6493F206971FC00FC12F7 /* Release */, @@ -6108,6 +6397,7 @@ isa = XCConfigurationList; buildConfigurations = ( 27B7E0F318F8FB4800044EBA /* Debug */, + D6200C052A57441D00790C0F /* Test_CE */, 2791EA2E2032745700BD813C /* Debug_EE */, D6D93DF32A2ACD9D00E30981 /* Test_EE */, 27B7E0F418F8FB4800044EBA /* Release */, @@ -6120,6 +6410,7 @@ isa = XCConfigurationList; buildConfigurations = ( 27DF7D651F4236500022F3DF /* Debug */, + D6200BFF2A57441D00790C0F /* Test_CE */, 2791EA272032745700BD813C /* Debug_EE */, D6D93DED2A2ACD9D00E30981 /* Test_EE */, 27DF7D661F4236500022F3DF /* Release */, @@ -6132,6 +6423,7 @@ isa = XCConfigurationList; buildConfigurations = ( 27EF807619142C2500A327B9 /* Debug */, + D6200C002A57441D00790C0F /* Test_CE */, 2791EA282032745700BD813C /* Debug_EE */, D6D93DEE2A2ACD9D00E30981 /* Test_EE */, 27EF807719142C2500A327B9 /* Release */, @@ -6144,6 +6436,7 @@ isa = XCConfigurationList; buildConfigurations = ( 27EF81101917EEC600A327B9 /* Debug */, + D6200BF72A57441D00790C0F /* Test_CE */, 2791EA1C2032745700BD813C /* Debug_EE */, D6D93DE52A2ACD9D00E30981 /* Test_EE */, 27EF81111917EEC600A327B9 /* Release */, @@ -6156,6 +6449,7 @@ isa = XCConfigurationList; buildConfigurations = ( 27FC81F11EAAB0D90028E38E /* Debug */, + D6200BFA2A57441D00790C0F /* Test_CE */, 2791EA1E2032745700BD813C /* Debug_EE */, D6D93DE82A2ACD9D00E30981 /* Test_EE */, 27FC81F21EAAB0D90028E38E /* Release */, @@ -6168,6 +6462,7 @@ isa = XCConfigurationList; buildConfigurations = ( 720EA3F31BA7EAD9002B8416 /* Debug */, + D6200BF82A57441D00790C0F /* Test_CE */, 2791EA1D2032745700BD813C /* Debug_EE */, D6D93DE62A2ACD9D00E30981 /* Test_EE */, 720EA3F41BA7EAD9002B8416 /* Release */, @@ -6180,6 +6475,7 @@ isa = XCConfigurationList; buildConfigurations = ( EAE4736A29BA113000C28D49 /* Debug */, + D6200C062A57441D00790C0F /* Test_CE */, EAE4736B29BA113000C28D49 /* Debug_EE */, D6D93DF42A2ACD9D00E30981 /* Test_EE */, EAE4736C29BA113000C28D49 /* Release */, diff --git a/Xcode/LiteCore.xcodeproj/xcshareddata/xcschemes/LiteCore C++ Tests.xcscheme b/Xcode/LiteCore.xcodeproj/xcshareddata/xcschemes/LiteCore C++ Tests.xcscheme index 9f0be23a6..b37d94f7c 100644 --- a/Xcode/LiteCore.xcodeproj/xcshareddata/xcschemes/LiteCore C++ Tests.xcscheme +++ b/Xcode/LiteCore.xcodeproj/xcshareddata/xcschemes/LiteCore C++ Tests.xcscheme @@ -1,7 +1,7 @@ + version = "1.8"> @@ -31,7 +31,7 @@ Date: Wed, 12 Jul 2023 11:53:01 +0100 Subject: [PATCH 4/6] CBL-4530: Remove unused actor::Observer and actor::Property (#1835) --- LiteCore/Support/ActorProperty.cc | 33 ---------- LiteCore/Support/ActorProperty.hh | 77 ----------------------- Networking/BLIP/cmake/platform_base.cmake | 1 - Xcode/LiteCore.xcodeproj/project.pbxproj | 4 -- 4 files changed, 115 deletions(-) delete mode 100644 LiteCore/Support/ActorProperty.cc delete mode 100644 LiteCore/Support/ActorProperty.hh diff --git a/LiteCore/Support/ActorProperty.cc b/LiteCore/Support/ActorProperty.cc deleted file mode 100644 index 0f2f0737d..000000000 --- a/LiteCore/Support/ActorProperty.cc +++ /dev/null @@ -1,33 +0,0 @@ -// -// ActorProperty.cc -// -// Copyright 2017-Present Couchbase, Inc. -// -// Use of this software is governed by the Business Source License included -// in the file licenses/BSL-Couchbase.txt. As of the Change Date specified -// in that file, in accordance with the Business Source License, use of this -// software will be governed by the Apache License, Version 2.0, included in -// the file licenses/APL2.txt. -// - -#include "ActorProperty.hh" - -using namespace std; - -namespace litecore::actor { - - template - PropertyImpl& PropertyImpl::operator=(const T& t) { - if ( t != _value ) { - _value = t; - for ( auto& observer : _observers ) { observer(_value); } - } - return *this; - } - - template - void PropertyImpl::addObserver(Observer& observer) { - _observers.push_back(observer); - } - -} // namespace litecore::actor diff --git a/LiteCore/Support/ActorProperty.hh b/LiteCore/Support/ActorProperty.hh deleted file mode 100644 index f0737ce84..000000000 --- a/LiteCore/Support/ActorProperty.hh +++ /dev/null @@ -1,77 +0,0 @@ -// -// ActorProperty.hh -// -// Copyright 2017-Present Couchbase, Inc. -// -// Use of this software is governed by the Business Source License included -// in the file licenses/BSL-Couchbase.txt. As of the Change Date specified -// in that file, in accordance with the Business Source License, use of this -// software will be governed by the Apache License, Version 2.0, included in -// the file licenses/APL2.txt. -// - -#pragma once -#include "Actor.hh" -#include -#include - -namespace litecore::actor { - - template - class Observer; - - /** Implementation of an Actor property. This would be a private member variable of an Actor. */ - template - class PropertyImpl { - public: - explicit PropertyImpl(Actor* owner) : _owner(*owner) {} - - explicit PropertyImpl(Actor* owner, T t) : _owner(*owner), _value(t) {} - - T get() const { return _value; } - - explicit operator T() const { return _value; } - - PropertyImpl& operator=(const T& t); - - void addObserver(Observer& observer); - - private: - Actor& _owner; - T _value{}; - std::vector> _observers; - }; - - template - class ObservedProperty { - public: - ~ObservedProperty(); - - T get() const { return _value; } - - explicit operator T() const { return _value; } - - private: - void receiveValue(T t) { _value = t; } - - Retained& _provider; - T _value; - }; - - /** Public Actor property. This would be a public member variable of an Actor. */ - template - class Property { - public: - explicit Property(PropertyImpl& prop) : _impl(prop) {} - - using Observer = std::function; - - void addObserver(Observer& observer) { _impl.addObserver(observer); } - - void removeObserver(Actor& a); - - private: - PropertyImpl& _impl; - }; - -} // namespace litecore::actor diff --git a/Networking/BLIP/cmake/platform_base.cmake b/Networking/BLIP/cmake/platform_base.cmake index 533bc57ff..5ae2b7c7d 100644 --- a/Networking/BLIP/cmake/platform_base.cmake +++ b/Networking/BLIP/cmake/platform_base.cmake @@ -15,7 +15,6 @@ function(set_source_files_base) ${WEBSOCKETS_LOCATION}/WebSocketImpl.cc ${WEBSOCKETS_LOCATION}/WebSocketInterface.cc ${SUPPORT_LOCATION}/Actor.cc - ${SUPPORT_LOCATION}/ActorProperty.cc # ${SUPPORT_LOCATION}/Async.cc ${SUPPORT_LOCATION}/Channel.cc ${SUPPORT_LOCATION}/Codec.cc diff --git a/Xcode/LiteCore.xcodeproj/project.pbxproj b/Xcode/LiteCore.xcodeproj/project.pbxproj index 99d8b7747..0d858d39a 100644 --- a/Xcode/LiteCore.xcodeproj/project.pbxproj +++ b/Xcode/LiteCore.xcodeproj/project.pbxproj @@ -1018,7 +1018,6 @@ 2744B331241854F2005A194D /* WebSocketImpl.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebSocketImpl.cc; sourceTree = ""; }; 2744B332241854F2005A194D /* WebSocketProtocol.hh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = WebSocketProtocol.hh; sourceTree = ""; }; 2744B334241854F2005A194D /* Codec.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Codec.cc; sourceTree = ""; }; - 2744B335241854F2005A194D /* ActorProperty.hh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ActorProperty.hh; sourceTree = ""; }; 2744B336241854F2005A194D /* Async.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Async.cc; sourceTree = ""; }; 2744B337241854F2005A194D /* Actor.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Actor.cc; sourceTree = ""; }; 2744B338241854F2005A194D /* ThreadedMailbox.hh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ThreadedMailbox.hh; sourceTree = ""; }; @@ -1028,7 +1027,6 @@ 2744B33C241854F2005A194D /* Batcher.hh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Batcher.hh; sourceTree = ""; }; 2744B33D241854F2005A194D /* ThreadUtil.hh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ThreadUtil.hh; sourceTree = ""; }; 2744B33E241854F2005A194D /* Codec.hh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Codec.hh; sourceTree = ""; }; - 2744B33F241854F2005A194D /* ActorProperty.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ActorProperty.cc; sourceTree = ""; }; 2744B340241854F2005A194D /* Actor.hh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Actor.hh; sourceTree = ""; }; 2744B341241854F2005A194D /* Async.hh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Async.hh; sourceTree = ""; }; 2744B342241854F2005A194D /* Channel.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Channel.cc; sourceTree = ""; }; @@ -2090,14 +2088,12 @@ 2744B36124185D24005A194D /* Actors */ = { isa = PBXGroup; children = ( - 2744B335241854F2005A194D /* ActorProperty.hh */, 2744B336241854F2005A194D /* Async.cc */, 2744B337241854F2005A194D /* Actor.cc */, 2744B338241854F2005A194D /* ThreadedMailbox.hh */, 2744B339241854F2005A194D /* GCDMailbox.hh */, 2744B33A241854F2005A194D /* ThreadedMailbox.cc */, 2744B33B241854F2005A194D /* GCDMailbox.cc */, - 2744B33F241854F2005A194D /* ActorProperty.cc */, 2744B340241854F2005A194D /* Actor.hh */, 2744B341241854F2005A194D /* Async.hh */, 2744B342241854F2005A194D /* Channel.cc */, From 42d66b0f959cfef5326f3c34997fb0c379eec065 Mon Sep 17 00:00:00 2001 From: jianminzhao <76990468+jianminzhao@users.noreply.github.com> Date: Thu, 13 Jul 2023 16:20:21 -0700 Subject: [PATCH 5/6] CBL-127: Conflict error in CBL P2P push replication when using different target database UID (#1838) The problem has been taken care of by the new property, "conflictIncludesRev", introduced by the resolution of CBL 2637, to the BLIP message "proposeChanges". We added test case to verify it. --- Replicator/tests/ReplicatorLoopbackTest.cc | 48 +++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/Replicator/tests/ReplicatorLoopbackTest.cc b/Replicator/tests/ReplicatorLoopbackTest.cc index 047e0e8db..b324993ee 100644 --- a/Replicator/tests/ReplicatorLoopbackTest.cc +++ b/Replicator/tests/ReplicatorLoopbackTest.cc @@ -1928,6 +1928,7 @@ TEST_CASE_METHOD(ReplicatorLoopbackTest, "Replicate Encrypted Properties", "[Pus CHECK(clear == "\"123-45-6789\""); } } +#endif // COUCHBASE_ENTERPRISE TEST_CASE_METHOD(ReplicatorLoopbackTest, "Replication Collections Must Match", "[Push][Pull][Sync]") { Options opts = GENERATE_COPY(Options::pushing(kC4OneShot, _collSpec), Options::pulling(kC4OneShot, _collSpec), @@ -1956,4 +1957,49 @@ TEST_CASE_METHOD(ReplicatorLoopbackTest, "Replication Collections Must Match", " runReplicators(opts, serverOpts); } -#endif // COUCHBASE_ENTERPRISE +TEST_CASE_METHOD(ReplicatorLoopbackTest, "Conflict Includes Rev", "[Push][Sync]") { + // The new push property, "conflictIncludesRev", introduced by the resolution of CBL-2637, + // also fixed the scenrio of CBL-127. + + FLSlice docID = C4STR("doc"); + slice jBody = R"({"name":"otherDB"})"_sl; + auto revID = createFleeceRev(_collDB2, docID, nullslice, jBody); + + _expectedDocumentCount = 1; + // Pre-conditions: db is empty, db2 has one doc. + runPushPullReplication(); + + // Post-conditions: db and db2 are sync'ed. + c4::ref docInDb1 = c4coll_getDoc(_collDB1, docID, true, kDocGetAll, nullptr); + c4::ref docInDb2 = c4coll_getDoc(_collDB2, docID, true, kDocGetAll, nullptr); + string revInDb1{(char*)docInDb1->revID.buf, docInDb1->revID.size}; + string revInDb2{(char*)docInDb2->revID.buf, docInDb2->revID.size}; + REQUIRE(revInDb1 == revInDb2); + REQUIRE(revID == revInDb1); + REQUIRE(c4rev_getGeneration(slice(revID)) == 1); + + // Modify the document in db + slice modifiedBody = R"({"name":"otherDB","modified":1})"_sl; + auto revID_2 = createFleeceRev(_collDB1, docID, nullslice, modifiedBody); + + Replicator::Options serverOpts = Replicator::Options::passive(_collSpec); + Replicator::Options clientOpts = Replicator::Options::pushing(kC4OneShot, _collSpec); + + SECTION("Same Target Revision 1 Was Synced") {} + SECTION("Assign a New UID to the Target") { + // We are to push revision 2 but with different UID, the pusher lost track of the + // remote counterpart of revision 1. The property "conflictIncludesRev" attached to the + // "proposeChange" message helps to resolve it. + clientOpts.setProperty(kC4ReplicatorOptionRemoteDBUniqueID, "DifferentUID"_sl); + } + + _expectedDocumentCount = 1; + runReplicators(clientOpts, serverOpts); + docInDb1 = c4coll_getDoc(_collDB1, docID, true, kDocGetAll, nullptr); + docInDb2 = c4coll_getDoc(_collDB2, docID, true, kDocGetAll, nullptr); + revInDb1 = string{(char*)docInDb1->revID.buf, docInDb1->revID.size}; + revInDb2 = string{(char*)docInDb2->revID.buf, docInDb2->revID.size}; + CHECK(revInDb1 == revInDb2); + CHECK(revID_2 == revInDb1); + CHECK(c4rev_getGeneration(slice(revID_2)) == 2); +} From 1604640cd4de2db09a6cef2ad79394452b13de7d Mon Sep 17 00:00:00 2001 From: jianminzhao <76990468+jianminzhao@users.noreply.github.com> Date: Fri, 14 Jul 2023 15:47:54 -0700 Subject: [PATCH 6/6] CBL-4721: UnicodeCollator_Stub.cc fails when building couchbase-mobile-tools/logcat on ubuntu. (#1839) --- LiteCore/Storage/UnicodeCollator_Stub.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/LiteCore/Storage/UnicodeCollator_Stub.cc b/LiteCore/Storage/UnicodeCollator_Stub.cc index 0dc88dca6..18d15f102 100644 --- a/LiteCore/Storage/UnicodeCollator_Stub.cc +++ b/LiteCore/Storage/UnicodeCollator_Stub.cc @@ -19,9 +19,13 @@ namespace litecore { using namespace std; - int CompareUTF8(slice str1, slice str2, const CollationContext&) { error::_throw(error::Unimplemented); } + int CompareUTF8(fleece::slice str1, fleece::slice str2, const CollationContext&) { + error::_throw(error::Unimplemented); + } - bool ContainsUTF8(slice str, slice substr, const CollationContext&) { error::_throw(error::Unimplemented); } + bool ContainsUTF8(fleece::slice str, fleece::slice substr, const CollationContext&) { + error::_throw(error::Unimplemented); + } unique_ptr RegisterSQLiteUnicodeCollation(sqlite3* dbHandle, const Collation& coll) { return nullptr;