cfgtest.pp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // $Id$
  2. {$MODE objfpc}
  3. {$H+}
  4. program cfgtest;
  5. uses xmlcfg;
  6. var
  7. cfg: TXMLConfig;
  8. i: Integer;
  9. s: String;
  10. b: Boolean;
  11. begin
  12. WriteLn('Writing a sample XML configuration to "testcfg.xml"...');
  13. cfg := TXMLConfig.Create('testcfg.xml');
  14. cfg.SetValue('cfgtest/MainWindow/Constraints/Width', 600);
  15. cfg.SetValue('cfgtest/MainWindow/Constraints/Height', 400);
  16. cfg.SetValue('cfgtest/MainWindow/Caption', 'TXMLConfig Test');
  17. cfg.SetValue('cfgtest/SomeForm/Presets/Preset1/Name', 'Example');
  18. cfg.SetValue('TipOfTheDay/Disabled', True);
  19. cfg.Free;
  20. WriteLn('Ok; now I''ll try to read back all values...');
  21. cfg := TXMLConfig.Create('testcfg.xml');
  22. i := cfg.GetValue('cfgtest/MainWindow/Constraints/Width', 0);
  23. if i <> 600 then
  24. WriteLn('Invalid value: cfgtest/MainWindow/Constraints/Width, got ', i);
  25. i := cfg.GetValue('cfgtest/MainWindow/Constraints/Height', 400);
  26. if i <> 400 then
  27. WriteLn('Invalid value: cfgtest/MainWindow/Constraints/Height, got ', i);
  28. s := cfg.GetValue('cfgtest/MainWindow/Caption', '');
  29. if s <> 'TXMLConfig Test' then
  30. WriteLn('Invalid value: cfgtest/MainWindow/Caption, got "', s, '"');
  31. s := cfg.GetValue('cfgtest/SomeForm/Presets/Preset1/Name', '');
  32. if s <> 'Example' then
  33. WriteLn('Invalid value: cfgtest/SomeForm/Presets/Preset1/Name, got "', s, '"');
  34. b := cfg.GetValue('TipOfTheDay/Disabled', False);
  35. if b <> True then
  36. WriteLn('Invalid value: TipOfTheDay/Disabled, got ', b);
  37. cfg.Free;
  38. WriteLn('Done!');
  39. end.
  40. {
  41. $Log$
  42. Revision 1.4 2000-01-06 01:20:36 peter
  43. * moved out of packages/ back to topdir
  44. Revision 1.1 2000/01/03 19:33:10 peter
  45. * moved to packages dir
  46. Revision 1.2 1999/12/22 13:43:14 sg
  47. * Improved messages in the case of failure: Now the test prints the results
  48. it got from the XMLCfg unit
  49. Revision 1.1 1999/07/09 21:06:59 michael
  50. + Initial implementation by sebastian Guenther
  51. }