inifile_test.anubis 1.53 KB

 *Project*                             The Anubis Project
   
 *Title*                      Tests of implementation of inifile
   
 *Copyright*                     Copyright (c) David René 2006. 


   

 *Created: 2006 02 22  
 *Author*  David René
 
 Unit test of reading of inifile
 
read system/parameter/inifile.anubis
read tools/basis.anubis
read tools/streams.anubis   

define One printIniFile (String fileName) = 
//  dumpIniInfo(loadIniFile(fileName))
  print("start reading " + fileName + "\n");
  with start_time = (UTime) unow,
  forget(loadIniFile(fileName));
  with time = (UTime) unow - start_time,
  if time is utime(s,m) then
    print("Parsing duration of " + fileName + " = " + to_decimal(s) + " sec " + to_decimal(m) + " microsecondes")
. 

define String bool_to_string (Bool bool) =
  if bool is false
  then "false"
  else "true".

define One testFile (One u)  =
 with config = loadIniFile("c:\\my_inifile.ini"),
 print("TEST STRING FullName     : " + readString(config, "NETWORK", "FullName", "N/A") + "\n");
 print("TEST INT32  TcpPort      : " + to_decimal(readInt(config, "NETWORK", "TcpPort", 4000)) + "\n");
 print("TEST BOOL   ShouldUpdate : " + bool_to_string(readBool(config, "NETWORK", "ShouldUpdate", false)) + "\n");
 writeIniInfo(config, "c:\\my_inifile2.ini")
.
define One syntax =
  print(" Usage: inifile_test <filename> ... <filename>\n")
.

global define One inifile_test ( List(String) args ) =
   if args is 
     {
       [ ] then testFile(unique),
       [_ . _] then 
         map_forget(printIniFile,args)
     }.