diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2017-03-07 15:38:45 -0500 |
---|---|---|
committer | Joel Fischer <joeljfischer@gmail.com> | 2017-03-07 15:38:45 -0500 |
commit | 143b7eaa355a421c0240613c3fb7b4812d81c193 (patch) | |
tree | 824098be431df73b26fd01f6e76b8bb6f901120d /SmartDeviceLinkTests/LoggingSpecs | |
parent | a239353f055f47290605c9a08c35f8e3a63dfdc5 (diff) | |
download | sdl_ios-143b7eaa355a421c0240613c3fb7b4812d81c193.tar.gz |
Fix module filters checking files instead of module name
* Add SDLLogFilter tests
Diffstat (limited to 'SmartDeviceLinkTests/LoggingSpecs')
-rw-r--r-- | SmartDeviceLinkTests/LoggingSpecs/SDLLogFilterSpec.m | 214 |
1 files changed, 214 insertions, 0 deletions
diff --git a/SmartDeviceLinkTests/LoggingSpecs/SDLLogFilterSpec.m b/SmartDeviceLinkTests/LoggingSpecs/SDLLogFilterSpec.m new file mode 100644 index 000000000..e5c659610 --- /dev/null +++ b/SmartDeviceLinkTests/LoggingSpecs/SDLLogFilterSpec.m @@ -0,0 +1,214 @@ +#import <Quick/Quick.h> +#import <Nimble/Nimble.h> + +#import "SDLLogFileModule.h" +#import "SDLLogFilter.h" +#import "SDLLogModel.h" + + +QuickSpecBegin(SDLLogFilterSpec) + +describe(@"a filter by a string", ^{ + __block NSString *testFilterString = @"filter string"; + __block SDLLogModel *testFilterModel = [[SDLLogModel alloc] initWithMessage:testFilterString timestamp:[NSDate date] level:SDLLogLevelDebug fileName:@"test" moduleName:@"test" functionName:@"test" line:0 queueLabel:@"test"]; + + __block NSString *testOtherString = @"Other string"; + __block SDLLogModel *testOtherModel = [[SDLLogModel alloc] initWithMessage:testOtherString timestamp:[NSDate date] level:SDLLogLevelDebug fileName:@"test" moduleName:@"test" functionName:@"test" line:0 queueLabel:@"test"]; + + __block NSString *testCaseFilterString = @"Filter string"; + __block SDLLogModel *testCaseFilterModel = [[SDLLogModel alloc] initWithMessage:testCaseFilterString timestamp:[NSDate date] level:SDLLogLevelDebug fileName:@"test" moduleName:@"test" functionName:@"test" line:0 queueLabel:@"test"]; + + context(@"that disallows a string", ^{ + context(@"that is case sensitive", ^{ + SDLLogFilterBlock testFilter = [SDLLogFilter filterByDisallowingString:testFilterString caseSensitive:YES]; + + it(@"should fail a matching string", ^{ + BOOL pass = testFilter(testFilterModel); + expect(@(pass)).to(equal(@NO)); + }); + + it(@"should pass a non-matching string", ^{ + BOOL pass = testFilter(testOtherModel); + expect(@(pass)).to(equal(@YES)); + }); + + it(@"should pass a differently cased string", ^{ + BOOL pass = testFilter(testCaseFilterModel); + expect(@(pass)).to(equal(@YES)); + }); + }); + + context(@"that is case insensitive", ^{ + SDLLogFilterBlock testFilter = [SDLLogFilter filterByDisallowingString:testFilterString caseSensitive:NO]; + + it(@"should fail a matching string", ^{ + BOOL pass = testFilter(testFilterModel); + expect(@(pass)).to(equal(@NO)); + }); + + it(@"should pass a non-matching string", ^{ + BOOL pass = testFilter(testOtherModel); + expect(@(pass)).to(equal(@YES)); + }); + + it(@"should fail a differently cased string", ^{ + BOOL pass = testFilter(testCaseFilterModel); + expect(@(pass)).to(equal(@NO)); + }); + }); + }); + + context(@"that allows a string", ^{ + context(@"that is case sensitive", ^{ + SDLLogFilterBlock testFilter = [SDLLogFilter filterByAllowingString:testFilterString caseSensitive:YES]; + + it(@"should pass a matching string", ^{ + BOOL pass = testFilter(testFilterModel); + expect(@(pass)).to(equal(@YES)); + }); + + it(@"should fail a non-matching string", ^{ + BOOL pass = testFilter(testOtherModel); + expect(@(pass)).to(equal(@NO)); + }); + + it(@"should fail a differently cased string", ^{ + BOOL pass = testFilter(testCaseFilterModel); + expect(@(pass)).to(equal(@NO)); + }); + }); + + context(@"that is case insensitive", ^{ + SDLLogFilterBlock testFilter = [SDLLogFilter filterByAllowingString:testFilterString caseSensitive:NO]; + + it(@"should pass a matching string", ^{ + BOOL pass = testFilter(testFilterModel); + expect(@(pass)).to(equal(@YES)); + }); + + it(@"should fail a non-matching string", ^{ + BOOL pass = testFilter(testOtherModel); + expect(@(pass)).to(equal(@NO)); + }); + + it(@"should pass a differently cased string", ^{ + BOOL pass = testFilter(testCaseFilterModel); + expect(@(pass)).to(equal(@YES)); + }); + }); + }); +}); + +describe(@"a filter by regex", ^{ + __block NSString *testFilterString = @"filter string"; + __block SDLLogModel *testFilterModel = [[SDLLogModel alloc] initWithMessage:testFilterString timestamp:[NSDate date] level:SDLLogLevelDebug fileName:@"test" moduleName:@"test" functionName:@"test" line:0 queueLabel:@"test"]; + + __block NSString *testOtherString = @"OTHER STRING"; + __block SDLLogModel *testOtherModel = [[SDLLogModel alloc] initWithMessage:testOtherString timestamp:[NSDate date] level:SDLLogLevelDebug fileName:@"test" moduleName:@"test" functionName:@"test" line:0 queueLabel:@"test"]; + + context(@"that disallows a regex", ^{ + NSRegularExpression *expr = [NSRegularExpression regularExpressionWithPattern:@"[a-z]+" options:0 error:nil]; + SDLLogFilterBlock testFilter = [SDLLogFilter filterByDisallowingRegex:expr]; + + it(@"should fail a matching string", ^{ + BOOL pass = testFilter(testFilterModel); + expect(@(pass)).to(equal(@NO)); + }); + + it(@"should pass a non-matching string", ^{ + BOOL pass = testFilter(testOtherModel); + expect(@(pass)).to(equal(@YES)); + }); + }); + + context(@"that allows a regex", ^{ + NSRegularExpression *expr = [NSRegularExpression regularExpressionWithPattern:@"[a-z]+" options:0 error:nil]; + SDLLogFilterBlock testFilter = [SDLLogFilter filterByAllowingRegex:expr]; + + it(@"should pass a matching string", ^{ + BOOL pass = testFilter(testFilterModel); + expect(@(pass)).to(equal(@YES)); + }); + + it(@"should fail a non-matching string", ^{ + BOOL pass = testFilter(testOtherModel); + expect(@(pass)).to(equal(@NO)); + }); + }); +}); + +describe(@"a filter by module", ^{ + __block NSString *testFilterModuleName = @"filter module"; + __block SDLLogModel *testFilterModel = [[SDLLogModel alloc] initWithMessage:@"test" timestamp:[NSDate date] level:SDLLogLevelDebug fileName:@"test" moduleName:testFilterModuleName functionName:@"test" line:0 queueLabel:@"test"]; + __block SDLLogFileModule *testFilterModule = [SDLLogFileModule moduleWithName:testFilterModuleName files:[NSSet setWithObject:@"test"]]; + + __block NSString *testOtherModuleName = @"other module"; + __block SDLLogModel *testOtherModel = [[SDLLogModel alloc] initWithMessage:@"test" timestamp:[NSDate date] level:SDLLogLevelDebug fileName:@"test" moduleName:testOtherModuleName functionName:@"test" line:0 queueLabel:@"test"]; + + context(@"that disallows modules", ^{ + SDLLogFilterBlock testFilter = [SDLLogFilter filterByDisallowingModules:[NSSet setWithObject:testFilterModule]]; + + it(@"should fail a matching module", ^{ + BOOL pass = testFilter(testFilterModel); + expect(@(pass)).to(equal(@NO)); + }); + + it(@"should pass a non-matching module", ^{ + BOOL pass = testFilter(testOtherModel); + expect(@(pass)).to(equal(@YES)); + }); + }); + + context(@"that allows modules", ^{ + SDLLogFilterBlock testFilter = [SDLLogFilter filterByAllowingModules:[NSSet setWithObject:testFilterModule]]; + + it(@"should pass a matching string", ^{ + BOOL pass = testFilter(testFilterModel); + expect(@(pass)).to(equal(@YES)); + }); + + it(@"should fail a non-matching string", ^{ + BOOL pass = testFilter(testOtherModel); + expect(@(pass)).to(equal(@NO)); + }); + }); +}); + +describe(@"a filter by file name", ^{ + __block NSString *testFilterFilename = @"filter file"; + __block SDLLogModel *testFilterModel = [[SDLLogModel alloc] initWithMessage:@"test" timestamp:[NSDate date] level:SDLLogLevelDebug fileName:testFilterFilename moduleName:@"test" functionName:@"test" line:0 queueLabel:@"test"]; + + __block NSString *testOtherModuleName = @"other file"; + __block SDLLogModel *testOtherModel = [[SDLLogModel alloc] initWithMessage:@"test" timestamp:[NSDate date] level:SDLLogLevelDebug fileName:testOtherModuleName moduleName:@"test" functionName:@"test" line:0 queueLabel:@"test"]; + + context(@"that disallows modules", ^{ + SDLLogFilterBlock testFilter = [SDLLogFilter filterByDisallowingFileNames:[NSSet setWithObject:testFilterFilename]]; + + it(@"should fail a matching module", ^{ + BOOL pass = testFilter(testFilterModel); + expect(@(pass)).to(equal(@NO)); + }); + + it(@"should pass a non-matching module", ^{ + BOOL pass = testFilter(testOtherModel); + expect(@(pass)).to(equal(@YES)); + }); + }); + + context(@"that allows modules", ^{ + SDLLogFilterBlock testFilter = [SDLLogFilter filterByAllowingFileNames:[NSSet setWithObject:testFilterFilename]]; + + it(@"should pass a matching string", ^{ + BOOL pass = testFilter(testFilterModel); + expect(@(pass)).to(equal(@YES)); + }); + + it(@"should fail a non-matching string", ^{ + BOOL pass = testFilter(testOtherModel); + expect(@(pass)).to(equal(@NO)); + }); + }); +}); + + +QuickSpecEnd |