t_ini_parser.cpp

Go to the documentation of this file.
00001 /*****************************************************************************\
00002 *                                                                             *
00003 *  Name   : test_ini_parser                                                   *
00004 *  Author : Chris Koeritz                                                     *
00005 *                                                                             *
00006 *******************************************************************************
00007 * Copyright (c) 1991-$now By Author.  This program is free software; you can  *
00008 * redistribute it and/or modify it under the terms of the GNU General Public  *
00009 * License as published by the Free Software Foundation; either version 2 of   *
00010 * the License or (at your option) any later version.  This is online at:      *
00011 *     http://www.fsf.org/copyleft/gpl.html                                    *
00012 * Please send any updates to: fred@gruntose.com                               *
00013 \*****************************************************************************/
00014 
00015 #include <basis/function.h>
00016 #include <basis/guards.h>
00017 #include <basis/istring.h>
00018 #include <data_struct/string_table.h>
00019 #include <opsystem/application_shell.h>
00020 #include <opsystem/byte_filer.h>
00021 #include <loggers/console_logger.h>
00022 #include <opsystem/ini_parser.h>
00023 #include <data_struct/static_memory_gremlin.h>
00024 
00025 const istring INI_FILE_1 = "\
00026 [bork]\n\
00027 norple=1\n\
00028 train=12.5\n\
00029 singhy=9   \r\n\
00030 \n\
00031 [twerf]\r\n\
00032 noodles=fungus\n\
00033 dora=34\n\
00034 ";
00035 
00036 //#define READ_FILE_TEST
00037   // uncomment to read in a file and parse it.
00038 
00039 class test_ini_parser : public application_shell
00040 {
00041 public:
00042   test_ini_parser() : application_shell(class_name()) {}
00043   IMPLEMENT_CLASS_NAME("test_ini_parser");
00044   virtual int execute();
00045 };
00046 
00047 int test_ini_parser::execute()
00048 {
00049   program_wide_logger().eol(log_base::NO_ENDING);
00050 
00051   ini_parser par(INI_FILE_1);
00052 
00053 //istring dump;
00054 //par.restate(dump);
00055 //log(istring("table has:\n") + dump);
00056 
00057   string_table twerf;
00058   if (!par.get_section("twerf", twerf))
00059     deadly_error(class_name(), "get_section 1", "twerf section was not found");
00060 //log(istring("twerf section is: ") + twerf.text_form());
00061   if (!twerf.find("noodles"))
00062     deadly_error(class_name(), "get_section 1", "item #1 was not found");
00063   if (*twerf.find("noodles") != "fungus")
00064     deadly_error(class_name(), "get_section 1", "item #1 found is incorrect");
00065   if (!twerf.find("dora"))
00066     deadly_error(class_name(), "get_section 1", "item #2 was not found");
00067   if (*twerf.find("dora") != "34")
00068     deadly_error(class_name(), "get_section 1", "item #2 found is incorrect");
00069 
00070   string_table bork;
00071   if (!par.get_section("bork", bork))
00072     deadly_error(class_name(), "get_section 2", "bork section was not found");
00073   if (!bork.find("norple"))
00074     deadly_error(class_name(), "get_section 2", "item #1 was not found");
00075   if (*bork.find("norple") != "1")
00076     deadly_error(class_name(), "get_section 2", "item #1 found is incorrect");
00077   if (!bork.find("train"))
00078     deadly_error(class_name(), "get_section 2", "item #2 was not found");
00079   if (*bork.find("train") != "12.5")
00080     deadly_error(class_name(), "get_section 2", "item #2 found is incorrect");
00081   if (!bork.find("singhy"))
00082     deadly_error(class_name(), "get_section 2", "item #3 was not found");
00083   if (*bork.find("singhy") != "9")
00084     deadly_error(class_name(), "get_section 2", "item #3 found is incorrect");
00085 
00086   istring new_ini;
00087   par.restate(new_ini);
00088 
00089   program_wide_logger().eol(log_base::CRLF_AT_END);
00090   log("");
00091 
00092 #ifdef READ_FILE_TEST
00093   byte_filer input("c:/home/fungal.lld", "rb");
00094   int len = input.length();
00095   log(isprintf("fungal len is %d", len));
00096   istring jojo;
00097   input.read(jojo, len);
00098   //log("whole file is:");
00099   //log(jojo);
00100 
00101   ini_parser klug(jojo);
00102   istring dump2;
00103   klug.restate(dump2);
00104   log(dump2);
00105 #endif
00106 
00107   guards::alert_message("ini_parser:: works for those functions tested.\n");
00108   return 0;
00109 }
00110 
00111 HOOPLE_MAIN(test_ini_parser, )
00112 

Generated on Fri Nov 28 04:29:39 2008 for HOOPLE Libraries by  doxygen 1.5.1