mirror of
https://github.com/CDevJoud/Minecraft-Community-Edition.git
synced 2026-07-16 03:00:47 +00:00
FileInputStream
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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
1
Tests/TestFiles/test.txt
Normal file
@@ -0,0 +1 @@
|
||||
this is some data
|
||||
Reference in New Issue
Block a user