From ed40e7a024e54f4b9ccd04f3c57a73701272b66c Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Sun, 1 Jan 2017 11:57:30 +0100 Subject: MacGui: fix the tests, an external file is required to run them now. --- macosx/HandBrakeKitTests/HBJobTests.m | 47 +++++++-- macosx/HandBrakeKitTests/HBJobUndoTests.m | 25 ++++- macosx/HandBrakeKitTests/HBMockTitle.h | 12 --- macosx/HandBrakeKitTests/HBMockTitle.m | 167 ------------------------------ 4 files changed, 58 insertions(+), 193 deletions(-) delete mode 100644 macosx/HandBrakeKitTests/HBMockTitle.h delete mode 100644 macosx/HandBrakeKitTests/HBMockTitle.m (limited to 'macosx/HandBrakeKitTests') diff --git a/macosx/HandBrakeKitTests/HBJobTests.m b/macosx/HandBrakeKitTests/HBJobTests.m index 55726deea..dba18e35d 100644 --- a/macosx/HandBrakeKitTests/HBJobTests.m +++ b/macosx/HandBrakeKitTests/HBJobTests.m @@ -7,7 +7,8 @@ #import #import -#import "HBMockTitle.h" +#import "HBCore.h" +#import "HBTitle.h" #import "HBJob.h" #import "HBPicture.h" #import "HBJob+UIAdditions.h" @@ -18,8 +19,11 @@ @interface HBJobTests : XCTestCase @property (nonatomic, readonly) HBPresetsManager *manager; - @property (nonatomic, readwrite) HBPreset *preset; + +@property (nonatomic, readwrite) dispatch_queue_t queue; +@property (nonatomic, readwrite) HBCore *core; + @property (nonatomic, readwrite) HBTitle *title; @property (nonatomic, readwrite) HBJob *job; @@ -36,7 +40,21 @@ self.preset = self.manager.defaultPreset; - self.title = [[HBMockTitle alloc] init]; + NSURL *sampleURL = [NSURL fileURLWithPath:@"test.mp4"]; + + self.queue = dispatch_queue_create("fr.handbrake.testQueue", DISPATCH_QUEUE_SERIAL); + dispatch_semaphore_t sem = dispatch_semaphore_create(0); + + self.core = [[HBCore alloc] initWithLogLevel:1 queue:self.queue]; + [self.core scanURL:sampleURL titleIndex:0 previews:1 minDuration:0 progressHandler:^(HBState state, HBProgress progress, NSString * _Nonnull info) { + + } completionHandler:^(HBCoreResult result) { + dispatch_semaphore_signal(sem); + }]; + + dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER); + + self.title = self.core.titles.firstObject; self.job = [[HBJob alloc] initWithTitle:self.title andPreset:self.preset]; self.job.destURL = [NSURL fileURLWithPath:@"/Dest.mp4"]; @@ -51,29 +69,32 @@ { HBJob *job = [[HBJob alloc] init]; - XCTAssert(job, @"Pass"); + XCTAssertNotNil(job, @"Pass"); } - (void)testApplyPreset { - HBMockTitle *title = [[HBMockTitle alloc] init]; HBPreset *preset = self.manager.defaultPreset; - HBJob *job = [[HBJob alloc] initWithTitle:title andPreset:preset]; - job.destURL = [NSURL fileURLWithPath:@"/Dest.mp4"]; + XCTAssertNotNil(self.title); + + HBJob *job = [[HBJob alloc] initWithTitle:self.title andPreset:preset]; + XCTAssertNotNil(self.job); + + job.destURL = [NSURL fileURLWithPath:@"/Dest.mp4"]; [job applyPreset:preset]; } - (void)testAudio { - XCTAssertGreaterThan(self.job.audio.tracks.count, 1); + XCTAssertEqual(self.job.audio.tracks.count, 1); } - (void)testPictureSize { - XCTAssertEqual(self.job.picture.width, 1254); - XCTAssertEqual(self.job.picture.height, 678); + XCTAssertEqual(self.job.picture.width, 1280); + XCTAssertEqual(self.job.picture.height, 720); } - (void)testAutoCrop @@ -83,6 +104,9 @@ - (void)testAutoCropValues { + XCTAssertNotNil(self.title); + XCTAssertNotNil(self.job); + XCTAssertEqual(self.title.autoCropTop, self.job.picture.cropTop); XCTAssertEqual(self.title.autoCropBottom, self.job.picture.cropBottom); XCTAssertEqual(self.title.autoCropLeft, self.job.picture.cropLeft); @@ -103,12 +127,13 @@ preset[@"PicturePARHeight"] = @45; HBJob *job = [self.job copy]; + job.title = self.job.title; [job applyPreset:preset]; XCTAssertEqual(job.picture.width, 720); XCTAssertEqual(job.picture.height, 576); - XCTAssertEqual(job.picture.displayWidth, 1064); + XCTAssertEqual(job.picture.displayWidth, 1024); } @end diff --git a/macosx/HandBrakeKitTests/HBJobUndoTests.m b/macosx/HandBrakeKitTests/HBJobUndoTests.m index bff23198e..afee23cae 100644 --- a/macosx/HandBrakeKitTests/HBJobUndoTests.m +++ b/macosx/HandBrakeKitTests/HBJobUndoTests.m @@ -6,7 +6,8 @@ #import -#import "HBMockTitle.h" +#import "HBCore.h" +#import "HBTitle.h" #import "HBJob.h" #import "HBChapter.h" #import "HBAudioTrack.h" @@ -18,8 +19,11 @@ @interface HBJobUndoTests : XCTestCase @property (nonatomic, readonly) HBPresetsManager *manager; - @property (nonatomic, readwrite) HBPreset *preset; + +@property (nonatomic, readwrite) dispatch_queue_t queue; +@property (nonatomic, readwrite) HBCore *core; + @property (nonatomic, readwrite) HBTitle *title; @property (nonatomic, readwrite) HBJob *job; @property (nonatomic, readwrite) HBJob *modifiedJob; @@ -37,7 +41,21 @@ self.preset = self.manager.defaultPreset; - self.title = [[HBMockTitle alloc] init]; + NSURL *sampleURL = [NSURL fileURLWithPath:@"test.mp4"]; + + self.queue = dispatch_queue_create("fr.handbrake.testQueue", DISPATCH_QUEUE_SERIAL); + dispatch_semaphore_t sem = dispatch_semaphore_create(0); + + self.core = [[HBCore alloc] initWithLogLevel:1 queue:self.queue]; + [self.core scanURL:sampleURL titleIndex:0 previews:1 minDuration:0 progressHandler:^(HBState state, HBProgress progress, NSString * _Nonnull info) { + + } completionHandler:^(HBCoreResult result) { + dispatch_semaphore_signal(sem); + }]; + + dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER); + + self.title = self.core.titles.firstObject; self.job = [[HBJob alloc] initWithTitle:self.title andPreset:self.preset]; self.job.destURL = [NSURL fileURLWithPath:@"/Dest.mp4"]; @@ -46,6 +64,7 @@ undoManager.groupsByEvent = NO; self.modifiedJob = [self.job copy]; + self.modifiedJob.title = self.job.title; self.modifiedJob.undo = undoManager; [self.manager.root enumerateObjectsUsingBlock:^(HBPreset * _Nonnull obj, NSIndexPath * _Nonnull idx, BOOL * _Nonnull stop) diff --git a/macosx/HandBrakeKitTests/HBMockTitle.h b/macosx/HandBrakeKitTests/HBMockTitle.h deleted file mode 100644 index e83a13ad2..000000000 --- a/macosx/HandBrakeKitTests/HBMockTitle.h +++ /dev/null @@ -1,12 +0,0 @@ -/* HBMockTitle - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#import -#import "HBTitle.h" - -@interface HBMockTitle : HBTitle - -@end diff --git a/macosx/HandBrakeKitTests/HBMockTitle.m b/macosx/HandBrakeKitTests/HBMockTitle.m deleted file mode 100644 index 217f56bfc..000000000 --- a/macosx/HandBrakeKitTests/HBMockTitle.m +++ /dev/null @@ -1,167 +0,0 @@ -/* HBMockTitle - - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -#import "HBMockTitle.h" -#import "HBChapter.h" - -extern NSString *keyAudioTrackIndex; -extern NSString *keyAudioTrackName; -extern NSString *keyAudioInputBitrate; -extern NSString *keyAudioInputSampleRate; -extern NSString *keyAudioInputCodec; -extern NSString *keyAudioInputCodecParam; -extern NSString *keyAudioInputChannelLayout; -extern NSString *keyAudioTrackLanguageIsoCode; - -extern NSString *keySubTrackName; -extern NSString *keySubTrackLanguageIsoCode; -extern NSString *keySubTrackType; - -@implementation HBMockTitle - -- (instancetype)init -{ - self = [super init]; - return self; -} - -- (NSString *)name -{ - return @"Test.mkv"; -} - -- (BOOL)isStream -{ - return YES; -} - -- (NSString *)description -{ - return @"Test Title"; -} - -- (NSURL *)url -{ - return [NSURL fileURLWithPath:@"/Test.mkv"]; -} - -- (int)index -{ - return 1; -} - -- (int)angles -{ - return 1; -} - -- (int)duration -{ - return 60; -} - -- (int)frames -{ - return 60 * 25; -} - -- (NSString *)timeCode -{ - return @"00:01:00"; -} - -- (int)width -{ - return 1280; -} - -- (int)height -{ - return 720; -} - -- (int)parWidth -{ - return 1; -} - -- (int)parHeight -{ - return 1; -} - -- (int)autoCropTop -{ - return 20; -} - -- (int)autoCropBottom -{ - return 22; -} - -- (int)autoCropLeft -{ - return 12; -} - -- (int)autoCropRight -{ - return 15; -} - -- (NSArray *)audioTracks -{ - NSMutableArray *tracks = [NSMutableArray array]; - [tracks addObject: @{keyAudioTrackIndex: @1, - keyAudioTrackName: [NSString stringWithFormat: @"%d: %s", 0, "English"], - keyAudioInputBitrate: @104, - keyAudioInputSampleRate: @48000, - keyAudioInputCodec: @65536, - keyAudioInputCodecParam: @86018, - keyAudioInputChannelLayout: @3, - keyAudioTrackLanguageIsoCode: @"eng"}]; - - [tracks addObject: @{keyAudioTrackIndex: @2, - keyAudioTrackName: [NSString stringWithFormat: @"%d: %s", 1, "Italian"], - keyAudioInputBitrate: @104, - keyAudioInputSampleRate: @48000, - keyAudioInputCodec: @65536, - keyAudioInputCodecParam: @86018, - keyAudioInputChannelLayout: @3, - keyAudioTrackLanguageIsoCode: @"ita"}]; - return [tracks copy]; -} - -- (NSArray *)subtitlesTracks -{ - NSMutableArray *tracks = [NSMutableArray array]; - NSString *nativeLanguage = @"English"; - - // create a dictionary of source subtitle information to store in our array - [tracks addObject:@{keySubTrackName: [NSString stringWithFormat:@"%d: %@ (%@) (%@)", 0, nativeLanguage, @"Bitmap", @"VobSub"], - keySubTrackType: @0, - keySubTrackLanguageIsoCode: @"eng"}]; - - return [tracks copy]; -} - -- (NSArray *)chapters -{ - 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]; -} - - -@end -- cgit v1.2.3