mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
forgot to revert test helpers
This commit is contained in:
parent
3e0c666263
commit
21315ce803
|
@ -26,8 +26,8 @@ public:
|
||||||
struct comparison_result
|
struct comparison_result
|
||||||
{
|
{
|
||||||
difference_type difference;
|
difference_type difference;
|
||||||
xlnt::string value_left;
|
std::string value_left;
|
||||||
xlnt::string value_right;
|
std::string value_right;
|
||||||
operator bool() const { return difference == difference_type::equivalent; }
|
operator bool() const { return difference == difference_type::equivalent; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -36,40 +36,40 @@ public:
|
||||||
return compare_xml(expected.get_root(), observed.get_root());
|
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))
|
if(PathHelper::FileExists(expected))
|
||||||
{
|
{
|
||||||
std::ifstream f(expected.data());
|
std::ifstream f(expected);
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
f >> s.rdbuf();
|
f >> s.rdbuf();
|
||||||
|
|
||||||
expected_contents = s.str().c_str();
|
expected_contents = s.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
xlnt::xml_document expected_xml;
|
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());
|
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;
|
xlnt::xml_document left_xml;
|
||||||
left_xml.from_string(left_contents.data());
|
left_xml.from_string(left_contents);
|
||||||
|
|
||||||
xlnt::xml_document right_xml;
|
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());
|
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)
|
static comparison_result compare_xml(const xlnt::xml_node &left, const xlnt::xml_node &right)
|
||||||
{
|
{
|
||||||
xlnt::string left_temp = left.get_name();
|
std::string left_temp = left.get_name();
|
||||||
xlnt::string right_temp = right.get_name();
|
std::string right_temp = right.get_name();
|
||||||
|
|
||||||
if(left_temp != right_temp)
|
if(left_temp != right_temp)
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,37 +22,37 @@
|
||||||
class PathHelper
|
class PathHelper
|
||||||
{
|
{
|
||||||
public:
|
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;
|
std::ostringstream ss;
|
||||||
ss << f.rdbuf();
|
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::string fixed;
|
||||||
std::stringstream ss(windows_path.data());
|
std::stringstream ss(windows_path);
|
||||||
std::string part;
|
std::string part;
|
||||||
|
|
||||||
while(std::getline(ss, part, '\\'))
|
while(std::getline(ss, part, '\\'))
|
||||||
{
|
{
|
||||||
if(fixed == "")
|
if(fixed == "")
|
||||||
{
|
{
|
||||||
fixed = part.c_str();
|
fixed = part;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fixed += "/" + xlnt::string(part.c_str());
|
fixed += "/" + part;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fixed;
|
return fixed;
|
||||||
}
|
}
|
||||||
|
|
||||||
static xlnt::string GetExecutableDirectory()
|
static std::string GetExecutableDirectory()
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
@ -62,7 +62,7 @@ public:
|
||||||
|
|
||||||
if (_NSGetExecutablePath(path.data(), &size) == 0)
|
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));
|
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");
|
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
|
#else
|
||||||
char arg1[20];
|
char arg1[20];
|
||||||
|
@ -84,40 +84,39 @@ public:
|
||||||
|
|
||||||
sprintf(arg1, "/proc/%d/exe", getpid());
|
sprintf(arg1, "/proc/%d/exe", getpid());
|
||||||
readlink(arg1, exepath, 1024);
|
readlink(arg1, exepath, 1024);
|
||||||
|
return std::string(exepath).substr(0, std::strlen(exepath) - 9);
|
||||||
return xlnt::string(exepath).substr(0, std::strlen(exepath) - 9);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static xlnt::string GetDataDirectory(const xlnt::string &append = "")
|
static std::string GetDataDirectory(const std::string &append = "")
|
||||||
{
|
{
|
||||||
return GetExecutableDirectory() + "../tests/data" + 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))
|
if(!overwrite && FileExists(destination))
|
||||||
{
|
{
|
||||||
throw std::runtime_error("destination file already exists and overwrite==false");
|
throw std::runtime_error("destination file already exists and overwrite==false");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ifstream src(source.data(), std::ios::binary);
|
std::ifstream src(source, std::ios::binary);
|
||||||
std::ofstream dst(destination.data(), std::ios::binary);
|
std::ofstream dst(destination, std::ios::binary);
|
||||||
|
|
||||||
dst << src.rdbuf();
|
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
|
#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());
|
return PathFileExists(path_wide.c_str()) && !PathIsDirectory(path_wide.c_str());
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
@ -126,7 +125,7 @@ public:
|
||||||
{
|
{
|
||||||
struct stat fileAtt;
|
struct stat fileAtt;
|
||||||
|
|
||||||
if (stat(path.data(), &fileAtt) == 0)
|
if (stat(path.c_str(), &fileAtt) == 0)
|
||||||
{
|
{
|
||||||
return S_ISREG(fileAtt.st_mode);
|
return S_ISREG(fileAtt.st_mode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
class TemporaryDirectory
|
class TemporaryDirectory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static xlnt::string CreateTemporaryFilename()
|
static std::string CreateTemporaryFilename()
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
std::array<TCHAR, MAX_PATH> buffer;
|
std::array<TCHAR, MAX_PATH> buffer;
|
||||||
|
@ -24,7 +24,7 @@ public:
|
||||||
{
|
{
|
||||||
throw std::runtime_error("GetTempPath failed");
|
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");
|
return PathHelper::WindowsToUniversalPath(directory + "xlnt");
|
||||||
#else
|
#else
|
||||||
return "/tmp/xlsx";
|
return "/tmp/xlsx";
|
||||||
|
@ -41,8 +41,8 @@ public:
|
||||||
remove(filename_.c_str());
|
remove(filename_.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
xlnt::string GetFilename() const { return filename_; }
|
std::string GetFilename() const { return filename_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const xlnt::string filename_;
|
const std::string filename_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
class TemporaryFile
|
class TemporaryFile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static xlnt::string CreateTemporaryFilename()
|
static std::string CreateTemporaryFilename()
|
||||||
{
|
{
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
std::array<TCHAR, MAX_PATH> buffer;
|
std::array<TCHAR, MAX_PATH> buffer;
|
||||||
|
@ -26,7 +26,7 @@ public:
|
||||||
throw std::runtime_error("GetTempPath failed");
|
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");
|
return PathHelper::WindowsToUniversalPath(directory + "xlnt.xlsx");
|
||||||
#else
|
#else
|
||||||
|
@ -38,17 +38,17 @@ public:
|
||||||
{
|
{
|
||||||
if(PathHelper::FileExists(GetFilename()))
|
if(PathHelper::FileExists(GetFilename()))
|
||||||
{
|
{
|
||||||
std::remove(filename_.data());
|
std::remove(filename_.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~TemporaryFile()
|
~TemporaryFile()
|
||||||
{
|
{
|
||||||
std::remove(filename_.data());
|
std::remove(filename_.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
xlnt::string GetFilename() const { return filename_; }
|
std::string GetFilename() const { return filename_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const xlnt::string filename_;
|
const std::string filename_;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user