summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2017-09-12 11:42:27 -0400
committerGitHub <noreply@github.com>2017-09-12 11:42:27 -0400
commitafda6cc4c27db1adbca4b8b5b2d4e902a3828fc0 (patch)
treec415472b54c6791e822fa2314021b65589420460
parent121b35aa3c10aba5f3b0b42fbe20ecebdca0101b (diff)
parentdfa2100de755e35b257a1baa24b62124bc69e1e4 (diff)
downloadsdl_ios-afda6cc4c27db1adbca4b8b5b2d4e902a3828fc0.tar.gz
Merge pull request #731 from smartdevicelink/bugfix/issue_730_logging_level_check_reversed
Fix log level checks
-rw-r--r--SmartDeviceLink-iOS.xcodeproj/project.pbxproj4
-rw-r--r--SmartDeviceLink/SDLLogConstants.h8
-rw-r--r--SmartDeviceLinkTests/LoggingSpecs/SDLLogManagerSpec.m149
-rw-r--r--SmartDeviceLinkTests/SDLLogConstantsSpec.m50
4 files changed, 207 insertions, 4 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/SmartDeviceLinkTests/LoggingSpecs/SDLLogManagerSpec.m b/SmartDeviceLinkTests/LoggingSpecs/SDLLogManagerSpec.m
index c89ed657f..28977cf4d 100644
--- a/SmartDeviceLinkTests/LoggingSpecs/SDLLogManagerSpec.m
+++ b/SmartDeviceLinkTests/LoggingSpecs/SDLLogManagerSpec.m
@@ -112,7 +112,156 @@ describe(@"a log manager", ^{
});
});
});
+
+ describe(@"log output", ^{
+ __block NSString *testFileName = @"file";
+ __block NSString *testFunctionName = @"function";
+ __block NSString *testQueue = @"queue";
+
+ __block SDLLogLevel testLogLevelWarning = SDLLogLevelWarning;
+ __block SDLLogLevel testLogLevelError = SDLLogLevelError;
+ __block SDLLogLevel testLogLevelDebug = SDLLogLevelDebug;
+ __block SDLLogLevel testLogLevelVerbose = SDLLogLevelVerbose;
+
+ __block NSInteger testLineWarning;
+ __block NSString *testMessageWarning;
+ __block NSString *testWarningFormattedLog;
+ __block NSInteger testLineError;
+ __block NSString *testMessageError;
+ __block NSString *testErrorFormattedLog;
+ __block NSInteger testLineDebug;
+ __block NSString *testMessageDebug;
+ __block NSString *testDebugFormattedLog;
+ __block NSInteger testLineVerbose;
+ __block NSString *testMessageVerbose;
+ __block NSString *testVerboseFormattedLog;
+
+ __block int expectedLogCount;
+ __block NSMutableArray<NSString *> *expectedMessages;
+ __block NSMutableArray<NSString *> *notExpectedMessages;
+
+ context(@"The type of debug messages logged depends on the SDLLogLevel", ^{
+ beforeEach(^{
+ testConfiguration = [[SDLLogConfiguration alloc] init];
+ testConfiguration.targets = [NSSet setWithObject:testLogTarget];
+ testConfiguration.asynchronous = NO;
+ testConfiguration.formatType = SDLLogFormatTypeSimple;
+
+ testLineWarning = 1;
+ testMessageWarning = @"warningMessage";
+ testWarningFormattedLog = [NSString stringWithFormat:@"%@ 🔶 (SDL)- %@", formattedDate, testMessageWarning];
+
+ testLineError = 2;
+ testMessageError = @"errorMessage";
+ testErrorFormattedLog = [NSString stringWithFormat:@"%@ ❌ (SDL)- %@", formattedDate, testMessageError];
+
+ testLineDebug = 3;
+ testMessageDebug = @"debugMessage";
+ testDebugFormattedLog = [NSString stringWithFormat:@"%@ 🔵 (SDL)- %@", formattedDate, testMessageDebug];
+
+ testLineVerbose = 4;
+ testMessageVerbose = @"verboseMessage";
+ testVerboseFormattedLog = [NSString stringWithFormat:@"%@ ⚪ (SDL)- %@", formattedDate, testMessageVerbose];
+
+ expectedMessages = [[NSMutableArray alloc] init];
+ notExpectedMessages = [[NSMutableArray alloc] init];
+ });
+
+ describe(@"When the global log level is set", ^{
+ beforeEach(^{
+ expectedLogCount = 0;
+ expect(testLogTarget.formattedLogMessages.count).to(equal(0));
+ 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;
+ expectedLogCount = 0;
+
+ [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;
+ 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;
+ 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;
+ 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;
+ expectedLogCount = 4;
+
+ [expectedMessages addObject:testWarningFormattedLog];
+ [expectedMessages addObject:testErrorFormattedLog];
+ [expectedMessages addObject:testDebugFormattedLog];
+ [expectedMessages addObject:testVerboseFormattedLog];
+ });
+
+ afterEach(^{
+ [testManager setConfiguration:testConfiguration];
+
+ // Warning
+ [testManager logWithLevel:testLogLevelWarning timestamp:testDate file:testFileName functionName:testFunctionName line:testLineWarning queue:testQueue message:testMessageWarning];
+
+ // Error
+ [testManager logWithLevel:testLogLevelError timestamp:testDate file:testFileName functionName:testFunctionName line:testLineError queue:testQueue message:testMessageError];
+
+ // Debug
+ [testManager logWithLevel:testLogLevelDebug timestamp:testDate file:testFileName functionName:testFunctionName line:testLineDebug queue:testQueue message:testMessageDebug];
+
+ // Verbose
+ [testManager logWithLevel:testLogLevelVerbose timestamp:testDate file:testFileName functionName:testFunctionName line:testLineVerbose queue:testQueue message:testMessageVerbose];
+ });
+ });
+
+ afterEach(^{
+ expect(testManager.asynchronous).to(equal(NO));
+ expect(testLogTarget.formattedLogMessages.count).to(equal(expectedLogCount));
+
+ for(int i = 0; i < expectedMessages.count; i += 1) {
+ expect([testLogTarget.formattedLogMessages objectAtIndex:i]).to(contain(expectedMessages[i]));
+ }
+
+ for(int i = 0; i < notExpectedMessages.count; i += 1) {
+ expect(testLogTarget.formattedLogMessages).toNot(contain(notExpectedMessages[i]));
+ }
+ });
+ });
+ });
});
});
+
+
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