00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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
00069
00070 tConfigProcessor.setRootNameSpace();
00071 try
00072 {
00073
00074
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
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
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 }