void FileFunctionsTestCase::DoConcatFile(const wxString& filePath1, const wxString& filePath2, const wxString& destFilePath) { const wxString msg = wxString::Format(wxT("File 1: %s File 2: %s File 3: %s"), filePath1.c_str(), filePath2.c_str(), destFilePath.c_str()); const char *pUnitMsg = (const char*)msg.mb_str(wxConvUTF8); // Prepare source data wxFFile f1(filePath1, wxT("wb")), f2(filePath2, wxT("wb")); CPPUNIT_ASSERT_MESSAGE( pUnitMsg, f1.IsOpened() && f2.IsOpened() ); wxString s1(wxT("1234567890")); wxString s2(wxT("abcdefghij")); CPPUNIT_ASSERT_MESSAGE( pUnitMsg, f1.Write(s1) ); CPPUNIT_ASSERT_MESSAGE( pUnitMsg, f2.Write(s2) ); CPPUNIT_ASSERT_MESSAGE( pUnitMsg, f1.Close() && f2.Close() ); // Concatenate source files CPPUNIT_ASSERT_MESSAGE( pUnitMsg, wxConcatFiles(filePath1, filePath2, destFilePath) ); // Verify content of destination file CPPUNIT_ASSERT_MESSAGE( pUnitMsg, wxFileExists(destFilePath) ); wxString sSrc = s1 + s2; wxString s3; wxFFile f3(destFilePath, wxT("rb")); CPPUNIT_ASSERT_MESSAGE( pUnitMsg, f3.ReadAll(&s3) ); CPPUNIT_ASSERT_MESSAGE( pUnitMsg, (sSrc.length() == s3.length()) && (memcmp(sSrc.c_str(), s3.c_str(), sSrc.length()) == 0) ); CPPUNIT_ASSERT_MESSAGE( pUnitMsg, f3.Close() ); CPPUNIT_ASSERT_MESSAGE( pUnitMsg, wxRemoveFile(filePath1) ); CPPUNIT_ASSERT_MESSAGE( pUnitMsg, wxRemoveFile(filePath2) ); CPPUNIT_ASSERT_MESSAGE( pUnitMsg, wxRemoveFile(destFilePath) ); }
bool XLPGo(void) { xlpBlockId = 0; if (!InputFile.empty() && !OutputFile.empty()) { Contents = wxFopen(TmpContentsName, _T("w")); Chapters = wxFopen(_T("chapters.xlp"), _T("w")); Sections = wxFopen(_T("sections.xlp"), _T("w")); Subsections = wxFopen(_T("subsections.xlp"), _T("w")); Subsubsections = wxFopen(_T("subsubsections.xlp"), _T("w")); Index = wxFopen(_T("index.xlp"), _T("w")); // Insert invisible section marker at beginning wxFprintf(Chapters, _T("\\hy-%d{%ld}{%s}\n"), hyBLOCK_INVISIBLE_SECTION, NewBlockId(), _T("\n")); wxFprintf(Contents, _T("\\hy-%d{%ld}{%s}\n\n"), // hyBLOCK_LARGE_HEADING, NewBlockId(), "\n\n%s\n\n", ContentsNameString); hyBLOCK_LARGE_HEADING, NewBlockId(), ContentsNameString); SetCurrentOutput(Chapters); wxFprintf(Index, _T("\n\\hyindex{\n\"%s\"\n"), contentsString ? contentsString : _T("WXHELPCONTENTS")); TraverseDocument(); wxNode *node = hyperLinks.GetFirst(); while (node) { long from = node->GetKeyInteger(); wxChar *label = (wxChar *)node->GetData(); wxNode *otherNode = hyperLabels.Find(label); if (otherNode) { long to = (long)otherNode->GetData(); wxFprintf(Index, _T("%ld %ld\n"), from, to); } node = node->GetNext(); } wxFprintf(Index, _T("}\n")); fclose(Contents); Contents = NULL; fclose(Chapters); Chapters = NULL; fclose(Sections); Sections = NULL; fclose(Subsections); Subsections = NULL; fclose(Subsubsections); Subsubsections = NULL; fclose(Index); Index = NULL; if (wxFileExists(ContentsName)) wxRemoveFile(ContentsName); if (!wxRenameFile(TmpContentsName, ContentsName)) { wxCopyFile(TmpContentsName, ContentsName); wxRemoveFile(TmpContentsName); } wxConcatFiles(_T("chapters.xlp"), _T("sections.xlp"), _T("tmp2.xlp")); wxConcatFiles(_T("tmp2.xlp"), _T("subsections.xlp"), _T("tmp1.xlp")); wxConcatFiles(_T("tmp1.xlp"), _T("subsubsections.xlp"), _T("tmp2.xlp")); wxConcatFiles(_T("tmp2.xlp"), _T("index.xlp"), OutputFile); wxRemoveFile(_T("tmp1.xlp")); wxRemoveFile(_T("tmp2.xlp")); wxRemoveFile(_T("chapters.xlp")); wxRemoveFile(_T("sections.xlp")); wxRemoveFile(_T("subsections.xlp")); wxRemoveFile(_T("subsubsections.xlp")); wxRemoveFile(_T("index.xlp")); return true; } return false; }