فهرست منبع

Remove "io" module dependency from TestHelper class

Patrick-Christopher Mattulat 2 سال پیش
والد
کامیت
bafabe6d17

+ 1 - 1
.gitignore

@@ -3,4 +3,4 @@ cmake-build-debug
 cmake-build-release
 cmake-build-debug-coverage
 cmake-build-wsl_debug
-test/classes/io/xml/TestHelper.hpp
+test/TestHelper.hpp

+ 0 - 1
CMakeLists.txt

@@ -168,7 +168,6 @@ if (${LS_STD_BUILD_WITH_TESTS})
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/StandardOutputWriterTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/StorableFileTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/io/xml/TestDataFactory.cpp
-            ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/io/xml/TestHelper.hpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/io/xml/XmlParserTestWrapper.cpp)
 
     set(TEST_FILES_LOGIC

+ 2 - 2
test/TestDataFactory.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-16
- * Changed:         2022-05-11
+ * Changed:         2022-05-15
  *
  * */
 
@@ -14,7 +14,7 @@
 
 namespace ls_std_test
 {
-  class TestDataFactory
+  class TestDataFactory // TODO: remove class, after migrated to submodules
   {
     public:
 

+ 198 - 0
test/TestHelper.hpp

@@ -0,0 +1,198 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2020-08-15
+ * Changed:         2022-05-15
+ *
+ * */
+
+#ifndef LS_STD_IO_TEST_HELPER_HPP
+#define LS_STD_IO_TEST_HELPER_HPP
+
+#include <string>
+#include <vector>
+#include <stdexcept>
+#include <algorithm>
+#include <sstream>
+#include <climits>
+#include <unistd.h>
+
+namespace ls_std_test
+{
+  class TestHelper
+  {
+    public:
+
+      TestHelper() = default;
+      ~TestHelper() = default;
+
+      static std::string getResourcesFolderLocation()
+      {
+        return TestHelper::getTestFolderLocation() + "resources" + ls_std_test::TestHelper::_getFilePathSeparator();
+      }
+
+      static std::string getTestFolderLocation()
+      {
+        ::std::string buildDirectory = ls_std_test::TestHelper::_getWorkingDirectory();
+        buildDirectory = ls_std_test::TestHelper::_normalizePath(buildDirectory);
+
+        return ls_std_test::TestHelper::_getParent(buildDirectory) + "test" + ls_std_test::TestHelper::_getFilePathSeparator();
+      }
+
+    private:
+
+      static char _getFilePathSeparator()
+      {
+        char separator;
+
+        #ifdef _WIN32
+        separator = '\\';
+        #endif
+        #if defined(unix) || defined(__APPLE__)
+        separator = '/';
+        #endif
+
+        return separator;
+      }
+
+      static std::string _getParent(const ::std::string &_path)
+      {
+        ::std::string parent{};
+        ::std::vector<::std::string> subDirectoryNames = ls_std_test::TestHelper::_splitIntoSubDirectoryNames(_path);
+        const char separator = ls_std_test::TestHelper::_getFilePathSeparator();
+        subDirectoryNames.pop_back();
+
+        for (auto const &subDirectoryName: subDirectoryNames)
+        {
+          parent += subDirectoryName + separator;
+        }
+
+        return parent;
+      }
+
+      static ::std::string _getWorkingDirectory()
+      {
+        ::std::string workingDirectory{};
+
+        #if defined(unix) || defined(__APPLE__)
+        workingDirectory = ls_std_test::TestHelper::_getWorkingDirectoryUnix();
+        #endif
+        #ifdef _WIN32
+        workingDirectory = ls_std_test::TestHelper::_getWorkingDirectoryWindows();
+        #endif
+
+        return workingDirectory;
+      }
+
+      #if defined(unix) || defined(__APPLE__)
+
+      static ::std::string _getWorkingDirectoryUnix()
+      {
+        ::std::string workingDirectory{};
+        char buffer[PATH_MAX];
+
+        if (getcwd(buffer, sizeof(buffer)) == nullptr)
+        {
+          throw ::std::runtime_error{"invalid file operation!"};
+        }
+        else
+        {
+          workingDirectory = ::std::string(buffer);
+        }
+
+        return workingDirectory;
+      }
+
+      #endif
+
+      #ifdef _WIN32
+
+      ::std::string _getWorkingDirectoryWindows()
+      {
+        ::std::string workingDirectory{};
+        TCHAR buffer[MAX_PATH];
+
+        if (!GetCurrentDirectory(MAX_PATH, buffer))
+        {
+          throw ::std::runtime_error{"invalid file operation!"};
+        }
+        else
+        {
+          workingDirectory = ::std::string(buffer);
+        }
+
+        return workingDirectory;
+      }
+
+      #endif
+
+      static ::std::string _normalizePath(::std::string _path)
+      {
+        _path = ls_std_test::TestHelper::_replaceWrongSeparator(_path);
+        _path = ls_std_test::TestHelper::_reduceSeparators(_path);
+
+        return _path;
+      }
+
+      static ::std::string _reduceSeparators(const ::std::string &_path)
+      {
+        static const char separator = {ls_std_test::TestHelper::_getFilePathSeparator()};
+        ::std::string normalizedPath{};
+        int index{};
+
+        while (index < _path.size())
+        {
+          if (_path[index] == separator)
+          {
+            normalizedPath += _path[index];
+
+            do
+            {
+              index++;
+            } while (_path[index] == separator);
+          }
+          else
+          {
+            normalizedPath += _path[index];
+            index++;
+          }
+        }
+
+        return normalizedPath;
+      }
+
+      static ::std::string _replaceWrongSeparator(::std::string _path)
+      {
+        static const char unixSeparator = '/';
+        static const char windowsSeparator = '\\';
+
+        #if defined(unix) || defined(__APPLE__)
+        ::std::replace(_path.begin(), _path.end(), windowsSeparator, unixSeparator);
+        #endif
+
+        #ifdef _WIN32
+        ::std::replace(_path.begin(), _path.end(), unixSeparator, windowsSeparator);
+        #endif
+
+        return _path;
+      }
+
+      static ::std::vector<::std::string> _splitIntoSubDirectoryNames(const ::std::string &_path)
+      {
+        ::std::vector<::std::string> subDirectoryNames{};
+        ::std::stringstream _stream{_path};
+        ::std::string subDirectoryName{};
+        const char separator = ls_std_test::TestHelper::_getFilePathSeparator();
+
+        while (::std::getline(_stream, subDirectoryName, separator))
+        {
+          subDirectoryNames.push_back(subDirectoryName);
+        }
+
+        return subDirectoryNames;
+      }
+  };
+}
+
+#endif

+ 6 - 6
test/cases/io/FileOutputStreamTest.cpp

@@ -8,9 +8,9 @@
  * */
 
 #include <gtest/gtest.h>
-#include <ls_std_io_test.hpp>
 #include <ls_std/ls_std_core.hpp>
 #include <ls_std/ls_std_io.hpp>
+#include "TestHelper.hpp"
 
 namespace
 {
@@ -30,7 +30,7 @@ namespace
 
   TEST_F(FileOutputStreamTest, constructor_file_does_not_exist)
   {
-    std::string path = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "not_existing.txt";
+    std::string path = ls_std_test::TestHelper::getResourcesFolderLocation() + "not_existing.txt";
     ls::std::io::File file{path};
 
     EXPECT_THROW({
@@ -47,7 +47,7 @@ namespace
 
   TEST_F(FileOutputStreamTest, write)
   {
-    std::string path = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "tmp_output_stream.txt";
+    std::string path = ls_std_test::TestHelper::getResourcesFolderLocation() + "tmp_output_stream.txt";
     ls::std::io::File file{path};
     file.createNewFile();
     ASSERT_TRUE(file.exists());
@@ -63,7 +63,7 @@ namespace
 
   TEST_F(FileOutputStreamTest, write_with_another_appending_stream)
   {
-    std::string path = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "tmp_output_stream.txt";
+    std::string path = ls_std_test::TestHelper::getResourcesFolderLocation() + "tmp_output_stream.txt";
     ls::std::io::File file{path};
     file.createNewFile();
     ASSERT_TRUE(file.exists());
@@ -92,10 +92,10 @@ namespace
   TEST_F(FileOutputStreamTest, write_no_permission_to_write)
   {
     #if defined(unix) || defined(__APPLE__)
-    ls::std::io::File file{ls_std_io_test::TestHelper::getResourcesFolderLocation() + "no_writable.txt"};
+    ls::std::io::File file{ls_std_test::TestHelper::getResourcesFolderLocation() + "no_writable.txt"};
     #endif
     #ifdef _WIN32
-    ls::std::io::File file{ls_std_io_test::TestHelper::getResourcesFolderLocation() + "no_writable_windows.txt"};
+    ls::std::io::File file{ls_std_test::TestHelper::getResourcesFolderLocation() + "no_writable_windows.txt"};
     #endif
 
     ls::std::io::FileOutputStream outputStream{file};

+ 7 - 7
test/cases/io/FileReaderTest.cpp

@@ -3,14 +3,14 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-18
- * Changed:         2022-05-14
+ * Changed:         2022-05-15
  *
  * */
 
 #include <gtest/gtest.h>
-#include <ls_std_io_test.hpp>
 #include <ls_std/ls_std_core.hpp>
 #include <ls_std/ls_std_io.hpp>
+#include "TestHelper.hpp"
 
 namespace
 {
@@ -30,7 +30,7 @@ namespace
 
   TEST_F(FileReaderTest, constructor_file_does_not_exist)
   {
-    ls::std::io::File file{ls_std_io_test::TestHelper::getResourcesFolderLocation() + "does_not_exist.txt"};
+    ls::std::io::File file{ls_std_test::TestHelper::getResourcesFolderLocation() + "does_not_exist.txt"};
 
     EXPECT_THROW({
                    try
@@ -46,7 +46,7 @@ namespace
 
   TEST_F(FileReaderTest, read)
   {
-    ls::std::io::File file{ls_std_io_test::TestHelper::getResourcesFolderLocation() + "simple.txt"};
+    ls::std::io::File file{ls_std_test::TestHelper::getResourcesFolderLocation() + "simple.txt"};
     ls::std::io::FileReader reader{file};
     std::string expectedUnix = "Hello!" + ls::std::io::NewLine::getUnixNewLine();
     std::string expectedWindows = "Hello!" + ls::std::io::NewLine::getWindowsNewLine();
@@ -57,7 +57,7 @@ namespace
 
   TEST_F(FileReaderTest, read_file_gets_lost_in_between)
   {
-    ls::std::io::File file{ls_std_io_test::TestHelper::getResourcesFolderLocation() + "lost_readable_file.txt"};
+    ls::std::io::File file{ls_std_test::TestHelper::getResourcesFolderLocation() + "lost_readable_file.txt"};
     file.createNewFile();
     ls::std::io::FileReader reader{file};
     file.remove();
@@ -76,7 +76,7 @@ namespace
 
   TEST_F(FileReaderTest, reset)
   {
-    ls::std::io::File file{ls_std_io_test::TestHelper::getResourcesFolderLocation() + "simple.txt"};
+    ls::std::io::File file{ls_std_test::TestHelper::getResourcesFolderLocation() + "simple.txt"};
     ls::std::io::FileReader reader{file};
     std::string expectedUnix = "Hello!" + ls::std::io::NewLine::getUnixNewLine();
     std::string expectedWindows = "Hello!" + ls::std::io::NewLine::getWindowsNewLine();
@@ -84,7 +84,7 @@ namespace
     ls::std::core::type::byte_field content = reader.read();
     ASSERT_TRUE(content == expectedUnix || content == expectedWindows);
 
-    ls::std::io::File anotherFile{ls_std_io_test::TestHelper::getResourcesFolderLocation() + "list_test/bla.txt"};
+    ls::std::io::File anotherFile{ls_std_test::TestHelper::getResourcesFolderLocation() + "list_test/bla.txt"};
     reader.reset(anotherFile);
     expectedUnix = "nothing to say!" + ls::std::io::NewLine::getUnixNewLine();
     expectedWindows = "nothing to say!" + ls::std::io::NewLine::getWindowsNewLine();

+ 30 - 30
test/cases/io/FileTest.cpp

@@ -3,14 +3,14 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-15
- * Changed:         2022-05-14
+ * Changed:         2022-05-15
  *
  * */
 
 #include <gtest/gtest.h>
-#include <ls_std_io_test.hpp>
 #include <ls_std/ls_std_core.hpp>
 #include <ls_std/ls_std_io.hpp>
+#include "TestHelper.hpp"
 
 namespace
 {
@@ -21,7 +21,7 @@ namespace
       FileTest() = default;
       ~FileTest() override = default;
 
-      std::string fileLocation = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "simple.txt";
+      std::string fileLocation = ls_std_test::TestHelper::getResourcesFolderLocation() + "simple.txt";
 
       void SetUp() override
       {}
@@ -48,7 +48,7 @@ namespace
   TEST_F(FileTest, operator_not_equals)
   {
     ls::std::io::File file{this->fileLocation};
-    ls::std::io::File file2{ls_std_io_test::TestHelper::getResourcesFolderLocation() + "app.exe"};
+    ls::std::io::File file2{ls_std_test::TestHelper::getResourcesFolderLocation() + "app.exe"};
 
     ASSERT_TRUE(file != file2);
     ASSERT_TRUE(file2 != file);
@@ -59,10 +59,10 @@ namespace
   TEST_F(FileTest, canExecute)
   {
     #ifdef _WIN32
-    ls::std::io::File executableFile{ls_std_io_test::TestHelper::getResourcesFolderLocation() + "app.exe"};
+    ls::std::io::File executableFile{ls_std_test::TestHelper::getResourcesFolderLocation() + "app.exe"};
     #endif
     #if defined(unix) || defined(__APPLE__)
-    ls::std::io::File executableFile{ls_std_io_test::TestHelper::getResourcesFolderLocation() + "app"};
+    ls::std::io::File executableFile{ls_std_test::TestHelper::getResourcesFolderLocation() + "app"};
     #endif
 
     ASSERT_TRUE(executableFile.canExecute());
@@ -105,18 +105,18 @@ namespace
   TEST_F(FileTest, canWrite_not_writable)
   {
     #if defined(unix) || defined(__APPLE__)
-    ls::std::io::File noWritableFile{ls_std_io_test::TestHelper::getResourcesFolderLocation() + "no_writable.txt"};
+    ls::std::io::File noWritableFile{ls_std_test::TestHelper::getResourcesFolderLocation() + "no_writable.txt"};
     ASSERT_FALSE(noWritableFile.canWrite());
     #endif
     #ifdef _WIN32
-    ls::std::io::File noWritableFile{ls_std_io_test::TestHelper::getResourcesFolderLocation() + "no_writable_windows.txt"};
+    ls::std::io::File noWritableFile{ls_std_test::TestHelper::getResourcesFolderLocation() + "no_writable_windows.txt"};
     ASSERT_FALSE(noWritableFile.canWrite());
     #endif
   }
 
   TEST_F(FileTest, createNewFile)
   {
-    ls::std::io::File file{ls_std_io_test::TestHelper::getResourcesFolderLocation() + "tmp.txt"};
+    ls::std::io::File file{ls_std_test::TestHelper::getResourcesFolderLocation() + "tmp.txt"};
     ASSERT_FALSE(file.exists());
 
     file.createNewFile();
@@ -128,7 +128,7 @@ namespace
 
   TEST_F(FileTest, createNewFile_file_does_already_exist)
   {
-    ls::std::io::File file{ls_std_io_test::TestHelper::getResourcesFolderLocation() + "simple.txt"};
+    ls::std::io::File file{ls_std_test::TestHelper::getResourcesFolderLocation() + "simple.txt"};
 
     EXPECT_THROW({
                    try
@@ -145,7 +145,7 @@ namespace
   TEST_F(FileTest, exists)
   {
     ls::std::io::File file{this->fileLocation};
-    ls::std::io::File directory{ls_std_io_test::TestHelper::getResourcesFolderLocation()};
+    ls::std::io::File directory{ls_std_test::TestHelper::getResourcesFolderLocation()};
 
     ASSERT_TRUE(file.exists());
     ASSERT_TRUE(directory.exists());
@@ -153,7 +153,7 @@ namespace
 
   TEST_F(FileTest, exists_does_not_exist)
   {
-    ls::std::io::File file{ls_std_io_test::TestHelper::getResourcesFolderLocation() + "bla.txt"};
+    ls::std::io::File file{ls_std_test::TestHelper::getResourcesFolderLocation() + "bla.txt"};
     ASSERT_FALSE(file.exists());
   }
 
@@ -172,9 +172,9 @@ namespace
   TEST_F(FileTest, getName)
   {
     ls::std::io::File file{this->fileLocation};
-    ls::std::io::File executableFile{ls_std_io_test::TestHelper::getResourcesFolderLocation() + "app.exe"};
+    ls::std::io::File executableFile{ls_std_test::TestHelper::getResourcesFolderLocation() + "app.exe"};
     ls::std::io::File anotherFile{"bla.txt"};
-    ls::std::io::File directory{ls_std_io_test::TestHelper::getResourcesFolderLocation()};
+    ls::std::io::File directory{ls_std_test::TestHelper::getResourcesFolderLocation()};
 
     ASSERT_STREQ("simple.txt", file.getName().c_str());
     ASSERT_STREQ("app.exe", executableFile.getName().c_str());
@@ -185,7 +185,7 @@ namespace
   TEST_F(FileTest, getParent)
   {
     ls::std::io::File file{this->fileLocation};
-    ASSERT_STREQ(ls_std_io_test::TestHelper::getResourcesFolderLocation().c_str(), file.getParent().c_str());
+    ASSERT_STREQ(ls_std_test::TestHelper::getResourcesFolderLocation().c_str(), file.getParent().c_str());
   }
 
   TEST_F(FileTest, getWorkingDirectory)
@@ -204,7 +204,7 @@ namespace
 
   TEST_F(FileTest, isDirectory)
   {
-    ls::std::io::File directory{ls_std_io_test::TestHelper::getResourcesFolderLocation()};
+    ls::std::io::File directory{ls_std_test::TestHelper::getResourcesFolderLocation()};
     ASSERT_TRUE(directory.isDirectory());
   }
 
@@ -221,13 +221,13 @@ namespace
     ls::std::io::File file{this->fileLocation};
     ASSERT_TRUE(file.isFile());
 
-    ls::std::io::File file2{ls_std_io_test::TestHelper::getResourcesFolderLocation() + "list_test" + separator + "bla.txt"};
+    ls::std::io::File file2{ls_std_test::TestHelper::getResourcesFolderLocation() + "list_test" + separator + "bla.txt"};
     ASSERT_TRUE(file2.isFile());
   }
 
   TEST_F(FileTest, isFile_is_a_directory)
   {
-    ls::std::io::File directory{ls_std_io_test::TestHelper::getResourcesFolderLocation()};
+    ls::std::io::File directory{ls_std_test::TestHelper::getResourcesFolderLocation()};
     ASSERT_FALSE(directory.isFile());
   }
 
@@ -239,7 +239,7 @@ namespace
 
   TEST_F(FileTest, list)
   {
-    ls::std::io::File file{ls_std_io_test::TestHelper::getResourcesFolderLocation() + "list_test"};
+    ls::std::io::File file{ls_std_test::TestHelper::getResourcesFolderLocation() + "list_test"};
     std::list<std::string> filesInDirectory = file.list();
     std::string expectedFile{};
     const char separator = ls::std::io::FilePathSeparator::get();
@@ -267,7 +267,7 @@ namespace
 
   TEST_F(FileTest, listFiles)
   {
-    ls::std::io::File file{ls_std_io_test::TestHelper::getResourcesFolderLocation() + "list_test"};
+    ls::std::io::File file{ls_std_test::TestHelper::getResourcesFolderLocation() + "list_test"};
     std::list<std::string> filesInDirectory = file.listFiles();
     std::string expectedFile{};
     const char separator = ls::std::io::FilePathSeparator::get();
@@ -287,7 +287,7 @@ namespace
 
   TEST_F(FileTest, makeDirectory)
   {
-    ls::std::io::File directory{ls_std_io_test::TestHelper::getResourcesFolderLocation() + "testDir"};
+    ls::std::io::File directory{ls_std_test::TestHelper::getResourcesFolderLocation() + "testDir"};
     ASSERT_FALSE(directory.exists());
 
     directory.makeDirectory();
@@ -299,7 +299,7 @@ namespace
 
   TEST_F(FileTest, makeDirectory_directory_already_exists)
   {
-    ls::std::io::File directory{ls_std_io_test::TestHelper::getResourcesFolderLocation() + "list_test"};
+    ls::std::io::File directory{ls_std_test::TestHelper::getResourcesFolderLocation() + "list_test"};
 
     EXPECT_THROW({
                    try
@@ -315,7 +315,7 @@ namespace
 
   TEST_F(FileTest, makeDirectories)
   {
-    ls::std::io::File directory{ls_std_io_test::TestHelper::getResourcesFolderLocation() + "testDir/sub/tmp/bla"};
+    ls::std::io::File directory{ls_std_test::TestHelper::getResourcesFolderLocation() + "testDir/sub/tmp/bla"};
     ASSERT_FALSE(directory.exists());
 
     directory.makeDirectories();
@@ -324,17 +324,17 @@ namespace
     // clean up
 
     directory.remove();
-    directory = ls::std::io::File(ls_std_io_test::TestHelper::getResourcesFolderLocation() + "testDir/sub/tmp");
+    directory = ls::std::io::File(ls_std_test::TestHelper::getResourcesFolderLocation() + "testDir/sub/tmp");
     directory.remove();
-    directory = ls::std::io::File(ls_std_io_test::TestHelper::getResourcesFolderLocation() + "testDir/sub");
+    directory = ls::std::io::File(ls_std_test::TestHelper::getResourcesFolderLocation() + "testDir/sub");
     directory.remove();
-    directory = ls::std::io::File(ls_std_io_test::TestHelper::getResourcesFolderLocation() + "testDir");
+    directory = ls::std::io::File(ls_std_test::TestHelper::getResourcesFolderLocation() + "testDir");
     directory.remove();
   }
 
   TEST_F(FileTest, remove)
   {
-    std::string fileName = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "removable_file.txt";
+    std::string fileName = ls_std_test::TestHelper::getResourcesFolderLocation() + "removable_file.txt";
     ls::std::io::File file{fileName};
     file.createNewFile();
 
@@ -346,8 +346,8 @@ namespace
 
   TEST_F(FileTest, renameTo)
   {
-    std::string currentName = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "tmp_rename_to.txt";
-    std::string newName = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "tmp_rename_to_better_name.txt";
+    std::string currentName = ls_std_test::TestHelper::getResourcesFolderLocation() + "tmp_rename_to.txt";
+    std::string newName = ls_std_test::TestHelper::getResourcesFolderLocation() + "tmp_rename_to_better_name.txt";
 
     ls::std::io::File file{currentName};
     file.createNewFile();
@@ -367,7 +367,7 @@ namespace
     ls::std::io::File file{this->fileLocation};
     ASSERT_TRUE(file.exists());
 
-    file.reset(ls_std_io_test::TestHelper::getResourcesFolderLocation() + "list_test/hello.txt");
+    file.reset(ls_std_test::TestHelper::getResourcesFolderLocation() + "list_test/hello.txt");
     ASSERT_TRUE(file.exists());
   }
 }

+ 6 - 6
test/cases/io/FileWriterTest.cpp

@@ -3,14 +3,14 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-17
- * Changed:         2022-05-14
+ * Changed:         2022-05-15
  *
  * */
 
 #include <gtest/gtest.h>
 #include <ls_std/ls_std_core.hpp>
 #include <ls_std/ls_std_io.hpp>
-#include <ls_std_io_test.hpp>
+#include "TestHelper.hpp"
 
 namespace
 {
@@ -30,7 +30,7 @@ namespace
 
   TEST_F(FileWriterTest, constructor_file_does_not_exist)
   {
-    std::string path = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "not_existing_file.txt";
+    std::string path = ls_std_test::TestHelper::getResourcesFolderLocation() + "not_existing_file.txt";
     ls::std::io::File file{path};
 
     EXPECT_THROW({
@@ -47,7 +47,7 @@ namespace
 
   TEST_F(FileWriterTest, reset)
   {
-    std::string path = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "tmp_file_writer_test.txt";
+    std::string path = ls_std_test::TestHelper::getResourcesFolderLocation() + "tmp_file_writer_test.txt";
     ls::std::io::File file{path};
     file.createNewFile();
     ls::std::io::FileWriter writer{file};
@@ -55,7 +55,7 @@ namespace
 
     // reset
 
-    path = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "tmp_file_writer_test2.txt";
+    path = ls_std_test::TestHelper::getResourcesFolderLocation() + "tmp_file_writer_test2.txt";
     ls::std::io::File anotherFile{path};
     anotherFile.createNewFile();
 
@@ -72,7 +72,7 @@ namespace
 
   TEST_F(FileWriterTest, write)
   {
-    std::string path = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "tmp_file_writer_test.txt";
+    std::string path = ls_std_test::TestHelper::getResourcesFolderLocation() + "tmp_file_writer_test.txt";
     ls::std::io::File file{path};
 
     ASSERT_FALSE(file.exists());

+ 5 - 5
test/cases/io/StorableFileTest.cpp

@@ -3,13 +3,13 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-19
- * Changed:         2022-05-14
+ * Changed:         2022-05-15
  *
  * */
 
 #include <gtest/gtest.h>
-#include <ls_std_io_test.hpp>
 #include <ls_std/ls_std_io.hpp>
+#include "TestHelper.hpp"
 
 namespace
 {
@@ -20,7 +20,7 @@ namespace
       StorableFileTest() = default;
       ~StorableFileTest() override = default;
 
-      std::string fileLocation = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "simple.txt";
+      std::string fileLocation = ls_std_test::TestHelper::getResourcesFolderLocation() + "simple.txt";
 
       void SetUp() override
       {}
@@ -58,7 +58,7 @@ namespace
 
     // reset
 
-    std::string anotherFileLocation = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "list_test/bla.txt";
+    std::string anotherFileLocation = ls_std_test::TestHelper::getResourcesFolderLocation() + "list_test/bla.txt";
     storableFile.reset(anotherFileLocation);
     content = storableFile.load();
 
@@ -70,7 +70,7 @@ namespace
 
   TEST_F(StorableFileTest, save)
   {
-    std::string path = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "tmp_storable_file.txt";
+    std::string path = ls_std_test::TestHelper::getResourcesFolderLocation() + "tmp_storable_file.txt";
     ls::std::io::File file{path};
     file.createNewFile();
 

+ 4 - 4
test/cases/io/kv/KvFileReaderTest.cpp

@@ -3,14 +3,14 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-12-25
- * Changed:         2022-05-14
+ * Changed:         2022-05-15
  *
  * */
 
 #include <gtest/gtest.h>
 #include <ls_std/ls_std_core.hpp>
 #include <ls_std/ls_std_io.hpp>
-#include <ls_std_io_test.hpp>
+#include "TestHelper.hpp"
 
 namespace
 {
@@ -29,7 +29,7 @@ namespace
 
       static std::shared_ptr<ls::std::io::KvFileReader> createTestKVFileReader()
       {
-        std::string kvPath = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "server_settings.kv";
+        std::string kvPath = ls_std_test::TestHelper::getResourcesFolderLocation() + "server_settings.kv";
         std::shared_ptr<ls::std::io::KvDocument> document = std::make_shared<ls::std::io::KvDocument>();
 
         return std::make_shared<ls::std::io::KvFileReader>(document, kvPath);
@@ -41,7 +41,7 @@ namespace
     EXPECT_THROW({
                    try
                    {
-                     std::string kvPath = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "server_settings.kv";
+                     std::string kvPath = ls_std_test::TestHelper::getResourcesFolderLocation() + "server_settings.kv";
                      ls::std::io::KvFileReader reader = ls::std::io::KvFileReader(nullptr, kvPath);
                    }
                    catch (const ls::std::core::IllegalArgumentException &_exception)

+ 3 - 3
test/cases/io/logging/LoggerTest.cpp

@@ -10,7 +10,7 @@
 #include <gtest/gtest.h>
 #include <ls_std/ls_std_core.hpp>
 #include <ls_std/ls_std_io.hpp>
-#include <ls_std_io_test.hpp>
+#include "TestHelper.hpp"
 
 namespace
 {
@@ -29,7 +29,7 @@ namespace
 
       static std::shared_ptr<ls::std::core::IWriter> createFileLogger(const std::string &_logName)
       {
-        std::string path = ls_std_io_test::TestHelper::getResourcesFolderLocation() + _logName;
+        std::string path = ls_std_test::TestHelper::getResourcesFolderLocation() + _logName;
         ls::std::io::File file{path};
 
         if (!file.exists())
@@ -44,7 +44,7 @@ namespace
 
       static ::std::string getContentFromLogFile(const std::string &_logName)
       {
-        ls::std::io::File file{ls_std_io_test::TestHelper::getResourcesFolderLocation() + _logName};
+        ls::std::io::File file{ls_std_test::TestHelper::getResourcesFolderLocation() + _logName};
         ls::std::io::FileReader reader{file};
         ::std::string content{reader.read()};
         file.remove();

+ 5 - 5
test/cases/io/xml/XmlParserTest.cpp

@@ -3,14 +3,14 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-26
- * Changed:         2022-05-14
+ * Changed:         2022-05-15
  *
  * */
 
 #include <gtest/gtest.h>
 #include <ls_std/ls_std_core.hpp>
 #include <ls_std/ls_std_io.hpp>
-#include <ls_std_io_test.hpp>
+#include "TestHelper.hpp"
 
 namespace
 {
@@ -23,7 +23,7 @@ namespace
 
       static ls::std::core::type::byte_field readXmlStateMachine()
       {
-        std::string xmlPath = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
+        std::string xmlPath = ls_std_test::TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
         ls::std::io::File file{xmlPath};
         ls::std::core::type::byte_field data = ls::std::io::FileReader{file}.read();
 
@@ -222,7 +222,7 @@ namespace
 
   TEST_F(XmlParserTest, getDocument)
   {
-    std::string xmlPath = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
+    std::string xmlPath = ls_std_test::TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
     ls::std::io::XmlParser xmlParser{std::make_shared<ls::std::io::XmlDocument>()};
 
     ASSERT_TRUE(xmlParser.getDocument() != nullptr);
@@ -230,7 +230,7 @@ namespace
 
   TEST_F(XmlParserTest, setDocument)
   {
-    std::string xmlPath = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
+    std::string xmlPath = ls_std_test::TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
     std::shared_ptr<ls::std::io::XmlDocument> document = std::make_shared<ls::std::io::XmlDocument>();
     ls::std::io::XmlParser xmlParser{document};
     ASSERT_TRUE(xmlParser.getDocument() == document);

+ 8 - 8
test/cases/io/xml/XmlReaderTest.cpp

@@ -3,14 +3,14 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-10-10
- * Changed:         2022-05-14
+ * Changed:         2022-05-15
  *
  * */
 
 #include <gtest/gtest.h>
 #include <ls_std/ls_std_core.hpp>
 #include <ls_std/ls_std_io.hpp>
-#include <ls_std_io_test.hpp>
+#include "TestHelper.hpp"
 
 namespace
 {
@@ -30,7 +30,7 @@ namespace
 
   TEST_F(XmlReaderTest, read)
   {
-    std::string xmlPath = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
+    std::string xmlPath = ls_std_test::TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
     ls::std::io::XmlReader xmlReader{std::make_shared<ls::std::io::XmlDocument>(), xmlPath};
 
     ASSERT_TRUE(!xmlReader.read().empty());
@@ -38,7 +38,7 @@ namespace
 
   TEST_F(XmlReaderTest, getDocument)
   {
-    std::string xmlPath = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
+    std::string xmlPath = ls_std_test::TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
     ls::std::io::XmlReader xmlReader{std::make_shared<ls::std::io::XmlDocument>(), xmlPath};
 
     ASSERT_TRUE(xmlReader.getDocument() != nullptr);
@@ -46,7 +46,7 @@ namespace
 
   TEST_F(XmlReaderTest, setDocument)
   {
-    std::string xmlPath = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
+    std::string xmlPath = ls_std_test::TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
     std::shared_ptr<ls::std::io::XmlDocument> document = std::make_shared<ls::std::io::XmlDocument>();
     ls::std::io::XmlReader xmlReader{document, xmlPath};
     ASSERT_TRUE(xmlReader.getDocument() == document);
@@ -58,7 +58,7 @@ namespace
 
   TEST_F(XmlReaderTest, setDocument_no_reference)
   {
-    std::string xmlPath = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
+    std::string xmlPath = ls_std_test::TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
     std::shared_ptr<ls::std::io::XmlDocument> document = std::make_shared<ls::std::io::XmlDocument>();
     ls::std::io::XmlReader xmlReader{document, xmlPath};
 
@@ -76,7 +76,7 @@ namespace
 
   TEST_F(XmlReaderTest, setFile)
   {
-    std::string xmlPath = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
+    std::string xmlPath = ls_std_test::TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
     ls::std::io::XmlReader xmlReader{std::make_shared<ls::std::io::XmlDocument>(), xmlPath};
     ls::std::io::File xmlFile{xmlPath};
     xmlReader.setFile(xmlFile);
@@ -86,7 +86,7 @@ namespace
 
   TEST_F(XmlReaderTest, setFile_does_not_exist)
   {
-    std::string xmlPath = ls_std_io_test::TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
+    std::string xmlPath = ls_std_test::TestHelper::getResourcesFolderLocation() + "state_machine_test.xml";
     ls::std::io::XmlReader xmlReader{std::make_shared<ls::std::io::XmlDocument>(), xmlPath};
     ls::std::io::File xmlFile{xmlPath};
 

+ 3 - 3
test/cases/logic/serialization/SerializableJsonStateMachineTest.cpp

@@ -10,7 +10,7 @@
 #include <gtest/gtest.h>
 #include <ls_std/ls_std.hpp>
 #include <TestDataFactory.hpp>
-#include "classes/io/xml/TestHelper.hpp"
+#include "TestHelper.hpp"
 
 namespace
 {
@@ -54,7 +54,7 @@ namespace
     std::string jsonString = serializable.marshal();
     ASSERT_TRUE(!jsonString.empty());
 
-    ls::std::io::File file{ls_std_io_test::TestHelper::getResourcesFolderLocation() + "/state_machine_test.json"};
+    ls::std::io::File file{ls_std_test::TestHelper::getResourcesFolderLocation() + "/state_machine_test.json"};
     ls::std::io::FileReader reader{file};
     ls::std::boxing::String data{reader.read()};
 
@@ -63,7 +63,7 @@ namespace
 
   TEST_F(SerializableJsonStateMachineTest, unmarshal)
   {
-    ls::std::io::File file{ls_std_io_test::TestHelper::getResourcesFolderLocation() + "/state_machine_test.json"};
+    ls::std::io::File file{ls_std_test::TestHelper::getResourcesFolderLocation() + "/state_machine_test.json"};
     ls::std::io::FileReader reader{file};
     std::shared_ptr<ls::std::logic::StateMachine> machine = std::make_shared<ls::std::logic::StateMachine>("bla");
     ls::std::logic::SerializableJsonStateMachine serializable{machine};

+ 0 - 38
test/classes/io/xml/TestHelper.hpp

@@ -1,38 +0,0 @@
-/*
- * Author:          Patrick-Christopher Mattulat
- * Company:         Lynar Studios
- * E-Mail:          webmaster@lynarstudios.com
- * Created:         2020-08-15
- * Changed:         2022-05-14
- *
- * */
-
-#ifndef LS_STD_IO_TEST_HELPER_HPP
-#define LS_STD_IO_TEST_HELPER_HPP
-
-#include <string>
-#include <ls_std/ls_std_io.hpp>
-
-namespace ls_std_io_test
-{
-  class TestHelper
-  {
-    public:
-
-      TestHelper() = default;
-      ~TestHelper() = default;
-
-      static std::string getResourcesFolderLocation()
-      {
-        return TestHelper::getTestFolderLocation() + "resources" + ls::std::io::FilePathSeparator::get();
-      }
-
-      static std::string getTestFolderLocation()
-      {
-        ls::std::io::File buildDirectory{ls::std::io::File::getWorkingDirectory()};
-        return buildDirectory.getParent() + "test" + ls::std::io::FilePathSeparator::get();
-      }
-  };
-}
-
-#endif

+ 1 - 2
test/ls_std_io_test.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2022-05-14
- * Changed:         2022-05-14
+ * Changed:         2022-05-15
  *
  * */
 
@@ -11,7 +11,6 @@
 #define LS_STD_LS_STD_IO_TEST_HPP
 
 #include <classes/io/xml/TestDataFactory.hpp>
-#include <classes/io/xml/TestHelper.hpp>
 #include <classes/io/xml/XmlParserTestWrapper.hpp>
 
 #endif