Browse Source

+ test for assign/rename/erase/mkdir/rmdir with utf8/cp866 encoded file
names

git-svn-id: branches/cpstrrtl@25140 -

Jonas Maebe 12 years ago
parent
commit
957854c0ae
2 changed files with 89 additions and 0 deletions
  1. 1 0
      .gitattributes
  2. 88 0
      tests/test/units/system/tfiledir.pp

+ 1 - 0
.gitattributes

@@ -12037,6 +12037,7 @@ tests/test/units/system/testmac.txt svneol=native#text/plain
 tests/test/units/system/testpc.txt svneol=native#text/plain
 tests/test/units/system/teststk.pp svneol=native#text/plain
 tests/test/units/system/testux.txt svneol=native#text/plain
+tests/test/units/system/tfiledir.pp svneol=native#text/plain
 tests/test/units/system/tgenstr.pp svneol=native#text/pascal
 tests/test/units/system/tincdec.pp svneol=native#text/plain
 tests/test/units/system/tint.pp svneol=native#text/plain

+ 88 - 0
tests/test/units/system/tfiledir.pp

@@ -0,0 +1,88 @@
+{$codepage utf8}
+{$mode objfpc}{$h+}
+
+uses
+{$ifdef unix}
+  cwstring,
+{$endif}
+  sysutils;
+
+type
+  tcpstr866 = type ansistring(866);
+
+procedure error(const s: string);
+begin
+  writeln('Error: ',s);
+  halt(1);
+end;
+
+
+procedure warn(const s: string);
+begin
+  writeln('Warning: cannot test '+s+' scenario fully because not all characters are supported by DefaultFileSystemCodePage');
+end;
+
+{$i-}
+
+procedure testsinglebyte;
+var
+  u, u2,u3: utf8string;
+  c,c2,c3: tcpstr866;
+  f: file;
+begin
+  u:='‹≈©◊';
+  assign(f,u);
+  rewrite(f);
+  if ioresult<>0 then
+    Error('Creating utf8string file');
+  close(f);
+  if ioresult<>0 then
+    Error('Closing utf8string file');
+  u2:='†∞';
+  mkdir(u2);
+  if ioresult<>0 then
+    Error('Creating utf8string dir');
+  u3:=u2+'/‹≈©◊1';
+  rename(f,u3);
+  if ioresult<>0 then
+    Error('Renaming utf8string file');
+  erase(f);
+  if ioresult<>0 then
+    Error('Erasing utf8string file');
+  rmdir(u2);
+  if ioresult<>0 then
+    Error('Removing utf8string dir');
+
+  c:='Русская';
+  setcodepage(rawbytestring(c),866);
+  assign(f,c);
+  rewrite(f);
+  if ioresult<>0 then
+    Error('Creating cp866 file');
+  close(f);
+  if ioresult<>0 then
+    Error('Closing cp866 file');
+  c2:='кая';
+  setcodepage(rawbytestring(c2),866);
+  mkdir(c2);
+  if ioresult<>0 then
+    Error('Creating cp866 dir');
+  c3:=c2+'/Русская1';
+  setcodepage(rawbytestring(c3),866);
+  rename(f,c3);
+  if ioresult<>0 then
+    Error('Renaming cp866 file');
+  erase(f);
+  if ioresult<>0 then
+    Error('Erasing cp866 file');
+  rmdir(c2);
+  if ioresult<>0 then
+    Error('Removing cp866 dir');
+end;
+
+
+begin
+  DefaultFileSystemCodePage:=CP_UTF8;
+  testsinglebyte;
+//  testtwobyte;
+end.