| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- /*
- * Author: Patrick-Christopher Mattulat
- * Co-Author: Claude Sonnet 4.6 (LLM)
- * Company: Lynar Studios
- * E-Mail: webmaster@lynarstudios.com
- * Created: 2020-08-17
- * Changed: 2026-06-23
- *
- * */
- #include <classes/TestHelper.hpp>
- #include <gtest/gtest.h>
- #include <ls-std/ls-std-core.hpp>
- #include <ls-std/ls-std-io.hpp>
- using ls::standard::core::FileNotFoundException;
- using ls::standard::io::File;
- using ls::standard::io::FileWriter;
- using ls::standard::test::TestHelper;
- using std::string;
- using testing::Test;
- namespace
- {
- class FileWriterTest : public Test
- {
- public:
- FileWriterTest() = default;
- ~FileWriterTest() override = default;
- };
- TEST_F(FileWriterTest, constructor_file_does_not_exist)
- {
- const string path = TestHelper::getResourcesFolderLocation() + "not-existing-file.txt";
- const File file{path};
- EXPECT_THROW(
- {
- try
- {
- FileWriter writer{file};
- }
- catch (const FileNotFoundException &_exception)
- {
- throw;
- }
- },
- FileNotFoundException);
- }
- TEST_F(FileWriterTest, reset)
- {
- string path = TestHelper::getResourcesFolderLocation() + "tmp-file-writer-test.txt";
- File file{path};
- file.createNewFile();
- FileWriter writer{file};
- ASSERT_TRUE(writer.write("Testing something!\n"));
- // reset
- path = TestHelper::getResourcesFolderLocation() + "tmp-file-writer-test2.txt";
- File anotherFile{path};
- anotherFile.createNewFile();
- writer.reset(anotherFile);
- ASSERT_TRUE(writer.write("Testing something else!\n"));
- // remove
- file.remove();
- ASSERT_FALSE(file.exists());
- anotherFile.remove();
- ASSERT_FALSE(anotherFile.exists());
- }
- TEST_F(FileWriterTest, write)
- {
- const string path = TestHelper::getResourcesFolderLocation() + "tmp-file-writer-test.txt";
- const File file{path};
- ASSERT_FALSE(file.exists());
- file.createNewFile();
- ASSERT_TRUE(file.exists());
- FileWriter writer{file};
- ASSERT_TRUE(writer.write("Testing something!\n"));
- file.remove();
- ASSERT_FALSE(file.exists());
- }
- }
|