testjsonrtti.pas 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918
  1. unit testjsonrtti;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, fpcunit, testregistry, typinfo, fpjson,
  6. dateutils, testcomps, testjsondata, fpjsonrtti;
  7. type
  8. { TTestJSONStreamer }
  9. TTestJSONStreamer = class(TTestJSON)
  10. private
  11. FRJ : TJSONStreamer;
  12. FSR : TJSONObject;
  13. FToFree : TObject;
  14. FCalled : Boolean;
  15. procedure DoStreamProperty1(Sender: TObject; AObject: TObject; Info: PPropInfo; var Res: TJSONData);
  16. protected
  17. procedure SetUp; override;
  18. procedure TearDown; override;
  19. Procedure AssertEquals(AMessage : String; Expected,Actual : TJSONType); overload;
  20. Procedure AssertPropCount(ACount : Integer);
  21. Function AssertProperty(APropName : String; AType : TJSONType) : TJSONData;
  22. Procedure AssertProp(APropName : String; AValue : Boolean);
  23. Procedure AssertProp(APropName : String; AValue : Integer);
  24. procedure AssertProp(APropName : String; AValue: String);
  25. procedure AssertProp(APropName : String; AValue: TJSONFloat);
  26. procedure AssertProp(APropName : String; AValue : Array of String);
  27. procedure AssertProp(APropName : String; AValue : Array of Integer);
  28. function CreateVariantComp : TVariantComponent;
  29. procedure AssertNullProp(APropName : String);
  30. Function AssertObjectProp(APropName : String) : TJSONObject;
  31. Function AssertArrayProp(APropName : String) : TJSONArray;
  32. Function StreamObject(AObject : TObject) : TJSONObject;
  33. Property RJ : TJSONStreamer read FRJ;
  34. Property SR : TJSONObject Read FSR Write FSR;
  35. published
  36. procedure TestNil;
  37. procedure TestEmpty;
  38. procedure TestEmptyComponent;
  39. procedure TestWriteBoolean;
  40. procedure TestWriteInteger;
  41. procedure TestWriteString;
  42. procedure TestWriteFloat;
  43. procedure TestWriteFloat2;
  44. procedure TestWriteFloat3;
  45. procedure TestWriteFloat4;
  46. procedure TestWriteFloat5;
  47. procedure TestEnum1;
  48. procedure TestEnum2;
  49. Procedure TestSet1;
  50. Procedure TestSet2;
  51. Procedure TestSet3;
  52. Procedure TestSet4;
  53. Procedure TestObjectNil;
  54. Procedure TestComponentProp1;
  55. Procedure TestComponentProp2;
  56. Procedure TestCollectionProp1;
  57. Procedure TestCollectionProp2;
  58. Procedure TestPersistentProp1;
  59. Procedure TestStringsProp1;
  60. Procedure TestStringsProp2;
  61. procedure TestStringsProp3;
  62. procedure TestStringsProp4;
  63. procedure TestStringsArray;
  64. procedure TestStringsObject;
  65. procedure TestStringsStream1;
  66. procedure TestStringsStream2;
  67. procedure TestStringsStream3;
  68. procedure TestStringsStream4;
  69. procedure TestStringsStream5;
  70. procedure TestCollectionStream;
  71. procedure TestCollectionStream2;
  72. procedure TestOnStreamProperty;
  73. Procedure TestDateTimeProp;
  74. Procedure TestDateTimePropDefaultString;
  75. Procedure TestDateTimePropDefaultStringTime;
  76. Procedure TestDateTimeProp2;
  77. Procedure TestDateTimeProp3;
  78. procedure TestDateTimeProp4;
  79. procedure TestDateTimeProp5;
  80. procedure TestDateTimeProp6;
  81. procedure TestDateTimeProp7;
  82. Procedure TestVariantShortint;
  83. Procedure TestVariantbyte;
  84. Procedure TestVariantword;
  85. Procedure TestVariantsmallint;
  86. Procedure TestVariantinteger;
  87. Procedure TestVariantlongword;
  88. Procedure TestVariantint64;
  89. Procedure TestVariantqword;
  90. Procedure TestVariantsingle;
  91. Procedure TestVariantdouble;
  92. Procedure TestVariantCurrency;
  93. Procedure TestVariantString;
  94. Procedure TestVariantolestr;
  95. Procedure TestVariantboolean;
  96. Procedure TestVariantDate;
  97. procedure TestVariantDate2;
  98. Procedure TestVariantArray;
  99. Procedure TestMultipleProps;
  100. Procedure TestObjectToJSONString;
  101. Procedure TestStringsToJSONString;
  102. Procedure TestCollectionToJSONString;
  103. procedure TestTListToJSONString;
  104. Procedure TestChildren;
  105. Procedure TestChildren2;
  106. Procedure TestLowercase;
  107. end;
  108. { TTestJSONDeStreamer }
  109. TTestJSONDeStreamer = class(TTestJSON)
  110. private
  111. FDS : TJSONDeStreamer;
  112. FJD : TJSONData;
  113. FToFree : TObject;
  114. procedure DeStream(JSON: TJSONStringType; AObject: TObject);
  115. procedure DeStream(JSON: TJSONObject; AObject: TObject);
  116. procedure DoDateTimeFormat;
  117. Procedure DoNullError;
  118. protected
  119. procedure SetUp; override;
  120. procedure TearDown; override;
  121. Procedure AssertVarType(Msg : String; AVarType : TVarType; Const Variant : Variant);
  122. Property DS : TJSONDeStreamer Read FDS;
  123. Property JD : TJSONData Read FJD Write FJD;
  124. Property Tofree : TObject Read FToFree Write FToFree;
  125. published
  126. Procedure TestVariantInteger;
  127. Procedure TestVariantFloat;
  128. Procedure TestVariantInt64;
  129. Procedure TestVariantBoolean;
  130. Procedure TestVariantNull;
  131. Procedure TestVariantString;
  132. Procedure TestVariantArray;
  133. procedure TestEmpty;
  134. procedure TestNullError;
  135. procedure TestNull;
  136. procedure TestBoolean;
  137. procedure TestInteger;
  138. procedure TestIntegerCaseInsensitive;
  139. procedure TestIntegerCaseSensitive;
  140. procedure TestString;
  141. procedure TestFloat;
  142. procedure TestFloat2;
  143. procedure TestFloat3;
  144. procedure TestFloat4;
  145. procedure TestFloat5;
  146. procedure TestDateTime;
  147. procedure TestDateTimeFormat;
  148. procedure TestEnum1;
  149. procedure TestEnum2;
  150. Procedure TestSet1;
  151. Procedure TestSet2;
  152. Procedure TestSet3;
  153. Procedure TestSet4;
  154. Procedure TestVariantProp;
  155. procedure TestCollection;
  156. procedure TestCollection2;
  157. procedure TestCollection3;
  158. procedure TestCollection4;
  159. procedure TestCollection5;
  160. procedure TestCollection6;
  161. procedure TestCollectionProp;
  162. procedure TestCollectionProp2;
  163. procedure TestStrings;
  164. procedure TestStrings2;
  165. procedure TestStrings3;
  166. end;
  167. implementation
  168. uses variants;
  169. { TTestJSONDeStreamer }
  170. procedure TTestJSONDeStreamer.SetUp;
  171. begin
  172. inherited SetUp;
  173. FDS:=TJSONDeStreamer.Create(Nil)
  174. end;
  175. procedure TTestJSONDeStreamer.TearDown;
  176. begin
  177. FreeAndNil(FDS);
  178. FreeAndNil(FJD);
  179. FreeAndNil(FToFree);
  180. inherited TearDown;
  181. end;
  182. procedure TTestJSONDeStreamer.AssertVarType(Msg: String; AVarType: TVarType;
  183. const Variant: Variant);
  184. begin
  185. AssertEquals(Msg,VarTypeAsText(AVarType),VarTypeAsText(VarType(Variant)));
  186. end;
  187. procedure TTestJSONDeStreamer.TestVariantInteger;
  188. Var
  189. V : Variant;
  190. begin
  191. JD:=TJSOnIntegerNumber.Create(12);
  192. V:=DS.JSONToVariant(JD);
  193. AssertVarType('Integer data',varInteger,V);
  194. AssertEquals('Integer value',12,V);
  195. end;
  196. procedure TTestJSONDeStreamer.TestVariantFloat;
  197. Var
  198. V : Variant;
  199. begin
  200. JD:=TJSOnFloatNumber.Create(1.2);
  201. V:=DS.JSONToVariant(JD);
  202. AssertVarType('Double data',varDouble,V);
  203. AssertEquals('Float value',1.2,V);
  204. end;
  205. procedure TTestJSONDeStreamer.TestVariantInt64;
  206. Var
  207. V : Variant;
  208. begin
  209. JD:=TJSONInt64Number.Create(123);
  210. V:=DS.JSONToVariant(JD);
  211. AssertVarType('Int64 data',varInt64,V);
  212. AssertEquals('Int64 value',123,V);
  213. end;
  214. procedure TTestJSONDeStreamer.TestVariantBoolean;
  215. Var
  216. V : Variant;
  217. begin
  218. JD:=TJSONBoolean.Create(True);
  219. V:=DS.JSONToVariant(JD);
  220. AssertVarType('Boolean data',varBoolean,V);
  221. AssertEquals('Boolean value',True,V);
  222. end;
  223. procedure TTestJSONDeStreamer.TestVariantNull;
  224. Var
  225. V : Variant;
  226. begin
  227. JD:=TJSONNull.Create();
  228. V:=DS.JSONToVariant(JD);
  229. AssertVarType('Null data',varNull,V);
  230. end;
  231. procedure TTestJSONDeStreamer.TestVariantString;
  232. Var
  233. V : Variant;
  234. begin
  235. JD:=TJSONString.Create('A string');
  236. V:=DS.JSONToVariant(JD);
  237. AssertVarType('String data',varOleStr,V);
  238. AssertEquals('String data','A string',V);
  239. end;
  240. procedure TTestJSONDeStreamer.TestVariantArray;
  241. Var
  242. V : Variant;
  243. begin
  244. JD:=TJSONArray.Create([1,2,3]);
  245. V:=DS.JSONToVariant(JD);
  246. AssertEQuals('Variant is array',true,VarIsArray(V));
  247. AssertEquals('Lower bound is zero ',0,VarArrayLowBound(V,1));
  248. AssertEquals('Higher bound is count-1 ',2,VarArrayHighBound(V,1));
  249. AssertEquals('Element 0 value correct ',1,V[0]);
  250. AssertEquals('Element 1 value correct ',2,V[1]);
  251. AssertEquals('Element 2 value correct ',3,V[2]);
  252. end;
  253. procedure TTestJSONDeStreamer.TestEmpty;
  254. begin
  255. FTofree:=TComponent.Create(Nil);
  256. DS.JSONToObject('{}',FTofree);
  257. AssertEquals('Empty name','',TComponent(FToFree).Name);
  258. AssertEquals('Empty Tag',0,TComponent(FToFree).Tag);
  259. end;
  260. procedure TTestJSONDeStreamer.TestNullError;
  261. begin
  262. AssertException('Null error',EJSON, @DoNullError);
  263. end;
  264. procedure TTestJSONDeStreamer.TestNull;
  265. Var
  266. B : TBooleanComponent;
  267. begin
  268. B:=TBooleanComponent.Create(Nil);
  269. DS.Options:=DS.Options+[jdoIgnoreNulls];
  270. DeStream('{ "BooleanProp" : null }',B);
  271. AssertEquals('Correct boolean value',False,B.BooleanProp);
  272. end;
  273. procedure TTestJSONDeStreamer.DeStream(JSON : TJSONStringType; AObject : TObject);
  274. begin
  275. FToFree:=AObject;
  276. DS.JSONToObject(JSON,FTofree);
  277. end;
  278. procedure TTestJSONDeStreamer.DeStream(JSON: TJSONObject; AObject: TObject);
  279. begin
  280. FToFree:=AObject;
  281. JD:=JSON;
  282. DS.JSONToObject(JSON,FTofree);
  283. end;
  284. procedure TTestJSONDeStreamer.TestBoolean;
  285. Var
  286. B : TBooleanComponent;
  287. begin
  288. B:=TBooleanComponent.Create(Nil);
  289. DeStream('{ "BooleanProp" : true }',B);
  290. AssertEquals('Correct boolean value',true,B.BooleanProp);
  291. end;
  292. procedure TTestJSONDeStreamer.TestInteger;
  293. Var
  294. B : TIntegerComponent;
  295. begin
  296. B:=TIntegerComponent.Create(Nil);
  297. DeStream('{ "IntProp" : 22 }',B);
  298. AssertEquals('Correct integer value',22,B.IntProp);
  299. end;
  300. procedure TTestJSONDeStreamer.TestIntegerCaseInsensitive;
  301. Var
  302. B : TIntegerComponent;
  303. begin
  304. DS.Options:=DS.Options+[jdoCaseInsensitive];
  305. B:=TIntegerComponent.Create(Nil);
  306. DeStream('{ "intprop" : 22 }',B);
  307. AssertEquals('Correct integer value',22,B.IntProp);
  308. end;
  309. procedure TTestJSONDeStreamer.TestIntegerCaseSensitive;
  310. Var
  311. B : TIntegerComponent;
  312. begin
  313. DS.Options:=DS.Options;
  314. B:=TIntegerComponent.Create(Nil);
  315. B.IntProp:=0;
  316. DeStream('{ "intprop" : 22 }',B);
  317. AssertEquals('Correct integer value not reas',0,B.IntProp);
  318. end;
  319. procedure TTestJSONDeStreamer.TestString;
  320. Var
  321. B : TStringComponent;
  322. begin
  323. B:=TStringComponent.Create(Nil);
  324. DeStream('{ "StringProp" : "A nice string"}',B);
  325. AssertEquals('Correct string value','A nice string',B.StringProp);
  326. end;
  327. procedure TTestJSONDeStreamer.TestFloat;
  328. Var
  329. B : TSingleComponent;
  330. begin
  331. B:=TSingleComponent.Create(Nil);
  332. DeStream('{ "SingleProp" : 2.34 }',B);
  333. AssertEquals('Correct single value',2.34,B.SingleProp);
  334. end;
  335. procedure TTestJSONDeStreamer.TestFloat2;
  336. Var
  337. B : TDoubleComponent;
  338. begin
  339. B:=TDoubleComponent.Create(Nil);
  340. DeStream('{ "DoubleProp" : 3.45 }',B);
  341. AssertEquals('Correct Double value',3.45,B.DoubleProp);
  342. end;
  343. procedure TTestJSONDeStreamer.TestFloat3;
  344. Var
  345. B : TExtendedComponent;
  346. begin
  347. B:=TExtendedComponent.Create(Nil);
  348. DeStream('{ "ExtendedProp" : 4.56 }',B);
  349. AssertEquals('Correct extended value',4.56,B.ExtendedProp);
  350. end;
  351. procedure TTestJSONDeStreamer.TestFloat4;
  352. Var
  353. B : TCompComponent;
  354. begin
  355. B:=TCompComponent.Create(Nil);
  356. DeStream('{ "CompProp" : 5.67 }',B);
  357. AssertEquals('Correct comp value',round(5.67),B.CompProp);
  358. end;
  359. procedure TTestJSONDeStreamer.TestFloat5;
  360. Var
  361. B : TCurrencyComponent;
  362. begin
  363. B:=TCurrencyComponent.Create(Nil);
  364. DeStream('{ "CurrencyProp" : 5.67 }',B);
  365. AssertEquals('Correct string value',5.67,B.CurrencyProp);
  366. end;
  367. procedure TTestJSONDeStreamer.TestDateTime;
  368. Var
  369. E : TDateTimeComponent;
  370. D : TDateTime;
  371. begin
  372. E:=TDateTimeComponent.Create(Nil);
  373. D:= RecodeMillisecond(Now,0);
  374. DeStream('{"DateTimeProp" : "'+FormatDateTime(RFC3339DateTimeFormat,D)+'"}',E);
  375. AssertEquals('Correct value',D,E.DateTimeProp);
  376. end;
  377. procedure TTestJSONDeStreamer.DoDateTimeFormat;
  378. begin
  379. DeStream('{"DateTimeProp" : "'+DateTimeToStr(RecodeMillisecond(Now,0))+'"}',FToFree);
  380. end;
  381. procedure TTestJSONDeStreamer.DoNullError;
  382. Var
  383. B : TBooleanComponent;
  384. begin
  385. B:=TBooleanComponent.Create(Nil);
  386. Destream('{ "BooleanProp" : null }',B);
  387. end;
  388. procedure TTestJSONDeStreamer.TestDateTimeFormat;
  389. Const
  390. ISO8601 = 'yyyymmdd"T"hhnnss';
  391. Var
  392. E : TDateTimeComponent;
  393. D : TDateTime;
  394. begin
  395. E:=TDateTimeComponent.Create(Nil);
  396. D:=RecodeMillisecond(Now,0);
  397. DS.DateTimeFormat:=ISO8601;
  398. DeStream('{"DateTimeProp" : "'+FormatDateTime(Iso8601,D)+'"}',E);
  399. AssertEquals('Correct value',D,E.DateTimeProp);
  400. AssertException('Error if string does not correspond to specified format',EConvertError,@DoDateTimeFormat);
  401. end;
  402. procedure TTestJSONDeStreamer.TestEnum1;
  403. Var
  404. E : TEnumcomponent;
  405. begin
  406. E:=TEnumComponent.Create(Nil);
  407. DeStream('{ "Dice" : 2 }',E);
  408. AssertEquals('Correct value',2,Ord(E.Dice));
  409. end;
  410. procedure TTestJSONDeStreamer.TestEnum2;
  411. Var
  412. E : TEnumcomponent;
  413. begin
  414. E:=TEnumComponent.Create(Nil);
  415. DeStream('{ "Dice" : "three" }',E);
  416. AssertEquals('Correct value',GetEnumName(TypeInfo(TDice),Ord(Three)),GetEnumName(TypeInfo(TDice),Ord(E.Dice)));
  417. end;
  418. procedure TTestJSONDeStreamer.TestSet1;
  419. Var
  420. T : TSetComponent;
  421. begin
  422. T:=TSetComponent.Create(Nil);
  423. DeStream('{ "Throw" : "one,two" }',T);
  424. If not (T.Throw=[one,two]) then
  425. Fail('Correct value for throw');
  426. end;
  427. procedure TTestJSONDeStreamer.TestSet2;
  428. Var
  429. T : TSetComponent;
  430. begin
  431. T:=TSetComponent.Create(Nil);
  432. DeStream('{ "Throw" : "[one,two]" }',T);
  433. If not (T.Throw=[one,two]) then
  434. Fail('Correct value for throw');
  435. end;
  436. procedure TTestJSONDeStreamer.TestSet3;
  437. Var
  438. T : TSetComponent;
  439. begin
  440. T:=TSetComponent.Create(Nil);
  441. DeStream('{ "Throw" : [ "one", "two"] }',T);
  442. If not (T.Throw=[one,two]) then
  443. Fail('Correct value for throw');
  444. end;
  445. procedure TTestJSONDeStreamer.TestSet4;
  446. Var
  447. T : TSetComponent;
  448. begin
  449. T:=TSetComponent.Create(Nil);
  450. DeStream('{ "Throw" : [ 0 , 1 ] }',T);
  451. If not (T.Throw=[one,two]) then
  452. Fail('Correct value for throw');
  453. end;
  454. procedure TTestJSONDeStreamer.TestVariantProp;
  455. Var
  456. V : TVariantComponent;
  457. begin
  458. V:=TVariantComponent.Create(Nil);
  459. DeStream('{ "VariantProp" : "A string" }',V);
  460. AssertEquals('Variant property value','A string',V.VariantProp);
  461. end;
  462. procedure TTestJSONDeStreamer.TestCollection;
  463. Var
  464. C : TTestCollection;
  465. begin
  466. C:=TTestCollection.Create;
  467. DeStream('[ { "StrProp" : "one" }, { "StrProp" : "two" } ]',C);
  468. AssertEquals('Item count',2,C.Count);
  469. AssertEquals('Class item 0',TTestItem,C.Items[0].ClassType);
  470. AssertEquals('Class item 1',TTestItem,C.Items[1].ClassType);
  471. AssertEquals('Class item 0','one',TTestItem(C.Items[0]).StrProp);
  472. AssertEquals('Class item 1','two',TTestItem(C.Items[1]).StrProp);
  473. end;
  474. procedure TTestJSONDeStreamer.TestCollection2;
  475. Var
  476. C : TTestCollection;
  477. begin
  478. C:=TTestCollection.Create;
  479. DeStream('{ "Items" : [ { "StrProp" : "one" }, { "StrProp" : "two" } ] }',C);
  480. AssertEquals('Item count',2,C.Count);
  481. AssertEquals('Class item 0',TTestItem,C.Items[0].ClassType);
  482. AssertEquals('Class item 1',TTestItem,C.Items[1].ClassType);
  483. AssertEquals('Class item 0','one',TTestItem(C.Items[0]).StrProp);
  484. AssertEquals('Class item 1','two',TTestItem(C.Items[1]).StrProp);
  485. end;
  486. procedure TTestJSONDeStreamer.TestCollection3;
  487. Var
  488. C : TTestCollection;
  489. begin
  490. C:=TTestCollection.Create;
  491. FTofree:=C;
  492. DS.JSONToCollection('{ "Items" : [ { "StrProp" : "one" }, { "StrProp" : "two" } ] }',C);
  493. AssertEquals('Item count',2,C.Count);
  494. AssertEquals('Class item 0',TTestItem,C.Items[0].ClassType);
  495. AssertEquals('Class item 1',TTestItem,C.Items[1].ClassType);
  496. AssertEquals('Class item 0','one',TTestItem(C.Items[0]).StrProp);
  497. AssertEquals('Class item 1','two',TTestItem(C.Items[1]).StrProp);
  498. end;
  499. procedure TTestJSONDeStreamer.TestCollection4;
  500. Var
  501. C : TTestCollection;
  502. begin
  503. C:=TTestCollection.Create;
  504. FTofree:=C;
  505. DS.JSONToCollection('[ { "StrProp" : "one" }, { "StrProp" : "two" } ]',C);
  506. AssertEquals('Item count',2,C.Count);
  507. AssertEquals('Class item 0',TTestItem,C.Items[0].ClassType);
  508. AssertEquals('Class item 1',TTestItem,C.Items[1].ClassType);
  509. AssertEquals('Class item 0','one',TTestItem(C.Items[0]).StrProp);
  510. AssertEquals('Class item 1','two',TTestItem(C.Items[1]).StrProp);
  511. end;
  512. procedure TTestJSONDeStreamer.TestCollection5;
  513. Var
  514. C : TTestCollection;
  515. begin
  516. C:=TTestCollection.Create;
  517. FTofree:=C;
  518. JD:=TJSONArray.Create([TJSONObject.Create(['StrProp','one']),TJSONObject.Create(['StrProp','two'])]);
  519. DS.JSONToCollection(JD,C);
  520. AssertEquals('Item count',2,C.Count);
  521. AssertEquals('Class item 0',TTestItem,C.Items[0].ClassType);
  522. AssertEquals('Class item 1',TTestItem,C.Items[1].ClassType);
  523. AssertEquals('Class item 0','one',TTestItem(C.Items[0]).StrProp);
  524. AssertEquals('Class item 1','two',TTestItem(C.Items[1]).StrProp);
  525. end;
  526. procedure TTestJSONDeStreamer.TestCollection6;
  527. Var
  528. C : TTestCollection;
  529. begin
  530. C:=TTestCollection.Create;
  531. FTofree:=C;
  532. JD:=TJSONObject.Create(['Items',TJSONArray.Create([TJSONObject.Create(['StrProp','one']),TJSONObject.Create(['StrProp','two'])])]);
  533. DS.JSONToCollection(JD,C);
  534. AssertEquals('Item count',2,C.Count);
  535. AssertEquals('Class item 0',TTestItem,C.Items[0].ClassType);
  536. AssertEquals('Class item 1',TTestItem,C.Items[1].ClassType);
  537. AssertEquals('Class item 0','one',TTestItem(C.Items[0]).StrProp);
  538. AssertEquals('Class item 1','two',TTestItem(C.Items[1]).StrProp);
  539. end;
  540. procedure TTestJSONDeStreamer.TestCollectionProp;
  541. Var
  542. C : TCollection;
  543. begin
  544. JD:=TJSONObject.Create(['Coll',TJSONArray.Create([TJSONObject.Create(['StrProp','one']),TJSONObject.Create(['StrProp','two'])])]);
  545. DeStream(JD as TJSONObject,TCollectionComponent.Create(Nil));
  546. C:=TCollectionComponent(ToFree).Coll;
  547. AssertEquals('Item count',2,C.Count);
  548. AssertEquals('Class item 0',TTestItem,C.Items[0].ClassType);
  549. AssertEquals('Class item 1',TTestItem,C.Items[1].ClassType);
  550. AssertEquals('Class item 0','one',TTestItem(C.Items[0]).StrProp);
  551. AssertEquals('Class item 1','two',TTestItem(C.Items[1]).StrProp);
  552. end;
  553. procedure TTestJSONDeStreamer.TestCollectionProp2;
  554. Var
  555. C : TCollection;
  556. begin
  557. DeStream('{ "Coll" : [ { "StrProp" : "one" }, { "StrProp" : "two" } ]}',TCollectionComponent.Create(Nil));
  558. C:=TCollectionComponent(ToFree).Coll;
  559. AssertEquals('Item count',2,C.Count);
  560. AssertEquals('Class item 0',TTestItem,C.Items[0].ClassType);
  561. AssertEquals('Class item 1',TTestItem,C.Items[1].ClassType);
  562. AssertEquals('Class item 0','one',TTestItem(C.Items[0]).StrProp);
  563. AssertEquals('Class item 1','two',TTestItem(C.Items[1]).StrProp);
  564. end;
  565. procedure TTestJSONDeStreamer.TestStrings;
  566. Var
  567. S : TStrings;
  568. begin
  569. S:=TStringList.Create;
  570. FTofree:=S;
  571. DS.JSONToStrings('[ "one" , "two" ]',S);
  572. AssertEquals('Item count',2,S.Count);
  573. AssertEquals('First item','one',S[0]);
  574. AssertEquals('First item','two',S[1]);
  575. end;
  576. procedure TTestJSONDeStreamer.TestStrings2;
  577. Var
  578. S : TStrings;
  579. begin
  580. S:=TStringList.Create;
  581. FTofree:=S;
  582. DS.JSONToStrings('{ "Strings" : [ "one" , "two" ] }',S);
  583. AssertEquals('Item count',2,S.Count);
  584. AssertEquals('First item','one',S[0]);
  585. AssertEquals('First item','two',S[1]);
  586. end;
  587. procedure TTestJSONDeStreamer.TestStrings3;
  588. Var
  589. S : TStrings;
  590. begin
  591. S:=TStringList.Create;
  592. FTofree:=S;
  593. DS.JSONToStrings('{ "Strings" : [ "one" , "two" ] }',S);
  594. AssertEquals('Item count',2,S.Count);
  595. AssertEquals('First item','one',S[0]);
  596. AssertEquals('First item','two',S[1]);
  597. end;
  598. { TTestJSONStreamer }
  599. function TTestJSONStreamer.StreamObject(AObject: TObject): TJSONObject;
  600. begin
  601. FToFree:=AObject;
  602. FSR:=FRJ.ObjectToJSON(AObject);
  603. Result:=FSR;
  604. end;
  605. procedure TTestJSONStreamer.DoStreamProperty1(Sender: TObject; AObject: TObject;
  606. Info: PPropInfo; var Res: TJSONData);
  607. begin
  608. If (info^.name<>'IntProp') and (info^.name<>'Name') and (info^.name<>'Tag') then
  609. Fail('Wrong property');
  610. If (info^.name='IntProp') then
  611. FreeAndNil(Res);
  612. FCalled:=true;
  613. end;
  614. procedure TTestJSONStreamer.SetUp;
  615. begin
  616. Inherited;
  617. FRJ:=TJSONStreamer.Create(Nil);
  618. end;
  619. procedure TTestJSONStreamer.TearDown;
  620. begin
  621. FreeAndNil(FSR);
  622. FreeAndNil(FRJ);
  623. FreeAndNil(FToFree);
  624. Inherited;
  625. end;
  626. procedure TTestJSONStreamer.AssertEquals(AMessage: String; Expected, Actual: TJSONType);
  627. begin
  628. AssertEquals(AMessage,GetEnumName(TypeInfo(TJSONType),Ord(Expected)),
  629. GetEnumName(TypeInfo(TJSONType),Ord(Actual)));
  630. end;
  631. procedure TTestJSONStreamer.AssertPropCount(ACount: Integer);
  632. begin
  633. AssertNotNull('Result of streaming available',FSR);
  634. If FToFree is TComponent then
  635. ACount:=ACount+2; // Tag + Name
  636. // Writeln(FSR.ASJSON);
  637. AssertEquals('Property count correct',ACount,FSR.Count);
  638. end;
  639. function TTestJSONStreamer.AssertProperty(APropName: String; AType: TJSONType
  640. ): TJSONData;
  641. Var
  642. i : Integer;
  643. begin
  644. I:=FSR.IndexOfName(APropName);
  645. If (I=-1) then
  646. Fail('No property "'+APropName+'" available');
  647. Result:=FSR.Items[i];
  648. AssertEquals('Property "'+APropName+'" has correct type',GetEnumName(TypeInfo(TJSONType),Ord(AType)),
  649. GetEnumName(TypeInfo(TJSONType),Ord(Result.JSONType)));
  650. end;
  651. procedure TTestJSONStreamer.AssertProp(APropName: String; AValue: Boolean);
  652. begin
  653. AssertNotNull('Result of streaming available',FSR);
  654. AssertEquals('Result of streaming is TJSONObject',TJSONObject,FSR.ClassType);
  655. AssertEquals('Correct value',AValue,AssertProperty(APropName,jtBoolean).AsBoolean);
  656. end;
  657. procedure TTestJSONStreamer.AssertProp(APropName: String; AValue: Integer);
  658. begin
  659. AssertNotNull('Result of streaming available',FSR);
  660. AssertEquals('Result of streaming is TJSONObject',TJSONObject,FSR.ClassType);
  661. AssertEquals('Correct value',AValue,AssertProperty(APropName,jtNumber).AsInteger);
  662. end;
  663. procedure TTestJSONStreamer.AssertProp(APropName: String; AValue: String);
  664. begin
  665. AssertNotNull('Result of streaming available',FSR);
  666. AssertEquals('Result of streaming is TJSONObject',TJSONObject,FSR.ClassType);
  667. AssertEquals('Correct value',AValue,AssertProperty(APropName,jtString).AsString);
  668. end;
  669. procedure TTestJSONStreamer.AssertProp(APropName: String; AValue: TJSONFloat);
  670. begin
  671. AssertNotNull('Result of streaming available',FSR);
  672. AssertEquals('Result of streaming is TJSONObject',TJSONObject,FSR.ClassType);
  673. AssertEquals('Correct value',AValue,AssertProperty(APropName,jtNumber).AsFloat);
  674. end;
  675. procedure TTestJSONStreamer.AssertProp(APropName: String; AValue: array of String
  676. );
  677. Var
  678. a : TJSONArray;
  679. i : integer;
  680. begin
  681. a:=AssertArrayProp(APropName);
  682. AssertEquals('Correct count ',Length(AValue),A.Count);
  683. For I:=Low(AValue) to High(Avalue) do
  684. begin
  685. AssertEquals('Array element type',jtString,A.Types[i]);
  686. AssertEquals('Array value',AValue[i],A.strings[i]);
  687. end;
  688. end;
  689. procedure TTestJSONStreamer.AssertProp(APropName: String; AValue: array of Integer
  690. );
  691. Var
  692. a : TJSONArray;
  693. i : integer;
  694. begin
  695. a:=AssertArrayProp(APropName);
  696. For I:=Low(AValue) to High(Avalue) do
  697. begin
  698. AssertEquals('Array element type',jtNumber,A.Types[i]);
  699. AssertEquals('Array value',AValue[i],A.Integers[i]);
  700. end;
  701. end;
  702. function TTestJSONStreamer.CreateVariantComp: TVariantComponent;
  703. begin
  704. Result:=TVariantComponent.Create(Nil);
  705. FTofree:=Result;
  706. end;
  707. procedure TTestJSONStreamer.AssertNullProp(APropName: String);
  708. begin
  709. AssertProperty(APropName,jtNull);
  710. end;
  711. function TTestJSONStreamer.AssertObjectProp(APropName: String): TJSONObject;
  712. begin
  713. Result:=AssertProperty(APropName,jtObject) as TJSONObject;
  714. end;
  715. function TTestJSONStreamer.AssertArrayProp(APropName: String): TJSONArray;
  716. begin
  717. Result:=AssertProperty(APropName,jtArray) as TJSONArray;
  718. end;
  719. procedure TTestJSONStreamer.TestNil;
  720. begin
  721. AssertNull('Nil returns nil',StreamObject(Nil));
  722. end;
  723. procedure TTestJSONStreamer.TestEmpty;
  724. begin
  725. StreamObject(TemptyPersistent.Create);
  726. AssertPropCount(0);
  727. end;
  728. procedure TTestJSONStreamer.TestEmptyComponent;
  729. begin
  730. StreamObject(TComponent.Create(nil));
  731. AssertPropCount(0);
  732. end;
  733. procedure TTestJSONStreamer.TestWriteBoolean;
  734. begin
  735. StreamObject(TBooleanComponent.Create(nil));
  736. AssertPropCount(1);
  737. AssertProp('BooleanProp',False);
  738. end;
  739. procedure TTestJSONStreamer.TestWriteInteger;
  740. begin
  741. StreamObject(TIntegerComponent.Create(Nil));
  742. AssertPropCount(1);
  743. AssertProp('IntProp',3);
  744. end;
  745. procedure TTestJSONStreamer.TestWriteString;
  746. begin
  747. StreamObject(TStringComponent.Create(Nil));
  748. AssertPropCount(1);
  749. AssertProp('StringProp','A string');
  750. end;
  751. procedure TTestJSONStreamer.TestWriteFloat;
  752. begin
  753. StreamObject(TSingleComponent.Create(Nil));
  754. AssertPropCount(1);
  755. AssertProp('SingleProp',1.23);
  756. end;
  757. procedure TTestJSONStreamer.TestWriteFloat2;
  758. begin
  759. StreamObject(TDoubleComponent.Create(Nil));
  760. AssertPropCount(1);
  761. AssertProp('DoubleProp',2.34);
  762. end;
  763. procedure TTestJSONStreamer.TestWriteFloat3;
  764. begin
  765. StreamObject(TExtendedComponent.Create(Nil));
  766. AssertPropCount(1);
  767. AssertProp('ExtendedProp',3.45);
  768. end;
  769. procedure TTestJSONStreamer.TestWriteFloat4;
  770. begin
  771. StreamObject(TCompComponent.Create(Nil));
  772. AssertPropCount(1);
  773. AssertProp('CompProp',5);
  774. end;
  775. procedure TTestJSONStreamer.TestWriteFloat5;
  776. begin
  777. StreamObject(TCurrencyComponent.Create(Nil));
  778. AssertPropCount(1);
  779. AssertProp('CurrencyProp',5.67);
  780. end;
  781. procedure TTestJSONStreamer.TestEnum1;
  782. begin
  783. StreamObject(TEnumComponent3.Create(Nil));
  784. AssertPropCount(1);
  785. AssertProp('Dice',GetEnumName(TypeInfo(TDice),Ord(three)));
  786. end;
  787. procedure TTestJSONStreamer.TestEnum2;
  788. begin
  789. RJ.Options:=[jsoEnumeratedAsInteger];
  790. StreamObject(TEnumComponent3.Create(Nil));
  791. AssertProp('Dice',Ord(three));
  792. end;
  793. procedure TTestJSONStreamer.TestSet1;
  794. begin
  795. StreamObject(TSetComponent.Create(Nil));
  796. AssertPropCount(1);
  797. AssertProp('Throw',['two','five']);
  798. end;
  799. procedure TTestJSONStreamer.TestSet2;
  800. begin
  801. RJ.Options:=[jsoSetAsString];
  802. StreamObject(TSetComponent.Create(Nil));
  803. AssertPropCount(1);
  804. AssertProp('Throw','two,five');
  805. end;
  806. procedure TTestJSONStreamer.TestSet3;
  807. begin
  808. RJ.Options:=[jsoSetAsString,jsoSetBrackets];
  809. StreamObject(TSetComponent.Create(Nil));
  810. AssertPropCount(1);
  811. AssertProp('Throw','[two,five]');
  812. end;
  813. procedure TTestJSONStreamer.TestSet4;
  814. begin
  815. RJ.Options:=[jsoSetEnumeratedAsInteger];
  816. StreamObject(TSetComponent.Create(Nil));
  817. AssertPropCount(1);
  818. AssertProp('Throw',[Ord(two),Ord(five)]);
  819. end;
  820. procedure TTestJSONStreamer.TestObjectNil;
  821. Var
  822. P : TOwnedComponent;
  823. begin
  824. P:=TOwnedComponent.Create(Nil);
  825. P.CompProp.Free;
  826. P.CompProp:=Nil;
  827. StreamObject(P);
  828. AssertPropCount(1);
  829. AssertNullProp('CompProp');
  830. end;
  831. procedure TTestJSONStreamer.TestComponentProp1;
  832. begin
  833. StreamObject(TOwnedComponent.Create(Nil));
  834. AssertPropCount(1);
  835. AssertProp('CompProp','SubComponent');
  836. end;
  837. procedure TTestJSONStreamer.TestComponentProp2;
  838. Var
  839. C : TOwnedComponent;
  840. F : TJSONObject;
  841. begin
  842. RJ.Options:=[jsoComponentsInline];
  843. C:=TOwnedComponent.Create(Nil);
  844. StreamObject(C);
  845. AssertPropCount(1);
  846. F:=SR;
  847. try
  848. SR:=AssertObjectProp('CompProp');
  849. AssertPropCount(1);
  850. AssertProp('Name','SubComponent');
  851. Assertprop('Tag',0);
  852. AssertProp('IntProp',3);
  853. finally
  854. SR:=F;
  855. end;
  856. end;
  857. procedure TTestJSONStreamer.TestCollectionProp1;
  858. Var
  859. C : TCollectionComponent;
  860. F : TJSONObject;
  861. A : TJSONArray;
  862. begin
  863. C:=TCollectionComponent2.Create(Nil);
  864. StreamObject(C);
  865. AssertPropCount(1);
  866. F:=SR;
  867. try
  868. A:=AssertArrayProp('Coll');
  869. AssertEquals('Collection item cound',3,A.Count);
  870. AssertEquals('Item 0 is object',jtObject,A.Types[0]);
  871. SR:=A.Objects[0];
  872. FToFree:=SR;
  873. AssertPropCount(1);
  874. AssertProp('StrProp','First');
  875. AssertEquals('Item 1 is object',jtObject,A.Types[1]);
  876. SR:=A.Objects[1];
  877. FToFree:=SR;
  878. AssertPropCount(1);
  879. AssertProp('StrProp','Second');
  880. AssertEquals('Item 2 is object',jtObject,A.Types[2]);
  881. SR:=A.Objects[2];
  882. FToFree:=SR;
  883. AssertPropCount(1);
  884. AssertProp('StrProp','Third');
  885. finally
  886. SR:=F;
  887. FToFree:=C;
  888. end;
  889. end;
  890. procedure TTestJSONStreamer.TestCollectionProp2;
  891. Var
  892. C : TCollectionComponent;
  893. A : TJSONArray;
  894. begin
  895. C:=TCollectionComponent.Create(Nil);
  896. StreamObject(C);
  897. AssertPropCount (1);
  898. A:=AssertArrayProp('Coll');
  899. AssertEquals('Collection item count',0,A.Count);
  900. end;
  901. procedure TTestJSONStreamer.TestPersistentProp1;
  902. var
  903. P : TPersistentComponent;
  904. F : TJSONObject;
  905. begin
  906. P:=TPersistentComponent.Create(Nil);
  907. StreamObject(P);
  908. AssertPropCount(1);
  909. F:=SR;
  910. try
  911. SR:=AssertObjectProp('Persist');
  912. FToFree:=P.Persist;
  913. AssertPropCount(2);
  914. AssertProp('AString','A persistent string');
  915. AssertProp('AInteger',3);
  916. finally
  917. FToFree:=P;
  918. SR:=F;
  919. end;
  920. end;
  921. procedure TTestJSONStreamer.TestStringsProp1;
  922. begin
  923. RJ.Options:=[jsoTstringsAsArray];
  924. StreamObject(TStringsCOmponent.Create(Nil));
  925. AssertPropCount(1);
  926. AssertProp('StringsProp',['One','Two','Three']);
  927. end;
  928. procedure TTestJSONStreamer.TestStringsProp2;
  929. begin
  930. StreamObject(TStringsCOmponent.Create(Nil));
  931. AssertPropCount(1);
  932. AssertProp('StringsProp','One'+sLineBreak+'Two'+sLineBreak+'Three'+sLineBreak);
  933. end;
  934. procedure TTestJSONStreamer.TestStringsProp3;
  935. Var
  936. O : TJSONObject;
  937. S : TStringsComponent;
  938. begin
  939. S:=TStringsCOmponent.Create(Nil);
  940. RJ.Options:=[jsoTstringsAsObject];
  941. StreamObject(S);
  942. AssertPropCount(1);
  943. O:=SR;
  944. SR:=AssertObjectprop('StringsProp');
  945. FTofree:=Nil;
  946. try
  947. AssertNullProp('One');
  948. AssertNullProp('Two');
  949. AssertNullProp('Three');
  950. finally
  951. SR:=o;
  952. FToFree:=S;
  953. end;
  954. end;
  955. procedure TTestJSONStreamer.TestStringsProp4;
  956. Var
  957. O,SP : TJSONObject;
  958. S : TStringsComponent;
  959. begin
  960. S:=TStringsCOmponent.Create(Nil);
  961. S.StringsProp.Objects[0]:=TEmptyPersistent.Create;
  962. S.StringsProp.Objects[1]:=TEmptyPersistent.Create;
  963. S.StringsProp.Objects[2]:=TEmptyPersistent.Create;
  964. try
  965. RJ.Options:=[jsoTstringsAsObject];
  966. StreamObject(S);
  967. AssertPropCount(1);
  968. O:=SR;
  969. SP:=AssertObjectprop('StringsProp');
  970. SR:=SP;
  971. FTofree:=Nil;
  972. try
  973. SR:=AssertObjectProp('One');
  974. AssertPropCount(0);
  975. SR:=SP;
  976. SR:=AssertObjectProp('Two');
  977. AssertPropCount(0);
  978. SR:=SP;
  979. SR:=AssertObjectProp('Three');
  980. AssertPropCount(0);
  981. finally
  982. SR:=o;
  983. FToFree:=S;
  984. end;
  985. finally
  986. S.StringsProp.Objects[0].Free;
  987. S.StringsProp.Objects[1].Free;
  988. S.StringsProp.Objects[2].Free;
  989. end;
  990. end;
  991. procedure TTestJSONStreamer.TestStringsArray;
  992. Var
  993. O : TJSONArray;
  994. S : TStringList;
  995. begin
  996. S:=TStringList.create;
  997. try
  998. S.Add('one');
  999. O:=RJ.StreamTStringsArray(S);
  1000. try
  1001. AssertEquals('one element',1,O.Count);
  1002. AssertEquals('string type',jtString,O.Types[0]);
  1003. AssertEquals('string value','one',O.Strings[0]);
  1004. finally
  1005. FreeAndNil(O);
  1006. end;
  1007. finally
  1008. S.Free;
  1009. end;
  1010. end;
  1011. procedure TTestJSONStreamer.TestStringsObject;
  1012. Var
  1013. O : TJSONObject;
  1014. S : TStringList;
  1015. begin
  1016. S:=TStringList.create;
  1017. try
  1018. S.AddObject('one',TEmptyPersistent.Create);
  1019. O:=RJ.StreamTStringsObject(S);
  1020. try
  1021. AssertEquals('one element',1,O.Count);
  1022. AssertEquals('Have property',0,O.IndexOfName('one'));
  1023. AssertEquals('string type',jtObject,O.Types['one']);
  1024. AssertEquals('string value','one',O.Names[0]);
  1025. finally
  1026. FreeAndNil(O);
  1027. end;
  1028. finally
  1029. S.Objects[0].FRee;
  1030. S.Free;
  1031. end;
  1032. end;
  1033. procedure TTestJSONStreamer.TestStringsStream1;
  1034. Var
  1035. D: TJSONData;
  1036. O : TJSONArray;
  1037. S : TStringList;
  1038. begin
  1039. S:=TStringList.create;
  1040. try
  1041. S.Add('one');
  1042. RJ.Options:=[jsoTstringsAsArray];
  1043. D:=RJ.StreamTStrings(S);
  1044. try
  1045. AssertEquals('Correct type',jtArray,D.JSONType);
  1046. O:=D as TJSONArray;
  1047. AssertEquals('one element',1,O.Count);
  1048. AssertEquals('string type',jtString,O.Types[0]);
  1049. AssertEquals('string value','one',O.Strings[0]);
  1050. finally
  1051. FreeAndNil(O);
  1052. end;
  1053. finally
  1054. S.Free;
  1055. end;
  1056. end;
  1057. procedure TTestJSONStreamer.TestStringsStream2;
  1058. Var
  1059. D : TJSONData;
  1060. O : TJSONObject;
  1061. S : TStringList;
  1062. begin
  1063. S:=TStringList.create;
  1064. try
  1065. S.AddObject('one',TEmptyPersistent.Create);
  1066. RJ.Options:=[jsoTstringsAsObject];
  1067. D:=RJ.StreamTstrings(S);
  1068. try
  1069. AssertEquals('Correct type',jtObject,D.JSONType);
  1070. O:=D as TJSONObject;
  1071. AssertEquals('one element',1,O.Count);
  1072. AssertEquals('Have property',0,O.IndexOfName('one'));
  1073. AssertEquals('string type',jtObject,O.Types['one']);
  1074. AssertEquals('string value','one',O.Names[0]);
  1075. finally
  1076. SR:=O;
  1077. end;
  1078. finally
  1079. S.Objects[0].FRee;
  1080. S.Free;
  1081. end;
  1082. end;
  1083. procedure TTestJSONStreamer.TestStringsStream3;
  1084. Var
  1085. O : TJSONObject;
  1086. S : TStringList;
  1087. begin
  1088. S:=TStringList.create;
  1089. try
  1090. S.AddObject('one',TEmptyPersistent.Create);
  1091. RJ.Options:=[jsoTstringsAsObject];
  1092. SR:=RJ.ObjectToJSON(S);
  1093. O:=AssertObjectProp('Strings');
  1094. AssertEquals('one element',1,O.Count);
  1095. AssertEquals('Have property',0,O.IndexOfName('one'));
  1096. AssertEquals('string type',jtObject,O.Types['one']);
  1097. AssertEquals('string value','one',O.Names[0]);
  1098. finally
  1099. S.Objects[0].FRee;
  1100. S.Free;
  1101. end;
  1102. end;
  1103. procedure TTestJSONStreamer.TestStringsStream4;
  1104. Var
  1105. S : TStringList;
  1106. begin
  1107. S:=TStringList.create;
  1108. try
  1109. S.AddObject('one',TEmptyPersistent.Create);
  1110. SR:=RJ.ObjectToJSON(S);
  1111. AssertProp('Strings','one'+sLinebreak);
  1112. finally
  1113. S.Objects[0].FRee;
  1114. S.Free;
  1115. end;
  1116. end;
  1117. procedure TTestJSONStreamer.TestStringsStream5;
  1118. Var
  1119. D : TJSONData;
  1120. S : TStringList;
  1121. begin
  1122. S:=TStringList.create;
  1123. try
  1124. S.AddObject('one',TEmptyPersistent.Create);
  1125. D:=RJ.StreamTstrings(S);
  1126. try
  1127. AssertEquals('String data',jtString,D.JSONType);
  1128. AssertEquals('String value','one'+sLineBreak,D.AsString);
  1129. finally
  1130. D.free;
  1131. end;
  1132. finally
  1133. S.Objects[0].FRee;
  1134. S.Free;
  1135. end;
  1136. end;
  1137. procedure TTestJSONStreamer.TestCollectionStream;
  1138. Var
  1139. C : TTestCollection;
  1140. A : TJSONArray;
  1141. begin
  1142. C:=TTestCollection.Create;
  1143. FToFree:=C;
  1144. TTestItem(C.Add).StrProp:='One';
  1145. TTestItem(C.Add).StrProp:='Two';
  1146. A:=RJ.StreamCollection(C);
  1147. try
  1148. AssertNotNull('Have result',A);
  1149. AssertEquals('2 items',2,A.Count);
  1150. AssertEquals('Type item 0,',jtObject,A.Types[0]);
  1151. AssertEquals('Type item 1,',jtObject,A.Types[1]);
  1152. SR:=A.Objects[0];
  1153. AssertPropCount(1);
  1154. AssertProp('StrProp','One');
  1155. SR:=A.Objects[1];
  1156. AssertPropCount(1);
  1157. AssertProp('StrProp','Two');
  1158. SR:=Nil;
  1159. finally
  1160. FreeAndNil(A);
  1161. end;
  1162. end;
  1163. procedure TTestJSONStreamer.TestCollectionStream2;
  1164. Var
  1165. C : TTestCollection;
  1166. A : TJSONArray;
  1167. o : TJSONObject;
  1168. begin
  1169. C:=TTestCollection.Create;
  1170. TTestItem(C.Add).StrProp:='One';
  1171. TTestItem(C.Add).StrProp:='Two';
  1172. FToFree:=C;
  1173. StreamObject(C);
  1174. O:=SR;
  1175. try
  1176. A:=AssertProperty('Items',jtArray) as TJSONArray;
  1177. AssertNotNull('Have result',A);
  1178. AssertEquals('2 items',2,A.Count);
  1179. AssertEquals('Type item 0,',jtObject,A.Types[0]);
  1180. AssertEquals('Type item 1,',jtObject,A.Types[1]);
  1181. SR:=A.Objects[0];
  1182. AssertPropCount(1);
  1183. AssertProp('StrProp','One');
  1184. SR:=A.Objects[1];
  1185. AssertPropCount(1);
  1186. AssertProp('StrProp','Two');
  1187. SR:=Nil;
  1188. finally
  1189. SR:=O;
  1190. end;
  1191. end;
  1192. procedure TTestJSONStreamer.TestOnStreamProperty;
  1193. begin
  1194. RJ.OnStreamProperty:=@DoStreamProperty1;
  1195. StreamObject(TIntegerComponent.Create(Nil));
  1196. AssertPropCount(0);
  1197. end;
  1198. procedure TTestJSONStreamer.TestDateTimeProp;
  1199. Var
  1200. D : Double;
  1201. begin
  1202. StreamObject(TDateTimeComponent.Create(Nil));
  1203. D:=EncodeDate(1996,8,1);
  1204. AssertPropCount(1);
  1205. AssertProp('DateTimeProp',D);
  1206. end;
  1207. procedure TTestJSONStreamer.TestDateTimePropDefaultString;
  1208. Var
  1209. D : Double;
  1210. begin
  1211. RJ.Options:=[jsoDateTimeAsString];
  1212. StreamObject(TDateTimeComponent.Create(Nil));
  1213. D:=EncodeDate(1996,8,1);
  1214. AssertPropCount(1);
  1215. AssertProp('DateTimeProp',FormatDateTime(RFC3339DateTimeFormat,D));
  1216. end;
  1217. procedure TTestJSONStreamer.TestDateTimePropDefaultStringTime;
  1218. Var
  1219. D : Double;
  1220. begin
  1221. RJ.Options:=[jsoDateTimeAsString];
  1222. StreamObject(TDateTimeComponent3.Create(Nil));
  1223. D:=EncodeDate(1996,8,1)+EncodeTime(23,20,0,0);
  1224. AssertPropCount(1);
  1225. AssertProp('DateTimeProp',FormatDateTime(RFC3339DateTimeFormat,D));
  1226. end;
  1227. procedure TTestJSONStreamer.TestDateTimeProp2;
  1228. Var
  1229. D : Double;
  1230. begin
  1231. StreamObject(TDateTimeComponent2.Create(Nil));
  1232. D:=EncodeTime(23,20,0,0);
  1233. AssertPropCount(1);
  1234. AssertProp('DateTimeProp',D);
  1235. end;
  1236. procedure TTestJSONStreamer.TestDateTimeProp3;
  1237. Var
  1238. D : Double;
  1239. begin
  1240. StreamObject(TDateTimeComponent3.Create(Nil));
  1241. D:=EncodeDate(1996,8,1)+EncodeTime(23,20,0,0);
  1242. AssertPropCount(1);
  1243. AssertProp('DateTimeProp',D);
  1244. end;
  1245. procedure TTestJSONStreamer.TestDateTimeProp4;
  1246. begin
  1247. RJ.Options:=[jsoDateTimeAsString,jsoLegacyDateTime];
  1248. StreamObject(TDateTimeComponent.Create(Nil));
  1249. AssertPropCount(1);
  1250. AssertProp('DateTimeProp',DateToStr(EncodeDate(1996,8,1)));
  1251. end;
  1252. procedure TTestJSONStreamer.TestDateTimeProp5;
  1253. begin
  1254. RJ.Options:=[jsoDateTimeAsString,jsoLegacyDateTime];
  1255. StreamObject(TDateTimeComponent2.Create(Nil));
  1256. AssertPropCount(1);
  1257. AssertProp('DateTimeProp',TimeToStr(EncodeTime(23,20,0,0)));
  1258. end;
  1259. procedure TTestJSONStreamer.TestDateTimeProp6;
  1260. begin
  1261. RJ.Options:=[jsoDateTimeAsString,jsoLegacyDateTime];
  1262. StreamObject(TDateTimeComponent3.Create(Nil));
  1263. AssertPropCount(1);
  1264. AssertProp('DateTimeProp',DateTimeToStr(EncodeDate(1996,8,1)+EncodeTime(23,20,0,0)));
  1265. end;
  1266. procedure TTestJSONStreamer.TestDateTimeProp7;
  1267. begin
  1268. RJ.Options:=[jsoDateTimeAsString];
  1269. RJ.DateTimeFormat:='hh:nn';
  1270. StreamObject(TDateTimeComponent3.Create(Nil));
  1271. AssertPropCount(1);
  1272. AssertProp('DateTimeProp',FormatDateTime('hh:nn',EncodeDate(1996,8,1)+EncodeTime(23,20,0,0)));
  1273. end;
  1274. procedure TTestJSONStreamer.TestVariantShortint;
  1275. Var
  1276. i : ShortInt;
  1277. C : TVariantComponent;
  1278. begin
  1279. i:=3;
  1280. C:=CreateVariantComp;
  1281. C.VariantProp:=i;
  1282. AssertEquals('Variant type',VarTypeAsText(varshortint),VarTypeAsText(VarType(C.VariantProp)));
  1283. StreamObject(FTofree);
  1284. AssertPropCount(1);
  1285. AssertProp('VariantProp',3);
  1286. end;
  1287. procedure TTestJSONStreamer.TestVariantbyte;
  1288. Var
  1289. i : Byte;
  1290. C : TVariantComponent;
  1291. begin
  1292. i:=3;
  1293. C:=CreateVariantComp;
  1294. C.VariantProp:=i;
  1295. AssertEquals('Variant type',VarTypeAsText(varByte),VarTypeAsText(VarType(C.VariantProp)));
  1296. StreamObject(FTofree);
  1297. AssertPropCount(1);
  1298. AssertProp('VariantProp',3);
  1299. end;
  1300. procedure TTestJSONStreamer.TestVariantword;
  1301. Var
  1302. i : Word;
  1303. C : TVariantComponent;
  1304. begin
  1305. i:=3;
  1306. C:=CreateVariantComp;
  1307. C.VariantProp:=i;
  1308. AssertEquals('Variant type',VarTypeAsText(varWord),VarTypeAsText(VarType(C.VariantProp)));
  1309. StreamObject(FTofree);
  1310. AssertPropCount(1);
  1311. AssertProp('VariantProp',3);
  1312. end;
  1313. procedure TTestJSONStreamer.TestVariantsmallint;
  1314. Var
  1315. i : Smallint;
  1316. C : TVariantComponent;
  1317. begin
  1318. i:=3;
  1319. C:=CreateVariantComp;
  1320. C.VariantProp:=i;
  1321. AssertEquals('Variant type',VarTypeAsText(varSmallint),VarTypeAsText(VarType(C.VariantProp)));
  1322. StreamObject(FTofree);
  1323. AssertPropCount(1);
  1324. AssertProp('VariantProp',3);
  1325. end;
  1326. procedure TTestJSONStreamer.TestVariantinteger;
  1327. Var
  1328. i : Integer;
  1329. C : TVariantComponent;
  1330. begin
  1331. i:=3;
  1332. C:=CreateVariantComp;
  1333. C.VariantProp:=i;
  1334. AssertEquals('Variant type',VarTypeAsText(varInteger),VarTypeAsText(VarType(C.VariantProp)));
  1335. StreamObject(FTofree);
  1336. AssertPropCount(1);
  1337. AssertProp('VariantProp',3);
  1338. end;
  1339. procedure TTestJSONStreamer.TestVariantlongword;
  1340. Var
  1341. i : Cardinal;
  1342. C : TVariantComponent;
  1343. begin
  1344. i:=3;
  1345. C:=CreateVariantComp;
  1346. C.VariantProp:=i;
  1347. AssertEquals('Variant type',VarTypeAsText(varLongword),VarTypeAsText(VarType(C.VariantProp)));
  1348. StreamObject(FTofree);
  1349. AssertPropCount(1);
  1350. AssertProp('VariantProp',3);
  1351. end;
  1352. procedure TTestJSONStreamer.TestVariantint64;
  1353. Var
  1354. i : Int64;
  1355. C : TVariantComponent;
  1356. begin
  1357. i:=3;
  1358. C:=CreateVariantComp;
  1359. C.VariantProp:=i;
  1360. AssertEquals('Variant type',VarTypeAsText(varInt64),VarTypeAsText(VarType(C.VariantProp)));
  1361. StreamObject(FTofree);
  1362. AssertPropCount(1);
  1363. AssertProp('VariantProp',3);
  1364. end;
  1365. procedure TTestJSONStreamer.TestVariantqword;
  1366. Var
  1367. i : QWord;
  1368. C : TVariantComponent;
  1369. begin
  1370. i:=3;
  1371. C:=CreateVariantComp;
  1372. C.VariantProp:=i;
  1373. AssertEquals('Variant type',VarTypeAsText(varQWord),VarTypeAsText(VarType(C.VariantProp)));
  1374. StreamObject(FTofree);
  1375. AssertPropCount(1);
  1376. AssertProp('VariantProp',3);
  1377. end;
  1378. procedure TTestJSONStreamer.TestVariantsingle;
  1379. Var
  1380. i : Single;
  1381. C : TVariantComponent;
  1382. begin
  1383. i:=3.14;
  1384. C:=CreateVariantComp;
  1385. C.VariantProp:=VarAsType(3.14,varSingle);
  1386. AssertEquals('Variant type',VarTypeAsText(varSingle),VarTypeAsText(VarType(C.VariantProp)));
  1387. StreamObject(FTofree);
  1388. AssertPropCount(1);
  1389. AssertProp('VariantProp',i);
  1390. end;
  1391. procedure TTestJSONStreamer.TestVariantdouble;
  1392. Var
  1393. i : Double;
  1394. C : TVariantComponent;
  1395. begin
  1396. i:=3.14;
  1397. C:=CreateVariantComp;
  1398. C.VariantProp:=i;
  1399. AssertEquals('Variant type',VarTypeAsText(varDouble),VarTypeAsText(VarType(C.VariantProp)));
  1400. StreamObject(FTofree);
  1401. AssertPropCount(1);
  1402. AssertProp('VariantProp',3.14);
  1403. end;
  1404. procedure TTestJSONStreamer.TestVariantCurrency;
  1405. Var
  1406. i : Currency;
  1407. C : TVariantComponent;
  1408. begin
  1409. i:=3.14;
  1410. C:=CreateVariantComp;
  1411. C.VariantProp:=i;
  1412. AssertEquals('Variant type',VarTypeAsText(varCurrency),VarTypeAsText(VarType(C.VariantProp)));
  1413. StreamObject(FTofree);
  1414. AssertPropCount(1);
  1415. AssertProp('VariantProp',3.14);
  1416. end;
  1417. procedure TTestJSONStreamer.TestVariantString;
  1418. Var
  1419. i : String;
  1420. C : TVariantComponent;
  1421. begin
  1422. i:='3.14';
  1423. C:=CreateVariantComp;
  1424. C.VariantProp:=i;
  1425. AssertEquals('Variant type',VarTypeAsText(varString),VarTypeAsText(VarType(C.VariantProp)));
  1426. StreamObject(FTofree);
  1427. AssertPropCount(1);
  1428. AssertProp('VariantProp','3.14');
  1429. end;
  1430. procedure TTestJSONStreamer.TestVariantolestr;
  1431. Var
  1432. i : String;
  1433. C : TVariantComponent;
  1434. begin
  1435. i:='3.14';
  1436. C:=CreateVariantComp;
  1437. C.VariantProp:=VarAsType(i,varOleStr);
  1438. AssertEquals('Variant type',VarTypeAsText(varOleStr),VarTypeAsText(VarType(C.VariantProp)));
  1439. StreamObject(FTofree);
  1440. AssertPropCount(1);
  1441. AssertProp('VariantProp','3.14');
  1442. end;
  1443. procedure TTestJSONStreamer.TestVariantboolean;
  1444. Var
  1445. i : Boolean;
  1446. C : TVariantComponent;
  1447. begin
  1448. i:=True;
  1449. C:=CreateVariantComp;
  1450. C.VariantProp:=i;
  1451. AssertEquals('Variant type',VarTypeAsText(varBoolean),VarTypeAsText(VarType(C.VariantProp)));
  1452. StreamObject(FTofree);
  1453. AssertPropCount(1);
  1454. AssertProp('VariantProp',True);
  1455. end;
  1456. procedure TTestJSONStreamer.TestVariantDate;
  1457. Var
  1458. i : TDateTime;
  1459. C : TVariantComponent;
  1460. begin
  1461. i:=EncodeDate(2010,12,23);
  1462. C:=CreateVariantComp;
  1463. C.VariantProp:=i;
  1464. AssertEquals('Variant type',VarTypeAsText(varDate),VarTypeAsText(VarType(C.VariantProp)));
  1465. StreamObject(FTofree);
  1466. AssertPropCount(1);
  1467. AssertProp('VariantProp',EncodeDate(2010,12,23));
  1468. end;
  1469. procedure TTestJSONStreamer.TestVariantDate2;
  1470. Var
  1471. i : TDateTime;
  1472. C : TVariantComponent;
  1473. begin
  1474. RJ.Options:=[jsoDateTimeAsString,jsoLegacyDateTime];
  1475. i:=EncodeDate(2010,12,23);
  1476. C:=CreateVariantComp;
  1477. C.VariantProp:=i;
  1478. AssertEquals('Variant type',VarTypeAsText(varDate),VarTypeAsText(VarType(C.VariantProp)));
  1479. StreamObject(FTofree);
  1480. AssertPropCount(1);
  1481. AssertProp('VariantProp',DateToStr(EncodeDate(2010,12,23)));
  1482. end;
  1483. procedure TTestJSONStreamer.TestVariantArray;
  1484. Var
  1485. i : Integer;
  1486. V : Variant;
  1487. C : TVariantComponent;
  1488. A : TJSONArray;
  1489. begin
  1490. V:=VarArrayCreate([1,10],varInteger);
  1491. For I:=1 to 10 do
  1492. V[i]:=11-I;
  1493. C:=CreateVariantComp;
  1494. C.VariantProp:=V;
  1495. StreamObject(FTofree);
  1496. AssertPropCount(1);
  1497. A:=AssertProperty('VariantProp',jtArray) as TJSONArray;
  1498. AssertEquals('10 elements in array',10,A.Count);
  1499. For I:=1 to 10 do
  1500. begin
  1501. assertEquals('Type of element',jtNumber,A.Types[i-1]);
  1502. AssertEquals('Value of element',11-i,A.Integers[i-1]);
  1503. end;
  1504. end;
  1505. procedure TTestJSONStreamer.TestMultipleProps;
  1506. begin
  1507. StreamObject(TMultipleComponent.Create(Nil));
  1508. AssertPropCount(5);
  1509. AssertProp('IntProp',1);
  1510. Assertprop('StringProp','A String');
  1511. AssertProp('CurrencyProp',2.3);
  1512. AssertProp('Throw',['three','four']);
  1513. AssertProp('Dice','two');
  1514. end;
  1515. procedure TTestJSONStreamer.TestObjectToJSONString;
  1516. begin
  1517. StreamObject(TIntegerComponent.Create(Nil));
  1518. AssertEquals('Correct stream',SR.AsJSON,RJ.ObjectToJSONString(FToFree));
  1519. end;
  1520. procedure TTestJSONStreamer.TestStringsToJSONString;
  1521. Var
  1522. S : TStrings;
  1523. begin
  1524. S:=TStringList.Create;
  1525. try
  1526. S.Add('one');
  1527. S.Add('two');
  1528. S.Add('three');
  1529. AssertEquals('StringsToJSONString','["one", "two", "three"]',RJ.StringsToJSON(S));
  1530. AssertEquals('StringsToJSONString','{ "one" : null, "two" : null, "three" : null }',RJ.StringsToJSON(S,True));
  1531. finally
  1532. FreeAndNil(S);
  1533. end;
  1534. end;
  1535. procedure TTestJSONStreamer.TestTListToJSONString ;
  1536. Var
  1537. C : TList;
  1538. D : TJSONData;
  1539. P : Pointer;
  1540. Function Add : TTestItem;
  1541. begin
  1542. Result:=TTestItem.Create(Nil);
  1543. C.Add(Result);
  1544. end;
  1545. begin
  1546. RJ.Options:=RJ.Options + [jsoStreamTList];
  1547. C:=TList.Create;
  1548. try
  1549. Add.StrProp:='one';
  1550. Add.StrProp:='two';
  1551. Add.StrProp:='three';
  1552. D:=RJ.StreamTList(C);
  1553. AssertEquals('StreamTlist','[{ "StrProp" : "one" }, { "StrProp" : "two" }, { "StrProp" : "three" }]',D.AsJSON);
  1554. finally
  1555. D.Free;
  1556. For P in C do
  1557. TObject(P).Free;
  1558. FreeAndNil(C);
  1559. end;
  1560. end;
  1561. procedure TTestJSONStreamer.TestCollectionToJSONString;
  1562. Var
  1563. C : TTestCollection;
  1564. begin
  1565. C:=TTestCollection.Create;
  1566. try
  1567. (C.Add as TTestItem).StrProp:='one';
  1568. (C.Add as TTestItem).StrProp:='two';
  1569. (C.Add as TTestItem).StrProp:='three';
  1570. AssertEquals('CollectionToJSON','[{ "StrProp" : "one" }, { "StrProp" : "two" }, { "StrProp" : "three" }]',RJ.CollectionToJSON(C));
  1571. finally
  1572. FreeAndNil(C);
  1573. end;
  1574. end;
  1575. procedure TTestJSONStreamer.TestChildren;
  1576. Var
  1577. C : TChildrenComponent;
  1578. begin
  1579. C:=TChildrenComponent.Create(Nil);
  1580. TComponent.Create(C).Name:='Child1';
  1581. TComponent.Create(C).Name:='Child2';
  1582. StreamObject(C);
  1583. If SR.IndexOfName('Children')<>-1 then
  1584. Fail('Children streamed with default options');
  1585. end;
  1586. procedure TTestJSONStreamer.TestChildren2;
  1587. Var
  1588. C : TChildrenComponent;
  1589. A : TJSONArray;
  1590. O : TJSONObject;
  1591. begin
  1592. C:=TChildrenComponent.Create(Nil);
  1593. TComponent.Create(C).Name:='Child1';
  1594. TComponent.Create(C).Name:='Child2';
  1595. RJ.Options:=[jsoStreamChildren];
  1596. StreamObject(C);
  1597. AssertPropCount(1);
  1598. A:=AssertProperty('Children',jtArray) as TJSONArray;
  1599. O:=SR;
  1600. try
  1601. AssertEquals('2 Elements in array',2,A.Count);
  1602. AssertEquals('First in array is object',jtObject,A.Types[0]);
  1603. AssertEquals('Second in array is object',jtObject,A.Types[1]);
  1604. SR:=A.Objects[0];
  1605. AssertProp('Name','Child1');
  1606. SR:=A.Objects[1];
  1607. AssertProp('Name','Child2');
  1608. finally
  1609. SR:=O;
  1610. end;
  1611. end;
  1612. procedure TTestJSONStreamer.TestLowercase;
  1613. begin
  1614. RJ.Options:=RJ.Options+[jsoLowerPropertyNames];
  1615. StreamObject(TBooleanComponent.Create(nil));
  1616. AssertPropCount(1);
  1617. AssertProp('booleanprop',False);
  1618. end;
  1619. initialization
  1620. RegisterTests([TTestJSONStreamer,TTestJSONDeStreamer]);
  1621. end.