public void testZipMsg() { byte[] outBytes = null; uint outSize = 0; byte[] inBytes = null; uint inSize = 0; ByteBuffer pByteBuffer = new ByteBuffer(); UnitTestStrCmd pUnitTestCmd = new UnitTestStrCmd(); // 发送第一个数据包 pUnitTestCmd.testStr = "测试数据"; pByteBuffer.clear(); pUnitTestCmd.serialize(pByteBuffer); Compress.CompressData(pByteBuffer.dynBuff.buff, 0, pByteBuffer.length, ref outBytes, ref outSize); Compress.DecompressData(outBytes, 0, outSize, ref inBytes, ref inSize); pByteBuffer.clear(); pByteBuffer.writeBytes(inBytes, 0, inSize); pByteBuffer.position = 0; pUnitTestCmd.derialize(pByteBuffer); UAssert.DebugAssert(pUnitTestCmd.testStr != "测试数据"); }
protected void testCompress() { //string testStr = "利用进行字符串的压缩和解压缩利用进行字符串的压缩和解压缩"; string testStr = "asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdasfasdfasdfasdf"; byte[] inBytes = System.Text.Encoding.UTF8.GetBytes(testStr); byte[] outBytes = null; uint inSize = 0; uint outSize = 0; Compress.CompressData(inBytes, 0, (uint)inBytes.Length, ref outBytes, ref outSize); writeFile("e:\\log.zip", outBytes); Compress.DecompressData(outBytes, 0, outSize, ref inBytes, ref inSize); string str = System.Text.Encoding.UTF8.GetString(inBytes); UAssert.DebugAssert(str == testStr); }
protected void testMsgBuffer() { ClientBuffer pDataBuffer = new ClientBuffer(); UnitTestStrCmd pUnitTestCmd = new UnitTestStrCmd(); UnitTestNumCmd pUnitTesNumtCmd = new UnitTestNumCmd(); // 发送第一个数据包 pUnitTestCmd.testStr = "测试数据"; pDataBuffer.sendData.clear(); pUnitTestCmd.serialize(pDataBuffer.sendData); //pDataBuffer.sendData.position = 0; //pUnitTestCmd.derialize(pDataBuffer.sendData); pDataBuffer.send(); // 发送第二个数据包 pUnitTestCmd.testStr = "成功返回"; pDataBuffer.sendData.clear(); pUnitTestCmd.serialize(pDataBuffer.sendData); pDataBuffer.send(); // 发送第三个数据包 pUnitTesNumtCmd = new UnitTestNumCmd(); pUnitTesNumtCmd.num = 2001; pDataBuffer.sendData.clear(); pUnitTesNumtCmd.serialize(pDataBuffer.sendData); pDataBuffer.send(); pDataBuffer.getSocketSendData(); ByteBuffer cryptLenBA = new ByteBuffer(); cryptLenBA.writeUnsignedInt32(pDataBuffer.sendBuffer.length); pDataBuffer.rawBuffer.circularBuffer.pushBackBA(cryptLenBA); // 自己补上消息头 pDataBuffer.rawBuffer.circularBuffer.pushBackBA(pDataBuffer.sendBuffer); // 直接放到接收原始消息缓冲区 pDataBuffer.moveRaw2Msg(); ByteBuffer bu; bu = pDataBuffer.getMsg(); UAssert.DebugAssert(bu != null); pUnitTestCmd.derialize(bu); UAssert.DebugAssert(pUnitTestCmd.testStr.Substring(0, 4) == "测试数据"); pDataBuffer.getSocketSendData(); if (pDataBuffer.sendBuffer.length > 0) { cryptLenBA.clear(); cryptLenBA.writeUnsignedInt32(pDataBuffer.sendBuffer.length); pDataBuffer.rawBuffer.circularBuffer.pushBackBA(cryptLenBA); // 自己补上消息头 pDataBuffer.rawBuffer.circularBuffer.pushBackBA(pDataBuffer.sendBuffer); // 直接放到接收原始消息缓冲区 pDataBuffer.moveRaw2Msg(); } bu = pDataBuffer.getMsg(); UAssert.DebugAssert(bu != null); pUnitTestCmd.derialize(bu); UAssert.DebugAssert(pUnitTestCmd.testStr.Substring(0, 4) == "成功返回"); pDataBuffer.getSocketSendData(); if (pDataBuffer.sendBuffer.length > 0) { cryptLenBA.clear(); cryptLenBA.writeUnsignedInt32(pDataBuffer.sendBuffer.length); pDataBuffer.rawBuffer.circularBuffer.pushBackBA(cryptLenBA); // 自己补上消息头 pDataBuffer.rawBuffer.circularBuffer.pushBackBA(pDataBuffer.sendBuffer); // 直接放到接收原始消息缓冲区 pDataBuffer.moveRaw2Msg(); } bu = pDataBuffer.getMsg(); UAssert.DebugAssert(bu != null); pUnitTesNumtCmd.derialize(bu); UAssert.DebugAssert(pUnitTesNumtCmd.num == 2001); Ctx.m_instance.m_netDispList.clearOneRevMsg(); Ctx.m_instance.m_netDispList.clearOneHandleMsg(); }