mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-07 14:12:43 -04:00
added more extensive test for rsdataservice and subsequent bug fixes.
added test for RsNxsTransac item. applied rule of three to RsTlvBinaryData (destructor, assign op, copy constructor implemented) git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-new_cache_system@5196 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
36103b29a1
commit
822e395f93
17 changed files with 1107 additions and 73 deletions
|
@ -46,27 +46,13 @@
|
||||||
#define COL_IDENTITY 8
|
#define COL_IDENTITY 8
|
||||||
|
|
||||||
|
|
||||||
|
#define RS_DATA_SERVICE_DEBUG
|
||||||
|
|
||||||
RsDataService::RsDataService(const std::string &serviceDir, const std::string &dbName, uint16_t serviceType,
|
RsDataService::RsDataService(const std::string &serviceDir, const std::string &dbName, uint16_t serviceType,
|
||||||
RsGxsSearchModule *mod)
|
RsGxsSearchModule *mod)
|
||||||
: mServiceDir(serviceDir), mDbName(dbName), mServType(serviceType){
|
: mServiceDir(serviceDir), mDbName(mServiceDir + "/" + dbName), mServType(serviceType){
|
||||||
|
|
||||||
|
initialise();
|
||||||
// initialise database
|
|
||||||
mDb = new RetroDb(dbName, RetroDb::OPEN_READWRITE_CREATE);
|
|
||||||
|
|
||||||
// create table for msgs
|
|
||||||
mDb->execSQL("CREATE TABLE " + MSG_TABLE_NAME + "(" + KEY_MSG_ID
|
|
||||||
+ " TEXT," + KEY_GRP_ID + " TEXT," + KEY_NXS_FLAGS + " INT,"
|
|
||||||
+ KEY_TIME_STAMP + " INT," + KEY_PUBLISH_SIGN + " BLOB," + KEY_NXS_IDENTITY + " TEXT,"
|
|
||||||
+ KEY_IDENTITY_SIGN + " BLOB," + KEY_NXS_FILE + " TEXT,"+ KEY_NXS_FILE_OFFSET + " INT,"
|
|
||||||
+ KEY_NXS_FILE_LEN+ " INT);");
|
|
||||||
|
|
||||||
// create table for grps
|
|
||||||
mDb->execSQL("CREATE TABLE " + GRP_TABLE_NAME + "(" + KEY_GRP_ID +
|
|
||||||
" TEXT," + KEY_TIME_STAMP + " INT," +
|
|
||||||
KEY_ADMIN_SIGN + " BLOB," + " BLOB," + KEY_NXS_FILE +
|
|
||||||
" TEXT," + KEY_NXS_FILE_OFFSET + " INT," + KEY_KEY_SET + " BLOB," + KEY_NXS_FILE_LEN + " INT,"
|
|
||||||
+ KEY_NXS_IDENTITY + " TEXT," + KEY_NXS_FLAGS + " INT," + KEY_IDENTITY_SIGN + " BLOB);");
|
|
||||||
|
|
||||||
msgColumns.push_back(KEY_GRP_ID); msgColumns.push_back(KEY_PUBLISH_SIGN); msgColumns.push_back(KEY_NXS_FILE);
|
msgColumns.push_back(KEY_GRP_ID); msgColumns.push_back(KEY_PUBLISH_SIGN); msgColumns.push_back(KEY_NXS_FILE);
|
||||||
msgColumns.push_back(KEY_NXS_FILE_OFFSET); msgColumns.push_back(KEY_NXS_FILE_LEN); msgColumns.push_back(KEY_TIME_STAMP);
|
msgColumns.push_back(KEY_NXS_FILE_OFFSET); msgColumns.push_back(KEY_NXS_FILE_LEN); msgColumns.push_back(KEY_TIME_STAMP);
|
||||||
|
@ -84,6 +70,27 @@ RsDataService::~RsDataService(){
|
||||||
delete mDb;
|
delete mDb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RsDataService::initialise(){
|
||||||
|
|
||||||
|
// initialise database
|
||||||
|
mDb = new RetroDb(mDbName, RetroDb::OPEN_READWRITE_CREATE);
|
||||||
|
|
||||||
|
// create table for msgs
|
||||||
|
mDb->execSQL("CREATE TABLE " + MSG_TABLE_NAME + "(" + KEY_MSG_ID
|
||||||
|
+ " TEXT," + KEY_GRP_ID + " TEXT," + KEY_NXS_FLAGS + " INT,"
|
||||||
|
+ KEY_TIME_STAMP + " INT," + KEY_PUBLISH_SIGN + " BLOB," + KEY_NXS_IDENTITY + " TEXT,"
|
||||||
|
+ KEY_IDENTITY_SIGN + " BLOB," + KEY_NXS_FILE + " TEXT,"+ KEY_NXS_FILE_OFFSET + " INT,"
|
||||||
|
+ KEY_NXS_FILE_LEN+ " INT);");
|
||||||
|
|
||||||
|
// create table for grps
|
||||||
|
mDb->execSQL("CREATE TABLE " + GRP_TABLE_NAME + "(" + KEY_GRP_ID +
|
||||||
|
" TEXT," + KEY_TIME_STAMP + " INT," +
|
||||||
|
KEY_ADMIN_SIGN + " BLOB," + " BLOB," + KEY_NXS_FILE +
|
||||||
|
" TEXT," + KEY_NXS_FILE_OFFSET + " INT," + KEY_KEY_SET + " BLOB," + KEY_NXS_FILE_LEN + " INT,"
|
||||||
|
+ KEY_NXS_IDENTITY + " TEXT," + KEY_NXS_FLAGS + " INT," + KEY_IDENTITY_SIGN + " BLOB);");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
RsNxsGrp* RsDataService::getGroup(RetroCursor &c){
|
RsNxsGrp* RsDataService::getGroup(RetroCursor &c){
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -409,7 +416,7 @@ int RsDataService::retrieveMsgVersions(const std::string &grpId, const std::stri
|
||||||
std::set<RsNxsMsg *>& msg, bool cache){
|
std::set<RsNxsMsg *>& msg, bool cache){
|
||||||
|
|
||||||
|
|
||||||
std::string selection = KEY_GRP_ID + "=" + grpId + "," + KEY_MSG_ID + "=" + msgId;
|
std::string selection = KEY_GRP_ID + "='" + grpId + "' and " + KEY_MSG_ID + "='" + msgId + "'";
|
||||||
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgColumns, selection, "");
|
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, msgColumns, selection, "");
|
||||||
|
|
||||||
|
|
||||||
|
@ -435,8 +442,8 @@ int RsDataService::retrieveMsgVersions(const std::string &grpId, const std::stri
|
||||||
|
|
||||||
int RsDataService::retrieveGrpVersions(const std::string &grpId, std::set<RsNxsGrp *> &grp, bool cache){
|
int RsDataService::retrieveGrpVersions(const std::string &grpId, std::set<RsNxsGrp *> &grp, bool cache){
|
||||||
|
|
||||||
std::string selection = KEY_GRP_ID + "=" + grpId;
|
std::string selection = KEY_GRP_ID + "='" + grpId + "'";
|
||||||
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, msgColumns, selection, "");
|
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, grpColumns, selection, "");
|
||||||
|
|
||||||
if(c){
|
if(c){
|
||||||
|
|
||||||
|
@ -502,7 +509,7 @@ RsNxsMsg* RsDataService::retrieveMsgVersion(const RsGxsMsgId &msgId){
|
||||||
for(; sit != msgs.end(); sit++){
|
for(; sit != msgs.end(); sit++){
|
||||||
|
|
||||||
msg = *sit;
|
msg = *sit;
|
||||||
if(!memcmp(msg->idSign.signData.bin_data, msgId.idSign.signData.bin_data,
|
if(0 == memcmp(msg->idSign.signData.bin_data, msgId.idSign.signData.bin_data,
|
||||||
msg->idSign.signData.bin_len))
|
msg->idSign.signData.bin_len))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -523,6 +530,28 @@ RsNxsMsg* RsDataService::retrieveMsgVersion(const RsGxsMsgId &msgId){
|
||||||
|
|
||||||
int RsDataService::resetDataStore(){
|
int RsDataService::resetDataStore(){
|
||||||
|
|
||||||
|
#ifdef RS_DATA_SERVICE_DEBUG
|
||||||
|
std::cerr << "resetDataStore() " << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::map<std::string, RsNxsGrp*> grps;
|
||||||
|
retrieveGrps(grps, false);
|
||||||
|
std::map<std::string, RsNxsGrp*>::iterator mit
|
||||||
|
= grps.begin();
|
||||||
|
|
||||||
|
for(; mit != grps.end(); mit++){
|
||||||
|
std::string file = mServiceDir + "/" + mit->first;
|
||||||
|
std::string msgFile = file + "-msgs";
|
||||||
|
remove(file.c_str());
|
||||||
|
remove(msgFile.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
mDb->closeDb();
|
||||||
|
remove(mDbName.c_str());
|
||||||
|
|
||||||
|
initialise();
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RsDataService::removeGroups(const std::list<RsGxsGrpId> &grpIds){
|
int RsDataService::removeGroups(const std::list<RsGxsGrpId> &grpIds){
|
||||||
|
|
|
@ -117,6 +117,7 @@ public:
|
||||||
* Completely clear out data stored in
|
* Completely clear out data stored in
|
||||||
* this data store and returns this to a state
|
* this data store and returns this to a state
|
||||||
* as it was when first constructed
|
* as it was when first constructed
|
||||||
|
* This also clears any data store items created in service directory
|
||||||
*/
|
*/
|
||||||
int resetDataStore();
|
int resetDataStore();
|
||||||
|
|
||||||
|
@ -125,6 +126,7 @@ private:
|
||||||
|
|
||||||
RsNxsMsg* getMessage(RetroCursor& c);
|
RsNxsMsg* getMessage(RetroCursor& c);
|
||||||
RsNxsGrp* getGroup(RetroCursor& c);
|
RsNxsGrp* getGroup(RetroCursor& c);
|
||||||
|
void initialise();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,7 @@ class RsGeneralDataService
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
virtual ~RsGeneralDataService(){return;};
|
||||||
/*!
|
/*!
|
||||||
* Retrieves signed message
|
* Retrieves signed message
|
||||||
* @param grpId
|
* @param grpId
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
* The interface is sparse as this service is mostly making the requests to other GXS components
|
* The interface is sparse as this service is mostly making the requests to other GXS components
|
||||||
*
|
*
|
||||||
* Groups:
|
* Groups:
|
||||||
* - As this is where exchanges occur between peers, this is also where groups relationships
|
* - As this is where exchanges occur between peers, this is also where group's relationships
|
||||||
* should get resolved as far as
|
* should get resolved as far as
|
||||||
* - Per implemented GXS there are a set of rules which will determine whether data is transferred
|
* - Per implemented GXS there are a set of rules which will determine whether data is transferred
|
||||||
* between any set of groups
|
* between any set of groups
|
||||||
|
@ -62,12 +62,13 @@ public:
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Use this to set how far back synchronisation of messages should take place
|
* Use this to set how far back synchronisation of messages should take place
|
||||||
* @param range how far back from current time to synchronise with other peers
|
* @param age the max age a sync item can to be allowed in a synchronisation
|
||||||
*/
|
*/
|
||||||
virtual void setTimeRange(uint64_t range) = 0;
|
virtual void setSyncAge(uint32_t age) = 0;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* requests all the groups contained by a peer
|
* Explicitly requests all the groups contained by a peer
|
||||||
|
* Circumvents polling of peers for message
|
||||||
* @param peerId id of peer
|
* @param peerId id of peer
|
||||||
*/
|
*/
|
||||||
virtual void requestGroupsOfPeer(const std::string& peerId) = 0;
|
virtual void requestGroupsOfPeer(const std::string& peerId) = 0;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
TEMPLATE = lib
|
TEMPLATE = lib
|
||||||
#CONFIG += staticlib release
|
#CONFIG += staticlib release
|
||||||
#CONFIG += staticlib testnetwork
|
#CONFIG += staticlib testnetwork
|
||||||
CONFIG += staticlib bitdht newcache# newservices
|
CONFIG += staticlib bitdht newcache newservices
|
||||||
CONFIG -= qt
|
CONFIG -= qt
|
||||||
TARGET = retroshare
|
TARGET = retroshare
|
||||||
#DEFINES += RSSERIAL_DEBUG
|
#DEFINES += RSSERIAL_DEBUG
|
||||||
|
|
|
@ -21,28 +21,32 @@ uint32_t RsNxsSerialiser::size(RsItem *item) {
|
||||||
RsSyncGrpList* sgl;
|
RsSyncGrpList* sgl;
|
||||||
RsSyncGrpMsg* sgm;
|
RsSyncGrpMsg* sgm;
|
||||||
RsSyncGrpMsgList* sgml;
|
RsSyncGrpMsgList* sgml;
|
||||||
|
RsNxsTransac* ntx;
|
||||||
|
|
||||||
|
|
||||||
if((sg = dynamic_cast<RsSyncGrp*>(item)) != NULL)
|
if((sg = dynamic_cast<RsSyncGrp*>(item)) != NULL)
|
||||||
{
|
{
|
||||||
sizeSyncGrp(sg);
|
return sizeSyncGrp(sg);
|
||||||
|
|
||||||
}else if ((sgl = dynamic_cast<RsSyncGrpList*>(item)) != NULL)
|
}else if(( ntx = dynamic_cast<RsNxsTransac*>(item)) != NULL){
|
||||||
|
return sizeNxsTrans(ntx);
|
||||||
|
}
|
||||||
|
else if ((sgl = dynamic_cast<RsSyncGrpList*>(item)) != NULL)
|
||||||
{
|
{
|
||||||
sizeSyncGrpList(sgl);
|
return sizeSyncGrpList(sgl);
|
||||||
|
|
||||||
}else if ((sgm = dynamic_cast<RsSyncGrpMsg*>(item)) != NULL)
|
}else if ((sgm = dynamic_cast<RsSyncGrpMsg*>(item)) != NULL)
|
||||||
{
|
{
|
||||||
sizeSyncGrpMsg(sgm);
|
return sizeSyncGrpMsg(sgm);
|
||||||
}else if ((sgml = dynamic_cast<RsSyncGrpMsgList*>(item)) != NULL)
|
}else if ((sgml = dynamic_cast<RsSyncGrpMsgList*>(item)) != NULL)
|
||||||
{
|
{
|
||||||
sizeSyncGrpMsgList(sgml);
|
return sizeSyncGrpMsgList(sgml);
|
||||||
}else if((ngp = dynamic_cast<RsNxsGrp*>(item)) != NULL)
|
}else if((ngp = dynamic_cast<RsNxsGrp*>(item)) != NULL)
|
||||||
{
|
{
|
||||||
sizeNxsGrp(ngp);
|
return sizeNxsGrp(ngp);
|
||||||
}else if((nmg = dynamic_cast<RsNxsMsg*>(item)) != NULL)
|
}else if((nmg = dynamic_cast<RsNxsMsg*>(item)) != NULL)
|
||||||
{
|
{
|
||||||
sizeNxsMsg(nmg);
|
return sizeNxsMsg(nmg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,6 +81,8 @@ RsItem* RsNxsSerialiser::deserialise(void *data, uint32_t *size) {
|
||||||
return deserialNxsGrp(data, size);
|
return deserialNxsGrp(data, size);
|
||||||
case RS_PKT_SUBTYPE_NXS_MSG:
|
case RS_PKT_SUBTYPE_NXS_MSG:
|
||||||
return deserialNxsMsg(data, size);
|
return deserialNxsMsg(data, size);
|
||||||
|
case RS_PKT_SUBTYPE_NXS_TRANS:
|
||||||
|
return deserialNxsTrans(data, size);
|
||||||
case RS_PKT_SUBTYPE_NXS_EXTENDED:
|
case RS_PKT_SUBTYPE_NXS_EXTENDED:
|
||||||
return deserialNxsExtended(data, size);
|
return deserialNxsExtended(data, size);
|
||||||
default:
|
default:
|
||||||
|
@ -102,11 +108,16 @@ bool RsNxsSerialiser::serialise(RsItem *item, void *data, uint32_t *size){
|
||||||
RsSyncGrpMsg* sgm;
|
RsSyncGrpMsg* sgm;
|
||||||
RsSyncGrpMsgList* sgml;
|
RsSyncGrpMsgList* sgml;
|
||||||
RsNxsExtended* nxt;
|
RsNxsExtended* nxt;
|
||||||
|
RsNxsTransac* ntx;
|
||||||
|
|
||||||
if((sg = dynamic_cast<RsSyncGrp*>(item)) != NULL)
|
if((sg = dynamic_cast<RsSyncGrp*>(item)) != NULL)
|
||||||
{
|
{
|
||||||
return serialiseSyncGrp(sg, data, size);
|
return serialiseSyncGrp(sg, data, size);
|
||||||
|
|
||||||
|
}else if ((ntx = dynamic_cast<RsNxsTransac*>(item)) != NULL)
|
||||||
|
{
|
||||||
|
return serialiseNxsTrans(ntx, data, size);
|
||||||
|
|
||||||
}else if ((sgl = dynamic_cast<RsSyncGrpList*>(item)) != NULL)
|
}else if ((sgl = dynamic_cast<RsSyncGrpList*>(item)) != NULL)
|
||||||
{
|
{
|
||||||
return serialiseSyncGrpList(sgl, data, size);
|
return serialiseSyncGrpList(sgl, data, size);
|
||||||
|
@ -157,7 +168,7 @@ bool RsNxsSerialiser::serialiseSynGrpMsgList(RsSyncGrpMsgList *item, void *data,
|
||||||
|
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
|
|
||||||
ok = setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||||
|
|
||||||
/* skip the header */
|
/* skip the header */
|
||||||
offset += 8;
|
offset += 8;
|
||||||
|
@ -208,7 +219,7 @@ bool RsNxsSerialiser::serialiseNxsMsg(RsNxsMsg *item, void *data, uint32_t *size
|
||||||
|
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
|
|
||||||
ok = setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||||
|
|
||||||
/* skip the header */
|
/* skip the header */
|
||||||
offset += 8;
|
offset += 8;
|
||||||
|
@ -262,7 +273,7 @@ bool RsNxsSerialiser::serialiseNxsGrp(RsNxsGrp *item, void *data, uint32_t *size
|
||||||
|
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
|
|
||||||
ok = setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||||
|
|
||||||
/* skip the header */
|
/* skip the header */
|
||||||
offset += 8;
|
offset += 8;
|
||||||
|
@ -316,7 +327,7 @@ bool RsNxsSerialiser::serialiseSyncGrp(RsSyncGrp *item, void *data, uint32_t *si
|
||||||
|
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
|
|
||||||
ok = setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||||
|
|
||||||
/* skip the header */
|
/* skip the header */
|
||||||
offset += 8;
|
offset += 8;
|
||||||
|
@ -343,6 +354,55 @@ bool RsNxsSerialiser::serialiseSyncGrp(RsSyncGrp *item, void *data, uint32_t *si
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool RsNxsSerialiser::serialiseNxsTrans(RsNxsTransac *item, void *data, uint32_t *size){
|
||||||
|
|
||||||
|
#ifdef RSSERIAL_DEBUG
|
||||||
|
std::cerr << "RsNxsSerialiser::serialiseNxsTrans()" << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uint32_t tlvsize = sizeNxsTrans(item);
|
||||||
|
uint32_t offset = 0;
|
||||||
|
|
||||||
|
if(*size < tlvsize){
|
||||||
|
#ifdef RSSERIAL_DEBUG
|
||||||
|
std::cerr << "RsNxsSerialiser::serialiseNxsTrans() size do not match" << std::endl;
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
*size = tlvsize;
|
||||||
|
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||||
|
|
||||||
|
/* skip the header */
|
||||||
|
offset += 8;
|
||||||
|
|
||||||
|
ok &= setRawUInt16(data, *size, &offset, item->transactFlag);
|
||||||
|
ok &= setRawUInt32(data, *size, &offset, item->nItems);
|
||||||
|
ok &= setRawUInt32(data, *size, &offset, item->timeout);
|
||||||
|
ok &= setRawUInt32(data, *size, &offset, item->transactionId);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(offset != tlvsize){
|
||||||
|
#ifdef RSSERIAL_DEBUG
|
||||||
|
std::cerr << "RsNxsSerialiser::serialiseNxsTrans() FAIL Size Error! " << std::endl;
|
||||||
|
#endif
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef RSSERIAL_DEBUG
|
||||||
|
if (!ok)
|
||||||
|
{
|
||||||
|
std::cerr << "RsNxsSerialiser::serialiseNxsTrans() NOK" << std::endl;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
bool RsNxsSerialiser::serialiseSyncGrpList(RsSyncGrpList *item, void *data, uint32_t *size)
|
bool RsNxsSerialiser::serialiseSyncGrpList(RsSyncGrpList *item, void *data, uint32_t *size)
|
||||||
{
|
{
|
||||||
#ifdef RSSERIAL_DEBUG
|
#ifdef RSSERIAL_DEBUG
|
||||||
|
@ -363,7 +423,7 @@ bool RsNxsSerialiser::serialiseSyncGrpList(RsSyncGrpList *item, void *data, uint
|
||||||
|
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
|
|
||||||
ok = setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||||
|
|
||||||
/* skip the header */
|
/* skip the header */
|
||||||
offset += 8;
|
offset += 8;
|
||||||
|
@ -411,7 +471,7 @@ bool RsNxsSerialiser::serialiseSyncGrpMsg(RsSyncGrpMsg *item, void *data, uint32
|
||||||
|
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
|
|
||||||
ok = setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||||
|
|
||||||
/* skip the header */
|
/* skip the header */
|
||||||
offset += 8;
|
offset += 8;
|
||||||
|
@ -438,11 +498,6 @@ bool RsNxsSerialiser::serialiseSyncGrpMsg(RsSyncGrpMsg *item, void *data, uint32
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: need to finalise search term members
|
|
||||||
bool RsNxsSerialiser::serialiseNxsSearchReq(RsNxsSearchReq *item, void *data, uint32_t *size){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool RsNxsSerialiser::serialiseNxsExtended(RsNxsExtended *item, void *data, uint32_t *size){
|
bool RsNxsSerialiser::serialiseNxsExtended(RsNxsExtended *item, void *data, uint32_t *size){
|
||||||
|
|
||||||
|
@ -726,6 +781,74 @@ RsSyncGrpList* RsNxsSerialiser::deserialSyncGrpList(void *data, uint32_t *size){
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RsNxsTransac* RsNxsSerialiser::deserialNxsTrans(void *data, uint32_t *size){
|
||||||
|
|
||||||
|
#ifdef RSSERIAL_DEBUG
|
||||||
|
std::cerr << "RsNxsSerialiser::deserialNxsTrans()" << std::endl;
|
||||||
|
#endif
|
||||||
|
/* get the type and size */
|
||||||
|
uint32_t rstype = getRsItemId(data);
|
||||||
|
uint32_t rssize = getRsItemSize(data);
|
||||||
|
|
||||||
|
uint32_t offset = 0;
|
||||||
|
|
||||||
|
|
||||||
|
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||||
|
(SERVICE_TYPE != getRsItemService(rstype)) ||
|
||||||
|
(RS_PKT_SUBTYPE_NXS_TRANS != getRsItemSubType(rstype)))
|
||||||
|
{
|
||||||
|
#ifdef RSSERIAL_DEBUG
|
||||||
|
std::cerr << "RsNxsSerialiser::deserialNxsTrans() FAIL wrong type" << std::endl;
|
||||||
|
#endif
|
||||||
|
return NULL; /* wrong type */
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*size < rssize) /* check size */
|
||||||
|
{
|
||||||
|
#ifdef RSSERIAL_DEBUG
|
||||||
|
std::cerr << "RsNxsSerialiser::deserialSyncGrpMsgList( FAIL wrong size" << std::endl;
|
||||||
|
#endif
|
||||||
|
return NULL; /* not enough data */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set the packet length */
|
||||||
|
*size = rssize;
|
||||||
|
|
||||||
|
/* skip the header */
|
||||||
|
offset += 8;
|
||||||
|
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
RsNxsTransac* item = new RsNxsTransac(SERVICE_TYPE);
|
||||||
|
|
||||||
|
ok &= getRawUInt16(data, *size, &offset, &(item->transactFlag));
|
||||||
|
ok &= getRawUInt32(data, *size, &offset, &(item->nItems));
|
||||||
|
ok &= getRawUInt32(data, *size, &offset, &(item->timeout));
|
||||||
|
ok &= getRawUInt32(data, *size, &offset, &(item->transactionId));
|
||||||
|
|
||||||
|
if (offset != rssize)
|
||||||
|
{
|
||||||
|
#ifdef RSSERIAL_DEBUG
|
||||||
|
std::cerr << "RsNxsSerialiser::deserialNxsTrans() FAIL size mismatch" << std::endl;
|
||||||
|
#endif
|
||||||
|
/* error */
|
||||||
|
delete item;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ok)
|
||||||
|
{
|
||||||
|
#ifdef RSSERIAL_DEBUG
|
||||||
|
std::cerr << "RsNxsSerialiser::deserialNxsTrans() NOK" << std::endl;
|
||||||
|
#endif
|
||||||
|
delete item;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return item;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
RsSyncGrpMsgList* RsNxsSerialiser::deserialSyncGrpMsgList(void *data, uint32_t *size){
|
RsSyncGrpMsgList* RsNxsSerialiser::deserialSyncGrpMsgList(void *data, uint32_t *size){
|
||||||
|
|
||||||
|
@ -864,11 +987,6 @@ RsSyncGrpMsg* RsNxsSerialiser::deserialSyncGrpMsg(void *data, uint32_t *size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RsNxsSearchReq* RsNxsSerialiser::deserialNxsSearchReq(void *data, uint32_t *size)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
RsNxsExtended* RsNxsSerialiser::deserialNxsExtended(void *data, uint32_t *size){
|
RsNxsExtended* RsNxsSerialiser::deserialNxsExtended(void *data, uint32_t *size){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -963,8 +1081,15 @@ uint32_t RsNxsSerialiser::sizeSyncGrpMsgList(RsSyncGrpMsgList *item)
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t RsNxsSerialiser::sizeNxsSearchReq(RsNxsSearchReq *item){
|
uint32_t RsNxsSerialiser::sizeNxsTrans(RsNxsTransac *item){
|
||||||
return 0;
|
|
||||||
|
uint32_t s = 8; // header size
|
||||||
|
s += 2; // flag
|
||||||
|
s += 4; // nMsgs
|
||||||
|
s += 4; // timeout
|
||||||
|
s += 4; // transaction id
|
||||||
|
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t RsNxsSerialiser::sizeNxsExtended(RsNxsExtended *item){
|
uint32_t RsNxsSerialiser::sizeNxsExtended(RsNxsExtended *item){
|
||||||
|
@ -1029,6 +1154,13 @@ void RsSyncGrpMsgList::clear()
|
||||||
grpId.clear();
|
grpId.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RsNxsTransac::clear(){
|
||||||
|
transactFlag = 0;
|
||||||
|
nItems = 0;
|
||||||
|
timeout = 0;
|
||||||
|
transactionId = 0;
|
||||||
|
}
|
||||||
|
|
||||||
std::ostream& RsSyncGrp::print(std::ostream &out, uint16_t indent)
|
std::ostream& RsSyncGrp::print(std::ostream &out, uint16_t indent)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -1164,3 +1296,22 @@ std::ostream& RsNxsMsg::print(std::ostream &out, uint16_t indent){
|
||||||
printRsItemEnd(out ,"RsNxsMsg", indent);
|
printRsItemEnd(out ,"RsNxsMsg", indent);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::ostream& RsNxsTransac::print(std::ostream &out, uint16_t indent){
|
||||||
|
|
||||||
|
printRsItemBase(out, "RsNxsTransac", indent);
|
||||||
|
uint16_t int_Indent = indent + 2;
|
||||||
|
|
||||||
|
out << "transactFlag: " << transactFlag << std::endl;
|
||||||
|
printIndent(out , int_Indent);
|
||||||
|
out << "nItems: " << nItems << std::endl;
|
||||||
|
printIndent(out , int_Indent);
|
||||||
|
out << "timeout: " << timeout << std::endl;
|
||||||
|
printIndent(out , int_Indent);
|
||||||
|
out << "transactionId: " << transactionId << std::endl;
|
||||||
|
printIndent(out , int_Indent);
|
||||||
|
|
||||||
|
printRsItemEnd(out ,"RsNxsTransac", indent);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
|
@ -42,7 +42,8 @@ const uint8_t RS_PKT_SUBTYPE_NXS_GRP = 0x0004;
|
||||||
const uint8_t RS_PKT_SUBTYPE_SYNC_MSG = 0x0008;
|
const uint8_t RS_PKT_SUBTYPE_SYNC_MSG = 0x0008;
|
||||||
const uint8_t RS_PKT_SUBTYPE_SYNC_MSG_LIST = 0x0010;
|
const uint8_t RS_PKT_SUBTYPE_SYNC_MSG_LIST = 0x0010;
|
||||||
const uint8_t RS_PKT_SUBTYPE_NXS_MSG = 0x0020;
|
const uint8_t RS_PKT_SUBTYPE_NXS_MSG = 0x0020;
|
||||||
const uint8_t RS_PKT_SUBTYPE_SEARCH_REQ = 0x0040;
|
const uint8_t RS_PKT_SUBTYPE_NXS_TRANS = 0x0040;
|
||||||
|
|
||||||
|
|
||||||
// possibility create second service to deal with this functionality
|
// possibility create second service to deal with this functionality
|
||||||
|
|
||||||
|
@ -51,6 +52,7 @@ const uint8_t RS_PKT_SUBTYPE_EXT_SEARCH_GRP = 0x0001;
|
||||||
const uint8_t RS_PKT_SUBTYPE_EXT_SEARCH_MSG = 0x0002;
|
const uint8_t RS_PKT_SUBTYPE_EXT_SEARCH_MSG = 0x0002;
|
||||||
const uint8_t RS_PKT_SUBTYPE_EXT_DELETE_GRP = 0x0004;
|
const uint8_t RS_PKT_SUBTYPE_EXT_DELETE_GRP = 0x0004;
|
||||||
const uint8_t RS_PKT_SUBTYPE_EXT_DELETE_MSG = 0x0008;
|
const uint8_t RS_PKT_SUBTYPE_EXT_DELETE_MSG = 0x0008;
|
||||||
|
const uint8_t RS_PKT_SUBTYPE_EXT_SEARCH_REQ = 0x0010;
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -105,7 +107,6 @@ public:
|
||||||
*/
|
*/
|
||||||
class RsNxsTransac : public RsNxsItem {
|
class RsNxsTransac : public RsNxsItem {
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/** transaction **/
|
/** transaction **/
|
||||||
|
@ -114,15 +115,29 @@ public:
|
||||||
static const uint16_t FLAG_END_P1;
|
static const uint16_t FLAG_END_P1;
|
||||||
static const uint16_t FLAG_END_P2;
|
static const uint16_t FLAG_END_P2;
|
||||||
static const uint16_t FLAG_CANCEL;
|
static const uint16_t FLAG_CANCEL;
|
||||||
|
static const uint16_t FLAG_FAIL_NUM;
|
||||||
|
static const uint16_t FLAG_FAIL_TIMEOUT;
|
||||||
|
static const uint16_t FLAG_FAIL_FULL;
|
||||||
|
|
||||||
|
|
||||||
/** transaction type **/
|
/** transaction type **/
|
||||||
static const uint16_t FLAG_TYPE_GRP_LIST_RESP;
|
static const uint16_t FLAG_TYPE_GRP_LIST_RESP;
|
||||||
static const uint16_t FLAG_TYPE_MSG_LIST_RESP;
|
static const uint16_t FLAG_TYPE_MSG_LIST_RESP;
|
||||||
static const uint16_t FLAG_TYPE_GRP_LIST_REQ;
|
static const uint16_t FLAG_TYPE_GRP_LIST_REQ;
|
||||||
static const uint16_t FLAG_TYPE_
|
static const uint16_t FLAG_TYPE_MSG_LIST_REQ;
|
||||||
|
static const uint16_t FLAG_TYPE_GRPS;
|
||||||
|
static const uint16_t FLAG_TYPE_MSGS;
|
||||||
|
|
||||||
|
RsNxsTransac(uint16_t servtype) : RsNxsItem(servtype, RS_PKT_SUBTYPE_NXS_TRANS) { return; }
|
||||||
|
virtual ~RsNxsTransac() { return ; }
|
||||||
|
|
||||||
|
virtual void clear();
|
||||||
|
virtual std::ostream &print(std::ostream &out, uint16_t indent);
|
||||||
|
|
||||||
|
uint16_t transactFlag;
|
||||||
|
uint32_t nItems;
|
||||||
|
uint32_t timeout;
|
||||||
|
uint32_t transactionId;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -261,7 +276,7 @@ class RsNxsSearchReq : public RsNxsItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RsNxsSearchReq(uint16_t servtype): RsNxsItem(servtype, RS_PKT_SUBTYPE_SEARCH_REQ), serviceSearchItem(servtype) { return; }
|
RsNxsSearchReq(uint16_t servtype): RsNxsItem(servtype, RS_PKT_SUBTYPE_EXT_SEARCH_REQ), serviceSearchItem(servtype) { return; }
|
||||||
virtual ~RsNxsSearchReq() { return;}
|
virtual ~RsNxsSearchReq() { return;}
|
||||||
|
|
||||||
virtual void clear() { return;}
|
virtual void clear() { return;}
|
||||||
|
@ -415,10 +430,10 @@ private:
|
||||||
virtual bool serialiseNxsMsg(RsNxsMsg* item, void* data, uint32_t* size);
|
virtual bool serialiseNxsMsg(RsNxsMsg* item, void* data, uint32_t* size);
|
||||||
virtual RsNxsMsg* deserialNxsMsg(void *data, uint32_t *size);
|
virtual RsNxsMsg* deserialNxsMsg(void *data, uint32_t *size);
|
||||||
|
|
||||||
/* RS_PKT_SUBTYPE_SEARCH_REQ */
|
/* RS_PKT_SUBTYPE_NXS_TRANS */
|
||||||
virtual uint32_t sizeNxsSearchReq(RsNxsSearchReq* item);
|
virtual uint32_t sizeNxsTrans(RsNxsTransac* item);
|
||||||
virtual bool serialiseNxsSearchReq(RsNxsSearchReq* item, void* data, uint32_t* size);
|
virtual bool serialiseNxsTrans(RsNxsTransac* item, void* data, uint32_t* size);
|
||||||
virtual RsNxsSearchReq* deserialNxsSearchReq(void* data, uint32_t *size);
|
virtual RsNxsTransac* deserialNxsTrans(void* data, uint32_t *size);
|
||||||
|
|
||||||
/* RS_PKT_SUBTYPE_EXTENDED */
|
/* RS_PKT_SUBTYPE_EXTENDED */
|
||||||
virtual RsNxsExtended* deserialNxsExtended(void* data, uint32_t *size);
|
virtual RsNxsExtended* deserialNxsExtended(void* data, uint32_t *size);
|
||||||
|
|
|
@ -76,6 +76,12 @@ RsTlvBinaryData::RsTlvBinaryData(uint16_t t)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RsTlvBinaryData::RsTlvBinaryData(const RsTlvBinaryData &b)
|
||||||
|
: tlvtype(b.tlvtype), bin_data(NULL), bin_len(0) {
|
||||||
|
|
||||||
|
setBinData(b.bin_data, b.bin_len);
|
||||||
|
}
|
||||||
|
|
||||||
RsTlvBinaryData::~RsTlvBinaryData()
|
RsTlvBinaryData::~RsTlvBinaryData()
|
||||||
{
|
{
|
||||||
TlvClear();
|
TlvClear();
|
||||||
|
|
|
@ -65,8 +65,9 @@ class RsTlvBinaryData: public RsTlvItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsTlvBinaryData(uint16_t t);
|
RsTlvBinaryData(uint16_t t);
|
||||||
void operator=(const RsTlvBinaryData& b);
|
RsTlvBinaryData(const RsTlvBinaryData& b); // as per rule of three
|
||||||
virtual ~RsTlvBinaryData();
|
void operator=(const RsTlvBinaryData& b); // as per rule of three
|
||||||
|
virtual ~RsTlvBinaryData(); // as per rule of three
|
||||||
virtual uint32_t TlvSize();
|
virtual uint32_t TlvSize();
|
||||||
virtual void TlvClear(); /*! Initialize fields to empty legal values ( "0", "", etc) */
|
virtual void TlvClear(); /*! Initialize fields to empty legal values ( "0", "", etc) */
|
||||||
virtual void TlvShallowClear(); /*! Don't delete the binary data */
|
virtual void TlvShallowClear(); /*! Don't delete the binary data */
|
||||||
|
|
81
libretroshare/src/tests/gxs/data_support.cc
Normal file
81
libretroshare/src/tests/gxs/data_support.cc
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
#include "support.h"
|
||||||
|
#include "data_support.h"
|
||||||
|
|
||||||
|
|
||||||
|
bool operator==(const RsNxsGrp& l, const RsNxsGrp& r){
|
||||||
|
|
||||||
|
if(!(l.adminSign == r.adminSign)) return false;
|
||||||
|
if(!(l.idSign == r.idSign)) return false;
|
||||||
|
if(l.timeStamp != r.timeStamp) return false;
|
||||||
|
if(l.grpFlag != r.grpFlag) return false;
|
||||||
|
if(l.identity != r.identity) return false;
|
||||||
|
if(l.grpId != r.grpId) return false;
|
||||||
|
if(l.keys.groupId != r.keys.groupId) return false;
|
||||||
|
if(!(l.grp == r.grp) ) return false;
|
||||||
|
|
||||||
|
std::map<std::string, RsTlvSecurityKey>::const_iterator mit =
|
||||||
|
l.keys.keys.begin(), mit_end = l.keys.keys.end();
|
||||||
|
|
||||||
|
for(; mit != mit_end; mit++){
|
||||||
|
const RsTlvSecurityKey& lk = l.keys.keys.find(mit->first)->second;
|
||||||
|
const RsTlvSecurityKey& rk = r.keys.keys.find(mit->first)->second;
|
||||||
|
|
||||||
|
if(! ( lk == rk) ) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const RsNxsMsg& l, const RsNxsMsg& r){
|
||||||
|
|
||||||
|
if(l.msgId != r.msgId) return false;
|
||||||
|
if(l.grpId != r.grpId) return false;
|
||||||
|
if(l.identity != r.identity) return false;
|
||||||
|
if(l.timeStamp != r.timeStamp) return false;
|
||||||
|
if(l.msgFlag != r.msgFlag) return false;
|
||||||
|
if(! (l.msg == r.msg) ) return false;
|
||||||
|
if(! (l.publishSign == r.publishSign) ) return false;
|
||||||
|
if(! (l.idSign == r.idSign) ) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void init_item(RsNxsGrp* nxg)
|
||||||
|
{
|
||||||
|
|
||||||
|
randString(SHORT_STR, nxg->identity);
|
||||||
|
randString(SHORT_STR, nxg->grpId);
|
||||||
|
nxg->timeStamp = rand()%23;
|
||||||
|
nxg->grpFlag = rand()%242;
|
||||||
|
init_item(nxg->grp);
|
||||||
|
|
||||||
|
init_item(nxg->adminSign);
|
||||||
|
init_item(nxg->idSign);
|
||||||
|
|
||||||
|
int nKey = rand()%12;
|
||||||
|
nxg->keys.groupId = nxg->grpId;
|
||||||
|
for(int i=0; i < nKey; i++){
|
||||||
|
RsTlvSecurityKey k;
|
||||||
|
init_item(k);
|
||||||
|
nxg->keys.keys[k.keyId] = k;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void init_item(RsNxsMsg* nxm)
|
||||||
|
{
|
||||||
|
randString(SHORT_STR, nxm->msgId);
|
||||||
|
randString(SHORT_STR, nxm->grpId);
|
||||||
|
randString(SHORT_STR, nxm->identity);
|
||||||
|
|
||||||
|
init_item(nxm->publishSign);
|
||||||
|
init_item(nxm->idSign);
|
||||||
|
init_item(nxm->msg);
|
||||||
|
nxm->msgFlag = rand()%4252;
|
||||||
|
nxm->timeStamp = rand()%246;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
12
libretroshare/src/tests/gxs/data_support.h
Normal file
12
libretroshare/src/tests/gxs/data_support.h
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#ifndef DATA_SUPPORT_H
|
||||||
|
#define DATA_SUPPORT_H
|
||||||
|
|
||||||
|
#include "serialiser/rsnxsitems.h"
|
||||||
|
|
||||||
|
bool operator==(const RsNxsGrp&, const RsNxsGrp&);
|
||||||
|
bool operator==(const RsNxsMsg&, const RsNxsMsg&);
|
||||||
|
|
||||||
|
void init_item(RsNxsGrp* nxg);
|
||||||
|
void init_item(RsNxsMsg* nxm);
|
||||||
|
|
||||||
|
#endif // DATA_SUPPORT_H
|
|
@ -1,19 +1,29 @@
|
||||||
|
|
||||||
#include "support.h"
|
#include "support.h"
|
||||||
|
#include "data_support.h"
|
||||||
#include "rsdataservice_test.h"
|
#include "rsdataservice_test.h"
|
||||||
#include "gxs/rsdataservice.h"
|
#include "gxs/rsdataservice.h"
|
||||||
|
|
||||||
|
#define DATA_BASE_NAME "msg_grp_Store"
|
||||||
|
|
||||||
INITTEST();
|
INITTEST();
|
||||||
|
RsGeneralDataService* dStore = NULL;
|
||||||
|
|
||||||
|
void setUp();
|
||||||
|
void tearDown();
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
||||||
std::cerr << "RsDataService Tests" << std::endl;
|
std::cerr << "RsDataService Tests" << std::endl;
|
||||||
|
|
||||||
|
test_groupStoreAndRetrieve(); REPORT("test_groupStoreAndRetrieve");
|
||||||
|
|
||||||
|
test_messageStoresAndRetrieve(); REPORT("test_messageStoresAndRetrieve");
|
||||||
|
|
||||||
|
test_messageVersionRetrieve(); REPORT("test_messageVersionRetrieve");
|
||||||
|
|
||||||
|
test_groupVersionRetrieve(); REPORT("test_groupVersionRetrieve");
|
||||||
|
|
||||||
FINALREPORT("RsDataService Tests");
|
FINALREPORT("RsDataService Tests");
|
||||||
|
|
||||||
|
@ -24,9 +34,210 @@ int main()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool test_groupStoreAndRetrieve(){
|
void test_groupStoreAndRetrieve(){
|
||||||
|
|
||||||
|
setUp();
|
||||||
|
|
||||||
|
int nGrp = rand()%32;
|
||||||
|
std::set<RsNxsGrp*> s;
|
||||||
RsNxsGrp* grp;
|
RsNxsGrp* grp;
|
||||||
|
for(int i = 0; i < nGrp; i++){
|
||||||
|
grp = new RsNxsGrp(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
|
init_item(grp);
|
||||||
|
s.insert(grp);
|
||||||
|
}
|
||||||
|
|
||||||
|
dStore->storeGroup(s);
|
||||||
|
|
||||||
|
std::map<std::string, RsNxsGrp*> gm;
|
||||||
|
dStore->retrieveGrps(gm, false);
|
||||||
|
|
||||||
|
// now match grps together
|
||||||
|
|
||||||
|
// simple check,are they the same size
|
||||||
|
CHECK(gm.size() == s.size());
|
||||||
|
|
||||||
|
std::set<RsNxsGrp*>::iterator sit = s.begin();
|
||||||
|
std::map<std::string, RsNxsGrp*>::iterator mit;
|
||||||
|
bool matched = true;
|
||||||
|
|
||||||
|
for(; sit != s.end(); sit++){
|
||||||
|
RsNxsGrp* g1 = *sit;
|
||||||
|
mit = gm.find(g1->grpId);
|
||||||
|
|
||||||
|
if(mit == gm.end()){
|
||||||
|
matched = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
RsNxsGrp* g2 = gm[g1->grpId];
|
||||||
|
|
||||||
|
if(! (*g1 == *g2) )
|
||||||
|
matched = false;
|
||||||
|
|
||||||
|
|
||||||
|
// remove grp file
|
||||||
|
if(g1)
|
||||||
|
remove(g1->grpId.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK(matched);
|
||||||
|
|
||||||
|
tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void test_messageStoresAndRetrieve(){
|
||||||
|
|
||||||
|
setUp();
|
||||||
|
|
||||||
|
int nMsgs = rand()%32;
|
||||||
|
std::set<RsNxsMsg*> s;
|
||||||
|
RsNxsMsg* msg;
|
||||||
|
std::string grpId;
|
||||||
|
randString(SHORT_STR, grpId);
|
||||||
|
for(int i = 0; i < nMsgs; i++){
|
||||||
|
msg = new RsNxsMsg(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
|
init_item(msg);
|
||||||
|
msg->grpId = grpId;
|
||||||
|
s.insert(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
dStore->storeMessage(s);
|
||||||
|
|
||||||
|
std::map<std::string, RsNxsMsg*> msgs;
|
||||||
|
dStore->retrieveMsgs(grpId, msgs, false);
|
||||||
|
|
||||||
|
CHECK(msgs.size() == s.size());
|
||||||
|
|
||||||
|
std::set<RsNxsMsg*>::iterator sit = s.begin();
|
||||||
|
std::map<std::string, RsNxsMsg*>::iterator mit;
|
||||||
|
bool matched = true;
|
||||||
|
|
||||||
|
for(; sit != s.end(); sit++){
|
||||||
|
RsNxsMsg* m1 = *sit;
|
||||||
|
mit = msgs.find(m1->msgId);
|
||||||
|
|
||||||
|
if(mit == msgs.end()){
|
||||||
|
matched = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
RsNxsMsg* m2 = msgs[m1->msgId];
|
||||||
|
|
||||||
|
if(! (*m1 == *m2) )
|
||||||
|
matched = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK(matched);
|
||||||
|
|
||||||
|
std::string msgFile = grpId + "-msgs";
|
||||||
|
remove(msgFile.c_str());
|
||||||
|
|
||||||
|
tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_messageVersionRetrieve(){
|
||||||
|
|
||||||
|
setUp();
|
||||||
|
|
||||||
|
// place two messages in store and attempt to retrieve them
|
||||||
|
std::set<RsNxsMsg*> s;
|
||||||
|
RsNxsMsg* msg1 = new RsNxsMsg(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);;
|
||||||
|
RsNxsMsg* msg2 = new RsNxsMsg(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);;
|
||||||
|
RsNxsMsg* msg3 = new RsNxsMsg(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);;
|
||||||
|
std::string grpId;
|
||||||
|
randString(SHORT_STR, grpId);
|
||||||
|
msg1->grpId = grpId;
|
||||||
|
msg2->grpId = grpId;
|
||||||
|
msg3->grpId = grpId;
|
||||||
|
init_item(msg1);
|
||||||
|
init_item(msg2);
|
||||||
|
init_item(msg3);
|
||||||
|
s.insert(msg1); s.insert(msg2); s.insert(msg3);
|
||||||
|
|
||||||
|
dStore->storeMessage(s);
|
||||||
|
|
||||||
|
RsGxsMsgId msgId;
|
||||||
|
msgId.grpId = msg2->grpId;
|
||||||
|
msgId.idSign = msg2->idSign;
|
||||||
|
msgId.msgId = msg2->msgId;
|
||||||
|
RsNxsMsg* msg2_r = dStore->retrieveMsgVersion(msgId);
|
||||||
|
|
||||||
|
CHECK(msg2_r != NULL);
|
||||||
|
|
||||||
|
if(msg2_r)
|
||||||
|
CHECK(*msg2 == *msg2_r);
|
||||||
|
|
||||||
|
delete msg1;
|
||||||
|
delete msg2;
|
||||||
|
delete msg3;
|
||||||
|
delete msg2_r;
|
||||||
|
|
||||||
|
std::string msgFile = grpId + "-msgs";
|
||||||
|
remove(msgFile.c_str());
|
||||||
|
|
||||||
|
tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_groupVersionRetrieve(){
|
||||||
|
|
||||||
|
setUp();
|
||||||
|
|
||||||
|
std::set<RsNxsGrp*> grps;
|
||||||
|
RsNxsGrp* group1 = new RsNxsGrp(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
|
RsNxsGrp* group2 = new RsNxsGrp(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);;
|
||||||
|
RsNxsGrp* group3 = new RsNxsGrp(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);;
|
||||||
|
RsNxsGrp* group2_r = NULL;
|
||||||
|
|
||||||
|
init_item(group1);
|
||||||
|
init_item(group2);
|
||||||
|
init_item(group3);
|
||||||
|
|
||||||
|
grps.insert(group1); grps.insert(group2); grps.insert(group3);
|
||||||
|
|
||||||
|
RsGxsGrpId grpId;
|
||||||
|
grpId.grpId = group2->grpId;
|
||||||
|
grpId.adminSign = group2->adminSign;
|
||||||
|
|
||||||
|
dStore->storeGroup(grps);
|
||||||
|
group2_r = dStore->retrieveGrpVersion(grpId);
|
||||||
|
|
||||||
|
|
||||||
|
CHECK(group2_r != NULL);
|
||||||
|
|
||||||
|
if(group2_r)
|
||||||
|
CHECK(*group2 == *group2_r);
|
||||||
|
|
||||||
|
|
||||||
|
delete group1;
|
||||||
|
delete group2;
|
||||||
|
delete group3;
|
||||||
|
delete group2_r;
|
||||||
|
|
||||||
|
tearDown();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void setUp(){
|
||||||
|
dStore = new RsDataService(".", DATA_BASE_NAME, RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tearDown(){
|
||||||
|
|
||||||
|
dStore->resetDataStore(); // reset to clean up store files except db
|
||||||
|
delete dStore;
|
||||||
|
dStore = NULL;
|
||||||
|
int rc = remove(DATA_BASE_NAME);
|
||||||
|
|
||||||
|
if(rc == 0){
|
||||||
|
std::cerr << "Successful tear down" << std::endl;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
std::cerr << "Tear down failed" << std::endl;
|
||||||
|
perror("Error: ");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,20 +2,22 @@
|
||||||
#define RSDATASERVICE_TEST_H
|
#define RSDATASERVICE_TEST_H
|
||||||
|
|
||||||
#include "util/rsthreads.h"
|
#include "util/rsthreads.h"
|
||||||
|
#include "serialiser/rsnxsitems.h"
|
||||||
|
#include "gxs/rsgds.h"
|
||||||
|
|
||||||
bool test_messageStoresAndRetrieve();
|
void test_messageStoresAndRetrieve();
|
||||||
bool test_messageVersionRetrieve();
|
void test_messageVersionRetrieve();
|
||||||
|
|
||||||
bool test_groupStoreAndRetrieve();
|
void test_groupStoreAndRetrieve();
|
||||||
bool test_groupVersionRetrieve();
|
void test_groupVersionRetrieve();
|
||||||
|
|
||||||
bool test_storeAndDeleteGroup();
|
void test_storeAndDeleteGroup();
|
||||||
bool test_storeAndDeleteMessage();
|
void test_storeAndDeleteMessage();
|
||||||
|
|
||||||
bool test_searchMsg();
|
void test_searchMsg();
|
||||||
bool test_searchGrp();
|
void test_searchGrp();
|
||||||
|
|
||||||
bool test_multiThreaded();
|
void test_multiThreaded();
|
||||||
|
|
||||||
class DataReadWrite : RsThread
|
class DataReadWrite : RsThread
|
||||||
{
|
{
|
||||||
|
@ -24,6 +26,9 @@ class DataReadWrite : RsThread
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
bool test_cacheSize();
|
void test_cacheSize();
|
||||||
|
|
||||||
|
void init_item(RsNxsGrp*);
|
||||||
|
void init_item(RsNxsMsg*);
|
||||||
|
|
||||||
#endif // RSDATASERVICE_TEST_H
|
#endif // RSDATASERVICE_TEST_H
|
||||||
|
|
272
libretroshare/src/tests/gxs/support.cc
Normal file
272
libretroshare/src/tests/gxs/support.cc
Normal file
|
@ -0,0 +1,272 @@
|
||||||
|
/*
|
||||||
|
* libretroshare/src/serialiser: t_support.h.cc
|
||||||
|
*
|
||||||
|
* RetroShare Serialiser tests.
|
||||||
|
*
|
||||||
|
* Copyright 2007-2008 by Christopher Evi-Parker
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "support.h"
|
||||||
|
#include "serialiser/rstlvbase.h"
|
||||||
|
|
||||||
|
void randString(const uint32_t length, std::string& outStr)
|
||||||
|
{
|
||||||
|
char alpha = 'a';
|
||||||
|
char* stringData = NULL;
|
||||||
|
|
||||||
|
stringData = new char[length];
|
||||||
|
|
||||||
|
for(uint32_t i=0; i != length; i++)
|
||||||
|
stringData[i] = alpha + (rand() % 26);
|
||||||
|
|
||||||
|
outStr.assign(stringData, length);
|
||||||
|
delete[] stringData;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void randString(const uint32_t length, std::wstring& outStr)
|
||||||
|
{
|
||||||
|
wchar_t alpha = L'a';
|
||||||
|
wchar_t* stringData = NULL;
|
||||||
|
|
||||||
|
stringData = new wchar_t[length];
|
||||||
|
|
||||||
|
for(uint32_t i=0; i != length; i++)
|
||||||
|
stringData[i] = (alpha + (rand() % 26));
|
||||||
|
|
||||||
|
outStr.assign(stringData, length);
|
||||||
|
delete[] stringData;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const RsTlvSecurityKey& sk1, const RsTlvSecurityKey& sk2)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(sk1.startTS != sk2.startTS) return false;
|
||||||
|
if(sk1.endTS != sk2.endTS) return false;
|
||||||
|
if(sk1.keyFlags != sk2.keyFlags) return false;
|
||||||
|
if(sk1.keyId != sk2.keyId) return false;
|
||||||
|
if(!(sk1.keyData == sk1.keyData)) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const RsTlvKeySignature& ks1, const RsTlvKeySignature& ks2)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(ks1.keyId != ks2.keyId) return false;
|
||||||
|
if(!(ks1.signData == ks2.signData)) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const RsTlvPeerIdSet& pids1, const RsTlvPeerIdSet& pids2)
|
||||||
|
{
|
||||||
|
std::list<std::string>::const_iterator it1 = pids1.ids.begin(),
|
||||||
|
it2 = pids2.ids.begin();
|
||||||
|
|
||||||
|
|
||||||
|
for(; ((it1 != pids1.ids.end()) && (it2 != pids2.ids.end())); it1++, it2++)
|
||||||
|
{
|
||||||
|
if(*it1 != *it2) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void init_item(RsTlvImage& im)
|
||||||
|
{
|
||||||
|
std::string imageData;
|
||||||
|
randString(LARGE_STR, imageData);
|
||||||
|
im.binData.setBinData(imageData.c_str(), imageData.size());
|
||||||
|
im.image_type = RSTLV_IMAGE_TYPE_PNG;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const RsTlvBinaryData& bd1, const RsTlvBinaryData& bd2)
|
||||||
|
{
|
||||||
|
if(bd1.tlvtype != bd2.tlvtype) return false;
|
||||||
|
if(bd1.bin_len != bd2.bin_len) return false;
|
||||||
|
|
||||||
|
unsigned char *bin1 = (unsigned char*)(bd1.bin_data),
|
||||||
|
*bin2 = (unsigned char*)(bd2.bin_data);
|
||||||
|
|
||||||
|
for(uint32_t i=0; i < bd1.bin_len; bin1++, bin2++, i++)
|
||||||
|
{
|
||||||
|
if(*bin1 != *bin2)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void init_item(RsTlvSecurityKey& sk)
|
||||||
|
{
|
||||||
|
int randnum = rand()%313131;
|
||||||
|
|
||||||
|
sk.endTS = randnum;
|
||||||
|
sk.keyFlags = randnum;
|
||||||
|
sk.startTS = randnum;
|
||||||
|
randString(SHORT_STR, sk.keyId);
|
||||||
|
|
||||||
|
std::string randomStr;
|
||||||
|
randString(LARGE_STR, randomStr);
|
||||||
|
|
||||||
|
sk.keyData.setBinData(randomStr.c_str(), randomStr.size());
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_item(RsTlvKeySignature& ks)
|
||||||
|
{
|
||||||
|
randString(SHORT_STR, ks.keyId);
|
||||||
|
|
||||||
|
std::string signData;
|
||||||
|
randString(LARGE_STR, signData);
|
||||||
|
|
||||||
|
ks.signData.setBinData(signData.c_str(), signData.size());
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool operator==(const RsTlvImage& img1, const RsTlvImage& img2)
|
||||||
|
{
|
||||||
|
if(img1.image_type != img2.image_type) return false;
|
||||||
|
if(!(img1.binData == img2.binData)) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/** channels, forums and blogs **/
|
||||||
|
|
||||||
|
void init_item(RsTlvHashSet& hs)
|
||||||
|
{
|
||||||
|
std::string hash;
|
||||||
|
|
||||||
|
for(int i=0; i < 10; i++)
|
||||||
|
{
|
||||||
|
randString(SHORT_STR, hash);
|
||||||
|
hs.ids.push_back(hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
hs.mType = TLV_TYPE_HASHSET;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_item(RsTlvPeerIdSet& ps)
|
||||||
|
{
|
||||||
|
std::string peer;
|
||||||
|
|
||||||
|
for(int i=0; i < 10; i++)
|
||||||
|
{
|
||||||
|
randString(SHORT_STR, peer);
|
||||||
|
ps.ids.push_back(peer);
|
||||||
|
}
|
||||||
|
|
||||||
|
ps.mType = TLV_TYPE_PEERSET;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const RsTlvHashSet& hs1,const RsTlvHashSet& hs2)
|
||||||
|
{
|
||||||
|
if(hs1.mType != hs2.mType) return false;
|
||||||
|
|
||||||
|
std::list<std::string>::const_iterator it1 = hs1.ids.begin(),
|
||||||
|
it2 = hs2.ids.begin();
|
||||||
|
|
||||||
|
for(; ((it1 != hs1.ids.end()) && (it2 != hs2.ids.end())); it1++, it2++)
|
||||||
|
{
|
||||||
|
if(*it1 != *it2) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_item(RsTlvFileItem& fi)
|
||||||
|
{
|
||||||
|
fi.age = rand()%200;
|
||||||
|
fi.filesize = rand()%34030313;
|
||||||
|
randString(SHORT_STR, fi.hash);
|
||||||
|
randString(SHORT_STR, fi.name);
|
||||||
|
randString(SHORT_STR, fi.path);
|
||||||
|
fi.piecesize = rand()%232;
|
||||||
|
fi.pop = rand()%2354;
|
||||||
|
init_item(fi.hashset);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_item(RsTlvBinaryData& bd){
|
||||||
|
bd.TlvClear();
|
||||||
|
std::string data;
|
||||||
|
randString(LARGE_STR, data);
|
||||||
|
bd.setBinData(data.data(), data.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_item(RsTlvFileSet& fSet){
|
||||||
|
|
||||||
|
randString(LARGE_STR, fSet.comment);
|
||||||
|
randString(SHORT_STR, fSet.title);
|
||||||
|
RsTlvFileItem fi1, fi2;
|
||||||
|
init_item(fi1);
|
||||||
|
init_item(fi2);
|
||||||
|
fSet.items.push_back(fi1);
|
||||||
|
fSet.items.push_back(fi2);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const RsTlvFileSet& fs1,const RsTlvFileSet& fs2)
|
||||||
|
{
|
||||||
|
if(fs1.comment != fs2.comment) return false;
|
||||||
|
if(fs1.title != fs2.title) return false;
|
||||||
|
|
||||||
|
std::list<RsTlvFileItem>::const_iterator it1 = fs1.items.begin(),
|
||||||
|
it2 = fs2.items.begin();
|
||||||
|
|
||||||
|
for(; ((it1 != fs1.items.end()) && (it2 != fs2.items.end())); it1++, it2++)
|
||||||
|
if(!(*it1 == *it2)) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const RsTlvFileItem& fi1,const RsTlvFileItem& fi2)
|
||||||
|
{
|
||||||
|
if(fi1.age != fi2.age) return false;
|
||||||
|
if(fi1.filesize != fi2.filesize) return false;
|
||||||
|
if(fi1.hash != fi2.hash) return false;
|
||||||
|
if(!(fi1.hashset == fi2.hashset)) return false;
|
||||||
|
if(fi1.name != fi2.name) return false;
|
||||||
|
if(fi1.path != fi2.path) return false;
|
||||||
|
if(fi1.piecesize != fi2.piecesize) return false;
|
||||||
|
if(fi1.pop != fi2.pop) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
222
libretroshare/src/tests/gxs/support.h
Normal file
222
libretroshare/src/tests/gxs/support.h
Normal file
|
@ -0,0 +1,222 @@
|
||||||
|
#ifndef SUPPORT_H_
|
||||||
|
#define SUPPORT_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
* libretroshare/src/tests/serialiser:
|
||||||
|
*
|
||||||
|
* RetroShare Serialiser tests.
|
||||||
|
*
|
||||||
|
* Copyright 2007-2008 by Christopher Evi-Parker, Cyril Soler
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "util/utest.h"
|
||||||
|
#include "serialiser/rsserial.h"
|
||||||
|
#include "serialiser/rstlvutil.h"
|
||||||
|
#include "serialiser/rstlvkeys.h"
|
||||||
|
#include "serialiser/rstlvtypes.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This contains functions that may be useful for testing throughout the
|
||||||
|
* retroshare's serialiser
|
||||||
|
* package, if you find a function you keep using everywhere, might be a good idea to add it here
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#define SHORT_STR 100
|
||||||
|
#define LARGE_STR 1000
|
||||||
|
|
||||||
|
void randString(const uint32_t, std::string&);
|
||||||
|
void randString(const uint32_t, std::wstring&);
|
||||||
|
|
||||||
|
|
||||||
|
/* for testing compound tlv items */
|
||||||
|
|
||||||
|
void init_item(RsTlvSecurityKey&);
|
||||||
|
void init_item(RsTlvKeySignature&);
|
||||||
|
void init_item(RsTlvBinaryData&);
|
||||||
|
void init_item(RsTlvFileItem&);
|
||||||
|
void init_item(RsTlvFileSet&);
|
||||||
|
void init_item(RsTlvHashSet&);
|
||||||
|
void init_item(RsTlvPeerIdSet&);
|
||||||
|
void init_item(RsTlvImage&);
|
||||||
|
void init_item(RsTlvPeerIdSet&);
|
||||||
|
|
||||||
|
bool operator==(const RsTlvSecurityKey&, const RsTlvSecurityKey& );
|
||||||
|
bool operator==(const RsTlvKeySignature&, const RsTlvKeySignature& );
|
||||||
|
bool operator==(const RsTlvBinaryData&, const RsTlvBinaryData&);
|
||||||
|
bool operator==(const RsTlvFileItem&, const RsTlvFileItem&);
|
||||||
|
bool operator==(const RsTlvFileSet&, const RsTlvFileSet& );
|
||||||
|
bool operator==(const RsTlvHashSet&, const RsTlvHashSet&);
|
||||||
|
bool operator==(const RsTlvImage&, const RsTlvImage& );
|
||||||
|
bool operator==(const RsTlvPeerIdSet& , const RsTlvPeerIdSet& );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* This templated test function which allows you to test
|
||||||
|
* retroshare serialiser items (except compound tlv items)
|
||||||
|
* you the function must implement a function
|
||||||
|
*
|
||||||
|
* 'RsSerialType* init_item(YourRsItem& rs_item)'
|
||||||
|
* which returns valid serialiser that
|
||||||
|
* can serialiser rs_item. You also need to implement an operator
|
||||||
|
*
|
||||||
|
* Also need to implement a function
|
||||||
|
* 'bool operator =(YourRsItem& rs_itemL, YourRsItem& rs_temR)'
|
||||||
|
* which allows this function to test for equality between both parameters.
|
||||||
|
* rs_temR is the result of deserialising the left operand (1st parameter).
|
||||||
|
* not YourRsItem in specifier in about functions should be a derived type from RsItem
|
||||||
|
*
|
||||||
|
* @param T the item you want to test
|
||||||
|
*/
|
||||||
|
|
||||||
|
template<class T> int test_RsItem()
|
||||||
|
{
|
||||||
|
/* make a serialisable RsTurtleItem */
|
||||||
|
|
||||||
|
RsSerialiser srl;
|
||||||
|
|
||||||
|
/* initialise */
|
||||||
|
T rsfi ;
|
||||||
|
RsSerialType *rsfis = init_item(rsfi) ;
|
||||||
|
|
||||||
|
/* attempt to serialise it before we add it to the serialiser */
|
||||||
|
|
||||||
|
CHECK(0 == srl.size(&rsfi));
|
||||||
|
|
||||||
|
static const uint32_t MAX_BUFSIZE = 22000 ;
|
||||||
|
|
||||||
|
char *buffer = new char[MAX_BUFSIZE];
|
||||||
|
uint32_t sersize = MAX_BUFSIZE;
|
||||||
|
|
||||||
|
CHECK(false == srl.serialise(&rsfi, (void *) buffer, &sersize));
|
||||||
|
|
||||||
|
/* now add to serialiser */
|
||||||
|
|
||||||
|
srl.addSerialType(rsfis);
|
||||||
|
|
||||||
|
uint32_t size = srl.size(&rsfi);
|
||||||
|
bool done = srl.serialise(&rsfi, (void *) buffer, &sersize);
|
||||||
|
|
||||||
|
std::cerr << "test_Item() size: " << size << std::endl;
|
||||||
|
std::cerr << "test_Item() done: " << done << std::endl;
|
||||||
|
std::cerr << "test_Item() sersize: " << sersize << std::endl;
|
||||||
|
|
||||||
|
std::cerr << "test_Item() serialised:" << std::endl;
|
||||||
|
//displayRawPacket(std::cerr, (void *) buffer, sersize);
|
||||||
|
|
||||||
|
CHECK(done == true);
|
||||||
|
|
||||||
|
uint32_t sersize2 = sersize;
|
||||||
|
RsItem *output = srl.deserialise((void *) buffer, &sersize2);
|
||||||
|
|
||||||
|
CHECK(output != NULL);
|
||||||
|
CHECK(sersize2 == sersize);
|
||||||
|
|
||||||
|
T *outfi = dynamic_cast<T *>(output);
|
||||||
|
|
||||||
|
CHECK(outfi != NULL);
|
||||||
|
|
||||||
|
if (outfi)
|
||||||
|
CHECK(*outfi == rsfi) ;
|
||||||
|
|
||||||
|
sersize2 = MAX_BUFSIZE;
|
||||||
|
bool done2 = srl.serialise(outfi, (void *) &(buffer[16*8]), &sersize2);
|
||||||
|
|
||||||
|
CHECK(done2) ;
|
||||||
|
CHECK(sersize2 == sersize);
|
||||||
|
|
||||||
|
// displayRawPacket(std::cerr, (void *) buffer, 16 * 8 + sersize2);
|
||||||
|
|
||||||
|
delete[] buffer ;
|
||||||
|
//delete rsfis;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T> int test_RsItem(uint16_t servtype)
|
||||||
|
{
|
||||||
|
/* make a serialisable RsTurtleItem */
|
||||||
|
|
||||||
|
RsSerialiser srl;
|
||||||
|
|
||||||
|
/* initialise */
|
||||||
|
T rsfi(servtype) ;
|
||||||
|
RsSerialType *rsfis = init_item(rsfi) ; // deleted on destruction of srl
|
||||||
|
|
||||||
|
/* attempt to serialise it before we add it to the serialiser */
|
||||||
|
|
||||||
|
CHECK(0 == srl.size(&rsfi));
|
||||||
|
|
||||||
|
static const uint32_t MAX_BUFSIZE = 22000 ;
|
||||||
|
|
||||||
|
char *buffer = new char[MAX_BUFSIZE];
|
||||||
|
uint32_t sersize = MAX_BUFSIZE;
|
||||||
|
|
||||||
|
CHECK(false == srl.serialise(&rsfi, (void *) buffer, &sersize));
|
||||||
|
|
||||||
|
/* now add to serialiser */
|
||||||
|
|
||||||
|
srl.addSerialType(rsfis);
|
||||||
|
|
||||||
|
uint32_t size = srl.size(&rsfi);
|
||||||
|
bool done = srl.serialise(&rsfi, (void *) buffer, &sersize);
|
||||||
|
|
||||||
|
std::cerr << "test_Item() size: " << size << std::endl;
|
||||||
|
std::cerr << "test_Item() done: " << done << std::endl;
|
||||||
|
std::cerr << "test_Item() sersize: " << sersize << std::endl;
|
||||||
|
|
||||||
|
std::cerr << "test_Item() serialised:" << std::endl;
|
||||||
|
//displayRawPacket(std::cerr, (void *) buffer, sersize);
|
||||||
|
|
||||||
|
CHECK(done == true);
|
||||||
|
|
||||||
|
uint32_t sersize2 = sersize;
|
||||||
|
RsItem *output = srl.deserialise((void *) buffer, &sersize2);
|
||||||
|
|
||||||
|
CHECK(output != NULL);
|
||||||
|
CHECK(sersize2 == sersize);
|
||||||
|
|
||||||
|
T *outfi = dynamic_cast<T *>(output);
|
||||||
|
|
||||||
|
CHECK(outfi != NULL);
|
||||||
|
|
||||||
|
if (outfi)
|
||||||
|
CHECK(*outfi == rsfi) ;
|
||||||
|
|
||||||
|
sersize2 = MAX_BUFSIZE;
|
||||||
|
bool done2 = srl.serialise(outfi, (void *) &(buffer[16*8]), &sersize2);
|
||||||
|
|
||||||
|
CHECK(done2) ;
|
||||||
|
CHECK(sersize2 == sersize);
|
||||||
|
|
||||||
|
// displayRawPacket(std::cerr, (void *) buffer, 16 * 8 + sersize2);
|
||||||
|
|
||||||
|
delete[] buffer ;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif /* SUPPORT_H_ */
|
|
@ -97,6 +97,17 @@ RsSerialType* init_item(RsSyncGrpMsgList& rsgml)
|
||||||
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RsSerialType* init_item(RsNxsTransac& rstx){
|
||||||
|
|
||||||
|
rstx.clear();
|
||||||
|
|
||||||
|
rstx.timeout = rand()%14141;
|
||||||
|
rstx.transactFlag = rand()%2424;
|
||||||
|
rstx.nItems = rand()%33132;
|
||||||
|
rstx.transactionId = rand()%242112;
|
||||||
|
|
||||||
|
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||||
|
}
|
||||||
|
|
||||||
bool operator==(const RsNxsGrp& l, const RsNxsGrp& r){
|
bool operator==(const RsNxsGrp& l, const RsNxsGrp& r){
|
||||||
|
|
||||||
|
@ -176,6 +187,17 @@ bool operator==(const RsSyncGrpMsgList& l, const RsSyncGrpMsgList& r)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator==(const RsNxsTransac& l, const RsNxsTransac& r){
|
||||||
|
|
||||||
|
if(l.transactFlag != r.transactFlag) return false;
|
||||||
|
if(l.transactionId != r.transactionId) return false;
|
||||||
|
if(l.timeout != r.timeout) return false;
|
||||||
|
if(l.nItems != r.nItems) return false;
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::cerr << "RsNxsItem Tests" << std::endl;
|
std::cerr << "RsNxsItem Tests" << std::endl;
|
||||||
|
@ -186,6 +208,7 @@ int main()
|
||||||
test_RsItem<RsSyncGrpMsg>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsSyncGrpMsg");
|
test_RsItem<RsSyncGrpMsg>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsSyncGrpMsg");
|
||||||
test_RsItem<RsSyncGrpList>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsSyncGrpList");
|
test_RsItem<RsSyncGrpList>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsSyncGrpList");
|
||||||
test_RsItem<RsSyncGrpMsgList>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsSyncGrpMsgList");
|
test_RsItem<RsSyncGrpMsgList>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsSyncGrpMsgList");
|
||||||
|
test_RsItem<RsNxsTransac>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsNxsTransac");
|
||||||
|
|
||||||
FINALREPORT("RsNxsItem Tests");
|
FINALREPORT("RsNxsItem Tests");
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ RsSerialType* init_item(RsSyncGrp&);
|
||||||
RsSerialType* init_item(RsSyncGrpMsg&);
|
RsSerialType* init_item(RsSyncGrpMsg&);
|
||||||
RsSerialType* init_item(RsSyncGrpList&);
|
RsSerialType* init_item(RsSyncGrpList&);
|
||||||
RsSerialType* init_item(RsSyncGrpMsgList&);
|
RsSerialType* init_item(RsSyncGrpMsgList&);
|
||||||
|
RsSerialType* init_item(RsNxsTransac& );
|
||||||
|
|
||||||
bool operator==(const RsNxsGrp&, const RsNxsGrp&);
|
bool operator==(const RsNxsGrp&, const RsNxsGrp&);
|
||||||
bool operator==(const RsNxsMsg&, const RsNxsMsg&);
|
bool operator==(const RsNxsMsg&, const RsNxsMsg&);
|
||||||
|
@ -17,6 +18,7 @@ bool operator==(const RsSyncGrp&, const RsSyncGrp&);
|
||||||
bool operator==(const RsSyncGrpMsg&, const RsSyncGrpMsg&);
|
bool operator==(const RsSyncGrpMsg&, const RsSyncGrpMsg&);
|
||||||
bool operator==(const RsSyncGrpList&, const RsSyncGrpList&);
|
bool operator==(const RsSyncGrpList&, const RsSyncGrpList&);
|
||||||
bool operator==(const RsSyncGrpMsgList&, const RsSyncGrpMsgList&);
|
bool operator==(const RsSyncGrpMsgList&, const RsSyncGrpMsgList&);
|
||||||
|
bool operator==(const RsNxsTransac&, const RsNxsTransac& );
|
||||||
|
|
||||||
|
|
||||||
#endif // RSNXSITEMS_TEST_H
|
#endif // RSNXSITEMS_TEST_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue