Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: testing/android/native_test_launcher.cc

Issue 10161032: Add PathUtilsTest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdio.h> 5 #include <stdio.h>
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/android/path_utils.h" 9 #include "base/android/path_utils.h"
10 #include "base/android/scoped_java_ref.h"
10 #include "base/at_exit.h" 11 #include "base/at_exit.h"
11 #include "base/command_line.h" 12 #include "base/command_line.h"
12 #include "base/file_path.h" 13 #include "base/file_path.h"
13 #include "base/file_util.h" 14 #include "base/file_util.h"
14 #include "base/logging.h" 15 #include "base/logging.h"
15 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
16 #include "base/string_tokenizer.h" 17 #include "base/string_tokenizer.h"
17 #include "base/string_util.h" 18 #include "base/string_util.h"
18 #include "base/test/test_suite.h" 19 #include "base/test/test_suite.h"
19 #include "testing/android/jni/chrome_native_test_activity_jni.h" 20 #include "testing/android/jni/chrome_native_test_activity_jni.h"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 false); // Tick count 150 false); // Tick count
150 VLOG(0) << "Chromium logging enabled: level = " << logging::GetMinLogLevel() 151 VLOG(0) << "Chromium logging enabled: level = " << logging::GetMinLogLevel()
151 << ", default verbosity = " << logging::GetVlogVerbosity(); 152 << ", default verbosity = " << logging::GetVlogVerbosity();
152 base::android::RegisterPathUtils(env); 153 base::android::RegisterPathUtils(env);
153 } 154 }
154 155
155 } // namespace 156 } // namespace
156 157
157 // This method is called on a separate java thread so that we won't trigger 158 // This method is called on a separate java thread so that we won't trigger
158 // an ANR. 159 // an ANR.
159 static void RunTests(JNIEnv* env, jobject obj, jstring jfiles_dir) { 160 static void RunTests(JNIEnv* env,
161 jobject obj,
162 jstring jfiles_dir,
163 jobject app_context) {
160 FilePath files_dir(base::android::ConvertJavaStringToUTF8(env, jfiles_dir)); 164 FilePath files_dir(base::android::ConvertJavaStringToUTF8(env, jfiles_dir));
161 // A few options, such "--gtest_list_tests", will just use printf directly 165 // A few options, such "--gtest_list_tests", will just use printf directly
162 // and won't use the "AndroidLogPrinter". Redirect stdout to a known file. 166 // and won't use the "AndroidLogPrinter". Redirect stdout to a known file.
163 FilePath stdout_path(files_dir.Append(FilePath("stdout.txt"))); 167 FilePath stdout_path(files_dir.Append(FilePath("stdout.txt")));
164 freopen(stdout_path.value().c_str(), "w", stdout); 168 freopen(stdout_path.value().c_str(), "w", stdout);
165 169
166 std::vector<std::string> args; 170 std::vector<std::string> args;
167 ParseArgsFromCommandLineFile(files_dir, &args); 171 ParseArgsFromCommandLineFile(files_dir, &args);
168 172
169 // We need to pass in a non-const char**. 173 // We need to pass in a non-const char**.
170 std::vector<char*> argv; 174 std::vector<char*> argv;
171 ArgsToArgv(args, &argv); 175 ArgsToArgv(args, &argv);
172 176
173 int argc = argv.size(); 177 int argc = argv.size();
174 // This object is owned by gtest. 178 // This object is owned by gtest.
175 AndroidLogPrinter* log = new AndroidLogPrinter(); 179 AndroidLogPrinter* log = new AndroidLogPrinter();
176 log->Init(&argc, &argv[0]); 180 log->Init(&argc, &argv[0]);
177 181
182 // Set the application context in base.
183 base::android::ScopedJavaLocalRef<jobject> scoped_context(env, app_context);
John Grabowski 2012/04/25 20:22:12 This doesn't look correct. You don't create the l
nilesh 2012/04/25 23:33:26 Thanks for explaining this. I am now creating a Ne
184 base::android::InitApplicationContext(scoped_context);
185
178 main(argc, &argv[0]); 186 main(argc, &argv[0]);
179 } 187 }
180 188
181 // This is called by the VM when the shared library is first loaded. 189 // This is called by the VM when the shared library is first loaded.
182 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { 190 JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
183 base::android::InitVM(vm); 191 base::android::InitVM(vm);
184 JNIEnv* env = base::android::AttachCurrentThread(); 192 JNIEnv* env = base::android::AttachCurrentThread();
185 if (!RegisterNativesImpl(env)) { 193 if (!RegisterNativesImpl(env)) {
186 return -1; 194 return -1;
187 } 195 }
188 LibraryLoadedOnMainThread(env); 196 LibraryLoadedOnMainThread(env);
189 return JNI_VERSION_1_4; 197 return JNI_VERSION_1_4;
190 } 198 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698