tcnvstr1.pp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. {****************************************************************}
  2. { CODE GENERATOR TEST PROGRAM }
  3. { Copyright (c) 2002, Carl Eric Codere }
  4. {****************************************************************}
  5. { NODE TESTED : secondtypeconvert() -> second_string_string }
  6. {****************************************************************}
  7. { PRE-REQUISITES: secondload() }
  8. { secondassign() }
  9. { secondtypeconv() }
  10. {****************************************************************}
  11. { DEFINES: }
  12. { FPC = Target is FreePascal compiler }
  13. {****************************************************************}
  14. { REMARKS: Same type short conversion is not tested, except for }
  15. { shortstrings , since it requires special handling. }
  16. { }
  17. { }
  18. {****************************************************************}
  19. {$ifdef fpc}
  20. {$mode objfpc}
  21. {$ifndef ver1_0}
  22. {$define haswidestring}
  23. {$endif}
  24. {$else}
  25. {$ifndef ver70}
  26. {$define haswidestring}
  27. {$endif}
  28. {$endif}
  29. {$H+}
  30. const
  31. { exactly 255 characters in length }
  32. BIG_STRING =
  33. ' This is a small text documentation to verify the validity of'+
  34. ' the string conversion routines. Of course the conversion routines'+
  35. ' should normally work like a charm, and this can only test that there'+
  36. ' aren''t any problems with maximum length strings. This fix!';
  37. { < 255 characters in length }
  38. SMALL_STRING = 'This is a small hello!';
  39. { > 255 characters in length }
  40. HUGE_STRING_END = ' the goal of this experiment';
  41. HUGE_STRING =
  42. ' This is a huge text documentation to verify the validity of'+
  43. ' the string conversion routines. Of course the conversion routines'+
  44. ' should normally work like a charm, and this can only test that there'+
  45. ' aren''t any problems with maximum length strings. I hope you understand'+
  46. HUGE_STRING_END;
  47. EMPTY_STRING = '';
  48. type
  49. shortstr = string[127];
  50. var
  51. s2: shortstr;
  52. str_ansi: ansistring;
  53. str_short: shortstring;
  54. {$ifdef haswidestring}
  55. str_wide : widestring;
  56. {$endif}
  57. procedure fail;
  58. begin
  59. WriteLn('Failure!');
  60. Halt(1);
  61. end;
  62. procedure test_ansi_to_short;
  63. begin
  64. {************************************************************************}
  65. { ansistring -> shortstring }
  66. {************************************************************************}
  67. WriteLn('Test ansistring -> shortstring');
  68. { ansistring -> shortstring }
  69. str_short := '';
  70. str_ansi:='';
  71. str_ansi := SMALL_STRING;
  72. str_short:=str_ansi;
  73. Write('small ansistring -> shortstring...');
  74. if str_short = str_ansi then
  75. WriteLn('Success.')
  76. else
  77. fail;
  78. str_short := '';
  79. str_ansi:='';
  80. str_ansi := EMPTY_STRING;
  81. str_short:=str_ansi;
  82. Write('empty ansistring -> shortstring...');
  83. if str_short = str_ansi then
  84. WriteLn('Success.')
  85. else
  86. fail;
  87. str_short := '';
  88. str_ansi:='';
  89. str_ansi := BIG_STRING;
  90. str_short:=str_ansi;
  91. Write('big ansistring -> shortstring...');
  92. if str_short = str_ansi then
  93. WriteLn('Success.')
  94. else
  95. fail;
  96. Write('huge ansistring -> shortstring...');
  97. str_short := '';
  98. str_ansi:='';
  99. str_ansi := HUGE_STRING;
  100. str_short:=str_ansi;
  101. { Delphi 3/Delphi 6 does not consider these as the same string }
  102. if str_short <> str_ansi then
  103. WriteLn('Success.')
  104. else
  105. fail;
  106. {}
  107. s2 := '';
  108. str_ansi:='';
  109. str_ansi := SMALL_STRING;
  110. s2:=str_ansi;
  111. Write('small ansistring -> shortstring...');
  112. if s2 = str_ansi then
  113. WriteLn('Success.')
  114. else
  115. fail;
  116. s2 := '';
  117. str_ansi:='';
  118. str_ansi := EMPTY_STRING;
  119. s2:=str_ansi;
  120. Write('empty ansistring -> shortstring...');
  121. if s2 = str_ansi then
  122. WriteLn('Success.')
  123. else
  124. fail;
  125. s2 := '';
  126. str_ansi:='';
  127. str_ansi := BIG_STRING;
  128. s2:=str_ansi;
  129. Write('big ansistring -> shortstring...');
  130. { Should fail, since comparing different string lengths }
  131. if s2 <> str_ansi then
  132. WriteLn('Success.')
  133. else
  134. fail;
  135. s2 := '';
  136. str_ansi:='';
  137. str_ansi := HUGE_STRING;
  138. s2:=str_ansi;
  139. Write('huge ansistring -> shortstring...');
  140. { Should fail, since comparing different string lengths }
  141. if s2 <> str_ansi then
  142. WriteLn('Success.')
  143. else
  144. fail;
  145. end;
  146. procedure test_short_to_short;
  147. begin
  148. {************************************************************************}
  149. { shortstring -> shortstring }
  150. {************************************************************************}
  151. WriteLn('Test shortstring -> shortstring...');
  152. { shortstring -> shortstring }
  153. str_short := '';
  154. s2:='';
  155. s2 := SMALL_STRING;
  156. str_short:=s2;
  157. Write('small shortstring -> shortstring...');
  158. if str_short = s2 then
  159. WriteLn('Success.')
  160. else
  161. fail;
  162. str_short := '';
  163. s2:='';
  164. s2 := EMPTY_STRING;
  165. str_short:=s2;
  166. Write('empty shortstring -> shortstring...');
  167. if str_short = s2 then
  168. WriteLn('Success.')
  169. else
  170. fail;
  171. {$ifdef fpc}
  172. { Delphi does not compile these }
  173. str_short := '';
  174. s2:='';
  175. s2 := BIG_STRING;
  176. str_short:=s2;
  177. Write('big shortstring -> shortstring...');
  178. if str_short = s2 then
  179. WriteLn('Success.')
  180. else
  181. fail;
  182. str_short := '';
  183. s2:='';
  184. s2 := HUGE_STRING;
  185. str_short:=s2;
  186. Write('huge shortstring -> shortstring...');
  187. { Delphi 3/Delphi 6 does not consider these as the same string }
  188. if str_short = s2 then
  189. WriteLn('Success.')
  190. else
  191. fail;
  192. {$endif}
  193. s2 := '';
  194. str_short:='';
  195. str_short := SMALL_STRING;
  196. Write('small shortstring -> shortstring...');
  197. s2:=str_short;
  198. if s2 = str_short then
  199. WriteLn('Success.')
  200. else
  201. fail;
  202. s2 := '';
  203. str_short:='';
  204. str_short := EMPTY_STRING;
  205. Write('empty shortstring -> shortstring...');
  206. s2:=str_short;
  207. if s2 = str_short then
  208. WriteLn('Success.')
  209. else
  210. fail;
  211. s2 := '';
  212. str_short:='';
  213. str_short := BIG_STRING;
  214. Write('big shortstring -> shortstring...');
  215. s2:=str_short;
  216. { Should fail, since comparing different string lengths }
  217. if s2 <> str_short then
  218. WriteLn('Success.')
  219. else
  220. fail;
  221. {$ifdef fpc}
  222. s2 := '';
  223. str_short:='';
  224. str_short := HUGE_STRING;
  225. Write('huge shortstring -> shortstring...');
  226. s2:=str_short;
  227. { Should fail, since comparing different string lengths }
  228. if s2 <> str_short then
  229. WriteLn('Success.')
  230. else
  231. fail;
  232. {$endif}
  233. end;
  234. procedure test_short_to_ansi;
  235. begin
  236. {************************************************************************}
  237. { shortstring -> ansistring }
  238. {************************************************************************}
  239. WriteLn('Test shortstring -> ansistring');
  240. Write('small shortstring -> ansistring...');
  241. { shortstring -> ansistring }
  242. str_short := SMALL_STRING;
  243. str_ansi:=str_short;
  244. if str_short = str_ansi then
  245. WriteLn('Success.')
  246. else
  247. fail;
  248. Write('empty shortstring -> ansistring...');
  249. str_short := EMPTY_STRING;
  250. str_ansi:=str_short;
  251. if str_short = str_ansi then
  252. WriteLn('Success.')
  253. else
  254. fail;
  255. Write('big shortstring -> ansistring...');
  256. str_short := BIG_STRING;
  257. str_ansi:=str_short;
  258. if str_short = str_ansi then
  259. WriteLn('Success.')
  260. else
  261. fail;
  262. Write('small shortstring -> ansistring...');
  263. { shortstring -> ansistring }
  264. s2 := SMALL_STRING;
  265. str_ansi:=s2;
  266. if s2 = str_ansi then
  267. WriteLn('Success.')
  268. else
  269. fail;
  270. Write('empty shortstring -> ansistring...');
  271. s2 := EMPTY_STRING;
  272. str_ansi:=s2;
  273. if s2 = str_ansi then
  274. WriteLn('Success.')
  275. else
  276. fail;
  277. end;
  278. {$ifdef haswidestring}
  279. procedure test_wide_to_ansi;
  280. begin
  281. {************************************************************************}
  282. { widestring -> ansistring }
  283. {************************************************************************}
  284. WriteLn('Test widestring -> ansistring');
  285. Write('small widestring -> ansistring...');
  286. { widestring -> ansistring }
  287. str_wide := SMALL_STRING;
  288. str_ansi:=str_wide;
  289. if str_wide = str_ansi then
  290. WriteLn('Success.')
  291. else
  292. fail;
  293. Write('empty widestring -> ansistring...');
  294. str_wide := EMPTY_STRING;
  295. str_ansi:=str_wide;
  296. if str_wide = str_ansi then
  297. WriteLn('Success.')
  298. else
  299. fail;
  300. Write('big widestring -> ansistring...');
  301. str_wide := BIG_STRING;
  302. str_ansi:=str_wide;
  303. if str_wide = str_ansi then
  304. WriteLn('Success.')
  305. else
  306. fail;
  307. Write('huge widestring -> ansistring...');
  308. str_wide := HUGE_STRING;
  309. str_ansi:=str_wide;
  310. if str_wide = str_ansi then
  311. WriteLn('Success.')
  312. else
  313. fail;
  314. end;
  315. procedure test_short_to_wide;
  316. begin
  317. {************************************************************************}
  318. { shortstring -> widestring }
  319. {************************************************************************}
  320. WriteLn('Test shortstring -> widestring');
  321. Write('small shortstring -> widestring...');
  322. { shortstring -> widestring }
  323. str_short := SMALL_STRING;
  324. str_wide:=str_short;
  325. if str_short = str_wide then
  326. WriteLn('Success.')
  327. else
  328. fail;
  329. Write('empty shortstring -> widestring...');
  330. str_short := EMPTY_STRING;
  331. str_wide:=str_short;
  332. if str_short = str_wide then
  333. WriteLn('Success.')
  334. else
  335. fail;
  336. Write('big shortstring -> widestring...');
  337. str_short := BIG_STRING;
  338. str_wide:=str_short;
  339. if str_short = str_wide then
  340. WriteLn('Success.')
  341. else
  342. fail;
  343. Write('small shortstring -> widestring...');
  344. { shortstring -> widestring }
  345. s2 := SMALL_STRING;
  346. str_wide:=s2;
  347. if s2 = str_wide then
  348. WriteLn('Success.')
  349. else
  350. fail;
  351. Write('empty shortstring -> widestring...');
  352. s2 := EMPTY_STRING;
  353. str_wide:=s2;
  354. if s2 = str_wide then
  355. WriteLn('Success.')
  356. else
  357. fail;
  358. end;
  359. procedure test_ansi_to_wide;
  360. begin
  361. {************************************************************************}
  362. { ansistring -> widestring }
  363. {************************************************************************}
  364. WriteLn('Test ansistring -> widestring');
  365. Write('small ansistring -> widestring...');
  366. { ansistring -> widestring }
  367. str_ansi := SMALL_STRING;
  368. str_wide:=str_ansi;
  369. if str_ansi = str_wide then
  370. WriteLn('Success.')
  371. else
  372. fail;
  373. Write('empty ansistring -> widestring...');
  374. str_ansi := EMPTY_STRING;
  375. str_wide:=str_ansi;
  376. if str_ansi = str_wide then
  377. WriteLn('Success.')
  378. else
  379. fail;
  380. Write('big ansistring -> widestring...');
  381. str_ansi := BIG_STRING;
  382. str_wide:=str_ansi;
  383. if str_ansi = str_wide then
  384. WriteLn('Success.')
  385. else
  386. fail;
  387. Write('small ansistring -> widestring...');
  388. { ansistring -> widestring }
  389. s2 := SMALL_STRING;
  390. str_wide:=s2;
  391. if s2 = str_wide then
  392. WriteLn('Success.')
  393. else
  394. fail;
  395. Write('empty ansistring -> widestring...');
  396. s2 := EMPTY_STRING;
  397. str_wide:=s2;
  398. if s2 = str_wide then
  399. WriteLn('Success.')
  400. else
  401. fail;
  402. end;
  403. procedure test_wide_to_short;
  404. begin
  405. {************************************************************************}
  406. { widestring -> shortstring }
  407. {************************************************************************}
  408. WriteLn('Test widestring -> shortstring');
  409. { widestring -> shortstring }
  410. str_short := '';
  411. str_wide:='';
  412. str_wide := SMALL_STRING;
  413. Write('small widestring -> shortstring...');
  414. str_short:=str_wide;
  415. if str_short = str_wide then
  416. WriteLn('Success.')
  417. else
  418. fail;
  419. str_short := '';
  420. str_wide:='';
  421. str_wide := EMPTY_STRING;
  422. Write('empty widestring -> shortstring...');
  423. str_short:=str_wide;
  424. if str_short = str_wide then
  425. WriteLn('Success.')
  426. else
  427. fail;
  428. Write('big widestring -> shortstring...');
  429. str_short := '';
  430. str_wide:='';
  431. str_wide := BIG_STRING;
  432. str_short:=str_wide;
  433. if str_short = str_wide then
  434. WriteLn('Success.')
  435. else
  436. fail;
  437. Write('huge widestring -> shortstring...');
  438. str_wide := HUGE_STRING;
  439. str_short:=str_wide;
  440. if str_short <> str_wide then
  441. WriteLn('Success.')
  442. else
  443. fail;
  444. {}
  445. Write('small widestring -> shortstring...');
  446. s2 := '';
  447. str_wide:='';
  448. str_wide := SMALL_STRING;
  449. s2:=str_wide;
  450. if s2 = str_wide then
  451. WriteLn('Success.')
  452. else
  453. fail;
  454. Write('empty widestring -> shortstring...');
  455. s2 := '';
  456. str_wide:='';
  457. str_wide := EMPTY_STRING;
  458. s2:=str_wide;
  459. if s2 = str_wide then
  460. WriteLn('Success.')
  461. else
  462. fail;
  463. Write('big widestring -> shortstring...');
  464. s2 := '';
  465. str_wide:='';
  466. str_wide := BIG_STRING;
  467. s2:=str_wide;
  468. if s2 <> str_wide then
  469. WriteLn('Success.')
  470. else
  471. fail;
  472. Write('huge widestring -> shortstring...');
  473. s2 := '';
  474. str_wide:='';
  475. str_wide := HUGE_STRING;
  476. s2:=str_wide;
  477. if s2 <> str_wide then
  478. WriteLn('Success.')
  479. else
  480. fail;
  481. end;
  482. {$endif}
  483. Begin
  484. test_ansi_to_short;
  485. test_short_to_short;
  486. test_short_to_ansi;
  487. { requires widestring support }
  488. {$ifdef haswidestring}
  489. test_short_to_wide;
  490. test_ansi_to_wide;
  491. test_wide_to_short;
  492. test_wide_to_ansi;
  493. {$endif}
  494. End.