Skip to content

Commit

Permalink
Merge pull request #65 from WideSpectrumComputing/master
Browse files Browse the repository at this point in the history
Exploring AUL integration within unit tests
  • Loading branch information
akornich authored Apr 15, 2021
2 parents 50a7ef4 + b0f1e44 commit 6fa0b1d
Show file tree
Hide file tree
Showing 12 changed files with 710 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ Dist/
build/

build_wrapper_output_directory/

_ General AUL Entries Bulk Capture.txt

_ AUL Entries Capture Samples.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"repositoryURL": "https://github.com/microsoft/plcrashreporter.git",
"state": {
"branch": "master",
"revision": "2afa27e23452171b971f67730821b7befa96842b",
"revision": "b7b88ee14bbc25ce408ae05464cb6f1cdd747948",
"version": null
}
},
Expand All @@ -24,7 +24,7 @@
"repositoryURL": "https://github.com/rollbar/rollbar-apple",
"state": {
"branch": "master",
"revision": "f32c08cf61692a2fbe7de5e0aedf49a1d1534683",
"revision": "50a7ef4569dd43619651c40dd11ccd16c67950b0",
"version": null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ + (NSMutableDictionary *)rollbar_safeDataFromJSONObject:(id)obj {
else if([obj description]) {
[safeData setObject:[obj description] forKey:key];
}
} else if ([obj isKindOfClass:[NSError class]] && [obj userInfo]) {
} else if ([obj isKindOfClass:[NSError class]] && (nil != [obj userInfo])) {
NSDictionary* userInfoData = [[self class] rollbar_safeDataFromJSONObject:[obj userInfo]];
if (userInfoData) {
[safeData setObject:userInfoData forKey:key];
Expand All @@ -76,7 +76,7 @@ + (NSMutableDictionary *)rollbar_safeDataFromJSONObject:(id)obj {
[NSJSONSerialization JSONObjectWithData:obj
options:(NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves)
error:&error];
if (error == nil) {
if ((error == nil) && (nil != json)) {
NSDictionary *jsonData = [[self class] rollbar_safeDataFromJSONObject:json];
if (jsonData) {
[safeData setObject:jsonData forKey:key];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ @implementation RollbarCallStackFrame
#pragma mark - Properties

-(nonnull NSString *)filename {
return [self getDataByKey:DFK_FILENAME];
return [self safelyGetStringByKey:DFK_FILENAME];;
}

-(void)setFilename:(nonnull NSString *)value {
Expand Down
8 changes: 4 additions & 4 deletions RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarData.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ @implementation RollbarData
#pragma mark - properties

- (NSString *)environment {
return [self getDataByKey:DFK_ENVIRONMENT];
return [self safelyGetStringByKey:DFK_ENVIRONMENT];
}

- (void)setEnvironment:(NSString *)environment {
Expand All @@ -63,7 +63,7 @@ -(void)setBody:(nonnull RollbarBody *)value {
}

-(RollbarLevel)level {
NSString *result = [self getDataByKey:DFK_LEVEL];
NSString *result = [self safelyGetStringByKey:DFK_LEVEL];
return [RollbarLevelUtil RollbarLevelFromString:result];
}

Expand All @@ -85,7 +85,7 @@ -(void)setTimestamp:(NSTimeInterval)value {
}

-(NSString *)codeVersion {
NSString *result = [self getDataByKey:DFK_CODE_VERSION];
NSString *result = [self safelyGetStringByKey:DFK_CODE_VERSION];
return result;
}

Expand All @@ -103,7 +103,7 @@ -(void)setPlatform:(NSString *)value {
}

-(RollbarAppLanguage)language {
NSString *result = [self getDataByKey:DFK_LANGUAGE];
NSString *result = [self safelyGetStringByKey:DFK_LANGUAGE];
return [RollbarAppLanguageUtil RollbarAppLanguageFromString:result];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// RollbarAulLogLevelConverter.m
//
//
// Created by Andrey Kornich on 2021-03-24.
//

#import "RollbarAulLogLevelConverter.h"

@implementation RollbarAulLogLevelConverter

+ (os_log_type_t) RollbarLevelToAulLevel:(RollbarLevel)value {

switch (value) {
case RollbarLevel_Debug:
return OS_LOG_TYPE_DEBUG;
case RollbarLevel_Info:
return OS_LOG_TYPE_INFO;
case RollbarLevel_Warning:
return OS_LOG_TYPE_DEFAULT;
case RollbarLevel_Error:
return OS_LOG_TYPE_ERROR;
case RollbarLevel_Critical:
return OS_LOG_TYPE_FAULT;
}
}

+ (RollbarLevel) RollbarLevelFromAulLevel:(os_log_type_t)value {

switch (value) {
case OS_LOG_TYPE_DEBUG:
return RollbarLevel_Debug;
case OS_LOG_TYPE_INFO:
return RollbarLevel_Info;
case OS_LOG_TYPE_ERROR:
return RollbarLevel_Error;
case OS_LOG_TYPE_FAULT:
return RollbarLevel_Critical;
case OS_LOG_TYPE_DEFAULT:
return RollbarLevel_Warning;
}
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// RollbarAulOSLogEntryLogLevelConverter.m
//
//
// Created by Andrey Kornich on 2021-03-24.
//

#import "RollbarAulOSLogEntryLogLevelConverter.h"

@implementation RollbarAulOSLogEntryLogLevelConverter

+ (OSLogEntryLogLevel) RollbarLevelToOSLogEntryLogLevel:(RollbarLevel)value {

switch (value) {

case RollbarLevel_Debug:
return OSLogEntryLogLevelDebug;
case RollbarLevel_Info:
return OSLogEntryLogLevelInfo;
case RollbarLevel_Warning:
return OSLogEntryLogLevelNotice;
case RollbarLevel_Error:
return OSLogEntryLogLevelError;
case RollbarLevel_Critical:
return OSLogEntryLogLevelFault;
}
}

+ (RollbarLevel) RollbarLevelFromOSLogEntryLogLevel:(OSLogEntryLogLevel)value {

switch (value) {

case OSLogEntryLogLevelUndefined:
case OSLogEntryLogLevelDebug:
return RollbarLevel_Debug;
case OSLogEntryLogLevelInfo:
return RollbarLevel_Info;
case OSLogEntryLogLevelNotice:
return RollbarLevel_Warning;
case OSLogEntryLogLevelError:
return RollbarLevel_Error;
case OSLogEntryLogLevelFault:
return RollbarLevel_Critical;
}
}

+ (NSString *) OSLogEntryLogLevelToString:(OSLogEntryLogLevel)value {

switch (value) {

case OSLogEntryLogLevelUndefined:
return @"OSLogEntryLogLevelUndefined";
case OSLogEntryLogLevelDebug:
return @"OSLogEntryLogLevelDebug";
case OSLogEntryLogLevelInfo:
return @"OSLogEntryLogLevelInfo";
case OSLogEntryLogLevelNotice:
return @"OSLogEntryLogLevelNotice";
case OSLogEntryLogLevelError:
return @"OSLogEntryLogLevelError";
case OSLogEntryLogLevelFault:
return @"OSLogEntryLogLevelFault";
}
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// RollbarAulLogLevelConverter.h
//
//
// Created by Andrey Kornich on 2021-03-24.
//

@import Foundation;
@import OSLog;

#import "RollbarLevel.h"

NS_ASSUME_NONNULL_BEGIN

@interface RollbarAulLogLevelConverter : NSObject

+ (os_log_type_t) RollbarLevelToAulLevel:(RollbarLevel)value;

+ (RollbarLevel) RollbarLevelFromAulLevel:(os_log_type_t)value;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// RollbarAulOSLogEntryLogLevelConverter.h
//
//
// Created by Andrey Kornich on 2021-03-24.
//

@import Foundation;
@import OSLog;

#import "RollbarLevel.h"

NS_ASSUME_NONNULL_BEGIN

API_AVAILABLE(macos(10.15))
API_UNAVAILABLE(ios, tvos, watchos)
@interface RollbarAulOSLogEntryLogLevelConverter : NSObject

+ (OSLogEntryLogLevel) RollbarLevelToOSLogEntryLogLevel:(RollbarLevel)value;

+ (RollbarLevel) RollbarLevelFromOSLogEntryLogLevel:(OSLogEntryLogLevel)value;

+ (NSString *) OSLogEntryLogLevelToString:(OSLogEntryLogLevel)value;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
@import Foundation;
@import OSLog;
@import RollbarNotifier;

#if !TARGET_OS_WATCH
#import <XCTest/XCTest.h>

@import RollbarNotifier;

@interface RollbarAulLogLevelConverterTests : XCTestCase

@end

@implementation RollbarAulLogLevelConverterTests

- (void)setUp {
[super setUp];
}

- (void)tearDown {
[super tearDown];
}

- (NSArray<NSNumber *> *) getOrederedAulLevels {

return @[

[NSNumber numberWithUnsignedShort:OS_LOG_TYPE_DEBUG],
[NSNumber numberWithUnsignedShort:OS_LOG_TYPE_INFO],
[NSNumber numberWithUnsignedShort:OS_LOG_TYPE_DEFAULT],
[NSNumber numberWithUnsignedShort:OS_LOG_TYPE_ERROR],
[NSNumber numberWithUnsignedShort:OS_LOG_TYPE_FAULT]
];
}

- (NSArray<NSNumber *> *) getOrederedRollbarLevels {

return @[

[NSNumber numberWithUnsignedLong:RollbarLevel_Debug],
[NSNumber numberWithUnsignedLong:RollbarLevel_Info],
[NSNumber numberWithUnsignedLong:RollbarLevel_Warning],
[NSNumber numberWithUnsignedLong:RollbarLevel_Error],
[NSNumber numberWithUnsignedLong:RollbarLevel_Critical]
];
}

- (void)testRollbarLevelFromAulLevel {

XCTAssertEqual(RollbarLevel_Debug, [RollbarAulLogLevelConverter RollbarLevelFromAulLevel:OS_LOG_TYPE_DEBUG]);
XCTAssertEqual(RollbarLevel_Info, [RollbarAulLogLevelConverter RollbarLevelFromAulLevel:OS_LOG_TYPE_INFO]);
XCTAssertEqual(RollbarLevel_Warning, [RollbarAulLogLevelConverter RollbarLevelFromAulLevel:OS_LOG_TYPE_DEFAULT]);
XCTAssertEqual(RollbarLevel_Error, [RollbarAulLogLevelConverter RollbarLevelFromAulLevel:OS_LOG_TYPE_ERROR]);
XCTAssertEqual(RollbarLevel_Critical, [RollbarAulLogLevelConverter RollbarLevelFromAulLevel:OS_LOG_TYPE_FAULT]);
}

- (void)testRollbarLevelToAulLevel {

XCTAssertEqual(OS_LOG_TYPE_DEBUG, [RollbarAulLogLevelConverter RollbarLevelToAulLevel:RollbarLevel_Debug]);
XCTAssertEqual(OS_LOG_TYPE_INFO, [RollbarAulLogLevelConverter RollbarLevelToAulLevel:RollbarLevel_Info]);
XCTAssertEqual(OS_LOG_TYPE_DEFAULT, [RollbarAulLogLevelConverter RollbarLevelToAulLevel:RollbarLevel_Warning]);
XCTAssertEqual(OS_LOG_TYPE_ERROR, [RollbarAulLogLevelConverter RollbarLevelToAulLevel:RollbarLevel_Error]);
XCTAssertEqual(OS_LOG_TYPE_FAULT, [RollbarAulLogLevelConverter RollbarLevelToAulLevel:RollbarLevel_Critical]);
}

@end
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
@import Foundation;
@import OSLog;
@import RollbarNotifier;

#if !TARGET_OS_WATCH
#import <XCTest/XCTest.h>

@import RollbarNotifier;

@interface RollbarAulOSLogEntryLogLevelConverterTests : XCTestCase

@end

@implementation RollbarAulOSLogEntryLogLevelConverterTests

- (void)setUp {
[super setUp];
}

- (void)tearDown {
[super tearDown];
}

- (void)testRollbarLevelFromOSLogEntryLogLevel {

XCTAssertEqual(RollbarLevel_Debug,
[RollbarAulOSLogEntryLogLevelConverter RollbarLevelFromOSLogEntryLogLevel:OSLogEntryLogLevelUndefined]);
XCTAssertEqual(RollbarLevel_Debug,
[RollbarAulOSLogEntryLogLevelConverter RollbarLevelFromOSLogEntryLogLevel:OSLogEntryLogLevelDebug]);
XCTAssertEqual(RollbarLevel_Info,
[RollbarAulOSLogEntryLogLevelConverter RollbarLevelFromOSLogEntryLogLevel:OSLogEntryLogLevelInfo]);
XCTAssertEqual(RollbarLevel_Warning,
[RollbarAulOSLogEntryLogLevelConverter RollbarLevelFromOSLogEntryLogLevel:OSLogEntryLogLevelNotice]);
XCTAssertEqual(RollbarLevel_Error,
[RollbarAulOSLogEntryLogLevelConverter RollbarLevelFromOSLogEntryLogLevel:OSLogEntryLogLevelError]);
XCTAssertEqual(RollbarLevel_Critical,
[RollbarAulOSLogEntryLogLevelConverter RollbarLevelFromOSLogEntryLogLevel:OSLogEntryLogLevelFault]);
}

- (void)testRollbarLevelToOSLogEntryLogLevel {

XCTAssertEqual(OSLogEntryLogLevelDebug,
[RollbarAulOSLogEntryLogLevelConverter RollbarLevelToOSLogEntryLogLevel:RollbarLevel_Debug]);
XCTAssertEqual(OSLogEntryLogLevelInfo,
[RollbarAulOSLogEntryLogLevelConverter RollbarLevelToOSLogEntryLogLevel:RollbarLevel_Info]);
XCTAssertEqual(OSLogEntryLogLevelNotice,
[RollbarAulOSLogEntryLogLevelConverter RollbarLevelToOSLogEntryLogLevel:RollbarLevel_Warning]);
XCTAssertEqual(OSLogEntryLogLevelError,
[RollbarAulOSLogEntryLogLevelConverter RollbarLevelToOSLogEntryLogLevel:RollbarLevel_Error]);
XCTAssertEqual(OSLogEntryLogLevelFault,
[RollbarAulOSLogEntryLogLevelConverter RollbarLevelToOSLogEntryLogLevel:RollbarLevel_Critical]);
}

@end
#endif
Loading

0 comments on commit 6fa0b1d

Please sign in to comment.