00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <spl/Debug.h>
00018
00019 #ifdef DEBUG
00020 #include <spl/Log.h>
00021 #include <spl/web/Uri.h>
00022
00023 static void _TestUri1()
00024 {
00025 Uri *uri = new Uri();
00026
00027 DEBUG_CLEAR_MEM_CHECK_POINTS();
00028 DEBUG_NOTE_MEM(uri);
00029 uri->CheckMem();
00030 DEBUG_DUMP_MEM_LEAKS();
00031 UNIT_ASSERT_MEM_NOTED("Uri test 1.0");
00032
00033 uri->Parse("http://localhost:8080/xml?addr=3501%20NE%20105TH%20ST&city=&zip=98125");
00034
00035 DEBUG_CLEAR_MEM_CHECK_POINTS();
00036 DEBUG_NOTE_MEM(uri);
00037 uri->CheckMem();
00038 DEBUG_DUMP_MEM_LEAKS();
00039 UNIT_ASSERT_MEM_NOTED("Uri test 1.1");
00040
00041 UNIT_ASSERT("protocol", uri->Protocol().Equals("http"));
00042 UNIT_ASSERT("host", uri->Host().Equals("localhost"));
00043 UNIT_ASSERT("port", uri->Port() == 8080);
00044 UNIT_ASSERT("path", uri->Path().Equals("/xml"));
00045 UNIT_ASSERT("param count", uri->Args().Count() == 3);
00046 UNIT_ASSERT("has addr", uri->HasArg("addr"));
00047 UNIT_ASSERT("has city", uri->HasArg("city"));
00048 UNIT_ASSERT("has zip", uri->HasArg("zip"));
00049 UNIT_ASSERT("addr", uri->GetArg("addr").Equals("3501 NE 105TH ST"));
00050 UNIT_ASSERT("city", uri->GetArg("city").Equals(""));
00051 UNIT_ASSERT("zip", uri->GetArg("zip").Equals("98125"));
00052
00053 delete uri;
00054
00055 DEBUG_CLEAR_MEM_CHECK_POINTS();
00056 DEBUG_DUMP_MEM_LEAKS();
00057 UNIT_ASSERT_MEM_NOTED("Uri test 1.3");
00058
00059 uri = new Uri();
00060 uri->Parse("/");
00061 UNIT_ASSERT("/", uri->Path().Equals("/"));
00062
00063 delete uri;
00064
00065 DEBUG_CLEAR_MEM_CHECK_POINTS();
00066 DEBUG_DUMP_MEM_LEAKS();
00067 UNIT_ASSERT_MEM_NOTED("Uri test 1.4");
00068
00069 Log::SWriteOkFail( "Uri test 1" );
00070 }
00071
00072 static void _TestUri2()
00073 {
00074 Uri *uri = new Uri();
00075
00076 uri->Parse("http://localhost/xml.asp");
00077
00078 DEBUG_CLEAR_MEM_CHECK_POINTS();
00079 DEBUG_NOTE_MEM(uri);
00080 uri->CheckMem();
00081 DEBUG_DUMP_MEM_LEAKS();
00082 UNIT_ASSERT_MEM_NOTED("Uri test 2.0");
00083
00084 UNIT_ASSERT("protocol", uri->Protocol().Equals("http"));
00085 UNIT_ASSERT("host", uri->Host().Equals("localhost"));
00086 UNIT_ASSERT("port", uri->Port() == 80);
00087 UNIT_ASSERT("path", uri->Path().Equals("/"));
00088 UNIT_ASSERT("filename", uri->Filename().Equals("xml.asp"));
00089 UNIT_ASSERT("fileext", uri->FileExt().Equals("asp"));
00090 UNIT_ASSERT("param count", uri->Args().Count() == 0);
00091
00092 delete uri;
00093
00094 DEBUG_CLEAR_MEM_CHECK_POINTS();
00095 DEBUG_DUMP_MEM_LEAKS();
00096 UNIT_ASSERT_MEM_NOTED("Uri test 2.3");
00097
00098 Log::SWriteOkFail( "Uri test 2" );
00099 }
00100
00101 void _TestUri()
00102 {
00103 _TestUri1();
00104 DEBUG_CLEAR_MEM_CHECK_POINTS();
00105 DEBUG_DUMP_MEM_LEAKS();
00106
00107 _TestUri2();
00108 DEBUG_CLEAR_MEM_CHECK_POINTS();
00109 DEBUG_DUMP_MEM_LEAKS();
00110 }
00111
00112
00113 #endif