1 // Copyright 2013 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 #ifndef TESTING_ANDROID_NATIVE_TEST_NATIVE_TEST_UTIL_H_ 6 #define TESTING_ANDROID_NATIVE_TEST_NATIVE_TEST_UTIL_H_ 7 8 #include <stdio.h> 9 10 #include <string> 11 #include <vector> 12 13 #include "base/compiler_specific.h" 14 15 // Helper methods for setting up environment for running gtest tests 16 // inside an APK. 17 namespace testing { 18 namespace android { 19 20 class ScopedMainEntryLogger { 21 public: ScopedMainEntryLogger()22 ScopedMainEntryLogger() { 23 printf(">>ScopedMainEntryLogger\n"); 24 } 25 ~ScopedMainEntryLogger()26 ~ScopedMainEntryLogger() { 27 printf("<<ScopedMainEntryLogger\n"); 28 // SAFETY: On Android with __ANDROID_API__ <= 22 (Lollipop MR1), `stdout` is 29 // a macro that accesses a buffer of unknown length, triggering the 30 // `-Wunsafe-buffer-usage` warning. This usage is sound, as it accesses a 31 // fixed position in a system-provided array. 32 // While Lollipop is no longer officially supported by Chromium, Cronet 33 // currently maintains compatibility with this older Android version. Check 34 // for optional bot `android-cronet-arm64-dbg` before removing this. 35 fflush(UNSAFE_BUFFERS(stdout)); 36 fflush(UNSAFE_BUFFERS(stderr)); 37 } 38 }; 39 40 void ParseArgsFromString( 41 const std::string& command_line, std::vector<std::string>* args); 42 void ParseArgsFromCommandLineFile( 43 const char* path, std::vector<std::string>* args); 44 int ArgsToArgv(const std::vector<std::string>& args, std::vector<char*>* argv); 45 46 } // namespace android 47 } // namespace testing 48 49 #endif // TESTING_ANDROID_NATIVE_TEST_NATIVE_TEST_UTIL_H_ 50