test.pp 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164
  1. {$mode delphi}
  2. {$codepage utf-8}
  3. {$namespace org.freepascal.test}
  4. {$j-}
  5. Unit test;
  6. interface
  7. const
  8. unitintconst = 3;
  9. unitfloatconst = 2.0;
  10. unitdoubleconst = 0.1;
  11. const
  12. tcl: longint = 4;
  13. type
  14. trec = record
  15. a,b,c,d,e: longint;
  16. end;
  17. const
  18. tcrec: trec = (a:1;b:2;c:3;d:4;e:5);
  19. type
  20. TMyClass = class
  21. const
  22. classintconst = 4;
  23. classfloatconst = 3.0;
  24. classdoubleconst = 0.3;
  25. classtcstringconst: unicodestring = 'abcdef';
  26. class var
  27. rec: trec;
  28. var
  29. intfield: jint;
  30. staticbytefield: jbyte; static;
  31. constructor create; overload;
  32. constructor create(l: longint);overload;
  33. constructor create(l1, l2: longint);overload;
  34. function sub(a1, a2: longint): longint;
  35. function test(l1, l2: longint): longint;
  36. class function staticmul3(l: longint): longint; static;
  37. procedure longboolobj(l: jlong; b: boolean; obj: tobject);
  38. procedure setintfield(l: jint);
  39. function getintfield: jint;
  40. property propintfield: jint read getintfield write setintfield;
  41. procedure setstaticbytefield(b: byte);
  42. function getstaticbytefield: byte;
  43. class procedure setstaticbytefieldstatic(b: byte); static;
  44. class function getstaticbytefieldstatic: byte; static;
  45. class procedure settestglobal(l: longint); static;
  46. class function gettestglobal: longint; static;
  47. end;
  48. tisinterface = interface
  49. end;
  50. tisclassbase = class
  51. procedure abstr; virtual; abstract;
  52. end;
  53. tisclassbase2 = class(tisclassbase)
  54. end;
  55. tisclass1 = class(tisclassbase2)
  56. type
  57. tisclass1nested = class(tisinterface)
  58. var
  59. anonrec: record c: char; end;
  60. type
  61. tisclass1nestedl2 = class
  62. anonrec: record l: longint; end;
  63. constructor create;
  64. function testl2: jint;
  65. end;
  66. constructor create;
  67. function testl1: jint;
  68. end;
  69. constructor create;
  70. procedure abstr; override;
  71. end;
  72. tisclass1ref = class of tisclass1;
  73. type
  74. tnestrec = record
  75. r: trec;
  76. arr: array[3..4] of byte;
  77. end;
  78. const
  79. tcnestrec: tnestrec = (r:(a:1;b:2;c:3;d:4;e:5);arr:(7,6));
  80. var
  81. anonrec: record s: string; end;
  82. function testset: jint;
  83. function testloop: longint;
  84. function testfloat: jint;
  85. function testcnvint1: longint;
  86. function testint2real: longint;
  87. function TestCmpListOneShort: longint;
  88. function TestCmpListTwoShort: longint;
  89. function TestCmpListOneWord: longint;
  90. function TestCmpListTwoWord: longint;
  91. function TestCmpListOneInt64: longint;
  92. function TestCmpListTwoInt64: longint;
  93. function TestCmpListThreeInt64: longint;
  94. function TestCmpListRangesOneShort: longint;
  95. function TestCmpListRangesTwoShort: longint;
  96. function TestCmpListRangesOneWord: longint;
  97. function TestCmpListRangesTwoWord: longint;
  98. function TestCmpListRangesThreeWord: longint;
  99. function TestCmpListRangesOneInt64: longint;
  100. function TestCmpListRangesTwoInt64: longint;
  101. function testsqr: longint;
  102. function testtrunc: longint;
  103. function testdynarr: longint;
  104. function testdynarr2: longint;
  105. function testbitcastintfloat: jint;
  106. function testis: longint;
  107. function testneg: longint;
  108. function testtry1: longint;
  109. function testtry2: longint;
  110. function testtryfinally1: longint;
  111. function testtryfinally2: longint;
  112. function testtryfinally3: longint;
  113. function testsmallarr1: longint;
  114. function testopenarr1: longint;
  115. function testopenarr2: longint;
  116. function testopenarr3: longint;
  117. function testopendynarr: longint;
  118. function testsmallarr2: longint;
  119. function testsmallarr3: longint;
  120. function testsmallarr4: longint;
  121. function testrec1: longint;
  122. function testopenarr1rec: longint;
  123. function testrec2: longint;
  124. function testunicodestring: JLString;
  125. function testunicodestring2: JLString;
  126. function testunicodestring3(a: unicodestring): unicodestring;
  127. function testunicodestring4(a: unicodestring): unicodestring;
  128. function testunicodestring5: unicodestring;
  129. function testunicodestring6: unicodestring;
  130. function testunicodestring7: unicodestring;
  131. procedure main(const args: array of string);
  132. var
  133. myrec: trec;
  134. implementation
  135. uses
  136. jdk15;
  137. { package visibility }
  138. var
  139. testglobal: jint;
  140. var
  141. funkyl: longint;
  142. function funky: longint;
  143. begin
  144. result:=funkyl;
  145. inc(funkyl);
  146. end;
  147. function testset: jint;
  148. var
  149. s,s2: set of 0..31;
  150. c1, c2: cardinal;
  151. const
  152. exit1: jint = 1;
  153. begin
  154. result:=0;
  155. s:=[3..6];
  156. s:=s+[10..20];
  157. if not([3..4]<=s) then
  158. exit(exit1);
  159. s:=s-[15..20];
  160. s2:=[15..20];
  161. if s2<=s then
  162. exit(2);
  163. s:=s+s2;
  164. if not(s2<=s) then
  165. exit(3);
  166. if s<=s2 then
  167. exit(4);
  168. c1:=1234;
  169. c2:=c1 mod 5;
  170. if c2<>4 then
  171. exit(5);
  172. end;
  173. function testloop: longint;
  174. var
  175. i,j: longint;
  176. const
  177. exit1: jint = 1;
  178. begin
  179. result:=0;
  180. i:=0;
  181. while i<10 do
  182. i:=i+1;
  183. if i<>10 then
  184. exit(exit1);
  185. i:=0;
  186. repeat
  187. i:=i+5;
  188. until i=20;
  189. if (i<20) or
  190. (i>20) then
  191. exit(2);
  192. j:=0;
  193. for i:=1 to 10 do
  194. j:=j+i;
  195. if (j<(i*(i+1) div 2)) or
  196. (j>(i*(i+1) div 2)) then
  197. exit(3);
  198. end;
  199. function testfloat: jint;
  200. var
  201. s1, s2: single;
  202. d1, d2: double;
  203. begin
  204. result:=0;
  205. s1:=0.5;
  206. s1:=s1+1.5;
  207. s2:=2.0;
  208. if (s1 < s2) or
  209. (s1 > s2) or
  210. (s1 <> s2) then
  211. exit(1);
  212. s1:=s1+s2;
  213. if s1<>4.0 then
  214. exit(2);
  215. s1:=s1-s2;
  216. if s1<>s2 then
  217. exit(3);
  218. s1:=s1*s2;
  219. if s1<>4.0 then
  220. exit(4);
  221. s1:=s1/s2;
  222. if s1<>s2 then
  223. exit(5);
  224. d1:=0.5;
  225. d1:=d1+1.5;
  226. d2:=2.0;
  227. if (d1 < d2) or
  228. (d1 > d2) or
  229. (d1 <> d2) then
  230. exit(6);
  231. d1:=d1+d2;
  232. if d1<>4.0 then
  233. exit(7);
  234. d1:=d1-d2;
  235. if d1<>d2 then
  236. exit(8);
  237. d1:=d1*d2;
  238. if d1<>4.0 then
  239. exit(9);
  240. d1:=d1/d2;
  241. if d1<>d2 then
  242. exit(10);
  243. end;
  244. function testcnvint1: longint;
  245. var
  246. tobyte : byte;
  247. toword : word;
  248. tolong : longint;
  249. {$ifndef tp}
  250. toint64 : int64;
  251. {$endif}
  252. b1 : boolean;
  253. bb1 : bytebool;
  254. wb1 : wordbool;
  255. lb1 : longbool;
  256. b2 : boolean;
  257. bb2 : bytebool;
  258. wb2 : wordbool;
  259. lb2 : longbool;
  260. begin
  261. result:=0;
  262. { left : LOC_REGISTER }
  263. { from : LOC_REFERENCE/LOC_REGISTER }
  264. b1 := TRUE;
  265. tobyte := byte(b1);
  266. if tobyte <> 1 then
  267. exit(1);
  268. b1 := FALSE;
  269. tobyte := byte(b1);
  270. if tobyte <> 0 then
  271. exit(2);
  272. b1 := TRUE;
  273. toword := word(b1);
  274. if toword <> 1 then
  275. exit(3);
  276. b1 := FALSE;
  277. toword := word(b1);
  278. if toword <> 0 then
  279. exit(4);
  280. b1 := TRUE;
  281. tolong := longint(b1);
  282. if tolong <> 1 then
  283. exit(5);
  284. b1 := FALSE;
  285. tolong := longint(b1);
  286. if tolong <> 0 then
  287. exit(6);
  288. bb1 := TRUE;
  289. tobyte := byte(bb1);
  290. if tobyte <> 255 then
  291. exit(7);
  292. bb1 := FALSE;
  293. tobyte := byte(bb1);
  294. if tobyte <> 0 then
  295. exit(8);
  296. bb1 := TRUE;
  297. toword := word(bb1);
  298. if toword <> 65535 then
  299. exit(9);
  300. bb1 := FALSE;
  301. toword := word(bb1);
  302. if toword <> 0 then
  303. exit(10);
  304. bb1 := TRUE;
  305. tolong := longint(bb1);
  306. if tolong <> -1 then
  307. exit(11);
  308. bb1 := FALSE;
  309. tolong := longint(bb1);
  310. if tolong <> 0 then
  311. exit(12);
  312. wb1 := TRUE;
  313. tobyte := byte(wb1);
  314. if tobyte <> 255 then
  315. exit(13);
  316. wb1 := FALSE;
  317. tobyte := byte(wb1);
  318. if tobyte <> 0 then
  319. exit(14);
  320. wb1 := TRUE;
  321. toword := word(wb1);
  322. if toword <> 65535 then
  323. exit(15);
  324. wb1 := FALSE;
  325. toword := word(wb1);
  326. if toword <> 0 then
  327. exit(16);
  328. wb1 := TRUE;
  329. tolong := longint(wb1);
  330. if tolong <> -1 then
  331. exit(17);
  332. wb1 := FALSE;
  333. tolong := longint(wb1);
  334. if tolong <> 0 then
  335. exit(18);
  336. {$ifndef tp}
  337. b1 := TRUE;
  338. toint64 :=int64(b1);
  339. if toint64 <> 1 then
  340. exit(19);
  341. b1 := FALSE;
  342. toint64 :=int64(b1);
  343. if toint64 <> 0 then
  344. exit(20);
  345. bb1 := TRUE;
  346. toint64 :=int64(bb1);
  347. if toint64 <> -1 then
  348. exit(21);
  349. bb1 := FALSE;
  350. toint64 :=int64(bb1);
  351. if toint64 <> 0 then
  352. exit(22);
  353. wb1 := TRUE;
  354. toint64 :=int64(wb1);
  355. if toint64 <> -1 then
  356. exit(23);
  357. wb1 := FALSE;
  358. toint64 :=int64(wb1);
  359. if toint64 <> 0 then
  360. exit(24);
  361. {$endif}
  362. lb1 := TRUE;
  363. tobyte := byte(lb1);
  364. if tobyte <> 255 then
  365. exit(25);
  366. lb1 := FALSE;
  367. tobyte := byte(lb1);
  368. if tobyte <> 0 then
  369. exit(26);
  370. lb1 := TRUE;
  371. toword := word(lb1);
  372. if toword <> 65535 then
  373. exit(27);
  374. lb1 := FALSE;
  375. toword := word(lb1);
  376. if toword <> 0 then
  377. exit(28);
  378. lb1 := TRUE;
  379. tolong := longint(lb1);
  380. if tolong <> -1 then
  381. exit(29);
  382. lb1 := FALSE;
  383. tolong := longint(lb1);
  384. if tolong <> 0 then
  385. exit(30);
  386. { left : LOC_REGISTER }
  387. { from : LOC_REFERENCE }
  388. wb1 := TRUE;
  389. b2 := wb1;
  390. if not b2 then
  391. exit(31);
  392. wb1 := FALSE;
  393. b2 := wb1;
  394. if b2 then
  395. exit(32);
  396. lb1 := TRUE;
  397. b2 := lb1;
  398. if not b2 then
  399. exit(33);
  400. lb1 := FALSE;
  401. b2 := lb1;
  402. if b2 then
  403. exit(34);
  404. wb1 := TRUE;
  405. bb2 := wb1;
  406. if not bb2 then
  407. exit(35);
  408. wb1 := FALSE;
  409. bb2 := wb1;
  410. if bb2 then
  411. exit(36);
  412. lb1 := TRUE;
  413. bb2 := lb1;
  414. if not bb2 then
  415. exit(37);
  416. lb1 := FALSE;
  417. bb2 := lb1;
  418. if bb2 then
  419. exit(38);
  420. b1 := TRUE;
  421. lb2 := b1;
  422. if not lb2 then
  423. exit(39);
  424. b1 := FALSE;
  425. lb2 := b1;
  426. if lb2 then
  427. exit(40);
  428. bb1 := TRUE;
  429. lb2 := bb1;
  430. if not lb2 then
  431. exit(41);
  432. bb1 := FALSE;
  433. lb2 := bb1;
  434. if lb2 then
  435. exit(42);
  436. { left : LOC_REGISTER }
  437. { from : LOC_JUMP }
  438. toword := 0;
  439. tobyte := 1;
  440. tobyte:=byte(toword > tobyte);
  441. if tobyte <> 0 then
  442. exit(43);
  443. toword := 2;
  444. tobyte := 1;
  445. tobyte:=byte(toword > tobyte);
  446. if tobyte <> 1 then
  447. exit(44);
  448. toword := 0;
  449. tobyte := 1;
  450. toword:=word(toword > tobyte);
  451. if toword <> 0 then
  452. exit(45);
  453. toword := 2;
  454. tobyte := 1;
  455. toword:=word(toword > tobyte);
  456. if toword <> 1 then
  457. exit(46);
  458. toword := 0;
  459. tobyte := 1;
  460. tolong:=longint(toword > tobyte);
  461. if tolong <> 0 then
  462. exit(47);
  463. toword := 2;
  464. tobyte := 1;
  465. tolong:=longint(toword > tobyte);
  466. if tolong <> 1 then
  467. exit(48);
  468. {$ifndef tp}
  469. toword := 0;
  470. tobyte := 1;
  471. toint64:=int64(toword > tobyte);
  472. if toint64 <> 0 then
  473. exit(49);
  474. toword := 2;
  475. tobyte := 1;
  476. toint64:=int64(toword > tobyte);
  477. if toint64 <> 1 then
  478. exit(50);
  479. {$endif}
  480. { left : LOC_REGISTER }
  481. { from : LOC_FLAGS }
  482. wb1 := TRUE;
  483. bb1 := FALSE;
  484. bb1 := (wb1 <> bb1);
  485. if not bb1 then
  486. exit(51);
  487. wb1 := FALSE;
  488. bb1 := FALSE;
  489. bb1 := (wb1 <> bb1);
  490. if bb1 then
  491. exit(52);
  492. lb1 := TRUE;
  493. bb1 := FALSE;
  494. bb1 := (bb1 = lb1);
  495. if bb1 then
  496. exit(53);
  497. lb1 := FALSE;
  498. bb1 := TRUE;
  499. bb1 := (bb1 <> lb1);
  500. if not bb1 then
  501. exit(54);
  502. lb1 := TRUE;
  503. bb1 := FALSE;
  504. wb1 := (bb1 = lb1);
  505. if wb1 then
  506. exit(55);
  507. lb1 := TRUE;
  508. bb1 := TRUE;
  509. wb1 := (bb1 = lb1);
  510. if not wb1 then
  511. exit(56);
  512. lb1 := TRUE;
  513. bb1 := FALSE;
  514. lb1 := (bb1 = lb1);
  515. if lb1 then
  516. exit(57);
  517. lb1 := FALSE;
  518. bb1 := FALSE;
  519. lb1 := (bb1 = lb1);
  520. if not lb1 then
  521. exit(58);
  522. bb1 := TRUE;
  523. bb2 := FALSE;
  524. lb1 := (bb1 <> bb2);
  525. if not lb1 then
  526. exit(59);
  527. bb1 := FALSE;
  528. bb2 := TRUE;
  529. lb1 := (bb1 = bb2);
  530. if lb1 then
  531. exit(60);
  532. end;
  533. function testint2real: longint;
  534. var
  535. l: longint;
  536. c: cardinal;
  537. i: int64;
  538. q: qword;
  539. s: single;
  540. d: double;
  541. begin
  542. result:=0;
  543. l:=-12345;
  544. c:=high(longint)+33;
  545. i:=-56789;
  546. q:=qword(high(int64))+48;
  547. s:=l;
  548. if s<>-12345 then
  549. exit(1);
  550. s:=c;
  551. if s<>high(longint)+33 then
  552. exit(2);
  553. s:=i;
  554. if s<>-56789 then
  555. exit(3);
  556. s:=q;
  557. if s<>qword(high(int64))+48 then
  558. exit(4);
  559. l:=-12345;
  560. c:=high(longint)+33;
  561. i:=-56789;
  562. q:=qword(high(int64))+48;
  563. d:=l;
  564. if d<>-12345 then
  565. exit(5);
  566. d:=c;
  567. if d<>high(longint)+33 then
  568. exit(6);
  569. d:=i;
  570. if d<>-56789 then
  571. exit(7);
  572. d:=q;
  573. if d<>qword(high(int64))+48 then
  574. exit(8);
  575. l:=123456789;
  576. c:=987654321;
  577. i:=high(cardinal)+12345;
  578. q:=12345;
  579. s:=l;
  580. if s<>123456789 then
  581. exit(11);
  582. s:=c;
  583. if s<>987654321 then
  584. exit(12);
  585. s:=i;
  586. if s<>high(cardinal)+12345 then
  587. exit(13);
  588. s:=q;
  589. if s<>12345 then
  590. exit(14);
  591. l:=123456789;
  592. c:=987654321;
  593. i:=high(cardinal)+12345;
  594. q:=12345;
  595. d:=l;
  596. if d<>123456789 then
  597. exit(16);
  598. d:=c;
  599. if d<>987654321 then
  600. exit(17);
  601. d:=i;
  602. if d<>high(cardinal)+12345 then
  603. exit(18);
  604. d:=q;
  605. if d<>12345 then
  606. exit(19);
  607. end;
  608. { low = high }
  609. function TestCmpListOneShort: longint;
  610. var
  611. s: smallint;
  612. failed :boolean;
  613. begin
  614. s := -12;
  615. failed := true;
  616. case s of
  617. -12 : failed := false;
  618. -10 : ;
  619. 3 : ;
  620. else
  621. end;
  622. if failed then
  623. result:=1
  624. else
  625. result:=0;
  626. end;
  627. { low = high }
  628. function TestCmpListTwoShort: longint;
  629. var
  630. s: smallint;
  631. failed :boolean;
  632. begin
  633. s := 30000;
  634. failed := true;
  635. case s of
  636. -12 : ;
  637. -10 : ;
  638. 3 : ;
  639. else
  640. failed := false;
  641. end;
  642. if failed then
  643. result:=1
  644. else
  645. result:=0;
  646. end;
  647. { low = high }
  648. function TestCmpListOneWord: longint;
  649. var
  650. s: word;
  651. failed :boolean;
  652. begin
  653. s := 12;
  654. failed := true;
  655. case s of
  656. 12 : failed := false;
  657. 10 : ;
  658. 3 : ;
  659. end;
  660. if failed then
  661. result:=1
  662. else
  663. result:=0;
  664. end;
  665. { low = high }
  666. function TestCmpListTwoWord: longint;
  667. var
  668. s: word;
  669. failed :boolean;
  670. begin
  671. s := 30000;
  672. failed := true;
  673. case s of
  674. 0 : ;
  675. 512 : ;
  676. 3 : ;
  677. else
  678. failed := false;
  679. end;
  680. if failed then
  681. result:=1
  682. else
  683. result:=0;
  684. end;
  685. { low = high }
  686. function TestCmpListOneInt64: longint;
  687. var
  688. s: int64;
  689. failed :boolean;
  690. begin
  691. s := 3000000;
  692. failed := true;
  693. case s of
  694. 3000000 : failed := false;
  695. 10 : ;
  696. 3 : ;
  697. end;
  698. if failed then
  699. result:=1
  700. else
  701. result:=0;
  702. end;
  703. { low = high }
  704. function TestCmpListTwoInt64: longint;
  705. var
  706. s: int64;
  707. failed :boolean;
  708. begin
  709. s := 30000;
  710. failed := true;
  711. case s of
  712. 0 : ;
  713. 512 : ;
  714. 3 : ;
  715. else
  716. failed := false;
  717. end;
  718. if failed then
  719. result:=1
  720. else
  721. result:=0;
  722. end;
  723. { low = high }
  724. function TestCmpListThreeInt64: longint;
  725. var
  726. s: int64;
  727. l : longint;
  728. failed :boolean;
  729. begin
  730. l:=3000000;
  731. s := (int64(l) shl 32);
  732. failed := true;
  733. case s of
  734. (int64(3000000) shl 32) : failed := false;
  735. 10 : ;
  736. 3 : ;
  737. end;
  738. if failed then
  739. result:=1
  740. else
  741. result:=0;
  742. end;
  743. function TestCmpListRangesOneShort: longint;
  744. var
  745. s: smallint;
  746. failed :boolean;
  747. begin
  748. s := -12;
  749. failed := true;
  750. case s of
  751. -12..-8 : failed := false;
  752. -7 : ;
  753. 3 : ;
  754. else
  755. end;
  756. if failed then
  757. result:=1
  758. else
  759. result:=0;
  760. end;
  761. function TestCmpListRangesTwoShort: longint;
  762. var
  763. s: smallint;
  764. failed :boolean;
  765. begin
  766. s := 30000;
  767. failed := true;
  768. case s of
  769. -12..-8 : ;
  770. -7 : ;
  771. 3 : ;
  772. else
  773. failed := false;
  774. end;
  775. if failed then
  776. result:=1
  777. else
  778. result:=0;
  779. end;
  780. { low = high }
  781. function TestCmpListRangesOneWord: longint;
  782. var
  783. s: word;
  784. failed :boolean;
  785. begin
  786. s := 12;
  787. failed := true;
  788. case s of
  789. 12..13 : failed := false;
  790. 10 : ;
  791. 3..7 : ;
  792. end;
  793. if failed then
  794. result:=1
  795. else
  796. result:=0;
  797. end;
  798. { low = high }
  799. function TestCmpListRangesTwoWord: longint;
  800. var
  801. s: word;
  802. failed :boolean;
  803. begin
  804. s := 30000;
  805. failed := true;
  806. case s of
  807. 0..2 : ;
  808. 3..29999 : ;
  809. else
  810. failed := false;
  811. end;
  812. if failed then
  813. result:=1
  814. else
  815. result:=0;
  816. end;
  817. function TestCmpListRangesThreeWord: longint;
  818. var
  819. s: word;
  820. failed :boolean;
  821. begin
  822. s := 3;
  823. failed := true;
  824. case s of
  825. 12..13 : ;
  826. 10 : ;
  827. 3..7 : failed := false;
  828. end;
  829. if failed then
  830. result:=1
  831. else
  832. result:=0;
  833. end;
  834. { low = high }
  835. function TestCmpListRangesOneInt64: longint;
  836. var
  837. s: int64;
  838. failed :boolean;
  839. begin
  840. s := 3000000;
  841. failed := true;
  842. case s of
  843. 11..3000000 : failed := false;
  844. 10 : ;
  845. 0..2 : ;
  846. end;
  847. if failed then
  848. result:=1
  849. else
  850. result:=0;
  851. end;
  852. { low = high }
  853. function TestCmpListRangesTwoInt64: longint;
  854. var
  855. s: int64;
  856. failed :boolean;
  857. begin
  858. s := 30000;
  859. failed := true;
  860. case s of
  861. 513..10000 : ;
  862. 512 : ;
  863. 0..3 : ;
  864. else
  865. failed := false;
  866. end;
  867. if failed then
  868. result:=1
  869. else
  870. result:=0;
  871. end;
  872. function testsqr: longint;
  873. var
  874. s1, s2: single;
  875. d1, d2: double;
  876. begin
  877. result:=0;
  878. s1:=25.0;
  879. s2:=sqr(s1);
  880. if s2<>625.0 then
  881. exit(1);
  882. d2:=sqr(s1);
  883. if d2<>625.0 then
  884. exit(2);
  885. d1:=7.0;
  886. d2:=sqr(d1);
  887. if d2<>49.0 then
  888. exit(3);
  889. d2:=sqr(d1);
  890. if d2<>49.0 then
  891. exit(4);
  892. end;
  893. function testtrunc: longint;
  894. var
  895. s1: single;
  896. d1: double;
  897. l: longint;
  898. i: int64;
  899. begin
  900. result:=0;
  901. s1:=123.99;
  902. l:=trunc(s1);
  903. if l<>123 then
  904. exit(1);
  905. i:=trunc(s1);
  906. if i<>123 then
  907. exit(2);
  908. d1:=67533.345923;
  909. l:=trunc(d1);
  910. if l<>67533 then
  911. exit(3);
  912. i:=trunc(d1);
  913. if i<>67533 then
  914. exit(4);
  915. end;
  916. function testdynarr: longint;
  917. type
  918. TReal1DArray = array of Double;
  919. TReal2DArray = array of array of Double;
  920. var
  921. MaxMN : Integer;
  922. PassCount : Integer;
  923. Threshold : Double;
  924. AEffective : TReal2DArray;
  925. AParam : TReal2DArray;
  926. XE : TReal1DArray;
  927. B : TReal1DArray;
  928. N : Integer;
  929. Pass : Integer;
  930. I : Integer;
  931. J : Integer;
  932. CntS : Integer;
  933. CntU : Integer;
  934. CntT : Integer;
  935. CntM : Integer;
  936. WasErrors : Boolean;
  937. IsUpper : Boolean;
  938. IsTrans : Boolean;
  939. IsUnit : Boolean;
  940. V : Double;
  941. S : Double;
  942. begin
  943. SetLength(AEffective, 2, 2); // crash occurs at this line
  944. WasErrors := False;
  945. MaxMN := 10;
  946. PassCount := 5;
  947. N:=2;
  948. isupper:=false;
  949. isunit:=true;
  950. istrans:=false;
  951. while N<=MaxMN do
  952. begin
  953. for i:=low(aeffective) to pred(length(aeffective)) do
  954. for j:=low(aeffective[i]) to pred(length(aeffective[i])) do
  955. aeffective[i,j]:=i*10+j;
  956. SetLength(AEffective, N+1, N+1);
  957. for i:=low(aeffective) to pred(length(aeffective))-1 do
  958. for j:=low(aeffective[i]) to pred(length(aeffective[i]))-1 do
  959. if aeffective[i,j]<>i*10+j then
  960. begin
  961. result:=-1;
  962. exit;
  963. end;
  964. for i:=low(aeffective) to pred(length(aeffective))-1 do
  965. if aeffective[i,pred(length(aeffective[i]))]<>0 then
  966. begin
  967. result:=-2;
  968. exit;
  969. end;
  970. Inc(N);
  971. end;
  972. { check shallow copy }
  973. AParam:=aeffective;
  974. aeffective[1,1]:=123;
  975. if AParam[1,1]<>123 then
  976. exit(-3);
  977. result:=0;
  978. end;
  979. function testdynarr2: longint;
  980. type
  981. tstaticarr = array[0..1] of longint;
  982. tstaticarr2 = array[0..1] of array of array of longint;
  983. var
  984. a,b: array of array of tstaticarr;
  985. c,d: tstaticarr2;
  986. w: word;
  987. arrb: array of byte;
  988. arrc: array of char;
  989. arrw: array of word;
  990. arrwc: array of unicodechar;
  991. arrd: array of dword;
  992. arrq: array of qword;
  993. arra: array of ansistring;
  994. arrs: array of shortstring;
  995. begin
  996. setlength(a,2,2);
  997. a[0,0,0]:=1;
  998. b:=a;
  999. a[0,0,1]:=1;
  1000. funkyl:=1;
  1001. setlength(a[funky],35);
  1002. if b[0,0,0]<>1 then
  1003. exit(1);
  1004. if b[0,0,1]<>1 then
  1005. exit(2);
  1006. if length(b[1])<>35 then
  1007. exit(3);
  1008. setlength(c[0],2,2);
  1009. d:=c;
  1010. c[0,0,0]:=1;
  1011. setlength(c[1],42);
  1012. if d[0,0,0]<>1 then
  1013. exit(4);
  1014. if length(d[1])<>0 then
  1015. exit(5);
  1016. b[1,0,0]:=555;
  1017. a:=copy(b,1,1);
  1018. if length(a)<>1 then
  1019. exit(6);
  1020. if a[0,0,0]<>555 then
  1021. exit(7);
  1022. setlength(arrb,4);
  1023. if length(arrb)<>4 then
  1024. exit(8);
  1025. for w:=low(arrb) to high(arrb) do
  1026. if arrb[w]<>0 then
  1027. exit(9);
  1028. setlength(arrc,32);
  1029. if length(arrc)<>32 then
  1030. exit(10);
  1031. for w:=low(arrc) to high(arrc) do
  1032. if arrc[w]<>#0 then
  1033. exit(11);
  1034. setlength(arrw,666);
  1035. if length(arrw)<>666 then
  1036. exit(11);
  1037. for w:=low(arrw) to high(arrw) do
  1038. if arrw[w]<>0 then
  1039. exit(12);
  1040. setlength(arrwc,12346);
  1041. if length(arrwc)<>12346 then
  1042. exit(13);
  1043. for w:=low(arrwc) to high(arrwc) do
  1044. if arrwc[w]<>#0 then
  1045. exit(14);
  1046. setlength(arrd,20000);
  1047. if length(arrd)<>20000 then
  1048. exit(15);
  1049. for w:=low(arrd) to high(arrd) do
  1050. if arrd[w]<>0 then
  1051. exit(16);
  1052. setlength(arrq,21532);
  1053. if length(arrq)<>21532 then
  1054. exit(17);
  1055. for w:=low(arrq) to high(arrq) do
  1056. if arrq[w]<>0 then
  1057. exit(18);
  1058. setlength(arra,21533);
  1059. if length(arra)<>21533 then
  1060. exit(19);
  1061. for w:=low(arra) to high(arra) do
  1062. if arra[w]<>'' then
  1063. exit(20);
  1064. setlength(arrs,21534);
  1065. if length(arrs)<>21534 then
  1066. exit(21);
  1067. for w:=low(arrs) to high(arrs) do
  1068. if arrs[w]<>'' then
  1069. exit(12);
  1070. result:=0;
  1071. end;
  1072. function testbitcastintfloat: jint;
  1073. var
  1074. f: jfloat;
  1075. d: jdouble;
  1076. i: jint;
  1077. l: jlong;
  1078. begin
  1079. result:=-1;
  1080. f:=123.125;
  1081. i:=jint(f);
  1082. f:=1.0;
  1083. f:=jfloat(i);
  1084. if f<>123.125 then
  1085. exit;
  1086. result:=-2;
  1087. d:=9876.0625;
  1088. l:=jlong(d);
  1089. d:=1.0;
  1090. d:=jdouble(l);
  1091. if d<>9876.0625 then
  1092. exit;
  1093. result:=0;
  1094. end;
  1095. { ********************** Is test ******************** }
  1096. type
  1097. tisclass2 = class(tisclass1)
  1098. constructor create;
  1099. end;
  1100. constructor tisclass1.create;
  1101. begin
  1102. end;
  1103. constructor tisclass1.tisclass1nested.create;
  1104. begin
  1105. anonrec.c:='x';
  1106. end;
  1107. function tisclass1.tisclass1nested.testl1: jint;
  1108. begin
  1109. if anonrec.c='x' then
  1110. result:=12345
  1111. else
  1112. result:=-1;
  1113. end;
  1114. constructor tisclass1.tisclass1nested.tisclass1nestedl2.create;
  1115. begin
  1116. anonrec.l:=961;
  1117. end;
  1118. function tisclass1.tisclass1nested.tisclass1nestedl2.testl2: jint;
  1119. begin
  1120. if anonrec.l=961 then
  1121. result:=42
  1122. else
  1123. result:=-1;
  1124. end;
  1125. procedure tisclass1.abstr;
  1126. begin
  1127. end;
  1128. constructor tisclass2.create;
  1129. begin
  1130. end;
  1131. function testispara(cref: tisclass1ref): longint;
  1132. begin
  1133. if cref<>tisclass2 then
  1134. result:=14;
  1135. result:=0;
  1136. end;
  1137. function testis: longint;
  1138. var
  1139. myclass1 : tisclass1;
  1140. myclass2 : tisclass2;
  1141. nested1 : tisclass1.tisclass1nested;
  1142. nested2 : tisclass1.tisclass1nested.tisclass1nestedl2;
  1143. myclassref : tisclass1ref;
  1144. begin
  1145. { create class instance }
  1146. myclass1:=tisclass1.create;
  1147. myclass2:=tisclass2.create;
  1148. {if myclass1 is tisclass1 }
  1149. if not(myclass1 is tisclass1) then
  1150. exit(1);
  1151. if (myclass1 is tisclass2) then
  1152. exit(2);
  1153. if not (myclass2 is tisclass2) then
  1154. exit(3);
  1155. if (myclass1 is tisclass2) then
  1156. exit(4);
  1157. nested1:=tisclass1.tisclass1nested.create;
  1158. nested2:=tisclass1.tisclass1nested.tisclass1nestedl2.create;
  1159. if not(nested1 is tisclass1.tisclass1nested) then
  1160. exit(5);
  1161. if nested1.testl1<>12345 then
  1162. exit(6);
  1163. if not(nested2 is tisclass2.tisclass1nested.tisclass1nestedl2) then
  1164. exit(7);
  1165. if nested2.testl2<>42 then
  1166. exit(8);
  1167. {$ifndef oldcomp}
  1168. myclassref:=tisclass1;
  1169. if not(myclass1 is myclassref) then
  1170. exit(10);
  1171. if not(myclass2 is myclassref) then
  1172. exit(11);
  1173. myclassref:=tisclass2;
  1174. if (myclass1 is myclassref) then
  1175. exit(12);
  1176. if not(myclass2 is myclassref) then
  1177. exit(13);
  1178. myclass1:=myclass2;
  1179. myclass1.abstr;
  1180. myclass2:=tisclass2(myclass1 as myclassref);
  1181. result:=testispara(tisclass2);
  1182. if result<>0 then
  1183. exit(14);
  1184. if not(nested1 is tisinterface) then
  1185. exit(15);
  1186. if nested2 is tisinterface then
  1187. exit(16);
  1188. {$endif}
  1189. result:=0;
  1190. end;
  1191. function testneg: longint;
  1192. var
  1193. b: shortint;
  1194. l: longint;
  1195. i: int64;
  1196. s: single;
  1197. d: double;
  1198. begin
  1199. b:=1;
  1200. b:=-b;
  1201. if b<>-1 then
  1202. exit(1);
  1203. l:=-1234567;
  1204. l:=-l;
  1205. if l<>1234567 then
  1206. exit(2);
  1207. i:=-123456789012345;
  1208. i:=-i;
  1209. if i<>123456789012345 then
  1210. exit(3);
  1211. s:=123.5;
  1212. s:=-s;
  1213. if s<>-123.5 then
  1214. exit(4);
  1215. d:=-4567.78;
  1216. d:=-d;
  1217. if d<>4567.78 then
  1218. exit(5);
  1219. result:=0;
  1220. end;
  1221. { ******************** End Is test ****************** }
  1222. { ****************** Exception test ***************** }
  1223. function testtry1: longint;
  1224. begin
  1225. result:=-1;
  1226. try
  1227. raise JLException.create;
  1228. except
  1229. result:=0;
  1230. end;
  1231. end;
  1232. function testtry2: longint;
  1233. begin
  1234. result:=-1;
  1235. try
  1236. raise JLException.create;
  1237. except
  1238. on JLException do
  1239. result:=0;
  1240. else
  1241. result:=-2
  1242. end;
  1243. if result<>0 then
  1244. exit;
  1245. result:=-3;
  1246. try
  1247. try
  1248. raise JLException.create;
  1249. except
  1250. result:=-4;
  1251. raise
  1252. end;
  1253. except
  1254. on JLException do
  1255. if result=-4 then
  1256. result:=0;
  1257. end;
  1258. end;
  1259. function testtryfinally1: longint;
  1260. begin
  1261. result:=-1;
  1262. try
  1263. try
  1264. try
  1265. raise JLException.create;
  1266. except
  1267. on JLException do
  1268. begin
  1269. result:=1;
  1270. raise;
  1271. end
  1272. else
  1273. result:=-2
  1274. end;
  1275. finally
  1276. if result=1 then
  1277. result:=0;
  1278. end;
  1279. except
  1280. on JLException do
  1281. if result<>0 then
  1282. raise
  1283. end;
  1284. end;
  1285. function testtryfinally2: longint;
  1286. var
  1287. i,j: longint;
  1288. check1, check2: byte;
  1289. begin
  1290. j:=0;
  1291. check1:=0;
  1292. check2:=0;
  1293. result:=-1;
  1294. try
  1295. for i:=1 to 10 do
  1296. try
  1297. inc(j);
  1298. if j=1 then
  1299. begin
  1300. inc(check1);
  1301. continue;
  1302. end;
  1303. if j=2 then
  1304. begin
  1305. inc(check2);
  1306. break;
  1307. end;
  1308. finally
  1309. if j=1 then
  1310. inc(check1);
  1311. if j=2 then
  1312. inc(check2);
  1313. end;
  1314. finally
  1315. if check1<>2 then
  1316. result:=-1
  1317. else if check2<>2 then
  1318. result:=-2
  1319. else if j<>2 then
  1320. result:=-3
  1321. else
  1322. result:=0;
  1323. end;
  1324. end;
  1325. function testtryfinally3: longint;
  1326. var
  1327. i,j: longint;
  1328. check1, check2: byte;
  1329. begin
  1330. j:=0;
  1331. check1:=0;
  1332. check2:=0;
  1333. result:=-1;
  1334. try
  1335. for i:=1 to 10 do
  1336. try
  1337. inc(j);
  1338. if j=1 then
  1339. begin
  1340. inc(check1);
  1341. continue;
  1342. end;
  1343. if j=2 then
  1344. begin
  1345. inc(check2);
  1346. exit;
  1347. end;
  1348. finally
  1349. if j=1 then
  1350. inc(check1);
  1351. if j=2 then
  1352. inc(check2);
  1353. end;
  1354. finally
  1355. if check1<>2 then
  1356. result:=-10
  1357. else if check2<>2 then
  1358. result:=-20
  1359. else if j<>2 then
  1360. result:=-30
  1361. else
  1362. result:=0;
  1363. end;
  1364. end;
  1365. { **************** End Exception test *************** }
  1366. { **************** Begin array test *************** }
  1367. function testsmallarr1: longint;
  1368. type
  1369. tarr = array[4..6] of longint;
  1370. var
  1371. a1,a2: tarr;
  1372. a3,a4: array[1..2,3..5] of tarr;
  1373. i,j,k: longint;
  1374. begin
  1375. a1[4]:=1;
  1376. a1[5]:=2;
  1377. a1[6]:=3;
  1378. { plain copy }
  1379. a2:=a1;
  1380. if (a2[4]<>1) or
  1381. (a2[5]<>2) or
  1382. (a2[6]<>3) then
  1383. exit(1);
  1384. { has to be deep copy }
  1385. a1[5]:=255;
  1386. if a2[5]<>2 then
  1387. exit(2);
  1388. { copy to multi-dim array }
  1389. a3[1,4]:=a1;
  1390. if (a3[1,4,4]<>1) or
  1391. (a3[1,4,5]<>255) or
  1392. (a3[1,4,6]<>3) then
  1393. exit(3);
  1394. i:=2;
  1395. j:=3;
  1396. a1[4]:=38;
  1397. a1[5]:=39;
  1398. a1[6]:=40;
  1399. { copy to multi-dim array }
  1400. a3[i,j]:=a1;
  1401. if (a3[i,j,4]<>38) or
  1402. (a3[i,j,5]<>39) or
  1403. (a3[i,j,6]<>40) then
  1404. exit(4);
  1405. { copy multi-dim array to multi-dim array }
  1406. a4:=a3;
  1407. { check for deep copy }
  1408. for i:=low(a3) to high(a3) do
  1409. for j:=low(a3[i]) to high(a3[i]) do
  1410. for k:=low(a3[i,j]) to high(a3[i,j]) do
  1411. a3[i,j,k]:=-1;
  1412. if (a4[1,4,4]<>1) or
  1413. (a4[1,4,5]<>255) or
  1414. (a4[1,4,6]<>3) then
  1415. exit(5);
  1416. i:=2;
  1417. j:=3;
  1418. if (a4[i,j,4]<>38) or
  1419. (a4[i,j,5]<>39) or
  1420. (a4[i,j,6]<>40) then
  1421. exit(6);
  1422. result:=0;
  1423. end;
  1424. function testopenarrval(a1: longint; arr: array of jfloat; a2: longint): longint;
  1425. var
  1426. i: longint;
  1427. begin
  1428. result:=a1+length(arr)+trunc(arr[high(arr)])+a2;
  1429. for i:=low(arr) to high(arr) do
  1430. arr[i]:=1.0;
  1431. end;
  1432. function testopenarrconst(a1: longint; const arr: array of jfloat; a2: longint): longint;
  1433. begin
  1434. result:=a1+length(arr)+trunc(arr[high(arr)])+a2;
  1435. end;
  1436. function testopenarrvar(a1: longint; var arr: array of jfloat; a2: longint): longint;
  1437. begin
  1438. result:=a1+length(arr)+trunc(arr[high(arr)])+a2;
  1439. arr[0]:=3.0;
  1440. end;
  1441. function testopenarr1: longint;
  1442. var
  1443. arr: array[4..10] of jfloat;
  1444. i: longint;
  1445. begin
  1446. result:=0;
  1447. arr[10]:=2.0;
  1448. if testopenarrval(1,arr,3)<>13 then
  1449. exit(1);
  1450. for i:=4 to 9 do
  1451. if arr[i]<>0.0 then
  1452. exit(2);
  1453. if arr[10]<>2.0 then
  1454. exit(3);
  1455. if testopenarrconst(2,arr,4)<>15 then
  1456. exit(4);
  1457. if testopenarrvar(3,arr,5)<>17 then
  1458. exit(5);
  1459. if arr[4]<>3.0 then
  1460. exit(6);
  1461. end;
  1462. type
  1463. tarrdynarr = array[1..10,1..4] of array of array of byte;
  1464. function testoutopenarrdyn(out arr: array of tarrdynarr): longint;
  1465. var
  1466. i, j, k: longint;
  1467. begin
  1468. for i:=low(arr) to high(arr) do
  1469. for j:=low(arr[i]) to high(arr[i]) do
  1470. for k:=low(arr[i][j]) to high(arr[i][j]) do
  1471. begin
  1472. if length(arr[i][j,k])<>0 then
  1473. exit(-1);
  1474. setlength(arr[i][j,k],j,k);
  1475. end;
  1476. result:=0;
  1477. end;
  1478. function testopenarr2: longint;
  1479. var
  1480. arr: array[20..30] of tarrdynarr;
  1481. dynarr: array of tarrdynarr;
  1482. i,j,k: longint;
  1483. barr, barr2: array of byte;
  1484. rarr: array of trec;
  1485. rarr2: array of array of trec;
  1486. begin
  1487. setlength(barr,4);
  1488. barr[1]:=4;
  1489. if barr[1]<>4 then
  1490. exit(-40);
  1491. barr2:=copy(barr);
  1492. if barr2[1]<>4 then
  1493. exit(-50);
  1494. barr2[2]:=48;
  1495. if barr[2]=48 then
  1496. exit(-60);
  1497. setlength(rarr,5);
  1498. rarr[4].a:=135;
  1499. if rarr[4].a<>135 then
  1500. exit(-70);
  1501. setlength(rarr2,4,5);
  1502. rarr2[3,4].b:=124;
  1503. if rarr2[3,4].b<>124 then
  1504. exit(-80);
  1505. for i:=low(arr) to high(arr) do
  1506. for j:=low(arr[i]) to high(arr[i]) do
  1507. for k:=low(arr[i][j]) to high(arr[i][j]) do
  1508. begin
  1509. setlength(arr[i][j,k],20,20);
  1510. end;
  1511. result:=testoutopenarrdyn(arr);
  1512. if result<>0 then
  1513. exit;
  1514. for i:=low(arr) to high(arr) do
  1515. for j:=low(arr[i]) to high(arr[i]) do
  1516. for k:=low(arr[i][j]) to high(arr[i][j]) do
  1517. begin
  1518. if (length(arr[i][j,k])<>j) then
  1519. exit(-2);
  1520. if (length(arr[i][j,k][0])<>k) then
  1521. exit(-3);
  1522. if (length(arr[i][j,k][j-1])<>k) then
  1523. exit(-4);
  1524. end;
  1525. setlength(dynarr,31);
  1526. result:=testoutopenarrdyn(dynarr);
  1527. for i:=low(arr) to high(arr) do
  1528. for j:=low(arr[i]) to high(arr[i]) do
  1529. for k:=low(arr[i][j]) to high(arr[i][j]) do
  1530. begin
  1531. if (length(arr[i][j,k])<>j) then
  1532. exit(-5);
  1533. if (length(arr[i][j,k][0])<>k) then
  1534. exit(-6);
  1535. if (length(arr[i][j,k][j-1])<>k) then
  1536. exit(-7);
  1537. end;
  1538. end;
  1539. function testopenarr3: longint;
  1540. var
  1541. arr: array[4..10] of jfloat;
  1542. i: longint;
  1543. begin
  1544. result:=0;
  1545. arr[10]:=2.0;
  1546. if testopenarrval(1,[1.0,2.0,3.0,4.0,5.0,6.0,2.0],3)<>13 then
  1547. exit(1);
  1548. if testopenarrconst(2,[1.0,2.0,3.0,4.0,5.0,6.0,7.0],4)<>20 then
  1549. exit(2);
  1550. end;
  1551. type
  1552. ByteArray = array of byte;
  1553. procedure FillChar(var X: Array of Byte; Count: integer; Value: byte; FirstIndex: integer);
  1554. var
  1555. i: integer;
  1556. y: bytearray;
  1557. begin
  1558. for i := FirstIndex to (FirstIndex + Count) - 1 do
  1559. X[i] := Value;
  1560. end;
  1561. function Err : ByteArray;
  1562. begin
  1563. SetLength(Result, 10);
  1564. FillChar(Result, Length(Result)-2, 1, 2); // !!!!
  1565. end;
  1566. function testopendynarr: longint;
  1567. var
  1568. x: bytearray;
  1569. i: longint;
  1570. begin
  1571. x:=err;
  1572. for i:=0 to 1 do
  1573. if x[i]<>0 then
  1574. exit(1);
  1575. for i:=2 to high(x) do
  1576. if x[i]<>1 then
  1577. exit(2);
  1578. result:=0;
  1579. end;
  1580. type
  1581. tdoublearray10 = array[1..10] of jdouble;
  1582. function testarrval(arr: tdoublearray10): double;
  1583. var
  1584. i: longint;
  1585. begin
  1586. result:=0.0;
  1587. for i:=low(arr) to high(arr) do
  1588. begin
  1589. result:=result+arr[i];
  1590. arr[i]:=-1.0;
  1591. end;
  1592. end;
  1593. function testsmallarr2: longint;
  1594. var
  1595. arr: tdoublearray10;
  1596. i: longint;
  1597. barr1,barr2: array[1..2] of byte;
  1598. begin
  1599. result:=0;
  1600. for i:=low(arr) to high(arr) do
  1601. arr[i]:=i;
  1602. if testarrval(arr)<>(10*11 div 2) then
  1603. exit(1);
  1604. for i:=low(arr) to high(arr) do
  1605. if arr[i]<>i then
  1606. exit(2);
  1607. barr1[1]:=1;
  1608. barr1[2]:=2;
  1609. barr2:=barr1;
  1610. if barr2[1]<>1 then
  1611. exit(3);
  1612. if barr2[2]<>2 then
  1613. exit(4);
  1614. end;
  1615. type
  1616. tsmall2darr = array[1..10,5..9] of longint;
  1617. function smallarr2dfunc: tsmall2darr;
  1618. var
  1619. i, j: longint;
  1620. begin
  1621. for i:=low(result) to high(result) do
  1622. for j:=low(result[i]) to high(result[i]) do
  1623. result[i,j]:=i*(high(result[i])-low(result[i])+1)+(j-low(result[i]));
  1624. end;
  1625. function testsmallarr3: longint;
  1626. var
  1627. a: tsmall2darr;
  1628. begin
  1629. a:=smallarr2dfunc;
  1630. if a[1,5]<>5 then
  1631. exit(1);
  1632. if a[2,9]<>14 then
  1633. exit(2);
  1634. result:=0;
  1635. end;
  1636. function testoutarrdyn(out arr: tarrdynarr): longint;
  1637. var
  1638. i, j: longint;
  1639. begin
  1640. for i:=low(arr) to high(arr) do
  1641. for j:=low(arr[i]) to high(arr[i]) do
  1642. begin
  1643. if length(arr[i,j])<>0 then
  1644. exit(-1);
  1645. setlength(arr[i,j],i,j);
  1646. end;
  1647. result:=0;
  1648. end;
  1649. function testsmallarr4: longint;
  1650. var
  1651. arr: tarrdynarr;
  1652. i,j: longint;
  1653. begin
  1654. for i:=low(arr) to high(arr) do
  1655. for j:=low(arr[i]) to high(arr[i]) do
  1656. begin
  1657. setlength(arr[i,j],20,20);
  1658. end;
  1659. result:=testoutarrdyn(arr);
  1660. if result<>0 then
  1661. exit;
  1662. for i:=low(arr) to high(arr) do
  1663. for j:=low(arr[i]) to high(arr[i]) do
  1664. begin
  1665. if (length(arr[i,j])<>i) then
  1666. exit(-2);
  1667. if (length(arr[i,j][0])<>j) then
  1668. exit(-3);
  1669. if (length(arr[i,j][i-1])<>j) then
  1670. exit(-4);
  1671. end;
  1672. end;
  1673. function testrec1: longint;
  1674. var
  1675. r1, r2: trec;
  1676. begin
  1677. r1.a:=1;
  1678. r1.b:=2;
  1679. r1.c:=3;
  1680. r1.d:=4;
  1681. r1.e:=5;
  1682. if r1.a<>1 then
  1683. exit(1);
  1684. if r1.b<>2 then
  1685. exit(2);
  1686. if r1.c<>3 then
  1687. exit(3);
  1688. if r1.d<>4 then
  1689. exit(4);
  1690. if r1.e<>5 then
  1691. exit(5);
  1692. r2:=r1;
  1693. if r2.a<>1 then
  1694. exit(6);
  1695. if r2.b<>2 then
  1696. exit(7);
  1697. if r2.c<>3 then
  1698. exit(8);
  1699. if r2.d<>4 then
  1700. exit(9);
  1701. if r2.e<>5 then
  1702. exit(10);
  1703. r2.a:=10;
  1704. if r1.a<>1 then
  1705. exit(11);
  1706. result:=0;
  1707. end;
  1708. function testrec2: longint;
  1709. var
  1710. r1, r2: tnestrec;
  1711. begin
  1712. r1:=tcnestrec;
  1713. r1.r.a:=1;
  1714. r1.r.b:=2;
  1715. r1.r.c:=3;
  1716. r1.r.d:=4;
  1717. r1.r.e:=5;
  1718. r1.arr[4]:=6;
  1719. if r1.r.a<>1 then
  1720. exit(1);
  1721. if r1.r.b<>2 then
  1722. exit(2);
  1723. if r1.r.c<>3 then
  1724. exit(3);
  1725. if r1.r.d<>4 then
  1726. exit(4);
  1727. if r1.r.e<>5 then
  1728. exit(5);
  1729. if r1.arr[4]<>6 then
  1730. exit(12);
  1731. r2:=r1;
  1732. if r2.r.a<>1 then
  1733. exit(6);
  1734. if r2.r.b<>2 then
  1735. exit(7);
  1736. if r2.r.c<>3 then
  1737. exit(8);
  1738. if r2.r.d<>4 then
  1739. exit(9);
  1740. if r2.r.e<>5 then
  1741. exit(10);
  1742. if r1.arr[4]<>6 then
  1743. exit(13);
  1744. r2.r.a:=10;
  1745. r2.arr[4]:=7;
  1746. if r1.r.a<>1 then
  1747. exit(11);
  1748. if r1.arr[4]<>6 then
  1749. exit(14);
  1750. anonrec.s:='abcdef';
  1751. if anonrec.s<>'abcdef' then
  1752. exit(15);
  1753. result:=0;
  1754. end;
  1755. function testopenarrvalrec(a1: longint; arr: array of trec; a2: longint): longint;
  1756. var
  1757. i: longint;
  1758. begin
  1759. result:=a1+length(arr)+arr[high(arr)].a+a2;
  1760. for i:=low(arr) to high(arr) do
  1761. arr[i].a:=123;
  1762. end;
  1763. function testopenarrconstrec(a1: longint; const arr: array of trec; a2: longint): longint;
  1764. begin
  1765. result:=a1+length(arr)+arr[high(arr)].b+a2;
  1766. end;
  1767. function testopenarrvarrec(a1: longint; var arr: array of trec; a2: longint): longint;
  1768. begin
  1769. result:=a1+length(arr)+arr[high(arr)].c+a2;
  1770. arr[0].d:=987;
  1771. end;
  1772. function testopenarr1rec: longint;
  1773. var
  1774. arr: array[4..10] of trec;
  1775. i: longint;
  1776. begin
  1777. result:=0;
  1778. arr[10].a:=2;
  1779. arr[10].b:=2;
  1780. arr[10].c:=2;
  1781. arr[10].d:=2;
  1782. arr[10].e:=2;
  1783. if testopenarrvalrec(1,arr,3)<>13 then
  1784. exit(1);
  1785. for i:=4 to 9 do
  1786. if arr[i].a<>0.0 then
  1787. exit(2);
  1788. if arr[10].a<>2.0 then
  1789. exit(3);
  1790. if testopenarrconstrec(2,arr,4)<>15 then
  1791. exit(4);
  1792. if testopenarrvarrec(3,arr,5)<>17 then
  1793. exit(5);
  1794. if arr[4].d<>987 then
  1795. exit(6);
  1796. end;
  1797. function testunicodestring: JLString;
  1798. var
  1799. s1, s2: unicodestring;
  1800. sarr: array[0..0] of unicodestring;
  1801. begin
  1802. s1:='abc';
  1803. sarr[0]:=s1;
  1804. funkyl:=0;
  1805. if length(sarr[funky])<>3 then
  1806. begin
  1807. result:='';
  1808. exit;
  1809. end;
  1810. s2:=s1;
  1811. s2:='~ê∂êºîƒ~©¬';
  1812. result:=s2;
  1813. end;
  1814. function testunicodestring2: JLString;
  1815. begin
  1816. result:='\'#13#10'"';
  1817. end;
  1818. function testunicodestring3(a: unicodestring): unicodestring;
  1819. begin
  1820. result:=a+'def';
  1821. end;
  1822. function testunicodestring4(a: unicodestring): unicodestring;
  1823. begin
  1824. // JLSystem.fout.println(JLString('in testunicodestring4'));
  1825. // JLSystem.fout.println(JLString(a));
  1826. result:=a;
  1827. // JLSystem.fout.println(JLString(result));
  1828. result[2]:='x';
  1829. // JLSystem.fout.println(JLString(result));
  1830. result[3]:='2';
  1831. // JLSystem.fout.println(JLString(result));
  1832. end;
  1833. function testunicodestring5: unicodestring;
  1834. var
  1835. arr: array[0..3] of ansichar;
  1836. arr2: array[1..5] of ansichar;
  1837. c: ansichar;
  1838. wc: widechar;
  1839. begin
  1840. arr:='abc'#0;
  1841. arr2:='defgh';
  1842. c:='i';
  1843. wc:='j';
  1844. result:=arr+arr2;
  1845. result:=copy(result,1,length(result))+c;
  1846. result:=result+wc;
  1847. end;
  1848. function testunicodestring6: unicodestring;
  1849. const
  1850. tcstr: string = 'ab';
  1851. var
  1852. arr: array[0..3] of widechar;
  1853. arr2: array[1..5] of widechar;
  1854. swap: ansichar;
  1855. wc: widechar;
  1856. i: longint;
  1857. begin
  1858. arr:='ab';
  1859. arr2:='cdefg';
  1860. swap:='h';
  1861. wc:='i';
  1862. result:=arr+arr2+swap;
  1863. result:=result+wc;
  1864. end;
  1865. function testunicodestring7: unicodestring;
  1866. const
  1867. tcstr: string = 'ab';
  1868. var
  1869. arr: array[0..3] of unicodechar;
  1870. arr2: array[1..5] of unicodechar;
  1871. c: ansichar = 'h';
  1872. wc: unicodechar;
  1873. begin
  1874. funkyl:=1;
  1875. arr:=tcstr;
  1876. arr2:='cdefg';
  1877. wc:='i';
  1878. result:=arr+arr2;
  1879. result:=result+c;
  1880. result:=result+wc;
  1881. result[funky]:='x';
  1882. end;
  1883. { **************** End array test *************** }
  1884. constructor TMyClass.create;
  1885. begin
  1886. end;
  1887. constructor TMyClass.create(l: longint);
  1888. var
  1889. dummy: TMyClass;
  1890. begin
  1891. dummy:=TMyClass.create;
  1892. create(l,l);
  1893. end;
  1894. constructor TMyClass.create(l1,l2: longint);
  1895. begin
  1896. inherited create;
  1897. propintfield:=4;
  1898. if propintfield<>4 then
  1899. jlsystem.fout.println('WRONG!!!!!!!!!!!!!!!!!!!');
  1900. end;
  1901. function TMyClass.sub(a1, a2: longint): longint;
  1902. begin
  1903. result:=a1-a2;
  1904. end;
  1905. function TMyClass.test(l1, l2: longint): longint;
  1906. var
  1907. locall: longint;
  1908. localsub: TMyClass;
  1909. begin
  1910. localsub:=TMyClass.create(1245);
  1911. locall:=localsub.sub(l1,l2);
  1912. result:=locall+1;
  1913. if result>4 then
  1914. result:=-1;
  1915. end;
  1916. class function tmyclass.staticmul3(l: longint): longint; static;
  1917. begin
  1918. result:=l*3;
  1919. end;
  1920. procedure tmyclass.longboolobj(l: jlong; b: boolean; obj: tobject);
  1921. begin
  1922. l:=5;
  1923. b:=true;
  1924. obj:=nil;
  1925. end;
  1926. procedure tmyclass.setintfield(l: jint);
  1927. const
  1928. xxx: longint = 4;
  1929. begin
  1930. intfield:=l;
  1931. longboolobj(xxx,true,self);
  1932. end;
  1933. function tmyclass.getintfield: jint;
  1934. begin
  1935. result:=intfield;
  1936. end;
  1937. procedure tmyclass.setstaticbytefield(b: byte);
  1938. begin
  1939. staticbytefield:=b;
  1940. myrec.a:=b;
  1941. end;
  1942. function tmyclass.getstaticbytefield: byte;
  1943. begin
  1944. result:=staticbytefield;
  1945. end;
  1946. class procedure tmyclass.setstaticbytefieldstatic(b: byte);
  1947. begin
  1948. staticbytefield:=b;
  1949. end;
  1950. class function tmyclass.getstaticbytefieldstatic: byte;
  1951. begin
  1952. result:=staticbytefield;
  1953. end;
  1954. class procedure tmyclass.settestglobal(l: longint);
  1955. begin
  1956. testglobal:=l;
  1957. end;
  1958. class function tmyclass.gettestglobal: longint;
  1959. begin
  1960. result:=testglobal;
  1961. end;
  1962. procedure main(const args: array of string);
  1963. begin
  1964. JLSystem.fout.println('This is the entry point');
  1965. end;
  1966. begin
  1967. myrec.b:=1234;
  1968. TMyClass.rec.c:=5678;
  1969. end.