diff --git a/Test/Applications/x2tTester/README.md b/Test/Applications/x2tTester/README.md new file mode 100644 index 0000000000..48c51c6b94 --- /dev/null +++ b/Test/Applications/x2tTester/README.md @@ -0,0 +1,31 @@ +CONFIGURATION +============= + +You need to create an xml configuration file. It must contain: + + # root of xml + # report.csv path + # folder with test documents + # results folder + # path to x2t + <*> # input format with output formats + + +You can use the following template: + + + + + + + + + txt + odt + + + +USAGE +===== + +Run a program with 1 argument - path to xml configuration file. \ No newline at end of file diff --git a/Test/Applications/x2tTester/main.cpp b/Test/Applications/x2tTester/main.cpp index 3ee87c15fa..62bd9c7c90 100644 --- a/Test/Applications/x2tTester/main.cpp +++ b/Test/Applications/x2tTester/main.cpp @@ -1,17 +1,4 @@ -#include - -#include "../../../Common/OfficeFileFormats.h" -#include "../../../Common/OfficeFileFormatChecker.h" - -#include "../../../DesktopEditor/graphics/Timer.h" -#include "../../../DesktopEditor/graphics/TemporaryCS.h" -#include "../../../DesktopEditor/common/File.h" -#include "../../../DesktopEditor/common/Directory.h" -#include "../../../DesktopEditor/common/StringBuilder.h" -#include "../../../DesktopEditor/raster/BgraFrame.h" -#include "../../../DesktopEditor/fontengine/ApplicationFontsWorker.h" - -#include "../../../OfficeUtils/src/OfficeUtils.h" +#include "x2tTester.h" #ifdef LINUX #include @@ -25,57 +12,16 @@ int wmain(int argc, wchar_t** argv) int main(int argc, char** argv) #endif { - // creating temporary xml file with params - NSStringUtils::CStringBuilder builder; - builder.WriteString(L""); + std::wstring config_path; - builder.WriteString(L""); + if(argc < 2) config_path = L"./config.xml"; + else config_path = std::wstring(argv[1]); - builder.WriteString(L""); - builder.WriteString(L""); - builder.WriteString(L""); - - builder.WriteString(L""); - builder.WriteString(L""); - builder.WriteString(L""); - - builder.WriteString(L""); - - std::wstring xml_params = builder.GetData(); - std::wstring xml_params_file = L""; - NSFile::CFileBinary::SaveToFile(xml_params_file, xml_params, true); - - std::wstring x2t_path = L""; - std::wstring command = x2t_path + L' ' + xml_params_file; - wchar_t *ptr_command = new wchar_t[command.size() + 1]; - memcpy(ptr_command, command.c_str(), command.length() * sizeof(wchar_t)); - ptr_command[command.size()] = L'\0'; - - PROCESS_INFORMATION processinfo; - STARTUPINFO sturtupinfo; - ZeroMemory(&processinfo,sizeof(PROCESS_INFORMATION)); - ZeroMemory(&sturtupinfo,sizeof(STARTUPINFO)); - sturtupinfo.cb = sizeof(sturtupinfo); - - BOOL bool_result = CreateProcessW(NULL, ptr_command, - NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &sturtupinfo, &processinfo); - - WaitForSingleObject(processinfo.hProcess, INFINITE); - RELEASEARRAYOBJECTS(ptr_command); - - DWORD exit_code = 0; - GetExitCodeProcess(processinfo.hProcess, &exit_code); - std::cout << exit_code << std::endl; - - // NSFile::CFileBinary::Remove(xml_params_file); + Cx2tTester tester = Cx2tTester(config_path); + tester.Start(); return 0; } - -// minimal test -// normal paths -// configuration -// csv report // linux support // multitask // etc.. diff --git a/Test/Applications/x2tTester/x2tTester.cpp b/Test/Applications/x2tTester/x2tTester.cpp new file mode 100644 index 0000000000..98a81c3c02 --- /dev/null +++ b/Test/Applications/x2tTester/x2tTester.cpp @@ -0,0 +1,208 @@ +#include "x2tTester.h" + +Cx2tTester::Cx2tTester(std::wstring configPath) +{ + setConfig(configPath); + + m_xmlParams = m_outputFolder + L'\\' + L"params.xml"; + + // todo check + m_reportStream.open(m_reportPath); + if(!m_reportStream.is_open()) + { + std::wcerr << "Report file is not open!" << std::endl; + exit(-1); + } + + setReportHeader(); +} +Cx2tTester::~Cx2tTester() +{ + m_reportStream.close(); +} + +void Cx2tTester::Start() +{ + // setup & clear output folder + if(NSDirectory::Exists(m_outputFolder)) + NSDirectory::DeleteDirectory(m_outputFolder); + + NSDirectory::CreateDirectory(m_outputFolder); + std::wstring process = NSFile::GetProcessDirectory(); + + std::vector files = NSDirectory::GetFiles(m_inputFolder, false); + COfficeFileFormatChecker checker; + + for(std::wstring& file : files) + { + + // setup folder for output files + std::wstring output_files_folder = m_outputFolder + + L'\\' + NSFile::GetFileName(file); + + if(NSDirectory::Exists(output_files_folder)) + NSDirectory::DeleteDirectory(output_files_folder); + + NSDirectory::CreateDirectory(output_files_folder); + + std::wstring input_ext = NSFile::GetFileExtention(file); + int input_format = COfficeFileFormatChecker::GetFormatByExtension(L'.' + input_ext); + + // input_ext in many output exts + for(int& output_format : m_formats[input_format]) + { + std::wstring output_file_path = output_files_folder + + L'\\' + NSFile::GetFileName(file) + checker.GetExtensionByType(output_format); + + // creating temporary xml file with params + NSStringUtils::CStringBuilder builder; + builder.WriteString(L""); + + builder.WriteString(L""); + + builder.WriteString(L""); + builder.WriteString(file); + builder.WriteString(L""); + + builder.WriteString(L""); + builder.WriteString(output_file_path); + builder.WriteString(L""); + + + builder.WriteString(L""); + builder.WriteString(std::to_wstring(input_format)); + builder.WriteString(L""); + + + builder.WriteString(L""); + builder.WriteString(std::to_wstring(output_format)); + builder.WriteString(L""); + + builder.WriteString(L"true"); + +// builder.WriteString(L""); +// builder.WriteString(process + L"/fonts/AllFonts.js"); +// builder.WriteString(L""); + +// builder.WriteString(L""); +// builder.WriteString(process + L"/fonts"); +// builder.WriteString(L""); + + std::wcout << process << std::endl; + + + builder.WriteString(L""); + + std::wstring xml_params = builder.GetData(); + + NSFile::CFileBinary::SaveToFile(m_xmlParams, xml_params, true); + + std::wcout << file << L" to " << output_file_path << L"... "; + int exit_code = convert(file, output_file_path); + + if(!exit_code) + std::wcout << "OK" << std::endl; + else + std::wcout << "BAD" << std::endl; + + // writing report + Report report; + report.inputFile = file; + report.outputFile = output_file_path; + report.inputExt = checker.GetExtensionByType(input_format); + report.outputExt = checker.GetExtensionByType(output_format); + report.exitCode = exit_code; + + writeReport(report); + } + } + m_reportStream.close(); + NSFile::CFileBinary::Remove(m_xmlParams); +} + +void Cx2tTester::setConfig(const std::wstring& configPath) +{ + XmlUtils::CXmlNode root; + XmlUtils::CXmlNodes nodes; + if(root.FromXmlFile(configPath) && root.GetChilds(nodes)) + for(int i = 0; i < nodes.GetCount(); i++) + { + XmlUtils::CXmlNode node; + nodes.GetAt(i, node); + std::wstring name = node.GetName();\ + + // key-value + if(name == L"reportPath") m_reportPath = node.GetText(); + else if(name == L"inputFolder") m_inputFolder = node.GetText(); + else if(name == L"outputFolder") m_outputFolder = node.GetText(); + else if(name == L"x2tPath") m_x2tPath = node.GetText(); + + // arrays + else + { + XmlUtils::CXmlNodes array; + node.GetNodes(L"item", array); + + std::wstring input_ext = L'.' + name; + int input_format = COfficeFileFormatChecker::GetFormatByExtension(input_ext); + + if(!input_format) + continue; + + for (int i = 0; i < array.GetCount(); i++) + { + XmlUtils::CXmlNode item; + array.GetAt(i, item); + + std::wstring output_ext = L'.' + item.GetText(); + + int output_format = COfficeFileFormatChecker::GetFormatByExtension(output_ext); + + if(!output_format) + continue; + + m_formats[input_format].push_back(output_format); + } + } + } + // else err +} +void Cx2tTester::setReportHeader() +{ + m_reportStream << L"Input file" << L"\t"; + m_reportStream << L"Output file" << L"\t"; + m_reportStream << L"Input extension" << L"\t"; + m_reportStream << L"Output extension" << L"\t"; + m_reportStream << L"Exit code" << L"\n"; +} +void Cx2tTester::writeReport(const Report& report) +{ + m_reportStream << report.inputFile << L"\t"; + m_reportStream << report.outputFile << L"\t"; + m_reportStream << report.inputExt << L"\t"; + m_reportStream << report.outputExt << L"\t"; + m_reportStream << report.exitCode << L"\n"; +} +int Cx2tTester::convert(const std::wstring& inputPath, const std::wstring& outputPath) +{ + std::wstring command = m_x2tPath + L' ' + m_xmlParams; + wchar_t *ptr_command = new wchar_t[command.size() + 1]; + memcpy(ptr_command, command.c_str(), command.length() * sizeof(wchar_t)); + ptr_command[command.size()] = L'\0'; + + PROCESS_INFORMATION processinfo; + STARTUPINFO sturtupinfo; + ZeroMemory(&processinfo,sizeof(PROCESS_INFORMATION)); + ZeroMemory(&sturtupinfo,sizeof(STARTUPINFO)); + sturtupinfo.cb = sizeof(sturtupinfo); + + BOOL bool_result = CreateProcessW(NULL, ptr_command, + NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &sturtupinfo, &processinfo); + + WaitForSingleObject(processinfo.hProcess, INFINITE); + RELEASEARRAYOBJECTS(ptr_command); + + DWORD exit_code = 0; + GetExitCodeProcess(processinfo.hProcess, &exit_code); + return exit_code; +} diff --git a/Test/Applications/x2tTester/x2tTester.h b/Test/Applications/x2tTester/x2tTester.h new file mode 100644 index 0000000000..f8592ba941 --- /dev/null +++ b/Test/Applications/x2tTester/x2tTester.h @@ -0,0 +1,61 @@ +#ifndef X2T_TESTER_H +#define X2T_TESTER_H + +#include +#include +#include +#include + +#include "../../../Common/OfficeFileFormats.h" +#include "../../../Common/OfficeFileFormatChecker.h" + +#include "../../../DesktopEditor/graphics/Timer.h" +#include "../../../DesktopEditor/graphics/TemporaryCS.h" +#include "../../../DesktopEditor/common/File.h" +#include "../../../DesktopEditor/common/Directory.h" +#include "../../../DesktopEditor/xml/include/xmlutils.h" +#include "../../../DesktopEditor/common/StringBuilder.h" +#include "../../../DesktopEditor/fontengine/ApplicationFontsWorker.h" + +#include "../../../OfficeUtils/src/OfficeUtils.h" + + +class Cx2tTester +{ +public: + Cx2tTester(std::wstring configPath); + ~Cx2tTester(); + + void Start(); + +private: + struct Report + { + std::wstring inputFile; + std::wstring outputFile; + std::wstring inputExt; + std::wstring outputExt; + int exitCode; + }; + + void setConfig(const std::wstring& configPath); + void setReportHeader(); + + void writeReport(const Report& report); + int convert(const std::wstring& inputPath, const std::wstring& outputPath); + + std::wstring m_reportPath; + std::wstring m_inputFolder; + std::wstring m_outputFolder; + std::wstring m_x2tPath; + + std::wstring m_xmlParams; + + std::wofstream m_reportStream; + + // from 1 to N formats + std::map> m_formats; + +}; + +#endif // X2T_TESTER_H diff --git a/Test/Applications/x2tTester/x2ttester.pro b/Test/Applications/x2tTester/x2ttester.pro index 1e7cae54f0..03cc640e30 100644 --- a/Test/Applications/x2tTester/x2ttester.pro +++ b/Test/Applications/x2tTester/x2ttester.pro @@ -10,7 +10,9 @@ $$PWD/../../../../core/Common/OfficeFileFormatChecker2.cpp \ $$PWD/../../../../core/Common/3dParty/pole/pole.cpp \ $$PWD/../../../../core/Common/DocxFormat/Source/Base/unicode_util.cpp -SOURCES += main.cpp + +HEADERS += x2tTester.h +SOURCES += main.cpp x2tTester.cpp CORE_ROOT_DIR = $$PWD/../../../../core PWD_ROOT_DIR = $$PWD