Added flag for coverage profiling to tests

updated services tests
- added chat and forum test skeletons

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4286 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2011-06-17 20:57:58 +00:00
parent cbb3b4587f
commit 6e633e419a
18 changed files with 295 additions and 435 deletions

View File

@ -1,5 +1,6 @@
RS_TOP_DIR = ../..
DHT_TOP_DIR = ../../../../libbitdht/src
##### Define any flags that are needed for this section #######
###############################################################

View File

@ -1,5 +1,6 @@
RS_TOP_DIR = ../..
DHT_TOP_DIR = ../../../../libbitdht/src
##### Define any flags that are needed for this section #######
###############################################################

View File

@ -21,11 +21,13 @@ CC = g++
RM = /bin/rm
RANLIB = ranlib
LIBDIR = $(RS_TOP_DIR)/lib
BITDIR = $(DHT_TOP_DIR)/lib
LIBRS = $(LIBDIR)/libretroshare.a
BITDHT = $(BITDIR)/libbitdht.a
# Unix: Linux/Cygwin
INCLUDE = -I $(RS_TOP_DIR)
CFLAGS = -Wall -g $(INCLUDE)
CFLAGS = -Wall -g $(INCLUDE)
#CFLAGS += -fprofile-arcs -ftest-coverage
CFLAGS += ${DEFINES}
#ifdef PQI_USE_XPGP
@ -56,7 +58,8 @@ BIOCFLAGS = -I $(SSL_DIR)/include ${DEFINES} -DOPENSSL_THREADS -D_REENTRANT -DD
# OS specific Linking.
#########################################################################
LIBS = -L$(LIBDIR) -lretroshare
LIBS = -lgpgme -L$(LIBDIR) -lretroshare
LIBS += -L$(BITDIR) -lbitdht -lgnome-keyring
ifdef PQI_USE_XPGP
LIBS += -L$(SSL_DIR)
endif
@ -64,7 +67,7 @@ LIBS += -lssl -lcrypto -lpthread
#LIBS += -L$(UPNPC_DIR) -lminiupnpc
LIBS += $(XLIB) -ldl -lz
LIBS += -lupnp
LIBS += -lgpgme
RSLIBS = $(LIBS)

View File

@ -13,7 +13,8 @@ librs: $(RSOBJ)
$(CC) $(CFLAGS) -c $<
clean:
-/bin/rm $(RSOBJ) $(EXECOBJ) $(TESTOBJ)
-/bin/rm -f $(RSOBJ) $(EXECOBJ) $(TESTOBJ) *.gcno *.gcda \
*.gcov *.tstout $(TESTS)
clobber: clean retest
-/bin/rm $(EXEC) $(TESTS)

View File

@ -1,5 +1,7 @@
RS_TOP_DIR = ../..
DHT_TOP_DIR = ../../../../libbitdht/src
##### Define any flags that are needed for this section #######
###############################################################

View File

@ -1,5 +1,6 @@
RS_TOP_DIR = ../..
DHT_TOP_DIR = ../../../../libbitdht/src
##### Define any flags that are needed for this section #######
###############################################################
@ -8,14 +9,20 @@ include $(RS_TOP_DIR)/tests/scripts/config.mk
###############################################################
OBJ += distrib_services.o Service_Test.o
TESTOBJ = servicetest.o forumservicetest.o chatservicetest.o
TESTOBJ += chattest.o distribtest.o
TESTS = distrib_test_main
TESTS = chattest distribtest
all: tests
distrib_test_main: distrib_test_main.o Service_Test.o distrib_services.o
$(CC) $(CFLAGS) -o distrib_test_main distrib_test_main.o $(OBJ) $(LIBS)
distribtest: distribtest.o servicetest.o forumservicetest.o
$(CC) $(CFLAGS) -o distribtest distribtest.o servicetest.o \
forumservicetest.o $(OBJ) $(LIBS)
chattest: chattest.o servicetest.o chatservicetest.o
$(CC) $(CFLAGS) -o chattest chattest.o servicetest.o \
chatservicetest.o $(OBJ) $(LIBS)
###############################################################

View File

@ -1,98 +0,0 @@
/*
* libretroshare/src/tests/services Service_Test.cc
*
* RetroShare Service Testing
*
* Copyright 2010 by Chris 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 "Service_Test.h"
ServiceTestFrame::ServiceTestFrame()
{
}
ServiceTestFrame::~ServiceTestFrame()
{
}
bool ServiceTestFrame::addTest(const std::string& testName, RsServiceTest* st)
{
if((st == NULL) || (testName.empty()))
return false;
serviceTests.insert(std::pair<std::string, RsServiceTest* >(testName, st));
return true;
}
void ServiceTestFrame::BeginTesting()
{
std::cout << "Begining Testing" << std::endl;
return;
}
void ServiceTestFrame::FinishTesting()
{
std::cout << "End of Testing\n Printing Results" << std::endl;
return;
}
/***************************** RsServiceTest *******************/
RsServiceTest::RsServiceTest()
{
}
RsServiceTest::~RsServiceTest()
{
}
void RsServiceTest::result(std::map<std::string, bool>& results){
std::map<std::string, bool>::iterator mit = testResults.begin();
std::cout << "Results of the Test : " << std::endl;
std::string passed("Passed"), failed("Failed");
for(;mit != testResults.end(); mit++){
std::cout << mit->first << mit->second?passed:failed;
// << std::endl;
}
std::cout << "End of Results" << std::endl;
return;
}

View File

@ -1,112 +0,0 @@
/*
* libretroshare/src/tests/services Service_Test.h
*
* RetroShare Service Testing
*
* Copyright 2010 by Chris 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".
*
*/
#ifndef SERVICE_TEST_H_
#define SERVICE_TEST_H_
#include <dbase/cachestrapper.h>
#include <string>
#include <list>
#include <map>
class RsServiceTest;
/*!
* This class deals with actual RsServiceTest objects and the share resources between these objects.
* It has the ability to run the tests
* held by service test objects, and also holds shared resources that are used by the test objects (networking, disk access)
*/
class ServiceTestFrame {
public:
ServiceTestFrame();
~ServiceTestFrame();
/*!
* This adds to the list of test to be done by retroshare
* @testName a name for this test
* @RsServiceTest_Frame a handle to the service test object
*/
bool addTest(const std::string& testName, RsServiceTest* );
/*!
* Begin testing
*/
void BeginTesting();
/*!
* prints out results of tests
*/
void FinishTesting();
private:
std::map<std::string, RsServiceTest* > serviceTests;
/* resources need by the RsServiceTestObjects */
CacheStrapper *cs;
CacheTransfer *cft;
};
/*!
* The aim of this class is form the basis for how services are
* tested
*/
class RsServiceTest {
public:
RsServiceTest();
~RsServiceTest();
/*!
* goes returns the result for given test cases
*/
void result(std::map<std::string, bool>&);
virtual bool setTestCases(std::list<std::string>& ) = 0;
virtual bool runCases(std::list<std::string>&) = 0;
/*!
* This is important for the get functions used by the deriving service
*/
virtual void loadDummyData() = 0;
private:
/// contains the test id to determine which set of tests are to be run
std::list<std::string> testCase;
/// maps to the results of test
std::map<std::string, bool> testResults;
};
#endif /* SERVICE_TEST_H_ */

View File

@ -0,0 +1,22 @@
/*
* chatservicetest.cpp
*
* Created on: 17 Jun 2011
* Author: greyfox
*/
#include "chatservicetest.h"
chatServiceTest::chatServiceTest()
: ServiceTest() {
mChat = new p3ChatService(mConnMgr);
}
chatServiceTest::~chatServiceTest() {
delete mChat;
}
void chatServiceTest::runTests(){
}

View File

@ -0,0 +1,29 @@
/*
* chatservicetest.h
*
* Created on: 17 Jun 2011
* Author: greyfox
*/
#ifndef CHATSERVICETEST_H_
#define CHATSERVICETEST_H_
#include "servicetest.h"
#include "services/p3chatservice.h"
class chatServiceTest: public ServiceTest {
public:
chatServiceTest();
virtual ~chatServiceTest();
public:
void runTests();
private:
p3ChatService* mChat;
};
#endif /* CHATSERVICETEST_H_ */

View File

@ -0,0 +1,14 @@
/*
* chattest.cc
*
* Created on: 17 Jun 2011
* Author: greyfox
*/
#include "chatservicetest.h"
// chat service is tested here
int main(){
return 0;
}

View File

@ -1,182 +0,0 @@
/*
* libretroshare/src/tests/services distrib_services.cc
*
* RetroShare Service Testing
*
* Copyright 2010 by Chris Evi-Parker, 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 <assert.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include <list>
#include <openssl/bio.h>
#include <openssl/crypto.h>
#include <openssl/evp.h>
#include <openssl/x509.h>
#include <openssl/x509v3.h>
/**************** PQI_USE_XPGP ******************/
#if defined(PQI_USE_XPGP)
#include <openssl/xPGP.h>
#else /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/
#endif /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/rand.h>
#include "distrib_services.h"
RsForum_Test::RsForum_Test() :
TEST_CREATE_FORUMS("Test Create Forums")
{
bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
/* enable memory leak checking unless explicitly disabled */
CRYPTO_malloc_debug_init();
CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
SSL_library_init();
SSL_load_error_strings();
forum = NULL;
}
RsForum_Test::~RsForum_Test()
{
/* cleanup */
CRYPTO_cleanup_all_ex_data();
ERR_free_strings();
ERR_remove_state(0);
EVP_cleanup();
//CRYPTO_mem_leaks(bio_err);
if (bio_err != NULL) BIO_free(bio_err);
}
void RsForum_Test::result(std::map<std::string, bool>& results)
{
return;
}
bool RsForum_Test::setTestCases(std::list<std::string>& testCases)
{
return false;
}
bool RsForum_Test::runCases(std::list<std::string>& cases)
{
return false;
}
void RsForum_Test::loadDummyData()
{
return;
}
bool RsForum_Test::testCreateForums()
{
std::string fId1 = forum->createForum(L"Forum 1", L"first forum", RS_DISTRIB_PUBLIC);
forum->tick(); /* expect group publish */
#ifdef WIN32
Sleep(1000);
#else
sleep(1);
#endif
forum->tick();
#ifdef WIN32
Sleep(1000);
#else
sleep(1);
#endif
std::string fId2 = forum->createForum(L"Forum 2", L"next first forum", RS_DISTRIB_PRIVATE);
forum->tick(); /* expect group publish */
#ifdef WIN32
Sleep(1000);
#else
sleep(1);
#endif
forum->tick();
#ifdef WIN32
Sleep(1000);
#else
sleep(1);
#endif
std::string mId1 = forum->createForumMsg(fId2, "", L"Forum 2 Msg 1", L"first forum msg", true);
forum->tick(); /* expect msg publish */
#ifdef WIN32
Sleep(1000);
#else
sleep(1);
#endif
forum->tick();
#ifdef WIN32
Sleep(1000);
#else
sleep(1);
#endif
std::string mId2 = forum->createForumMsg(fId2, "", L"Forum 2 Msg 2", L"second forum msg", false);
forum->tick(); /* expect msg publish */
#ifdef WIN32
Sleep(1000);
#else
sleep(1);
#endif
forum->tick();
#ifdef WIN32
Sleep(1000);
#else
sleep(1);
#endif
return 1 ;
}

View File

@ -3,7 +3,7 @@
*
* RetroShare Service Testing
*
* Copyright 2010 by Chris Evi-Parker.
* Copyright 2011 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
@ -23,16 +23,19 @@
*
*/
#include "forumservicetest.h"
#include "util/utest.h"
#include "distrib_services.h"
INITTEST()
// distrib services are tested here
int main()
{
forumServiceTest forumTest;
forumTest.runTests();
REPORT("Forum Tests");
ServiceTestFrame tf;
RsForum_Test* forum_test = new RsForum_Test();
std::string testName("test1");
tf.addTest(testName, forum_test);
FINALREPORT("Distrib Test");
return 0;
return TESTRESULT();
}

View File

@ -0,0 +1,61 @@
/*
* libretroshare/src/tests/services distrib_services.cc
*
* RetroShare Service Testing
*
* Copyright 2010 by Chris Evi-Parker, 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 "forumservicetest.h"
forumServiceTest::forumServiceTest()
: ServiceTest() {
mForums = NULL;
}
forumServiceTest::~forumServiceTest(){
if(mForums != NULL)
delete mForums;
}
bool forumServiceTest::getForumMsgTest(){
return false;
}
bool forumServiceTest::setForumMsgTest(){
return false;
}
bool forumServiceTest::createGroupTests(){
return false;
}
void forumServiceTest::runTests(){
}
void forumServiceTest::loadDummyData(){
}

View File

@ -27,42 +27,32 @@
#ifndef DISTRIB_SERVICE_TEST_H_
#define DISTRIB_SERVICE_TEST_H_
#include "Service_Test.h"
#include "servicetest.h"
#include "services/p3forums.h"
#include "services/p3channels.h"
#include "services/p3blogs.h"
/*!
* For testing forums
*/
class RsForum_Test : public RsServiceTest {
class forumServiceTest : public ServiceTest {
public:
RsForum_Test();
virtual ~RsForum_Test();
forumServiceTest();
~forumServiceTest();
/*!
* goes returns the result for given test cases
*/
void result(std::map<std::string, bool>&);
bool setTestCases(std::list<std::string>& );
bool runCases(std::list<std::string>&);
/*!
* This is important for the get functions used by the deriving service
*/
void loadDummyData();
const std::string TEST_CREATE_FORUMS;
void runTests();
private:
bool testCreateForums();
BIO *bio_err;
p3Forums* forum;
bool getForumMsgTest();
bool setForumMsgTest();
bool createGroupTests();
private:
void loadDummyData();
private:
p3Forums* mForums;
};

View File

@ -0,0 +1,51 @@
/*
* libretroshare/src/tests/services Service_Test.cc
*
* RetroShare Service Testing
*
* Copyright 2010 by Chris 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 "servicetest.h"
#include "pqi/pqisslpersongrp.h"
ServiceTest::ServiceTest()
{
mConnMgr = new p3ConnectMgr();
SecurityPolicy *none = secpolicy_create();
mPersonGrp = new pqisslpersongrp(none, NULL);
mPeers = new p3Peers(mConnMgr);
}
ServiceTest::~ServiceTest()
{
// release resources
delete mConnMgr;
delete mPersonGrp;
delete mPeers;
}

View File

@ -0,0 +1,66 @@
/*
* libretroshare/src/tests/services Service_Test.h
*
* RetroShare Service Testing
*
* Copyright 2010 by Chris 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".
*
*/
#ifndef SERVICE_TEST_H_
#define SERVICE_TEST_H_
#include "pqi/p3connmgr.h"
#include "rsserver/p3peers.h"
#include "dbase/cachestrapper.h"
#include "pqi/pqipersongrp.h"
/*!
* A convenience class from which tests derive from
* This enables user to test in shallow manner the public methods
* of a service
*/
class ServiceTest {
public:
ServiceTest();
virtual ~ServiceTest();
/*!
* all tests of service should be implemented here
*/
virtual void runTests() = 0;
protected:
p3ConnectMgr* mConnMgr;
CacheStrapper *mCs;
CacheTransfer *mCt;
p3Peers* mPeers;
pqipersongrp* mPersonGrp;
};
#endif /* SERVICE_TEST_H_ */

View File

@ -1,5 +1,6 @@
RS_TOP_DIR = ..
RS_TOP_DIR = ../..
DHT_TOP_DIR = ../../../../libbitdht/src
##### Define any flags that are needed for this section #######
###############################################################