From: mpv Date: Fri, 31 Aug 2018 08:16:16 +0000 (+0300) Subject: Make TestExport unit test works also on Windows X-Git-Tag: V9_2_0a1~76 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e805b718c368fab6c95496d7f1e6e65f466334a1;p=modules%2Fshaper.git Make TestExport unit test works also on Windows --- diff --git a/src/ExchangeAPI/ExchangeAPI_Export.cpp b/src/ExchangeAPI/ExchangeAPI_Export.cpp index 492479e50..6165c8fa6 100644 --- a/src/ExchangeAPI/ExchangeAPI_Export.cpp +++ b/src/ExchangeAPI/ExchangeAPI_Export.cpp @@ -72,10 +72,28 @@ ExchangeAPI_Export::~ExchangeAPI_Export() { } +// this method is needed on Windows because back-slashes in python may cause error +static void correctSeparators(std::string& thePath) { + // replace single "\" or triple "\\\" or more by double "\" + for (std::size_t aFind = thePath.find('\\'); aFind != std::string::npos; + aFind = thePath.find('\\', aFind)) { + // search the next + std::size_t aFind2 = thePath.find('\\', aFind + 1); + if (aFind2 == std::string::npos || aFind2 > aFind + 1) { // single, so add one more + thePath.replace(aFind, 1, 2, '\\'); + } else { // if there is more than double "\", remove them + for (aFind2 = thePath.find('\\', aFind2 + 1); + aFind2 != std::string::npos && aFind2 <= aFind + 2; + aFind2 = thePath.find('\\', aFind2)) { + thePath.erase(aFind2, 1); + } + } + aFind += 2; + } +} void ExchangeAPI_Export::dump(ModelHighAPI_Dumper& theDumper) const { - FeaturePtr aBase = feature(); const std::string& aDocName = theDumper.name(aBase->document()); @@ -84,9 +102,10 @@ void ExchangeAPI_Export::dump(ModelHighAPI_Dumper& theDumper) const std::string exportType = aBase->string(ExchangePlugin_ExportFeature::EXPORT_TYPE_ID())->value(); if (exportType == "XAO") { - std::string tmpXAOFile = + std::string aTmpXAOFile = aBase->string(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID())->value(); - theDumper << "exportToXAO(" << aDocName << ", '" << tmpXAOFile << "'" ; + correctSeparators(aTmpXAOFile); + theDumper << "exportToXAO(" << aDocName << ", '" << aTmpXAOFile << "'" ; std::string theAuthor = aBase->string(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID())->value(); if (! theAuthor.empty()) theDumper << ", '" << theAuthor << "'"; @@ -97,14 +116,15 @@ void ExchangeAPI_Export::dump(ModelHighAPI_Dumper& theDumper) const theDumper << ")" << std::endl; } else { - theDumper << "exportToFile(" << aDocName << ", " << - aBase->string(ExchangePlugin_ExportFeature::FILE_PATH_ID()) << ", " << - aBase->selectionList(ExchangePlugin_ExportFeature::SELECTION_LIST_ID()) ; - std::string theFileFormat = - aBase->string(ExchangePlugin_ExportFeature::FILE_FORMAT_ID())->value(); - if (! theFileFormat.empty()) - theDumper << ", '" << theFileFormat << "'"; - theDumper << ")" << std::endl; + std::string aFilePath = aBase->string(ExchangePlugin_ExportFeature::FILE_PATH_ID())->value(); + correctSeparators(aFilePath); + theDumper << "exportToFile(" << aDocName << ", \"" << aFilePath << "\", " << + aBase->selectionList(ExchangePlugin_ExportFeature::SELECTION_LIST_ID()); + std::string theFileFormat = + aBase->string(ExchangePlugin_ExportFeature::FILE_FORMAT_ID())->value(); + if (!theFileFormat.empty()) + theDumper << ", '" << theFileFormat << "'"; + theDumper << ")" << std::endl; } }