treadwrt.pp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. {$i+}
  2. { Widestring is not supported in 1.0.x }
  3. {$ifndef VER1_0}
  4. {$define HASWIDESTR}
  5. {$endif VER1_0}
  6. function getint64_1 : int64;
  7. var
  8. value : longint;
  9. begin
  10. value:=1;
  11. getint64_1 := int64(value) shl 40;
  12. end;
  13. function getint64_2 : int64;
  14. var
  15. value : longint;
  16. begin
  17. value:=65535;
  18. getint64_2 := value;
  19. end;
  20. procedure test_rwtext;
  21. var
  22. t: text;
  23. s: shortstring;
  24. a: ansistring;
  25. {$ifdef HASWIDESTR}
  26. wc : widechar;
  27. w : widestring;
  28. {$endif HASWIDESTR}
  29. l: longint;
  30. card: cardinal;
  31. b: byte; bool: boolean;
  32. c: char;
  33. arr: array[1..10] of char;
  34. p: pchar;
  35. r: real;
  36. vl : int64;
  37. vl1 : int64;
  38. tmplong : longint;
  39. begin
  40. bool := true;
  41. writeln('ShortString const test');
  42. writeln('ShortString const test with const len':70);
  43. b := 60;
  44. writeln('ShortString const test with var len':b);
  45. s := 'ShortStr var test';
  46. writeln(s);
  47. s := s+ ' with const len';
  48. writeln(s:40);
  49. s := 'ShortStr var test with var len';
  50. writeln(s:b);
  51. l := -1; c := 'y'; card := 18; r := 5.1234;
  52. writeln('A combo test: ',b,' ',l,' ',c,' ',card,' ',bool:10);
  53. writeln('floats: ',r,' ',r:1,' ',r:8,' ',r:10:2);
  54. arr := 'arrofchars';
  55. writeln('array of char: ',arr:38);
  56. arr[10] := #0;
  57. p := @arr;
  58. writeln('pchar test: ',p);
  59. a := 'this is an ansistring';
  60. writeln(a);
  61. vl:=getint64_1;
  62. vl1:=getint64_2;
  63. writeln('int64 test : ',vl, ' ',vl1);
  64. {$ifdef HASWIDESTR}
  65. wc := 'y';
  66. writeln('widechar: ',wc);
  67. w := 'this is a widestring';
  68. writeln(w);
  69. {$endif HASWIDESTR}
  70. write('no new line now...',l,c,b);
  71. write;
  72. read;
  73. assign(t,'treadwrt.txt');
  74. rewrite(t);
  75. writeln('testing text file functionality...');
  76. writeln(t,'this is a string');
  77. writeln(t,l);
  78. writeln(t,c);
  79. writeln(t,b);
  80. writeln(t,vl);
  81. writeln(t,vl1);
  82. l := 0;
  83. c := #32;
  84. b := 5;
  85. vl:=1;
  86. vl1 := 2;
  87. close(t);
  88. reset(t);
  89. readln(t,s);
  90. if s <> 'this is a string' then
  91. halt(1);
  92. readln(t,l);
  93. if l <> -1 then
  94. halt(1);
  95. readln(t,c);
  96. if c <> 'y' then
  97. halt(1);
  98. readln(t,b);
  99. if b <> 60 then
  100. halt(1);
  101. { 64-bit read testing }
  102. readln(t,vl);
  103. if vl <> getint64_1 then
  104. halt(1);
  105. readln(t,vl1);
  106. if vl1 <> getint64_2 then
  107. halt(1);
  108. close(t);
  109. erase(t);
  110. writeln('write/read text passed...');
  111. end;
  112. procedure test_rwtyped;
  113. var
  114. f: file of cardinal;
  115. c: cardinal;
  116. begin
  117. assign(f,'treadwrt.dat');
  118. rewrite(f);
  119. c := 8;
  120. write(f,c);
  121. write(f,cardinal(10));
  122. close(f);
  123. reset(f);
  124. read(f,c);
  125. if c <> 8 then
  126. halt(1);
  127. read(f,c);
  128. if c <> 10 then
  129. halt(1);
  130. close(f);
  131. erase(f);
  132. writeln('write/read typed passed...');
  133. end;
  134. begin
  135. test_rwtext;
  136. test_rwtyped;
  137. end.