|
| 1 | +// |
| 2 | +// InstabugAPMTests.m |
| 3 | +// InstabugSampleTests |
| 4 | +// |
| 5 | +// Created by Ali Abdelfattah on 12/12/20. |
| 6 | +// Copyright © 2020 Facebook. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +#import <XCTest/XCTest.h> |
| 10 | +#import "OCMock/OCMock.h" |
| 11 | +#import "InstabugAPMBridge.h" |
| 12 | +#import <Instabug/IBGTypes.h> |
| 13 | +#import <Instabug/IBGAPM.h> |
| 14 | +#import "Instabug/Instabug.h" |
| 15 | +#import "IBGConstants.h" |
| 16 | + |
| 17 | +@interface InstabugAPMTests : XCTestCase |
| 18 | +@property (nonatomic, retain) InstabugAPMBridge *instabugBridge; |
| 19 | +@end |
| 20 | + |
| 21 | +@protocol APMCPTestProtocol <NSObject> |
| 22 | +/** |
| 23 | + * This protocol helps in correctly mapping APM mocked methods |
| 24 | + * when their method name matches another method in a different |
| 25 | + * module that differs in method signature. |
| 26 | + */ |
| 27 | +- (void)setEnabled:(BOOL)isEnabled; |
| 28 | + |
| 29 | +@end |
| 30 | + |
| 31 | +@protocol ExecutionTraceCPTestProtocol <NSObject> |
| 32 | +/** |
| 33 | + * This protocol helps in correctly mapping IBGExecutionTrace mocked methods |
| 34 | + * when their method name matches another method in a different |
| 35 | + * module that differs in method signature. |
| 36 | + */ |
| 37 | +- (void)end; |
| 38 | +@end |
| 39 | + |
| 40 | +@implementation InstabugAPMTests |
| 41 | + |
| 42 | +- (void)setUp { |
| 43 | + // Put setup code here. This method is called before the invocation of each test method in the class. |
| 44 | + self.instabugBridge = [[InstabugAPMBridge alloc] init]; |
| 45 | +} |
| 46 | + |
| 47 | +/* |
| 48 | ++------------------------------------------------------------------------+ |
| 49 | +| APM Module | |
| 50 | ++------------------------------------------------------------------------+ |
| 51 | +*/ |
| 52 | + |
| 53 | +- (void) testSetAPMEnabled { |
| 54 | + id mock = OCMClassMock([IBGAPM class]); |
| 55 | + BOOL isEnabled = YES; |
| 56 | + |
| 57 | + OCMStub([mock setEnabled:isEnabled]); |
| 58 | + [self.instabugBridge setEnabled:isEnabled]; |
| 59 | + OCMVerify([mock setEnabled:isEnabled]); |
| 60 | +} |
| 61 | + |
| 62 | +- (void) testSetLogLevel { |
| 63 | + id mock = OCMClassMock([IBGAPM class]); |
| 64 | + BOOL logLevel = IBGLogLevelVerbose; |
| 65 | + |
| 66 | + OCMStub([mock setLogLevel:logLevel]); |
| 67 | + [self.instabugBridge setLogLevel:logLevel]; |
| 68 | + OCMVerify([mock setLogLevel:logLevel]); |
| 69 | +} |
| 70 | + |
| 71 | +- (void) testSetAppLaunchEnabled { |
| 72 | + id mock = OCMClassMock([IBGAPM class]); |
| 73 | + BOOL isEnabled = YES; |
| 74 | + |
| 75 | + OCMStub([mock setAppLaunchEnabled:isEnabled]); |
| 76 | + [self.instabugBridge setAppLaunchEnabled:isEnabled]; |
| 77 | + OCMVerify([mock setAppLaunchEnabled:isEnabled]); |
| 78 | +} |
| 79 | + |
| 80 | +- (void) testSetAutoUITraceEnabled { |
| 81 | + id mock = OCMClassMock([IBGAPM class]); |
| 82 | + BOOL isEnabled = YES; |
| 83 | + |
| 84 | + OCMStub([mock setAutoUITraceEnabled:isEnabled]); |
| 85 | + [self.instabugBridge setAutoUITraceEnabled:isEnabled]; |
| 86 | + OCMVerify([mock setAutoUITraceEnabled:isEnabled]); |
| 87 | +} |
| 88 | + |
| 89 | +- (void) testStartExecutionTrace { |
| 90 | + id mock = OCMClassMock([IBGAPM class]); |
| 91 | + NSString* traceName = @"Trace_1"; |
| 92 | + NSString* traceKey = @"1"; |
| 93 | + RCTResponseSenderBlock callback = ^(NSArray *response) {}; |
| 94 | + |
| 95 | + OCMStub([mock startExecutionTraceWithName:traceName]); |
| 96 | + [self.instabugBridge startExecutionTrace:traceName :traceKey :callback]; |
| 97 | + OCMVerify([mock startExecutionTraceWithName:traceName]); |
| 98 | +} |
| 99 | + |
| 100 | +- (void) testSetExecutionTraceAttribute { |
| 101 | + NSString* traceName = @"Trace_1"; |
| 102 | + NSString* traceId = @"Id_1"; |
| 103 | + NSString* traceKey = @"Key_1"; |
| 104 | + NSString* traceValue = @"1"; |
| 105 | + RCTResponseSenderBlock callback = ^(NSArray *response) {}; |
| 106 | + IBGExecutionTrace * trace = [IBGExecutionTrace alloc]; |
| 107 | + id mock = OCMClassMock([IBGAPM class]); |
| 108 | + id traceMock = OCMPartialMock(trace); |
| 109 | + |
| 110 | + OCMStub([mock startExecutionTraceWithName:traceName]).andReturn(trace); |
| 111 | + [self.instabugBridge startExecutionTrace:traceName :traceId :callback]; |
| 112 | + |
| 113 | + OCMStub([traceMock setAttributeWithKey:traceKey value:traceValue]); |
| 114 | + [self.instabugBridge setExecutionTraceAttribute:traceId :traceKey :traceValue]; |
| 115 | + OCMVerify([traceMock setAttributeWithKey:traceKey value:traceValue]); |
| 116 | +} |
| 117 | + |
| 118 | +- (void) testEndExecutionTrace { |
| 119 | + NSString* traceName = @"Trace_1"; |
| 120 | + NSString* traceId = @"Id_1"; |
| 121 | + RCTResponseSenderBlock callback = ^(NSArray *response) {}; |
| 122 | + IBGExecutionTrace * trace = [IBGExecutionTrace alloc]; |
| 123 | + id apmMock = OCMClassMock([IBGAPM class]); |
| 124 | + id<ExecutionTraceCPTestProtocol> traceMock = OCMPartialMock(trace); |
| 125 | + |
| 126 | + OCMStub([apmMock startExecutionTraceWithName:traceName]).andReturn(trace); |
| 127 | + [self.instabugBridge startExecutionTrace:traceName :traceId :callback]; |
| 128 | + |
| 129 | + OCMStub([traceMock end]); |
| 130 | + [self.instabugBridge endExecutionTrace:traceId]; |
| 131 | + OCMVerify([traceMock end]); |
| 132 | +} |
| 133 | + |
| 134 | +- (void) testStartUITrace { |
| 135 | + id mock = OCMClassMock([IBGAPM class]); |
| 136 | + NSString* traceName = @"UITrace_1"; |
| 137 | + |
| 138 | + OCMStub([mock startUITraceWithName:traceName]); |
| 139 | + [self.instabugBridge startUITrace:traceName]; |
| 140 | + OCMVerify([mock startUITraceWithName:traceName]); |
| 141 | +} |
| 142 | + |
| 143 | +- (void) testEndUITrace { |
| 144 | + id mock = OCMClassMock([IBGAPM class]); |
| 145 | + |
| 146 | + OCMStub([mock endUITrace]); |
| 147 | + [self.instabugBridge endUITrace]; |
| 148 | + OCMVerify([mock endUITrace]); |
| 149 | +} |
| 150 | + |
| 151 | +@end |
0 commit comments