summaryrefslogtreecommitdiffstats
path: root/macosx/HandBrake Tests/HBPresetsTests.m
diff options
context:
space:
mode:
authorDamiano Galassi <[email protected]>2015-11-03 10:00:12 +0100
committerDamiano Galassi <[email protected]>2015-11-03 10:00:12 +0100
commit4c829b3c2cd3789ae001ce91f7fc0a64c8c66f58 (patch)
treeaea1d0c8bc10629eb28610a0d51f94fffa1e0214 /macosx/HandBrake Tests/HBPresetsTests.m
parent10cb64d1dc4c4572b8496ead471fc22ca98289e6 (diff)
MacGui: add two tests for presets save and upgrade.
Diffstat (limited to 'macosx/HandBrake Tests/HBPresetsTests.m')
-rw-r--r--macosx/HandBrake Tests/HBPresetsTests.m53
1 files changed, 52 insertions, 1 deletions
diff --git a/macosx/HandBrake Tests/HBPresetsTests.m b/macosx/HandBrake Tests/HBPresetsTests.m
index 231f151a4..af7e48ddd 100644
--- a/macosx/HandBrake Tests/HBPresetsTests.m
+++ b/macosx/HandBrake Tests/HBPresetsTests.m
@@ -46,8 +46,59 @@
[self measureBlock:^{
[manager generateBuiltInPresets];
-
}];
}
+- (void)testSave
+{
+ NSURL *tempURL = [NSURL fileURLWithPath:NSTemporaryDirectory()];
+ NSURL *presetsURL = [tempURL URLByAppendingPathComponent:@"test.json"];
+ HBPresetsManager *manager = [[HBPresetsManager alloc] initWithURL:presetsURL];
+ [manager savePresets];
+
+ XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:presetsURL.path]);
+
+ // Remove the temp files.
+ [[NSFileManager defaultManager] removeItemAtURL:presetsURL error:NULL];
+}
+
+- (void)testUpgrade
+{
+ NSURL *tempURL = [NSURL fileURLWithPath:NSTemporaryDirectory()];
+ NSURL *presetsURL = [tempURL URLByAppendingPathComponent:@"test.json"];
+ NSURL *modifiedPresetsURL = [tempURL URLByAppendingPathComponent:@"test2.json"];
+
+ // Create a new presets manager with the defaults presets.
+ HBPresetsManager *manager = [[HBPresetsManager alloc] initWithURL:presetsURL];
+ [manager savePresets];
+
+ // Read the json and change the version to the previous major
+ // so it will kick in the import routine.
+ NSData *data = [NSData dataWithContentsOfURL:presetsURL];
+ NSMutableDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:NULL];
+ dict[@"VersionMajor"] = @([dict[@"VersionMajor"] integerValue] - 1);
+
+
+ NSString *backupName = [NSString stringWithFormat:@"%@.%d.%d.%d.json",
+ modifiedPresetsURL.lastPathComponent.stringByDeletingPathExtension,
+ [dict[@"VersionMajor"] intValue],
+ [dict[@"VersionMinor"] intValue],
+ [dict[@"VersionMicro"] intValue]];
+ NSURL *backupURL = [tempURL URLByAppendingPathComponent:backupName];
+
+ NSData *modifiedData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:NULL];
+ [modifiedData writeToURL:modifiedPresetsURL atomically:YES];
+
+ // Create a new manager and init it with the modified json.
+ HBPresetsManager *newManager = [[HBPresetsManager alloc] initWithURL:modifiedPresetsURL];
+
+ XCTAssert(newManager);
+ XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:backupURL.path]);
+
+ // Remove the temp files.
+ [[NSFileManager defaultManager] removeItemAtURL:presetsURL error:NULL];
+ [[NSFileManager defaultManager] removeItemAtURL:modifiedPresetsURL error:NULL];
+ [[NSFileManager defaultManager] removeItemAtURL:backupURL error:NULL];
+}
+
@end