xlnt/tests/helpers/helper.hpp

62 lines
1.4 KiB
C++
Raw Normal View History

2014-06-05 06:42:17 +08:00
#pragma once
#include <sstream>
#include <pugixml.hpp>
2014-06-06 04:19:31 +08:00
#include "path_helper.hpp"
2014-06-05 06:42:17 +08:00
class Helper
{
public:
static bool EqualsFileContent(const std::string &reference_file, const std::string &fixture)
{
2014-07-17 07:53:45 +08:00
std::string fixture_content;
if(false)//PathHelper::FileExists(fixture))
{
std::fstream fixture_file;
fixture_file.open(fixture);
std::stringstream ss;
ss << fixture_file.rdbuf();
fixture_content = ss.str();
}
else
{
fixture_content = fixture;
}
std::string expected_content;
if(PathHelper::FileExists(reference_file))
{
std::fstream file;
file.open(reference_file);
std::stringstream ss;
ss << file.rdbuf();
expected_content = ss.str();
}
else
{
throw std::runtime_error("file not found");
}
2014-06-05 06:42:17 +08:00
{
2014-07-17 07:53:45 +08:00
pugi::xml_document doc;
doc.load(fixture_content.c_str());
std::stringstream ss;
doc.save(ss);
fixture_content = ss.str();
2014-06-05 06:42:17 +08:00
}
{
2014-07-17 07:53:45 +08:00
pugi::xml_document doc;
doc.load(expected_content.c_str());
std::stringstream ss;
doc.save(ss);
expected_content = ss.str();
2014-06-05 06:42:17 +08:00
}
2014-07-17 07:53:45 +08:00
return expected_content == fixture_content;
2014-06-05 06:42:17 +08:00
}
};