From ad4002c17b3e53f48b4e91e57cad94b6c962bac4 Mon Sep 17 00:00:00 2001 From: Juha Alanen Date: Thu, 23 Jan 2020 14:24:09 +0200 Subject: [test] Enable HTTP server on Android --- next/platform/android/android.cmake | 24 +++++++++++++++++++++++- next/test/CMakeLists.txt | 2 +- platform/android/src/test/test_runner.cpp | 9 ++++++--- test/android/app/build.gradle | 2 +- test/android/app/src/main/AndroidManifest.xml | 2 ++ test/include/mbgl/test/util.hpp | 2 -- 6 files changed, 33 insertions(+), 8 deletions(-) diff --git a/next/platform/android/android.cmake b/next/platform/android/android.cmake index 454e11bcd2..1f77d0a29a 100644 --- a/next/platform/android/android.cmake +++ b/next/platform/android/android.cmake @@ -329,7 +329,6 @@ add_library( ${MBGL_ROOT}/platform/default/src/mbgl/text/local_glyph_rasterizer.cpp ${MBGL_ROOT}/platform/android/src/test/collator_test_stub.cpp ${MBGL_ROOT}/platform/android/src/test/number_format_test_stub.cpp - ${MBGL_ROOT}/platform/android/src/test/http_file_source_test_stub.cpp ) target_include_directories( @@ -347,6 +346,29 @@ target_link_libraries( -Wl,--no-whole-archive ) +if(ANDROID_NATIVE_API_LEVEL VERSION_LESS 24) + target_sources( + mbgl-test-runner + PRIVATE ${MBGL_ROOT}/platform/android/src/test/http_file_source_test_stub.cpp + ) +else() + set(CURL_DIR ${MBGL_ROOT}/vendor/curl-android-ios/prebuilt-with-ssl/android) + set(CURL_LIBRARY ${CURL_DIR}/${ANDROID_ABI}/libcurl.a) + + target_sources( + mbgl-test-runner + PRIVATE ${MBGL_ROOT}/platform/default/src/mbgl/storage/http_file_source.cpp + ) + target_include_directories( + mbgl-test-runner + PRIVATE ${CURL_DIR}/include + ) + target_link_libraries( + mbgl-test-runner + PRIVATE ${CURL_LIBRARY} + ) +endif() + add_custom_command( TARGET mbgl-test-runner PRE_BUILD COMMAND diff --git a/next/test/CMakeLists.txt b/next/test/CMakeLists.txt index ce980f78d1..a9814aa033 100644 --- a/next/test/CMakeLists.txt +++ b/next/test/CMakeLists.txt @@ -117,7 +117,7 @@ if(MBGL_WITH_OPENGL) ) endif() -if(WIN32 OR CMAKE_SYSTEM_NAME STREQUAL Android) +if(WIN32 OR CMAKE_SYSTEM_NAME STREQUAL Android AND ANDROID_NATIVE_API_LEVEL VERSION_LESS 24) message("Target platform does not support HTTP tests or dependencies not found.") set(MBGL_TEST_HAS_TEST_SERVER 0) diff --git a/platform/android/src/test/test_runner.cpp b/platform/android/src/test/test_runner.cpp index ec315fe27c..4f8b2165f8 100644 --- a/platform/android/src/test/test_runner.cpp +++ b/platform/android/src/test/test_runner.cpp @@ -2,12 +2,14 @@ #include "test_runner_common.hpp" #include +#include #include using namespace mbgl; using namespace mbgl::android; std::atomic running{true}; +std::atomic success{false}; std::once_flag done; ALooper* looper = NULL; @@ -23,6 +25,7 @@ void runner() { int status = mbgl::runTests(argv.size(), argv.data()); mbgl::Log::Info(mbgl::Event::General, "TestRunner finished with status: '%d'", status); running = false; + success = (status == 0); ALooper_wake(looper); } @@ -39,14 +42,14 @@ void android_main(struct android_app* app) { if (copyFile(env, app->activity->assetManager, zipFile, storagePath, "data.zip")) { if (chdir("/sdcard")) { mbgl::Log::Error(mbgl::Event::General, "Failed to change the directory to /sdcard"); - changeState(env, app, false); + changeState(env, app, success); } else { unZipFile(env, zipFile, "/sdcard/"); runnerThread = std::thread(runner); } } else { mbgl::Log::Error(mbgl::Event::General, "Failed to copy zip file '%s' to external storage", zipFile.c_str()); - changeState(env, app, false); + changeState(env, app, success); } int outFd, outEvents; @@ -62,7 +65,7 @@ void android_main(struct android_app* app) { std::call_once(done, [&] { mbgl::Log::Info(mbgl::Event::General, "TestRunner done"); runnerThread.join(); - changeState(env, app, true); + changeState(env, app, success); }); } diff --git a/test/android/app/build.gradle b/test/android/app/build.gradle index 9f915bbbd0..cadbdf6fd9 100644 --- a/test/android/app/build.gradle +++ b/test/android/app/build.gradle @@ -5,7 +5,7 @@ android { defaultConfig { applicationId = 'com.mapbox.mapboxsdk.maps.test_runner' - minSdkVersion 14 + minSdkVersion 24 targetSdkVersion 28 def abi = 'all' if (project.hasProperty('mapbox.abis')) { diff --git a/test/android/app/src/main/AndroidManifest.xml b/test/android/app/src/main/AndroidManifest.xml index 40767881d1..5311bf0507 100644 --- a/test/android/app/src/main/AndroidManifest.xml +++ b/test/android/app/src/main/AndroidManifest.xml @@ -5,6 +5,8 @@ android:versionName="1.0"> + +