Skip to content

Commit 4a8c5f2

Browse files
committed
cool#4535 convert-to compare option: add testcase
Fails with the previous commit reverted. Test the RTF output, because that has markup for redlines and is text-based, so easier to inspect than PDF. Signed-off-by: Miklos Vajna <[email protected]> Change-Id: Ib3aab16a75d0215f3784dad380ae905210703da7
1 parent 7b111bd commit 4a8c5f2

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

test/UnitConvert.cpp

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ class UnitConvert : public UnitWSD
5858
config.setBool("storage.filesystem[@allow]", false);
5959
}
6060

61-
void sendConvertTo(std::unique_ptr<Poco::Net::HTTPClientSession>& session, const std::string& filename, bool isTemplate = false)
61+
void sendConvertTo(std::unique_ptr<Poco::Net::HTTPClientSession>& session, const std::string& filename, bool isTemplate = false, bool isCompare = false)
6262
{
6363
std::string uri;
64-
if (isTemplate)
64+
if (isTemplate || isCompare)
6565
{
6666
uri = "/cool/convert-to";
6767
}
@@ -80,6 +80,14 @@ class UnitConvert : public UnitWSD
8080
std::string templatePath = Poco::Path(TDOC, "template.docx").toString();
8181
form.addPart("template", new Poco::Net::FilePartSource(templatePath));
8282
}
83+
else if (isCompare)
84+
{
85+
form.set("format", "rtf");
86+
std::string dataPath = Poco::Path(TDOC, filename).toString();
87+
form.addPart("data", new Poco::Net::FilePartSource(dataPath));
88+
std::string comparePath = Poco::Path(TDOC, "old.docx").toString();
89+
form.addPart("compare", new Poco::Net::FilePartSource(comparePath));
90+
}
8391
else
8492
{
8593
form.set("format", "txt");
@@ -89,7 +97,7 @@ class UnitConvert : public UnitWSD
8997
form.write(session->sendRequest(request));
9098
}
9199

92-
bool checkConvertTo(std::unique_ptr<Poco::Net::HTTPClientSession>& session, bool isTemplate = false)
100+
bool checkConvertTo(std::unique_ptr<Poco::Net::HTTPClientSession>& session, bool isTemplate = false, bool isCompare = false)
93101
{
94102
Poco::Net::HTTPResponse response;
95103
std::stringstream stringStream;
@@ -101,7 +109,7 @@ class UnitConvert : public UnitWSD
101109
}
102110

103111
bool ret = response.getStatus() == Poco::Net::HTTPResponse::HTTPStatus::HTTP_OK;
104-
if (!ret || !isTemplate)
112+
if (!ret || !(isTemplate || isCompare))
105113
{
106114
if (!ret)
107115
{
@@ -112,16 +120,33 @@ class UnitConvert : public UnitWSD
112120
}
113121

114122
std::string responseString = stringStream.str();
115-
if (responseString.find("DOCTYPE html") == std::string::npos)
123+
if (isTemplate)
116124
{
117-
TST_LOG("checkConvertTo: output is not HTML");
118-
return false;
119-
}
125+
if (responseString.find("DOCTYPE html") == std::string::npos)
126+
{
127+
TST_LOG("checkConvertTo: output is not HTML");
128+
return false;
129+
}
120130

121-
if (responseString.find("background: #156082") == std::string::npos)
131+
if (responseString.find("background: #156082") == std::string::npos)
132+
{
133+
TST_LOG("checkConvertTo: no template color in output");
134+
return false;
135+
}
136+
}
137+
else if (isCompare)
122138
{
123-
TST_LOG("checkConvertTo: no template color in output");
124-
return false;
139+
if (!responseString.starts_with("{\\rtf"))
140+
{
141+
TST_LOG("checkConvertTo: output is not RTF");
142+
return false;
143+
}
144+
145+
if (responseString.find("\\deleted") == std::string::npos)
146+
{
147+
TST_LOG("checkConvertTo: no old content in output");
148+
return false;
149+
}
125150
}
126151

127152
return true;
@@ -164,6 +189,18 @@ class UnitConvert : public UnitWSD
164189
return;
165190
}
166191

192+
// Given a current docx + old docx:
193+
// When comparing those documents and saving the result as RTF:
194+
sendConvertTo(session, "new.docx", /*isTemplate=*/false, /*isCompare=*/true);
195+
// Then make sure the output has content from the old document, too:
196+
// Without the accompanying fix in place, this test would have failed with:
197+
// checkConvertTo: no old content in output
198+
if(!checkConvertTo(session, /*isTemplate=*/false, /*isCompare=*/true))
199+
{
200+
exitTest(TestResult::Failed);
201+
return;
202+
}
203+
167204
exitTest(TestResult::Ok);
168205
});
169206
}

test/data/new.docx

13 KB
Binary file not shown.

test/data/old.docx

13 KB
Binary file not shown.

0 commit comments

Comments
 (0)