diff options
Diffstat (limited to 'test')
25 files changed, 556 insertions, 19 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index dcde7cd21a..a9ae0ac874 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -134,6 +134,12 @@ else() COMPILE_FLAGS -Wno-shadow ) + set_source_files_properties( + ${PROJECT_SOURCE_DIR}/test/src/mbgl/test/http_server.cpp + PROPERTIES + COMPILE_OPTIONS + $<$<STREQUAL:${CMAKE_SYSTEM_NAME},iOS>:-Wno-shorten-64-to-32> + ) target_include_directories( mbgl-test PRIVATE ${PROJECT_SOURCE_DIR}/vendor/cpp-httplib @@ -167,6 +173,18 @@ target_include_directories( include(${PROJECT_SOURCE_DIR}/vendor/googletest.cmake) +if(CMAKE_SYSTEM_NAME STREQUAL iOS) + set_target_properties(mbgl-vendor-googletest PROPERTIES XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "${IOS_DEPLOYMENT_TARGET}") + set_target_properties(mbgl-vendor-googletest PROPERTIES XCODE_ATTRIBUTE_ENABLE_BITCODE "YES") + set_target_properties(mbgl-vendor-googletest PROPERTIES XCODE_ATTRIBUTE_BITCODE_GENERATION_MODE bitcode) + set_target_properties(mbgl-vendor-googletest PROPERTIES XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH $<$<CONFIG:Debug>:YES>) + + set_target_properties(mbgl-test PROPERTIES XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "${IOS_DEPLOYMENT_TARGET}") + set_target_properties(mbgl-test PROPERTIES XCODE_ATTRIBUTE_ENABLE_BITCODE "YES") + set_target_properties(mbgl-test PROPERTIES XCODE_ATTRIBUTE_BITCODE_GENERATION_MODE bitcode) + set_target_properties(mbgl-test PROPERTIES XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH $<$<CONFIG:Debug>:YES>) +endif() + # Needed for testing private classes get_target_property(MBGL_CORE_PRIVATE_LIBRARIES mbgl-core LINK_LIBRARIES) diff --git a/test/fixtures/local_glyphs/ping_fang/expected.png b/test/fixtures/local_glyphs/ping_fang/expected.png Binary files differindex 2ec62e1bc6..8c891a5232 100644 --- a/test/fixtures/local_glyphs/ping_fang/expected.png +++ b/test/fixtures/local_glyphs/ping_fang/expected.png diff --git a/test/include/mbgl/test/util.hpp b/test/include/mbgl/test/util.hpp index 959b3e646f..a8b1d1b2c6 100644 --- a/test/include/mbgl/test/util.hpp +++ b/test/include/mbgl/test/util.hpp @@ -4,17 +4,12 @@ #include <TargetConditionals.h> #endif -#if ANDROID - #define TEST_READ_ONLY 0 -#elif TARGET_OS_IOS - #define TEST_READ_ONLY 1 - #undef TEST_HAS_SERVER - #define TEST_HAS_SERVER 0 -#else - #define TEST_READ_ONLY 0 - #ifndef TEST_HAS_SERVER - #define TEST_HAS_SERVER 1 - #endif +#define TEST_READ_ONLY 0 + +#if !ANDROID +#ifndef TEST_HAS_SERVER +#define TEST_HAS_SERVER 1 +#endif #endif #if TARGET_OS_SIMULATOR diff --git a/test/ios/Info.plist b/test/ios/Info.plist new file mode 100644 index 0000000000..c53d0d06e9 --- /dev/null +++ b/test/ios/Info.plist @@ -0,0 +1,62 @@ +<?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>CFBundleDisplayName</key> + <string>${PRODUCT_NAME}</string> + <key>CFBundleExecutable</key> + <string>UnitTestsApp</string> + <key>CFBundleIdentifier</key> + <string>com.mapbox.UnitTestsApp</string> + <key>CFBundleGetInfoString</key> + <string>com.mapbox.UnitTestsApp</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>1.0</string> + <key>CFBundleLongVersionString</key> + <string>1.0</string> + <key>CFBundleName</key> + <string>com.mapbox.UnitTestsApp</string> + <key>CFBundlePackageType</key> + <string>APPL</string> + <key>CFBundleShortVersionString</key> + <string>1.0</string> + <key>CFBundleSignature</key> + <string>MBGL</string> + <key>CFBundleVersion</key> + <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> + <string>LaunchScreen</string> + <key>UIMainStoryboardFile</key> + <string>Main</string> + <key>UIBackgroundModes</key> + <array> + <string>fetch</string> + <string>remote-notification</string> + </array> + <key>UIRequiredDeviceCapabilities</key> + <array> + <string>armv7</string> + </array> + <key>UISupportedInterfaceOrientations</key> + <array> + <string>UIInterfaceOrientationPortrait</string> + <string>UIInterfaceOrientationLandscapeLeft</string> + <string>UIInterfaceOrientationLandscapeRight</string> + </array> + <key>NSAppTransportSecurity</key> + <dict> + <key>NSAllowsArbitraryLoads</key> + <true/> + </dict> +</dict> +</plist>
\ No newline at end of file diff --git a/test/ios/README.md b/test/ios/README.md new file mode 100644 index 0000000000..5b0d1f6a08 --- /dev/null +++ b/test/ios/README.md @@ -0,0 +1,7 @@ +# iOS UnitTestsRunner App + +This is a blank single-view-controller iOS app, linked against to a C++ static libraries, plus a a simple unit xctest. We use CMake to create an Xcode-friendly out-of-source build system. In another word, the build system is maintained by `CMakeLists` file,instead of a configured `.xcodeproj` file. + +This CMake project can build the executable UnitTestsApp which is linked to the static C++ library 'mbgl-test'. CMakeLists.txt files are the only build configuration kept in source control. This is in contrast to committing the `.xcodeproj` directory which includes the backing XML, which is nonsensically hard to edit by hand. + +The test instantiates ObjC object of class `IosTestRunner` from the app, the class will instantiates a C++ object from the linked library `mbgl-test` and calls running unit test function on it. It subsequently deletes the C++ object pointer. In the end, the test will check the existence of test report, which is an xml file that attach to xctest result. diff --git a/test/ios/UnitTestsApp_iphoneos13.2-arm64e-debug.xctestrun b/test/ios/UnitTestsApp_iphoneos13.2-arm64e-debug.xctestrun new file mode 100644 index 0000000000..b6b7a9d1b0 --- /dev/null +++ b/test/ios/UnitTestsApp_iphoneos13.2-arm64e-debug.xctestrun @@ -0,0 +1,68 @@ +<?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>UnitTestsAppTests</key> + <dict> + <key>BlueprintName</key> + <string>UnitTestsAppTests</string> + <key>BundleIdentifiersForCrashReportEmphasis</key> + <array> + <string>com.mapbox.UnitTestsApp</string> + <string>com.mapbox.UnitTestsAppTests</string> + </array> + <key>CommandLineArguments</key> + <array/> + <key>DependentProductPaths</key> + <array> + <string>__TESTROOT__/Debug-iphoneos/UnitTestsApp.app</string> + <string>__TESTROOT__/Debug-iphoneos/UnitTestsApp.app/PlugIns/UnitTestsAppTests.xctest</string> + </array> + <key>EnvironmentVariables</key> + <dict> + <key>OS_ACTIVITY_DT_MODE</key> + <string>YES</string> + <key>SQLITE_ENABLE_THREAD_ASSERTIONS</key> + <string>1</string> + </dict> + <key>IsAppHostedTestBundle</key> + <true/> + <key>ProductModuleName</key> + <string>UnitTestsAppTests</string> + <key>RunOrder</key> + <integer>0</integer> + <key>SystemAttachmentLifetime</key> + <string>deleteOnSuccess</string> + <key>TestBundlePath</key> + <string>__TESTHOST__/PlugIns/UnitTestsAppTests.xctest</string> + <key>TestHostBundleIdentifier</key> + <string>com.mapbox.UnitTestsApp</string> + <key>TestHostPath</key> + <string>__TESTROOT__/Debug-iphoneos/UnitTestsApp.app</string> + <key>TestLanguage</key> + <string></string> + <key>TestRegion</key> + <string></string> + <key>TestingEnvironmentVariables</key> + <dict> + <key>DYLD_FALLBACK_FRAMEWORK_PATH</key> + <string></string> + <key>DYLD_INSERT_LIBRARIES</key> + <string>__PLATFORMS__/iPhoneOS.platform/Developer/usr/lib/libXCTestBundleInject.dylib</string> + <key>XCInjectBundleInto</key> + <string>unused</string> + </dict> + <key>ToolchainsSettingValue</key> + <array/> + <key>UITargetAppCommandLineArguments</key> + <array/> + <key>UserAttachmentLifetime</key> + <string>deleteOnSuccess</string> + </dict> + <key>__xctestrun_metadata__</key> + <dict> + <key>FormatVersion</key> + <integer>1</integer> + </dict> +</dict> +</plist> diff --git a/test/ios/UnitTestsApp_iphoneos13.2-arm64e-release.xctestrun b/test/ios/UnitTestsApp_iphoneos13.2-arm64e-release.xctestrun new file mode 100644 index 0000000000..02038a4417 --- /dev/null +++ b/test/ios/UnitTestsApp_iphoneos13.2-arm64e-release.xctestrun @@ -0,0 +1,68 @@ +<?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>UnitTestsAppTests</key> + <dict> + <key>BlueprintName</key> + <string>UnitTestsAppTests</string> + <key>BundleIdentifiersForCrashReportEmphasis</key> + <array> + <string>com.mapbox.UnitTestsApp</string> + <string>com.mapbox.UnitTestsAppTests</string> + </array> + <key>CommandLineArguments</key> + <array/> + <key>DependentProductPaths</key> + <array> + <string>__TESTROOT__/Release-iphoneos/UnitTestsApp.app</string> + <string>__TESTROOT__/Release-iphoneos/UnitTestsApp.app/PlugIns/UnitTestsAppTests.xctest</string> + </array> + <key>EnvironmentVariables</key> + <dict> + <key>OS_ACTIVITY_DT_MODE</key> + <string>YES</string> + <key>SQLITE_ENABLE_THREAD_ASSERTIONS</key> + <string>1</string> + </dict> + <key>IsAppHostedTestBundle</key> + <true/> + <key>ProductModuleName</key> + <string>UnitTestsAppTests</string> + <key>RunOrder</key> + <integer>0</integer> + <key>SystemAttachmentLifetime</key> + <string>deleteOnSuccess</string> + <key>TestBundlePath</key> + <string>__TESTHOST__/PlugIns/UnitTestsAppTests.xctest</string> + <key>TestHostBundleIdentifier</key> + <string>com.mapbox.UnitTestsApp</string> + <key>TestHostPath</key> + <string>__TESTROOT__/Release-iphoneos/UnitTestsApp.app</string> + <key>TestLanguage</key> + <string></string> + <key>TestRegion</key> + <string></string> + <key>TestingEnvironmentVariables</key> + <dict> + <key>DYLD_FALLBACK_FRAMEWORK_PATH</key> + <string></string> + <key>DYLD_INSERT_LIBRARIES</key> + <string>__PLATFORMS__/iPhoneOS.platform/Developer/usr/lib/libXCTestBundleInject.dylib</string> + <key>XCInjectBundleInto</key> + <string>unused</string> + </dict> + <key>ToolchainsSettingValue</key> + <array/> + <key>UITargetAppCommandLineArguments</key> + <array/> + <key>UserAttachmentLifetime</key> + <string>deleteOnSuccess</string> + </dict> + <key>__xctestrun_metadata__</key> + <dict> + <key>FormatVersion</key> + <integer>1</integer> + </dict> +</dict> +</plist> diff --git a/test/ios/codesigning/UnitTestsApp.app.xcent.template b/test/ios/codesigning/UnitTestsApp.app.xcent.template new file mode 100644 index 0000000000..a851541766 --- /dev/null +++ b/test/ios/codesigning/UnitTestsApp.app.xcent.template @@ -0,0 +1,16 @@ +<?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>application-identifier</key> + <string>$TEAM_ID.com.mapbox.UnitTestsApp</string> + <key>com.apple.developer.team-identifier</key> + <string>$TEAM_ID</string> + <key>get-task-allow</key> + <true/> + <key>keychain-access-groups</key> + <array> + <string>$TEAM_ID.com.mapbox.UnitTestsApp</string> + </array> +</dict> +</plist>
\ No newline at end of file diff --git a/test/ios/codesigning/UnitTestsAppTests.xctest.xcent.template b/test/ios/codesigning/UnitTestsAppTests.xctest.xcent.template new file mode 100644 index 0000000000..72b2dbbb9d --- /dev/null +++ b/test/ios/codesigning/UnitTestsAppTests.xctest.xcent.template @@ -0,0 +1,16 @@ +<?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>application-identifier</key> + <string>$TEAM_ID.com.mapbox.UnitTestsAppTests</string> + <key>com.apple.developer.team-identifier</key> + <string>$TEAM_ID</string> + <key>get-task-allow</key> + <true/> + <key>keychain-access-groups</key> + <array> + <string>$TEAM_ID.com.mapbox.UnitTestsAppTests</string> + </array> +</dict> +</plist>
\ No newline at end of file diff --git a/test/ios/codesigning/XCTAutomationSupport.framework.xcent.template b/test/ios/codesigning/XCTAutomationSupport.framework.xcent.template new file mode 100644 index 0000000000..72b2dbbb9d --- /dev/null +++ b/test/ios/codesigning/XCTAutomationSupport.framework.xcent.template @@ -0,0 +1,16 @@ +<?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>application-identifier</key> + <string>$TEAM_ID.com.mapbox.UnitTestsAppTests</string> + <key>com.apple.developer.team-identifier</key> + <string>$TEAM_ID</string> + <key>get-task-allow</key> + <true/> + <key>keychain-access-groups</key> + <array> + <string>$TEAM_ID.com.mapbox.UnitTestsAppTests</string> + </array> +</dict> +</plist>
\ No newline at end of file diff --git a/test/ios/codesigning/XCTest.framework.xcent.template b/test/ios/codesigning/XCTest.framework.xcent.template new file mode 100644 index 0000000000..72b2dbbb9d --- /dev/null +++ b/test/ios/codesigning/XCTest.framework.xcent.template @@ -0,0 +1,16 @@ +<?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>application-identifier</key> + <string>$TEAM_ID.com.mapbox.UnitTestsAppTests</string> + <key>com.apple.developer.team-identifier</key> + <string>$TEAM_ID</string> + <key>get-task-allow</key> + <true/> + <key>keychain-access-groups</key> + <array> + <string>$TEAM_ID.com.mapbox.UnitTestsAppTests</string> + </array> +</dict> +</plist>
\ No newline at end of file diff --git a/test/ios/codesigning/codesign_all.sh b/test/ios/codesigning/codesign_all.sh new file mode 100755 index 0000000000..1a6007ea94 --- /dev/null +++ b/test/ios/codesigning/codesign_all.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +codesign --force --sign $CODESIGNIDENTITY --entitlements ../codesigning/UnitTestsApp.app.xcent --timestamp=none ./Release-iphoneos/UnitTestsApp.app +codesign --force --sign $CODESIGNIDENTITY --deep --preserve-metadata=identifier,entitlements,flags --timestamp=none ./Release-iphoneos/UnitTestsApp.app/Frameworks/libXCTestSwiftSupport.dylib +codesign --force --sign $CODESIGNIDENTITY --deep --preserve-metadata=identifier,entitlements,flags --timestamp=none ./Release-iphoneos/UnitTestsApp.app/Frameworks/libXCTestBundleInject.dylib +codesign --force --sign $CODESIGNIDENTITY --deep --preserve-metadata=identifier,entitlements,flags --timestamp=none ./Release-iphoneos/UnitTestsApp.app/Frameworks/XCTAutomationSupport.framework +codesign --force --sign $CODESIGNIDENTITY --deep --preserve-metadata=identifier,entitlements,flags --timestamp=none ./Release-iphoneos/UnitTestsApp.app/Frameworks/XCTest.framework +codesign --force --sign $CODESIGNIDENTITY --deep --entitlements ../codesigning/UnitTestsAppTests.xctest.xcent --timestamp=none ./Release-iphoneos/UnitTestsApp.app/PlugIns/UnitTestsAppTests.xctest diff --git a/test/ios/codesigning/generate-entitlements.swift b/test/ios/codesigning/generate-entitlements.swift new file mode 100755 index 0000000000..83834483bf --- /dev/null +++ b/test/ios/codesigning/generate-entitlements.swift @@ -0,0 +1,40 @@ +#!/usr/bin/swift + +/// Generates Entitlement files .xcent for codesigning, containing the correct team id +import Swift +import Foundation + +let fileManager = FileManager.default + +let contentsOfCurrentWorkingDirectory = try FileManager.default.contentsOfDirectory(at: URL(fileURLWithPath: "./codesigning/"), includingPropertiesForKeys: nil, options: []) + +guard let rawTeamIdEnv = getenv("IOS_DEVELOPMENT_TEAM") else { + print("Please add a IOS_DEVELOPMENT_TEAM environment variable.") + exit(1) +} + +let teamId2 = String(utf8String: rawTeamIdEnv) + +for file in contentsOfCurrentWorkingDirectory { + if (file.pathExtension == "template") { + var content = "" + do { + content = try String(contentsOf: file, encoding: .utf8) + } + catch { + print("Error reading xcent file: \(error).") + } + + content = content.replacingOccurrences(of: "$TEAM_ID", with: teamId2!) + + var targetFile = file + targetFile.deletePathExtension() + do { + try content.write(to: targetFile, atomically: false, encoding: .utf8) + print("Entitlement " + targetFile.absoluteString + " generated.") + } + catch { + print("Error writing xcent file: \(error).") + } + } +}
\ No newline at end of file diff --git a/test/ios/codesigning/libXCTestSwiftSupport.dylib.xcent.template b/test/ios/codesigning/libXCTestSwiftSupport.dylib.xcent.template new file mode 100644 index 0000000000..72b2dbbb9d --- /dev/null +++ b/test/ios/codesigning/libXCTestSwiftSupport.dylib.xcent.template @@ -0,0 +1,16 @@ +<?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>application-identifier</key> + <string>$TEAM_ID.com.mapbox.UnitTestsAppTests</string> + <key>com.apple.developer.team-identifier</key> + <string>$TEAM_ID</string> + <key>get-task-allow</key> + <true/> + <key>keychain-access-groups</key> + <array> + <string>$TEAM_ID.com.mapbox.UnitTestsAppTests</string> + </array> +</dict> +</plist>
\ No newline at end of file diff --git a/test/ios/fastlane/Appfile b/test/ios/fastlane/Appfile new file mode 100644 index 0000000000..f9e7e1e7c1 --- /dev/null +++ b/test/ios/fastlane/Appfile @@ -0,0 +1,3 @@ +app_identifier("com.mapbox.UnitTestsApp") # The bundle identifier of your app +apple_id ENV['MAPBOX_APPLE_ID'] +team_id ENV['MAPBOX_APPLE_TEAM_ID'] # Developer Portal Team ID
\ No newline at end of file diff --git a/test/ios/fastlane/Matchfile b/test/ios/fastlane/Matchfile new file mode 100644 index 0000000000..2a815bfc8e --- /dev/null +++ b/test/ios/fastlane/Matchfile @@ -0,0 +1,5 @@ +git_url("git@github.com:mapbox/apple-certificates.git") +type("development") # The default type, can be: appstore, adhoc, enterprise or development +app_identifier(["com.mapbox.UnitTestsApp", "com.mapbox.UnitTestsAppTests"]) +username ENV['MAPBOX_APPLE_ID'] +keychain_name("fastlane_keychain")
\ No newline at end of file diff --git a/test/ios/iosTestRunner.h b/test/ios/iosTestRunner.h new file mode 100644 index 0000000000..dcbb77e9d4 --- /dev/null +++ b/test/ios/iosTestRunner.h @@ -0,0 +1,9 @@ +#import <Foundation/Foundation.h> + +__attribute__((visibility ("default"))) +@interface IosTestRunner : NSObject + +- (NSString*) getResultPath; +- (BOOL) getTestStatus; + +@end diff --git a/test/ios/iosTestRunner.mm b/test/ios/iosTestRunner.mm new file mode 100644 index 0000000000..d3f6113a05 --- /dev/null +++ b/test/ios/iosTestRunner.mm @@ -0,0 +1,82 @@ +#import "iosTestRunner.h" + +#include <ios_test_runner.hpp> + +#include <string> + +@interface IosTestRunner () + +@property (nullable) TestRunner* runner; + +@property (copy, nullable) NSString *resultPath; + +@property BOOL testStatus; + +@end + +@implementation IosTestRunner + +-(instancetype)init +{ + self = [super init]; + if (self) { + self.testStatus = NO; + self.runner = new TestRunner(); + 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]; + BOOL success = [fileManager fileExistsAtPath: destinationPath]; + if (success) { + [fileManager removeItemAtPath:destinationPath error:NULL]; + } + + success = [fileManager fileExistsAtPath: destinationPath]; + if (!success) { + NSString *copyDirPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: dirName]; + success = [fileManager copyItemAtPath: copyDirPath toPath: destinationPath error: &error]; + + if (!success) { + NSLog(@"Failed to copy file '%@'", dirName); + NSAssert1(0, @"Failed to copy file, error '%@'", [error localizedDescription]); + } else { + NSLog(@"File '%@' copied OK", dirName); + } + } else { + NSLog(@"Failed to remove file '%@'", dirName); + NSAssert1(0, @"Failed to remove file, error '%@'", [error localizedDescription]); + } + break; + } + } + std::string basePath = std::string([documentsDir UTF8String]) + std::string("/test-data"); + self.testStatus = self.runner->startTest(basePath) ? YES : NO; + self.resultPath = [documentsDir stringByAppendingPathComponent:@"/test-data/test/results.xml"]; + + BOOL fileFound = [fileManager fileExistsAtPath: self.resultPath]; + if (fileFound == NO) { + NSLog(@"Test result file '%@' does not exist", self.resultPath); + self.testStatus = NO; + } + + delete self.runner; + self.runner = nullptr; + } + return self; +} + +- (NSString*) getResultPath { + return self.resultPath; +} + +- (BOOL) getTestStatus { + return self.testStatus; +} +@end diff --git a/test/ios/ios_test_runner.cpp b/test/ios/ios_test_runner.cpp new file mode 100644 index 0000000000..c99d8c3f30 --- /dev/null +++ b/test/ios/ios_test_runner.cpp @@ -0,0 +1,31 @@ +#include <ios_test_runner.hpp> + +#include <mbgl/test.hpp> + +#include <mbgl/util/logging.hpp> + +#include <unistd.h> +#include <vector> + +#define EXPORT __attribute__((visibility("default"))) + +EXPORT +bool TestRunner::startTest(const std::string& basePath) { + std::vector<std::string> arguments = {"mbgl-test-runner", "--gtest_output=xml:" + basePath + "/test/results.xml"}; + std::vector<char*> argv; + for (const auto& arg : arguments) { + argv.push_back(const_cast<char*>(arg.data())); + } + argv.push_back(nullptr); + + if (chdir(basePath.c_str())) { + mbgl::Log::Error(mbgl::Event::General, "Failed to change the directory to " + basePath); + return false; + } + + mbgl::Log::Info(mbgl::Event::General, "Start TestRunner"); + int status = mbgl::runTests(static_cast<uint32_t>(argv.size()), argv.data()); + mbgl::Log::Info(mbgl::Event::General, "TestRunner finished with status: '%d'", status); + + return status == 0; +} diff --git a/test/ios/tests/Info.plist b/test/ios/tests/Info.plist new file mode 100644 index 0000000000..ba6b34e5b6 --- /dev/null +++ b/test/ios/tests/Info.plist @@ -0,0 +1,22 @@ +<?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>CFBundleExecutable</key> + <string>UnitTestsAppTests</string> + <key>CFBundleIdentifier</key> + <string>com.mapbox.UnitTestsAppTests</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>1.0</string> + <key>CFBundleName</key> + <string>UnitTestsAppTests</string> + <key>CFBundlePackageType</key> + <string>BNDL</string> + <key>CFBundleShortVersionString</key> + <string>1.0</string> + <key>CFBundleVersion</key> + <string>1</string> +</dict> +</plist> diff --git a/test/map/transform.test.cpp b/test/map/transform.test.cpp index 95fb744206..02ecbfbee4 100644 --- a/test/map/transform.test.cpp +++ b/test/map/transform.test.cpp @@ -621,7 +621,8 @@ TEST(Transform, LatLngBounds) { } transform.jumpTo(CameraOptions().withCenter(sanFrancisco)); - ASSERT_EQ(transform.getLatLng(), sanFrancisco); + ASSERT_NEAR(transform.getLatLng().latitude(), sanFrancisco.latitude(), 1e-8); + ASSERT_NEAR(transform.getLatLng().longitude(), sanFrancisco.longitude(), 1e-8); // Single location. transform.setLatLngBounds(LatLngBounds::singleton(sanFrancisco)); @@ -655,7 +656,7 @@ TEST(Transform, LatLngBounds) { // └───┴───┸───┴───┸───┴───┘ transform.setLatLngBounds(LatLngBounds::hull({ -90.0, 0.0 }, { 90.0, 180.0 })); transform.jumpTo(CameraOptions().withCenter(sanFrancisco)); - ASSERT_EQ(transform.getLatLng().latitude(), sanFrancisco.latitude()); + ASSERT_NEAR(transform.getLatLng().latitude(), sanFrancisco.latitude(), 1e-8); ASSERT_EQ(transform.getLatLng().longitude(), 0.0); // -1 | 0 | +1 diff --git a/test/storage/main_resource_loader.test.cpp b/test/storage/main_resource_loader.test.cpp index ee9211b064..b5245dbad8 100644 --- a/test/storage/main_resource_loader.test.cpp +++ b/test/storage/main_resource_loader.test.cpp @@ -8,6 +8,7 @@ #include <mbgl/storage/resource_transform.hpp> #include <mbgl/test/util.hpp> #include <mbgl/util/run_loop.hpp> +#include <mbgl/util/timer.hpp> using namespace mbgl; @@ -749,3 +750,38 @@ TEST(MainResourceLoader, TEST_REQUIRES_SERVER(CachedResourceLowPriority)) { loop.run(); } + +TEST(MainResourceLoader, TEST_REQUIRES_SERVER(NoDoubleDispatch)) { + util::RunLoop loop; + MainResourceLoader fs(ResourceOptions{}); + + const Resource resource{Resource::Unknown, "http://127.0.0.1:3000/revalidate-same"}; + Response response; + response.data = std::make_shared<std::string>("data"); + response.etag.emplace("snowfall"); + + std::unique_ptr<AsyncRequest> req; + unsigned responseCount = 0u; + auto dbfs = FileSourceManager::get()->getFileSource(FileSourceType::Database, ResourceOptions{}); + dbfs->forward(resource, response, [&] { + req = fs.request(resource, [&](Response res) { + EXPECT_EQ(nullptr, res.error); + EXPECT_FALSE(bool(res.modified)); + EXPECT_TRUE(bool(res.etag)); + EXPECT_EQ("snowfall", *res.etag); + if (!res.notModified) { + ASSERT_TRUE(res.data.get()); + EXPECT_EQ("data", *res.data); + ++responseCount; + } + }); + }); + + util::Timer timer; + timer.start(Milliseconds(100), Duration::zero(), [&loop, &responseCount] { + EXPECT_EQ(1u, responseCount); + loop.stop(); + }); + + loop.run(); +} diff --git a/test/storage/offline_database.test.cpp b/test/storage/offline_database.test.cpp index f988457dac..f344151297 100644 --- a/test/storage/offline_database.test.cpp +++ b/test/storage/offline_database.test.cpp @@ -779,7 +779,7 @@ TEST(OfflineDatabase, MapboxTileLimitExceeded) { db.put(ambientTile, response); }; - auto insertRegionTile = [&](int64_t regionID, unsigned i) { + auto insertRegionTile = [&](int64_t regionID, uint64_t i) { const Resource tile = Resource::tile("mapbox://region_tile_" + std::to_string(i), 1, 0, 0, 0, Tileset::Scheme::XYZ); db.putRegionResource(regionID, tile, response); }; @@ -801,14 +801,14 @@ TEST(OfflineDatabase, MapboxTileLimitExceeded) { ASSERT_EQ(db.getOfflineMapboxTileCount(), 0); // Fine because this region is under the tile limit. - for (unsigned i = 0; i < limit - 10; ++i) { + for (uint64_t i = 0; i < limit - 10; ++i) { insertRegionTile(region1->getID(), i); } ASSERT_EQ(db.getOfflineMapboxTileCount(), limit - 10); // Fine because this region + the previous is at the limit. - for (unsigned i = limit; i < limit + 10; ++i) { + for (uint64_t i = limit; i < limit + 10; ++i) { insertRegionTile(region2->getID(), i); } @@ -848,7 +848,7 @@ TEST(OfflineDatabase, MapboxTileLimitExceeded) { // 10, which would blow up the limit if it wasn't // for the fact that tile 60 is already on the // database and will not count. - for (unsigned i = limit; i < limit + 10; ++i) { + for (uint64_t i = limit; i < limit + 10; ++i) { insertRegionTile(region1->getID(), i); } diff --git a/test/tile/vector_tile.test.cpp b/test/tile/vector_tile.test.cpp index a31915498a..7bf5dae267 100644 --- a/test/tile/vector_tile.test.cpp +++ b/test/tile/vector_tile.test.cpp @@ -91,6 +91,8 @@ TEST(VectorTileData, ParseResults) { ASSERT_TRUE(false) << "should throw: feature index is out of range."; } catch (const std::out_of_range&) { ASSERT_TRUE(true); + } catch (...) { // needed for iOS when MBGL_WITH_RTTI=OFF + ASSERT_TRUE(true); } std::unique_ptr<GeometryTileFeature> feature = layer->getFeature(0u); diff --git a/test/util/tile_cover.test.cpp b/test/util/tile_cover.test.cpp index af9f0c4884..ba39bfa61b 100644 --- a/test/util/tile_cover.test.cpp +++ b/test/util/tile_cover.test.cpp @@ -365,7 +365,7 @@ TEST(TileCount, BoundsCrossingAntimeridian) { TEST(TileCover, DISABLED_FuzzPoly) { while(true) { - std::srand (time(nullptr)); + std::srand(static_cast<uint32_t>(time(nullptr))); std::size_t len = std::rand() % 10000 + 3; Polygon<double> polygon; @@ -393,7 +393,7 @@ TEST(TileCover, DISABLED_FuzzPoly) { TEST(TileCover, DISABLED_FuzzLine) { while(true) { - std::srand (time(nullptr)); + std::srand(static_cast<uint32_t>(time(nullptr))); std::size_t len = std::rand() % 10000 + 3; MultiLineString<double> mls; |