[sword-cvs] sword/tests/cppunit Makefile.am, NONE, 1.1 main.cpp,
NONE, 1.1 url_test.cpp, NONE, 1.1 versekey_test.cpp, NONE, 1.1
sword at www.crosswire.org
sword at www.crosswire.org
Thu Jul 15 06:10:35 MST 2004
Committed by: joachim
Update of /cvs/core/sword/tests/cppunit
In directory www:/tmp/cvs-serv9869/tests/cppunit
Added Files:
Makefile.am main.cpp url_test.cpp versekey_test.cpp
Log Message:
added cppunit testsuite to automake testing
--- NEW FILE: Makefile.am ---
LDADD = $(top_builddir)/lib/libsword.la
# Rules for the test code (use `make check` to execute)
TESTS = LibSword
check_PROGRAMS = $(TESTS)
LibSword_SOURCES = main.cpp url_test.cpp versekey_test.cpp
LibSword_CXXFLAGS = $(CPPUNIT_CFLAGS)
LibSword_LDFLAGS = -lcppunit -ldl
swcppunitpdir = $(top_srcdir)/tests/cppunit
all: check
--- NEW FILE: main.cpp ---
//LibSword tests
//CppUnit includes
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/CompilerOutputter.h>
#include <iostream>
int main( int argc, char* argv[] ) {
CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest( registry.makeTest() );
// Change the default outputter to a compiler error format outputter
// uncomment the following line if you need a compiler outputter.
runner.setOutputter(new CppUnit::CompilerOutputter( &runner.result(), std::cout ) );
//runner.setOutputter( new CppUnit::XmlOutputter( &runner.result(),
// std::cerr ) );
bool success = runner.run();
return success ? 0 : -1;
}
--- NEW FILE: url_test.cpp ---
#include <cppunit/extensions/HelperMacros.h>
#include <iostream>
#include "url.h"
class URLTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE( URLTest );
CPPUNIT_TEST( testProtocol );
CPPUNIT_TEST( testHostName );
CPPUNIT_TEST( testPath );
CPPUNIT_TEST( testParametersMap );
CPPUNIT_TEST( testParameterValue );
CPPUNIT_TEST_SUITE_END();
private:
sword::URL* m_url1;
sword::URL* m_url2;
sword::URL* m_url3;
public:
void setUp() {
m_url1 = new sword::URL("http://www.crosswire.org/index.jsp?page=help&user=foo&name=bar");
m_url2 = new sword::URL("ftp://ftp.crosswire.org/sword/wiki/index.jsp?page=help&user=foo&name=bar");
m_url3 = new sword::URL("crosswire.org/index.jsp");
}
void tearDown() {
delete m_url1;
delete m_url2;
delete m_url3;
}
void testProtocol()
{
CPPUNIT_ASSERT( !strcmp(m_url1->getProtocol(), "http") );
CPPUNIT_ASSERT( !strcmp(m_url2->getProtocol(), "ftp") );
CPPUNIT_ASSERT( strlen( m_url3->getProtocol() ) == 0 );
}
void testHostName()
{
CPPUNIT_ASSERT( !strcmp(m_url1->getHostName(), "www.crosswire.org") );
CPPUNIT_ASSERT( !strcmp(m_url2->getHostName(), "ftp.crosswire.org") );
CPPUNIT_ASSERT( !strcmp(m_url3->getHostName(), "crosswire.org") );
}
void testPath()
{
CPPUNIT_ASSERT( !strcmp(m_url1->getPath(), "/index.jsp") );
CPPUNIT_ASSERT( !strcmp(m_url2->getPath(), "/sword/wiki/index.jsp") );
CPPUNIT_ASSERT( !strcmp(m_url3->getPath(), "/index.jsp") );
}
void testParametersMap()
{
std::map< sword::SWBuf, sword::SWBuf > params = m_url1->getParameters();
CPPUNIT_ASSERT( !strcmp(params[sword::SWBuf("page")].c_str(), "help") );
CPPUNIT_ASSERT( !strcmp(params[sword::SWBuf("user")].c_str(), "foo") );
CPPUNIT_ASSERT( !strcmp(params[sword::SWBuf("name")].c_str(), "bar") );
params = m_url2->getParameters(); //test url2 params
CPPUNIT_ASSERT( !strcmp(params[sword::SWBuf("page")].c_str(), "help") );
CPPUNIT_ASSERT( !strcmp(params[sword::SWBuf("user")].c_str(), "foo") );
CPPUNIT_ASSERT( !strcmp(params[sword::SWBuf("name")].c_str(), "bar") );
params = m_url3->getParameters(); //test url3 params
CPPUNIT_ASSERT( params.size() == 0 );
}
void testParameterValue()
{
CPPUNIT_ASSERT( !strcmp(m_url1->getParamterValue("page"), "help") );
CPPUNIT_ASSERT( !strcmp(m_url1->getParamterValue("user"), "foo") );
CPPUNIT_ASSERT( !strcmp(m_url1->getParamterValue("name"), "bar") );
CPPUNIT_ASSERT( !strcmp(m_url2->getParamterValue("page"), "help") );
CPPUNIT_ASSERT( !strcmp(m_url2->getParamterValue("user"), "foo") );
CPPUNIT_ASSERT( !strcmp(m_url2->getParamterValue("name"), "bar") );
CPPUNIT_ASSERT( strlen(m_url3->getParamterValue("page")) == 0 );
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(URLTest);
--- NEW FILE: versekey_test.cpp ---
#include <cppunit/extensions/HelperMacros.h>
#include <iostream>
#include "swbuf.h"
#include "versekey.h"
using namespace sword;
class VerseKeyTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE( VerseKeyTest );
CPPUNIT_TEST( testSingleKeyParsing );
CPPUNIT_TEST_SUITE_END();
private:
sword::VerseKey* m_vk1;
sword::VerseKey* m_vk2;
sword::VerseKey* m_vk3;
protected:
void setLocaleToAll(const char* name) {
m_vk1->setLocale(name);
m_vk2->setLocale(name);
m_vk3->setLocale(name);
};
SWBuf parseKey(const char* keyValue, const char* locale) {
sword::VerseKey vk;
vk.setLocale(locale);
vk.setText(keyValue);
SWBuf ret( vk.getText() );
//std::cout << ret.c_str();
return ret;
};
public:
void setUp() {
m_vk1 = new sword::VerseKey();
m_vk2 = new sword::VerseKey();
m_vk3 = new sword::VerseKey();
setLocaleToAll("en");
}
void tearDown() {
delete m_vk1;
delete m_vk2;
delete m_vk3;
}
void testSingleKeyParsing() {
//testing with I John 2:3 and locale en
CPPUNIT_ASSERT( parseKey("1jn.2.3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey("1 jn.2.3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey("Ijn.2.3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey("I jn.2.3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey( "1jn 2.3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey( "1 jn 2.3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey( "Ijn 2.3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey( "I jn 2.3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey( "1jn.2:3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey( "1 jn.2:3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey( "Ijn.2:3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey( "I jn.2:3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey( "1jn 2:3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey( "1 jn 2:3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey( "Ijn 2:3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey("1.jn.2.3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey("1. jn.2.3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey("I.jn.2.3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey("I. jn.2.3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey("1.jn 2.3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey("1. jn 2.3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey("I.jn 2.3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey("I. jn 2.3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey("1.jn.2:3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey("1. jn.2:3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey("I.jn.2:3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey("I. jn.2:3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey("1.jn 2:3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey("1. jn 2:3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey("I.jn 2:3", "en") == "I John 2:3");
CPPUNIT_ASSERT( parseKey("I. jn 2:3", "en") == "I John 2:3");
//testing the same with german locale
CPPUNIT_ASSERT( parseKey("1jn.2.3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey("1 jn.2.3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey("Ijn.2.3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey("I jn.2.3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey( "1jn 2.3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey( "1 jn 2.3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey( "Ijn 2.3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey( "I jn 2.3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey( "1jn.2:3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey( "1 jn.2:3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey( "Ijn.2:3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey( "I jn.2:3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey( "1jn 2:3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey( "1 jn 2:3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey( "Ijn 2:3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey("1.jn.2.3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey("1. jn.2.3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey("I.jn.2.3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey("I. jn.2.3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey("1.jn 2.3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey("1. jn 2.3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey("I.jn 2.3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey("I. jn 2.3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey("1.jn.2:3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey("1. jn.2:3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey("I.jn.2:3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey("I. jn.2:3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey("1.jn 2:3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey("1. jn 2:3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey("I.jn 2:3", "de") == "1. Johannes 2:3");
CPPUNIT_ASSERT( parseKey("I. jn 2:3", "de") == "1. Johannes 2:3");
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(VerseKeyTest);
More information about the sword-cvs
mailing list