Merged Code from: /branches/v0.5-new_cache_system/ into main trunk.

- Revisions 4771 => 5334

 * This merge brings a lot of unfinished code for GXS (new cache system)
 	- See branch commits for more details.
 * Code is disabled, and should have minimal effect on trunk build.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5338 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-07-27 15:03:16 +00:00
commit bec1407648
170 changed files with 44564 additions and 11756 deletions

View file

@ -0,0 +1,97 @@
#include "support.h"
#include "data_support.h"
bool operator==(const RsNxsGrp& l, const RsNxsGrp& r){
if(l.grpId != r.grpId) return false;
if(!(l.grp == r.grp) ) return false;
if(!(l.meta == r.meta) ) return false;
if(l.transactionNumber != r.transactionNumber) 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.msg == r.msg) ) return false;
if(! (l.meta == r.meta) ) return false;
if(l.transactionNumber != r.transactionNumber) return false;
return true;
}
void init_item(RsNxsGrp& nxg)
{
nxg.clear();
randString(SHORT_STR, nxg.grpId);
nxg.transactionNumber = rand()%23;
init_item(nxg.grp);
init_item(nxg.meta);
return;
}
void init_item(RsNxsMsg& nxm)
{
nxm.clear();
randString(SHORT_STR, nxm.msgId);
randString(SHORT_STR, nxm.grpId);
init_item(nxm.msg);
init_item(nxm.meta);
nxm.transactionNumber = rand()%23;
return;
}
void init_item(RsGxsGrpMetaData* metaGrp)
{
randString(SHORT_STR, metaGrp->mGroupId);
randString(SHORT_STR, metaGrp->mOrigGrpId);
randString(SHORT_STR, metaGrp->mAuthorId);
randString(SHORT_STR, metaGrp->mGroupName);
init_item(metaGrp->adminSign);
init_item(metaGrp->keys);
init_item(metaGrp->idSign);
metaGrp->mPublishTs = rand()%3452;
metaGrp->mGroupFlags = rand()%43;
metaGrp->mGroupStatus = rand()%313;
metaGrp->mSubscribeFlags = rand()%2251;
metaGrp->mMsgCount = rand()%2421;
metaGrp->mLastPost = rand()%2211;
metaGrp->mPop = rand()%5262;
}
void init_item(RsGxsMsgMetaData* metaMsg)
{
randString(SHORT_STR, metaMsg->mGroupId);
randString(SHORT_STR, metaMsg->mMsgId);
randString(SHORT_STR, metaMsg->mThreadId);
randString(SHORT_STR, metaMsg->mParentId);
randString(SHORT_STR, metaMsg->mAuthorId);
randString(SHORT_STR, metaMsg->mOrigMsgId);
randString(SHORT_STR, metaMsg->mMsgName);
init_item(metaMsg->pubSign);
init_item(metaMsg->idSign);
metaMsg->mPublishTs = rand()%313;
metaMsg->mMsgFlags = rand()%224;
metaMsg->mMsgStatus = rand()%4242;
metaMsg->mChildTs = rand()%221;
}

View file

@ -0,0 +1,15 @@
#ifndef DATA_SUPPORT_H
#define DATA_SUPPORT_H
#include "serialiser/rsnxsitems.h"
#include "gxs/rsgxsdata.h"
bool operator==(const RsNxsGrp&, const RsNxsGrp&);
bool operator==(const RsNxsMsg&, const RsNxsMsg&);
void init_item(RsNxsGrp& nxg);
void init_item(RsNxsMsg& nxm);
void init_item(RsGxsGrpMetaData* metaGrp);
void init_item(RsGxsMsgMetaData* metaMsg);
#endif // DATA_SUPPORT_H

View file

@ -0,0 +1,81 @@
#include "nxstesthub.h"
NxsTestHub::NxsTestHub(NxsTestScenario* nts) : mTestScenario(nts)
{
netServicePairs.first = new RsGxsNetService(mTestScenario->getServiceType(),
mTestScenario->dummyDataService1(), &netMgr1, mTestScenario);
netServicePairs.second = new RsGxsNetService(mTestScenario->getServiceType(),
mTestScenario->dummyDataService2(), &netMgr2, mTestScenario);
mServicePairs.first = netServicePairs.first;
mServicePairs.second = netServicePairs.second;
createThread(*(netServicePairs.first));
createThread(*(netServicePairs.second));
}
NxsTestHub::~NxsTestHub()
{
delete netServicePairs.first;
delete netServicePairs.second;
}
void NxsTestHub::run()
{
std::list<RsItem*> send_queue_s1, send_queue_s2;
while(isRunning()){
// make thread sleep for a couple secs
usleep(3000);
p3Service* s1 = mServicePairs.first;
p3Service* s2 = mServicePairs.second;
RsItem* item = NULL;
while((item = s1->send()) != NULL)
{
item->PeerId("PeerB");
send_queue_s1.push_back(item);
}
while((item = s2->send()) != NULL)
{
item->PeerId("PeerA");
send_queue_s2.push_back(item);
}
while(!send_queue_s1.empty()){
item = send_queue_s1.front();
s2->receive(dynamic_cast<RsRawItem*>(item));
send_queue_s1.pop_front();
}
while(!send_queue_s2.empty()){
item = send_queue_s2.front();
s1->receive(dynamic_cast<RsRawItem*>(item));
send_queue_s2.pop_front();
}
// tick services so nxs net services process items
s1->tick();
s2->tick();
}
// also shut down this net service peers if this goes down
netServicePairs.first->join();
netServicePairs.second->join();
}
void NxsTestHub::cleanUp()
{
mTestScenario->cleanUp();
}
bool NxsTestHub::testsPassed()
{
return false;
}

View file

@ -0,0 +1,109 @@
#ifndef NXSTESTHUB_H
#define NXSTESTHUB_H
#include "util/rsthreads.h"
#include "gxs/rsgxsnetservice.h"
#include "nxstestscenario.h"
// it would probably be useful if the test scenario
// provided the net dummy managers
// hence one could envision synchronising between an arbitrary number
// of peers
class NxsNetDummyMgr1 : public RsNxsNetMgr
{
public:
NxsNetDummyMgr1() : mOwnId("peerA") {
mPeers.insert("peerB");
}
std::string getOwnId() { return mOwnId; }
void getOnlineList(std::set<std::string>& ssl_peers) { ssl_peers = mPeers; }
private:
std::string mOwnId;
std::set<std::string> mPeers;
};
class NxsNetDummyMgr2 : public RsNxsNetMgr
{
public:
NxsNetDummyMgr2() : mOwnId("peerB") {
mPeers.insert("peerA");
}
std::string getOwnId() { return mOwnId; }
void getOnlineList(std::set<std::string>& ssl_peers) { ssl_peers = mPeers; }
private:
std::string mOwnId;
std::set<std::string> mPeers;
};
/*!
* Testing of nxs services occurs through use of two services
* When a service sends this class can interrogate the send and the receives of
*
* NxsScenario stores the type of synchronisation to be tested
* Operation:
* First NxsTestHub needs to be instantiated with a test scenario
* * The scenario contains two databases to be used on the communicating pair of RsGxsNetService instances (net instances)
* The Test hub has a ticker service for the p3Services which allows the netservices to search what groups and messages they have
* and synchronise according to their subscriptions. The default is to subscribe to all groups held by other peer
* The threads for both net instances are started which begins their processing of transactions
*/
class NxsTestHub : public RsThread
{
public:
/*!
* This construct the test hub
* for a give scenario in mind
*/
NxsTestHub(NxsTestScenario*);
/*!
*
*/
virtual ~NxsTestHub();
/*!
* To be called only after this thread has
* been shutdown
*/
bool testsPassed();
/*!
* This simulates the p3Service ticker and calls both gxs net services tick methods
* Also enables transport of messages between both services
*/
void run();
void cleanUp();
private:
std::pair<p3Service*, p3Service*> mServicePairs;
std::pair<RsGxsNetService*, RsGxsNetService*> netServicePairs;
NxsTestScenario *mTestScenario;
NxsNetDummyMgr1 netMgr1;
NxsNetDummyMgr2 netMgr2;
};
#endif // NXSTESTHUB_H

View file

@ -0,0 +1,161 @@
/*
* nxstestscenario.cc
*
* Created on: 10 Jul 2012
* Author: crispy
*/
#include "nxstestscenario.h"
#include "gxs/rsdataservice.h"
#include "data_support.h"
NxsMessageTest::NxsMessageTest(uint16_t servtype)
: mServType(servtype)
{
mStorePair.first = new RsDataService(".", "dStore1", mServType);
mStorePair.second = new RsDataService(".", "dStore2", mServType);
setUpDataBases();
}
std::string NxsMessageTest::getTestName()
{
return std::string("Nxs Message Test!");
}
NxsMessageTest::~NxsMessageTest(){
delete mStorePair.first;
delete mStorePair.second;
}
void NxsMessageTest::setUpDataBases()
{
// create several groups and then messages of that
// group for both second and first of pair
RsDataService* dStore = dynamic_cast<RsDataService*>(mStorePair.first);
populateStore(dStore);
dStore = dynamic_cast<RsDataService*>(mStorePair.second);
populateStore(dStore);
dStore = NULL;
return;
}
uint16_t NxsMessageTest::getServiceType()
{
return mServType;
}
void NxsMessageTest::populateStore(RsGeneralDataService* dStore)
{
int nGrp = rand()%7;
std::vector<std::string> grpIdList;
std::map<RsNxsGrp*, RsGxsGrpMetaData*> grps;
RsNxsGrp* grp = NULL;
RsGxsGrpMetaData* grpMeta =NULL;
for(int i = 0; i < nGrp; i++)
{
std::pair<RsNxsGrp*, RsGxsGrpMetaData*> p;
grp = new RsNxsGrp(mServType);
grpMeta = new RsGxsGrpMetaData();
p.first = grp;
p.second = grpMeta;
init_item(*grp);
init_item(grpMeta);
grpMeta->mGroupId = grp->grpId;
grps.insert(p);
grpIdList.push_back(grp->grpId);
grpMeta = NULL;
grp = NULL;
}
dStore->storeGroup(grps);
std::map<RsNxsGrp*, RsGxsGrpMetaData*>::iterator grp_it
= grps.begin();
for(; grp_it != grps.end(); grp_it++)
{
delete grp_it->first;
delete grp_it->second;
}
int nMsgs = rand()%23;
std::map<RsNxsMsg*, RsGxsMsgMetaData*> msgs;
RsNxsMsg* msg = NULL;
RsGxsMsgMetaData* msgMeta = NULL;
for(int i=0; i<nMsgs; i++)
{
msg = new RsNxsMsg(mServType);
msgMeta = new RsGxsMsgMetaData();
init_item(*msg);
init_item(msgMeta);
std::pair<RsNxsMsg*, RsGxsMsgMetaData*> p(msg, msgMeta);
// pick a grp at random to associate the msg to
const std::string& grpId = grpIdList[rand()%nGrp];
msgMeta->mMsgId = msg->msgId;
msgMeta->mGroupId = msg->grpId = grpId;
msg = NULL;
msgMeta = NULL;
msgs.insert(p);
}
dStore->storeMessage(msgs);
// clean up
std::map<RsNxsMsg*, RsGxsMsgMetaData*>::iterator msg_it
= msgs.begin();
for(; msg_it != msgs.end(); msg_it++)
{
delete msg_it->first;
delete msg_it->second;
}
return;
}
void NxsMessageTest::notifyNewMessages(std::vector<RsNxsMsg*>& messages)
{
std::vector<RsNxsMsg*>::iterator vit = messages.begin();
for(; vit != messages.end(); vit++)
{
mPeerMsgs[(*vit)->PeerId()].push_back(*vit);
}
}
void NxsMessageTest::notifyNewGroups(std::vector<RsNxsGrp*>& groups)
{
std::vector<RsNxsGrp*>::iterator vit = groups.begin();
for(; vit != groups.end(); vit++)
{
mPeerGrps[(*vit)->PeerId()].push_back(*vit);
}
}
RsGeneralDataService* NxsMessageTest::dummyDataService1()
{
return mStorePair.first;
}
RsGeneralDataService* NxsMessageTest::dummyDataService2()
{
return mStorePair.second;
}
void NxsMessageTest::cleanUp()
{
mStorePair.first->resetDataStore();
mStorePair.second->resetDataStore();
return;
}

View file

@ -0,0 +1,83 @@
/*
* nxstestscenario.h
*
* Created on: 10 Jul 2012
* Author: crispy
*/
#ifndef NXSTESTSCENARIO_H_
#define NXSTESTSCENARIO_H_
#include <map>
#include "gxs/rsdataservice.h"
#include "gxs/rsnxsobserver.h"
/*!
* This scenario module provides data resources
*/
class NxsTestScenario : public RsNxsObserver
{
public:
virtual std::string getTestName() = 0;
virtual RsGeneralDataService* dummyDataService1() = 0;
virtual RsGeneralDataService* dummyDataService2() = 0;
virtual uint16_t getServiceType() = 0;
/*!
* Call to remove files created
* in the test directory
*/
virtual void cleanUp() = 0;
};
class NxsMessageTest : public NxsTestScenario
{
public:
NxsMessageTest(uint16_t servtype);
virtual ~NxsMessageTest();
std::string getTestName();
uint16_t getServiceType();
RsGeneralDataService* dummyDataService1();
RsGeneralDataService* dummyDataService2();
/*!
* Call to remove files created
* in the test directory
*/
void cleanUp();
public:
/*!
* @param messages messages are deleted after function returns
*/
void notifyNewMessages(std::vector<RsNxsMsg*>& messages);
/*!
* @param messages messages are deleted after function returns
*/
void notifyNewGroups(std::vector<RsNxsGrp*>& groups);
private:
void setUpDataBases();
void populateStore(RsGeneralDataService* dStore);
private:
std::string mTestName;
std::pair<RsGeneralDataService*, RsGeneralDataService*> mStorePair;
std::map<std::string, std::vector<RsNxsMsg*> > mPeerMsgs;
std::map<std::string, std::vector<RsNxsGrp*> > mPeerGrps;
uint16_t mServType;
};
#endif /* NXSTESTSCENARIO_H_ */

View file

@ -0,0 +1,73 @@
#-------------------------------------------------
#
# Project created by QtCreator 2012-05-06T09:19:26
#
#-------------------------------------------------
QT += core network
QT -= gui
TARGET = rs_test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
win32 {
# Switch on extra warnings
QMAKE_CFLAGS += -Wextra
QMAKE_CXXFLAGS += -Wextra
# Switch off optimization for release version
QMAKE_CXXFLAGS_RELEASE -= -O2
QMAKE_CXXFLAGS_RELEASE += -O0
QMAKE_CFLAGS_RELEASE -= -O2
QMAKE_CFLAGS_RELEASE += -O0
# Switch on optimization for debug version
#QMAKE_CXXFLAGS_DEBUG += -O2
#QMAKE_CFLAGS_DEBUG += -O2
DEFINES *= WINDOWS_SYS
PRE_TARGETDEPS += C:\Development\Rs\v0.5-new_cache_system\libretroshare\libretroshare-build-desktop\lib\libretroshare.a
LIBS += C:\Development\Rs\v0.5-new_cache_system\libretroshare\libretroshare-build-desktop\lib\libretroshare.a
LIBS += -L"../lib"
LIBS += -lssl -lcrypto -lgpgme -lpthreadGC2d -lminiupnpc -lz
# added after bitdht
# LIBS += -lws2_32
LIBS += -luuid -lole32 -liphlpapi -lcrypt32-cygwin -lgdi32
LIBS += -lole32 -lwinmm
# export symbols for the plugins
#LIBS += -Wl,--export-all-symbols,--out-implib,lib/libretroshare-gui.a
GPG_ERROR_DIR = ../../../../libgpg-error-1.7
GPGME_DIR = ../../../../gpgme-1.1.8
GPG_ERROR_DIR = ../../../../lib/libgpg-error-1.7
GPGME_DIR = ../../../../lib/gpgme-1.1.8
INCLUDEPATH += . $${GPGME_DIR}/src $${GPG_ERROR_DIR}/src ../../Libraries/sqlite/sqlite-autoconf-3070900
LIBS += C:\Development\Libraries\sqlite\sqlite-autoconf-3070900\.libs\libsqlite3.a
}
win32 {
# must be added after bitdht
LIBS += -lws2_32
}
SOURCES += \
support.cc \
#rsnxsitems_test.cc
rsdataservice_test.cc \
data_support.cc
#rsnxsservice_test.cc \
#nxstesthub.cc
#rsgxsdata_test.cc
HEADERS += support.h \
#rsnxsitems_test.h
rsdataservice_test.h \
data_support.h
#rsnxsservice_test.h \
#nxstesthub.h
INCLUDEPATH += C:\Development\Rs\v0.5-new_cache_system\libretroshare\src

View file

@ -0,0 +1,351 @@
#include "support.h"
#include "data_support.h"
#include "rsdataservice_test.h"
#include "gxs/rsdataservice.h"
#define DATA_BASE_NAME "msg_grp_Store"
INITTEST();
RsGeneralDataService* dStore = NULL;
void setUp();
void tearDown();
int main()
{
std::cerr << "RsDataService Tests" << std::endl;
test_groupStoreAndRetrieve(); REPORT("test_groupStoreAndRetrieve");
test_messageStoresAndRetrieve(); REPORT("test_messageStoresAndRetrieve");
FINALREPORT("RsDataService Tests");
return TESTRESULT();
}
/*!
* All memory is disposed off, good for looking
* for memory leaks
*/
void test_groupStoreAndRetrieve(){
setUp();
int nGrp = rand()%32;
std::map<RsNxsGrp*, RsGxsGrpMetaData*> grps;
RsNxsGrp* grp;
RsGxsGrpMetaData* grpMeta;
for(int i = 0; i < nGrp; i++){
std::pair<RsNxsGrp*, RsGxsGrpMetaData*> p;
grp = new RsNxsGrp(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
grpMeta = new RsGxsGrpMetaData();
p.first = grp;
p.second = grpMeta;
init_item(*grp);
init_item(grpMeta);
grpMeta->mGroupId = grp->grpId;
grps.insert(p);
grpMeta = NULL;
grp = NULL;
}
dStore->storeGroup(grps);
std::map<std::string, RsNxsGrp*> gR;
std::map<std::string, RsGxsGrpMetaData*> grpMetaR;
dStore->retrieveNxsGrps(gR, false);
dStore->retrieveGxsGrpMetaData(grpMetaR);
std::map<RsNxsGrp*, RsGxsGrpMetaData*>::iterator mit = grps.begin();
bool grpMatch = true, grpMetaMatch = true;
for(; mit != grps.end(); mit++)
{
const std::string grpId = mit->first->grpId;
// check if it exists
if(gR.find(grpId) == gR.end()) {
grpMatch = false;
break;
}
RsNxsGrp *l = mit->first,
*r = gR[grpId];
// assign transaction number
// to right to as tn is not stored
// in db
r->transactionNumber = l->transactionNumber;
// then do a comparison
if(!( *l == *r)) {
grpMatch = false;
break;
}
// now do a comparison of grp meta types
if(grpMetaR.find(grpId) == grpMetaR.end())
{
grpMetaMatch = false;
break;
}
RsGxsGrpMetaData *l_Meta = mit->second,
*r_Meta = grpMetaR[grpId];
if(!(*l_Meta == *r_Meta))
{
grpMetaMatch = false;
break;
}
/* release resources */
delete l_Meta;
delete r_Meta;
delete l;
delete r;
remove(grpId.c_str());
}
grpMetaR.clear();
CHECK(grpMatch);
tearDown();
}
/*!
* Test for both selective and
* bulk msg retrieval
*/
void test_messageStoresAndRetrieve()
{
setUp();
// first create a grpId
std::string grpId0, grpId1;
randString(SHORT_STR, grpId0);
randString(SHORT_STR, grpId1);
std::vector<std::string> grpV; // stores grpIds of all msgs stored and retrieved
grpV.push_back(grpId0);
grpV.push_back(grpId1);
std::map<RsNxsMsg*, RsGxsMsgMetaData*> msgs;
RsNxsMsg* msg = NULL;
RsGxsMsgMetaData* msgMeta = NULL;
int nMsgs = rand()%120;
GxsMsgReq req;
std::map<std::string, RsNxsMsg*> VergrpId0, VergrpId1;
std::map<std::string, RsGxsMsgMetaData*> VerMetagrpId0, VerMetagrpId1;
for(int i=0; i<nMsgs; i++)
{
msg = new RsNxsMsg(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
msgMeta = new RsGxsMsgMetaData();
init_item(*msg);
init_item(msgMeta);
std::pair<RsNxsMsg*, RsGxsMsgMetaData*> p(msg, msgMeta);
int chosen = 0;
if(rand()%50 > 24){
chosen = 1;
}
const std::string& grpId = grpV[chosen];
if(chosen)
req[grpId].insert(msg->msgId);
msgMeta->mMsgId = msg->msgId;
msgMeta->mGroupId = msg->grpId = grpId;
// store msgs in map to use for verification
std::pair<std::string, RsNxsMsg*> vP(msg->msgId, msg);
std::pair<std::string, RsGxsMsgMetaData*> vPmeta(msg->msgId, msgMeta);
if(!chosen)
{
VergrpId0.insert(vP);
VerMetagrpId0.insert(vPmeta);
}
else
{
VergrpId1.insert(vP);
VerMetagrpId0.insert(vPmeta);
}
msg = NULL;
msgMeta = NULL;
msgs.insert(p);
}
req[grpV[0]] = std::set<std::string>(); // assign empty list for other
dStore->storeMessage(msgs);
// now retrieve msgs for comparison
// first selective retrieval
GxsMsgResult msgResult;
GxsMsgMetaResult msgMetaResult;
dStore->retrieveNxsMsgs(req, msgResult, false);
dStore->retrieveGxsMsgMetaData(grpV, msgMetaResult);
// now look at result for grpId 1
std::vector<RsNxsMsg*>& result0 = msgResult[grpId0];
std::vector<RsNxsMsg*>& result1 = msgResult[grpId1];
std::vector<RsGxsMsgMetaData*>& resultMeta0 = msgMetaResult[grpId0];
std::vector<RsGxsMsgMetaData*>& resultMeta1 = msgMetaResult[grpId1];
bool msgGrpId0_Match = true, msgGrpId1_Match = true;
bool msgMetaGrpId0_Match = true, msgMetaGrpId1_Match = true;
// MSG test, selective retrieval
for(std::vector<RsNxsMsg*>::size_type i = 0; i < result0.size(); i++)
{
RsNxsMsg* l = result0[i] ;
if(VergrpId0.find(l->msgId) == VergrpId0.end())
{
msgGrpId0_Match = false;
break;
}
RsNxsMsg* r = VergrpId0[l->msgId];
r->transactionNumber = l->transactionNumber;
if(!(*l == *r))
{
msgGrpId0_Match = false;
break;
}
}
CHECK(msgGrpId0_Match);
// META test
for(std::vector<RsGxsMsgMetaData*>::size_type i = 0; i < resultMeta0.size(); i++)
{
RsGxsMsgMetaData* l = resultMeta0[i] ;
if(VerMetagrpId0.find(l->mMsgId) == VerMetagrpId0.end())
{
msgMetaGrpId0_Match = false;
break;
}
RsGxsMsgMetaData* r = VerMetagrpId0[l->mMsgId];
if(!(*l == *r))
{
msgMetaGrpId0_Match = false;
break;
}
}
CHECK(msgMetaGrpId0_Match);
// MSG test, bulk retrieval
for(std::vector<RsNxsMsg*>::size_type i = 0; i < result1.size(); i++)
{
RsNxsMsg* l = result1[i] ;
if(VergrpId1.find(l->msgId) == VergrpId1.end())
{
msgGrpId1_Match = false;
break;
}
RsNxsMsg* r = VergrpId1[l->msgId];
r->transactionNumber = l->transactionNumber;
if(!(*l == *r))
{
msgGrpId1_Match = false;
break;
}
}
CHECK(msgGrpId1_Match);
//dStore->retrieveGxsMsgMetaData();
std::string msgFile = grpId0 + "-msgs";
remove(msgFile.c_str());
msgFile = grpId1 + "-msgs";
remove(msgFile.c_str());
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: ");
}
}
bool operator ==(const RsGxsGrpMetaData& l, const RsGxsGrpMetaData& r)
{
if(!(l.adminSign == r.adminSign)) return false;
if(!(l.idSign == r.idSign)) return false;
if(!(l.keys == r.keys)) return false;
if(l.mGroupFlags != r.mGroupFlags) return false;
if(l.mPublishTs != r.mPublishTs) return false;
if(l.mAuthorId != r.mAuthorId) return false;
if(l.mGroupName != r.mGroupName) return false;
if(l.mGroupId != r.mGroupId) return false;
if(l.mGroupStatus != r.mGroupStatus) return false;
if(l.mPop != r.mPop) return false;
if(l.mMsgCount != r.mMsgCount) return false;
if(l.mSubscribeFlags != r.mSubscribeFlags) return false;
return true;
}
bool operator ==(const RsGxsMsgMetaData& l, const RsGxsMsgMetaData& r)
{
if(!(l.idSign == r.idSign)) return false;
if(!(l.pubSign == r.pubSign)) return false;
if(l.mGroupId != r.mGroupId) return false;
if(l.mAuthorId != r.mAuthorId) return false;
if(l.mParentId != r.mParentId) return false;
if(l.mOrigMsgId != r.mOrigMsgId) return false;
if(l.mThreadId != r.mThreadId) return false;
if(l.mMsgId != r.mMsgId) return false;
if(l.mMsgName != r.mMsgName) return false;
if(l.mPublishTs != r.mPublishTs) return false;
if(l.mMsgFlags != r.mMsgFlags) return false;
return true;
}

View file

@ -0,0 +1,33 @@
#ifndef RSDATASERVICE_TEST_H
#define RSDATASERVICE_TEST_H
#include "util/rsthreads.h"
#include "serialiser/rsnxsitems.h"
#include "gxs/rsgds.h"
void test_messageStoresAndRetrieve();
void test_groupStoreAndRetrieve();
void test_storeAndDeleteGroup();
void test_storeAndDeleteMessage();
void test_searchMsg();
void test_searchGrp();
bool operator ==(const RsGxsGrpMetaData& l, const RsGxsGrpMetaData& r);
bool operator ==(const RsGxsMsgMetaData& l, const RsGxsMsgMetaData& r);
void test_multiThreaded();
class DataReadWrite : RsThread
{
};
void test_cacheSize();
#endif // RSDATASERVICE_TEST_H

View file

@ -0,0 +1,80 @@
#include "support.h"
#include "data_support.h"
#include "gxs/rsgxsdata.h"
#include "util/utest.h"
INITTEST();
bool operator ==(const RsGxsGrpMetaData& l, const RsGxsGrpMetaData& r);
bool operator ==(const RsGxsMsgMetaData& l, const RsGxsMsgMetaData& r);
int main()
{
RsGxsGrpMetaData grpMeta1, grpMeta2;
RsGxsMsgMetaData msgMeta1, msgMeta2;
grpMeta1.clear();
init_item(&grpMeta1);
msgMeta1.clear();
init_item(&msgMeta1);
uint32_t pktsize = grpMeta1.serial_size();
char grp_data[pktsize];
bool ok = true;
ok &= grpMeta1.serialise(grp_data, pktsize);
grpMeta2.clear();
ok &= grpMeta2.deserialise(grp_data, pktsize);
CHECK(grpMeta1 == grpMeta2);
pktsize = msgMeta1.serial_size();
char msg_data[pktsize];
ok &= msgMeta1.serialise(msg_data, &pktsize);
msgMeta2.clear();
ok &= msgMeta2.deserialise(msg_data, &pktsize);
CHECK(msgMeta1 == msgMeta2);
FINALREPORT("GxsMeta Data Test");
return TESTRESULT();
}
bool operator ==(const RsGxsGrpMetaData& l, const RsGxsGrpMetaData& r)
{
if(!(l.adminSign == r.adminSign)) return false;
if(!(l.idSign == r.idSign)) return false;
if(!(l.keys == r.keys)) return false;
if(l.mGroupFlags != r.mGroupFlags) return false;
if(l.mPublishTs != r.mPublishTs) return false;
if(l.mAuthorId != r.mAuthorId) return false;
if(l.mGroupName != r.mGroupName) return false;
if(l.mGroupId != r.mGroupId) return false;
return true;
}
bool operator ==(const RsGxsMsgMetaData& l, const RsGxsMsgMetaData& r)
{
if(!(l.idSign == r.idSign)) return false;
if(!(l.pubSign == r.pubSign)) return false;
if(l.mGroupId != r.mGroupId) return false;
if(l.mAuthorId != r.mAuthorId) return false;
if(l.mParentId != r.mParentId) return false;
if(l.mOrigMsgId != r.mOrigMsgId) return false;
if(l.mThreadId != r.mThreadId) return false;
if(l.mMsgId != r.mMsgId) return false;
if(l.mMsgName != r.mMsgName) return false;
if(l.mPublishTs != r.mPublishTs) return false;
if(l.mMsgFlags != r.mMsgFlags) return false;
return true;
}

View file

@ -0,0 +1,36 @@
/*
* rsgxsnetservice_test.cc
*
* Created on: 11 Jul 2012
* Author: crispy
*/
#include "util/utest.h"
#include "nxstesthub.h"
#include "nxstestscenario.h"
INITTEST();
int main()
{
// first setup
NxsMessageTest msgTest(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
NxsTestHub hub(&msgTest);
// now get things started
createThread(hub);
// put this thread to sleep for 10 secs
sleep(10);
hub.join();
CHECK(hub.testsPassed());
hub.cleanUp();
FINALREPORT("RsGxsNetService Tests");
return TESTRESULT();
}

View file

@ -0,0 +1,303 @@
/*
* 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;
}
void init_item(RsTlvSecurityKeySet& ks)
{
int n = rand()%24;
randString(SHORT_STR, ks.groupId);
for(int i=1; i<n; i++)
{
std::string a_str;
randString(SHORT_STR, a_str);
RsTlvSecurityKey& a_key = ks.keys[a_str];
init_item(a_key);
a_key.keyId = a_str;
}
}
bool operator==(const RsTlvSecurityKeySet& l, const RsTlvSecurityKeySet& r)
{
if(l.groupId != r.groupId) return false;
std::map<std::string, RsTlvSecurityKey>::const_iterator l_cit = l.keys.begin(),
r_cit = r.keys.begin();
for(; l_cit != l.keys.end(); l_cit++, r_cit++){
if(l_cit->first != r_cit->first) return false;
if(!(l_cit->second == r_cit->second)) return false;
}
return true;
}
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;
}

View file

@ -0,0 +1,224 @@
#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&);
void init_item(RsTlvSecurityKeySet& );
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& );
bool operator==(const RsTlvSecurityKeySet& , const RsTlvSecurityKeySet& );
/*!
* 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_ */

View file

@ -0,0 +1,187 @@
#include "support.h"
#include "rsnxsitems_test.h"
INITTEST();
#define NUM_BIN_OBJECTS 5
#define NUM_SYNC_MSGS 8
#define NUM_SYNC_GRPS 5
RsSerialType* init_item(RsNxsGrp& nxg)
{
nxg.clear();
randString(SHORT_STR, nxg.grpId);
nxg.transactionNumber = rand()%23;
init_item(nxg.grp);
init_item(nxg.meta);
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
}
RsSerialType* init_item(RsNxsMsg& nxm)
{
nxm.clear();
randString(SHORT_STR, nxm.msgId);
randString(SHORT_STR, nxm.grpId);
init_item(nxm.msg);
init_item(nxm.meta);
nxm.transactionNumber = rand()%23;
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
}
RsSerialType* init_item(RsNxsSyncGrp& rsg)
{
rsg.clear();
rsg.flag = RsNxsSyncGrp::FLAG_USE_SYNC_HASH;
rsg.syncAge = rand()%2423;
randString(3124,rsg.syncHash);
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
}
RsSerialType* init_item(RsNxsSyncMsg& rsgm)
{
rsgm.clear();
rsgm.flag = RsNxsSyncMsg::FLAG_USE_SYNC_HASH;
rsgm.syncAge = rand()%24232;
rsgm.transactionNumber = rand()%23;
randString(SHORT_STR, rsgm.grpId);
randString(SHORT_STR, rsgm.syncHash);
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
}
RsSerialType* init_item(RsNxsSyncGrpItem& rsgl)
{
rsgl.clear();
rsgl.flag = RsNxsSyncGrpItem::FLAG_RESPONSE;
rsgl.transactionNumber = rand()%23;
rsgl.publishTs = rand()%23;
randString(SHORT_STR, rsgl.grpId);
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
}
RsSerialType* init_item(RsNxsSyncMsgItem& rsgml)
{
rsgml.clear();
rsgml.flag = RsNxsSyncGrpItem::FLAG_RESPONSE;
rsgml.transactionNumber = rand()%23;
randString(SHORT_STR, rsgml.grpId);
randString(SHORT_STR, rsgml.msgId);
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
}
RsSerialType* init_item(RsNxsTransac& rstx){
rstx.clear();
rstx.timestamp = rand()%14141;
rstx.transactFlag = rand()%2424;
rstx.nItems = rand()%33132;
rstx.transactionNumber = rand()%242112;
return new RsNxsSerialiser(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
}
bool operator==(const RsNxsGrp& l, const RsNxsGrp& r){
if(l.grpId != r.grpId) return false;
if(!(l.grp == r.grp) ) return false;
if(!(l.meta == r.meta) ) return false;
if(l.transactionNumber != r.transactionNumber) 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.msg == r.msg) ) return false;
if(! (l.meta == r.meta) ) return false;
if(l.transactionNumber != r.transactionNumber) return false;
return true;
}
bool operator==(const RsNxsSyncGrp& l, const RsNxsSyncGrp& r)
{
if(l.syncHash != r.syncHash) return false;
if(l.flag != r.flag) return false;
if(l.syncAge != r.syncAge) return false;
if(l.transactionNumber != r.transactionNumber) return false;
return true;
}
bool operator==(const RsNxsSyncMsg& l, const RsNxsSyncMsg& r)
{
if(l.flag != r.flag) return false;
if(l.syncAge != r.syncAge) return false;
if(l.syncHash != r.syncHash) return false;
if(l.grpId != r.grpId) return false;
if(l.transactionNumber != r.transactionNumber) return false;
return true;
}
bool operator==(const RsNxsSyncGrpItem& l, const RsNxsSyncGrpItem& r)
{
if(l.flag != r.flag) return false;
if(l.publishTs != r.publishTs) return false;
if(l.grpId != r.grpId) return false;
if(l.transactionNumber != r.transactionNumber) return false;
return true;
}
bool operator==(const RsNxsSyncMsgItem& l, const RsNxsSyncMsgItem& r)
{
if(l.flag != r.flag) return false;
if(l.grpId != r.grpId) return false;
if(l.msgId != r.msgId) return false;
if(l.transactionNumber != r.transactionNumber) return false;
return true;
}
bool operator==(const RsNxsTransac& l, const RsNxsTransac& r){
if(l.transactFlag != r.transactFlag) return false;
if(l.transactionNumber != r.transactionNumber) return false;
if(l.timestamp != r.timestamp) return false;
if(l.nItems != r.nItems) return false;
return true;
}
int main()
{
std::cerr << "RsNxsItem Tests" << std::endl;
test_RsItem<RsNxsGrp>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsGrpResp");
test_RsItem<RsNxsMsg>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsGrpMsgResp");
test_RsItem<RsNxsSyncGrp>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsNxsSyncGrp");
test_RsItem<RsNxsSyncMsg>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsNxsSyncMsg");
test_RsItem<RsNxsSyncGrpItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsNxsSyncGrpItem");
test_RsItem<RsNxsSyncMsgItem>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsNxsSyncMsgItem");
test_RsItem<RsNxsTransac>(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); REPORT("Serialise/Deserialise RsNxsTransac");
FINALREPORT("RsNxsItem Tests");
return TESTRESULT();
}

View file

@ -0,0 +1,24 @@
#ifndef RSNXSITEMS_TEST_H
#define RSNXSITEMS_TEST_H
#include "serialiser/rsnxsitems.h"
RsSerialType* init_item(RsNxsGrp&);
RsSerialType* init_item(RsNxsMsg&);
RsSerialType* init_item(RsNxsSyncGrp&);
RsSerialType* init_item(RsNxsSyncMsg&);
RsSerialType* init_item(RsNxsSyncGrpItem&);
RsSerialType* init_item(RsNxsSyncMsgItem&);
RsSerialType* init_item(RsNxsTransac& );
bool operator==(const RsNxsGrp&, const RsNxsGrp&);
bool operator==(const RsNxsMsg&, const RsNxsMsg&);
bool operator==(const RsNxsSyncGrp&, const RsNxsSyncGrp&);
bool operator==(const RsNxsSyncMsg&, const RsNxsSyncMsg&);
bool operator==(const RsNxsSyncGrpItem&, const RsNxsSyncGrpItem&);
bool operator==(const RsNxsSyncMsgItem&, const RsNxsSyncMsgItem&);
bool operator==(const RsNxsTransac&, const RsNxsTransac& );
#endif // RSNXSITEMS_TEST_H

View file

@ -223,6 +223,13 @@ void init_item(RsTlvFileItem& fi)
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);

View file

@ -157,5 +157,66 @@ template<class T> int test_RsItem()
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_ */

View file

@ -0,0 +1,374 @@
#include <memory.h>
#include "retrodb.h"
#include "utest.h"
bool operator==(const ContentValue& lCV, ContentValue& rCV){
std::map<std::string, uint8_t> leftKtMap, rightKtMap;
lCV.getKeyTypeMap(leftKtMap);
rCV.getKeyTypeMap(rightKtMap);
return (leftKtMap == rightKtMap);
}
/*!
* Test content value ability to take a set of data and ability to get it out
* For all data types
*/
void testEnterAndRetrieve();
/*!
* Check to see if copy constructor intialises
* 'this' correctly
*/
void testCopyConstructor();
/*!
* check that key type map returned is consistent
* with data contained in ContentValue
*/
void testGetKeyTypeMap();
/*!
* Test the clearing functionality
*/
void testClear();
/*!
* check errors are meaningful
*/
void testErrors();
/*!
* enter the same key twice and ensure previous data gets overwritten
*
*/
void testSameKey();
INITTEST();
int main(){
testEnterAndRetrieve();
testCopyConstructor();
testClear();
testSameKey();
testGetKeyTypeMap();
testErrors();
FINALREPORT("TEST_CONTENT_VALUE");
}
void testSameKey(){
ContentValue cv;
// test data
std::string src = "adalkjalfalfalfkal";
const char* data = src.data();
uint32_t data_len = src.length();
std::string data_key = "private_key";
cv.put(data_key, data_len, data);
std::string other_src = "daldko5202402224";
data_len = other_src.length();
data = other_src.data();
cv.put(data_key, data_len, data);
uint32_t val_len;
char* val;
cv.getAsData(data_key, val_len, val);
std::string str_val(val, val_len);
CHECK(str_val == other_src);
// now check string
std::string key = "peer";
cv.put(key, std::string("sexy_girl"));
cv.put(key, std::string("manly man"));
std::string val_str;
cv.getAsString(key, val_str);
CHECK(val_str == "manly man");
// and double
cv.put(key, 4.);
cv.put(key, 32.);
double val_d;
cv.getAsDouble(key, val_d);
CHECK(val_d == 32.);
// and int64
int64_t large(20420492040123);
cv.put(key, large);
cv.put(key, large+34);
int64_t val_i64;
cv.getAsInt64(key, val_i64);
CHECK(val_i64 == large+34);
// and bool
cv.put(key, false);
cv.put(key, true);
bool bool_val = false;
cv.getAsBool(key, bool_val);
CHECK(bool_val == true);
// and int32
int32_t medium = 20432123;
cv.put(key, medium);
cv.put(key, medium+34);
int32_t val_i32;
cv.getAsInt32(key, val_i32);
CHECK(val_i32 == medium+34);
REPORT("testSameKey()");
}
void testErrors(){
ContentValue cv;
int32_t val_32;
int64_t val_64;
char* data;
uint32_t data_len;
std::string val_str;
bool val_bool;
double val_d;
CHECK(!cv.getAsInt32("dda", val_32));
CHECK(!cv.getAsInt64("dda", val_64));
CHECK(!cv.getAsData("ds", data_len, data));
CHECK(!cv.getAsString("d3536356336356356s", val_str));
CHECK(!cv.getAsBool("d424s", val_bool));
CHECK(!cv.getAsDouble("daads", val_d));
REPORT("testErrors()");
}
void testEnterAndRetrieve(){
// INT 32
int32_t value32 = 1, retval32;
std::string key = "one";
ContentValue cv;
cv.put(key, value32);
cv.getAsInt32(key, retval32);
CHECK(value32 == retval32);
// INT 64
int64_t value64 = 423425242, retval64;
key = "int64";
cv.put(key, value64);
cv.getAsInt64(key, retval64);
CHECK(value64 == retval64);
// Double
double dvalue = 3.5, retvaldbl;
key = "double";
cv.put(key, dvalue);
cv.getAsDouble(key, retvaldbl);
CHECK(dvalue == retvaldbl );
// BLOB
uint32_t data_len = 45, get_len = 0;
char* src = new char[data_len];
char* get_src = NULL;
memset(src, '$', data_len);
key = "data";
cv.put(key, data_len, src);
cv.getAsData(key, get_len, get_src);
bool fine = true;
CHECK(get_len = data_len);
if(data_len == get_len){
for(int i=0; i < data_len; i++){
if(src[i] != get_src[i])
fine &= false;
}
}
delete[] src;
CHECK(fine);
// STRING
std::string strVal = "whoo", getVal("");
key = "string";
cv.put(key, strVal);
cv.getAsString(key, getVal);
CHECK(getVal == strVal);
// BOOL
bool mefalse = false, retvalBool;
key = "bool";
cv.put(key, mefalse);
cv.getAsBool(key, retvalBool);
CHECK(mefalse == retvalBool);
cv.clear();
REPORT("testEnterAndRetrieve()");
}
void testGetKeyTypeMap(){
ContentValue cv;
std::string key1="key1", key2="key2", key3="key3", key4="key4";
std::string key1_val;
int32_t key2_val = 42;
double key3_val = 23;
int64_t key4_val = 42052094224;
cv.put(key1, key1_val);
cv.put(key2, key2_val);
cv.put(key3, key3_val);
cv.put(key4, key4_val);
std::map<std::string, uint8_t> kvMap;
cv.getKeyTypeMap(kvMap);
CHECK(kvMap.size() == 4);
CHECK(kvMap[key1] == ContentValue::STRING_TYPE);
CHECK(kvMap[key2] == ContentValue::INT32_TYPE);
CHECK(kvMap[key3] == ContentValue::DOUBLE_TYPE);
CHECK(kvMap[key4] == ContentValue::INT64_TYPE);
REPORT("testGetKeyTypeMap()");
}
void testCopyConstructor(){
ContentValue cv1;
// INT 32
int value32 = 1;
std::string key = "one";
cv1.put(key, value32);
// INT 64
int64_t value64 = 423425242;
key = "int64";
cv1.put(key, value64);
// Double
double dvalue = 3.5;
key = "double";
cv1.put(key, dvalue);
// BLOB
uint32_t data_len = 45;
char* src = new char[data_len];
memset(src, '$', data_len);
key = "data";
cv1.put(key, data_len, src);
delete[] src;
// STRING
std::string strVal = "whoo";
key = "string";
cv1.put(key, strVal);
// BOOL
bool mefalse = false;
key = "bool";
cv1.put(key, mefalse);
ContentValue cv2(cv1);
CHECK(cv1 == cv2);
cv1.clear();
cv2.clear();
REPORT("testCopyConstructor()");
}
void testClear(){
ContentValue cv1;
// INT 32
int value32 = 1;
std::string key = "one";
cv1.put(key, value32);
// INT 64
int64_t value64 = 423425242;
key = "int64";
cv1.put(key, value64);
// Double
double dvalue = 3.5;
key = "double";
cv1.put(key, dvalue);
// BLOB
uint32_t data_len = 45;
char* src = new char[data_len];
memset(src, '$', data_len);
key = "data";
cv1.put(key, data_len, src);
delete[] src;
// STRING
std::string strVal = "whoo";
key = "string";
cv1.put(key, strVal);
// BOOL
bool mefalse = false;
key = "bool";
cv1.put(key, mefalse);
std::map<std::string, uint8_t> ktMap;
cv1.getKeyTypeMap(ktMap);
CHECK(ktMap.size() > 0);
cv1.clear();
cv1.getKeyTypeMap(ktMap);
CHECK(ktMap.size() == 0);
REPORT("testClear()");
}

View file

@ -0,0 +1,127 @@
#include <iostream>
#include <memory.h>
#include <sstream>
#include <time.h>
#include "retrodb.h"
#include "utest.h"
#define INT32_KEY "day"
#define INT64_KEY "pub_key"
#define DATA_KEY "data"
#define DOUBLE_KEY "a_double"
#define STRING_KEY "a_string"
#define BOOL_KEY "a_bool"
#define DB_FILE_NAME "RetroDb"
static RetroDb* mDb = NULL;
void createRetroDb();
void destroyRetroDb();
INITTEST();
// mainly test ability to move up and down result set
void testTraverseResult();
int main() {
testTraverseResult();
FINALREPORT("RETRO CURSOR TEST");
return 0;
}
void createRetroDb(){
if(mDb)
destroyRetroDb();
remove(DB_FILE_NAME); // account for interrupted tests
mDb = new RetroDb(DB_FILE_NAME, RetroDb::OPEN_READWRITE_CREATE);
}
void destroyRetroDb(){
if(mDb == NULL)
return;
mDb->closeDb();
delete mDb;
mDb = NULL;
int rc = remove(DB_FILE_NAME);
std::cerr << "remove code: " << rc << std::endl;
if(rc !=0){
perror("Could not delete db: ");
}
}
void testTraverseResult(){
createRetroDb();
bool statementExecuted = mDb->execSQL("CREATE TABLE retroDB(day INTEGER PRIMARY KEY ASC, pub_key INT, data BLOB, a_double REAL, a_string VARCHAR(255), a_bool INT);");
CHECK(statementExecuted);
ContentValue cv;
cv.put(INT32_KEY, (int32_t)20);
int64_t large_num = 32432242344423;
cv.put(INT64_KEY, large_num);
std::string str = "3dajaojaljfacjlaf£%£^%\"%\"%$";
const char* data = str.data();
int size = str.size();
cv.put(DATA_KEY, size, data);
cv.put(DOUBLE_KEY, 3.14);
cv.put(STRING_KEY, "hello precious");
cv.put(BOOL_KEY, false);
bool insertExecuted = mDb->sqlInsert("retroDB", "", cv);
cv.put(INT32_KEY, (int32_t)21);
insertExecuted &= mDb->sqlInsert("retroDB", "", cv);
cv.put(INT32_KEY, (int32_t)2);
insertExecuted &= mDb->sqlInsert("retroDB", "", cv);
cv.put(INT32_KEY, (int32_t)204);
insertExecuted &= mDb->sqlInsert("retroDB", "", cv);
cv.put(INT32_KEY, (int32_t)22);
insertExecuted &= mDb->sqlInsert("retroDB", "", cv);
CHECK(insertExecuted);
std::list<std::string> columns;
columns.push_back(INT32_KEY); columns.push_back(INT64_KEY); columns.push_back(DOUBLE_KEY);
columns.push_back(DATA_KEY); columns.push_back(BOOL_KEY); columns.push_back(STRING_KEY);
std::string orderBy = std::string(INT32_KEY) + " ASC";
RetroCursor* cursor = mDb->sqlQuery("retroDB", columns, "", orderBy);
CHECK(cursor->getResultCount() == 5);
cursor->moveToFirst();
CHECK(cursor->getPosition() == 0);
cursor->moveToLast();
CHECK(cursor->getPosition() == cursor->getResultCount());
cursor->moveToFirst();
CHECK(cursor->getInt32(0) == 2);
cursor->moveToNext();
cursor->moveToNext();
CHECK(cursor->getInt32(0) == 21);
delete cursor;
REPORT("testTraverseResult()");
destroyRetroDb();
}

View file

@ -0,0 +1,352 @@
#include <iostream>
#include <memory.h>
#include <sstream>
#include <time.h>
#include "retrodb.h"
#include "utest.h"
#define DAY_KEY "day"
#define PUB_KEY "pub_key"
#define DATA_KEY "data"
#define DOUBLE_KEY "a_double"
#define DB_FILE_NAME "RetroDb"
static RetroDb* mDb = NULL;
void createRetroDb();
void destroyRetroDb();
void testSqlExec();
void testSqlUpdate();
void testSqlInsert();
void testSqlDelete();
void testSqlQuery();
void testBinaryInsertion();
INITTEST();
int main(){
testSqlExec();
testBinaryInsertion();
testSqlInsert();
testSqlUpdate();
testSqlDelete();
testSqlQuery();
FINALREPORT("RETRO DB TEST");
return 0;
}
void createRetroDb(){
if(mDb)
destroyRetroDb();
remove(DB_FILE_NAME); // account for interrupted tests
mDb = new RetroDb(DB_FILE_NAME, RetroDb::OPEN_READWRITE_CREATE);
}
void destroyRetroDb(){
if(mDb == NULL)
return;
mDb->closeDb();
delete mDb;
mDb = NULL;
int rc = remove(DB_FILE_NAME);
std::cerr << "remove code: " << rc << std::endl;
if(rc !=0){
perror("Could not delete db: ");
}
}
void testSqlExec(){
createRetroDb();
// create simple table
bool statementExecuted = mDb->execSQL("CREATE TABLE retroDB(day INTEGER PRIMARY KEY ASC, pub_key, data);");
statementExecuted &= mDb->execSQL("INSERT INTO retroDB(day, pub_key, data) VALUES(1,2,3);");
statementExecuted &= mDb->execSQL("INSERT INTO retroDB(day, pub_key, data) VALUES(3,4525624,4524);");
CHECK(statementExecuted);
// now check if you can retrieve records
std::list<std::string> columns;
columns.push_back("day");
columns.push_back("pub_key");
columns.push_back("data");
std::string selection, orderBy;
RetroCursor* c = mDb->sqlQuery("retroDB", columns, selection, orderBy);
CHECK(c->getResultCount() == 2);
// got to first record
c->moveToFirst();
int32_t first =c->getInt32(0), second = c->getInt32(1),
third = c->getInt32(2);
CHECK(first == 1);
CHECK(second == 2);
CHECK(third == 3);
// get 2nd record
c->moveToNext();
first =c->getInt32(0), second = c->getInt32(1),
third = c->getInt32(2);
CHECK(first == 3);
CHECK(second == 4525624);
CHECK(third == 4524);
delete c;
REPORT("testSqlExec()");
destroyRetroDb();
}
void testBinaryInsertion(){
createRetroDb();
// create simple table
bool statementExecuted = mDb->execSQL("CREATE TABLE retroDB(day INTEGER PRIMARY KEY ASC, data BLOB);");
statementExecuted &= mDb->execSQL("INSERT INTO retroDB(day, data) VALUES(1, 'dafadfad%$£%^£%%\"$R\"$\"$\"');");
// now check if you can retrieve records
std::list<std::string> columns;
columns.push_back("day");
columns.push_back("data");
std::string selection, orderBy;
RetroCursor* c = mDb->sqlQuery("retroDB", columns, selection, orderBy);
c->moveToFirst();
int first = c->getInt32(0);
uint32_t size;
const char* data = (const char*)c->getData(1, size);
std::string str = "dafadfad%$£%^£%%\"$R\"$\"$\"";
const char* data_comp = str.data();
bool binCompare = ok;
for(int i=0; i < 24 ; i++)
binCompare &= data[i] == data_comp[i];
CHECK(first == 1);
CHECK(binCompare);
delete c;
REPORT("testBinaryInsertion()");
destroyRetroDb();
}
void testSqlUpdate(){
createRetroDb();
bool statementExecuted = mDb->execSQL("CREATE TABLE retroDB(day INTEGER PRIMARY KEY ASC, data BLOB, peerId VARCHAR(255), time INT);");
CHECK(statementExecuted);
std::string data = "dadJOOodaodaoro20r2-0r20002ri02fgi3t0***";
ContentValue cv;
cv.put("day", (int32_t)20);
std::string peerid = "TheRetroSquad";
cv.put("peerId", peerid);
cv.put("data", data.size(), data.data());
int64_t now = time(NULL);
cv.put("time", now);
bool insertExecuted = mDb->sqlInsert("retroDB", "", cv);
CHECK(insertExecuted);
// now check entry is fine
std::list<std::string> columns;
columns.push_back("day"); columns.push_back("peerId"); columns.push_back("data"); columns.push_back("time");
RetroCursor* c = mDb->sqlQuery("retroDB", columns, "", "");
CHECK(c->getResultCount() == 1);
std::string result;
c->moveToFirst();
c->getString(1, result);
CHECK(result == peerid);
delete c;
c = NULL;
// now make an update and see if this is reflected
int64_t now_plus = now+203;
cv.put("time", now_plus);
bool update = mDb->sqlUpdate("retroDB", "", cv);
CHECK(update);
c = mDb->sqlQuery("retroDB", columns, "", "");
c->moveToFirst();
int64_t now_plus_compare = c->getDouble(3);
CHECK(now_plus_compare == now_plus);
// now attempt an update which should find no valid record
delete c;
REPORT("testSqlUpdate()");
destroyRetroDb();
}
void testSqlInsert(){
createRetroDb();
bool statementExecuted = mDb->execSQL("CREATE TABLE retroDB(day INTEGER PRIMARY KEY ASC, a_double DOUBLE, data BLOB);");
CHECK(statementExecuted);
ContentValue cv;
cv.put("day", (int32_t)20);
std::string str = "3dajaojaljfacjlaf£%£^%\"%\"%$";
const char* data = str.data();
int size = 27;
cv.put(DATA_KEY, size, data);
cv.put(DOUBLE_KEY, 3.14);
bool insertExecuted = mDb->sqlInsert("retroDB", "", cv);
std::list<std::string> columns;
columns.push_back("day"); columns.push_back("a_double"); columns.push_back("data");
RetroCursor* cursor = mDb->sqlQuery("retroDB", columns, "", "");
CHECK(cursor != NULL);
cursor->moveToFirst();
CHECK(20 == cursor->getInt32(0));
CHECK(3.14 == cursor->getDouble(1));
CHECK(insertExecuted);
delete cursor;
FINALREPORT("testSqlInsert()");
destroyRetroDb();
}
void testSqlQuery(){
// test ordering of data and selection clause
createRetroDb();
// create simple table
bool statementExecuted = mDb->execSQL("CREATE TABLE retroDB(priority INTEGER PRIMARY KEY ASC, name VARCHAR(255), friends, games INTEGER);");
statementExecuted &= mDb->execSQL("INSERT INTO retroDB(priority, name, friends, games) VALUES(4,'sammy',2,30);");
statementExecuted &= mDb->execSQL("INSERT INTO retroDB(priority, name, friends, games) VALUES(2,'davy',6,9);");
statementExecuted &= mDb->execSQL("INSERT INTO retroDB(priority, name, friends, games) VALUES(6,'pammy',2,4);");
statementExecuted &= mDb->execSQL("INSERT INTO retroDB(priority, name, friends, games) VALUES(5,'tommy',3,4534);");
statementExecuted &= mDb->execSQL("INSERT INTO retroDB(priority, name, friends, games) VALUES(9,'jonny',3,44);");
CHECK(statementExecuted);
std::list<std::string> columns;
columns.push_back("name");
std::string selection = "games <= 31";
std::string orderBy = "priority DESC";
// output should be by name: pammy, sammy and davy
RetroCursor* cursor = mDb->sqlQuery("retroDB", columns,selection, orderBy);
cursor->moveToFirst();
std::string name;
cursor->getString(0,name);
CHECK(name == "pammy");
cursor->moveToNext();
cursor->getString(0,name);
CHECK(name == "sammy");
cursor->moveToNext();
cursor->getString(0,name);
CHECK(name == "davy");
delete cursor;
FINALREPORT("testSqlQuery()");
destroyRetroDb();
return;
}
void testSqlDelete(){
createRetroDb();
bool statementExecuted = mDb->execSQL("CREATE TABLE retroDB(day INTEGER PRIMARY KEY ASC, a_double DOUBLE, data BLOB);");
CHECK(statementExecuted);
ContentValue cv;
cv.put("day", (int32_t)20);
std::string str = "3dajaojaljfacjlaf£%£^%\"%\"%$";
const char* data = str.data();
uint32_t size = str.size();
cv.put(DATA_KEY, size, data);
cv.put(DOUBLE_KEY, 3.14);
// insert to records
bool insertExecuted = mDb->sqlInsert("retroDB", "", cv);
cv.put("day", (int32_t(5)));
CHECK(insertExecuted);
mDb->sqlInsert("retroDB", "", cv);
// now check that their are two records in the db
std::list<std::string> columns;
columns.push_back("day"); columns.push_back("a_double"); columns.push_back("data");
RetroCursor* cursor = mDb->sqlQuery("retroDB", columns, "", "");
CHECK(cursor->getResultCount() == 2);
delete cursor;
// now remove a record and search for the removed record, query should return no records
mDb->sqlDelete("retroDB", "day=5", "");
cursor = mDb->sqlQuery("retroDB", columns, "day=5", "");
CHECK(cursor->getResultCount() == 0);
delete cursor;
// now check for the remaining record
cursor = mDb->sqlQuery("retroDB", columns, "day=20", "");
CHECK(cursor->getResultCount() == 1);
cursor->moveToFirst();
// verify there is no data corruption
const char* data_comp1 = (const char*)cursor->getData(2, size);
const char* data_comp2 = str.data();
bool binCompare = true;
for(int i=0; i < str.size() ; i++)
binCompare &= data_comp1[i] == data_comp2[i];
CHECK(binCompare);
delete cursor;
FINALREPORT("testSqlDelete()");
destroyRetroDb();
}