/* $Id: makeimagedl-info-test.cc,v 1.7 2004/09/11 23:26:30 atterer Exp $ -*- C++ -*- __ _ |_) /| Copyright (C) 2003 | richard@ | \/¯| Richard Atterer | atterer.net ¯ '` ¯ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2. See the file COPYING for details. #test-deps job/makeimagedl-info.o net/uri.o */ #include #include #include #include #include #include //______________________________________________________________________ using namespace Job; MakeImageDl::MakeImageDl(/*IO* ioPtr,*/ const string& jigdoUri, const string& destination) : io(/*ioPtr*/), stateVal(DOWNLOADING_JIGDO), jigdoUrl(jigdoUri), childrenVal(), dest(destination), tmpDirVal(), mi(), imageNameVal(), imageInfoVal(), imageShortInfoVal(), templateUrls(0), templateMd5Val(0) { } Job::MakeImageDl::~MakeImageDl() { } void MakeImageDl::setImageSection(string* imageName, string* imageInfo, string* imageShortInfo, PartUrlMapping* templateUrls, MD5** templateMd5) { msg("setImageSection"); Paranoid(!haveImageSection()); imageNameVal.swap(*imageName); imageInfoVal.swap(*imageInfo); imageShortInfoVal.swap(*imageShortInfo); this->templateUrls = templateUrls; templateMd5Val = *templateMd5; *templateMd5 = 0; IOSOURCE_SEND(IO, io, makeImageDl_haveImageSection, ()); } //====================================================================== namespace { const char* const hexDigits = "0123456789abcdef"; void escapedChar(string* o, byte c) { switch (c) { case 0: *o += "\\0"; break; case '\n': *o += "\\n"; break; case '\t': *o += "\\t"; break; case '"': case '\\': *o += '\\'; *o += c; break; default: if (c >= ' ' && c <= '~') { *o += c; } else { *o += "\\x"; *o += hexDigits[unsigned(c) >> 4]; *o += hexDigits[unsigned(c) & 0xfU]; } } } inline string escapedString(const string& s) { string result; for (unsigned i = 0; i < s.length(); ++i) escapedChar(&result, s[i]); return result; } } //______________________________________________________________________ string testImageInfo(const char* subst[], bool escapedText, const char* text, const char* expected) { string imageShortInfo; PartUrlMapping* templateUrls = 0; MD5* templateMd5 = 0; MakeImageDl m("http://url/", ""); string imageName = "image.iso"; string imageInfo = text; m.setImageSection(&imageName, &imageInfo, &imageShortInfo, templateUrls, &templateMd5); string info = " "; m.imageInfo(&info, escapedText, subst); msg("\"%1\"", escapedString(info)); Assert(info == expected); return info; } //______________________________________________________________________ int main(int argc, char* argv[]) { if (argc == 2) Logger::scanOptions(argv[1], argv[0]); const char* gtk[] = { "", "", // , "", "", // , "", "", // , "", "", // , "", "", // , "", "", // , "\n" //
}; const char* tex[] = { "\\textbf{", "}", // , "\\textit{", "}", // , "\\texttt{", "}", // , "\\underline{", "}", // , "\\large{", "}", // , "\\small{", "}", // , "\\\\" //
}; testImageInfo(gtk, true, "'Sun, <16> \"Mar 2003 & 04:45:40 -0700'", " 'Sun, <16> \"Mar 2003 & 04:45:40 -0700'"); testImageInfo(tex, false, "'Sun, <16> \"Mar 2003 & 04:45:40 -0700'", " 'Sun, <16> \"Mar 2003 & 04:45:40 -0700'"); testImageInfo(gtk, true, "Let him who


" "hath understanding reckon", " Let him " "who\n\nhath " "understanding reckon"); testImageInfo(tex, false, "Let him who


" "hath understanding reckon", " \\textbf{Let} \\large{him} \\small{who}\\\\\\\\" "\\textit{hath} \\texttt{understanding} \\underline{reckon}"); testImageInfo(gtk, true, "br must be empty

", " br must be empty <br> </br>"); testImageInfo(tex, false, "Ugh, does no good", " Ugh, does no good"); testImageInfo(gtk, true, "Now let mee
ee
entertain
you
", " Now let mee\nee " "entertain you"); testImageInfo(tex, false, "x", " x"); testImageInfo(gtk, true, "nobold", " <b x=\"\">nobold</b>"); testImageInfo(gtk, true, "nocomment", " nocomment<!-- x -->"); /* CDATA sections are supported by glib. However, our parseComment() creates an error if it sees one, because glib doesn't strip the "" strings - not useful! */ testImageInfo(gtk, true, "is & quoted]]>", " <b><![CDATA[This <i>is</i> & " "quoted]]></b>"); // " This <i>is</i> & quoted" return 0; }