chromium - 測試程式使用base空間的類
阿新 • • 發佈:2018-12-20
前言
上個實驗,只在chromium中加了一個標準的win32console的工程,現在實驗了,使用base命令空間的類的工程修改。
不只是程式要包含base類的標頭檔案, Z:\chromium\src\base\test\BUILD.gn 也要修改,依賴base名稱空間,才能編譯過。
實驗
測試程式
// @file Z:\chromium\src\base\test\test_by_me\main.cpp // @brief write some test code to study chromium project /** # cd /d Z:\chromium\src\ # gn --ide=vs args out\my_x86_d # gn ls out\my_x86_d > d:\my_tmp\gn_list_target.log # 新加的測試工程位置//base/test:test_by_me # autoninja -C out\my_x86_d test_by_me */ #include <stdlib.h> #include <stdio.h> #include "base/bind.h" // for base:Bind() #include "base/logging.h" // for LOG() #include "base/callback.h" // for base ::Callback() #define PROG_NAME "test_my_me" void fn_test(); int main(int argc, char** argv) { printf(">> %s\n", PROG_NAME); // printf("hello chromium\n"); fn_test(); system("pause"); return EXIT_SUCCESS; } int Return5() { return 5; } void fn_test() { base::Callback<int(void)> func_cb = base::Bind(&Return5); DLOG(WARNING) << ">> fn_test()"; LOG(INFO) << func_cb.Run(); // Prints 5. DLOG(WARNING) << func_cb.Run(); }
配置檔案的修改
Z:\chromium\src\base\test\BUILD.gn
android_aidl("test_support_java_aidl") { testonly = true import_include = [ "android/java/src", "//base/android/java/src", ] sources = [ "android/java/src/org/chromium/base/ITestCallback.aidl", "android/java/src/org/chromium/base/ITestController.aidl", ] } } # Trivial executable which outputs space-delimited argv to stdout, # used for testing. executable("test_child_process") { testonly = true sources = [ "test_child_process.cc", ] deps = [ "//build/config:exe_and_shlib_deps", ] } executable("test_by_me") { sources = [ "test_by_me/main.cpp", ] deps = [ "//base", ] }
執行效果
列印到了日誌 Z:\chromium\src\out\my_x86_d\debug.log
[1217/131353.498:WARNING:main.cpp(40)] >> fn_test()
[1217/131353.499:INFO:main.cpp(41)] 5
[1217/131353.499:WARNING:main.cpp(42)] 5