[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Camino-devel] camino/src main-unittest.cpp common/MsgCoder.cp...
From: |
Philippe Fremy |
Subject: |
[Camino-devel] camino/src main-unittest.cpp common/MsgCoder.cp... |
Date: |
Sun, 26 Jan 2003 16:55:55 -0500 |
CVSROOT: /cvsroot/camino
Module name: camino
Changes by: Philippe Fremy <address@hidden> 03/01/26 16:55:54
Modified files:
src : main-unittest.cpp
src/common : MsgCoder.cpp MsgCoder.h MsgDecoder.cpp
MsgDecoder.h TestMsgDecoder.cpp
TestMsgDecoder.h
Log message:
uses qdatastream instead of qtextstream, to support strings with spaces
Patches:
Index: camino/src/common/MsgCoder.cpp
diff -u camino/src/common/MsgCoder.cpp:1.4 camino/src/common/MsgCoder.cpp:1.5
--- camino/src/common/MsgCoder.cpp:1.4 Sun Jan 26 15:32:19 2003
+++ camino/src/common/MsgCoder.cpp Sun Jan 26 16:55:54 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: MsgCoder.cpp,v 1.4 2003/01/26 20:32:19 pfremy Exp $
+** Version : $Id: MsgCoder.cpp,v 1.5 2003/01/26 21:55:54 pfremy Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 14/01/2003
@@ -30,9 +30,10 @@
MsgCoder::MsgCoder( QIODevice * socket)
-: QTextStream( socket )
+: QDataStream( socket )
{
- setEncoding( Latin1 );
+// setEncoding( Latin1 );
+// setPrintableData( true );
}
@@ -40,13 +41,15 @@
{
// Don't forget the spaces between each value
- *this << ConnectServer << " " << 0 << " " << playerName << endl;
+// *this << ConnectServer << " " << 0 << " " << playerName;
+ *this << ConnectServer << 0 << playerName;
device()->flush();
}
-void MsgCoder::sendMsg( NetMsgSubtype msgLevel, const QString & msg )
+void MsgCoder::sendMsg( NetMsgSubtype msgLevel, const QString & source, const
QString & msg )
{
- *this << Msg << " " << msgLevel << " " << msg << endl;
+ // *this << Msg << " " << msgLevel << " " << source << " " <<
msg.length() << msg; // << endl;
+ *this << Msg << msgLevel << source << msg;
device()->flush();
}
Index: camino/src/common/MsgCoder.h
diff -u camino/src/common/MsgCoder.h:1.5 camino/src/common/MsgCoder.h:1.6
--- camino/src/common/MsgCoder.h:1.5 Sun Jan 26 15:32:19 2003
+++ camino/src/common/MsgCoder.h Sun Jan 26 16:55:54 2003
@@ -3,7 +3,7 @@
** Camino
**
**
-** Version : $Id: MsgCoder.h,v 1.5 2003/01/26 20:32:19 pfremy Exp $
+** Version : $Id: MsgCoder.h,v 1.6 2003/01/26 21:55:54 pfremy Exp $
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 14/01/2003
** Copyright: Pascal Audoux, Philippe Fremy 2003
@@ -96,7 +96,7 @@
};
-class MsgCoder : public QTextStream
+class MsgCoder : public QDataStream
{
public:
@@ -106,7 +106,7 @@
//! from QTextStream: void setDevice( QIODevice * );
void connectServer( QString playerName );
- void sendMsg( NetMsgSubtype msgLevel, const QString & msg );
+ void sendMsg( NetMsgSubtype msgLevel, const QString & source, const
QString & msg );
private:
MsgCoder( MsgCoder & );
Index: camino/src/common/MsgDecoder.cpp
diff -u camino/src/common/MsgDecoder.cpp:1.5
camino/src/common/MsgDecoder.cpp:1.6
--- camino/src/common/MsgDecoder.cpp:1.5 Sun Jan 26 15:32:19 2003
+++ camino/src/common/MsgDecoder.cpp Sun Jan 26 16:55:54 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: MsgDecoder.cpp,v 1.5 2003/01/26 20:32:19 pfremy Exp $
+** Version : $Id: MsgDecoder.cpp,v 1.6 2003/01/26 21:55:54 pfremy Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 15/01/2003
@@ -25,7 +25,7 @@
// generic include files
// include files for QT
-#include <qtextstream.h>
+#include <qdatastream.h>
// application specific include files
#include "common/MsgDecoder.h"
@@ -36,7 +36,8 @@
MsgDecoder::MsgDecoder( QIODevice * socket )
{
setDevice( socket );
- _ts.setEncoding( QTextStream::Latin1 );
+ //_ts.setEncoding( QTextStream::Latin1 );
+// _ts.setPrintableData( true );
}
void MsgDecoder::setDevice( QIODevice * socket )
@@ -81,7 +82,8 @@
void MsgDecoder::decodeMsg()
{
- QString msg;
- _ts >> msg;
- recvMsg( msg );
+ qDebug( "MsgDecoder::decodeMsg()");
+ QString source, msg;
+ _ts >> source >> msg;
+ recvMsg( source , msg );
}
Index: camino/src/common/MsgDecoder.h
diff -u camino/src/common/MsgDecoder.h:1.7 camino/src/common/MsgDecoder.h:1.8
--- camino/src/common/MsgDecoder.h:1.7 Sun Jan 26 15:32:19 2003
+++ camino/src/common/MsgDecoder.h Sun Jan 26 16:55:54 2003
@@ -5,7 +5,7 @@
** MsgDecoder.h
** Decoder for socket msg
**
-** Version : $Id: MsgDecoder.h,v 1.7 2003/01/26 20:32:19 pfremy Exp $
+** Version : $Id: MsgDecoder.h,v 1.8 2003/01/26 21:55:54 pfremy Exp $
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 14/01/2003
** Copyright: Pascal Audoux, Philippe Fremy 2003
@@ -32,7 +32,7 @@
// include files for QT
#include <qstring.h>
#include <qobject.h>
-#include <qtextstream.h>
+#include <qdatastream.h>
// application specific include files
#include "common/MsgCoder.h"
@@ -57,7 +57,7 @@
void setDevice( QIODevice * socket );
virtual void recvServerConnect( QString /* playerName */ ) {}
- virtual void recvMsg( QString /* msg */ ) {}
+ virtual void recvMsg( QString /* source */ , QString /* msg */ ) {}
public slots:
/** call this to tell the Decoder that there is some data to decode
@@ -75,11 +75,12 @@
virtual void slotDecode();
protected:
+ //QString decodeString( int minimumLen );
void decodeServerConnect();
void decodeMsg();
QIODevice * _socket;
- QTextStream _ts;
+ QDataStream _ts;
NetMsgType _type;
NetMsgSubtype _subtype;
Index: camino/src/common/TestMsgDecoder.cpp
diff -u camino/src/common/TestMsgDecoder.cpp:1.4
camino/src/common/TestMsgDecoder.cpp:1.5
--- camino/src/common/TestMsgDecoder.cpp:1.4 Sun Jan 26 15:32:19 2003
+++ camino/src/common/TestMsgDecoder.cpp Sun Jan 26 16:55:54 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: TestMsgDecoder.cpp,v 1.4 2003/01/26 20:32:19 pfremy Exp $
+** Version : $Id: TestMsgDecoder.cpp,v 1.5 2003/01/26 21:55:54 pfremy Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 14/01/2003
@@ -62,7 +62,8 @@
QDataStream ds( &buf );
ds.setPrintableData( true );
- ds << 0 << 1 << 2 << QString("hop");
+ QString s("hop bof bip tuut 3");
+ ds << 0 << 1 << 2 << s;
buf.putch( 0 );
buf.flush();
buf.at(0);
@@ -71,13 +72,13 @@
// qDebug( "Buffer : '%s'", (const char *) mySocket );
int v1, v2, v3;
- QString s;
- ds >> v1 >> v2 >> v3 >> s;
-// qDebug( "v1=%d, v2=%d, v3=%d s = '%s'", v1, v2, v3, s.latin1() );
+ QString s1;
+ ds >> v1 >> v2 >> v3 >> s1;
+// qDebug( "v1=%d, v2=%d, v3=%d s = '%s'", v1, v2, v3, s1.latin1() );
checkEquals( v1, 0 );
checkEquals( v2, 1 );
checkEquals( v3, 2 );
- checkEquals( s, "hop" );
+ checkEquals( s, s1 );
}
void TestMsgDecoder::testQTextStream()
@@ -108,38 +109,6 @@
// ----------------------- Here, the real tests begins
-void TestMsgDecoder::testCreation()
-{
- /*
- {
- MsgDecoder md;
- MsgCoder mc;
- }
-
- QCString s;
- {
- QBuffer buf( s );
- QBuffer buf2( s );
- buf.open( IO_ReadWrite );
- buf2.open( IO_ReadWrite );
- MsgDecoder md( &buf );
- MsgCoder mc( &buf );
- MockDecoder md2( &buf );
- buf.close();
- buf2.close();
- MsgCoder();
- MsgDecoder();
- MockDecoder();
- }
-
- {
- QBuffer buf( s );
- // MsgCoder mc( &buf );
- // MsgCoder mc2 = mc;
- }
- */
-}
-
void TestMsgDecoder::testServerConnect()
{
QString playerName = "Phil";
@@ -155,17 +124,42 @@
checkEquals( _dec->s1, playerName );
}
+void TestMsgDecoder::testDecodeString()
+{
+ /*
+ QTextStream ts( _buf );
+ QString s = "A string with some space";
+
+ // put something into buffer
+ ts << s;
+
+ _buf->putch( 0 );
+ _buf->flush();
+ _buf->at(0);
+
+ qDebug("Socket content : '%s'", (const char *) *_socketContent );
+
+ int len;
+ ts >> len;
+
+ checkEquals( _dec->decodeString(len), s );
+ */
+}
+
void TestMsgDecoder::testSendMsg()
{
- QString msg = "Msg";
+ // test that a message with space inside is accepted
- _cod->sendMsg( DebugMsg, msg + "D" );
+ QString msg = "Msg with same space";
+ QString source = "Src";
+
+ _cod->sendMsg( DebugMsg, source + "1", msg + "D" );
_buf->flush();
- _cod->sendMsg( InfoMsg, msg + "I" );
+ _cod->sendMsg( InfoMsg, source + "2", msg + "I" );
_buf->flush();
- _cod->sendMsg( ChatMsg, msg + "C" );
+ _cod->sendMsg( ChatMsg, source + "3", msg + "C" );
_buf->putch( 0 );
_buf->flush();
_buf->at(0);
@@ -175,12 +169,16 @@
_dec->slotDecode();
checkEquals( _dec->subtype(), DebugMsg );
checkEquals( _dec->s1, msg + "D" );
+ checkEquals( _dec->s2, source + "1" );
_dec->slotDecode();
checkEquals( _dec->subtype(), InfoMsg );
checkEquals( _dec->s1, msg + "I" );
+ checkEquals( _dec->s2, source + "2" );
_dec->slotDecode();
checkEquals( _dec->subtype(), ChatMsg );
checkEquals( _dec->s1, msg + "C" );
+ checkEquals( _dec->s2, source + "3" );
+
}
Index: camino/src/common/TestMsgDecoder.h
diff -u camino/src/common/TestMsgDecoder.h:1.4
camino/src/common/TestMsgDecoder.h:1.5
--- camino/src/common/TestMsgDecoder.h:1.4 Sun Jan 26 15:32:19 2003
+++ camino/src/common/TestMsgDecoder.h Sun Jan 26 16:55:54 2003
@@ -5,7 +5,7 @@
** TestMsgDecoder.h
** this is a template for all .h test files
**
-** Version : $Id: TestMsgDecoder.h,v 1.4 2003/01/26 20:32:19 pfremy Exp $
+** Version : $Id: TestMsgDecoder.h,v 1.5 2003/01/26 21:55:54 pfremy Exp $
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 14/01/2003
**
@@ -55,9 +55,9 @@
CPPUNIT_TEST( testQDataStream );
CPPUNIT_TEST( testQTextStream );
- CPPUNIT_TEST( testCreation );
CPPUNIT_TEST( testServerConnect );
CPPUNIT_TEST( testSendMsg );
+ CPPUNIT_TEST( testDecodeString );
CPPUNIT_TEST_SUITE_END();
@@ -66,9 +66,9 @@
void testQDataStream();
void testQTextStream();
- void testCreation();
void testServerConnect();
void testSendMsg();
+ void testDecodeString();
protected:
@@ -93,8 +93,9 @@
s1 = playerName;
}
- void recvMsg( QString msg ) {
+ void recvMsg( QString source, QString msg ) {
s1 = msg;
+ s2 = source;
}
NetMsgType type() { return _type; }
Index: camino/src/main-unittest.cpp
diff -u camino/src/main-unittest.cpp:1.4 camino/src/main-unittest.cpp:1.5
--- camino/src/main-unittest.cpp:1.4 Sun Jan 26 15:32:18 2003
+++ camino/src/main-unittest.cpp Sun Jan 26 16:55:54 2003
@@ -1,3 +1,7 @@
+
+#include <qapplication.h>
+#include <qwidget.h>
+
#include <iostream>
#include <cppunit/extensions/TestFactoryRegistry.h>