[test-runner] Run render test runner as a NativeActivity app on android device (#15827)
* [test-runner]Add android render-test-runner NativeActivity app * [test-runner] Fix cmake for CI build failure * [test-runner] Update folder location, change app configureation * [test-runner] Add running instruction
This commit is contained in:
40
platform/android/src/test/render_test_collator.cpp
Normal file
40
platform/android/src/test/render_test_collator.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <mbgl/i18n/collator.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace mbgl {
|
||||
namespace platform {
|
||||
|
||||
class Collator::Impl {
|
||||
public:
|
||||
Impl(bool caseSensitive_, bool diacriticSensitive_, optional<std::string>)
|
||||
: caseSensitive(caseSensitive_), diacriticSensitive(diacriticSensitive_) {}
|
||||
|
||||
bool operator==(const Impl& other) const { return true; }
|
||||
|
||||
int compare(const std::string& lhs, const std::string& rhs) const { return 0; }
|
||||
|
||||
std::string resolvedLocale() const { return ""; }
|
||||
|
||||
private:
|
||||
bool caseSensitive;
|
||||
bool diacriticSensitive;
|
||||
};
|
||||
|
||||
Collator::Collator(bool caseSensitive, bool diacriticSensitive, optional<std::string> locale_)
|
||||
: impl(std::make_shared<Impl>(caseSensitive, diacriticSensitive, std::move(locale_))) {}
|
||||
|
||||
int Collator::compare(const std::string& lhs, const std::string& rhs) const {
|
||||
return impl->compare(lhs, rhs);
|
||||
}
|
||||
|
||||
bool Collator::operator==(const Collator& other) const {
|
||||
return *impl == *(other.impl);
|
||||
}
|
||||
|
||||
std::string Collator::resolvedLocale() const {
|
||||
return impl->resolvedLocale();
|
||||
}
|
||||
|
||||
} // namespace platform
|
||||
} // namespace mbgl
|
||||
15
platform/android/src/test/render_test_number_format.cpp
Normal file
15
platform/android/src/test/render_test_number_format.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <mbgl/i18n/number_format.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace platform {
|
||||
|
||||
std::string formatNumber(double /*number*/,
|
||||
const std::string& /*localeId */,
|
||||
const std::string& /*currency*/,
|
||||
uint8_t /*minFractionDigits*/,
|
||||
uint8_t /*maxFractionDigits*/) {
|
||||
return "";
|
||||
}
|
||||
|
||||
} // namespace platform
|
||||
} // namespace mbgl
|
||||
57
platform/android/src/test/render_test_runner.cpp
Normal file
57
platform/android/src/test/render_test_runner.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#include <android_native_app_glue.h>
|
||||
#include <mbgl/render_test.hpp>
|
||||
#include "jni.hpp"
|
||||
#include "logger.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <mbgl/util/logging.hpp>
|
||||
|
||||
#include <android/log.h>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
namespace {
|
||||
|
||||
int severityToPriority(EventSeverity severity) {
|
||||
switch (severity) {
|
||||
case EventSeverity::Debug:
|
||||
return ANDROID_LOG_DEBUG;
|
||||
|
||||
case EventSeverity::Info:
|
||||
return ANDROID_LOG_INFO;
|
||||
|
||||
case EventSeverity::Warning:
|
||||
return ANDROID_LOG_WARN;
|
||||
|
||||
case EventSeverity::Error:
|
||||
return ANDROID_LOG_ERROR;
|
||||
|
||||
default:
|
||||
return ANDROID_LOG_VERBOSE;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void Log::platformRecord(EventSeverity severity, const std::string& msg) {
|
||||
__android_log_print(severityToPriority(severity), "mbgl", "%s", msg.c_str());
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
void android_main(struct android_app* app) {
|
||||
mbgl::android::theJVM = app->activity->vm;
|
||||
JNIEnv* env;
|
||||
app->activity->vm->AttachCurrentThread(&env, NULL);
|
||||
|
||||
std::vector<std::string> arguments = {"mbgl-render-test-runner", "-p", "/sdcard/render-test"};
|
||||
std::vector<char*> argv;
|
||||
for (const auto& arg : arguments) {
|
||||
argv.push_back((char*)arg.data());
|
||||
}
|
||||
argv.push_back(nullptr);
|
||||
(void)mbgl::runRenderTests(argv.size() - 1, argv.data());
|
||||
app->activity->vm->DetachCurrentThread();
|
||||
}
|
||||
Reference in New Issue
Block a user