Skip to content

Commit e60c39f

Browse files
Add 4 new crash types for demonstration with PLCrashReporter, adds visual feedback to watchOS app when slecting row
1 parent 8ce2abc commit e60c39f

File tree

4 files changed

+60
-3
lines changed

4 files changed

+60
-3
lines changed

Test Harness/NRTestApp/NRTestApp (watchOS) Watch App/ContentView.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,26 @@ import SwiftUI
99
import NewRelic
1010

1111
struct ContentView: View {
12-
var viewModel = UtilViewModel()
1312

13+
@State private var isTapped: UtilOption? = nil
14+
var viewModel = UtilViewModel()
15+
1416
var body: some View {
1517
List(viewModel.options, id: \.title) { option in
1618
Text(option.title)
19+
.background( isTapped == option ? Color.gray.opacity(0.3) : Color.clear)
1720
.onTapGesture {
1821
option.handler()
1922
}
23+
.onLongPressGesture(minimumDuration: 0.1) { _ in
24+
withAnimation {
25+
isTapped = option
26+
}
27+
} perform: {
28+
withAnimation {
29+
isTapped = nil
30+
}
31+
}
2032
}
2133
.NRTrackView(name: "WatchOSContentView")
2234
}

Test Harness/NRTestApp/NRTestApp/Helpers/triggerException.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
@interface triggerException : NSObject
1111

1212
+ (void) testing;
13+
+ (void)invalidPerformSelector;
1314
@end

Test Harness/NRTestApp/NRTestApp/Helpers/triggerException.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@ + (void) testing {
1919
[NewRelic recordHandledException:e];
2020
}
2121
}
22+
+ (void)invalidPerformSelector {
23+
[self performSelector:@selector(die_die)];
24+
}
2225

2326
@end

Test Harness/NRTestApp/NRTestApp/ViewModels/UtilViewModel.swift

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
import Foundation
99
import NewRelic
1010

11-
struct UtilOption {
11+
struct UtilOption: Equatable {
12+
static func == (lhs: UtilOption, rhs: UtilOption) -> Bool {
13+
lhs.title == rhs.title
14+
}
15+
1216
let title:String
1317
let handler:(() -> Void)
1418
}
@@ -38,6 +42,13 @@ class UtilViewModel {
3842
options.append(UtilOption(title: "Set Attributes", handler: { [self] in setAttributes()}))
3943
options.append(UtilOption(title: "Remove Attributes", handler: { [self] in removeAttributes()}))
4044
options.append(UtilOption(title: "Crash Now!", handler: { [self] in crash()}))
45+
46+
// crash types
47+
options.append(UtilOption(title: "Unhandled Exception Now!", handler: { [self] in generateUncaughtException()}))
48+
options.append(UtilOption(title: "Stack Overflow Now!", handler: { [self] in generateStackOverflow()}))
49+
options.append(UtilOption(title: "Fatal App Hang Now!", handler: { [self] in generateFatalAppHang()}))
50+
options.append(UtilOption(title: "Raise NSException Now!", handler: { [self] in throwNSException()}))
51+
4152
options.append(UtilOption(title: "Record Error", handler: { [self] in makeError()}))
4253
options.append(UtilOption(title: "Record Handled Exception", handler: { triggerException.testing()}))
4354

@@ -62,11 +73,41 @@ class UtilViewModel {
6273
options.append(UtilOption(title: "Shut down New Relic Agent", handler: { [self] in shutDown()}))
6374
}
6475

76+
// Crash Types
6577
func crash() {
6678
// This will cause a crash to test the crash uploader, crash files may not get recorded if the debugger is running.
6779
NewRelic.crashNow("New Relic intentionally crashed to test Utils")
6880
}
69-
81+
82+
func generateUncaughtException() {
83+
let someJson : Dictionary = ["foo":self]
84+
do {
85+
let data = try JSONSerialization.data(withJSONObject: someJson, options: .prettyPrinted)
86+
print("Received data: %@", data)
87+
} catch {
88+
89+
}
90+
}
91+
92+
func generateStackOverflow() {
93+
let items = ["Hello world"]
94+
// Use if statement to remove warning about calling self through any path
95+
if (items[0] == "Hello world") {
96+
generateStackOverflow()
97+
}
98+
print("items: %@", items)
99+
}
100+
101+
func generateFatalAppHang() {
102+
Thread.sleep(forTimeInterval: 3)
103+
_exit(1)
104+
}
105+
106+
func throwNSException() {
107+
NSException(name: .internalInconsistencyException, reason: "example internalInconsistencyException", userInfo: nil).raise()
108+
}
109+
// End test crashes.
110+
70111
func removeAttributes() {
71112
if(NewRelic.removeAllAttributes()){
72113
attributes = ""

0 commit comments

Comments
 (0)