00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <spl/Debug.h>
00018 #include <spl/io/BlockingStream.h>
00019 #include <spl/Log.h>
00020 #include <spl/net/Packet.h>
00021 #include <spl/io/MemoryStream.h>
00022
00023 #ifdef DEBUG
00024
00025 static void _TestPacket1()
00026 {
00027 Packet *pkt = new Packet();
00028 DEBUG_CLEAR_MEM_CHECK_POINTS();
00029 DEBUG_NOTE_MEM( pkt );
00030 pkt->CheckMem();
00031 DEBUG_DUMP_MEM_LEAKS();
00032 UNIT_ASSERT_MEM_NOTED("Packet test 1.0");
00033
00034 delete pkt;
00035 DEBUG_CLEAR_MEM_CHECK_POINTS();
00036 DEBUG_DUMP_MEM_LEAKS();
00037 UNIT_ASSERT_MEM_NOTED("Packet test 1.1");
00038
00039 Log::SWriteOkFail( "Packet test 1" );
00040 }
00041
00042 static void _TestPacket2()
00043 {
00044 Packet *pkt = new Packet();
00045 ASSERT_MEM( pkt, sizeof(Packet) );
00046 pkt->ValidateMem();
00047
00048 BlockingStream con(MemoryStreamPtr(new MemoryStream()));
00049
00050 pkt->Append("hi");
00051 pkt->Append(71010);
00052 pkt->Append(66.6);
00053 pkt->Append((int16)3);
00054 pkt->SendPacket(con);
00055
00056 DEBUG_CLEAR_MEM_CHECK_POINTS();
00057 DEBUG_NOTE_MEM( pkt );
00058 pkt->CheckMem();
00059 con.CheckMem();
00060 DEBUG_DUMP_MEM_LEAKS();
00061 UNIT_ASSERT_MEM_NOTED("Packet test 2.0");
00062
00063 DEBUG_CLEAR_MEM_CHECK_POINTS();
00064 DEBUG_NOTE_MEM( pkt );
00065 pkt->CheckMem();
00066 con.CheckMem();
00067 DEBUG_DUMP_MEM_LEAKS();
00068 UNIT_ASSERT_MEM_NOTED("Packet test 2.1");
00069
00070 pkt->ReadPacket(con);
00071 StringPtr str = pkt->ReadString();
00072 UNIT_ASSERT("pkt->ReadString == hi", str->Equals("hi"));
00073 UNIT_ASSERT("pkt->ReadInt == 71010", pkt->ReadInt32() == 71010);
00074 UNIT_ASSERT("pkt->ReadDouble == 66.6", pkt->ReadDouble() == 66.6);
00075 UNIT_ASSERT("pkt->ReadInt16 = 3.14", pkt->ReadInt16() == 3);
00076
00077 delete pkt;
00078 DEBUG_CLEAR_MEM_CHECK_POINTS();
00079 con.CheckMem();
00080 str.CheckMem();
00081 DEBUG_DUMP_MEM_LEAKS();
00082 UNIT_ASSERT_MEM_NOTED("Packet test 2.2");
00083
00084 Log::SWriteOkFail( "Packet test 2" );
00085 }
00086
00087 void TestPacket()
00088 {
00089 _TestPacket1();
00090 DEBUG_CLEAR_MEM_CHECK_POINTS();
00091 DEBUG_DUMP_MEM_LEAKS();
00092
00093 _TestPacket2();
00094 DEBUG_CLEAR_MEM_CHECK_POINTS();
00095 DEBUG_DUMP_MEM_LEAKS();
00096 }
00097
00098 #endif