00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <spl/Debug.h>
00018 #include <spl/configuration/CommandLine.h>
00019
00020 #ifdef DEBUG
00021
00022 #include <spl/Log.h>
00023
00024 static void _TestCommandLine1()
00025 {
00026 CommandLine cl(0, NULL);
00027 DEBUG_CLEAR_MEM_CHECK_POINTS();
00028 cl.CheckMem();
00029 DEBUG_DUMP_MEM_LEAKS();
00030 UNIT_ASSERT_MEM_NOTED("CommandLine test 1.0");
00031
00032 Log::SWriteOkFail( "CommandLine test 1" );
00033 }
00034
00035 static void _TestCommandLine2()
00036 {
00037 DEBUG_CLEAR_MEM_CHECK_POINTS();
00038 DEBUG_DUMP_MEM_LEAKS();
00039 UNIT_ASSERT_MEM_NOTED("Test command line 2");
00040
00041 const char *argv[] = {"prog", "--dir2=/bob/is/here"};
00042
00043 CommandLine cl(2, argv);
00044 cl.ValidateMem();
00045
00046 DEBUG_CLEAR_MEM_CHECK_POINTS();
00047 cl.CheckMem();
00048 DEBUG_DUMP_MEM_LEAKS();
00049 UNIT_ASSERT_MEM_NOTED("CommandLine test 2.1");
00050
00051 UNIT_ASSERT( "arg count", 1 == cl.GetArgCount() );
00052 UNIT_ASSERT( "prog", cl.GetArg(0).Equals("prog") );
00053 UNIT_ASSERT( "dir2 doesn't exist", cl.HasSwitch("dir2") );
00054 UNIT_ASSERT( "dir2!=/bob/is/here", cl.GetSwitch("dir2").Equals("/bob/is/here") );
00055
00056 Log::SWriteOkFail( "CommandLine test 2.0" );
00057 }
00058
00059 static void _TestCommandLine3()
00060 {
00061 const char *argv[] = {"prog", "-t=bob", "--dir=/mydir", "arg1", "--dir2=/bob/is/here"};
00062
00063 CommandLine cl(5, argv);
00064
00065 cl.ValidateMem();
00066
00067
00068 DEBUG_CLEAR_MEM_CHECK_POINTS();
00069 cl.CheckMem();
00070 DEBUG_DUMP_MEM_LEAKS();
00071 UNIT_ASSERT_MEM_NOTED("CommandLine test 3.0");
00072
00073 UNIT_ASSERT( "arg count", 2 == cl.GetArgCount() );
00074 UNIT_ASSERT( "switch count", 3 == cl.GetSwitchCount() );
00075 UNIT_ASSERT( "prog", cl.GetArg(0).Equals("prog") );
00076 UNIT_ASSERT( "-t", cl.HasSwitch("t") );
00077 UNIT_ASSERT( "dir=/mydir", cl.HasSwitch("dir") );
00078 UNIT_ASSERT( "dir=/mydir", cl.GetSwitch("dir").Equals("/mydir") );
00079 UNIT_ASSERT( "dir2=/bob/is/here", cl.GetSwitch("dir2").Equals("/bob/is/here") );
00080
00081 Log::SWriteOkFail( "CommandLine test 3" );
00082 }
00083
00084 static void _TestCommandLine4()
00085 {
00086 const char *argv[] = {"prog", "/t", "/dir", "\\mydir", "arg1", "/dir2:\\bob\\is\\here"};
00087
00088 CommandLine cl(6, argv);
00089
00090 DEBUG_CLEAR_MEM_CHECK_POINTS();
00091 cl.CheckMem();
00092 DEBUG_DUMP_MEM_LEAKS();
00093 UNIT_ASSERT_MEM_NOTED("CommandLine test 4.0");
00094
00095 UNIT_ASSERT( "arg count", 3 == cl.GetArgCount() );
00096 UNIT_ASSERT( "prog", cl.GetArg(0).Equals("prog") );
00097 UNIT_ASSERT( "prog", cl.GetArg(1).Equals("\\mydir") );
00098 UNIT_ASSERT( "prog", cl.GetArg(2).Equals("arg1") );
00099 UNIT_ASSERT( "-t", cl.HasSwitch("t") );
00100 UNIT_ASSERT( "dir=/mydir", cl.HasSwitch("dir") );
00101 UNIT_ASSERT( "dir=/mydir", cl.GetSwitch("dir").Equals("") );
00102 UNIT_ASSERT( "dir2=/bob/is/here", cl.GetSwitch("dir2").Equals("\\bob\\is\\here") );
00103
00104 Log::SWriteOkFail( "CommandLine test 4" );
00105 }
00106
00107 static void _TestCommandLine5()
00108 {
00109 const char *argv[] = {"/home/john/sources/spl/AnsiTerminal/.libs/lt-ansiterm", "localhost", "8011"};
00110
00111 CommandLine cl(3, argv);
00112 cl.ValidateMem();
00113
00114 DEBUG_CLEAR_MEM_CHECK_POINTS();
00115 cl.CheckMem();
00116 DEBUG_DUMP_MEM_LEAKS();
00117 UNIT_ASSERT_MEM_NOTED("CommandLine test 5.0");
00118
00119 UNIT_ASSERT( "arg count", 3 == cl.GetArgCount() );
00120 UNIT_ASSERT( "prog", cl.GetArg(0).Equals("/home/john/sources/spl/AnsiTerminal/.libs/lt-ansiterm") );
00121 UNIT_ASSERT( "localhost", cl.GetArg(1).Equals("localhost") );
00122 UNIT_ASSERT( "port", cl.GetArg(2).Equals("8011") );
00123
00124 Log::SWriteOkFail( "CommandLine test 5" );
00125 }
00126
00127 void _CommandLineRegression1()
00128 {
00129 const char *argv[] = {"/home/john/sources/CoreServer/.libs/lt-RunTest"};
00130 CommandLine *cl = new CommandLine(1, argv);
00131
00132 DEBUG_CLEAR_MEM_CHECK_POINTS();
00133 DEBUG_NOTE_MEM(cl);
00134 cl->CheckMem();
00135 DEBUG_DUMP_MEM_LEAKS();
00136 UNIT_ASSERT_MEM_NOTED("CommandLine regresstion 1.1");
00137
00138 delete cl;
00139 DEBUG_CLEAR_MEM_CHECK_POINTS();
00140 DEBUG_DUMP_MEM_LEAKS();
00141 UNIT_ASSERT_MEM_NOTED("CommandLine regresstion 1.2");
00142
00143 Log::SWriteOkFail( "CommandLine regression 1" );
00144 }
00145
00146 void TestCommandLine()
00147 {
00148 _TestCommandLine1();
00149 DEBUG_CLEAR_MEM_CHECK_POINTS();
00150 DEBUG_DUMP_MEM_LEAKS();
00151
00152 _TestCommandLine2();
00153 DEBUG_CLEAR_MEM_CHECK_POINTS();
00154 DEBUG_DUMP_MEM_LEAKS();
00155
00156 _TestCommandLine3();
00157 DEBUG_CLEAR_MEM_CHECK_POINTS();
00158 DEBUG_DUMP_MEM_LEAKS();
00159
00160 _TestCommandLine4();
00161 DEBUG_CLEAR_MEM_CHECK_POINTS();
00162 DEBUG_DUMP_MEM_LEAKS();
00163
00164 _TestCommandLine5();
00165 DEBUG_CLEAR_MEM_CHECK_POINTS();
00166 DEBUG_DUMP_MEM_LEAKS();
00167
00168 _CommandLineRegression1();
00169 DEBUG_CLEAR_MEM_CHECK_POINTS();
00170 DEBUG_DUMP_MEM_LEAKS();
00171 }
00172
00173 #endif