summaryrefslogtreecommitdiffstats
path: root/macosx/HandBrakeKitTests/HBJobTests.m
blob: d4a91863d44aaf4c5a9fa010b87e60c3e4e966b9 (plain)
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
/*  HBJobTests.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 <Cocoa/Cocoa.h>
#import <XCTest/XCTest.h>

#import "HBCore.h"
#import "HBTitle.h"
#import "HBJob.h"
#import "HBPicture.h"
#import "HBJob+UIAdditions.h"
#import "HBPresetsManager.h"
#import "HBPreset.h"
#import "HBMutablePreset.h"

@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;

@end

@implementation HBJobTests

- (void)setUp
{
    [super setUp];

    _manager = [[HBPresetsManager alloc] init];
    [_manager generateBuiltInPresets];

    self.preset = self.manager.defaultPreset;

    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.outputURL = [NSURL fileURLWithPath:@"/"];
    self.job.outputFileName = @"Dest.mp4";
}

- (void)tearDown
{
    [super tearDown];
}

- (void)testJobCreation
{
    HBJob *job = [[HBJob alloc] init];

    XCTAssertNotNil(job, @"Pass");
}

- (void)testApplyPreset
{
    HBPreset *preset = self.manager.defaultPreset;

    XCTAssertNotNil(self.title);

    HBJob *job = [[HBJob alloc] initWithTitle:self.title andPreset:preset];

    XCTAssertNotNil(self.job);

    self.job.outputURL = [NSURL fileURLWithPath:@"/"];
    self.job.outputFileName = @"Dest.mp4";
    [job applyPreset:preset];
}

- (void)testAudio
{
    XCTAssertEqual(self.job.audio.tracks.count, 1);
}

- (void)testPictureSize
{
    XCTAssertEqual(self.job.picture.width, 1280);
    XCTAssertEqual(self.job.picture.height, 720);
}

- (void)testAutoCrop
{
    XCTAssertEqual([self.preset[@"PictureAutoCrop"] boolValue], self.job.picture.autocrop);
}

- (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);
    XCTAssertEqual(self.title.autoCropRight, self.job.picture.cropRight);
}

- (void)testCustomAnamorphic
{
    HBMutablePreset *preset = [self.preset mutableCopy];

    preset[@"UsesPictureSettings"] = @1;

    preset[@"PictureWidth"] = @720;
    preset[@"PictureHeight"] = @576;

    preset[@"PicturePAR"] = @"custom";
    preset[@"PicturePARWidth"] = @64;
    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, 1024);
}

@end