summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorritsuka <[email protected]>2015-06-01 17:20:43 +0000
committerritsuka <[email protected]>2015-06-01 17:20:43 +0000
commit876f1f8cafd3510cb04f022f004610e39d50dbc8 (patch)
tree8fb00efa2f170d03eb96b7859a9a6605f4d8b6f9
parentc0cb605ff2e3fff65db994506df8f6f7253b5ad8 (diff)
MacGui: split HBTitle header to make it easier to test. Added some simple tests.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7256 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r--macosx/HBCore.m2
-rw-r--r--macosx/HBJob+HBJobConversion.m3
-rw-r--r--macosx/HBJob.h2
-rw-r--r--macosx/HBRange.m2
-rw-r--r--macosx/HBSubtitles.m2
-rw-r--r--macosx/HBTitle.h12
-rw-r--r--macosx/HBTitle.m8
-rw-r--r--macosx/HBTitlePrivate.h29
-rw-r--r--macosx/HandBrake Tests/HBJobTests.m59
-rw-r--r--macosx/HandBrake Tests/HBMockTitle.h14
-rw-r--r--macosx/HandBrake Tests/HBMockTitle.m182
-rw-r--r--macosx/HandBrake Tests/HBPresetsTests.m14
-rw-r--r--macosx/HandBrake.xcodeproj/project.pbxproj8
13 files changed, 310 insertions, 27 deletions
diff --git a/macosx/HBCore.m b/macosx/HBCore.m
index 0f7b6cb8f..13344f8b7 100644
--- a/macosx/HBCore.m
+++ b/macosx/HBCore.m
@@ -10,7 +10,7 @@
#import "HBDVDDetector.h"
#import "HBUtilities.h"
-#import "HBTitle.h"
+#import "HBTitlePrivate.h"
#include <dlfcn.h>
diff --git a/macosx/HBJob+HBJobConversion.m b/macosx/HBJob+HBJobConversion.m
index 70692d801..6d69f0661 100644
--- a/macosx/HBJob+HBJobConversion.m
+++ b/macosx/HBJob+HBJobConversion.m
@@ -9,7 +9,7 @@
#import "HBAudioDefaults.h"
#import "HBAudioTrack.h"
-#import "HBTitle.h"
+#import "HBTitlePrivate.h"
@implementation HBJob (HBJobConversion)
@@ -19,6 +19,7 @@
- (hb_job_t *)hb_job
{
NSAssert(self.title, @"HBJob: calling hb_job without a valid title loaded");
+ NSAssert(self.destURL, @"HBJob: calling hb_job without a valid destination");
hb_title_t *title = self.title.hb_title;
hb_job_t *job = hb_job_init(title);
diff --git a/macosx/HBJob.h b/macosx/HBJob.h
index d9aca7953..5808320cd 100644
--- a/macosx/HBJob.h
+++ b/macosx/HBJob.h
@@ -56,7 +56,7 @@ typedef NS_ENUM(NSUInteger, HBJobState){
@property (nonatomic, readonly) NSURL *fileURL;
/// The file URL at which the new file will be created.
-@property (nonatomic, readwrite, copy) NSURL *destURL;
+@property (nonatomic, readwrite, copy, nullable) NSURL *destURL;
// Job settings
@property (nonatomic, readwrite) int container;
diff --git a/macosx/HBRange.m b/macosx/HBRange.m
index ae09edbe7..2f3c8d0dc 100644
--- a/macosx/HBRange.m
+++ b/macosx/HBRange.m
@@ -5,7 +5,7 @@
It may be used under the terms of the GNU General Public License. */
#import "HBRange.h"
-#import "HBTitle.h"
+#import "HBTitlePrivate.h"
#import "HBCodingUtilities.h"
NSString *HBRangeChangedNotification = @"HBRangeChangedNotification";
diff --git a/macosx/HBSubtitles.m b/macosx/HBSubtitles.m
index e03292620..b21a956a6 100644
--- a/macosx/HBSubtitles.m
+++ b/macosx/HBSubtitles.m
@@ -11,7 +11,9 @@
#import "HBTitle.h"
#import "HBCodingUtilities.h"
+
#include "lang.h"
+#include "common.h"
NSString *keySubTrackSelectionIndex = @"keySubTrackSelectionIndex";
NSString *keySubTrackName = @"keySubTrackName";
diff --git a/macosx/HBTitle.h b/macosx/HBTitle.h
index 137ea1b09..1c0ddc963 100644
--- a/macosx/HBTitle.h
+++ b/macosx/HBTitle.h
@@ -5,7 +5,6 @@
It may be used under the terms of the GNU General Public License. */
#import <Foundation/Foundation.h>
-#include "hb.h"
NS_ASSUME_NONNULL_BEGIN
@@ -15,23 +14,12 @@ NS_ASSUME_NONNULL_BEGIN
*/
@interface HBTitle : NSObject
-/**
- * Returns an HBTitle object initialized with a given title.
- * It must be called only inside HBCore.
- *
- * @param title the libhb title to wrap.
- * @param featured whether the title is the featured one or not.
- */
-- (instancetype)initWithTitle:(hb_title_t *)title featured:(BOOL)featured NS_DESIGNATED_INITIALIZER;
-
@property (nonatomic, readonly) NSString *name;
@property (nonatomic, readonly, getter=isFeatured) BOOL featured;
@property (nonatomic, readonly, getter=isStream) BOOL stream;
@property (nonatomic, readonly) NSURL *url;
-@property (nonatomic, readonly) hb_title_t *hb_title;
-
@property (nonatomic, readonly) int index;
@property (nonatomic, readonly) int angles;
@property (nonatomic, readonly) int duration;
diff --git a/macosx/HBTitle.m b/macosx/HBTitle.m
index 42453d34a..ad926e0cd 100644
--- a/macosx/HBTitle.m
+++ b/macosx/HBTitle.m
@@ -5,6 +5,7 @@
It may be used under the terms of the GNU General Public License. */
#import "HBTitle.h"
+#import "HBTitlePrivate.h"
#include "lang.h"
@@ -33,6 +34,7 @@ extern NSString *keySubTrackSrtCharCode;
@interface HBTitle ()
+@property (nonatomic, readonly) hb_title_t *hb_title;
@property (nonatomic, readwrite, strong) NSString *name;
@property (nonatomic, readwrite) NSArray *audioTracks;
@@ -43,6 +45,12 @@ extern NSString *keySubTrackSrtCharCode;
@implementation HBTitle
+/*- (instancetype)init
+{
+ NSAssert(false, @"[HBTitle init] should not be called");
+ return nil;
+}*/
+
- (instancetype)initWithTitle:(hb_title_t *)title featured:(BOOL)featured
{
self = [super init];
diff --git a/macosx/HBTitlePrivate.h b/macosx/HBTitlePrivate.h
new file mode 100644
index 000000000..01e9532eb
--- /dev/null
+++ b/macosx/HBTitlePrivate.h
@@ -0,0 +1,29 @@
+//
+// HBTitlePrivate.h
+// HandBrake
+//
+// Created by Damiano Galassi on 30/05/15.
+//
+//
+
+#import <Foundation/Foundation.h>
+#import "HBTitle.h"
+#include "hb.h"
+
+@interface HBTitle (Private)
+
+/**
+ * Returns an HBTitle object initialized with a given title.
+ * It must be called only inside HBCore.
+ *
+ * @param title the libhb title to wrap.
+ * @param featured whether the title is the featured one or not.
+ */
+- (instancetype)initWithTitle:(hb_title_t *)title featured:(BOOL)featured;
+
+/**
+ * The internal libhb structure.
+ */
+@property (nonatomic, readonly) hb_title_t *hb_title;
+
+@end \ No newline at end of file
diff --git a/macosx/HandBrake Tests/HBJobTests.m b/macosx/HandBrake Tests/HBJobTests.m
index e12f3ef10..c63fce273 100644
--- a/macosx/HandBrake Tests/HBJobTests.m
+++ b/macosx/HandBrake Tests/HBJobTests.m
@@ -7,7 +7,10 @@
#import <Cocoa/Cocoa.h>
#import <XCTest/XCTest.h>
+#import "HBMockTitle.h"
#import "HBJob.h"
+#import "HBPicture.h"
+#import "HBJob+UIAdditions.h"
#import "HBPresetsManager.h"
#import "HBPreset.h"
@@ -15,28 +18,74 @@
@property (nonatomic, readonly) HBPresetsManager *manager;
+@property (nonatomic, readwrite) HBPreset *preset;
+@property (nonatomic, readwrite) HBTitle *title;
+@property (nonatomic, readwrite) HBJob *job;
+
@end
@implementation HBJobTests
-- (void)setUp {
+- (void)setUp
+{
[super setUp];
_manager = [[HBPresetsManager alloc] init];
[_manager generateBuiltInPresets];
- // Put setup code here. This method is called before the invocation of each test method in the class.
+ 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"];
}
-- (void)tearDown {
- // Put teardown code here. This method is called after the invocation of each test method in the class.
+- (void)tearDown
+{
[super tearDown];
}
-- (void)testJobCreation {
+- (void)testJobCreation
+{
HBJob *job = [[HBJob alloc] init];
XCTAssert(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"];
+
+ [job applyPreset:preset];
+}
+
+- (void)testAudio
+{
+ XCTAssertEqual(self.job.audio.tracks.count, 2);
+}
+
+- (void)testPictureSize
+{
+ XCTAssertEqual(self.job.picture.width, 1254);
+ XCTAssertEqual(self.job.picture.height, 678);
+}
+
+- (void)testAutoCrop
+{
+ XCTAssertEqual([self.preset.content[@"PictureAutoCrop"] boolValue], self.job.picture.autocrop);
+}
+
+- (void)testAutoCropValues
+{
+ 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);
+}
+
@end
diff --git a/macosx/HandBrake Tests/HBMockTitle.h b/macosx/HandBrake Tests/HBMockTitle.h
new file mode 100644
index 000000000..ee1f87a62
--- /dev/null
+++ b/macosx/HandBrake Tests/HBMockTitle.h
@@ -0,0 +1,14 @@
+//
+// HBMockTitle.h
+// HandBrake
+//
+// Created by Damiano Galassi on 30/05/15.
+//
+//
+
+#import <Foundation/Foundation.h>
+#import "HBTitle.h"
+
+@interface HBMockTitle : HBTitle
+
+@end
diff --git a/macosx/HandBrake Tests/HBMockTitle.m b/macosx/HandBrake Tests/HBMockTitle.m
new file mode 100644
index 000000000..0e61bd414
--- /dev/null
+++ b/macosx/HandBrake Tests/HBMockTitle.m
@@ -0,0 +1,182 @@
+//
+// HBMockTitle.m
+// HandBrake
+//
+// Created by Damiano Galassi on 30/05/15.
+//
+//
+
+#import "HBMockTitle.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 *keySubTrackIndex;
+extern NSString *keySubTrackLanguage;
+extern NSString *keySubTrackLanguageIsoCode;
+extern NSString *keySubTrackType;
+
+extern NSString *keySubTrackForced;
+extern NSString *keySubTrackBurned;
+extern NSString *keySubTrackDefault;
+
+extern NSString *keySubTrackSrtOffset;
+extern NSString *keySubTrackSrtFilePath;
+extern NSString *keySubTrackSrtCharCode;
+
+@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", 1, "English"],
+ keyAudioInputBitrate: @104,
+ keyAudioInputSampleRate: @48000,
+ keyAudioInputCodec: @65536,
+ keyAudioInputCodecParam: @86018,
+ keyAudioInputChannelLayout: @3,
+ keyAudioTrackLanguageIsoCode: @"eng"}];
+ return [tracks copy];
+}
+
+- (NSArray *)subtitlesTracks
+{
+ /*if (!_subtitlesTracks)
+ {
+ NSMutableArray *tracks = [NSMutableArray array];
+ hb_subtitle_t *subtitle;
+ hb_list_t *list = self.hb_title->list_subtitle;
+ int count = hb_list_count(list);
+
+ for (int i = 0; i < count; i++)
+ {
+ subtitle = (hb_subtitle_t *) hb_list_item(self.hb_title->list_subtitle, i);
+
+ // Human-readable representation of subtitle->source
+ NSString *bitmapOrText = subtitle->format == PICTURESUB ? @"Bitmap" : @"Text";
+ NSString *subSourceName = @(hb_subsource_name(subtitle->source));
+
+ // Use the native language name if available
+ iso639_lang_t *language = lang_for_code2(subtitle->iso639_2);
+ NSString *nativeLanguage = strlen(language->native_name) ? @(language->native_name) : @(language->eng_name);
+
+ // create a dictionary of source subtitle information to store in our array
+ [tracks addObject:@{keySubTrackName: [NSString stringWithFormat:@"%d: %@ (%@) (%@)", i, nativeLanguage, bitmapOrText, subSourceName],
+ keySubTrackIndex: @(i),
+ keySubTrackType: @(subtitle->source),
+ keySubTrackLanguage: nativeLanguage,
+ keySubTrackLanguageIsoCode: @(subtitle->iso639_2)}];
+ }
+
+ _subtitlesTracks = [tracks copy];
+ }*/
+
+ return nil;
+}
+
+- (NSArray *)chapters
+{
+ return @[@"Chapter 1", @"Chapter 2"];
+}
+
+
+@end
diff --git a/macosx/HandBrake Tests/HBPresetsTests.m b/macosx/HandBrake Tests/HBPresetsTests.m
index aff566911..231f151a4 100644
--- a/macosx/HandBrake Tests/HBPresetsTests.m
+++ b/macosx/HandBrake Tests/HBPresetsTests.m
@@ -18,28 +18,30 @@
- (void)setUp {
[super setUp];
- // Put setup code here. This method is called before the invocation of each test method in the class.
}
-- (void)tearDown {
- // Put teardown code here. This method is called after the invocation of each test method in the class.
+- (void)tearDown
+{
[super tearDown];
}
-- (void)testManagerCreation {
+- (void)testManagerCreation
+{
HBPresetsManager *manager = [[HBPresetsManager alloc] init];
XCTAssert(manager, @"Pass");
}
-- (void)testDefaultPresets {
+- (void)testDefaultPresets
+{
HBPresetsManager *manager = [[HBPresetsManager alloc] init];
[manager generateBuiltInPresets];
XCTAssert(manager.root.children.count > 1, @"Pass");
}
-- (void)testCreationTime {
+- (void)testCreationTime
+{
HBPresetsManager *manager = [[HBPresetsManager alloc] init];
[self measureBlock:^{
diff --git a/macosx/HandBrake.xcodeproj/project.pbxproj b/macosx/HandBrake.xcodeproj/project.pbxproj
index 3026246f5..639c71828 100644
--- a/macosx/HandBrake.xcodeproj/project.pbxproj
+++ b/macosx/HandBrake.xcodeproj/project.pbxproj
@@ -158,6 +158,7 @@
A971281F1A2C75180088C076 /* HBTitle.m in Sources */ = {isa = PBXBuildFile; fileRef = A971281E1A2C75180088C076 /* HBTitle.m */; };
A975C08E1AE8C5270061870D /* HBStateFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = A975C08D1AE8C5270061870D /* HBStateFormatter.m */; };
A98C29C41977B10600AF5DED /* HBLanguagesSelection.m in Sources */ = {isa = PBXBuildFile; fileRef = A98C29C31977B10600AF5DED /* HBLanguagesSelection.m */; };
+ A98FD5931B19C63800FCC7A5 /* HBMockTitle.m in Sources */ = {isa = PBXBuildFile; fileRef = A98FD5921B19C63800FCC7A5 /* HBMockTitle.m */; };
A9906B2C1A710920001D82D5 /* HBQueueController.m in Sources */ = {isa = PBXBuildFile; fileRef = A9906B2B1A710920001D82D5 /* HBQueueController.m */; };
A990D9071A64562200139032 /* HBJob+HBJobConversion.m in Sources */ = {isa = PBXBuildFile; fileRef = A990D9061A64562200139032 /* HBJob+HBJobConversion.m */; };
A9935213196F38A70069C6B7 /* ChaptersTitles.xib in Resources */ = {isa = PBXBuildFile; fileRef = A9935211196F38A70069C6B7 /* ChaptersTitles.xib */; };
@@ -447,6 +448,9 @@
A975C08D1AE8C5270061870D /* HBStateFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBStateFormatter.m; sourceTree = "<group>"; };
A98C29C21977B10600AF5DED /* HBLanguagesSelection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HBLanguagesSelection.h; sourceTree = "<group>"; };
A98C29C31977B10600AF5DED /* HBLanguagesSelection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBLanguagesSelection.m; sourceTree = "<group>"; };
+ A98FD5911B19C63800FCC7A5 /* HBMockTitle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HBMockTitle.h; sourceTree = "<group>"; };
+ A98FD5921B19C63800FCC7A5 /* HBMockTitle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBMockTitle.m; sourceTree = "<group>"; };
+ A98FD5941B19C6E400FCC7A5 /* HBTitlePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HBTitlePrivate.h; sourceTree = "<group>"; };
A9906B2B1A710920001D82D5 /* HBQueueController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBQueueController.m; sourceTree = "<group>"; };
A990D9051A64562200139032 /* HBJob+HBJobConversion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "HBJob+HBJobConversion.h"; sourceTree = "<group>"; };
A990D9061A64562200139032 /* HBJob+HBJobConversion.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "HBJob+HBJobConversion.m"; sourceTree = "<group>"; };
@@ -975,6 +979,8 @@
A95B8D941B09F16700F2F152 /* HandBrake Tests */ = {
isa = PBXGroup;
children = (
+ A98FD5911B19C63800FCC7A5 /* HBMockTitle.h */,
+ A98FD5921B19C63800FCC7A5 /* HBMockTitle.m */,
A9A24B2E1B09F87400AD1FAB /* HBJobTests.m */,
A9A24B2C1B09F6FD00AD1FAB /* HBPresetsTests.m */,
A95B8D951B09F16700F2F152 /* Supporting Files */,
@@ -997,6 +1003,7 @@
A9DEC8731A23C87500C79B48 /* HBCore.m */,
A971281D1A2C75180088C076 /* HBTitle.h */,
A971281E1A2C75180088C076 /* HBTitle.m */,
+ A98FD5941B19C6E400FCC7A5 /* HBTitlePrivate.h */,
A9DEC87D1A23DF6F00C79B48 /* HBJob.h */,
A9DEC87E1A23DF6F00C79B48 /* HBJob.m */,
A990D9051A64562200139032 /* HBJob+HBJobConversion.h */,
@@ -1423,6 +1430,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ A98FD5931B19C63800FCC7A5 /* HBMockTitle.m in Sources */,
A9A24B2D1B09F6FD00AD1FAB /* HBPresetsTests.m in Sources */,
A9A24B2F1B09F87400AD1FAB /* HBJobTests.m in Sources */,
);