Add target for iOS render test to Bazel (#1277)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
66
render-test/ios/BUILD.bazel
Normal file
66
render-test/ios/BUILD.bazel
Normal file
@@ -0,0 +1,66 @@
|
||||
load("//bazel:flags.bzl", "CPP_FLAGS", "MAPLIBRE_FLAGS")
|
||||
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_unit_test")
|
||||
load("@build_bazel_rules_apple//apple:resources.bzl", "apple_resource_bundle")
|
||||
|
||||
apple_resource_bundle(
|
||||
name = "TestData",
|
||||
infoplists = [
|
||||
"Empty.plist",
|
||||
],
|
||||
structured_resources = [
|
||||
"//metrics:render-test-files",
|
||||
],
|
||||
)
|
||||
|
||||
objc_library(
|
||||
name = "tests",
|
||||
testonly = True,
|
||||
srcs = [
|
||||
"tests/Tests.m",
|
||||
],
|
||||
deps = [
|
||||
"render_test_ios_src",
|
||||
],
|
||||
)
|
||||
|
||||
objc_library(
|
||||
name = "render_test_ios_src",
|
||||
srcs = [
|
||||
"iosTestRunner.h",
|
||||
"iosTestRunner.mm",
|
||||
"ios_test_runner.cpp",
|
||||
],
|
||||
copts = CPP_FLAGS + MAPLIBRE_FLAGS,
|
||||
data = [
|
||||
"TestData",
|
||||
],
|
||||
includes = [
|
||||
".",
|
||||
],
|
||||
visibility = [
|
||||
"//platform/ios/test/common:__pkg__",
|
||||
],
|
||||
deps = [
|
||||
"//:mbgl-core",
|
||||
"//platform/ios/test/common:ios_test_runner_lib",
|
||||
"//render-test:render-test-lib",
|
||||
"//render-test:render-test-srcs",
|
||||
"//vendor:zip-archive",
|
||||
],
|
||||
)
|
||||
|
||||
ios_unit_test(
|
||||
name = "RenderTest",
|
||||
minimum_os_version = "12.0",
|
||||
provisioning_profile = "//platform/ios:xcode_profile",
|
||||
runner = "@build_bazel_rules_apple//apple/testing/default_runner:ios_xctestrun_ordered_runner",
|
||||
test_host = "//platform/ios/test/common:RenderTestApp",
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
],
|
||||
deps = [":tests"],
|
||||
)
|
||||
|
||||
exports_files([
|
||||
"Info.plist",
|
||||
])
|
||||
18
render-test/ios/Empty.plist
Normal file
18
render-test/ios/Empty.plist
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>org.maplibre.$(PRODUCT_NAME)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN""http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
@@ -9,15 +9,15 @@
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>RenderTestApp</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.mapbox.RenderTestApp</string>
|
||||
<string>org.maplibre.RenderTestApp</string>
|
||||
<key>CFBundleGetInfoString</key>
|
||||
<string>com.mapbox.RenderTestApp</string>
|
||||
<string>org.maplibre.RenderTestApp</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleLongVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>com.mapbox.RenderTestApp</string>
|
||||
<string>org.maplibre.RenderTestApp</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
@@ -28,10 +28,6 @@
|
||||
<string>7877</string>
|
||||
<key>CSResourcesFileMapped</key>
|
||||
<true/>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>© 2014–2020 Mapbox</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
|
||||
@@ -25,117 +25,102 @@
|
||||
-(instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.testStatus = NO;
|
||||
self.runner = new TestRunner();
|
||||
NSString *path = nil;
|
||||
NSError *error;
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
|
||||
NSArray *bundleContents = [fileManager contentsOfDirectoryAtPath: bundleRoot error: &error];
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
||||
NSString *documentsDir = [paths objectAtIndex: 0];
|
||||
|
||||
for (uint32_t i = 0; i < bundleContents.count; i++) {
|
||||
NSString *dirName = [bundleContents objectAtIndex: i];
|
||||
if ([dirName isEqualToString:@"test-data"]) {
|
||||
NSString *destinationPath = [documentsDir stringByAppendingPathComponent: dirName];
|
||||
//Using NSFileManager we can perform many file system operations.
|
||||
BOOL success = [fileManager fileExistsAtPath: destinationPath];
|
||||
if (success) {
|
||||
success = [fileManager removeItemAtPath:destinationPath error:NULL];
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!self) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
self.testStatus = NO;
|
||||
self.runner = new TestRunner();
|
||||
NSError *error;
|
||||
BOOL success;
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
NSString *xcTestBundleRoot = [[NSBundle bundleForClass:[self class]] resourcePath];
|
||||
NSString *testDataDir = [xcTestBundleRoot stringByAppendingString:@"/TestData.bundle"];
|
||||
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
||||
NSString *documentsDir = [paths objectAtIndex: 0];
|
||||
|
||||
NSString *destinationPath = [documentsDir stringByAppendingPathComponent: @"test-data"];
|
||||
NSString *path = destinationPath;
|
||||
|
||||
// delete destinationPath if it exists
|
||||
if ([fileManager fileExistsAtPath:destinationPath]) {
|
||||
success = [fileManager removeItemAtPath: destinationPath error: &error];
|
||||
if (!success) {
|
||||
NSAssert1(0, @"Failed to delete '%@'.", destinationPath);
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < bundleContents.count; i++) {
|
||||
NSString *dirName = [bundleContents objectAtIndex: i];
|
||||
if ([dirName isEqualToString:@"test-data"]) {
|
||||
NSString *destinationPath = [documentsDir stringByAppendingPathComponent: dirName];
|
||||
BOOL success = [fileManager fileExistsAtPath: destinationPath];
|
||||
if (!success) {
|
||||
NSString *copyDirPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: dirName];
|
||||
}
|
||||
|
||||
success = [fileManager copyItemAtPath: copyDirPath toPath: destinationPath error: &error];
|
||||
|
||||
if (!success){
|
||||
NSAssert1(0, @"Failed to copy file '%@'.", [error localizedDescription]);
|
||||
NSLog(@"Failed to copy %@ file, error %@", dirName, [error localizedDescription]);
|
||||
}
|
||||
else {
|
||||
path = destinationPath;
|
||||
NSLog(@"File copied %@ OK", dirName);
|
||||
}
|
||||
}
|
||||
else {
|
||||
NSLog(@"File exits %@, skip copy", dirName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
success = [fileManager copyItemAtPath: testDataDir toPath: destinationPath error: &error];
|
||||
if (!success){
|
||||
NSAssert1(0, @"Failed to copy file '%@'.", [error localizedDescription]);
|
||||
NSLog(@"Failed to copy %@ file, error %@", testDataDir, [error localizedDescription]);
|
||||
}
|
||||
else {
|
||||
path = destinationPath;
|
||||
NSLog(@"File copied %@ OK", testDataDir);
|
||||
}
|
||||
|
||||
if (path) {
|
||||
std::string basePath = std::string([path UTF8String]);
|
||||
self.testStatus = self.runner->startTest(basePath) ? YES : NO;
|
||||
self.styleResultPath = [path stringByAppendingPathComponent:@"/ios-render-test-runner-style.html"];
|
||||
self.metricResultPath = [path stringByAppendingPathComponent:@"/ios-render-test-runner-metrics.html"];
|
||||
|
||||
BOOL fileFound = [fileManager fileExistsAtPath: self.styleResultPath];
|
||||
if (fileFound == NO) {
|
||||
NSLog(@"Style test result file '%@' doese not exit ", self.styleResultPath);
|
||||
self.testStatus = NO;
|
||||
}
|
||||
if (path) {
|
||||
|
||||
std::string basePath = std::string([path UTF8String]);
|
||||
self.testStatus = self.runner->startTest(basePath) ? YES : NO;
|
||||
self.styleResultPath = [path stringByAppendingPathComponent:@"/ios-render-test-runner-style.html"];
|
||||
self.metricResultPath = [path stringByAppendingPathComponent:@"/ios-render-test-runner-metrics.html"];
|
||||
fileFound = [fileManager fileExistsAtPath: self.metricResultPath];
|
||||
if (fileFound == NO) {
|
||||
NSLog(@"Metric test result file '%@' doese not exit ", self.metricResultPath);
|
||||
self.testStatus = NO;
|
||||
}
|
||||
|
||||
BOOL fileFound = [fileManager fileExistsAtPath: self.styleResultPath];
|
||||
if (fileFound == NO) {
|
||||
NSLog(@"Style test result file '%@' doese not exit ", self.styleResultPath);
|
||||
self.testStatus = NO;
|
||||
}
|
||||
|
||||
fileFound = [fileManager fileExistsAtPath: self.metricResultPath];
|
||||
if (fileFound == NO) {
|
||||
NSLog(@"Metric test result file '%@' doese not exit ", self.metricResultPath);
|
||||
self.testStatus = NO;
|
||||
}
|
||||
|
||||
NSString *rebaselinePath = [path stringByAppendingPathComponent:@"/baselines"];
|
||||
BOOL needArchiving = NO;
|
||||
BOOL isDir = NO;
|
||||
NSArray *subpaths = [[NSArray alloc] init];
|
||||
if ([fileManager fileExistsAtPath:rebaselinePath isDirectory: &isDir] && isDir){
|
||||
subpaths = [fileManager subpathsAtPath:rebaselinePath];
|
||||
for(NSString *path in subpaths)
|
||||
NSString *rebaselinePath = [path stringByAppendingPathComponent:@"/baselines"];
|
||||
BOOL needArchiving = NO;
|
||||
BOOL isDir = NO;
|
||||
NSArray *subpaths = [[NSArray alloc] init];
|
||||
if ([fileManager fileExistsAtPath:rebaselinePath isDirectory: &isDir] && isDir){
|
||||
subpaths = [fileManager subpathsAtPath:rebaselinePath];
|
||||
for(NSString *path in subpaths)
|
||||
{
|
||||
NSString *longPath = [rebaselinePath stringByAppendingPathComponent:path];
|
||||
if([fileManager fileExistsAtPath:longPath isDirectory:&isDir] && !isDir)
|
||||
{
|
||||
NSString *longPath = [rebaselinePath stringByAppendingPathComponent:path];
|
||||
if([fileManager fileExistsAtPath:longPath isDirectory:&isDir] && !isDir)
|
||||
{
|
||||
needArchiving = YES;
|
||||
break;
|
||||
}
|
||||
needArchiving = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
NSLog(@"Metric path '%@' doese not exit ", rebaselinePath);
|
||||
}
|
||||
|
||||
if (needArchiving) {
|
||||
NSString *archivePath = [path stringByAppendingString:@"/metrics.zip"];
|
||||
BOOL success = [SSZipArchive createZipFileAtPath:archivePath
|
||||
withContentsOfDirectory:rebaselinePath
|
||||
keepParentDirectory:NO
|
||||
compressionLevel:-1
|
||||
password:nil
|
||||
AES:YES
|
||||
progressHandler:nil];
|
||||
|
||||
if (success) {
|
||||
NSLog(@"Successfully archive all of the metrics into metrics.zip");
|
||||
self.metricPath = archivePath;
|
||||
}
|
||||
else {
|
||||
NSLog(@"Metric path '%@' doese not exit ", rebaselinePath);
|
||||
}
|
||||
|
||||
if (needArchiving) {
|
||||
NSString *archivePath = [path stringByAppendingString:@"/metrics.zip"];
|
||||
BOOL success = [SSZipArchive createZipFileAtPath:archivePath
|
||||
withContentsOfDirectory:rebaselinePath
|
||||
keepParentDirectory:NO
|
||||
compressionLevel:-1
|
||||
password:nil
|
||||
AES:YES
|
||||
progressHandler:nil];
|
||||
|
||||
if (success) {
|
||||
NSLog(@"Successfully archive all of the metrics into metrics.zip");
|
||||
self.metricPath = archivePath;
|
||||
}
|
||||
else {
|
||||
NSLog(@"Failed to archive rebaselined metrics into metrics.zip");
|
||||
}
|
||||
NSLog(@"Failed to archive rebaselined metrics into metrics.zip");
|
||||
}
|
||||
}
|
||||
|
||||
delete self.runner;
|
||||
self.runner = nullptr;
|
||||
}
|
||||
|
||||
delete self.runner;
|
||||
self.runner = nullptr;
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user