Procházet zdrojové kódy

Extended File class

- added "reset" method to File class for setting a new
path
- extended tests for File class
patrickmattulat před 4 roky
rodič
revize
b36d4371a1
3 změnil soubory, kde provedl 16 přidání a 1 odebrání
  1. 5 0
      source/io/File.cpp
  2. 1 0
      source/io/File.hpp
  3. 10 1
      test/cases/io/FileTest.cpp

+ 5 - 0
source/io/File.cpp

@@ -200,6 +200,11 @@ bool ls_std::File::renameTo(const std::string &_newName)
   return renamed;
 }
 
+void ls_std::File::reset(const std::string &_newPath)
+{
+  this->absoluteFilePath = ls_std::File::_normalizePath(_newPath);
+}
+
 #ifdef _WIN32
 void ls_std::File::_addToFileListWindows(const std::string& _path, bool _withDirectories, WIN32_FIND_DATA _data, std::list<std::string>& _list)
 {

+ 1 - 0
source/io/File.hpp

@@ -57,6 +57,7 @@ namespace ls_std {
       void makeDirectories();
       void remove();
       bool renameTo(const std::string& _newName);
+      void reset(const std::string& _newPath);
 
     private:
 

+ 10 - 1
test/cases/io/FileTest.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-15
- * Changed:         2020-08-18
+ * Changed:         2020-08-19
  *
  * */
 
@@ -289,4 +289,13 @@ namespace {
 
     file.remove();
   }
+
+  TEST_F(FileTest, reset)
+  {
+    ls_std::File file {this->fileLocation};
+    ASSERT_TRUE(file.exists());
+
+    file.reset(TestHelper::getResourcesFolderLocation() + "list_test/hello.txt");
+    ASSERT_TRUE(file.exists());
+  }
 }