0027433: Opening/Saving OCAF Documents With Own Document Format Does Not Work
authorBenjamin Bihler <benjamin.bihler@compositence.de>
Thu, 28 Apr 2016 11:18:35 +0000 (14:18 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 12 May 2016 07:37:11 +0000 (10:37 +0300)
Modified Load(...) method of Resource_Manager.cxx to print file names correctly.

Removed appending (empty) file name to directory name, since this is not
necessary and leads to a Standard_OutOfRange failure in TCollection_AsciiString.

Appending file name is done, but only if the name is not empty.

Added test case

src/Resource/Resource_Manager.cxx
tests/bugs/caf/bug27433 [new file with mode: 0755]

index 8186eb9178aa0961e0d602aa42f82859f1b6baed..73a5d580a691aaf86c550855e36f7c7951391822 100644 (file)
@@ -113,9 +113,9 @@ void Resource_Manager::Load(TCollection_AsciiString& aPath,
 {
   Resource_KindOfLine aKind;
   TCollection_AsciiString Token1, Token2;
-  TCollection_AsciiString Directory, Name;
-  TCollection_AsciiString FileName;
-  OSD_File File = OSD_Path(aPath);
+  OSD_Path Path(aPath);
+  OSD_File File = Path;
+  TCollection_AsciiString FileName = Path.Name();
   File.Open(OSD_ReadOnly,OSD_Protection());
   if (File.Failed()) {
     if (myVerbose)
@@ -486,7 +486,12 @@ void Resource_Manager::GetResourcePath (TCollection_AsciiString& aPath, const St
   TCollection_AsciiString aResPath(dir);
 
   OSD_Path anOSDPath(aResPath);
-  anOSDPath.DownTrek(anOSDPath.Name());
+
+  if (!anOSDPath.Name().IsEmpty())
+  {
+    anOSDPath.DownTrek(anOSDPath.Name());
+  }
+
   anOSDPath.SetName(aName);
 
   anOSDPath.SystemName(aPath);
diff --git a/tests/bugs/caf/bug27433 b/tests/bugs/caf/bug27433
new file mode 100755 (executable)
index 0000000..72c21eb
--- /dev/null
@@ -0,0 +1,21 @@
+puts "==========="
+puts "OCC27433 Opening/Saving OCAF Documents With Own Document Format Does Not Work"
+puts "==========="
+
+# make variable ends with "/" to get empty myName in OSD_Path
+dsetenv "CSF_PluginDefaults" [dgetenv CSF_PluginDefaults]/
+
+# Create simple document with some data
+NewDocument Doc BinOcaf
+SetInteger Doc 0:2 100
+
+# Save the document
+set aFile ${imagedir}/OCC27433-[file tail [info script]].cbf
+file delete ${aFile}
+puts ${aFile}
+catch {SaveAs Doc ${aFile}}
+if { ![file exists ${aFile}] } {
+       puts "Error: Can not save the file with path to plugins ended with slash"
+}
+
+Close Doc