PageRenderTime 59ms CodeModel.GetById 14ms app.highlight 41ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/update-engine/externals/google-toolbox-for-mac/Foundation/GTMLogger+ASLTest.m

http://macfuse.googlecode.com/
Objective C | 131 lines | 82 code | 26 blank | 23 comment | 1 complexity | 7899830900b44ea90ff3453e9892d24c MD5 | raw file
  1//
  2//  GTMLogger+ASLTest.m
  3//
  4//  Copyright 2007-2008 Google Inc.
  5//
  6//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
  7//  use this file except in compliance with the License.  You may obtain a copy
  8//  of the License at
  9//
 10//  http://www.apache.org/licenses/LICENSE-2.0
 11//
 12//  Unless required by applicable law or agreed to in writing, software
 13//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 14//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 15//  License for the specific language governing permissions and limitations under
 16//  the License.
 17//
 18
 19#import "GTMLogger+ASL.h"
 20#import "GTMSenTestCase.h"
 21
 22@interface DummyASLClient : GTMLoggerASLClient {
 23 @private
 24  NSString *facility_;
 25}
 26@end
 27
 28static NSMutableArray *gDummyLog;  // weak
 29
 30@implementation DummyASLClient
 31
 32- (id)initWithFacility:(NSString *)facility {
 33  if ((self = [super initWithFacility:facility])) {
 34    facility_ = [facility copy];
 35  }
 36  return self;
 37}
 38
 39- (void)dealloc {
 40  [facility_ release];
 41  [super dealloc];
 42}
 43
 44- (void)log:(NSString *)msg level:(int)level {
 45  NSString *line = [NSString stringWithFormat:@"%@-%@-%d",
 46                       (facility_ ? facility_ : @""), msg, level];
 47  [gDummyLog addObject:line];
 48}
 49
 50@end
 51
 52
 53@interface GTMLogger_ASLTest : GTMTestCase
 54@end
 55
 56@implementation GTMLogger_ASLTest
 57
 58- (void)testCreation {
 59  GTMLogger *aslLogger = [GTMLogger standardLoggerWithASL];
 60  STAssertNotNil(aslLogger, nil);
 61
 62  GTMLogASLWriter *writer = [GTMLogASLWriter aslWriter];
 63  STAssertNotNil(writer, nil);
 64}
 65
 66- (void)testLogWriter {
 67  gDummyLog = [[[NSMutableArray alloc] init] autorelease];
 68  GTMLogASLWriter *writer = [[[GTMLogASLWriter alloc]
 69                              initWithClientClass:[DummyASLClient class]
 70                                         facility:nil]
 71                             autorelease];
 72
 73
 74  STAssertNotNil(writer, nil);
 75  STAssertEquals([gDummyLog count], (NSUInteger)0, nil);
 76
 77  // Log some messages
 78  [writer logMessage:@"unknown" level:kGTMLoggerLevelUnknown];
 79  [writer logMessage:@"debug" level:kGTMLoggerLevelDebug];
 80  [writer logMessage:@"info" level:kGTMLoggerLevelInfo];
 81  [writer logMessage:@"error" level:kGTMLoggerLevelError];
 82  [writer logMessage:@"assert" level:kGTMLoggerLevelAssert];
 83
 84  // Inspect the logged message to make sure they were logged correctly. The
 85  // dummy writer will save the messages w/ @level concatenated. The "level"
 86  // will be the ASL level, not the GTMLogger level. GTMLogASLWriter will log
 87  // all
 88  NSArray *expected = [NSArray arrayWithObjects:
 89                       @"-unknown-5",
 90                       @"-debug-5",
 91                       @"-info-5",
 92                       @"-error-3",
 93                       @"-assert-1",
 94                       nil];
 95
 96  STAssertEqualObjects(gDummyLog, expected, nil);
 97  [gDummyLog removeAllObjects];
 98
 99  // Same test with facility
100  writer = [[[GTMLogASLWriter alloc]
101               initWithClientClass:[DummyASLClient class]
102                          facility:@"testfac"] autorelease];
103
104
105  STAssertNotNil(writer, nil);
106  STAssertEquals([gDummyLog count], (NSUInteger)0, nil);
107
108  [writer logMessage:@"unknown" level:kGTMLoggerLevelUnknown];
109  [writer logMessage:@"debug" level:kGTMLoggerLevelDebug];
110  [writer logMessage:@"info" level:kGTMLoggerLevelInfo];
111  [writer logMessage:@"error" level:kGTMLoggerLevelError];
112  [writer logMessage:@"assert" level:kGTMLoggerLevelAssert];
113  expected = [NSArray arrayWithObjects:
114                @"testfac-unknown-5",
115                @"testfac-debug-5",
116                @"testfac-info-5",
117                @"testfac-error-3",
118                @"testfac-assert-1",
119                nil];
120  STAssertEqualObjects(gDummyLog, expected, nil);
121
122  gDummyLog = nil;
123}
124
125- (void)testASLClient {
126  GTMLoggerASLClient *client = [[GTMLoggerASLClient alloc] init];
127  STAssertNotNil(client, nil);
128  [client release];
129}
130
131@end