-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBugSplatTestSupport.h
More file actions
189 lines (144 loc) · 4.96 KB
/
BugSplatTestSupport.h
File metadata and controls
189 lines (144 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
//
// BugSplatTestSupport.h
//
// Protocols and utilities for testing BugSplat components.
// These protocols allow dependency injection for unit testing.
//
// Copyright © BugSplat, LLC. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
#pragma mark - URL Session Protocol
/**
* Protocol for URL session operations.
* NSURLSession already conforms to this implicitly, but having an explicit protocol
* allows for easy mocking in tests.
*/
@protocol BugSplatURLSessionProtocol <NSObject>
- (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request
completionHandler:(void (^)(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error))completionHandler;
- (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request
fromData:(NSData *)bodyData
completionHandler:(void (^)(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error))completionHandler;
- (void)invalidateAndCancel;
@end
// NSURLSession implicitly conforms to BugSplatURLSessionProtocol
// This category makes it explicit for documentation purposes
#pragma mark - Crash Reporter Protocol
/**
* Protocol for crash reporter operations.
* Allows mocking of PLCrashReporter for unit testing.
*/
@protocol BugSplatCrashReporterProtocol <NSObject>
/**
* Check if there is a pending crash report from the previous session.
*/
- (BOOL)hasPendingCrashReport;
/**
* Load the pending crash report data.
*/
- (nullable NSData *)loadPendingCrashReportDataAndReturnError:(NSError **)outError;
/**
* Purge (delete) the pending crash report.
*/
- (void)purgePendingCrashReport;
/**
* Enable the crash reporter.
*/
- (BOOL)enableCrashReporterAndReturnError:(NSError **)outError;
/**
* Custom data to embed in crash reports.
*/
@property (nonatomic, strong, nullable) NSData *customData;
@end
#pragma mark - Crash Storage Protocol
/**
* Protocol for crash report file storage operations.
* Allows mocking of file system operations for unit testing.
*/
@protocol BugSplatCrashStorageProtocol <NSObject>
/**
* Returns the path to the crashes directory, creating it if necessary.
*/
- (nullable NSString *)crashesDirectoryPath;
/**
* Get a list of pending crash filenames (without extension), sorted oldest first.
*/
- (NSArray<NSString *> *)getPendingCrashFiles;
/**
* Persist crash report data to disk.
*
* @param data The crash report data.
* @param filename The base filename (without extension).
* @return YES if successful, NO otherwise.
*/
- (BOOL)persistCrashData:(NSData *)data withFilename:(NSString *)filename;
/**
* Load crash report data from disk.
*
* @param filename The base filename (without extension).
* @return The crash data, or nil if not found.
*/
- (nullable NSData *)loadCrashDataWithFilename:(NSString *)filename;
/**
* Persist metadata for a crash report.
*
* @param metadata The metadata dictionary.
* @param filename The base filename (without extension).
* @return YES if successful, NO otherwise.
*/
- (BOOL)persistMetadata:(NSDictionary *)metadata forFilename:(NSString *)filename;
/**
* Load metadata for a crash report.
*
* @param filename The base filename (without extension).
* @return The metadata dictionary, or nil if not found.
*/
- (nullable NSDictionary *)loadMetadataForFilename:(NSString *)filename;
/**
* Persist an array of attachment data for a crash.
*
* @param attachmentsData Array of archived attachment data.
* @param filename The base crash filename.
*/
- (void)persistAttachmentsData:(NSArray<NSData *> *)attachmentsData forFilename:(NSString *)filename;
/**
* Load persisted attachments for a crash.
*
* @param filename The base crash filename.
* @return Array of archived attachment data.
*/
- (NSArray<NSData *> *)loadAttachmentsDataForFilename:(NSString *)filename;
/**
* Cleanup all files associated with a crash report.
*
* @param filename The base filename (without extension).
*/
- (void)cleanupCrashReportWithFilename:(NSString *)filename;
/**
* Cleanup all pending crash reports.
*/
- (void)cleanupAllPendingCrashReports;
@end
#pragma mark - Bundle Protocol
/**
* Protocol for accessing bundle information.
* Allows mocking of NSBundle for unit testing.
*/
@protocol BugSplatBundleProtocol <NSObject>
- (nullable id)objectForInfoDictionaryKey:(NSString *)key;
@end
// NSBundle implicitly conforms to BugSplatBundleProtocol
#pragma mark - User Defaults Protocol
/**
* Protocol for user defaults operations.
* Allows mocking of NSUserDefaults for unit testing.
*/
@protocol BugSplatUserDefaultsProtocol <NSObject>
- (nullable NSString *)stringForKey:(NSString *)defaultName;
- (BOOL)boolForKey:(NSString *)defaultName;
- (void)setObject:(nullable id)value forKey:(NSString *)defaultName;
- (void)setBool:(BOOL)value forKey:(NSString *)defaultName;
@end
// NSUserDefaults implicitly conforms to BugSplatUserDefaultsProtocol
NS_ASSUME_NONNULL_END