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
|
//
// HBDictTests.m
// HandBrake
//
// Created by Damiano Galassi on 01/03/16.
//
//
#import <XCTest/XCTest.h>
#import "NSDictionary+HBAdditions.h"
#include "hb.h"
@interface HBDictTests : XCTestCase
@property (nonatomic, strong) NSDictionary *dict;
@end
@implementation HBDictTests
- (void)setUp
{
[super setUp];
self.dict = @{@"DoubleKey": @(20.3),
@"StringKey": @"miao",
@"BoolKey": @YES,
@"ArrayKey": @[@"First", @"Second", @20]};
}
- (void)tearDown
{
self.dict = nil;
[super tearDown];
}
- (void)testNSDictionaryToHBDict
{
hb_dict_t *hbdict = self.dict.hb_value;
double doubleValue = hb_value_get_double(hb_dict_get(hbdict, "DoubleKey"));
XCTAssertEqual(doubleValue, [self.dict[@"DoubleKey"] doubleValue]);
const char *stringValue = hb_value_get_string(hb_dict_get(hbdict, "StringKey"));
XCTAssertEqualObjects(@(stringValue), self.dict[@"StringKey"]);
BOOL boolValue = (BOOL)hb_value_get_bool(hb_dict_get(hbdict, "BoolKey"));
XCTAssertEqual(boolValue, [self.dict[@"BoolKey"] boolValue]);
hb_value_array_t *array = hb_dict_get(hbdict, "ArrayKey");
size_t count = hb_value_array_len(array);
XCTAssertEqual(count, [self.dict[@"ArrayKey"] count]);
const char *arrayString = hb_value_get_string(hb_value_array_get(array, 0));
XCTAssertEqualObjects(@(arrayString), self.dict[@"ArrayKey"][0]);
long long arrayInt = hb_value_get_int(hb_value_array_get(array, 2));
XCTAssertEqual(arrayInt, [self.dict[@"ArrayKey"][2] integerValue]);
hb_dict_free(&hbdict);
}
- (void)testNSDictionaryToHBDictToNSDictionary
{
hb_dict_t *hbdict = self.dict.hb_value;
NSDictionary *result = [[NSDictionary alloc] initWithHBDict:hbdict];
XCTAssertEqualObjects(result[@"DoubleKey"], self.dict[@"DoubleKey"]);
XCTAssertEqualObjects(result[@"StringKey"], self.dict[@"StringKey"]);
XCTAssertEqualObjects(result[@"BoolKey"], self.dict[@"BoolKey"]);
XCTAssertEqualObjects(result[@"ArrayKey"], self.dict[@"ArrayKey"]);
}
- (void)testPerformanceHBDict
{
NSDictionary *dict = self.dict;
[self measureBlock:^{
for (int i = 0; i < 10000; i++)
{
hb_dict_t *result = dict.hb_value;
hb_dict_free(&result);
}
}];
}
- (void)testPerformanceNSDictionary
{
NSDictionary *dict = self.dict;
hb_dict_t *hbdict = dict.hb_value;
[self measureBlock:^{
for (int i = 0; i < 10000; i++)
{
__unused NSDictionary *result = [[NSDictionary alloc] initWithHBDict:hbdict];
}
}];
}
@end
|