• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <vector>
6 
7 #include "base/android/jni_array.h"
8 #include "base/check.h"
9 #include "testing/android/native_test/native_test_jni_headers/MainRunner_jni.h"
10 #include "testing/android/native_test/native_test_util.h"
11 
12 extern int main(int argc, char** argv);
13 
14 namespace testing {
15 namespace android {
16 
JNI_MainRunner_RunMain(JNIEnv * env,const base::android::JavaParamRef<jobjectArray> & command_line)17 static jint JNI_MainRunner_RunMain(
18     JNIEnv* env,
19     const base::android::JavaParamRef<jobjectArray>& command_line) {
20   // Guards against process being reused.
21   // In most cases, running main again will cause problems (static variables,
22   // singletons, lazy instances won't be in the same state as a clean run).
23   static bool alreadyRun = false;
24   CHECK(!alreadyRun);
25   alreadyRun = true;
26 
27   std::vector<std::string> cpp_command_line;
28   AppendJavaStringArrayToStringVector(env, command_line, &cpp_command_line);
29 
30   std::vector<char*> argv;
31   int argc = ArgsToArgv(cpp_command_line, &argv);
32   return main(argc, &argv[0]);
33 }
34 
35 }  // namespace android
36 }  // namespace testing
37