mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-10 18:15:18 -04:00
moved test sources to test directory and deleted a few dead files , created new util test directory.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3396 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
dc7dd949ca
commit
9e86265f91
8 changed files with 0 additions and 239 deletions
444
libretroshare/src/tests/ft/pqitestor.cc
Normal file
444
libretroshare/src/tests/ft/pqitestor.cc
Normal file
|
@ -0,0 +1,444 @@
|
|||
/*
|
||||
* libretroshare/src/ft: pqitestor.cc
|
||||
*
|
||||
* File Transfer for RetroShare.
|
||||
*
|
||||
* Copyright 2008 by Robert Fernie.
|
||||
*
|
||||
* 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 "ft/pqitestor.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
|
||||
/******
|
||||
*#define HUB_DEBUG 1
|
||||
*****/
|
||||
|
||||
P3Hub::P3Hub(uint32_t flags, RsSerialiser *rss)
|
||||
:mSerialiser(rss), mUseSerialiser(false)
|
||||
{
|
||||
if (rss)
|
||||
{
|
||||
mUseSerialiser = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void P3Hub::addP3Pipe(std::string id, P3Pipe *pqi, p3ConnectMgr *mgr)
|
||||
{
|
||||
hubItem item(id, pqi, mgr);
|
||||
|
||||
std::map<std::string, hubItem>::iterator it;
|
||||
for(it = mPeers.begin(); it != mPeers.end(); it++)
|
||||
{
|
||||
(it->second).mConnMgr->connectResult(id, true, 0);
|
||||
mgr->connectResult(it->first, true, 0);
|
||||
}
|
||||
|
||||
mPeers[id] = item;
|
||||
|
||||
/* tell all the other peers we are connected */
|
||||
|
||||
#ifdef HUB_DEBUG
|
||||
std::cerr << "P3Hub::addPQIPipe()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
RsItem *P3Hub::SerialiserPass(RsItem *inItem)
|
||||
{
|
||||
/* pass through serialiser */
|
||||
|
||||
RsItem *item = NULL;
|
||||
|
||||
uint32_t pktsize = mSerialiser->size(inItem);
|
||||
void *ptr = malloc(pktsize);
|
||||
|
||||
#ifdef HUB_DEBUG
|
||||
std::cerr << "P3Hub::SerialiserPass() Expected Size: " << pktsize;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
if (!mSerialiser->serialise(inItem, ptr, &pktsize))
|
||||
{
|
||||
|
||||
#ifdef HUB_DEBUG
|
||||
std::cerr << "P3Hub::SerialiserPass() serialise Failed";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
#ifdef HUB_DEBUG
|
||||
std::cerr << "P3Hub::SerialiserPass() serialise success, size: " << pktsize;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
item = mSerialiser->deserialise(ptr, &pktsize);
|
||||
item->PeerId(inItem->PeerId());
|
||||
|
||||
if (!item)
|
||||
{
|
||||
#ifdef HUB_DEBUG
|
||||
std::cerr << "P3Hub::SerialiserPass() deSerialise Failed";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
delete inItem;
|
||||
free(ptr);
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
void P3Hub::run()
|
||||
{
|
||||
#ifdef HUB_DEBUG
|
||||
std::cerr << "P3Hub::run()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
RsItem *item;
|
||||
std::list<std::pair<std::string, RsItem *> > recvdQ;
|
||||
std::list<std::pair<std::string, RsItem *> >::iterator lit;
|
||||
while(1)
|
||||
{
|
||||
#ifdef HUB_DEBUG
|
||||
std::cerr << "P3Hub::run()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, hubItem>::iterator it;
|
||||
for(it = mPeers.begin(); it != mPeers.end(); it++)
|
||||
{
|
||||
while (NULL != (item = it->second.mPQI->PopSentItem()))
|
||||
{
|
||||
#ifdef HUB_DEBUG
|
||||
std::cerr << "P3Hub::run() recvd msg from: ";
|
||||
std::cerr << it->first;
|
||||
std::cerr << " for " << item->PeerId();
|
||||
std::cerr << std::endl;
|
||||
item->print(std::cerr, 10);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
if (mUseSerialiser)
|
||||
{
|
||||
item = SerialiserPass(item);
|
||||
}
|
||||
|
||||
/* serialiser might hav munched it. */
|
||||
if (item)
|
||||
{
|
||||
recvdQ.push_back(make_pair(it->first, item));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* now send out */
|
||||
for(lit = recvdQ.begin(); lit != recvdQ.end(); lit++)
|
||||
{
|
||||
std::string srcId = lit->first;
|
||||
std::string destId = (lit->second)->PeerId();
|
||||
if (mPeers.end() == (it = mPeers.find(destId)))
|
||||
{
|
||||
#ifdef HUB_DEBUG
|
||||
std::cerr << "Failed to Find destination: " << destId;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "Deleting Packet";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
delete (lit->second);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* now we have dest, set source Id */
|
||||
(lit->second)->PeerId(srcId);
|
||||
#ifdef HUB_DEBUG
|
||||
std::cerr << "P3Hub::run() sending msg from: ";
|
||||
std::cerr << srcId << "to: ";
|
||||
std::cerr << destId;
|
||||
std::cerr << std::endl;
|
||||
(lit->second)->print(std::cerr, 10);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
(it->second).mPQI->PushRecvdItem(lit->second);
|
||||
}
|
||||
}
|
||||
|
||||
recvdQ.clear();
|
||||
|
||||
|
||||
|
||||
/* Tick the Connection Managers (normally done by rsserver)
|
||||
*/
|
||||
|
||||
/* sleep a bit */
|
||||
#ifdef WIN32
|
||||
Sleep(1000);
|
||||
#else
|
||||
sleep(1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
PQIPipe::PQIPipe(std::string peerId)
|
||||
:PQInterface(peerId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int PQIPipe::SendItem(RsItem *item)
|
||||
{
|
||||
RsStackMutex stack(pipeMtx); /***** LOCK MUTEX ****/
|
||||
|
||||
mSentItems.push_back(item);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
RsItem *PQIPipe::PopSentItem()
|
||||
{
|
||||
RsStackMutex stack(pipeMtx); /***** LOCK MUTEX ****/
|
||||
|
||||
if (mSentItems.size() == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RsItem *item = mSentItems.front();
|
||||
mSentItems.pop_front();
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
int PQIPipe::PushRecvdItem(RsItem *item)
|
||||
{
|
||||
RsStackMutex stack(pipeMtx); /***** LOCK MUTEX ****/
|
||||
|
||||
mRecvdItems.push_back(item);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
RsItem *PQIPipe::GetItem()
|
||||
{
|
||||
RsStackMutex stack(pipeMtx); /***** LOCK MUTEX ****/
|
||||
|
||||
if (mRecvdItems.size() == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RsItem *item = mRecvdItems.front();
|
||||
mRecvdItems.pop_front();
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/***** P3Pipe here *****/
|
||||
|
||||
|
||||
|
||||
|
||||
int P3Pipe::SendAllItem(RsItem *item)
|
||||
{
|
||||
RsStackMutex stack(pipeMtx); /***** LOCK MUTEX ****/
|
||||
|
||||
mSentItems.push_back(item);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
RsItem *P3Pipe::PopSentItem()
|
||||
{
|
||||
RsStackMutex stack(pipeMtx); /***** LOCK MUTEX ****/
|
||||
|
||||
if (mSentItems.size() == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RsItem *item = mSentItems.front();
|
||||
mSentItems.pop_front();
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
int P3Pipe::PushRecvdItem(RsItem *item)
|
||||
{
|
||||
RsStackMutex stack(pipeMtx); /***** LOCK MUTEX ****/
|
||||
|
||||
RsCacheRequest *rcr;
|
||||
RsCacheItem *rci;
|
||||
RsFileRequest *rfr;
|
||||
RsFileData *rfd;
|
||||
RsRawItem *rri;
|
||||
|
||||
if (NULL != (rcr = dynamic_cast<RsCacheRequest *>(item)))
|
||||
{
|
||||
mRecvdRsCacheRequests.push_back(rcr);
|
||||
}
|
||||
else if (NULL != (rci = dynamic_cast<RsCacheItem *>(item)))
|
||||
{
|
||||
mRecvdRsCacheItems.push_back(rci);
|
||||
}
|
||||
else if (NULL != (rfr = dynamic_cast<RsFileRequest *>(item)))
|
||||
{
|
||||
mRecvdRsFileRequests.push_back(rfr);
|
||||
}
|
||||
else if (NULL != (rfd = dynamic_cast<RsFileData *>(item)))
|
||||
{
|
||||
mRecvdRsFileDatas.push_back(rfd);
|
||||
}
|
||||
else if (NULL != (rri = dynamic_cast<RsRawItem *>(item)))
|
||||
{
|
||||
mRecvdRsRawItems.push_back(rri);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int P3Pipe::SearchSpecific(RsCacheRequest *item)
|
||||
{
|
||||
SendAllItem(item);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int P3Pipe::SendSearchResult(RsCacheItem *item)
|
||||
{
|
||||
SendAllItem(item);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int P3Pipe::SendFileRequest(RsFileRequest *item)
|
||||
{
|
||||
SendAllItem(item);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int P3Pipe::SendFileData(RsFileData *item)
|
||||
{
|
||||
SendAllItem(item);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int P3Pipe::SendRsRawItem(RsRawItem *item)
|
||||
{
|
||||
SendAllItem(item);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Cache Requests
|
||||
RsCacheRequest *P3Pipe::RequestedSearch()
|
||||
{
|
||||
RsStackMutex stack(pipeMtx); /***** LOCK MUTEX ****/
|
||||
|
||||
if (mRecvdRsCacheRequests.size() == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RsCacheRequest *item = mRecvdRsCacheRequests.front();
|
||||
mRecvdRsCacheRequests.pop_front();
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
// Cache Results
|
||||
RsCacheItem *P3Pipe::GetSearchResult()
|
||||
{
|
||||
RsStackMutex stack(pipeMtx); /***** LOCK MUTEX ****/
|
||||
|
||||
if (mRecvdRsCacheItems.size() == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RsCacheItem *item = mRecvdRsCacheItems.front();
|
||||
mRecvdRsCacheItems.pop_front();
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
// FileTransfer.
|
||||
RsFileRequest *P3Pipe::GetFileRequest()
|
||||
{
|
||||
RsStackMutex stack(pipeMtx); /***** LOCK MUTEX ****/
|
||||
|
||||
if (mRecvdRsFileRequests.size() == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RsFileRequest *item = mRecvdRsFileRequests.front();
|
||||
mRecvdRsFileRequests.pop_front();
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
RsFileData *P3Pipe::GetFileData()
|
||||
{
|
||||
RsStackMutex stack(pipeMtx); /***** LOCK MUTEX ****/
|
||||
|
||||
if (mRecvdRsFileDatas.size() == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RsFileData *item = mRecvdRsFileDatas.front();
|
||||
mRecvdRsFileDatas.pop_front();
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
RsRawItem *P3Pipe::GetRsRawItem()
|
||||
{
|
||||
RsStackMutex stack(pipeMtx); /***** LOCK MUTEX ****/
|
||||
|
||||
if (mRecvdRsRawItems.size() == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RsRawItem *item = mRecvdRsRawItems.front();
|
||||
mRecvdRsRawItems.pop_front();
|
||||
|
||||
return item;
|
||||
}
|
||||
|
152
libretroshare/src/tests/ft/pqitestor.h
Normal file
152
libretroshare/src/tests/ft/pqitestor.h
Normal file
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
* libretroshare/src/ft: pqitestor.h
|
||||
*
|
||||
* File Transfer for RetroShare.
|
||||
*
|
||||
* Copyright 2008 by Robert Fernie.
|
||||
*
|
||||
* 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PQI_HUB_TEST_H
|
||||
#define PQI_HUB_TEST_H
|
||||
|
||||
/*
|
||||
* pqi Test Interface.
|
||||
*/
|
||||
|
||||
/***
|
||||
* Structures for ftserver simulations
|
||||
*
|
||||
****/
|
||||
|
||||
#include "pqi/pqi.h"
|
||||
#include "util/rsthreads.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class hubItem;
|
||||
class PQIPipe;
|
||||
class PQIHub;
|
||||
class P3Pipe;
|
||||
class P3Hub;
|
||||
class p3ConnectMgr;
|
||||
|
||||
|
||||
class hubItem
|
||||
{
|
||||
public:
|
||||
hubItem()
|
||||
:mPQI(NULL), mConnMgr(NULL) { return; }
|
||||
|
||||
hubItem(std::string id, P3Pipe *pqi, p3ConnectMgr *mgr)
|
||||
:mPeerId(id), mPQI(pqi), mConnMgr(mgr) { return; }
|
||||
|
||||
std::string mPeerId;
|
||||
P3Pipe *mPQI;
|
||||
p3ConnectMgr *mConnMgr;
|
||||
};
|
||||
|
||||
|
||||
class P3Hub: public RsThread
|
||||
{
|
||||
public:
|
||||
|
||||
P3Hub(uint32_t flags, RsSerialiser *rss);
|
||||
void addP3Pipe(std::string id, P3Pipe *, p3ConnectMgr *mgr);
|
||||
|
||||
virtual void run();
|
||||
|
||||
private:
|
||||
|
||||
RsItem* SerialiserPass(RsItem *inItem);
|
||||
|
||||
std::map<std::string, hubItem> mPeers;
|
||||
RsSerialiser *mSerialiser;
|
||||
bool mUseSerialiser;
|
||||
};
|
||||
|
||||
|
||||
class PQIPipe: public PQInterface
|
||||
{
|
||||
public:
|
||||
PQIPipe(std::string peerId);
|
||||
|
||||
virtual int SendItem(RsItem *);
|
||||
virtual RsItem *GetItem();
|
||||
|
||||
// PQIHub Interface.
|
||||
RsItem *PopSentItem();
|
||||
int PushRecvdItem(RsItem *);
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
private:
|
||||
|
||||
RsMutex pipeMtx;
|
||||
|
||||
std::list<RsItem *> mSentItems;
|
||||
std::list<RsItem *> mRecvdItems;
|
||||
|
||||
};
|
||||
|
||||
class P3Pipe: public P3Interface
|
||||
{
|
||||
public:
|
||||
P3Pipe() {return; }
|
||||
virtual ~P3Pipe() {return; }
|
||||
|
||||
virtual int tick() { return 1; }
|
||||
virtual int status() { return 1; }
|
||||
|
||||
/* Overloaded from P3Interface */
|
||||
virtual int SearchSpecific(RsCacheRequest *item);
|
||||
virtual int SendSearchResult(RsCacheItem *item);
|
||||
virtual int SendFileRequest(RsFileRequest *item);
|
||||
virtual int SendFileData(RsFileData *item);
|
||||
virtual int SendRsRawItem(RsRawItem *item);
|
||||
|
||||
virtual RsCacheRequest *RequestedSearch();
|
||||
virtual RsCacheItem *GetSearchResult();
|
||||
virtual RsFileRequest *GetFileRequest();
|
||||
virtual RsFileData *GetFileData();
|
||||
virtual RsRawItem *GetRsRawItem();
|
||||
|
||||
/* Lower Interface for PQIHub */
|
||||
|
||||
RsItem *PopSentItem();
|
||||
int PushRecvdItem(RsItem *item);
|
||||
|
||||
private:
|
||||
|
||||
int SendAllItem(RsItem *item);
|
||||
|
||||
RsMutex pipeMtx;
|
||||
|
||||
std::list<RsItem *> mSentItems;
|
||||
|
||||
std::list<RsCacheRequest *> mRecvdRsCacheRequests;
|
||||
std::list<RsCacheItem *> mRecvdRsCacheItems;
|
||||
std::list<RsFileRequest *> mRecvdRsFileRequests;
|
||||
std::list<RsFileData *> mRecvdRsFileDatas;
|
||||
std::list<RsRawItem *> mRecvdRsRawItems;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
48
libretroshare/src/tests/tcponudp/udptestfn.cc
Normal file
48
libretroshare/src/tests/tcponudp/udptestfn.cc
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* libretroshare/src/tcponudp: udptestfn.cc
|
||||
*
|
||||
* TCP-on-UDP (tou) network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2007-2008 by Robert Fernie.
|
||||
*
|
||||
* 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 "udptestfn.h"
|
||||
|
||||
void UdpRecvTest::recvPkt(void *data, int size, struct sockaddr_in &from)
|
||||
{
|
||||
/* print packet information */
|
||||
std::cerr << "UdpRecvTest::recvPkt(" << size << ") from: " << from;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
UdpPeerTest::UdpPeerTest(struct sockaddr_in &addr)
|
||||
:raddr(addr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void UdpPeerTest::recvPkt(void *data, int size)
|
||||
{
|
||||
/* print packet information */
|
||||
std::cerr << "UdpPeerTest::recvPkt(" << size << ") from: " << raddr;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
|
49
libretroshare/src/tests/tcponudp/udptestfn.h
Normal file
49
libretroshare/src/tests/tcponudp/udptestfn.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* libretroshare/src/tcponudp: udptestfn.h
|
||||
*
|
||||
* TCP-on-UDP (tou) network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2007-2008 by Robert Fernie.
|
||||
*
|
||||
* 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 "udplayer.h"
|
||||
#include "udpsorter.h"
|
||||
|
||||
#ifndef TOU_UDP_TEST_FN_H
|
||||
#define TOU_UDP_TEST_FN_H
|
||||
|
||||
class UdpRecvTest: public UdpReceiver
|
||||
{
|
||||
public:
|
||||
virtual void recvPkt(void *data, int size, struct sockaddr_in &from);
|
||||
};
|
||||
|
||||
|
||||
class UdpPeerTest: public UdpPeer
|
||||
{
|
||||
public:
|
||||
UdpPeerTest(struct sockaddr_in &addr);
|
||||
virtual void recvPkt(void *data, int size);
|
||||
|
||||
struct sockaddr_in raddr;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
79
libretroshare/src/tests/util/dir2test.cc
Normal file
79
libretroshare/src/tests/util/dir2test.cc
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* dirtest.cc
|
||||
*
|
||||
* RetroShare Test Program.
|
||||
*
|
||||
* Copyright 2004-2007 by Robert Fernie.
|
||||
*
|
||||
* 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 "util/rsdir.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int processpath(std::string path);
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
std::string path1 = "/home/tst1//test2///test3/";
|
||||
std::string path2 = "home2/tst4//test5///test6";
|
||||
std::string path3 = "//home3";
|
||||
std::string path4 = "//";
|
||||
std::string path5 = "/a/b/c/d/";
|
||||
std::string path6 = "a//b/c//d";
|
||||
|
||||
processpath(path1);
|
||||
processpath(path2);
|
||||
processpath(path3);
|
||||
processpath(path4);
|
||||
processpath(path5);
|
||||
processpath(path6);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int processpath(std::string path)
|
||||
{
|
||||
std::string pathtogo = path;
|
||||
while(pathtogo != "")
|
||||
{
|
||||
std::string basedir = RsDirUtil::getRootDir(pathtogo);
|
||||
std::string rempath = RsDirUtil::removeRootDir(pathtogo);
|
||||
std::string topdir = RsDirUtil::getTopDir(pathtogo);
|
||||
std::string remtoppath = RsDirUtil::removeTopDir(pathtogo);
|
||||
|
||||
std::cerr << "Processing: \"" << pathtogo << "\"" << std::endl;
|
||||
std::cerr << "\tRootDir : \"" << basedir << "\"" << std::endl;
|
||||
std::cerr << "\tRemaining: \"" << rempath << "\"" << std::endl;
|
||||
std::cerr << "\tTopDir : \"" << topdir << "\"" << std::endl;
|
||||
std::cerr << "\tRemaining(Top): \"" << remtoppath << "\"" << std::endl;
|
||||
std::cerr << std::endl;
|
||||
|
||||
pathtogo = rempath;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
99
libretroshare/src/tests/util/dirtest.cc
Normal file
99
libretroshare/src/tests/util/dirtest.cc
Normal file
|
@ -0,0 +1,99 @@
|
|||
|
||||
/*
|
||||
* "$Id: dirtest.cc,v 1.1 2007-02-19 20:08:30 rmf24 Exp $"
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2004-2007 by Robert Fernie.
|
||||
*
|
||||
* 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 "util/rsdir.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
bool testRsDirUtils(std::string path);
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
std::list<std::string> dirs;
|
||||
std::list<std::string>::iterator it;
|
||||
dirs.push_back("/incoming/htuyr/file.txt");
|
||||
dirs.push_back("/incoming/htuyr/file.txt ");
|
||||
dirs.push_back("/incoming/htuyr/file.txt/");
|
||||
dirs.push_back("/incoming/htuyr/file.txt//");
|
||||
dirs.push_back("/incoming/htuyr//file.txt//");
|
||||
dirs.push_back("/incoming/htuyr//file .txt");
|
||||
dirs.push_back("/incoming/htuyr/Q");
|
||||
dirs.push_back("/incoming/htuyr/Q//");
|
||||
dirs.push_back("/incoming/htuyr/Q/");
|
||||
dirs.push_back("/incoming/htuyr/Q/text");
|
||||
dirs.push_back("/home/tst1//test2///test3/");
|
||||
dirs.push_back("home2/tst4//test5///test6");
|
||||
dirs.push_back("//home3");
|
||||
dirs.push_back("//");
|
||||
dirs.push_back("A");
|
||||
dirs.push_back("ABC");
|
||||
dirs.push_back("////ABC////");
|
||||
dirs.push_back("A/B/C");
|
||||
|
||||
for(it = dirs.begin(); it != dirs.end(); it++)
|
||||
{
|
||||
testRsDirUtils(*it);
|
||||
}
|
||||
}
|
||||
|
||||
bool testRsDirUtils(std::string path)
|
||||
{
|
||||
|
||||
std::cerr << "RsUtilTest input: [" << path << "]";
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::string top = RsDirUtil::getTopDir(path);
|
||||
std::string root = RsDirUtil::getRootDir(path);
|
||||
std::string topdirs = RsDirUtil::removeRootDir(path);
|
||||
std::string topdirs2 = RsDirUtil::removeRootDirs(path, root);
|
||||
std::string restdirs = RsDirUtil::removeTopDir(path);
|
||||
std::list<std::string> split;
|
||||
std::list<std::string>::iterator it;
|
||||
RsDirUtil::breakupDirList(path, split);
|
||||
|
||||
std::cerr << "\tTop: [" << top << "]";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\tRest: [" << restdirs << "]";
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::cerr << "\tRoot: [" << root << "]";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\tRemoveRoot: [" << topdirs << "]";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\tSplit Up ";
|
||||
for(it = split.begin(); it != split.end(); it++)
|
||||
{
|
||||
std::cerr << ":" << (*it);
|
||||
}
|
||||
std::cerr << std::endl;
|
||||
std::cerr << std::endl;
|
||||
return true;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue