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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
/* 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 "HBCore.h"
#import "HBTitle.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) dispatch_queue_t queue;
@property (nonatomic, readwrite) HBCore *core;
@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;
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";
NSUndoManager *undoManager = [[NSUndoManager alloc] init];
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)
{
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];
XCTAssertEqual(t1.sourceTrackIdx, t2.sourceTrackIdx);
}
}
- (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);
XCTAssertEqualObjects(self.job.filters.sharpen, self.modifiedJob.filters.sharpen);
XCTAssertEqualObjects(self.job.filters.sharpenPreset, self.modifiedJob.filters.sharpenPreset);
XCTAssertEqualObjects(self.job.filters.sharpenTune, self.modifiedJob.filters.sharpenTune);
XCTAssertEqualObjects(self.job.filters.sharpenCustomString, self.modifiedJob.filters.sharpenCustomString);
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
|