mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
Add debug output for a relationship mismatch
This commit is contained in:
parent
53c193433f
commit
ec02121c15
|
@ -3,17 +3,17 @@
|
|||
#include <sstream>
|
||||
#include <unordered_set>
|
||||
|
||||
#include <xlnt/packaging/manifest.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
#include <detail/external/include_libstudxml.hpp>
|
||||
#include <detail/serialization/vector_streambuf.hpp>
|
||||
#include <detail/serialization/zstream.hpp>
|
||||
#include <xlnt/packaging/manifest.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
|
||||
class xml_helper
|
||||
{
|
||||
public:
|
||||
static bool compare_files(const std::string &left,
|
||||
const std::string &right, const std::string &content_type)
|
||||
const std::string &right, const std::string &content_type)
|
||||
{
|
||||
// content types are stored in unordered maps, too complicated to compare
|
||||
if (content_type == "[Content_Types].xml")
|
||||
|
@ -34,7 +34,7 @@ public:
|
|||
}
|
||||
|
||||
auto is_xml = (content_type.substr(0, 12) == "application/"
|
||||
&& content_type.substr(content_type.size() - 4) == "+xml")
|
||||
&& content_type.substr(content_type.size() - 4) == "+xml")
|
||||
|| content_type == "application/xml"
|
||||
|| content_type == "[Content_Types].xml"
|
||||
|| content_type == "application/vnd.openxmlformats-officedocument.vmlDrawing";
|
||||
|
@ -63,8 +63,7 @@ public:
|
|||
bool difference = false;
|
||||
auto right_iter = right_parser.begin();
|
||||
|
||||
auto is_whitespace = [](const std::string &v)
|
||||
{
|
||||
auto is_whitespace = [](const std::string &v) {
|
||||
return v.find_first_not_of("\n\r\t ") == std::string::npos;
|
||||
};
|
||||
|
||||
|
@ -198,26 +197,26 @@ public:
|
|||
++right_iter;
|
||||
}
|
||||
|
||||
if (difference && !suppress_debug_info)
|
||||
{
|
||||
std::cout << "documents don't match" << std::endl;
|
||||
if (difference && !suppress_debug_info)
|
||||
{
|
||||
std::cout << "documents don't match" << std::endl;
|
||||
|
||||
std::cout << "left:" << std::endl;
|
||||
std::cout << "left:" << std::endl;
|
||||
for (auto c : left)
|
||||
{
|
||||
std::cout << c << std::flush;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "right:" << std::endl;
|
||||
std::cout << "right:" << std::endl;
|
||||
for (auto c : right)
|
||||
{
|
||||
std::cout << c << std::flush;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
return !difference;
|
||||
return !difference;
|
||||
}
|
||||
|
||||
static bool compare_relationships(const xlnt::manifest &left,
|
||||
|
@ -271,27 +270,26 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool xlsx_archives_match(const std::vector<std::uint8_t> &left,
|
||||
static bool xlsx_archives_match(const std::vector<std::uint8_t> &left,
|
||||
const std::vector<std::uint8_t> &right)
|
||||
{
|
||||
{
|
||||
xlnt::detail::vector_istreambuf left_buffer(left);
|
||||
std::istream left_stream(&left_buffer);
|
||||
xlnt::detail::izstream left_archive(left_stream);
|
||||
|
||||
const auto left_info = left_archive.files();
|
||||
const auto left_info = left_archive.files();
|
||||
|
||||
xlnt::detail::vector_istreambuf right_buffer(right);
|
||||
std::istream right_stream(&right_buffer);
|
||||
xlnt::detail::izstream right_archive(right_stream);
|
||||
|
||||
const auto right_info = right_archive.files();
|
||||
const auto right_info = right_archive.files();
|
||||
|
||||
auto difference_is_missing_calc_chain = false;
|
||||
|
||||
if (std::abs(int(left_info.size()) - int(right_info.size())) == 1)
|
||||
{
|
||||
auto is_calc_chain = [](const xlnt::path &p)
|
||||
{
|
||||
auto is_calc_chain = [](const xlnt::path &p) {
|
||||
return p.filename() == "calcChain.xml";
|
||||
};
|
||||
|
||||
|
@ -306,7 +304,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
if (left_info.size() != right_info.size() && ! difference_is_missing_calc_chain)
|
||||
if (left_info.size() != right_info.size() && !difference_is_missing_calc_chain)
|
||||
{
|
||||
std::cout << "left has a different number of files than right" << std::endl;
|
||||
|
||||
|
@ -338,12 +336,41 @@ public:
|
|||
|
||||
if (!compare_relationships(left_manifest, right_manifest))
|
||||
{
|
||||
std::cout << "relationship mismatch\n"
|
||||
<< "Left:\n";
|
||||
for (const auto &part : left_manifest.parts())
|
||||
{
|
||||
std::cout << "-part: " << part.string() << '\n';
|
||||
auto rels = left_manifest.relationships(part);
|
||||
for (auto &rel : rels)
|
||||
{
|
||||
std::cout << rel.id() << ':'
|
||||
<< static_cast<int>(rel.type())
|
||||
<< ':' << static_cast<int>(rel.target_mode())
|
||||
<< ':' << rel.source().path().string()
|
||||
<< ':' << rel.target().path().string() << '\n';
|
||||
}
|
||||
}
|
||||
std::cout << "\nRight:\n";
|
||||
for (const auto &part : right_manifest.parts())
|
||||
{
|
||||
std::cout << "-part: " << part.string() << '\n';
|
||||
auto rels = right_manifest.relationships(part);
|
||||
for (auto &rel : rels)
|
||||
{
|
||||
std::cout << rel.id()
|
||||
<< ':' << static_cast<int>(rel.type())
|
||||
<< ':' << static_cast<int>(rel.target_mode())
|
||||
<< ':' << rel.source().path().string()
|
||||
<< ':' << rel.target().path().string() << '\n';
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto left_member : left_info)
|
||||
{
|
||||
if (!right_archive.has_file(left_member))
|
||||
for (auto left_member : left_info)
|
||||
{
|
||||
if (!right_archive.has_file(left_member))
|
||||
{
|
||||
if (difference_is_missing_calc_chain)
|
||||
{
|
||||
|
@ -357,32 +384,34 @@ public:
|
|||
}
|
||||
|
||||
auto left_content_type = left_member.string() == "[Content_Types].xml"
|
||||
? "[Content_Types].xml" : left_manifest.content_type(left_member);
|
||||
? "[Content_Types].xml"
|
||||
: left_manifest.content_type(left_member);
|
||||
auto right_content_type = left_member.string() == "[Content_Types].xml"
|
||||
? "[Content_Types].xml" : right_manifest.content_type(left_member);
|
||||
? "[Content_Types].xml"
|
||||
: right_manifest.content_type(left_member);
|
||||
|
||||
if (left_content_type != right_content_type)
|
||||
{
|
||||
std::cout << "content types differ: "
|
||||
<< left_member.string()
|
||||
<< " "
|
||||
<< left_content_type
|
||||
<< " "
|
||||
<< right_content_type
|
||||
<< std::endl;
|
||||
<< left_member.string()
|
||||
<< " "
|
||||
<< left_content_type
|
||||
<< " "
|
||||
<< right_content_type
|
||||
<< std::endl;
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!compare_files(left_archive.read(left_member),
|
||||
right_archive.read(left_member), left_content_type))
|
||||
{
|
||||
std::cout << left_member.string() << std::endl;
|
||||
right_archive.read(left_member), left_content_type))
|
||||
{
|
||||
std::cout << left_member.string() << std::endl;
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
return match;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user