New build system for unit tests.

This commit is contained in:
Vincent Richard 2004-11-06 10:48:58 +00:00
parent c34d699f98
commit 418c0c1456
5 changed files with 461 additions and 20 deletions

View File

@ -230,6 +230,52 @@ libvmime_tests = [
'tests/run-tests.sh' 'tests/run-tests.sh'
] ]
libunitpp_common = [
'tests/lib/unit++/aclocal.m4',
'tests/lib/unit++/COPYING',
'tests/lib/unit++/guitester.cc',
'tests/lib/unit++/main.h',
'tests/lib/unit++/optmap-compat.h',
'tests/lib/unit++/tester.h',
'tests/lib/unit++/Test_unit++.cc',
'tests/lib/unit++/unit++-compat.h',
'tests/lib/unit++/Changelog',
'tests/lib/unit++/guitester.h',
'tests/lib/unit++/optmap.h',
'tests/lib/unit++/unit++.1',
'tests/lib/unit++/unit++.h',
'tests/lib/unit++/gui.cc',
'tests/lib/unit++/INSTALL',
'tests/lib/unit++/Makefile.in',
'tests/lib/unit++/Test_gui.cc',
'tests/lib/unit++/unit++.3',
'tests/lib/unit++/configure.ac',
'tests/lib/unit++/gui.h',
# 'tests/lib/unit++/main.cc',
# 'tests/lib/unit++/optmap.cc',
# 'tests/lib/unit++/tester.cc',
'tests/lib/unit++/Test_optmap.cc',
# 'tests/lib/unit++/unit++.cc',
'tests/lib/unit++/unitpp.m4'
]
libunitpp_sources = [
'tests/lib/unit++/unit++.cc',
'tests/lib/unit++/main.cc',
'tests/lib/unit++/optmap.cc',
'tests/lib/unit++/tester.cc'
]
libvmimetest_common = [
'tests/parser/testUtils.hpp'
]
libvmimetest_sources = [
[ 'tests/parser/headerTest', [ 'tests/parser/headerTest.cpp' ] ],
[ 'tests/parser/mailboxTest', [ 'tests/parser/mailboxTest.cpp' ] ],
[ 'tests/parser/textTest', [ 'tests/parser/textTest.cpp' ] ]
]
libvmime_dist_files = libvmime_sources + libvmime_messaging_sources libvmime_dist_files = libvmime_sources + libvmime_messaging_sources
for i in range(len(libvmime_dist_files)): for i in range(len(libvmime_dist_files)):
@ -242,6 +288,11 @@ for p in libvmime_messaging_proto_sources:
libvmime_dist_files = libvmime_dist_files + libvmime_extra + libvmime_examples_sources libvmime_dist_files = libvmime_dist_files + libvmime_extra + libvmime_examples_sources
libvmime_dist_files_with_tests = libvmime_dist_files + libvmime_tests libvmime_dist_files_with_tests = libvmime_dist_files + libvmime_tests
libvmime_dist_files = libvmime_dist_files + libunitpp_common
libvmime_dist_files = libvmime_dist_files + libunitpp_sources
libvmime_dist_files = libvmime_dist_files + libvmimetest_common
libvmime_dist_files = libvmime_dist_files + libvmimetest_sources
################# #################
# Set options # # Set options #
@ -374,6 +425,14 @@ opts.AddOptions(
allowed_values = ('char', 'short', 'int', 'long'), allowed_values = ('char', 'short', 'int', 'long'),
map = { }, map = { },
ignorecase = 1 ignorecase = 1
),
EnumOption(
'build_tests',
'Build unit tests (in "tests" directory)',
'no',
allowed_values = ('yes', 'no'),
map = { },
ignorecase = 1
) )
) )
@ -619,28 +678,54 @@ for file in libvmime_full_sources:
# Main program build # Main program build
if env['debug'] == 'yes': if env['debug'] == 'yes':
libVmime = env.StaticLibrary( if env['static'] == 'yes':
target = 'vmime-debug', libVmime = env.StaticLibrary(
source = libvmime_sources_CPP target = 'vmime-debug',
) source = libvmime_sources_CPP
libVmimeSh = env.SharedLibrary( )
target = 'vmime-debug',
source = libvmime_sources_CPP if env['shared'] == 'yes':
) libVmimeSh = env.SharedLibrary(
target = 'vmime-debug',
source = libvmime_sources_CPP
)
else: else:
libVmime = env.StaticLibrary( if env['static'] == 'yes':
target = 'vmime', libVmime = env.StaticLibrary(
source = libvmime_sources_CPP target = 'vmime',
) source = libvmime_sources_CPP
libVmimeSh = env.SharedLibrary( )
target = 'vmime',
source = libvmime_sources_CPP if env['shared'] == 'yes':
) libVmimeSh = env.SharedLibrary(
target = 'vmime',
source = libvmime_sources_CPP
)
if env['static'] == 'yes': Default(libVmime) if env['static'] == 'yes': Default(libVmime)
if env['shared'] == 'yes': Default(libVmimeSh) if env['shared'] == 'yes': Default(libVmimeSh)
# Tests
if env['build_tests'] == 'yes':
libUnitpp = env.StaticLibrary(
target = 'tests/unit++',
source = libunitpp_sources
)
Default(libUnitpp)
for test in libvmimetest_sources:
Default(
env.Program(
target = test[0],
source = test[1],
LIBS=['unit++', 'vmime-debug'],
LIBPATH=['.', './tests/']
)
)
######################## ########################
# Installation rules # # Installation rules #
######################## ########################

View File

@ -1,4 +0,0 @@
main: headerTest.cpp ../../libvmime-debug.a
g++ -o headerTest headerTest.cpp ../../libvmime-debug.a ../lib/unit++/unit++.cc ../lib/unit++/main.cc ../lib/unit++/optmap.cc ../lib/unit++/tester.cc -Wall

View File

@ -0,0 +1,114 @@
//
// VMime library (http://vmime.sourceforge.net)
// Copyright (C) 2002-2004 Vincent Richard <vincent@vincent-richard.net>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// This program 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
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include "../lib/unit++/unit++.h"
#include <iostream>
#include <ostream>
#include "../../src/vmime"
#include "../../examples/common.inc"
#include "testUtils.hpp"
using namespace unitpp;
namespace
{
class mailboxTest : public suite
{
void testParse()
{
static const vmime::string testSuitesParse[] =
{
// Test 1
"My (this is a comment)name <me(another \\)comment) @ somewhere(else).com>",
"[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=My name]]], email=me@somewhere.com]]]",
// Test 2
"mailbox1 <mailbox@one>,;,,, ,, ,,;group1:mailbox1@group1, mailbox2@group2,,\"mailbox #3\" <mailbox3@group2>;, <mailbox@two>,,,,,,,,=?iso-8859-1?q?mailbox_number_3?= <mailbox@three>, =?abc?Q?mailbox?= =?def?Q?_number_4?= <mailbox@four>",
"[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=mailbox1]]], email=mailbox@one],[mailbox-group: name=[text: [[word: charset=us-ascii, buffer=group1]]], list=[[mailbox: name=[text: []], email=mailbox1@group1],[mailbox: name=[text: []], email=mailbox2@group2],[mailbox: name=[text: [[word: charset=us-ascii, buffer=mailbox #3]]], email=mailbox3@group2]]],[mailbox: name=[text: []], email=mailbox@two],[mailbox: name=[text: [[word: charset=iso-8859-1, buffer=mailbox number 3]]], email=mailbox@three],[mailbox: name=[text: [[word: charset=abc, buffer=mailbox],[word: charset=def, buffer= number 4]]], email=mailbox@four]]]",
// Test 3
"John Doe <john.doe@acme.com>",
"[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=John Doe]]], email=john.doe@acme.com]]]",
// Test 4
"john.doe@acme.com (John Doe)",
"[address-list: [[mailbox: name=[text: []], email=john.doe@acme.com]]]",
// Test 5
"John.Doe (ignore) @acme.com (John Doe)",
"[address-list: [[mailbox: name=[text: []], email=John.Doe@acme.com]]]",
// Test 6
"<john.doe@acme.com>",
"[address-list: [[mailbox: name=[text: []], email=john.doe@acme.com]]]",
// Test 7
"john.doe@acme.com",
"[address-list: [[mailbox: name=[text: []], email=john.doe@acme.com]]]",
// Test 8
"\"John Doe\" <john.doe@acme.com>",
"[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=John Doe]]], email=john.doe@acme.com]]]",
};
for (unsigned int i = 0 ; i < sizeof(testSuitesParse) / sizeof(testSuitesParse[0]) / 2 ; ++i)
{
vmime::string in = testSuitesParse[i * 2];
vmime::string out = testSuitesParse[i * 2 + 1];
std::ostringstream oss;
oss << "Test " << (i + 1);
vmime::addressList addrList;
addrList.parse(in);
std::ostringstream cmp;
cmp << addrList;
assert_eq(oss.str(), out, cmp.str());
}
}
public:
mailboxTest() : suite("vmime::mailbox")
{
vmime::platformDependant::setHandler<my_handler>();
add("Parse", testcase(this, "Parse", &mailboxTest::testParse));
suite::main().add("vmime::mailbox", this);
}
};
mailboxTest* theTest = new mailboxTest();
}

113
tests/parser/testUtils.hpp Normal file
View File

@ -0,0 +1,113 @@
//
// VMime library (http://vmime.sourceforge.net)
// Copyright (C) 2002-2004 Vincent Richard <vincent@vincent-richard.net>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// This program 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
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include <ostream>
namespace std
{
std::ostream& operator<<(std::ostream& os, const vmime::charset& ch)
{
os << "[charset: " << ch.getName() << "]";
return (os);
}
std::ostream& operator<<(std::ostream& os, const vmime::text& txt)
{
os << "[text: [";
for (int i = 0 ; i < txt.getWordCount() ; ++i)
{
const vmime::word& w = *txt.getWordAt(i);
if (i != 0)
os << ",";
os << "[word: charset=" << w.getCharset().getName() << ", buffer=" << w.getBuffer() << "]";
}
os << "]]";
return (os);
}
std::ostream& operator<<(std::ostream& os, const vmime::mailbox& mbox)
{
os << "[mailbox: name=" << mbox.getName() << ", email=" << mbox.getEmail() << "]";
return (os);
}
std::ostream& operator<<(std::ostream& os, const vmime::mailboxGroup& group)
{
os << "[mailbox-group: name=" << group.getName() << ", list=[";
for (int i = 0 ; i < group.getMailboxCount() ; ++i)
{
if (i != 0)
os << ",";
os << *group.getMailboxAt(i);
}
os << "]]";
return (os);
}
std::ostream& operator<<(std::ostream& os, const vmime::addressList& list)
{
os << "[address-list: [";
for (int i = 0 ; i < list.getAddressCount() ; ++i)
{
const vmime::address& addr = *list.getAddressAt(i);
if (i != 0)
os << ",";
if (addr.isGroup())
{
const vmime::mailboxGroup& group =
dynamic_cast <const vmime::mailboxGroup&>(addr);
os << group;
}
else
{
const vmime::mailbox& mbox =
dynamic_cast <const vmime::mailbox&>(addr);
os << mbox;
}
}
os << "]]";
return (os);
}
}

133
tests/parser/textTest.cpp Normal file
View File

@ -0,0 +1,133 @@
//
// VMime library (http://vmime.sourceforge.net)
// Copyright (C) 2002-2004 Vincent Richard <vincent@vincent-richard.net>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// This program 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
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include "../lib/unit++/unit++.h"
#include <iostream>
#include <ostream>
#include "../../src/vmime"
#include "../../examples/common.inc"
#include "testUtils.hpp"
using namespace unitpp;
namespace
{
class textTest : public suite
{
void testConstructors()
{
vmime::text t1;
assert_eq("1.1", 0, t1.getWordCount());
vmime::text t2("Test\xa9\xc3");
assert_eq("2.1", 1, t2.getWordCount());
assert_eq("2.2", "Test\xa9\xc3", t2.getWordAt(0)->getBuffer());
assert_eq("2.3", vmime::charset::getLocaleCharset(), t2.getWordAt(0)->getCharset());
vmime::text t3("Test\xa9\xc3", vmime::charset(vmime::charsets::ISO8859_13));
assert_eq("3.1", 1, t3.getWordCount());
assert_eq("3.2", "Test\xa9\xc3", t3.getWordAt(0)->getBuffer());
assert_eq("3.3", vmime::charset(vmime::charsets::ISO8859_13), t3.getWordAt(0)->getCharset());
vmime::word w1("Test", vmime::charset(vmime::charsets::UTF_8));
vmime::text t4(w1);
assert_eq("4.1", 1, t4.getWordCount());
assert_eq("4.2", w1.getBuffer(), t4.getWordAt(0)->getBuffer());
assert_eq("4.3", w1.getCharset(), t4.getWordAt(0)->getCharset());
vmime::word w2("Other", vmime::charset(vmime::charsets::US_ASCII));
t4.appendWord(new vmime::word(w2));
vmime::text t5(t4);
assert_eq("5.1", 2, t5.getWordCount());
assert_eq("5.2", w1.getBuffer(), t5.getWordAt(0)->getBuffer());
assert_eq("5.3", w1.getCharset(), t5.getWordAt(0)->getCharset());
assert_eq("5.4", w2.getBuffer(), t5.getWordAt(1)->getBuffer());
assert_eq("5.5", w2.getCharset(), t5.getWordAt(1)->getCharset());
}
void testCopy()
{
vmime::text t1("Test: \xa9\xc3");
assert_true("operator==", t1 == t1);
assert_true("clone", *(t1.clone()) == t1);
vmime::text t2;
t2.copyFrom(t1);
assert_true("copyFrom", t1 == t2);
}
void testNewFromString()
{
vmime::string s1 = "only ASCII characters";
vmime::charset c1("test");
vmime::text t1;
vmime::text::newFromString(s1, c1, &t1);
assert_eq("1.1", 1, t1.getWordCount());
assert_eq("1.2", s1, t1.getWordAt(0)->getBuffer());
assert_eq("1.3", vmime::charset(vmime::charsets::US_ASCII), t1.getWordAt(0)->getCharset());
vmime::string s2_1 = "some ASCII characters and special chars: ";
vmime::string s2_2 = "\xf1\xf2\xf3\xf4 ";
vmime::string s2_3 = "and then more ASCII chars.";
vmime::string s2 = s2_1 + s2_2 + s2_3;
vmime::charset c2("test");
vmime::text t2;
vmime::text::newFromString(s2, c2, &t2);
assert_eq("2.1", 3, t2.getWordCount());
assert_eq("2.2", s2_1, t2.getWordAt(0)->getBuffer());
assert_eq("2.3", vmime::charset(vmime::charsets::US_ASCII), t2.getWordAt(0)->getCharset());
assert_eq("2.4", s2_2, t2.getWordAt(1)->getBuffer());
assert_eq("2.5", c2, t2.getWordAt(1)->getCharset());
assert_eq("2.6", s2_3, t2.getWordAt(2)->getBuffer());
assert_eq("2.7", vmime::charset(vmime::charsets::US_ASCII), t2.getWordAt(2)->getCharset());
}
public:
textTest() : suite("vmime::text")
{
vmime::platformDependant::setHandler<my_handler>();
add("Constructors", testcase(this, "Constructors", &textTest::testConstructors));
add("Copy", testcase(this, "Copy", &textTest::testCopy));
add("NewFromString", testcase(this, "NewFromString", &textTest::testNewFromString));
suite::main().add("vmime::text", this);
}
};
textTest* theTest = new textTest();
}