Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

test-config_processor.cc

00001 /*
00002 *  Name:      test-config_processor.cc
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   Test for config processor
00005 *  Date:      $Date: 2003/04/14 00:18:36 $
00006 *  Revision:  $Revision: 1.1 $
00007 *
00008 *  Copyright (C) 1994-2002  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00009 *
00010 *  This program is free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  This program is distributed in the hope that it will be useful,
00016 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 *  GNU General Public License for more details.
00019 *
00020 *  You should have received a copy of the GNU General Public License
00021 *  along with this program; if not, write to the Free Software
00022 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 *  MA 02111-1307, USA.
00024 */
00025 
00026 #include <iostream>
00027 #include <mpcl/util/prefs/config_processor.hh>
00028 #include <mpcl/test.h>
00029 
00030 
00031 using mpcl::util::prefs::TConfigProcessor;
00032 using mpcl::util::prefs::TException;
00033 using mpcl::util::prefs::TNotParameterAbleException;
00034 using mpcl::util::prefs::TOptionAlreadyDefinedException;
00035 
00036 
00044 int main (int argc, const char* argv[])
00045 {
00046 
00047   TEST_INIT ("tests for class 'TConfigProcessor'");
00048 
00049   TConfigProcessor   tConfigProcessor;
00050 
00051   //
00052   //  Define string constants names for options.
00053   // 
00054   tConfigProcessor.addOption ("first_option",  "a", "");
00055   tConfigProcessor.addOption ("second_option", "b", "");
00056   tConfigProcessor.addOption ("third_option",  "c", "");
00057   tConfigProcessor.addOption ("fourth_option", "d");
00058   tConfigProcessor.setCurrentNameSpace ("first_name_space");
00059   tConfigProcessor.addOption ("first_option",  "A", "");
00060   tConfigProcessor.addOption ("second_option", "B", "");
00061   tConfigProcessor.addOption ("third_option",  "C", "");
00062   tConfigProcessor.setCurrentNameSpace ("second_name_space");
00063   tConfigProcessor.addOption ("first_option",  "D", "");
00064   tConfigProcessor.addOption ("second_option", "E", "");
00065   tConfigProcessor.addOption ("third_option",  "F", "");
00066 
00067   //
00068   //  Checks for already defined options.
00069   //
00070   tConfigProcessor.setRootNameSpace();
00071   try
00072   {
00073     //
00074     //  Shortcut already defined.
00075     //
00076     tConfigProcessor.addOption ("fifth_option", "A");
00077     TEST_FAIL;
00078   }
00079   catch (const TOptionAlreadyDefinedException&)
00080   {
00081     TEST_PASS;
00082   }
00083   try
00084   {
00085     //
00086     //  Name already defined.
00087     //
00088     tConfigProcessor.addOption ("fourth_option", "d");
00089     TEST_FAIL;
00090   }
00091   catch (const TOptionAlreadyDefinedException&)
00092   {
00093     TEST_PASS;
00094   }
00095 
00096   tConfigProcessor.setConfigFileName ("test-config_processor.configuration");
00097   tConfigProcessor.setCommandLineParameters (argc, argv);
00098   try
00099   {
00100     tConfigProcessor.processOptions();
00101   }
00102   catch (const TException& rktEXCEPTION)
00103   {
00104     if ( !TEST_IN_SILENT_MODE )
00105     {
00106       fprintf ( hptTestTargetFile                          ,
00107                 "#ERROR: %s:%d:%s; %s\n"                   ,
00108                 rktEXCEPTION.fileName().c_str()            ,
00109                 rktEXCEPTION.lineNumber()                  ,
00110                 rktEXCEPTION.generalDescription().c_str()  ,
00111                 rktEXCEPTION.specificDescription().c_str() );
00112     }
00113     TEST_FAIL;
00114   }
00115   try
00116   {
00117     TEST_STRINGS (tConfigProcessor ["fourth_option"].getValue().c_str(), "");  
00118     TEST_FAIL;
00119   }
00120   catch (const TNotParameterAbleException&)
00121   {
00122     TEST_PASS;
00123   }
00124 
00125   TEST_STRINGS ("1",   tConfigProcessor ["first_option"].getValue().c_str());
00126   TEST_STRINGS ("2",   tConfigProcessor ["second_option"].getValue().c_str());
00127   TEST_STRINGS ("3",   tConfigProcessor ["third_option"].getValue().c_str());
00128   TEST_NUMBERS (false, tConfigProcessor ["fourth_option"].isAtCmdLine());
00129   TEST_STRINGS ("1.1", tConfigProcessor ["first_name_space.first_option"].getValue().c_str());
00130   TEST_STRINGS ("1.2", tConfigProcessor ["first_name_space.second_option"].getValue().c_str());
00131   TEST_STRINGS ("1.3", tConfigProcessor ["first_name_space.third_option"].getValue().c_str());
00132   TEST_STRINGS ("2.1", tConfigProcessor ["second_name_space.first_option"].getValue().c_str());
00133   TEST_STRINGS ("2.2", tConfigProcessor ["second_name_space.second_option"].getValue().c_str());
00134   TEST_STRINGS ("2.3", tConfigProcessor ["second_name_space.third_option"].getValue().c_str());
00135 
00136   //
00137   //  Only make argument checking when not in 'silent_mode'.
00138   //
00139   if ( !TEST_IN_SILENT_MODE )
00140   {
00141     TEST_NUMBERS (true, tConfigProcessor.hasArguments());
00142     TEST_NUMBERS (true, ( tConfigProcessor.numberOfArguments() == 3 ));  
00143     if ( tConfigProcessor.numberOfArguments() >= 3 )
00144     {
00145       TEST_STRINGS ("arg_0", tConfigProcessor.argumentValue (0).c_str());
00146       TEST_STRINGS ("arg_1", tConfigProcessor.argumentValue (1).c_str());  
00147       TEST_STRINGS ("arg_2", tConfigProcessor.argumentValue (2).c_str());
00148     }
00149   }
00150   tConfigProcessor.saveConfigFile();
00151 
00152   TEST_MEMORY_STATUS;
00153   TEST_RETURN_CODE;
00154 
00155 }  // main()

Generated on Mon Oct 13 02:35:24 2003 for MPCL by doxygen1.2.18