-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTestResources.mm
More file actions
86 lines (69 loc) · 2.51 KB
/
TestResources.mm
File metadata and controls
86 lines (69 loc) · 2.51 KB
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
// Copyright © 2021 Brad Howes. All rights reserved.
//
#import "TestResources.hpp"
#import "SF2File/IO/File.hpp"
#include <pthread.h>
// Setup internal state that is loaded once for all tests.
//
static pthread_once_t soundFontUrls_init_ = PTHREAD_ONCE_INIT;
static NSArray<NSURL*>* soundFontUrls_ = nullptr;
static NSPredicate* onlyGood = [NSPredicate predicateWithFormat: @"not absoluteString contains %@", @"ZZZ"];
static NSPredicate* onlyBad = [NSPredicate predicateWithFormat: @"absoluteString contains %@", @"ZZZ"];
static std::vector<SF2::IO::File> files_;
void initSoundFontUrls() {
soundFontUrls_ = [TestResources getInitSoundFontUrls];
files_.reserve(soundFontUrls_.count);
for (size_t index = 0; index < soundFontUrls_.count; ++index) {
auto url = [soundFontUrls_ objectAtIndex:index];
NSLog(@"getSoundFontUrls[%lu] = %@", index, url);
auto isBad = [url.absoluteString containsString:@"ZZZ"];
if (!isBad) {
files_.emplace_back(url.path.UTF8String);
files_.back().load();
}
}
NSLog(@"soundFontUrls: %lu files: %zu", soundFontUrls_.count, files_.size());
}
@implementation TestResources : NSObject
#ifndef SWIFTPM_MODULE_BUNDLE
+ (NSArray<NSURL*>*)getInitSoundFontUrls {
pthread_once(&soundFontUrls_init_, initSoundFontUrls);
NSArray<NSBundle*>* allBundles = [NSBundle allBundles];
for (int index = 0; index < [allBundles count]; ++index) {
NSBundle* bundle = [allBundles objectAtIndex:index];
NSString* bundleIdent = bundle.bundleIdentifier;
NSLog(@"bundle: %@ - %@", bundleIdent, bundle.resourcePath);
NSArray<NSURL*>* found = [bundle URLsForResourcesWithExtension:@"sf2" subdirectory:nil];
if (found != NULL && found.count == 3) {
return found;
}
}
return NULL;
}
#else
+ (NSArray<NSURL*>*)getInitSoundFontUrls {
return [SWIFTPM_MODULE_BUNDLE URLsForResourcesWithExtension:@"sf2" subdirectory:nil];
}
#endif
+ (NSArray<NSURL*>*)getSoundFontUrls {
pthread_once(&soundFontUrls_init_, initSoundFontUrls);
return soundFontUrls_;
}
+ (NSURL*)getResourceUrl:(NSUInteger)urlIndex
{
auto urls = [TestResources getSoundFontUrls];
auto url = [[urls filteredArrayUsingPredicate:onlyGood] objectAtIndex:urlIndex];
return url;
}
+ (NSURL*)getBadResourceUrl:(NSUInteger)urlIndex
{
auto urls = [TestResources getSoundFontUrls];
auto url = [[urls filteredArrayUsingPredicate:onlyBad] objectAtIndex:urlIndex];
return url;
}
+ (SF2::IO::File&)getFile:(NSUInteger)index
{
pthread_once(&soundFontUrls_init_, initSoundFontUrls);
return files_[index];
}
@end