service testing framework and initial work on distrib testing

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3710 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2010-10-28 19:22:13 +00:00
parent 70c90832be
commit fc593ccf50
6 changed files with 524 additions and 0 deletions

View File

@ -0,0 +1,24 @@
RS_TOP_DIR = ../..
##### Define any flags that are needed for this section #######
###############################################################
###############################################################
include $(RS_TOP_DIR)/tests/scripts/config.mk
###############################################################
OBJ += distrib_services.o Service_Test.o
TESTS = distrib_test_main
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)
###############################################################
include $(RS_TOP_DIR)/scripts/rules.mk
###############################################################

View File

@ -0,0 +1,98 @@
/*
* 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

@ -0,0 +1,112 @@
/*
* 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,182 @@
/*
* 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

@ -0,0 +1,70 @@
/*
* libretroshare/src/tests/services distrib_services.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 DISTRIB_SERVICE_TEST_H_
#define DISTRIB_SERVICE_TEST_H_
#include "Service_Test.h"
#include "services/p3forums.h"
#include "services/p3channels.h"
#include "services/p3blogs.h"
/*!
* For testing forums
*/
class RsForum_Test : public RsServiceTest {
public:
RsForum_Test();
virtual ~RsForum_Test();
/*!
* 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;
private:
bool testCreateForums();
BIO *bio_err;
p3Forums* forum;
};
#endif /* DISTRIB_SERVICE_TEST_H_ */

View File

@ -0,0 +1,38 @@
/*
* libretroshare/src/tests/services distrib_test_main.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 "distrib_services.h"
int main()
{
ServiceTestFrame tf;
RsForum_Test* forum_test = new RsForum_Test();
std::string testName("test1");
tf.addTest(testName, forum_test);
return 0;
}