diff options
author | Damiano Galassi <[email protected]> | 2015-10-25 07:04:39 +0100 |
---|---|---|
committer | Damiano Galassi <[email protected]> | 2015-10-25 07:04:39 +0100 |
commit | b5a8b39d9b2efea411a02bc906f275fc78ba92b4 (patch) | |
tree | 20400435cd8d3970297bd109ac6f9567c7703c62 /macosx | |
parent | 646cb272a2c9feecc5a839360248621991c1f453 (diff) |
MacGui: add some simple tests for the undo/redo implementation of HBJob.
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/HandBrake Tests/HBJobUndoTests.m | 182 | ||||
-rw-r--r-- | macosx/HandBrake Tests/HBMockTitle.m | 14 | ||||
-rw-r--r-- | macosx/HandBrake.xcodeproj/project.pbxproj | 4 |
3 files changed, 198 insertions, 2 deletions
diff --git a/macosx/HandBrake Tests/HBJobUndoTests.m b/macosx/HandBrake Tests/HBJobUndoTests.m new file mode 100644 index 000000000..c62d4b1f3 --- /dev/null +++ b/macosx/HandBrake Tests/HBJobUndoTests.m @@ -0,0 +1,182 @@ +/* HBJobUndoTests.m + + This file is part of the HandBrake source code. + Homepage: <http://handbrake.fr/>. + It may be used under the terms of the GNU General Public License. */ + +#import <XCTest/XCTest.h> + +#import "HBMockTitle.h" +#import "HBJob.h" +#import "HBChapter.h" +#import "HBAudioTrack.h" +#import "HBSubtitlesTrack.h" +#import "HBPicture.h" +#import "HBPresetsManager.h" +#import "HBPreset.h" + +@interface HBJobUndoTests : XCTestCase + +@property (nonatomic, readonly) HBPresetsManager *manager; + +@property (nonatomic, readwrite) HBPreset *preset; +@property (nonatomic, readwrite) HBTitle *title; +@property (nonatomic, readwrite) HBJob *job; +@property (nonatomic, readwrite) HBJob *modifiedJob; + +@end + +@implementation HBJobUndoTests + +- (void)setUp +{ + [super setUp]; + + _manager = [[HBPresetsManager alloc] init]; + [_manager generateBuiltInPresets]; + + self.preset = self.manager.defaultPreset; + + self.title = [[HBMockTitle alloc] init]; + + self.job = [[HBJob alloc] initWithTitle:self.title andPreset:self.preset]; + self.job.destURL = [NSURL fileURLWithPath:@"/Dest.mp4"]; + + NSUndoManager *undoManager = [[NSUndoManager alloc] init]; + undoManager.groupsByEvent = NO; + + self.modifiedJob = [self.job copy]; + self.modifiedJob.undo = undoManager; + + [self.manager.root enumerateObjectsUsingBlock:^(HBPreset * _Nonnull obj, NSIndexPath * _Nonnull idx, BOOL * _Nonnull stop) + { + if (obj.isLeaf) + { + [undoManager beginUndoGrouping]; + [self.modifiedJob applyPreset:obj]; + [undoManager endUndoGrouping]; + } + }]; + + // Container changed + [undoManager beginUndoGrouping]; + self.modifiedJob.container = 0x200000; + [undoManager endUndoGrouping]; + + // Chapters changed + [undoManager beginUndoGrouping]; + self.modifiedJob.chapterTitles[0].title = @"Test chapter"; + self.modifiedJob.range.type = HBRangeTypeFrames; + [undoManager endUndoGrouping]; + + // Undo, redo and undo again the whole thing one time + while (undoManager.canUndo) + { + [undoManager undo]; + } + while (undoManager.canRedo) + { + [undoManager redo]; + } + while (undoManager.canUndo) + { + [undoManager undo]; + } +} + +- (void)tearDown { + [super tearDown]; +} + +- (void)testJob +{ + XCTAssertEqualObjects(self.job.presetName, self.modifiedJob.presetName); + XCTAssertEqual(self.job.container, self.modifiedJob.container); + + XCTAssertEqual(self.job.mp4HttpOptimize, self.modifiedJob.mp4HttpOptimize); + XCTAssertEqual(self.job.mp4iPodCompatible, self.modifiedJob.mp4iPodCompatible); + + XCTAssertEqual(self.job.angle, self.modifiedJob.angle); +} + +- (void)testAudio +{ + XCTAssertEqual([self.job.audio countOfTracks], [self.modifiedJob.audio countOfTracks]); + + for (NSUInteger idx = 0; idx < [self.job.audio countOfTracks]; idx++) + { + HBAudioTrack *t1 = self.job.audio.tracks[idx]; + HBAudioTrack *t2 = self.modifiedJob.audio.tracks[idx]; + + XCTAssertEqualObjects(t1.track, t2.track); + } +} + +- (void)testRange +{ + XCTAssertEqual(self.job.range.type, self.modifiedJob.range.type); +} + +- (void)testPicture +{ + XCTAssertEqual(self.job.picture.width, self.modifiedJob.picture.width); + XCTAssertEqual(self.job.picture.height, self.modifiedJob.picture.height); + + XCTAssertEqual(self.job.picture.displayWidth, self.modifiedJob.picture.displayWidth); + XCTAssertEqual(self.job.picture.parWidth, self.modifiedJob.picture.parWidth); + XCTAssertEqual(self.job.picture.parHeight, self.modifiedJob.picture.parHeight); + + XCTAssertEqual(self.job.picture.autocrop, self.modifiedJob.picture.autocrop); + + XCTAssertEqual(self.job.picture.cropTop, self.modifiedJob.picture.cropTop); + XCTAssertEqual(self.job.picture.cropBottom, self.modifiedJob.picture.cropBottom); + XCTAssertEqual(self.job.picture.cropLeft, self.modifiedJob.picture.cropLeft); + XCTAssertEqual(self.job.picture.cropRight, self.modifiedJob.picture.cropRight); +} + +- (void)testFilters +{ + XCTAssertEqualObjects(self.job.filters.deinterlace, self.modifiedJob.filters.deinterlace); + XCTAssertEqualObjects(self.job.filters.deinterlacePreset, self.modifiedJob.filters.deinterlacePreset); + XCTAssertEqualObjects(self.job.filters.deinterlaceCustomString, self.modifiedJob.filters.deinterlaceCustomString); + + XCTAssertEqualObjects(self.job.filters.detelecine, self.modifiedJob.filters.detelecine); + XCTAssertEqualObjects(self.job.filters.detelecineCustomString, self.modifiedJob.filters.detelecineCustomString); + + XCTAssertEqualObjects(self.job.filters.denoise, self.modifiedJob.filters.denoise); + XCTAssertEqualObjects(self.job.filters.denoisePreset, self.modifiedJob.filters.denoisePreset); + XCTAssertEqualObjects(self.job.filters.denoiseTune, self.modifiedJob.filters.denoiseTune); + XCTAssertEqualObjects(self.job.filters.denoiseCustomString, self.modifiedJob.filters.denoiseCustomString); + + XCTAssertEqual(self.job.filters.deblock, self.modifiedJob.filters.deblock); + XCTAssertEqual(self.job.filters.grayscale, self.modifiedJob.filters.grayscale); +} + +- (void)testSubtitles +{ + XCTAssertEqual([self.job.subtitles countOfTracks], [self.modifiedJob.subtitles countOfTracks]); + + for (NSUInteger idx = 0; idx < [self.job.subtitles countOfTracks]; idx++) + { + HBSubtitlesTrack *t1 = self.job.subtitles.tracks[idx]; + HBSubtitlesTrack *t2 = self.modifiedJob.subtitles.tracks[idx]; + + XCTAssertEqual(t1.sourceTrackIdx, t2.sourceTrackIdx); + XCTAssertEqual(t1.type, t2.type); + XCTAssertEqual(t1.burnedIn, t2.burnedIn); + XCTAssertEqual(t1.forcedOnly, t2.forcedOnly); + XCTAssertEqual(t1.def, t2.def); + } +} + +- (void)testChapters +{ + XCTAssertEqual(self.job.chaptersEnabled, self.modifiedJob.chaptersEnabled); + + for (NSUInteger idx = 0; idx < [self.job.subtitles countOfTracks]; idx++) + { + XCTAssertEqualObjects(self.job.chapterTitles[idx].title, self.modifiedJob.chapterTitles[idx].title); + } +} + +@end diff --git a/macosx/HandBrake Tests/HBMockTitle.m b/macosx/HandBrake Tests/HBMockTitle.m index 78ce4c05c..9cfd374a3 100644 --- a/macosx/HandBrake Tests/HBMockTitle.m +++ b/macosx/HandBrake Tests/HBMockTitle.m @@ -7,6 +7,7 @@ // #import "HBMockTitle.h" +#import "HBChapter.h" extern NSString *keyAudioTrackIndex; extern NSString *keyAudioTrackName; @@ -162,9 +163,18 @@ extern NSString *keySubTrackType; return nil; } -- (NSArray *)chapters +- (NSArray<HBChapter *> *)chapters { - return @[@"Chapter 1", @"Chapter 2"]; + NSMutableArray *chapters = [NSMutableArray array]; + + for (int i = 0; i < 10; i++) + { + NSString *title = [NSString stringWithFormat:@"Chapter %d", i + 1]; + [chapters addObject:[[HBChapter alloc] initWithTitle:title + index:i + 1 + duration:100]]; + } + return [chapters copy]; } diff --git a/macosx/HandBrake.xcodeproj/project.pbxproj b/macosx/HandBrake.xcodeproj/project.pbxproj index 5a037cd34..21848373b 100644 --- a/macosx/HandBrake.xcodeproj/project.pbxproj +++ b/macosx/HandBrake.xcodeproj/project.pbxproj @@ -113,6 +113,7 @@ 6F0D69A91AD0683100A39DCA /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 273F204014ADBC210021BE6D /* Foundation.framework */; }; A90A0CAF1988D57200DA65CE /* HBAudioTrackPreset.m in Sources */ = {isa = PBXBuildFile; fileRef = A90A0CAE1988D57200DA65CE /* HBAudioTrackPreset.m */; }; A91017B41A64440A00039BFB /* HBSubtitles.m in Sources */ = {isa = PBXBuildFile; fileRef = A91017B31A64440A00039BFB /* HBSubtitles.m */; }; + A91404611BDBB7DE00BE29A7 /* HBJobUndoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = A91404601BDBB7DE00BE29A7 /* HBJobUndoTests.m */; }; A914BCB31BC441C700157917 /* HBPreviewView.m in Sources */ = {isa = PBXBuildFile; fileRef = A914BCB21BC441C700157917 /* HBPreviewView.m */; }; A914BCB61BC441D100157917 /* QTKit+HBQTMovieExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = A914BCB51BC441D100157917 /* QTKit+HBQTMovieExtensions.m */; }; A9160A351AE7A165009A7818 /* HBCodingUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = A9160A341AE7A165009A7818 /* HBCodingUtilities.m */; }; @@ -391,6 +392,7 @@ A90A0CAE1988D57200DA65CE /* HBAudioTrackPreset.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBAudioTrackPreset.m; sourceTree = "<group>"; }; A91017B21A64440A00039BFB /* HBSubtitles.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HBSubtitles.h; sourceTree = "<group>"; }; A91017B31A64440A00039BFB /* HBSubtitles.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBSubtitles.m; sourceTree = "<group>"; }; + A91404601BDBB7DE00BE29A7 /* HBJobUndoTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBJobUndoTests.m; sourceTree = "<group>"; }; A914BCB11BC441C700157917 /* HBPreviewView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HBPreviewView.h; sourceTree = "<group>"; }; A914BCB21BC441C700157917 /* HBPreviewView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBPreviewView.m; sourceTree = "<group>"; }; A914BCB41BC441D100157917 /* QTKit+HBQTMovieExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "QTKit+HBQTMovieExtensions.h"; sourceTree = "<group>"; }; @@ -1081,6 +1083,7 @@ children = ( A98FD5911B19C63800FCC7A5 /* HBMockTitle.h */, A98FD5921B19C63800FCC7A5 /* HBMockTitle.m */, + A91404601BDBB7DE00BE29A7 /* HBJobUndoTests.m */, A9A24B2E1B09F87400AD1FAB /* HBJobTests.m */, A9A24B2C1B09F6FD00AD1FAB /* HBPresetsTests.m */, A95B8D951B09F16700F2F152 /* Supporting Files */, @@ -1526,6 +1529,7 @@ buildActionMask = 2147483647; files = ( A98FD5931B19C63800FCC7A5 /* HBMockTitle.m in Sources */, + A91404611BDBB7DE00BE29A7 /* HBJobUndoTests.m in Sources */, A9A24B2D1B09F6FD00AD1FAB /* HBPresetsTests.m in Sources */, A9A24B2F1B09F87400AD1FAB /* HBJobTests.m in Sources */, ); |