This source file includes following definitions.
- SaveEnvironmentVariable
- RestoreEnvironmentVariable
- TEST_F
- TEST_F
#include "base/environment.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/common/env_vars.h"
#include "chrome/common/logging_chrome.h"
#include "testing/gtest/include/gtest/gtest.h"
class ChromeLoggingTest : public testing::Test {
public:
void SaveEnvironmentVariable(std::string new_value) {
scoped_ptr<base::Environment> env(base::Environment::Create());
if (!env->GetVar(env_vars::kLogFileName, &environment_filename_))
environment_filename_ = "";
env->SetVar(env_vars::kLogFileName, new_value);
}
void RestoreEnvironmentVariable() {
scoped_ptr<base::Environment> env(base::Environment::Create());
env->SetVar(env_vars::kLogFileName, environment_filename_);
}
private:
std::string environment_filename_;
};
TEST_F(ChromeLoggingTest, LogFileName) {
SaveEnvironmentVariable(std::string());
base::FilePath filename = logging::GetLogFileName();
ASSERT_NE(base::FilePath::StringType::npos,
filename.value().find(FILE_PATH_LITERAL("chrome_debug.log")));
RestoreEnvironmentVariable();
}
TEST_F(ChromeLoggingTest, EnvironmentLogFileName) {
SaveEnvironmentVariable("test value");
base::FilePath filename = logging::GetLogFileName();
ASSERT_EQ(base::FilePath(FILE_PATH_LITERAL("test value")).value(),
filename.value());
RestoreEnvironmentVariable();
}