Browse Source

Tweaked the get file extention code. Also built out the rough structure for the rest of the file operations test code.

master
DomtronVox 1 year ago
parent
commit
0949cf6594
2 changed files with 39 additions and 1 deletions
  1. +7
    -1
      src/Configuration/FileOperations.h
  2. +32
    -0
      tests/test_FileOperations.cpp

+ 7
- 1
src/Configuration/FileOperations.h View File

@ -66,7 +66,13 @@ std::string cleanPath(std::string path) {
// @return: only grabs final extention, so test.tar.gz would return gz
std::string getFileExtention(std::string filepath) {
filepath = trimString(filepath);
return filepath.substr(filepath.find_last_of(".")+1);
std::size_t ext_pos = filepath.find_last_of(".");
//there is no extention if the find function returns npos
if (ext_pos == std::string::npos) { return ""; }
//otherwise return the ext string
return filepath.substr(ext_pos+1);
}


+ 32
- 0
tests/test_FileOperations.cpp View File

@ -3,6 +3,7 @@
#include "TestBase.h"
#include "Configuration/FileOperations.h"
#include <iostream>
int main (int argc, char* argv[]) {
@ -25,9 +26,40 @@ int main (int argc, char* argv[]) {
/*TEST_BEGIN( "Test cleanPath" );
ASSERT_THROW( cleanPath("/path/to/location") == "/path/to/location" );
std::cout << cleanPath("../../path") << std::endl;
ASSERT_THROW( cleanPath("../../path") == "/path" );
ASSERT_THROW( cleanPath("./path") == "/path" );
ASSERT_THROW( cleanPath("//path//to") == "/path/to" );
//TODO need to test windows style paths also
TEST_END();*/
TEST_BEGIN( "Test getFileExtention" );
ASSERT_THROW( getFileExtention("test.txt") == "txt" );
ASSERT_THROW( getFileExtention("test.md.txt") == "txt" );
ASSERT_THROW( getFileExtention("/path/to/place/test.md") == "md" );
ASSERT_THROW( getFileExtention("test") == "" );
ASSERT_THROW( getFileExtention("") == "" );
TEST_END();
TEST_BEGIN( "Test listDirectoryContents" );
ASSERT_THROW( false );
TEST_END();
/*TEST_BEGIN( "Test listAllFiles" );
ASSERT_THROW( false );
TEST_END();
TEST_BEGIN( "Test openFile" );
ASSERT_THROW( false );
TEST_END();
TEST_BEGIN( "Test writeToTextFile" );
ASSERT_THROW( true );
TEST_END();*/
return 0;


Loading…
Cancel
Save