FileInputStream

This commit is contained in:
BendedWills
2026-03-07 03:29:20 -06:00
parent 4cc532f5c9
commit 5b294712e2
8 changed files with 136 additions and 4 deletions

View File

@@ -9,5 +9,16 @@ function(DeclareTest name)
gtest_discover_tests(${name})
endfunction()
function(CopyFilesFor target)
add_custom_command(TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_LIST_DIR}/TestFiles
$<TARGET_FILE_DIR:${target}>/TestFiles
)
endfunction()
DeclareTest(InputStream)
DeclareTest(Logging)
CopyFilesFor(InputStream)

View File

@@ -1,5 +1,34 @@
#include <gtest/gtest.h>
TEST(InputStream, reading) {
#include "IO/Stream/FileInputStream.hpp"
using namespace mce;
TEST(InputStream, Reading) {
FileInputStream testStream("TestFiles/test.txt");
EXPECT_TRUE(testStream.isOpen());
EXPECT_FALSE(testStream.eof());
std::vector<char> fileContent(testStream.getSize() + 1, 0);
size_t bytesRead = testStream.read(fileContent.data(), testStream.getSize());
std::ifstream stream("TestFiles/test.txt");
std::string content;
while (std::getline(stream, content)) {}
EXPECT_EQ(content, fileContent.data());
EXPECT_EQ(bytesRead, content.size());
stream.close();
}
TEST(InputStream, ReadMoreThanFileHas) {
FileInputStream testStream("TestFiles/test.txt");
std::vector<char> fileContent(testStream.getSize() + 1, 0);
size_t bytesRead = testStream.read(fileContent.data(), testStream.getSize() + 2);
EXPECT_EQ(bytesRead, testStream.getSize());
}

1
Tests/TestFiles/test.txt Normal file
View File

@@ -0,0 +1 @@
this is some data