TEST(FileTest, IsAbsolute) { static const string kFileName = this->test_info_->name(); FileHelper helper; const string path = helper.CreateTempFile(kFileName, "Hello World"); EXPECT_TRUE(File::IsAbsolutePath(path)); EXPECT_FALSE(File::IsAbsolutePath(kFileName)); }
TEST(FileTest, LastWriteTime_NotOpen) { static const string kHelloWorld = "Hello World"; FileHelper helper; time_t now = time(nullptr); string path = helper.CreateTempFile(this->test_info_->name(), kHelloWorld); File file(path); ASSERT_LE(now, file.last_write_time()); }
TEST(FileTest, IsOpen_Open) { static const string kHelloWorld = "Hello World"; FileHelper helper; string path = helper.CreateTempFile(this->test_info_->name(), kHelloWorld); File file(path); ASSERT_TRUE(file.Open(File::modeBinary | File::modeReadOnly)); EXPECT_TRUE(file.IsOpen()); EXPECT_TRUE((bool) file); }
TEST(FileTest, RealPath_Same) { static const string kFileName = this->test_info_->name(); FileHelper helper; const string path = helper.CreateTempFile(kFileName, "Hello World"); string realpath; ASSERT_TRUE(File::RealPath(path, &realpath)); EXPECT_EQ(path, realpath); }
TEST(FileTest, MakeAbsolutePath_AlreadyAbsolute) { static const string kFileName = this->test_info_->name(); FileHelper helper; const string path = helper.CreateTempFile(kFileName, "Hello World"); string relative(path); // Note: relative == absolute path (path) File::MakeAbsolutePath(helper.TempDir(), &relative); EXPECT_EQ(path, relative); }
TEST(FileTest, IsDirectory_Open) { static const string kHelloWorld = "Hello World"; FileHelper helper; string path = helper.CreateTempFile(this->test_info_->name(), kHelloWorld); File file(path); ASSERT_TRUE(file.Open(File::modeBinary | File::modeReadOnly)); ASSERT_FALSE(file.IsDirectory()); ASSERT_TRUE(file.IsFile()); }
TEST(FileTest, Length_Open) { static const string kHelloWorld = "Hello World"; FileHelper helper; string path = helper.CreateTempFile(this->test_info_->name(), kHelloWorld); File file(path); ASSERT_TRUE(file.Open(File::modeBinary | File::modeReadOnly)); ASSERT_EQ(static_cast<long>(kHelloWorld.size()), file.GetLength()); }
TEST(FileTest, RealPath_Different) { static const string kFileName = this->test_info_->name(); FileHelper helper; const string path = helper.CreateTempFile(kFileName, "Hello World"); string realpath; // Add an extra ./ into the path. ASSERT_TRUE(File::RealPath(StrCat(helper.TempDir(), File::pathSeparatorString, ".", File::pathSeparatorString, kFileName), &realpath)); EXPECT_EQ(path, realpath); }
TEST(FileTest, ExistsWildCard_Extension) { FileHelper helper; const string path = helper.CreateTempFile("msg00000.001", "msg00000.001"); ASSERT_TRUE(File::Exists(path)); string wildcard_path = StrCat(helper.TempDir(), File::pathSeparatorString, "msg*.001"); ASSERT_TRUE(File::ExistsWildcard(wildcard_path)) << path << "; w: " << wildcard_path; wildcard_path = StrCat(helper.TempDir(), File::pathSeparatorString, "msg*.??1"); ASSERT_TRUE(File::ExistsWildcard(wildcard_path)) << path << "; w: " << wildcard_path; }
TEST(PPPConfigTest, NodeConfig) { FileHelper files; files.Mkdir("network"); const string line("@2 [email protected]"); files.CreateTempFile("network/address.net", line); const string network_dir = files.DirName("network"); PPPConfig config(1, "mybbs", network_dir); const PPPNodeConfig* node_config = config.node_config_for(2); ASSERT_TRUE(node_config != nullptr); EXPECT_EQ("*****@*****.**", node_config->email_address); }
TEST(FileTest, Read) { static const string kHelloWorld = "Hello World"; FileHelper helper; string path = helper.CreateTempFile(this->test_info_->name(), kHelloWorld); File file(path); ASSERT_TRUE(file.Open(File::modeBinary | File::modeReadOnly)); char buf[255]; ASSERT_EQ(static_cast<int>(kHelloWorld.length()), file.Read(buf, kHelloWorld.length())); buf[11] = 0; ASSERT_STREQ(kHelloWorld.c_str(), buf); }
TEST_F(CalloutTest, NodeConfig) { FileHelper files; files.Mkdir("network"); const string line("@1 & \"foo\""); files.CreateTempFile("network/callout.net", line); const string network_dir = files.DirName("network"); Callout callout(network_dir); const net_call_out_rec* con = callout.node_config_for(1); ASSERT_TRUE(con != nullptr); EXPECT_EQ(options_sendback, con->options); EXPECT_STREQ("foo", con->password); }