76 lines
1.9 KiB
C++
76 lines
1.9 KiB
C++
#include <webserv/utils/FileUtils.hpp>
|
|
|
|
#include <gtest/gtest.h>
|
|
#include <fstream>
|
|
#include <filesystem>
|
|
|
|
/**
|
|
* @file test_file_utils.cpp
|
|
* @brief Comprehensive unit tests for FileUtils class
|
|
*/
|
|
|
|
class FileUtilsTest : public ::testing::Test
|
|
{
|
|
protected:
|
|
void SetUp() override
|
|
{
|
|
// Create a temporary directory for testing
|
|
testDir = std::filesystem::temp_directory_path() / "webserv_test";
|
|
std::filesystem::create_directories(testDir);
|
|
|
|
// Create a test file
|
|
testFile = testDir / "test.txt";
|
|
std::ofstream file(testFile);
|
|
file << "Hello, World!\nThis is a test file.\n";
|
|
file.close();
|
|
|
|
// Create a test HTML file
|
|
htmlFile = testDir / "index.html";
|
|
std::ofstream htmlOut(htmlFile);
|
|
htmlOut << "<!DOCTYPE html>\n<html><body><h1>Test</h1></body></html>";
|
|
htmlOut.close();
|
|
}
|
|
|
|
void TearDown() override
|
|
{
|
|
// Clean up the test directory
|
|
if (std::filesystem::exists(testDir)) {
|
|
std::filesystem::remove_all(testDir);
|
|
}
|
|
}
|
|
|
|
public:
|
|
std::filesystem::path testDir;
|
|
std::filesystem::path testFile;
|
|
std::filesystem::path htmlFile;
|
|
};
|
|
|
|
TEST_F(FileUtilsTest, FileExists)
|
|
{
|
|
// Test if FileUtils can check file existence
|
|
// This depends on the actual implementation
|
|
EXPECT_TRUE(std::filesystem::exists(testFile));
|
|
EXPECT_FALSE(std::filesystem::exists(testDir / "nonexistent.txt"));
|
|
}
|
|
|
|
TEST_F(FileUtilsTest, ReadFileContent)
|
|
{
|
|
// Test reading file content
|
|
// This depends on what methods FileUtils provides
|
|
SUCCEED(); // Placeholder until we see the actual FileUtils API
|
|
}
|
|
|
|
TEST_F(FileUtilsTest, GetFileExtension)
|
|
{
|
|
// Test getting file extensions
|
|
// This depends on the actual implementation
|
|
SUCCEED(); // Placeholder
|
|
}
|
|
|
|
TEST_F(FileUtilsTest, IsValidPath)
|
|
{
|
|
// Test path validation
|
|
// This depends on the actual implementation
|
|
SUCCEED(); // Placeholder
|
|
}
|