From 21315ce803a32480190e2c0126ff9d1bf3247c0f Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Tue, 10 Nov 2015 19:46:57 -0500 Subject: [PATCH] forgot to revert test helpers --- tests/helpers/helper.hpp | 24 +++++++------- tests/helpers/path_helper.hpp | 45 +++++++++++++-------------- tests/helpers/temporary_directory.hpp | 8 ++--- tests/helpers/temporary_file.hpp | 12 +++---- 4 files changed, 44 insertions(+), 45 deletions(-) diff --git a/tests/helpers/helper.hpp b/tests/helpers/helper.hpp index 636bea08..661ac789 100644 --- a/tests/helpers/helper.hpp +++ b/tests/helpers/helper.hpp @@ -26,8 +26,8 @@ public: struct comparison_result { difference_type difference; - xlnt::string value_left; - xlnt::string value_right; + std::string value_left; + std::string value_right; operator bool() const { return difference == difference_type::equivalent; } }; @@ -36,40 +36,40 @@ public: return compare_xml(expected.get_root(), observed.get_root()); } - static comparison_result compare_xml(const xlnt::string &expected, const xlnt::xml_document &observed) + static comparison_result compare_xml(const std::string &expected, const xlnt::xml_document &observed) { - xlnt::string expected_contents = expected; + std::string expected_contents = expected; if(PathHelper::FileExists(expected)) { - std::ifstream f(expected.data()); + std::ifstream f(expected); std::ostringstream s; f >> s.rdbuf(); - expected_contents = s.str().c_str(); + expected_contents = s.str(); } xlnt::xml_document expected_xml; - expected_xml.from_string(expected_contents.data()); + expected_xml.from_string(expected_contents); return compare_xml(expected_xml.get_root(), observed.get_root()); } - static comparison_result compare_xml(const xlnt::string &left_contents, const xlnt::string &right_contents) + static comparison_result compare_xml(const std::string &left_contents, const std::string &right_contents) { xlnt::xml_document left_xml; - left_xml.from_string(left_contents.data()); + left_xml.from_string(left_contents); xlnt::xml_document right_xml; - right_xml.from_string(right_contents.data()); + right_xml.from_string(right_contents); return compare_xml(left_xml.get_root(), right_xml.get_root()); } static comparison_result compare_xml(const xlnt::xml_node &left, const xlnt::xml_node &right) { - xlnt::string left_temp = left.get_name(); - xlnt::string right_temp = right.get_name(); + std::string left_temp = left.get_name(); + std::string right_temp = right.get_name(); if(left_temp != right_temp) { diff --git a/tests/helpers/path_helper.hpp b/tests/helpers/path_helper.hpp index 277ac9e2..f52ce6e7 100644 --- a/tests/helpers/path_helper.hpp +++ b/tests/helpers/path_helper.hpp @@ -22,37 +22,37 @@ class PathHelper { public: - static xlnt::string read_file(const xlnt::string &filename) + static std::string read_file(const std::string &filename) { - std::ifstream f(filename.data()); + std::ifstream f(filename); std::ostringstream ss; ss << f.rdbuf(); - return ss.str().c_str(); + return ss.str(); } - static xlnt::string WindowsToUniversalPath(const xlnt::string &windows_path) + static std::string WindowsToUniversalPath(const std::string &windows_path) { - xlnt::string fixed; - std::stringstream ss(windows_path.data()); + std::string fixed; + std::stringstream ss(windows_path); std::string part; while(std::getline(ss, part, '\\')) { if(fixed == "") { - fixed = part.c_str(); + fixed = part; } else { - fixed += "/" + xlnt::string(part.c_str()); + fixed += "/" + part; } } return fixed; } - static xlnt::string GetExecutableDirectory() + static std::string GetExecutableDirectory() { #ifdef __APPLE__ @@ -62,7 +62,7 @@ public: if (_NSGetExecutablePath(path.data(), &size) == 0) { - return xlnt::string(path.begin(), std::find(path.begin(), path.end(), '\0') - 9); + return std::string(path.begin(), std::find(path.begin(), path.end(), '\0') - 9); } throw std::runtime_error("buffer too small, " + std::to_string(path.size()) + ", should be: " + std::to_string(size)); @@ -76,7 +76,7 @@ public: { throw std::runtime_error("GetModuleFileName failed or buffer was too small"); } - return WindowsToUniversalPath(xlnt::string(buffer.begin(), buffer.begin() + result - 13)) + "/"; + return WindowsToUniversalPath(std::string(buffer.begin(), buffer.begin() + result - 13)) + "/"; #else char arg1[20]; @@ -84,40 +84,39 @@ public: sprintf(arg1, "/proc/%d/exe", getpid()); readlink(arg1, exepath, 1024); - - return xlnt::string(exepath).substr(0, std::strlen(exepath) - 9); + return std::string(exepath).substr(0, std::strlen(exepath) - 9); #endif } - static xlnt::string GetDataDirectory(const xlnt::string &append = "") + static std::string GetDataDirectory(const std::string &append = "") { return GetExecutableDirectory() + "../tests/data" + append; } - static void CopyFile(const xlnt::string &source, const xlnt::string &destination, bool overwrite) + static void CopyFile(const std::string &source, const std::string &destination, bool overwrite) { if(!overwrite && FileExists(destination)) { throw std::runtime_error("destination file already exists and overwrite==false"); } - std::ifstream src(source.data(), std::ios::binary); - std::ofstream dst(destination.data(), std::ios::binary); + std::ifstream src(source, std::ios::binary); + std::ofstream dst(destination, std::ios::binary); dst << src.rdbuf(); } - static void DeleteFile(const xlnt::string &path) + static void DeleteFile(const std::string &path) { - std::remove(path.data()); + std::remove(path.c_str()); } - static bool FileExists(const xlnt::string &path) + static bool FileExists(const std::string &path) { #ifdef _MSC_VER - std::string path_stdstring = path.data(); - std::wstring path_wide(path_stdstring.begin(), path_stdstring.end()); + + std::wstring path_wide(path.begin(), path.end()); return PathFileExists(path_wide.c_str()) && !PathIsDirectory(path_wide.c_str()); #else @@ -126,7 +125,7 @@ public: { struct stat fileAtt; - if (stat(path.data(), &fileAtt) == 0) + if (stat(path.c_str(), &fileAtt) == 0) { return S_ISREG(fileAtt.st_mode); } diff --git a/tests/helpers/temporary_directory.hpp b/tests/helpers/temporary_directory.hpp index 06249c21..9d9a91d6 100644 --- a/tests/helpers/temporary_directory.hpp +++ b/tests/helpers/temporary_directory.hpp @@ -11,7 +11,7 @@ class TemporaryDirectory { public: - static xlnt::string CreateTemporaryFilename() + static std::string CreateTemporaryFilename() { #ifdef _WIN32 std::array buffer; @@ -24,7 +24,7 @@ public: { throw std::runtime_error("GetTempPath failed"); } - xlnt::string directory(buffer.begin(), buffer.begin() + result); + std::string directory(buffer.begin(), buffer.begin() + result); return PathHelper::WindowsToUniversalPath(directory + "xlnt"); #else return "/tmp/xlsx"; @@ -41,8 +41,8 @@ public: remove(filename_.c_str()); } - xlnt::string GetFilename() const { return filename_; } + std::string GetFilename() const { return filename_; } private: - const xlnt::string filename_; + const std::string filename_; }; diff --git a/tests/helpers/temporary_file.hpp b/tests/helpers/temporary_file.hpp index 92b315f8..35ce6781 100644 --- a/tests/helpers/temporary_file.hpp +++ b/tests/helpers/temporary_file.hpp @@ -10,7 +10,7 @@ class TemporaryFile { public: - static xlnt::string CreateTemporaryFilename() + static std::string CreateTemporaryFilename() { #ifdef _MSC_VER std::array buffer; @@ -26,7 +26,7 @@ public: throw std::runtime_error("GetTempPath failed"); } - xlnt::string directory(buffer.begin(), buffer.begin() + result); + std::string directory(buffer.begin(), buffer.begin() + result); return PathHelper::WindowsToUniversalPath(directory + "xlnt.xlsx"); #else @@ -38,17 +38,17 @@ public: { if(PathHelper::FileExists(GetFilename())) { - std::remove(filename_.data()); + std::remove(filename_.c_str()); } } ~TemporaryFile() { - std::remove(filename_.data()); + std::remove(filename_.c_str()); } - xlnt::string GetFilename() const { return filename_; } + std::string GetFilename() const { return filename_; } private: - const xlnt::string filename_; + const std::string filename_; };