// ===================================================================================================================== // ======================================================================================================================= CDateFileLogWriter::CDateFileLogWriter() { //~~~~~~~~~ time_t ltime; //~~~~~~~~~ time(<ime); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ struct tm *newtime = localtime(<ime); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ char path[256] = {0}; snprintf(path, sizeof(path), "%s/%s", GetDocumentPath(), "debug"); MyCreateDirectory(path); //~~~~~~~~~~~~~~~~~~~~~ char szLogName[256] = ""; //~~~~~~~~~~~~~~~~~~~~~ snprintf(szLogName, sizeof(szLogName) - 1, "%s/%u_%u_%u.log", path, newtime->tm_year + 1900, newtime->tm_mon + 1, newtime->tm_mday); szLogName[sizeof(szLogName) - 1] = 0; m_strFileName = szLogName; m_fp = fopen(m_strFileName.c_str(), "a+"); }
// ===================================================================================================================== // ======================================================================================================================= void CDateFileLogWriter::Write(const std::string &str) { if (m_fp) { //~~~~~~~~~ time_t ltime; //~~~~~~~~~ time(<ime); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ struct tm *newtime = localtime(<ime); char szLogName[256] = ""; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // 检查日期是否已改变,如果改变,则创建一个新的文件 snprintf(szLogName, sizeof(szLogName) - 1, "%s/debug/%u_%u_%u.log", GetDocumentPath(), newtime->tm_year + 1900, newtime->tm_mon + 1, newtime->tm_mday); szLogName[sizeof(szLogName) - 1] = 0; if (m_strFileName != szLogName) { fclose(m_fp); m_strFileName = szLogName; m_fp = fopen(m_strFileName.c_str(), "a+"); } if (m_fp) { #if defined DEBUG || defined _DEBUG char szBuf[1024] = {0}; snprintf(szBuf, 1024, "%s -- %s\n", str.c_str(), ctime(<ime)); #ifdef WIN32 OutputDebugStringA(szBuf); #else printf("%s", szBuf); #endif #endif fprintf(m_fp, "%s -- %s", str.c_str(), ctime(<ime)); fflush(m_fp); } } }
int tp_unittest_main(const char* path) { #ifdef RUN_ON_DEVICE #ifdef APP_IOS char gcdaFolder[1024] = ""; unsigned long uPathLen = 1024; GetDocumentPath(gcdaFolder, uPathLen); setenv("GCOV_PREFIX", gcdaFolder, 1); setenv("GCOV_PREFIX_STRIP", "1", 1); #endif #ifdef ANDROID setenv("GCOV_PREFIX", "/sdcard/wme_gcov/", 1); setenv("GCOV_PREFIX_STRIP", "6", 1); #endif #endif int argc = 1; const char *argv[] = {"tp_unittest_main"}; if (NULL == path || strlen(path) <= 0) return 1; char xmlPath[1024] = ""; sprintf(xmlPath, "xml:%s", path); printf("absolute path for XML:%s\n", xmlPath); ::testing::GTEST_FLAG(output) = xmlPath; ::testing::InitGoogleTest(&argc, (char **)argv); if(!g_sGTestFilter.empty()) { ::testing::FLAGS_gtest_filter = g_sGTestFilter.c_str(); } int ret = RUN_ALL_TESTS(); #ifdef ENABLED_GCOV_FLAG #if defined(MACOS) || defined(APP_IOS) __gcov_flush(); #endif #ifdef ANDROID exit(0); #endif #endif return ret; }