diff options
author | Ryan Wilson <wilsonryan@google.com> | 2018-06-27 09:42:09 -0400 |
---|---|---|
committer | Paul Beusterien <paulbeusterien@google.com> | 2018-06-27 06:42:09 -0700 |
commit | 8d399c78bda9529832d6ecd70a6c4c564c62da6d (patch) | |
tree | 260b62ce7721906b948b15088bb92f82cd174593 /Firebase | |
parent | 5c4b7b58a46d21b5803d65e1dbc6cfe6059ef067 (diff) |
Better mocking for Core Unit Tests (#1467)
* Better mocking for Core Unit Tests
This includes NSNotificationCenter and NSUserDefaults to prevent
flaky tests and unit tests interfering with each other.
* Share variable for intervals being set.
Diffstat (limited to 'Firebase')
-rw-r--r-- | Firebase/Core/FIRLogger.m | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/Firebase/Core/FIRLogger.m b/Firebase/Core/FIRLogger.m index ae14e9f..2784ae9 100644 --- a/Firebase/Core/FIRLogger.m +++ b/Firebase/Core/FIRLogger.m @@ -64,6 +64,10 @@ static aslclient sFIRLoggerClient; static dispatch_queue_t sFIRClientQueue; +/// NSUserDefaults that should be used to store and read variables. If nil, `standardUserDefaults` +/// will be used. +static NSUserDefaults *sFIRLoggerUserDefaults; + static BOOL sFIRLoggerDebugMode; // The sFIRAnalyticsDebugMode flag is here to support the -FIRDebugEnabled/-FIRDebugDisabled @@ -113,14 +117,17 @@ void FIRLoggerInitializeASL() { sFIRAnalyticsDebugMode = NO; sFIRLoggerMaximumLevel = FIRLoggerLevelNotice; - NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; - BOOL debugMode = [userDefaults boolForKey:kFIRPersistedDebugModeKey]; + // Use the standard NSUserDefaults if it hasn't been explicitly set. + if (sFIRLoggerUserDefaults == nil) { + sFIRLoggerUserDefaults = [NSUserDefaults standardUserDefaults]; + } + BOOL debugMode = [sFIRLoggerUserDefaults boolForKey:kFIRPersistedDebugModeKey]; if ([arguments containsObject:kFIRDisableDebugModeApplicationArgument]) { // Default mode - [userDefaults removeObjectForKey:kFIRPersistedDebugModeKey]; + [sFIRLoggerUserDefaults removeObjectForKey:kFIRPersistedDebugModeKey]; } else if ([arguments containsObject:kFIREnableDebugModeApplicationArgument] || debugMode) { // Debug mode - [userDefaults setBool:YES forKey:kFIRPersistedDebugModeKey]; + [sFIRLoggerUserDefaults setBool:YES forKey:kFIRPersistedDebugModeKey]; asl_set_filter(sFIRLoggerClient, ASL_FILTER_MASK_UPTO(ASL_LEVEL_DEBUG)); sFIRLoggerDebugMode = YES; } @@ -190,7 +197,12 @@ __attribute__((no_sanitize("thread"))) BOOL FIRIsLoggableLevel(FIRLoggerLevel lo #ifdef DEBUG void FIRResetLogger() { sFIRLoggerOnceToken = 0; - [[NSUserDefaults standardUserDefaults] removeObjectForKey:kFIRPersistedDebugModeKey]; + [sFIRLoggerUserDefaults removeObjectForKey:kFIRPersistedDebugModeKey]; + sFIRLoggerUserDefaults = nil; +} + +void FIRSetLoggerUserDefaults(NSUserDefaults *defaults) { + sFIRLoggerUserDefaults = defaults; } aslclient getFIRLoggerClient() { |