File tree 2 files changed +38
-4
lines changed 2 files changed +38
-4
lines changed Original file line number Diff line number Diff line change @@ -180,17 +180,35 @@ - (void)addLogToTrackingCollections:(GDLLogEvent *)log logFile:(NSURL *)logFile
180
180
181
181
#pragma mark - NSSecureCoding
182
182
183
+ /* * The NSKeyedCoder key for the logHashToFile property. */
184
+ static NSString *const kGDLLogHashToLogFileKey = @" logHashToLogFileKey" ;
185
+
186
+ /* * The NSKeyedCoder key for the logTargetToLogFileSet property. */
187
+ static NSString *const kGDLLogTargetToLogSetKey = @" logTargetToLogFileSetKey" ;
188
+
183
189
+ (BOOL )supportsSecureCoding {
184
190
return YES ;
185
191
}
186
192
187
193
- (instancetype )initWithCoder : (NSCoder *)aDecoder {
188
- // TODO
189
- return [self .class sharedInstance ];
194
+ // Create the singleton and populate its ivars.
195
+ GDLLogStorage *sharedInstance = [self .class sharedInstance ];
196
+ dispatch_sync (sharedInstance.storageQueue , ^{
197
+ Class NSMutableDictionaryClass = [NSMutableDictionary class ];
198
+ sharedInstance->_logHashToLogFile =
199
+ [aDecoder decodeObjectOfClass: NSMutableDictionaryClass forKey: kGDLLogHashToLogFileKey ];
200
+ sharedInstance->_logTargetToLogFileSet =
201
+ [aDecoder decodeObjectOfClass: NSMutableDictionaryClass forKey: kGDLLogTargetToLogSetKey ];
202
+ });
203
+ return sharedInstance;
190
204
}
191
205
192
206
- (void )encodeWithCoder : (NSCoder *)aCoder {
193
- // TODO
207
+ GDLLogStorage *sharedInstance = [self .class sharedInstance ];
208
+ dispatch_sync (sharedInstance.storageQueue , ^{
209
+ [aCoder encodeObject: sharedInstance->_logHashToLogFile forKey: kGDLLogHashToLogFileKey ];
210
+ [aCoder encodeObject: sharedInstance->_logTargetToLogFileSet forKey: kGDLLogTargetToLogSetKey ];
211
+ });
194
212
}
195
213
196
214
@end
Original file line number Diff line number Diff line change @@ -116,7 +116,23 @@ - (void)testLogEventDeallocationIsEnforced {
116
116
117
117
/* * Tests encoding and decoding the storage singleton correctly. */
118
118
- (void )testNSSecureCoding {
119
- // TODO
119
+ GDLLogEvent *logEvent = [[GDLLogEvent alloc ] initWithLogMapID: @" 404" logTarget: logTarget];
120
+ logEvent.extensionBytes = [@" testString" dataUsingEncoding: NSUTF8StringEncoding];
121
+ NSUInteger logHash = logEvent.hash ;
122
+ XCTAssertNoThrow ([[GDLLogStorage sharedInstance ] storeLog: logEvent]);
123
+ logEvent = nil ;
124
+ NSData *storageData = [NSKeyedArchiver archivedDataWithRootObject: [GDLLogStorage sharedInstance ]];
125
+ dispatch_sync ([GDLLogStorage sharedInstance ].storageQueue , ^{
126
+ XCTAssertNotNil ([GDLLogStorage sharedInstance ].logHashToLogFile [@(logHash)]);
127
+ });
128
+ [[GDLLogStorage sharedInstance ] removeLog: @(logHash) logTarget: @(logTarget)];
129
+ dispatch_sync ([GDLLogStorage sharedInstance ].storageQueue , ^{
130
+ XCTAssertNil ([GDLLogStorage sharedInstance ].logHashToLogFile [@(logHash)]);
131
+ });
132
+
133
+ // TODO(mikehaney24): Ensure that the object created by alloc is discarded?
134
+ [NSKeyedUnarchiver unarchiveObjectWithData: storageData];
135
+ XCTAssertNotNil ([GDLLogStorage sharedInstance ].logHashToLogFile [@(logHash)]);
120
136
}
121
137
122
138
/* * Tests logging a fast log causes an upload attempt. */
You can’t perform that action at this time.
0 commit comments