diff options
author | NicoleYarroch <nicole@livio.io> | 2017-09-12 10:57:24 -0400 |
---|---|---|
committer | NicoleYarroch <nicole@livio.io> | 2017-09-12 10:57:24 -0400 |
commit | 3e3407e9bcd0b478edf74fb4a36a13fb0fe26de5 (patch) | |
tree | 5d616e467f0bf8fbc33aa215f0ac6ca8dd169c5d | |
parent | 59360dd1df9987b10fb2d4b17a78860ffa580f44 (diff) | |
download | sdl_ios-3e3407e9bcd0b478edf74fb4a36a13fb0fe26de5.tar.gz |
Fixed the log level bitwise left shift assignment
Signed-off-by: NicoleYarroch <nicole@livio.io>
-rw-r--r-- | SmartDeviceLink-iOS.xcodeproj/project.pbxproj | 4 | ||||
-rw-r--r-- | SmartDeviceLink/SDLLogConstants.h | 8 | ||||
-rw-r--r-- | SmartDeviceLink/SDLLogManager.m | 2 | ||||
-rw-r--r-- | SmartDeviceLinkTests/LoggingSpecs/SDLLogManagerSpec.m | 68 | ||||
-rw-r--r-- | SmartDeviceLinkTests/SDLLogConstantsSpec.m | 50 |
5 files changed, 103 insertions, 29 deletions
diff --git a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj index 977fe51ec..97f4dc54a 100644 --- a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj +++ b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj @@ -949,6 +949,7 @@ 8877F5F11F34AA2D00DC128A /* SDLSendHapticDataResponseSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 8877F5F01F34AA2D00DC128A /* SDLSendHapticDataResponseSpec.m */; }; 88B848C31F45E1A600DED768 /* TestResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 88B848C21F45E1A600DED768 /* TestResponse.m */; }; 88B848C91F462E3600DED768 /* TestProgressResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 88B848C81F462E3600DED768 /* TestProgressResponse.m */; }; + 88D2AAE41F682BB20078D5B2 /* SDLLogConstantsSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 88D2AAE31F682BB20078D5B2 /* SDLLogConstantsSpec.m */; }; 88EED8381F33AE1700E6C42E /* SDLHapticRect.h in Headers */ = {isa = PBXBuildFile; fileRef = 88EED8361F33AE1700E6C42E /* SDLHapticRect.h */; settings = {ATTRIBUTES = (Public, ); }; }; 88EED8391F33AE1700E6C42E /* SDLHapticRect.m in Sources */ = {isa = PBXBuildFile; fileRef = 88EED8371F33AE1700E6C42E /* SDLHapticRect.m */; }; 88EED83B1F33BECB00E6C42E /* SDLHapticRectSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 88EED83A1F33BECB00E6C42E /* SDLHapticRectSpec.m */; }; @@ -2097,6 +2098,7 @@ 88B848C21F45E1A600DED768 /* TestResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestResponse.m; sourceTree = "<group>"; }; 88B848C71F462E3600DED768 /* TestProgressResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestProgressResponse.h; sourceTree = "<group>"; }; 88B848C81F462E3600DED768 /* TestProgressResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestProgressResponse.m; sourceTree = "<group>"; }; + 88D2AAE31F682BB20078D5B2 /* SDLLogConstantsSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLLogConstantsSpec.m; sourceTree = "<group>"; }; 88EED8361F33AE1700E6C42E /* SDLHapticRect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLHapticRect.h; sourceTree = "<group>"; }; 88EED8371F33AE1700E6C42E /* SDLHapticRect.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLHapticRect.m; sourceTree = "<group>"; }; 88EED83A1F33BECB00E6C42E /* SDLHapticRectSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLHapticRectSpec.m; sourceTree = "<group>"; }; @@ -2747,6 +2749,7 @@ 5D43466A1E6F3B4C00B639C6 /* SDLLogFilterSpec.m */, 5D43466C1E6F522000B639C6 /* SDLLogModelSpec.m */, 5D43466E1E6F55BD00B639C6 /* SDLLogManagerSpec.m */, + 88D2AAE31F682BB20078D5B2 /* SDLLogConstantsSpec.m */, ); name = LoggingSpecs; sourceTree = "<group>"; @@ -5480,6 +5483,7 @@ 162E834D1A9BDE8B00906325 /* SDLChangeRegistrationResponseSpec.m in Sources */, DA9F7EAC1DCC062400ACAE48 /* SDLUnsubscribeWaypointsResponseSpec.m in Sources */, 5D43466B1E6F3B4C00B639C6 /* SDLLogFilterSpec.m in Sources */, + 88D2AAE41F682BB20078D5B2 /* SDLLogConstantsSpec.m in Sources */, 162E836B1A9BDE8B00906325 /* SDLSyncPDataResponseSpec.m in Sources */, 8B7B31AF1F2FBA0200BDC38D /* SDLVideoStreamingCapabilitySpec.m in Sources */, 162E839B1A9BDE8B00906325 /* SDLRPCNotificationSpec.m in Sources */, diff --git a/SmartDeviceLink/SDLLogConstants.h b/SmartDeviceLink/SDLLogConstants.h index c667e14a6..f0d9751bc 100644 --- a/SmartDeviceLink/SDLLogConstants.h +++ b/SmartDeviceLink/SDLLogConstants.h @@ -34,10 +34,10 @@ typedef NS_ENUM(NSUInteger, SDLLogBytesDirection) { - SDLLogFlagError: Error level logging. */ typedef NS_OPTIONS(NSUInteger, SDLLogFlag) { - SDLLogFlagVerbose = 1 << 0, - SDLLogFlagDebug = 1 << 1, - SDLLogFlagWarning = 1 << 2, - SDLLogFlagError = 1 << 3 + SDLLogFlagError = 1 << 0, + SDLLogFlagWarning = 1 << 1, + SDLLogFlagDebug = 1 << 2, + SDLLogFlagVerbose = 1 << 3, }; /** diff --git a/SmartDeviceLink/SDLLogManager.m b/SmartDeviceLink/SDLLogManager.m index a532ef215..ab781dc13 100644 --- a/SmartDeviceLink/SDLLogManager.m +++ b/SmartDeviceLink/SDLLogManager.m @@ -172,7 +172,7 @@ static dispatch_queue_t _logQueue = NULL; } - (void)sdl_log:(SDLLogModel *)log { - if ([self sdl_logLevelForFile:log.fileName] > log.level) { return; } + if ([self sdl_logLevelForFile:log.fileName] < log.level) { return; } for (SDLLogFilter *filter in self.filters) { if (!filter.filter(log)) { return; } diff --git a/SmartDeviceLinkTests/LoggingSpecs/SDLLogManagerSpec.m b/SmartDeviceLinkTests/LoggingSpecs/SDLLogManagerSpec.m index c06ffa062..85fc60ba4 100644 --- a/SmartDeviceLinkTests/LoggingSpecs/SDLLogManagerSpec.m +++ b/SmartDeviceLinkTests/LoggingSpecs/SDLLogManagerSpec.m @@ -137,15 +137,13 @@ describe(@"a log manager", ^{ __block NSString *testVerboseFormattedLog; __block int expectedLogCount; - + __block int testLogLevel; __block NSMutableArray<NSString *> *expectedMessages; __block NSMutableArray<NSString *> *notExpectedMessages; context(@"debug configuration", ^{ beforeEach(^{ testConfiguration = [[SDLLogConfiguration alloc] init]; - testConfiguration.modules = [NSSet setWithObject:[SDLLogFileModule moduleWithName:@"test" files:[NSSet setWithObject:@"test"]]]; - testConfiguration.filters = [NSSet setWithObject:[SDLLogFilter filterByDisallowingString:@"this string should never trigger" caseSensitive:NO]]; testConfiguration.targets = [NSSet setWithObject:testLogTarget]; testConfiguration.asynchronous = NO; testConfiguration.formatType = SDLLogFormatTypeSimple; @@ -166,62 +164,81 @@ describe(@"a log manager", ^{ testMessageVerbose = @"verboseMessage"; testVerboseFormattedLog = [NSString stringWithFormat:@"%@ ⚪ (SDL)- %@", formattedDate, testMessageVerbose]; - [expectedMessages removeAllObjects]; - [notExpectedMessages removeAllObjects]; + expectedMessages = [[NSMutableArray alloc] init]; + notExpectedMessages = [[NSMutableArray alloc] init]; }); describe(@"", ^{ beforeEach(^{ expectedLogCount = 0; - expect(testLogTarget.formattedLogMessages.count).to(equal(0)); - }); - - it(@"should log error, warn, and debug logs but not verbose", ^{ - testConfiguration.globalLogLevel = SDLLogLevelDebug; - [testManager setConfiguration:testConfiguration]; - expectedLogCount = 3; - - [expectedMessages addObject:testWarningFormattedLog]; - [expectedMessages addObject:testErrorFormattedLog]; - [expectedMessages addObject:testDebugFormattedLog]; - - [notExpectedMessages addObject:testVerboseFormattedLog]; + expect(expectedMessages.count).to(equal(0)); + expect(notExpectedMessages.count).to(equal(0)); }); it(@"should not log anything when the log level is OFF", ^{ testConfiguration.globalLogLevel = SDLLogLevelOff; - [testManager setConfiguration:testConfiguration]; + testLogLevel = SDLLogLevelOff; expectedLogCount = 0; - [notExpectedMessages addObjectsFromArray:@[testWarningFormattedLog, testErrorFormattedLog, testDebugFormattedLog, testVerboseFormattedLog]]; + [notExpectedMessages addObject:testWarningFormattedLog]; + [notExpectedMessages addObject:testErrorFormattedLog]; + [notExpectedMessages addObject:testDebugFormattedLog]; + [notExpectedMessages addObject:testVerboseFormattedLog]; }); it(@"should only log errors when the log level is ERROR", ^{ testConfiguration.globalLogLevel = SDLLogLevelError; - [testManager setConfiguration:testConfiguration]; + testLogLevel = SDLLogLevelError; expectedLogCount = 1; + + [expectedMessages addObject:testErrorFormattedLog]; + + [notExpectedMessages addObject:testWarningFormattedLog]; + [notExpectedMessages addObject:testDebugFormattedLog]; + [notExpectedMessages addObject:testVerboseFormattedLog]; }); it(@"should only log errors and warnings when the log level is WARNING", ^{ testConfiguration.globalLogLevel = SDLLogLevelWarning; - [testManager setConfiguration:testConfiguration]; + testLogLevel = SDLLogLevelWarning; expectedLogCount = 2; + + [expectedMessages addObject:testWarningFormattedLog]; + [expectedMessages addObject:testErrorFormattedLog]; + + [notExpectedMessages addObject:testDebugFormattedLog]; + [notExpectedMessages addObject:testVerboseFormattedLog]; }); it(@"should only log errors, warnings, and debug logs when the log level is DEBUG", ^{ testConfiguration.globalLogLevel = SDLLogLevelDebug; - [testManager setConfiguration:testConfiguration]; + testLogLevel = SDLLogLevelDebug; expectedLogCount = 3; + + [expectedMessages addObject:testWarningFormattedLog]; + [expectedMessages addObject:testErrorFormattedLog]; + [expectedMessages addObject:testDebugFormattedLog]; + + [notExpectedMessages addObject:testVerboseFormattedLog]; }); it(@"should log errors, warnings, debug, and verbose logs when the log level is VERBOSE", ^{ testConfiguration.globalLogLevel = SDLLogLevelVerbose; - [testManager setConfiguration:testConfiguration]; + testLogLevel = SDLLogLevelVerbose; expectedLogCount = 4; + + [expectedMessages addObject:testWarningFormattedLog]; + [expectedMessages addObject:testErrorFormattedLog]; + [expectedMessages addObject:testDebugFormattedLog]; + [expectedMessages addObject:testVerboseFormattedLog]; }); afterEach(^{ + SDLLogFileModule *module = [[SDLLogFileModule alloc] initWithName:@"test" files:[NSSet setWithObject:@"test"] level:testLogLevel]; + testConfiguration.modules = [NSSet setWithObject:module]; + [testManager setConfiguration:testConfiguration]; + // Warning [testManager logWithLevel:testLogLevelWarning timestamp:testDate file:testFileName functionName:testFunctionName line:testLineWarning queue:testQueue message:testMessageWarning]; @@ -237,6 +254,7 @@ describe(@"a log manager", ^{ }); afterEach(^{ + expect(testManager.asynchronous).to(equal(NO)); expect(testLogTarget.formattedLogMessages.count).to(equal(expectedLogCount)); for(int i = 0; i < expectedMessages.count; i += 1) { @@ -252,4 +270,6 @@ describe(@"a log manager", ^{ }); }); + + QuickSpecEnd diff --git a/SmartDeviceLinkTests/SDLLogConstantsSpec.m b/SmartDeviceLinkTests/SDLLogConstantsSpec.m new file mode 100644 index 000000000..cf10793d9 --- /dev/null +++ b/SmartDeviceLinkTests/SDLLogConstantsSpec.m @@ -0,0 +1,50 @@ +// +// SDLLogConstantsSpec.m +// SmartDeviceLink-iOS +// +// Created by Nicole on 9/12/17. +// Copyright © 2017 smartdevicelink. All rights reserved. +// + +#import <Quick/Quick.h> +#import <Nimble/Nimble.h> + +#import "SDLLogConstants.h" + +QuickSpecBegin(SDLLogConstantsSpec) + +describe(@"log constants", ^{ + it(@"should assigned the correct integer value to each SDLLogLevel", ^{ + expect((int)SDLLogLevelOff).to(beGreaterThan((int)SDLLogLevelDefault)); + expect((int)SDLLogLevelOff).to(beLessThan((int)SDLLogLevelError)); + expect((int)SDLLogLevelOff).to(beLessThan((int)SDLLogLevelWarning)); + expect((int)SDLLogLevelOff).to(beLessThan((int)SDLLogLevelDebug)); + expect((int)SDLLogLevelOff).to(beLessThan((int)SDLLogLevelVerbose)); + + expect((int)SDLLogLevelError).to(beGreaterThan((int)SDLLogLevelDefault)); + expect((int)SDLLogLevelError).to(beGreaterThan((int)SDLLogLevelOff)); + expect((int)SDLLogLevelError).to(beLessThan((int)SDLLogLevelWarning)); + expect((int)SDLLogLevelError).to(beLessThan((int)SDLLogLevelDebug)); + expect((int)SDLLogLevelError).to(beLessThan((int)SDLLogLevelVerbose)); + + expect((int)SDLLogLevelWarning).to(beGreaterThan((int)SDLLogLevelDefault)); + expect((int)SDLLogLevelWarning).to(beGreaterThan((int)SDLLogLevelOff)); + expect((int)SDLLogLevelWarning).to(beGreaterThan((int)SDLLogLevelError)); + expect((int)SDLLogLevelWarning).to(beLessThan((int)SDLLogLevelDebug)); + expect((int)SDLLogLevelWarning).to(beLessThan((int)SDLLogLevelVerbose)); + + expect((int)SDLLogLevelDebug).to(beGreaterThan((int)SDLLogLevelDefault)); + expect((int)SDLLogLevelDebug).to(beGreaterThan((int)SDLLogLevelOff)); + expect((int)SDLLogLevelDebug).to(beGreaterThan((int)SDLLogLevelError)); + expect((int)SDLLogLevelDebug).to(beGreaterThan((int)SDLLogLevelWarning)); + expect((int)SDLLogLevelDebug).to(beLessThan((int)SDLLogLevelVerbose)); + + expect((int)SDLLogLevelVerbose).to(beGreaterThan((int)SDLLogLevelDefault)); + expect((int)SDLLogLevelVerbose).to(beGreaterThan((int)SDLLogLevelOff)); + expect((int)SDLLogLevelVerbose).to(beGreaterThan((int)SDLLogLevelError)); + expect((int)SDLLogLevelVerbose).to(beGreaterThan((int)SDLLogLevelWarning)); + expect((int)SDLLogLevelVerbose).to(beGreaterThan((int)SDLLogLevelDebug)); + }); +}); + +QuickSpecEnd |