aboutsummaryrefslogtreecommitdiffstats
path: root/tests/parser
diff options
context:
space:
mode:
Diffstat (limited to 'tests/parser')
-rw-r--r--tests/parser/bodyPartTest.cpp96
-rw-r--r--tests/parser/datetimeTest.cpp191
-rw-r--r--tests/parser/dispositionTest.cpp221
-rw-r--r--tests/parser/encoderTest.cpp404
-rw-r--r--tests/parser/headerTest.cpp519
-rw-r--r--tests/parser/mailboxTest.cpp130
-rw-r--r--tests/parser/mediaTypeTest.cpp126
-rw-r--r--tests/parser/messageIdSequenceTest.cpp96
-rw-r--r--tests/parser/messageIdTest.cpp78
-rw-r--r--tests/parser/parameterTest.cpp366
-rw-r--r--tests/parser/pathTest.cpp128
-rw-r--r--tests/parser/testUtils.hpp123
-rw-r--r--tests/parser/textTest.cpp375
13 files changed, 1270 insertions, 1583 deletions
diff --git a/tests/parser/bodyPartTest.cpp b/tests/parser/bodyPartTest.cpp
index ffbdefda..0591e4d1 100644
--- a/tests/parser/bodyPartTest.cpp
+++ b/tests/parser/bodyPartTest.cpp
@@ -17,77 +17,61 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
-#include "../lib/unit++/unit++.h"
+#include "tests/testUtils.hpp"
-#include <iostream>
-#include <ostream>
-#include "vmime/vmime.hpp"
-#include "vmime/platforms/posix/posixHandler.hpp"
+#define VMIME_TEST_SUITE bodyPartTest
+#define VMIME_TEST_SUITE_MODULE "Parser"
-using namespace unitpp;
+VMIME_TEST_SUITE_BEGIN
-namespace
-{
- class bodyPartTest : public suite
- {
- static const vmime::string extractComponentString
- (const vmime::string& buffer, const vmime::component& c)
- {
- return vmime::string(buffer.begin() + c.getParsedOffset(),
- buffer.begin() + c.getParsedOffset() + c.getParsedLength());
- }
-
-
- void testParse()
- {
- vmime::string str1 = "HEADER\r\n\r\nBODY";
- vmime::bodyPart p1;
- p1.parse(str1);
-
- assert_eq("1", "HEADER\r\n\r\n", extractComponentString(str1, *p1.getHeader()));
- assert_eq("2", "BODY", extractComponentString(str1, *p1.getBody()));
+ VMIME_TEST_LIST_BEGIN
+ VMIME_TEST(testParse)
+ VMIME_TEST(testGenerate)
+ VMIME_TEST_LIST_END
- vmime::string str2 = "HEADER\n\nBODY";
- vmime::bodyPart p2;
- p2.parse(str2);
- assert_eq("3", "HEADER\n\n", extractComponentString(str2, *p2.getHeader()));
- assert_eq("4", "BODY", extractComponentString(str2, *p2.getBody()));
+ static const vmime::string extractComponentString
+ (const vmime::string& buffer, const vmime::component& c)
+ {
+ return vmime::string(buffer.begin() + c.getParsedOffset(),
+ buffer.begin() + c.getParsedOffset() + c.getParsedLength());
+ }
- vmime::string str3 = "HEADER\r\n\nBODY";
- vmime::bodyPart p3;
- p3.parse(str3);
- assert_eq("5", "HEADER\r\n\n", extractComponentString(str3, *p3.getHeader()));
- assert_eq("6", "BODY", extractComponentString(str3, *p3.getBody()));
- }
+ void testParse()
+ {
+ vmime::string str1 = "HEADER\r\n\r\nBODY";
+ vmime::bodyPart p1;
+ p1.parse(str1);
- void testGenerate()
- {
- vmime::bodyPart p1;
- p1.getHeader()->getField("Foo")->setValue(vmime::string("bar"));
- p1.getBody()->setContents(vmime::create <vmime::stringContentHandler>("Baz"));
+ VASSERT_EQ("1", "HEADER\r\n\r\n", extractComponentString(str1, *p1.getHeader()));
+ VASSERT_EQ("2", "BODY", extractComponentString(str1, *p1.getBody()));
- assert_eq("1", "Foo: bar\r\n\r\nBaz", p1.generate());
- }
+ vmime::string str2 = "HEADER\n\nBODY";
+ vmime::bodyPart p2;
+ p2.parse(str2);
- public:
+ VASSERT_EQ("3", "HEADER\n\n", extractComponentString(str2, *p2.getHeader()));
+ VASSERT_EQ("4", "BODY", extractComponentString(str2, *p2.getBody()));
- bodyPartTest() : suite("vmime::bodyPart")
- {
- // VMime initialization
- vmime::platformDependant::setHandler<vmime::platforms::posix::posixHandler>();
+ vmime::string str3 = "HEADER\r\n\nBODY";
+ vmime::bodyPart p3;
+ p3.parse(str3);
- add("Parse", testcase(this, "Parse", &bodyPartTest::testParse));
+ VASSERT_EQ("5", "HEADER\r\n\n", extractComponentString(str3, *p3.getHeader()));
+ VASSERT_EQ("6", "BODY", extractComponentString(str3, *p3.getBody()));
+ }
- add("Generate", testcase(this, "Generate", &bodyPartTest::testGenerate));
+ void testGenerate()
+ {
+ vmime::bodyPart p1;
+ p1.getHeader()->getField("Foo")->setValue(vmime::string("bar"));
+ p1.getBody()->setContents(vmime::create <vmime::stringContentHandler>("Baz"));
- suite::main().add("vmime::bodyPart", this);
- }
+ VASSERT_EQ("1", "Foo: bar\r\n\r\nBaz", p1.generate());
+ }
- };
+VMIME_TEST_SUITE_END
- bodyPartTest* theTest = new bodyPartTest();
-}
diff --git a/tests/parser/datetimeTest.cpp b/tests/parser/datetimeTest.cpp
index d372d685..12bf3dd4 100644
--- a/tests/parser/datetimeTest.cpp
+++ b/tests/parser/datetimeTest.cpp
@@ -17,126 +17,109 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
-#include "../lib/unit++/unit++.h"
+#include "tests/testUtils.hpp"
-#include <iostream>
-#include <ostream>
-#include "vmime/vmime.hpp"
-#include "vmime/platforms/posix/posixHandler.hpp"
+#define VMIME_TEST_SUITE datetimeTest
+#define VMIME_TEST_SUITE_MODULE "Parser"
-#include "tests/parser/testUtils.hpp"
-using namespace unitpp;
+VMIME_TEST_SUITE_BEGIN
+ VMIME_TEST_LIST_BEGIN
+ VMIME_TEST(testParse)
+ VMIME_TEST(testGenerate)
+ VMIME_TEST(testCompare)
+ VMIME_TEST_LIST_END
-namespace
-{
- class datetimeTest : public suite
+
+ void testParse()
{
- void testParse()
+ struct datetimePair
{
- struct datetimePair
- {
- vmime::string parseBuffer;
- vmime::datetime result;
- };
-
- // Here, we can't test all the possible structures for date/time,
- // so we test some cases. Don't forget to add a new test case
- // each time you encounter a bug in date/time parsing (after
- // you have fixed it).
- datetimePair pairs[] =
- {
- { /* 1 */ "Mon, 8 Nov 2004 13:42:56 +0000 (GMT)",
- vmime::datetime(2004, 11, 8, 13, 42, 56, vmime::datetime::GMT) },
-
- { /* 2 */ "Sun, 7 Nov 2004 00:43:22 -0500 (EST)",
- vmime::datetime(2004, 11, 7, 0, 43, 22, vmime::datetime::GMT_5) },
-
- { /* 3 */ "Thu Nov 18 12:11:16 2004",
- vmime::datetime(vmime::datetime::now().getYear(), 11, 18, 12, 11, 16, vmime::datetime::GMT) },
-
- { /* 4 */ "Sat, 18, 2004 22:36:32 -0400",
- vmime::datetime(2004, 1, 18, 22, 36, 32, vmime::datetime::GMT_4) },
-
- { /* 5 */ "Mon Dec 13 21:57:18 2004",
- vmime::datetime(vmime::datetime::now().getYear(), 12, 13, 21, 57, 18, vmime::datetime::GMT) },
-
- { /* 6 */ "18 Nov 2004 21:44:54 +0300",
- vmime::datetime(2004, 11, 18, 21, 44, 54, vmime::datetime::GMT3) }
- };
-
- for (unsigned int i = 0 ; i < sizeof(pairs) / sizeof(pairs[0]) ; ++i)
- {
- vmime::datetime d;
- d.parse(pairs[i].parseBuffer);
-
- std::ostringstream oss;
- oss << (i + 1);
-
- assert_eq(oss.str(), pairs[i].result, d);
- }
- }
-
- void testGenerate()
+ vmime::string parseBuffer;
+ vmime::datetime result;
+ };
+
+ // Here, we can't test all the possible structures for date/time,
+ // so we test some cases. Don't forget to add a new test case
+ // each time you encounter a bug in date/time parsing (after
+ // you have fixed it).
+ datetimePair pairs[] =
{
- vmime::datetime d1(2005, 7, 8, 4, 5, 6, 1 * 60 + 23);
+ { /* 1 */ "Mon, 8 Nov 2004 13:42:56 +0000 (GMT)",
+ vmime::datetime(2004, 11, 8, 13, 42, 56, vmime::datetime::GMT) },
- assert_eq("1", "Fri, 8 Jul 2005 04:05:06 +0123", d1.generate());
- }
+ { /* 2 */ "Sun, 7 Nov 2004 00:43:22 -0500 (EST)",
+ vmime::datetime(2004, 11, 7, 0, 43, 22, vmime::datetime::GMT_5) },
- void testCompare()
- {
- // Date1 = Date2
- vmime::datetime d1(2005, 4, 22, 14, 6, 0, vmime::datetime::GMT2);
- vmime::datetime d2(2005, 4, 22, 10, 6, 0, vmime::datetime::GMT_2);
-
- assert_eq("1.1", true, d1 == d2);
- assert_eq("1.2", false, d1 != d2);
- assert_eq("1.3", true, d1 <= d2);
- assert_eq("1.4", false, d1 < d2);
- assert_eq("1.5", true, d1 >= d2);
- assert_eq("1.6", false, d1 > d2);
-
- // Date1 < Date2
- vmime::datetime d3(2005, 4, 22, 14, 6, 0);
- vmime::datetime d4(2005, 4, 22, 15, 6, 0);
-
- assert_eq("2.1", false, d3 == d4);
- assert_eq("2.2", true, d3 != d4);
- assert_eq("2.3", true, d3 <= d4);
- assert_eq("2.4", true, d3 < d4);
- assert_eq("2.5", false, d3 >= d4);
- assert_eq("2.6", false, d3 > d4);
-
- // Date1 > Date2
- vmime::datetime d5(2005, 4, 22, 15, 6, 0);
- vmime::datetime d6(2005, 4, 22, 14, 6, 0);
-
- assert_eq("3.1", false, d5 == d6);
- assert_eq("3.2", true, d5 != d6);
- assert_eq("3.3", false, d5 <= d6);
- assert_eq("3.4", false, d5 < d6);
- assert_eq("3.5", true, d5 >= d6);
- assert_eq("3.6", true, d5 > d6);
- }
+ { /* 3 */ "Thu Nov 18 12:11:16 2004",
+ vmime::datetime(vmime::datetime::now().getYear(), 11, 18, 12, 11, 16, vmime::datetime::GMT) },
- public:
+ { /* 4 */ "Sat, 18, 2004 22:36:32 -0400",
+ vmime::datetime(2004, 1, 18, 22, 36, 32, vmime::datetime::GMT_4) },
- datetimeTest() : suite("vmime::datetime")
+ { /* 5 */ "Mon Dec 13 21:57:18 2004",
+ vmime::datetime(vmime::datetime::now().getYear(), 12, 13, 21, 57, 18, vmime::datetime::GMT) },
+
+ { /* 6 */ "18 Nov 2004 21:44:54 +0300",
+ vmime::datetime(2004, 11, 18, 21, 44, 54, vmime::datetime::GMT3) }
+ };
+
+ for (unsigned int i = 0 ; i < sizeof(pairs) / sizeof(pairs[0]) ; ++i)
{
- // VMime initialization
- vmime::platformDependant::setHandler<vmime::platforms::posix::posixHandler>();
+ vmime::datetime d;
+ d.parse(pairs[i].parseBuffer);
- add("Parse", testcase(this, "Parse", &datetimeTest::testParse));
- add("Generate", testcase(this, "Generate", &datetimeTest::testGenerate));
- add("Compare", testcase(this, "Compare", &datetimeTest::testCompare));
+ std::ostringstream oss;
+ oss << (i + 1);
- suite::main().add("vmime::datetime", this);
+ VASSERT_EQ(oss.str(), pairs[i].result, d);
}
+ }
+
+ void testGenerate()
+ {
+ vmime::datetime d1(2005, 7, 8, 4, 5, 6, 1 * 60 + 23);
+
+ VASSERT_EQ("1", "Fri, 8 Jul 2005 04:05:06 +0123", d1.generate());
+ }
- };
+ void testCompare()
+ {
+ // Date1 = Date2
+ vmime::datetime d1(2005, 4, 22, 14, 6, 0, vmime::datetime::GMT2);
+ vmime::datetime d2(2005, 4, 22, 10, 6, 0, vmime::datetime::GMT_2);
+
+ VASSERT_EQ("1.1", true, d1 == d2);
+ VASSERT_EQ("1.2", false, d1 != d2);
+ VASSERT_EQ("1.3", true, d1 <= d2);
+ VASSERT_EQ("1.4", false, d1 < d2);
+ VASSERT_EQ("1.5", true, d1 >= d2);
+ VASSERT_EQ("1.6", false, d1 > d2);
+
+ // Date1 < Date2
+ vmime::datetime d3(2005, 4, 22, 14, 6, 0);
+ vmime::datetime d4(2005, 4, 22, 15, 6, 0);
+
+ VASSERT_EQ("2.1", false, d3 == d4);
+ VASSERT_EQ("2.2", true, d3 != d4);
+ VASSERT_EQ("2.3", true, d3 <= d4);
+ VASSERT_EQ("2.4", true, d3 < d4);
+ VASSERT_EQ("2.5", false, d3 >= d4);
+ VASSERT_EQ("2.6", false, d3 > d4);
+
+ // Date1 > Date2
+ vmime::datetime d5(2005, 4, 22, 15, 6, 0);
+ vmime::datetime d6(2005, 4, 22, 14, 6, 0);
+
+ VASSERT_EQ("3.1", false, d5 == d6);
+ VASSERT_EQ("3.2", true, d5 != d6);
+ VASSERT_EQ("3.3", false, d5 <= d6);
+ VASSERT_EQ("3.4", false, d5 < d6);
+ VASSERT_EQ("3.5", true, d5 >= d6);
+ VASSERT_EQ("3.6", true, d5 > d6);
+ }
+
+VMIME_TEST_SUITE_END
- datetimeTest* theTest = new datetimeTest();
-}
diff --git a/tests/parser/dispositionTest.cpp b/tests/parser/dispositionTest.cpp
index e0c269f7..bad63a63 100644
--- a/tests/parser/dispositionTest.cpp
+++ b/tests/parser/dispositionTest.cpp
@@ -17,152 +17,135 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
-#include "../lib/unit++/unit++.h"
+#include "tests/testUtils.hpp"
-#include <iostream>
-#include <ostream>
-#include "vmime/vmime.hpp"
-#include "vmime/platforms/posix/posixHandler.hpp"
+#define VMIME_TEST_SUITE dispositionTest
+#define VMIME_TEST_SUITE_MODULE "Parser"
-#include "tests/parser/testUtils.hpp"
-using namespace unitpp;
+VMIME_TEST_SUITE_BEGIN
+ VMIME_TEST_LIST_BEGIN
+ VMIME_TEST(testParse)
+ VMIME_TEST(testGenerate)
+ VMIME_TEST(testModifiers)
+ VMIME_TEST_LIST_END
-namespace
-{
- class dispositionTest : public suite
- {
- void testParse()
- {
- // disposition-mode ";" disposition-type
- // [ "/" disposition-modifier *( "," disposition-modifier ) ]
- //
- // disposition-mode = action-mode "/" sending-mode
-
- vmime::disposition disp1;
- disp1.parse("mode");
-
- assert_eq("1.1", "mode", disp1.getActionMode());
- assert_eq("1.2", "", disp1.getSendingMode());
- assert_eq("1.3", "", disp1.getType());
- assert_eq("1.4", 0, static_cast <int>(disp1.getModifierList().size()));
-
- vmime::disposition disp2;
- disp2.parse("amode/smode");
-
- assert_eq("2.1", "amode", disp2.getActionMode());
- assert_eq("2.2", "smode", disp2.getSendingMode());
- assert_eq("2.3", "", disp2.getType());
- assert_eq("2.4", 0, static_cast <int>(disp2.getModifierList().size()));
-
- vmime::disposition disp3;
- disp3.parse("amode/smode;type");
-
- assert_eq("3.1", "amode", disp3.getActionMode());
- assert_eq("3.2", "smode", disp3.getSendingMode());
- assert_eq("3.3", "type", disp3.getType());
- assert_eq("3.4", 0, static_cast <int>(disp3.getModifierList().size()));
-
- vmime::disposition disp4;
- disp4.parse("amode/smode;type/modif");
-
- assert_eq("4.1", "amode", disp4.getActionMode());
- assert_eq("4.2", "smode", disp4.getSendingMode());
- assert_eq("4.3", "type", disp4.getType());
- assert_eq("4.4", 1, static_cast <int>(disp4.getModifierList().size()));
- assert_eq("4.5", "modif", disp4.getModifierList()[0]);
-
- vmime::disposition disp5;
- disp5.parse("amode/smode;type/modif1,modif2");
- assert_eq("5.1", "amode", disp5.getActionMode());
- assert_eq("5.2", "smode", disp5.getSendingMode());
- assert_eq("5.3", "type", disp5.getType());
- assert_eq("5.4", 2, static_cast <int>(disp5.getModifierList().size()));
- assert_eq("5.5", "modif1", disp5.getModifierList()[0]);
- assert_eq("5.6", "modif2", disp5.getModifierList()[1]);
- }
-
- void testGenerate()
- {
- vmime::disposition disp;
-
- assert_eq("1", "automatic-action/MDN-sent-automatically;displayed", disp.generate());
-
- disp.setActionMode("amode");
-
- assert_eq("2", "amode/MDN-sent-automatically;displayed", disp.generate());
-
- disp.setActionMode("amode");
- disp.setSendingMode("smode");
-
- assert_eq("3", "amode/smode;displayed", disp.generate());
+ void testParse()
+ {
+ // disposition-mode ";" disposition-type
+ // [ "/" disposition-modifier *( "," disposition-modifier ) ]
+ //
+ // disposition-mode = action-mode "/" sending-mode
+
+ vmime::disposition disp1;
+ disp1.parse("mode");
+
+ VASSERT_EQ("1.1", "mode", disp1.getActionMode());
+ VASSERT_EQ("1.2", "", disp1.getSendingMode());
+ VASSERT_EQ("1.3", "", disp1.getType());
+ VASSERT_EQ("1.4", 0, static_cast <int>(disp1.getModifierList().size()));
+
+ vmime::disposition disp2;
+ disp2.parse("amode/smode");
+
+ VASSERT_EQ("2.1", "amode", disp2.getActionMode());
+ VASSERT_EQ("2.2", "smode", disp2.getSendingMode());
+ VASSERT_EQ("2.3", "", disp2.getType());
+ VASSERT_EQ("2.4", 0, static_cast <int>(disp2.getModifierList().size()));
+
+ vmime::disposition disp3;
+ disp3.parse("amode/smode;type");
+
+ VASSERT_EQ("3.1", "amode", disp3.getActionMode());
+ VASSERT_EQ("3.2", "smode", disp3.getSendingMode());
+ VASSERT_EQ("3.3", "type", disp3.getType());
+ VASSERT_EQ("3.4", 0, static_cast <int>(disp3.getModifierList().size()));
+
+ vmime::disposition disp4;
+ disp4.parse("amode/smode;type/modif");
+
+ VASSERT_EQ("4.1", "amode", disp4.getActionMode());
+ VASSERT_EQ("4.2", "smode", disp4.getSendingMode());
+ VASSERT_EQ("4.3", "type", disp4.getType());
+ VASSERT_EQ("4.4", 1, static_cast <int>(disp4.getModifierList().size()));
+ VASSERT_EQ("4.5", "modif", disp4.getModifierList()[0]);
+
+ vmime::disposition disp5;
+ disp5.parse("amode/smode;type/modif1,modif2");
+
+ VASSERT_EQ("5.1", "amode", disp5.getActionMode());
+ VASSERT_EQ("5.2", "smode", disp5.getSendingMode());
+ VASSERT_EQ("5.3", "type", disp5.getType());
+ VASSERT_EQ("5.4", 2, static_cast <int>(disp5.getModifierList().size()));
+ VASSERT_EQ("5.5", "modif1", disp5.getModifierList()[0]);
+ VASSERT_EQ("5.6", "modif2", disp5.getModifierList()[1]);
+ }
+
+ void testGenerate()
+ {
+ vmime::disposition disp;
- disp.setType("type");
+ VASSERT_EQ("1", "automatic-action/MDN-sent-automatically;displayed", disp.generate());
- assert_eq("4", "amode/smode;type", disp.generate());
+ disp.setActionMode("amode");
- disp.addModifier("modif1");
+ VASSERT_EQ("2", "amode/MDN-sent-automatically;displayed", disp.generate());
- assert_eq("5", "amode/smode;type/modif1", disp.generate());
+ disp.setActionMode("amode");
+ disp.setSendingMode("smode");
- disp.addModifier("modif2");
+ VASSERT_EQ("3", "amode/smode;displayed", disp.generate());
- assert_eq("6", "amode/smode;type/modif1,modif2", disp.generate());
- }
+ disp.setType("type");
- void testModifiers()
- {
- vmime::disposition disp1;
+ VASSERT_EQ("4", "amode/smode;type", disp.generate());
- assert_eq("1", false, disp1.hasModifier("foo"));
- assert_eq("2", 0, static_cast <int>(disp1.getModifierList().size()));
+ disp.addModifier("modif1");
- disp1.addModifier("bar");
+ VASSERT_EQ("5", "amode/smode;type/modif1", disp.generate());
- assert_eq("3", false, disp1.hasModifier("foo"));
- assert_eq("4", true, disp1.hasModifier("bar"));
- assert_eq("5", 1, static_cast <int>(disp1.getModifierList().size()));
+ disp.addModifier("modif2");
- disp1.addModifier("plop");
+ VASSERT_EQ("6", "amode/smode;type/modif1,modif2", disp.generate());
+ }
- assert_eq("6", false, disp1.hasModifier("foo"));
- assert_eq("7", true, disp1.hasModifier("bar"));
- assert_eq("8", true, disp1.hasModifier("plop"));
- assert_eq("9", 2, static_cast <int>(disp1.getModifierList().size()));
+ void testModifiers()
+ {
+ vmime::disposition disp1;
- disp1.removeModifier("bar");
+ VASSERT_EQ("1", false, disp1.hasModifier("foo"));
+ VASSERT_EQ("2", 0, static_cast <int>(disp1.getModifierList().size()));
- assert_eq("10", false, disp1.hasModifier("foo"));
- assert_eq("11", false, disp1.hasModifier("bar"));
- assert_eq("12", true, disp1.hasModifier("plop"));
- assert_eq("13", 1, static_cast <int>(disp1.getModifierList().size()));
+ disp1.addModifier("bar");
- disp1.removeModifier("PlOp");
+ VASSERT_EQ("3", false, disp1.hasModifier("foo"));
+ VASSERT_EQ("4", true, disp1.hasModifier("bar"));
+ VASSERT_EQ("5", 1, static_cast <int>(disp1.getModifierList().size()));
- assert_eq("14", false, disp1.hasModifier("foo"));
- assert_eq("15", false, disp1.hasModifier("bar"));
- assert_eq("16", false, disp1.hasModifier("plop"));
- assert_eq("17", 0, static_cast <int>(disp1.getModifierList().size()));
- }
+ disp1.addModifier("plop");
- public:
+ VASSERT_EQ("6", false, disp1.hasModifier("foo"));
+ VASSERT_EQ("7", true, disp1.hasModifier("bar"));
+ VASSERT_EQ("8", true, disp1.hasModifier("plop"));
+ VASSERT_EQ("9", 2, static_cast <int>(disp1.getModifierList().size()));
- dispositionTest() : suite("vmime::disposition")
- {
- vmime::platformDependant::setHandler<vmime::platforms::posix::posixHandler>();
+ disp1.removeModifier("bar");
- add("Parse", testcase(this, "Parse", &dispositionTest::testParse));
- add("Generate", testcase(this, "Generate", &dispositionTest::testGenerate));
+ VASSERT_EQ("10", false, disp1.hasModifier("foo"));
+ VASSERT_EQ("11", false, disp1.hasModifier("bar"));
+ VASSERT_EQ("12", true, disp1.hasModifier("plop"));
+ VASSERT_EQ("13", 1, static_cast <int>(disp1.getModifierList().size()));
- add("Modifiers", testcase(this, "Modifiers", &dispositionTest::testModifiers));
+ disp1.removeModifier("PlOp");
- suite::main().add("vmime::disposition", this);
- }
+ VASSERT_EQ("14", false, disp1.hasModifier("foo"));
+ VASSERT_EQ("15", false, disp1.hasModifier("bar"));
+ VASSERT_EQ("16", false, disp1.hasModifier("plop"));
+ VASSERT_EQ("17", 0, static_cast <int>(disp1.getModifierList().size()));
+ }
- };
+VMIME_TEST_SUITE_END
- dispositionTest* theTest = new dispositionTest();
-}
diff --git a/tests/parser/encoderTest.cpp b/tests/parser/encoderTest.cpp
index 55c83f83..38e4ff4e 100644
--- a/tests/parser/encoderTest.cpp
+++ b/tests/parser/encoderTest.cpp
@@ -17,282 +17,268 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
-#include "../lib/unit++/unit++.h"
+#include "tests/testUtils.hpp"
-#include <iostream>
-#include <ostream>
-#include "vmime/vmime.hpp"
-#include "vmime/platforms/posix/posixHandler.hpp"
+#define VMIME_TEST_SUITE encoderTest
+#define VMIME_TEST_SUITE_MODULE "Parser"
-using namespace unitpp;
+VMIME_TEST_SUITE_BEGIN
-namespace
-{
- class encoderTest : public suite
+ VMIME_TEST_LIST_BEGIN
+ VMIME_TEST(testBase64)
+ VMIME_TEST(testQuotedPrintable)
+ VMIME_TEST_LIST_END
+
+
+ // Encoding helper function
+ static const vmime::string encode(const vmime::string& name, const vmime::string& in, int maxLineLength = 0)
{
- // Encoding helper function
- static const vmime::string encode(const vmime::string& name, const vmime::string& in, int maxLineLength = 0)
- {
- vmime::ref <vmime::encoder> enc = vmime::encoderFactory::getInstance()->create(name);
+ vmime::ref <vmime::encoder> enc = vmime::encoderFactory::getInstance()->create(name);
- if (maxLineLength != 0)
- enc->getProperties()["maxlinelength"] = maxLineLength;
+ if (maxLineLength != 0)
+ enc->getProperties()["maxlinelength"] = maxLineLength;
- vmime::utility::inputStreamStringAdapter vin(in);
+ vmime::utility::inputStreamStringAdapter vin(in);
- std::ostringstream out;
- vmime::utility::outputStreamAdapter vout(out);
+ std::ostringstream out;
+ vmime::utility::outputStreamAdapter vout(out);
- enc->encode(vin, vout);
+ enc->encode(vin, vout);
- return (out.str());
- }
+ return (out.str());
+ }
- // Decoding helper function
- static const vmime::string decode(const vmime::string& name, const vmime::string& in, int maxLineLength = 0)
- {
- vmime::ref <vmime::encoder> enc = vmime::encoderFactory::getInstance()->create(name);
+ // Decoding helper function
+ static const vmime::string decode(const vmime::string& name, const vmime::string& in, int maxLineLength = 0)
+ {
+ vmime::ref <vmime::encoder> enc = vmime::encoderFactory::getInstance()->create(name);
- if (maxLineLength != 0)
- enc->getProperties()["maxlinelength"] = maxLineLength;
+ if (maxLineLength != 0)
+ enc->getProperties()["maxlinelength"] = maxLineLength;
- vmime::utility::inputStreamStringAdapter vin(in);
+ vmime::utility::inputStreamStringAdapter vin(in);
- std::ostringstream out;
- vmime::utility::outputStreamAdapter vout(out);
+ std::ostringstream out;
+ vmime::utility::outputStreamAdapter vout(out);
- enc->decode(vin, vout);
+ enc->decode(vin, vout);
- return (out.str());
- }
+ return (out.str());
+ }
- void testBase64()
+ void testBase64()
+ {
+ static const vmime::string testSuites[] =
{
- static const vmime::string testSuites[] =
- {
- // Test 1
- "",
+ // Test 1
+ "",
+
+ "",
- "",
+ // Test 2
+ "A",
- // Test 2
- "A",
+ "QQ==",
- "QQ==",
+ // Test 3
+ "AB",
- // Test 3
- "AB",
+ "QUI=",
- "QUI=",
+ // Test 4
+ "ABC",
- // Test 4
- "ABC",
+ "QUJD",
- "QUJD",
+ // Test 5
+ "foo",
- // Test 5
- "foo",
+ "Zm9v",
- "Zm9v",
+ // Test 6
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
- // Test 6
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
+ "QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAx"
+ "MjM0NTY3ODk=",
- "QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAx"
- "MjM0NTY3ODk=",
+ // Test 7
+ vmime::string(
+ "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
+ "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
+ "\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f"
+ "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f"
+ "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f"
+ "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f"
+ "\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f"
+ "\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f"
+ "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
+ "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
+ "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf"
+ "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf"
+ "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"
+ "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf"
+ "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef"
+ "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
+ 256),
- // Test 7
- vmime::string(
- "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
- "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
- "\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f"
- "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f"
- "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f"
- "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f"
- "\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f"
- "\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f"
- "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
- "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
- "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf"
- "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf"
- "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"
- "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf"
- "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef"
- "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
- 256),
+ "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1"
+ "Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWpr"
+ "bG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6Ch"
+ "oqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX"
+ "2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w=="
+ };
- "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1"
- "Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWpr"
- "bG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6Ch"
- "oqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX"
- "2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w=="
- };
+ for (unsigned int i = 0 ; i < sizeof(testSuites) / sizeof(testSuites[0]) / 2 ; ++i)
+ {
+ const vmime::string decoded = testSuites[i * 2];
+ const vmime::string encoded = testSuites[i * 2 + 1];
- for (unsigned int i = 0 ; i < sizeof(testSuites) / sizeof(testSuites[0]) / 2 ; ++i)
- {
- const vmime::string decoded = testSuites[i * 2];
- const vmime::string encoded = testSuites[i * 2 + 1];
+ std::ostringstream oss;
+ oss << "[Base64] Test " << (i + 1) << ": ";
- std::ostringstream oss;
- oss << "[Base64] Test " << (i + 1) << ": ";
+ // Encoding
+ VASSERT_EQ(oss.str() + "encoding", encoded, encode("base64", decoded));
- // Encoding
- assert_eq(oss.str() + "encoding", encoded, encode("base64", decoded));
+ // Decoding
+ VASSERT_EQ(oss.str() + "decoding", decoded, decode("base64", encoded));
- // Decoding
- assert_eq(oss.str() + "decoding", decoded, decode("base64", encoded));
+ // Multiple and successive encoding/decoding
+ VASSERT_EQ(oss.str() + "multiple1", decoded,
+ decode("base64",
+ encode("base64", decoded)));
- // Multiple and successive encoding/decoding
- assert_eq(oss.str() + "multiple1", decoded,
+ VASSERT_EQ(oss.str() + "multiple2", decoded,
+ decode("base64",
decode("base64",
- encode("base64", decoded)));
+ encode("base64",
+ encode("base64", decoded)))));
- assert_eq(oss.str() + "multiple2", decoded,
+ VASSERT_EQ(oss.str() + "multiple3", decoded,
+ decode("base64",
decode("base64",
decode("base64",
encode("base64",
- encode("base64", decoded)))));
-
- assert_eq(oss.str() + "multiple3", decoded,
- decode("base64",
- decode("base64",
- decode("base64",
encode("base64",
- encode("base64",
- encode("base64", decoded)))))));
+ encode("base64", decoded)))))));
- assert_eq(oss.str() + "multiple4", decoded,
+ VASSERT_EQ(oss.str() + "multiple4", decoded,
+ decode("base64",
decode("base64",
decode("base64",
decode("base64",
- decode("base64",
+ encode("base64",
encode("base64",
encode("base64",
- encode("base64",
- encode("base64", decoded)))))))));
- }
+ encode("base64", decoded)))))))));
}
+ }
- void testQuotedPrintable()
+ void testQuotedPrintable()
+ {
+ static const vmime::string testSuites[] =
{
- static const vmime::string testSuites[] =
- {
- // Test 1
- "",
-
- "",
-
- // Test 2
- "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
-
- "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
-
- // Test 3
- "0123456789012345678901234567890123456789012345678901234567890123456789012"
- "3456789012345678901234567890123456789012345678901234567890123456789012345"
- "6789",
-
- "0123456789012345678901234567890123456789012345678901234567890123456789012=\r\n"
- "3456789012345678901234567890123456789012345678901234567890123456789012345=\r\n"
- "6789",
-
- // Test 4
- vmime::string(
- "\x89\xe8\x24\x04\x2f\xe8\xff\xfb\xeb\xff\x90\xd7\x74\x8d\x00\x26\x89\x55"
- "\x83\xe5\x08\xec\x04\xc7\xa0\x24\x05\xa2\xe8\x08\x43\xee\x00\x00\xc0\x85"
- "\x0a\x74\xec\x89\xc3\x5d\xb6\x8d\x00\x00\x00\x00\x04\xc7\xa8\x24\x05\xa2"
- "\xe8\x08\x43\xd4\x00\x00\xe8\xeb\xf6\x89\x89\x55\x81\xe5\xa8\xec\x00\x00"
- "\x89\x00\xfc\x75\x75\x8b\x89\x08\xf8\x5d\xb9\xe8\xff\xff\x83\xff\x14\xfe"
- "\x47\x74\xc0\x31\x9d\x8d\xff\x68\xff\xff\x85\x89\xff\x68\xff\xff\x85\x8d"
- "\xff\x6c\xff\xff\x04\x89\xe8\x24\xfa\x50\xff\xff\x45\xc7\x00\xec\x00\x00"
- "\x31\x00\x89\xc0\x24\x44\x89\x08\x24\x5c\x89\x04\x24\x34\x87\xe8\xff\xf6"
- "\x89\xff\x24\x34\x2f\xe8\xff\xf9\x8b\xff\xf8\x5d\x75\x8b\x89\xfc\x5d\xec"
- "\xbe\xc3\x00\x13\x00\x00\xe7\xeb\xb6\x8d\x00\x00\x00\x00\x89\x55\x57\xe5"
- "\x53\x56\xec\x81\x01\xdc\x00\x00\x45\xbb\x05\x5c\x8b\x08\x0c\x55\xe4\x83"
- "\x8b\xf0\x89\x02\x24\x5c\xc7\x04\x24\x04\x00\x06\x00\x00\xec\xa3\x05\xa9"
- "\xe8\x08\xf7\x2a\xff\xff\x04\xc7\x46\x24\x05\x5c\xb9\x08\x5c\x50\x08\x05"
- "\x4c\x89\x04\x24\xf5\xe8\xff\xf7\xc7\xff\x24\x04\x5c\x46\x08\x05\xe9\xe8"
- "\xff\xf8\xc7\xff\x24\x04\x1d\x70\x08\x05\x55\xe8\x00\xbb\xb8\x00\x00\x01"
- "\x00\x00\xd2\x31\x08\xa3\x05\xa7\xb8\x08\x00\x01\x00\x00\x0c\xa3\x05\xa7",
- 18 * 16),
-
- "=89=E8$=04/=E8=FF=FB=EB=FF=90=D7t=8D=00&=89U=83=E5=08=EC=04=C7=A0$=05=A2=E8=\r\n"
- "=08C=EE=00=00=C0=85=0At=EC=89=C3]=B6=8D=00=00=00=00=04=C7=A8$=05=A2=E8=08=\r\n"
- "C=D4=00=00=E8=EB=F6=89=89U=81=E5=A8=EC=00=00=89=00=FCuu=8B=89=08=F8]=B9=E8=\r\n"
- "=FF=FF=83=FF=14=FEGt=C01=9D=8D=FFh=FF=FF=85=89=FFh=FF=FF=85=8D=FFl=FF=FF=04=\r\n"
- "=89=E8$=FAP=FF=FFE=C7=00=EC=00=001=00=89=C0$D=89=08$\\=89=04$4=87=E8=FF=F6=\r\n"
- "=89=FF$4/=E8=FF=F9=8B=FF=F8]u=8B=89=FC]=EC=BE=C3=00=13=00=00=E7=EB=B6=8D=00=\r\n"
- "=00=00=00=89UW=E5SV=EC=81=01=DC=00=00E=BB=05\\=8B=08=0CU=E4=83=8B=F0=89=02=\r\n"
- "$\\=C7=04$=04=00=06=00=00=EC=A3=05=A9=E8=08=F7*=FF=FF=04=C7F$=05\\=B9=08\\P=08=\r\n"
- "=05L=89=04$=F5=E8=FF=F7=C7=FF$=04\\F=08=05=E9=E8=FF=F8=C7=FF$=04=1Dp=08=05=\r\n"
- "U=E8=00=BB=B8=00=00=01=00=00=D21=08=A3=05=A7=B8=08=00=01=00=00=0C=A3=05=A7=\r\n"
- };
-
-
- for (unsigned int i = 0 ; i < sizeof(testSuites) / sizeof(testSuites[0]) / 2 ; ++i)
- {
- const vmime::string decoded = testSuites[i * 2];
- const vmime::string encoded = testSuites[i * 2 + 1];
-
- std::ostringstream oss;
- oss << "[QP] Test " << (i + 1) << ": ";
-
- // Encoding
- assert_eq(oss.str() + "encoding", encoded, encode("quoted-printable", decoded, 74));
-
- // Decoding
- assert_eq(oss.str() + "decoding", decoded, decode("quoted-printable", encoded, 74));
-
- // Multiple and successive encoding/decoding
- assert_eq(oss.str() + "multiple1", decoded,
- decode("quoted-printable",
- encode("quoted-printable", decoded)));
+ // Test 1
+ "",
+
+ "",
+
+ // Test 2
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
+
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
+
+ // Test 3
+ "0123456789012345678901234567890123456789012345678901234567890123456789012"
+ "3456789012345678901234567890123456789012345678901234567890123456789012345"
+ "6789",
+
+ "0123456789012345678901234567890123456789012345678901234567890123456789012=\r\n"
+ "3456789012345678901234567890123456789012345678901234567890123456789012345=\r\n"
+ "6789",
+
+ // Test 4
+ vmime::string(
+ "\x89\xe8\x24\x04\x2f\xe8\xff\xfb\xeb\xff\x90\xd7\x74\x8d\x00\x26\x89\x55"
+ "\x83\xe5\x08\xec\x04\xc7\xa0\x24\x05\xa2\xe8\x08\x43\xee\x00\x00\xc0\x85"
+ "\x0a\x74\xec\x89\xc3\x5d\xb6\x8d\x00\x00\x00\x00\x04\xc7\xa8\x24\x05\xa2"
+ "\xe8\x08\x43\xd4\x00\x00\xe8\xeb\xf6\x89\x89\x55\x81\xe5\xa8\xec\x00\x00"
+ "\x89\x00\xfc\x75\x75\x8b\x89\x08\xf8\x5d\xb9\xe8\xff\xff\x83\xff\x14\xfe"
+ "\x47\x74\xc0\x31\x9d\x8d\xff\x68\xff\xff\x85\x89\xff\x68\xff\xff\x85\x8d"
+ "\xff\x6c\xff\xff\x04\x89\xe8\x24\xfa\x50\xff\xff\x45\xc7\x00\xec\x00\x00"
+ "\x31\x00\x89\xc0\x24\x44\x89\x08\x24\x5c\x89\x04\x24\x34\x87\xe8\xff\xf6"
+ "\x89\xff\x24\x34\x2f\xe8\xff\xf9\x8b\xff\xf8\x5d\x75\x8b\x89\xfc\x5d\xec"
+ "\xbe\xc3\x00\x13\x00\x00\xe7\xeb\xb6\x8d\x00\x00\x00\x00\x89\x55\x57\xe5"
+ "\x53\x56\xec\x81\x01\xdc\x00\x00\x45\xbb\x05\x5c\x8b\x08\x0c\x55\xe4\x83"
+ "\x8b\xf0\x89\x02\x24\x5c\xc7\x04\x24\x04\x00\x06\x00\x00\xec\xa3\x05\xa9"
+ "\xe8\x08\xf7\x2a\xff\xff\x04\xc7\x46\x24\x05\x5c\xb9\x08\x5c\x50\x08\x05"
+ "\x4c\x89\x04\x24\xf5\xe8\xff\xf7\xc7\xff\x24\x04\x5c\x46\x08\x05\xe9\xe8"
+ "\xff\xf8\xc7\xff\x24\x04\x1d\x70\x08\x05\x55\xe8\x00\xbb\xb8\x00\x00\x01"
+ "\x00\x00\xd2\x31\x08\xa3\x05\xa7\xb8\x08\x00\x01\x00\x00\x0c\xa3\x05\xa7",
+ 18 * 16),
+
+ "=89=E8$=04/=E8=FF=FB=EB=FF=90=D7t=8D=00&=89U=83=E5=08=EC=04=C7=A0$=05=A2=E8=\r\n"
+ "=08C=EE=00=00=C0=85=0At=EC=89=C3]=B6=8D=00=00=00=00=04=C7=A8$=05=A2=E8=08=\r\n"
+ "C=D4=00=00=E8=EB=F6=89=89U=81=E5=A8=EC=00=00=89=00=FCuu=8B=89=08=F8]=B9=E8=\r\n"
+ "=FF=FF=83=FF=14=FEGt=C01=9D=8D=FFh=FF=FF=85=89=FFh=FF=FF=85=8D=FFl=FF=FF=04=\r\n"
+ "=89=E8$=FAP=FF=FFE=C7=00=EC=00=001=00=89=C0$D=89=08$\\=89=04$4=87=E8=FF=F6=\r\n"
+ "=89=FF$4/=E8=FF=F9=8B=FF=F8]u=8B=89=FC]=EC=BE=C3=00=13=00=00=E7=EB=B6=8D=00=\r\n"
+ "=00=00=00=89UW=E5SV=EC=81=01=DC=00=00E=BB=05\\=8B=08=0CU=E4=83=8B=F0=89=02=\r\n"
+ "$\\=C7=04$=04=00=06=00=00=EC=A3=05=A9=E8=08=F7*=FF=FF=04=C7F$=05\\=B9=08\\P=08=\r\n"
+ "=05L=89=04$=F5=E8=FF=F7=C7=FF$=04\\F=08=05=E9=E8=FF=F8=C7=FF$=04=1Dp=08=05=\r\n"
+ "U=E8=00=BB=B8=00=00=01=00=00=D21=08=A3=05=A7=B8=08=00=01=00=00=0C=A3=05=A7=\r\n"
+ };
+
+
+ for (unsigned int i = 0 ; i < sizeof(testSuites) / sizeof(testSuites[0]) / 2 ; ++i)
+ {
+ const vmime::string decoded = testSuites[i * 2];
+ const vmime::string encoded = testSuites[i * 2 + 1];
+
+ std::ostringstream oss;
+ oss << "[QP] Test " << (i + 1) << ": ";
+
+ // Encoding
+ VASSERT_EQ(oss.str() + "encoding", encoded, encode("quoted-printable", decoded, 74));
+
+ // Decoding
+ VASSERT_EQ(oss.str() + "decoding", decoded, decode("quoted-printable", encoded, 74));
+
+ // Multiple and successive encoding/decoding
+ VASSERT_EQ(oss.str() + "multiple1", decoded,
+ decode("quoted-printable",
+ encode("quoted-printable", decoded)));
- assert_eq(oss.str() + "multiple2", decoded,
+ VASSERT_EQ(oss.str() + "multiple2", decoded,
+ decode("quoted-printable",
decode("quoted-printable",
- decode("quoted-printable",
- encode("quoted-printable",
- encode("quoted-printable", decoded)))));
+ encode("quoted-printable",
+ encode("quoted-printable", decoded)))));
- assert_eq(oss.str() + "multiple3", decoded,
+ VASSERT_EQ(oss.str() + "multiple3", decoded,
+ decode("quoted-printable",
decode("quoted-printable",
decode("quoted-printable",
- decode("quoted-printable",
+ encode("quoted-printable",
encode("quoted-printable",
- encode("quoted-printable",
- encode("quoted-printable", decoded)))))));
+ encode("quoted-printable", decoded)))))));
- assert_eq(oss.str() + "multiple4", decoded,
+ VASSERT_EQ(oss.str() + "multiple4", decoded,
+ decode("quoted-printable",
decode("quoted-printable",
decode("quoted-printable",
decode("quoted-printable",
- decode("quoted-printable",
+ encode("quoted-printable",
encode("quoted-printable",
encode("quoted-printable",
- encode("quoted-printable",
- encode("quoted-printable", decoded)))))))));
- }
+ encode("quoted-printable", decoded)))))))));
}
+ }
- // TODO: UUEncode
-
- public:
-
- encoderTest() : suite("vmime::encoder")
- {
- vmime::platformDependant::setHandler<vmime::platforms::posix::posixHandler>();
-
- add("Base64", testcase(this, "Base64", &encoderTest::testBase64));
- add("QuotedPrintable", testcase(this, "QuotedPrintable", &encoderTest::testQuotedPrintable));
-
- suite::main().add("vmime::encoder", this);
- }
+ // TODO: UUEncode
- };
+VMIME_TEST_SUITE_END
- encoderTest* theTest = new encoderTest();
-}
diff --git a/tests/parser/headerTest.cpp b/tests/parser/headerTest.cpp
index 83f0409e..18325f5c 100644
--- a/tests/parser/headerTest.cpp
+++ b/tests/parser/headerTest.cpp
@@ -17,356 +17,341 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
-#include "../lib/unit++/unit++.h"
+#include "tests/testUtils.hpp"
-#include <iostream>
-#include <ostream>
-#include "vmime/vmime.hpp"
-#include "vmime/platforms/posix/posixHandler.hpp"
+#define VMIME_TEST_SUITE headerTest
+#define VMIME_TEST_SUITE_MODULE "Parser"
-using namespace unitpp;
+VMIME_TEST_SUITE_BEGIN
-namespace
-{
- class headerTest : public suite
- {
- static const std::string getFieldValue(const vmime::headerField& field)
- {
- std::ostringstream oss;
- vmime::utility::outputStreamAdapter voss(oss);
- field.generate(voss);
+ VMIME_TEST_LIST_BEGIN
+ VMIME_TEST(testHas1)
+ VMIME_TEST(testHas2)
- return (oss.str());
- }
+ VMIME_TEST(testAppend1)
+ VMIME_TEST(testAppend2)
- // has function tests
- void testHas1()
- {
- vmime::header hdr;
- hdr.parse("From: x\r\nTo: y\r\nTo: z\r\n");
+ VMIME_TEST(testInsertFieldBefore1)
+ VMIME_TEST(testInsertFieldBefore2)
- bool res = hdr.hasField("Z");
+ VMIME_TEST(testInsertFieldAfter1)
+ VMIME_TEST(testInsertFieldAfter2)
- assert_eq("Value", false, res);
- }
+ VMIME_TEST(testRemoveField1)
+ VMIME_TEST(testRemoveField2)
- void testHas2()
- {
- vmime::header hdr;
- hdr.parse("X: x\r\nTo: y\r\nTo: z\r\n");
+ VMIME_TEST(testRemoveAllFields)
- bool res = hdr.hasField("To");
+ VMIME_TEST(testgetFieldCount)
- assert_eq("Value", true, res);
- }
+ VMIME_TEST(testIsEmpty1)
+ VMIME_TEST(testIsEmpty2)
- // appendField function tests
- void testAppend1()
- {
- vmime::header hdr;
- hdr.parse("");
+ VMIME_TEST(testGetFieldAt)
- vmime::ref <vmime::headerField> hf = vmime::headerFieldFactory::getInstance()->create("A", "a");
- hdr.appendField(hf);
+ VMIME_TEST(testGetFieldList1)
+ VMIME_TEST(testGetFieldList2)
- std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
+ VMIME_TEST(testFind1)
- assert_eq("Count", static_cast <unsigned int>(1), res.size());
- assert_eq("First value", "A: a", headerTest::getFieldValue(*res[0]));
- }
+ VMIME_TEST(testFindAllFields1)
+ VMIME_TEST(testFindAllFields2)
+ VMIME_TEST(testFindAllFields3)
+ VMIME_TEST_LIST_END
- void testAppend2()
- {
- vmime::header hdr;
- hdr.parse("A: a\r\n");
- vmime::ref <vmime::headerField> hf = vmime::headerFieldFactory::getInstance()->create("B", "b");
- hdr.appendField(hf);
+ static const std::string getFieldValue(const vmime::headerField& field)
+ {
+ std::ostringstream oss;
+ vmime::utility::outputStreamAdapter voss(oss);
+ field.generate(voss);
- std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
+ return (oss.str());
+ }
- assert_eq("Count", static_cast <unsigned int>(2), res.size());
- assert_eq("First value", "A: a", headerTest::getFieldValue(*res[0]));
- assert_eq("Second value", "B: b", headerTest::getFieldValue(*res[1]));
- }
+ // has function tests
+ void testHas1()
+ {
+ vmime::header hdr;
+ hdr.parse("From: x\r\nTo: y\r\nTo: z\r\n");
- // insertFieldBefore
- void testInsertFieldBefore1()
- {
- vmime::header hdr;
- hdr.parse("A: a\r\nC: c\r\n");
+ bool res = hdr.hasField("Z");
- vmime::ref <vmime::headerField> hf = vmime::headerFieldFactory::getInstance()->create("B", "b");
- hdr.insertFieldBefore(hdr.getField("C"), hf);
+ VASSERT_EQ("Value", false, res);
+ }
- std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
+ void testHas2()
+ {
+ vmime::header hdr;
+ hdr.parse("X: x\r\nTo: y\r\nTo: z\r\n");
- assert_eq("Count", static_cast <unsigned int>(3), res.size());
- assert_eq("First value", "A: a", headerTest::getFieldValue(*res[0]));
- assert_eq("Second value", "B: b", headerTest::getFieldValue(*res[1]));
- assert_eq("Third value", "C: c", headerTest::getFieldValue(*res[2]));
- }
+ bool res = hdr.hasField("To");
- void testInsertFieldBefore2()
- {
- vmime::header hdr;
- hdr.parse("A: a\r\nC: c\r\n");
+ VASSERT_EQ("Value", true, res);
+ }
- vmime::ref <vmime::headerField> hf = vmime::headerFieldFactory::getInstance()->create("B", "b");
- hdr.insertFieldBefore(1, hf);
+ // appendField function tests
+ void testAppend1()
+ {
+ vmime::header hdr;
+ hdr.parse("");
- std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
+ vmime::ref <vmime::headerField> hf = vmime::headerFieldFactory::getInstance()->create("A", "a");
+ hdr.appendField(hf);
- assert_eq("Count", static_cast <unsigned int>(3), res.size());
- assert_eq("First value", "A: a", headerTest::getFieldValue(*res[0]));
- assert_eq("Second value", "B: b", headerTest::getFieldValue(*res[1]));
- assert_eq("Third value", "C: c", headerTest::getFieldValue(*res[2]));
- }
+ std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
- // insertFieldAfter
- void testInsertFieldAfter1()
- {
- vmime::header hdr;
- hdr.parse("A: a\r\nC: c\r\n");
+ VASSERT_EQ("Count", static_cast <unsigned int>(1), res.size());
+ VASSERT_EQ("First value", "A: a", headerTest::getFieldValue(*res[0]));
+ }
- vmime::ref <vmime::headerField> hf = vmime::headerFieldFactory::getInstance()->create("B", "b");
- hdr.insertFieldAfter(hdr.getField("A"), hf);
+ void testAppend2()
+ {
+ vmime::header hdr;
+ hdr.parse("A: a\r\n");
- std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
+ vmime::ref <vmime::headerField> hf = vmime::headerFieldFactory::getInstance()->create("B", "b");
+ hdr.appendField(hf);
- assert_eq("Count", static_cast <unsigned int>(3), res.size());
- assert_eq("First value", "A: a", headerTest::getFieldValue(*res[0]));
- assert_eq("Second value", "B: b", headerTest::getFieldValue(*res[1]));
- assert_eq("Third value", "C: c", headerTest::getFieldValue(*res[2]));
- }
+ std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
- void testInsertFieldAfter2()
- {
- vmime::header hdr;
- hdr.parse("A: a\r\nC: c\r\n");
+ VASSERT_EQ("Count", static_cast <unsigned int>(2), res.size());
+ VASSERT_EQ("First value", "A: a", headerTest::getFieldValue(*res[0]));
+ VASSERT_EQ("Second value", "B: b", headerTest::getFieldValue(*res[1]));
+ }
- vmime::ref <vmime::headerField> hf = vmime::headerFieldFactory::getInstance()->create("B", "b");
- hdr.insertFieldAfter(0, hf);
+ // insertFieldBefore
+ void testInsertFieldBefore1()
+ {
+ vmime::header hdr;
+ hdr.parse("A: a\r\nC: c\r\n");
- std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
+ vmime::ref <vmime::headerField> hf = vmime::headerFieldFactory::getInstance()->create("B", "b");
+ hdr.insertFieldBefore(hdr.getField("C"), hf);
- assert_eq("Count", static_cast <unsigned int>(3), res.size());
- assert_eq("First value", "A: a", headerTest::getFieldValue(*res[0]));
- assert_eq("Second value", "B: b", headerTest::getFieldValue(*res[1]));
- assert_eq("Third value", "C: c", headerTest::getFieldValue(*res[2]));
- }
+ std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
- // removeField
- void testRemoveField1()
- {
- vmime::header hdr1, hdr2;
- hdr1.parse("A: a\r\nB: b\r\nC: c\r\n");
- hdr2.parse("A: a\r\nB: b\r\nC: c\r\n");
-
- hdr1.removeField(hdr1.getField("B"));
- hdr2.removeField(1);
+ VASSERT_EQ("Count", static_cast <unsigned int>(3), res.size());
+ VASSERT_EQ("First value", "A: a", headerTest::getFieldValue(*res[0]));
+ VASSERT_EQ("Second value", "B: b", headerTest::getFieldValue(*res[1]));
+ VASSERT_EQ("Third value", "C: c", headerTest::getFieldValue(*res[2]));
+ }
- std::vector <vmime::ref <vmime::headerField> > res1 = hdr1.getFieldList();
-
- assert_eq("Count", static_cast <unsigned int>(2), res1.size());
- assert_eq("First value", "A: a", headerTest::getFieldValue(*res1[0]));
- assert_eq("Second value", "C: c", headerTest::getFieldValue(*res1[1]));
-
- std::vector <vmime::ref <vmime::headerField> > res2 = hdr2.getFieldList();
+ void testInsertFieldBefore2()
+ {
+ vmime::header hdr;
+ hdr.parse("A: a\r\nC: c\r\n");
- assert_eq("Count", static_cast <unsigned int>(2), res2.size());
- assert_eq("First value", "A: a", headerTest::getFieldValue(*res2[0]));
- assert_eq("Second value", "C: c", headerTest::getFieldValue(*res2[1]));
- }
-
- void testRemoveField2()
- {
- vmime::header hdr1, hdr2;
- hdr1.parse("A: a\r\n");
- hdr2.parse("A: a\r\n");
+ vmime::ref <vmime::headerField> hf = vmime::headerFieldFactory::getInstance()->create("B", "b");
+ hdr.insertFieldBefore(1, hf);
- hdr1.removeField(hdr1.getField("A"));
- hdr2.removeField(0);
-
- std::vector <vmime::ref <vmime::headerField> > res1 = hdr1.getFieldList();
- assert_eq("Count", static_cast <unsigned int>(0), res1.size());
-
- std::vector <vmime::ref <vmime::headerField> > res2 = hdr2.getFieldList();
- assert_eq("Count", static_cast <unsigned int>(0), res2.size());
- }
+ std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
- // removeAllFields
- void testRemoveAllFields()
- {
- vmime::header hdr1, hdr2;
- hdr1.parse("A: a\r\n");
- hdr2.parse("A: a\r\nB: b\r\n");
-
- hdr1.removeAllFields();
- hdr2.removeAllFields();
+ VASSERT_EQ("Count", static_cast <unsigned int>(3), res.size());
+ VASSERT_EQ("First value", "A: a", headerTest::getFieldValue(*res[0]));
+ VASSERT_EQ("Second value", "B: b", headerTest::getFieldValue(*res[1]));
+ VASSERT_EQ("Third value", "C: c", headerTest::getFieldValue(*res[2]));
+ }
- std::vector <vmime::ref <vmime::headerField> > res1 = hdr1.getFieldList();
- assert_eq("Count", static_cast <unsigned int>(0), res1.size());
+ // insertFieldAfter
+ void testInsertFieldAfter1()
+ {
+ vmime::header hdr;
+ hdr.parse("A: a\r\nC: c\r\n");
- std::vector <vmime::ref <vmime::headerField> > res2 = hdr2.getFieldList();
- assert_eq("Count", static_cast <unsigned int>(0), res2.size());
- }
+ vmime::ref <vmime::headerField> hf = vmime::headerFieldFactory::getInstance()->create("B", "b");
+ hdr.insertFieldAfter(hdr.getField("A"), hf);
- // getFieldCount
- void testgetFieldCount()
- {
- vmime::header hdr;
- hdr.parse("A: a\r\nB: b\r\nC: c\r\nD: d\r\n");
-
- assert_eq("Value", 4, hdr.getFieldCount());
- }
+ std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
- // isEmpty
- void testIsEmpty1()
- {
- vmime::header hdr;
- hdr.parse("A: a\r\nB: b\r\nC: c\r\n");
+ VASSERT_EQ("Count", static_cast <unsigned int>(3), res.size());
+ VASSERT_EQ("First value", "A: a", headerTest::getFieldValue(*res[0]));
+ VASSERT_EQ("Second value", "B: b", headerTest::getFieldValue(*res[1]));
+ VASSERT_EQ("Third value", "C: c", headerTest::getFieldValue(*res[2]));
+ }
- assert_eq("Value", false, hdr.isEmpty());
- }
+ void testInsertFieldAfter2()
+ {
+ vmime::header hdr;
+ hdr.parse("A: a\r\nC: c\r\n");
- void testIsEmpty2()
- {
- vmime::header hdr;
- hdr.parse("\r\n");
+ vmime::ref <vmime::headerField> hf = vmime::headerFieldFactory::getInstance()->create("B", "b");
+ hdr.insertFieldAfter(0, hf);
- assert_eq("Value", true, hdr.isEmpty());
- }
+ std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
- // getFieldAt
- void getFieldAt()
- {
- vmime::header hdr;
- hdr.parse("B: b\r\nA: a\r\nC: c\r\n");
+ VASSERT_EQ("Count", static_cast <unsigned int>(3), res.size());
+ VASSERT_EQ("First value", "A: a", headerTest::getFieldValue(*res[0]));
+ VASSERT_EQ("Second value", "B: b", headerTest::getFieldValue(*res[1]));
+ VASSERT_EQ("Third value", "C: c", headerTest::getFieldValue(*res[2]));
+ }
- vmime::ref <vmime::headerField> res = hdr.getFieldAt(2);
+ // removeField
+ void testRemoveField1()
+ {
+ vmime::header hdr1, hdr2;
+ hdr1.parse("A: a\r\nB: b\r\nC: c\r\n");
+ hdr2.parse("A: a\r\nB: b\r\nC: c\r\n");
- assert_eq("Value", "C: c", getFieldValue(*res));
- }
+ hdr1.removeField(hdr1.getField("B"));
+ hdr2.removeField(1);
- // getFieldList
- void testGetFieldList1()
- {
- vmime::header hdr;
- hdr.parse("A: a\r\nB: b1\r\nC: c\r\nB: b2\r\n");
+ std::vector <vmime::ref <vmime::headerField> > res1 = hdr1.getFieldList();
- std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
+ VASSERT_EQ("Count", static_cast <unsigned int>(2), res1.size());
+ VASSERT_EQ("First value", "A: a", headerTest::getFieldValue(*res1[0]));
+ VASSERT_EQ("Second value", "C: c", headerTest::getFieldValue(*res1[1]));
- assert_eq("Count", static_cast <unsigned int>(4), res.size());
- assert_eq("First value", "A: a", headerTest::getFieldValue(*res[0]));
- assert_eq("Second value", "B: b1", headerTest::getFieldValue(*res[1]));
- assert_eq("Third value", "C: c", headerTest::getFieldValue(*res[2]));
- assert_eq("Thourth value", "B: b2", headerTest::getFieldValue(*res[3]));
- }
+ std::vector <vmime::ref <vmime::headerField> > res2 = hdr2.getFieldList();
- void testGetFieldList2()
- {
- vmime::header hdr;
- hdr.parse("\r\n");
+ VASSERT_EQ("Count", static_cast <unsigned int>(2), res2.size());
+ VASSERT_EQ("First value", "A: a", headerTest::getFieldValue(*res2[0]));
+ VASSERT_EQ("Second value", "C: c", headerTest::getFieldValue(*res2[1]));
+ }
- std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
+ void testRemoveField2()
+ {
+ vmime::header hdr1, hdr2;
+ hdr1.parse("A: a\r\n");
+ hdr2.parse("A: a\r\n");
- assert_eq("Count", static_cast <unsigned int>(0), res.size());
- }
+ hdr1.removeField(hdr1.getField("A"));
+ hdr2.removeField(0);
- // find function tests
- void testFind1()
- {
- vmime::header hdr;
- hdr.parse("A: a\r\nB: b\r\nC: c\r\nB: d\r\n");
+ std::vector <vmime::ref <vmime::headerField> > res1 = hdr1.getFieldList();
+ VASSERT_EQ("Count", static_cast <unsigned int>(0), res1.size());
- vmime::ref <vmime::headerField> res = hdr.findField("B");
+ std::vector <vmime::ref <vmime::headerField> > res2 = hdr2.getFieldList();
+ VASSERT_EQ("Count", static_cast <unsigned int>(0), res2.size());
+ }
- assert_eq("Value", "B: b", getFieldValue(*res));
- }
+ // removeAllFields
+ void testRemoveAllFields()
+ {
+ vmime::header hdr1, hdr2;
+ hdr1.parse("A: a\r\n");
+ hdr2.parse("A: a\r\nB: b\r\n");
- // getAllByName function tests
- void testFindAllFields1()
- {
- vmime::header hdr;
- hdr.parse("A: a1\nC: c1\n");
+ hdr1.removeAllFields();
+ hdr2.removeAllFields();
- std::vector <vmime::ref <vmime::headerField> > res = hdr.findAllFields("B");
+ std::vector <vmime::ref <vmime::headerField> > res1 = hdr1.getFieldList();
+ VASSERT_EQ("Count", static_cast <unsigned int>(0), res1.size());
- assert_eq("Count", static_cast <unsigned int>(0), res.size());
- }
+ std::vector <vmime::ref <vmime::headerField> > res2 = hdr2.getFieldList();
+ VASSERT_EQ("Count", static_cast <unsigned int>(0), res2.size());
+ }
- void testFindAllFields2()
- {
- vmime::header hdr;
- hdr.parse("A: a1\nB: b1\nB: b2\nC: c1\n");
+ // getFieldCount
+ void testgetFieldCount()
+ {
+ vmime::header hdr;
+ hdr.parse("A: a\r\nB: b\r\nC: c\r\nD: d\r\n");
- std::vector <vmime::ref <vmime::headerField> > res = hdr.findAllFields("B");
+ VASSERT_EQ("Value", 4, hdr.getFieldCount());
+ }
- assert_eq("Count", static_cast <unsigned int>(2), res.size());
- assert_eq("First value", "B: b1", headerTest::getFieldValue(*res[0]));
- assert_eq("Second value", "B: b2", headerTest::getFieldValue(*res[1]));
- }
+ // isEmpty
+ void testIsEmpty1()
+ {
+ vmime::header hdr;
+ hdr.parse("A: a\r\nB: b\r\nC: c\r\n");
- void testFindAllFields3()
- {
- vmime::header hdr;
- hdr.parse("A: a1\nB: b1\nB: b2\nC: c1\nC: c3\nC: c2\n");
+ VASSERT_EQ("Value", false, hdr.isEmpty());
+ }
- std::vector <vmime::ref <vmime::headerField> > res = hdr.findAllFields("C");
+ void testIsEmpty2()
+ {
+ vmime::header hdr;
+ hdr.parse("\r\n");
+
+ VASSERT_EQ("Value", true, hdr.isEmpty());
+ }
+
+ // getFieldAt
+ void testGetFieldAt()
+ {
+ vmime::header hdr;
+ hdr.parse("B: b\r\nA: a\r\nC: c\r\n");
+
+ vmime::ref <vmime::headerField> res = hdr.getFieldAt(2);
+
+ VASSERT_EQ("Value", "C: c", getFieldValue(*res));
+ }
+
+ // getFieldList
+ void testGetFieldList1()
+ {
+ vmime::header hdr;
+ hdr.parse("A: a\r\nB: b1\r\nC: c\r\nB: b2\r\n");
- assert_eq("Count", static_cast <unsigned int>(3), res.size());
- assert_eq("First value", "C: c1", headerTest::getFieldValue(*res[0]));
- assert_eq("Second value", "C: c3", headerTest::getFieldValue(*res[1]));
- assert_eq("Second value", "C: c2", headerTest::getFieldValue(*res[2]));
- }
+ std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
- public:
+ VASSERT_EQ("Count", static_cast <unsigned int>(4), res.size());
+ VASSERT_EQ("First value", "A: a", headerTest::getFieldValue(*res[0]));
+ VASSERT_EQ("Second value", "B: b1", headerTest::getFieldValue(*res[1]));
+ VASSERT_EQ("Third value", "C: c", headerTest::getFieldValue(*res[2]));
+ VASSERT_EQ("Thourth value", "B: b2", headerTest::getFieldValue(*res[3]));
+ }
- headerTest() : suite("vmime::header")
- {
- // VMime initialization
- vmime::platformDependant::setHandler<vmime::platforms::posix::posixHandler>();
+ void testGetFieldList2()
+ {
+ vmime::header hdr;
+ hdr.parse("\r\n");
- add("Has", testcase(this, "Has1", &headerTest::testHas1));
- add("Has", testcase(this, "Has2", &headerTest::testHas2));
+ std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
- add("Append", testcase(this, "Append1", &headerTest::testAppend1));
- add("Append", testcase(this, "Append2", &headerTest::testAppend2));
+ VASSERT_EQ("Count", static_cast <unsigned int>(0), res.size());
+ }
- add("InsertFieldBefore", testcase(this, "InsertFieldBefore1", &headerTest::testInsertFieldBefore1));
- add("InsertFieldBefore", testcase(this, "InsertFieldBefore2", &headerTest::testInsertFieldBefore2));
+ // find function tests
+ void testFind1()
+ {
+ vmime::header hdr;
+ hdr.parse("A: a\r\nB: b\r\nC: c\r\nB: d\r\n");
- add("InsertFieldAfter", testcase(this, "InsertFieldAfter1", &headerTest::testInsertFieldAfter1));
- add("InsertFieldAfter", testcase(this, "InsertFieldAfter2", &headerTest::testInsertFieldAfter2));
+ vmime::ref <vmime::headerField> res = hdr.findField("B");
- add("RemoveField", testcase(this, "RemoveField1", &headerTest::testRemoveField1));
- add("RemoveField", testcase(this, "RemoveField2", &headerTest::testRemoveField2));
+ VASSERT_EQ("Value", "B: b", getFieldValue(*res));
+ }
- add("RemoveAllFields", testcase(this, "RemoveAllFields", &headerTest::testRemoveAllFields));
+ // getAllByName function tests
+ void testFindAllFields1()
+ {
+ vmime::header hdr;
+ hdr.parse("A: a1\nC: c1\n");
- add("GetFieldCount", testcase(this, "GetFieldCount", &headerTest::testgetFieldCount));
+ std::vector <vmime::ref <vmime::headerField> > res = hdr.findAllFields("B");
- add("IsEmpty", testcase(this, "IsEmpty1", &headerTest::testIsEmpty1));
- add("IsEmpty", testcase(this, "IsEmpty2", &headerTest::testIsEmpty2));
+ VASSERT_EQ("Count", static_cast <unsigned int>(0), res.size());
+ }
- add("GetFieldAt", testcase(this, "GetFieldAt", &headerTest::getFieldAt));
+ void testFindAllFields2()
+ {
+ vmime::header hdr;
+ hdr.parse("A: a1\nB: b1\nB: b2\nC: c1\n");
+
+ std::vector <vmime::ref <vmime::headerField> > res = hdr.findAllFields("B");
- add("GetFieldList", testcase(this, "GetFieldList1", &headerTest::testGetFieldList1));
- add("GetFieldList", testcase(this, "GetFieldList2", &headerTest::testGetFieldList2));
+ VASSERT_EQ("Count", static_cast <unsigned int>(2), res.size());
+ VASSERT_EQ("First value", "B: b1", headerTest::getFieldValue(*res[0]));
+ VASSERT_EQ("Second value", "B: b2", headerTest::getFieldValue(*res[1]));
+ }
- add("Find", testcase(this, "Find1", &headerTest::testFind1));
+ void testFindAllFields3()
+ {
+ vmime::header hdr;
+ hdr.parse("A: a1\nB: b1\nB: b2\nC: c1\nC: c3\nC: c2\n");
- add("FindAllFields", testcase(this, "FindAllFields1", &headerTest::testFindAllFields1));
- add("FindAllFields", testcase(this, "FindAllFields2", &headerTest::testFindAllFields2));
- add("FindAllFields", testcase(this, "FindAllFields3", &headerTest::testFindAllFields3));
+ std::vector <vmime::ref <vmime::headerField> > res = hdr.findAllFields("C");
- suite::main().add("vmime::header", this);
- }
+ VASSERT_EQ("Count", static_cast <unsigned int>(3), res.size());
+ VASSERT_EQ("First value", "C: c1", headerTest::getFieldValue(*res[0]));
+ VASSERT_EQ("Second value", "C: c3", headerTest::getFieldValue(*res[1]));
+ VASSERT_EQ("Second value", "C: c2", headerTest::getFieldValue(*res[2]));
+ }
- };
+VMIME_TEST_SUITE_END
- headerTest* theTest = new headerTest();
-}
diff --git a/tests/parser/mailboxTest.cpp b/tests/parser/mailboxTest.cpp
index 3c991b61..b4683ca2 100644
--- a/tests/parser/mailboxTest.cpp
+++ b/tests/parser/mailboxTest.cpp
@@ -17,113 +17,97 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
-#include "../lib/unit++/unit++.h"
+#include "tests/testUtils.hpp"
-#include <iostream>
-#include <ostream>
-#include "vmime/vmime.hpp"
-#include "vmime/platforms/posix/posixHandler.hpp"
+#define VMIME_TEST_SUITE mailboxTest
+#define VMIME_TEST_SUITE_MODULE "Parser"
-#include "tests/parser/testUtils.hpp"
-using namespace unitpp;
+VMIME_TEST_SUITE_BEGIN
+ VMIME_TEST_LIST_BEGIN
+ VMIME_TEST(testParse)
+ VMIME_TEST_LIST_END
-namespace
-{
- class mailboxTest : public suite
+
+ void testParse()
{
- void testParse()
+ static const vmime::string testSuitesParse[] =
{
- 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 protected]]]]",
-
- // 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 1
+ "My (this is a comment)name <me(another \\)comment) @ somewhere(else).com>",
- // Test 3
- "John Doe <[email protected]>",
+ "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=My name]]], [email protected]]]]",
- "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=John Doe]]], [email protected]]]]",
+ // 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>",
- // Test 4
- "[email protected] (John Doe)",
+ "[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]]]",
- "[address-list: [[mailbox: name=[text: []], [email protected]]]]",
+ // Test 3
+ "John Doe <[email protected]>",
- // Test 5
- "John.Doe (ignore) @acme.com (John Doe)",
+ "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=John Doe]]], [email protected]]]]",
- "[address-list: [[mailbox: name=[text: []], [email protected]]]]",
+ // Test 4
+ "[email protected] (John Doe)",
- // Test 6
+ "[address-list: [[mailbox: name=[text: []], [email protected]]]]",
- "[address-list: [[mailbox: name=[text: []], [email protected]]]]",
+ // Test 5
+ "John.Doe (ignore) @acme.com (John Doe)",
- // Test 7
+ "[address-list: [[mailbox: name=[text: []], [email protected]]]]",
- "[address-list: [[mailbox: name=[text: []], [email protected]]]]",
+ // Test 6
- // Test 8
- "\"John Doe\" <[email protected]>",
+ "[address-list: [[mailbox: name=[text: []], [email protected]]]]",
- "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=John Doe]]], [email protected]]]]",
+ // Test 7
- // Test 9
- "=?us-ascii?q?John?=<[email protected]>",
+ "[address-list: [[mailbox: name=[text: []], [email protected]]]]",
- "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=John]]], [email protected]]]]",
+ // Test 8
+ "\"John Doe\" <[email protected]>",
- // Test 10
- "\"John\"<[email protected]>",
+ "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=John Doe]]], [email protected]]]]",
- "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=John]]], [email protected]]]]",
+ // Test 9
+ "=?us-ascii?q?John?=<[email protected]>",
- // Test 11
+ "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=John]]], [email protected]]]]",
- "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=John]]], [email protected]]]]"
- };
+ // Test 10
+ "\"John\"<[email protected]>",
- 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];
+ "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=John]]], [email protected]]]]",
- std::ostringstream oss;
- oss << "Test " << (i + 1);
+ // Test 11
- vmime::addressList addrList;
- addrList.parse(in);
+ "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=John]]], [email protected]]]]"
+ };
- std::ostringstream cmp;
- cmp << addrList;
-
- assert_eq(oss.str(), out, cmp.str());
- }
- }
+ 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];
- public:
+ std::ostringstream oss;
+ oss << "Test " << (i + 1);
- mailboxTest() : suite("vmime::mailbox")
- {
- vmime::platformDependant::setHandler<vmime::platforms::posix::posixHandler>();
+ vmime::addressList addrList;
+ addrList.parse(in);
- add("Parse", testcase(this, "Parse", &mailboxTest::testParse));
+ std::ostringstream cmp;
+ cmp << addrList;
- suite::main().add("vmime::mailbox", this);
+ VASSERT_EQ(oss.str(), out, cmp.str());
}
+ }
- };
+VMIME_TEST_SUITE_END
- mailboxTest* theTest = new mailboxTest();
-}
diff --git a/tests/parser/mediaTypeTest.cpp b/tests/parser/mediaTypeTest.cpp
index 52da8096..868fdab6 100644
--- a/tests/parser/mediaTypeTest.cpp
+++ b/tests/parser/mediaTypeTest.cpp
@@ -17,99 +17,85 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
-#include "../lib/unit++/unit++.h"
+#include "tests/testUtils.hpp"
-#include <iostream>
-#include <ostream>
-#include "vmime/vmime.hpp"
-#include "vmime/platforms/posix/posixHandler.hpp"
+#define VMIME_TEST_SUITE mediaTypeTest
+#define VMIME_TEST_SUITE_MODULE "Parser"
-using namespace unitpp;
+VMIME_TEST_SUITE_BEGIN
-namespace
-{
- class mediaTypeTest : public suite
- {
- void testConstructors()
- {
- vmime::mediaType t1;
-
- assert_eq("1.1", vmime::mediaTypes::APPLICATION, t1.getType());
- assert_eq("1.2", vmime::mediaTypes::APPLICATION_OCTET_STREAM, t1.getSubType());
+ VMIME_TEST_LIST_BEGIN
+ VMIME_TEST(testConstructors)
+ VMIME_TEST(testCopy)
+ VMIME_TEST(testSetFromString)
+ VMIME_TEST(testParse)
+ VMIME_TEST(testGenerate)
+ VMIME_TEST_LIST_END
- vmime::mediaType t2("type", "sub");
- assert_eq("2.1", "type", t2.getType());
- assert_eq("2.2", "sub", t2.getSubType());
-
- vmime::mediaType t3("type/sub");
+ void testConstructors()
+ {
+ vmime::mediaType t1;
- assert_eq("3.1", "type", t3.getType());
- assert_eq("3.2", "sub", t3.getSubType());
- }
+ VASSERT_EQ("1.1", vmime::mediaTypes::APPLICATION, t1.getType());
+ VASSERT_EQ("1.2", vmime::mediaTypes::APPLICATION_OCTET_STREAM, t1.getSubType());
- void testCopy()
- {
- vmime::mediaType t1("type/sub");
+ vmime::mediaType t2("type", "sub");
- assert_eq("eq1", "type", t1.getType());
- assert_eq("eq2", "sub", t1.getSubType());
+ VASSERT_EQ("2.1", "type", t2.getType());
+ VASSERT_EQ("2.2", "sub", t2.getSubType());
- assert_true("operator==", t1 == t1);
- assert_true("clone", t1 == *vmime::clone(t1));
+ vmime::mediaType t3("type/sub");
- assert_eq("eq3", "type", vmime::clone(t1)->getType());
- assert_eq("eq4", "sub", vmime::clone(t1)->getSubType());
+ VASSERT_EQ("3.1", "type", t3.getType());
+ VASSERT_EQ("3.2", "sub", t3.getSubType());
+ }
- vmime::mediaType t2;
- t2.copyFrom(t1);
+ void testCopy()
+ {
+ vmime::mediaType t1("type/sub");
- assert_true("copyFrom", t1 == t2);
- }
+ VASSERT_EQ("eq1", "type", t1.getType());
+ VASSERT_EQ("eq2", "sub", t1.getSubType());
- void testSetFromString()
- {
- vmime::mediaType t1;
- t1.setFromString("type/sub");
+ VASSERT("operator==", t1 == t1);
+ VASSERT("clone", t1 == *vmime::clone(t1));
- assert_eq("1.1", "type", t1.getType());
- assert_eq("1.2", "sub", t1.getSubType());
- }
+ VASSERT_EQ("eq3", "type", vmime::clone(t1)->getType());
+ VASSERT_EQ("eq4", "sub", vmime::clone(t1)->getSubType());
- void testParse()
- {
- vmime::mediaType t1;
- t1.parse("type/sub");
+ vmime::mediaType t2;
+ t2.copyFrom(t1);
- assert_eq("1.1", "type", t1.getType());
- assert_eq("1.2", "sub", t1.getSubType());
- }
+ VASSERT("copyFrom", t1 == t2);
+ }
- void testGenerate()
- {
- vmime::mediaType t1("type", "sub");
+ void testSetFromString()
+ {
+ vmime::mediaType t1;
+ t1.setFromString("type/sub");
- assert_eq("1", "type/sub", t1.generate());
- }
+ VASSERT_EQ("1.1", "type", t1.getType());
+ VASSERT_EQ("1.2", "sub", t1.getSubType());
+ }
- public:
+ void testParse()
+ {
+ vmime::mediaType t1;
+ t1.parse("type/sub");
- mediaTypeTest() : suite("vmime::mediaType")
- {
- vmime::platformDependant::setHandler<vmime::platforms::posix::posixHandler>();
+ VASSERT_EQ("1.1", "type", t1.getType());
+ VASSERT_EQ("1.2", "sub", t1.getSubType());
+ }
- add("Constructors", testcase(this, "Constructors", &mediaTypeTest::testConstructors));
- add("Copy", testcase(this, "Copy", &mediaTypeTest::testCopy));
- add("SetFromString", testcase(this, "SetFromString", &mediaTypeTest::testSetFromString));
- add("Parse", testcase(this, "Parse", &mediaTypeTest::testParse));
- add("Generate", testcase(this, "Generate", &mediaTypeTest::testGenerate));
+ void testGenerate()
+ {
+ vmime::mediaType t1("type", "sub");
- suite::main().add("vmime::mediaType", this);
- }
+ VASSERT_EQ("1", "type/sub", t1.generate());
+ }
- };
+VMIME_TEST_SUITE_END
- mediaTypeTest* theTest = new mediaTypeTest();
-}
diff --git a/tests/parser/messageIdSequenceTest.cpp b/tests/parser/messageIdSequenceTest.cpp
index 6382adef..f9a1ede5 100644
--- a/tests/parser/messageIdSequenceTest.cpp
+++ b/tests/parser/messageIdSequenceTest.cpp
@@ -17,79 +17,63 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
-#include "../lib/unit++/unit++.h"
+#include "tests/testUtils.hpp"
-#include <iostream>
-#include <ostream>
-#include "vmime/vmime.hpp"
-#include "vmime/platforms/posix/posixHandler.hpp"
+#define VMIME_TEST_SUITE messageIdSequenceTest
+#define VMIME_TEST_SUITE_MODULE "Parser"
-#include "tests/parser/testUtils.hpp"
-using namespace unitpp;
+VMIME_TEST_SUITE_BEGIN
+ VMIME_TEST_LIST_BEGIN
+ VMIME_TEST(testParse)
+ VMIME_TEST(testGenerate)
+ VMIME_TEST_LIST_END
-namespace
-{
- class messageIdSequenceTest : public suite
- {
- void testParse()
- {
- vmime::messageIdSequence s1;
- s1.parse("");
-
- assert_eq("1", 0, s1.getMessageIdCount());
-
- vmime::messageIdSequence s2;
- s2.parse(" \t ");
- assert_eq("2", 0, s2.getMessageIdCount());
-
- vmime::messageIdSequence s3;
- s3.parse("<a@b>");
+ void testParse()
+ {
+ vmime::messageIdSequence s1;
+ s1.parse("");
- assert_eq("3.1", 1, s3.getMessageIdCount());
- assert_eq("3.2", "a", s3.getMessageIdAt(0)->getLeft());
- assert_eq("3.3", "b", s3.getMessageIdAt(0)->getRight());
+ VASSERT_EQ("1", 0, s1.getMessageIdCount());
- vmime::messageIdSequence s4;
- s4.parse("<a@b> \r\n\t<c@d>");
+ vmime::messageIdSequence s2;
+ s2.parse(" \t ");
- assert_eq("4.1", 2, s4.getMessageIdCount());
- assert_eq("4.2", "a", s4.getMessageIdAt(0)->getLeft());
- assert_eq("4.3", "b", s4.getMessageIdAt(0)->getRight());
- assert_eq("4.4", "c", s4.getMessageIdAt(1)->getLeft());
- assert_eq("4.5", "d", s4.getMessageIdAt(1)->getRight());
- }
+ VASSERT_EQ("2", 0, s2.getMessageIdCount());
- void testGenerate()
- {
- vmime::messageIdSequence s1;
- s1.appendMessageId(vmime::create <vmime::messageId>("a", "b"));
+ vmime::messageIdSequence s3;
+ s3.parse("<a@b>");
- assert_eq("1", "<a@b>", s1.generate());
+ VASSERT_EQ("3.1", 1, s3.getMessageIdCount());
+ VASSERT_EQ("3.2", "a", s3.getMessageIdAt(0)->getLeft());
+ VASSERT_EQ("3.3", "b", s3.getMessageIdAt(0)->getRight());
- vmime::messageIdSequence s2;
- s2.appendMessageId(vmime::create <vmime::messageId>("a", "b"));
- s2.appendMessageId(vmime::create <vmime::messageId>("c", "d"));
+ vmime::messageIdSequence s4;
+ s4.parse("<a@b> \r\n\t<c@d>");
- assert_eq("2", "<a@b> <c@d>", s2.generate());
- }
+ VASSERT_EQ("4.1", 2, s4.getMessageIdCount());
+ VASSERT_EQ("4.2", "a", s4.getMessageIdAt(0)->getLeft());
+ VASSERT_EQ("4.3", "b", s4.getMessageIdAt(0)->getRight());
+ VASSERT_EQ("4.4", "c", s4.getMessageIdAt(1)->getLeft());
+ VASSERT_EQ("4.5", "d", s4.getMessageIdAt(1)->getRight());
+ }
- public:
+ void testGenerate()
+ {
+ vmime::messageIdSequence s1;
+ s1.appendMessageId(vmime::create <vmime::messageId>("a", "b"));
- messageIdSequenceTest() : suite("vmime::messageIdSequence")
- {
- vmime::platformDependant::setHandler<vmime::platforms::posix::posixHandler>();
+ VASSERT_EQ("1", "<a@b>", s1.generate());
- add("Parse", testcase(this, "Parse", &messageIdSequenceTest::testParse));
- add("Generate", testcase(this, "Generate", &messageIdSequenceTest::testGenerate));
+ vmime::messageIdSequence s2;
+ s2.appendMessageId(vmime::create <vmime::messageId>("a", "b"));
+ s2.appendMessageId(vmime::create <vmime::messageId>("c", "d"));
- suite::main().add("vmime::messageIdSequence", this);
- }
+ VASSERT_EQ("2", "<a@b> <c@d>", s2.generate());
+ }
- };
+VMIME_TEST_SUITE_END
- messageIdSequenceTest* theTest = new messageIdSequenceTest();
-}
diff --git a/tests/parser/messageIdTest.cpp b/tests/parser/messageIdTest.cpp
index e05ac9c1..1c0661cd 100644
--- a/tests/parser/messageIdTest.cpp
+++ b/tests/parser/messageIdTest.cpp
@@ -17,68 +17,52 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
-#include "../lib/unit++/unit++.h"
+#include "tests/testUtils.hpp"
-#include <iostream>
-#include <ostream>
-#include "vmime/vmime.hpp"
-#include "vmime/platforms/posix/posixHandler.hpp"
+#define VMIME_TEST_SUITE messageIdTest
+#define VMIME_TEST_SUITE_MODULE "Parser"
-#include "tests/parser/testUtils.hpp"
-using namespace unitpp;
+VMIME_TEST_SUITE_BEGIN
+ VMIME_TEST_LIST_BEGIN
+ VMIME_TEST(testParse)
+ VMIME_TEST(testGenerate)
+ VMIME_TEST_LIST_END
-namespace
-{
- class messageIdTest : public suite
- {
- void testParse()
- {
- vmime::messageId m1;
- m1.parse("<a@b>");
-
- assert_eq("1.1", "a", m1.getLeft());
- assert_eq("1.2", "b", m1.getRight());
- }
-
- void testGenerate()
- {
- vmime::messageId m1;
- assert_eq("1", "<@>", m1.generate());
-
- vmime::messageId m2;
- m2.setLeft("a");
+ void testParse()
+ {
+ vmime::messageId m1;
+ m1.parse("<a@b>");
- assert_eq("2", "<a@>", m2.generate());
+ VASSERT_EQ("1.1", "a", m1.getLeft());
+ VASSERT_EQ("1.2", "b", m1.getRight());
+ }
- vmime::messageId m3;
- m3.setRight("b");
+ void testGenerate()
+ {
+ vmime::messageId m1;
- assert_eq("3", "<@b>", m3.generate());
+ VASSERT_EQ("1", "<@>", m1.generate());
- vmime::messageId m4;
- m4.setLeft("a");
- m4.setRight("b");
+ vmime::messageId m2;
+ m2.setLeft("a");
- assert_eq("4", "<a@b>", m4.generate());
- }
+ VASSERT_EQ("2", "<a@>", m2.generate());
- public:
+ vmime::messageId m3;
+ m3.setRight("b");
- messageIdTest() : suite("vmime::messageId")
- {
- vmime::platformDependant::setHandler<vmime::platforms::posix::posixHandler>();
+ VASSERT_EQ("3", "<@b>", m3.generate());
- add("Parse", testcase(this, "Parse", &messageIdTest::testParse));
- add("Generate", testcase(this, "Generate", &messageIdTest::testGenerate));
+ vmime::messageId m4;
+ m4.setLeft("a");
+ m4.setRight("b");
- suite::main().add("vmime::messageId", this);
- }
+ VASSERT_EQ("4", "<a@b>", m4.generate());
+ }
- };
+VMIME_TEST_SUITE_END
- messageIdTest* theTest = new messageIdTest();
-}
diff --git a/tests/parser/parameterTest.cpp b/tests/parser/parameterTest.cpp
index 9b3bd66a..5f838fe1 100644
--- a/tests/parser/parameterTest.cpp
+++ b/tests/parser/parameterTest.cpp
@@ -17,21 +17,21 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
-#include "../lib/unit++/unit++.h"
+#include "tests/testUtils.hpp"
-#include <iostream>
-#include <ostream>
-#include "vmime/vmime.hpp"
-#include "vmime/platforms/posix/posixHandler.hpp"
+#define VMIME_TEST_SUITE parameterTest
+#define VMIME_TEST_SUITE_MODULE "Parser"
-#include "tests/parser/testUtils.hpp"
-using namespace unitpp;
+VMIME_TEST_SUITE_BEGIN
+
+ VMIME_TEST_LIST_BEGIN
+ VMIME_TEST(testParse)
+ VMIME_TEST(testGenerate)
+ VMIME_TEST_LIST_END
-namespace
-{
// HACK: parameterizedHeaderField constructor is private
class parameterizedHeaderField : public vmime::parameterizedHeaderField
{
@@ -65,193 +65,177 @@ namespace
(p.getParameterAt(n).staticCast <vmime::defaultParameter>())->getValue().getBuffer())
- class parameterTest : public suite
+ void testParse()
{
- void testParse()
- {
- // Simple parameter
- parameterizedHeaderField p1;
- p1.parse("X; param1=value1;\r\n");
-
- assert_eq("1.1", 1, p1.getParameterCount());
- assert_eq("1.2", "param1", PARAM_NAME(p1, 0));
- assert_eq("1.3", "value1", PARAM_VALUE(p1, 0));
-
- // Multi-section parameters (1/2)
- parameterizedHeaderField p2a;
- p2a.parse("X; param1=value1;\r\n"
- " param2*0=\"val\";\r\n"
- " param2*1=\"ue2\";");
-
- assert_eq("2a.1", 2, p2a.getParameterCount());
- assert_eq("2a.2", "param1", PARAM_NAME(p2a, 0));
- assert_eq("2a.3", "value1", PARAM_VALUE(p2a, 0));
- assert_eq("2a.4", "param2", PARAM_NAME(p2a, 1));
- assert_eq("2a.5", "value2", PARAM_VALUE(p2a, 1));
-
- // Multi-section parameters (2/2)
- parameterizedHeaderField p2b;
- p2b.parse("X; param1=value1;\r\n"
- " param2=\"should be ignored\";\r\n"
- " param2*0=\"val\";\r\n"
- " param2*1=\"ue2\";");
-
- assert_eq("2b.1", 2, p2b.getParameterCount());
- assert_eq("2b.2", "param1", PARAM_NAME(p2b, 0));
- assert_eq("2b.3", "value1", PARAM_VALUE(p2b, 0));
- assert_eq("2b.4", "param2", PARAM_NAME(p2b, 1));
- assert_eq("2b.5", "value2", PARAM_VALUE(p2b, 1));
-
- // Extended parameter (charset and language information)
- parameterizedHeaderField p3;
- p3.parse("X; param1*=charset'language'value1;\r\n");
-
- assert_eq("3.1", 1, p3.getParameterCount());
- assert_eq("3.2", "param1", PARAM_NAME(p3, 0));
- assert_eq("3.3", "charset", PARAM_CHARSET(p3, 0));
- assert_eq("3.4", "value1", PARAM_BUFFER(p3, 0));
-
- // Encoded characters in extended parameter values
- parameterizedHeaderField p4;
- p4.parse("X; param1*=a%20value%20with%20multiple%20word%73"); // 0x73 = 's'
-
- assert_eq("4.1", 1, p4.getParameterCount());
- assert_eq("4.2", "param1", PARAM_NAME(p4, 0));
- assert_eq("4.3", "a value with multiple words", PARAM_VALUE(p4, 0));
-
- // Invalid encoded character
- parameterizedHeaderField p5;
- p5.parse("X; param1*=test%20value%");
-
- assert_eq("5.1", 1, p5.getParameterCount());
- assert_eq("5.2", "param1", PARAM_NAME(p5, 0));
- assert_eq("5.3", "test value%", PARAM_VALUE(p5, 0));
-
- // Spaces before and after '='
- parameterizedHeaderField p6;
- p6.parse("X; param1\t= \"value1\"");
-
- assert_eq("6.1", 1, p6.getParameterCount());
- assert_eq("6.2", "param1", PARAM_NAME(p6, 0));
- assert_eq("6.3", "value1", PARAM_VALUE(p6, 0));
-
- // Quoted strings and escaped chars
- parameterizedHeaderField p7;
- p7.parse("X; param1=\"this is a slash: \\\"\\\\\\\"\""); // \"\\\"
-
- assert_eq("7.1", 1, p7.getParameterCount());
- assert_eq("7.2", "param1", PARAM_NAME(p7, 0));
- assert_eq("7.3", "this is a slash: \"\\\"", PARAM_VALUE(p7, 0));
-
- // Extended parameter with charset specified in more than one
- // section (this is forbidden by RFC, but is should not fail)
- parameterizedHeaderField p8;
- p8.parse("X; param1*0*=charset1'language1'value1;\r\n"
- " param1*1*=charset2'language2'value2;");
-
- assert_eq("8.1", 1, p8.getParameterCount());
- assert_eq("8.2", "param1", PARAM_NAME(p8, 0));
- assert_eq("8.3", "charset1", PARAM_CHARSET(p8, 0));
- assert_eq("8.4", "value1charset2'language2'value2", PARAM_BUFFER(p8, 0));
-
- // Charset not specified in the first section (that is not encoded),
- // but specified in the second one (legal)
- parameterizedHeaderField p9;
- p9.parse("X; param1*0=value1;\r\n"
- " param1*1*=charset'language'value2;");
-
- assert_eq("9.1", 1, p9.getParameterCount());
- assert_eq("9.2", "param1", PARAM_NAME(p9, 0));
- assert_eq("9.3", "charset", PARAM_CHARSET(p9, 0));
- assert_eq("9.4", "value1value2", PARAM_BUFFER(p9, 0));
-
- // Characters prefixed with '%' in a simple (not extended) section
- // should not be decoded
- parameterizedHeaderField p10;
- p10.parse("X; param1=val%20ue1");
-
- assert_eq("10.1", 1, p10.getParameterCount());
- assert_eq("10.2", "param1", PARAM_NAME(p10, 0));
- assert_eq("10.3", "val%20ue1", PARAM_VALUE(p10, 0));
-
- // Multiple sections + charset specified and encoding
- parameterizedHeaderField p11;
- p11.parse("X; param1*0*=charset'language'value1a%20;"
- " param1*1*=value1b%20;"
- " param1*2=value1c");
-
- assert_eq("11.1", 1, p11.getParameterCount());
- assert_eq("11.2", "param1", PARAM_NAME(p11, 0));
- assert_eq("11.3", "charset", PARAM_CHARSET(p11, 0));
- assert_eq("11.4", "value1a value1b value1c", PARAM_BUFFER(p11, 0));
-
- // No charset specified: defaults to US-ASCII
- parameterizedHeaderField p12;
- p12.parse("X; param1*='language'value1");
-
- assert_eq("12.1", 1, p12.getParameterCount());
- assert_eq("12.2", "param1", PARAM_NAME(p12, 0));
- assert_eq("12.3", "us-ascii", PARAM_CHARSET(p12, 0));
- assert_eq("12.4", "value1", PARAM_BUFFER(p12, 0));
- }
+ // Simple parameter
+ parameterizedHeaderField p1;
+ p1.parse("X; param1=value1;\r\n");
+
+ VASSERT_EQ("1.1", 1, p1.getParameterCount());
+ VASSERT_EQ("1.2", "param1", PARAM_NAME(p1, 0));
+ VASSERT_EQ("1.3", "value1", PARAM_VALUE(p1, 0));
+
+ // Multi-section parameters (1/2)
+ parameterizedHeaderField p2a;
+ p2a.parse("X; param1=value1;\r\n"
+ " param2*0=\"val\";\r\n"
+ " param2*1=\"ue2\";");
+
+ VASSERT_EQ("2a.1", 2, p2a.getParameterCount());
+ VASSERT_EQ("2a.2", "param1", PARAM_NAME(p2a, 0));
+ VASSERT_EQ("2a.3", "value1", PARAM_VALUE(p2a, 0));
+ VASSERT_EQ("2a.4", "param2", PARAM_NAME(p2a, 1));
+ VASSERT_EQ("2a.5", "value2", PARAM_VALUE(p2a, 1));
+
+ // Multi-section parameters (2/2)
+ parameterizedHeaderField p2b;
+ p2b.parse("X; param1=value1;\r\n"
+ " param2=\"should be ignored\";\r\n"
+ " param2*0=\"val\";\r\n"
+ " param2*1=\"ue2\";");
+
+ VASSERT_EQ("2b.1", 2, p2b.getParameterCount());
+ VASSERT_EQ("2b.2", "param1", PARAM_NAME(p2b, 0));
+ VASSERT_EQ("2b.3", "value1", PARAM_VALUE(p2b, 0));
+ VASSERT_EQ("2b.4", "param2", PARAM_NAME(p2b, 1));
+ VASSERT_EQ("2b.5", "value2", PARAM_VALUE(p2b, 1));
+
+ // Extended parameter (charset and language information)
+ parameterizedHeaderField p3;
+ p3.parse("X; param1*=charset'language'value1;\r\n");
+
+ VASSERT_EQ("3.1", 1, p3.getParameterCount());
+ VASSERT_EQ("3.2", "param1", PARAM_NAME(p3, 0));
+ VASSERT_EQ("3.3", "charset", PARAM_CHARSET(p3, 0));
+ VASSERT_EQ("3.4", "value1", PARAM_BUFFER(p3, 0));
+
+ // Encoded characters in extended parameter values
+ parameterizedHeaderField p4;
+ p4.parse("X; param1*=a%20value%20with%20multiple%20word%73"); // 0x73 = 's'
+
+ VASSERT_EQ("4.1", 1, p4.getParameterCount());
+ VASSERT_EQ("4.2", "param1", PARAM_NAME(p4, 0));
+ VASSERT_EQ("4.3", "a value with multiple words", PARAM_VALUE(p4, 0));
+
+ // Invalid encoded character
+ parameterizedHeaderField p5;
+ p5.parse("X; param1*=test%20value%");
+
+ VASSERT_EQ("5.1", 1, p5.getParameterCount());
+ VASSERT_EQ("5.2", "param1", PARAM_NAME(p5, 0));
+ VASSERT_EQ("5.3", "test value%", PARAM_VALUE(p5, 0));
+
+ // Spaces before and after '='
+ parameterizedHeaderField p6;
+ p6.parse("X; param1\t= \"value1\"");
+
+ VASSERT_EQ("6.1", 1, p6.getParameterCount());
+ VASSERT_EQ("6.2", "param1", PARAM_NAME(p6, 0));
+ VASSERT_EQ("6.3", "value1", PARAM_VALUE(p6, 0));
+
+ // Quoted strings and escaped chars
+ parameterizedHeaderField p7;
+ p7.parse("X; param1=\"this is a slash: \\\"\\\\\\\"\""); // \"\\\"
+
+ VASSERT_EQ("7.1", 1, p7.getParameterCount());
+ VASSERT_EQ("7.2", "param1", PARAM_NAME(p7, 0));
+ VASSERT_EQ("7.3", "this is a slash: \"\\\"", PARAM_VALUE(p7, 0));
+
+ // Extended parameter with charset specified in more than one
+ // section (this is forbidden by RFC, but is should not fail)
+ parameterizedHeaderField p8;
+ p8.parse("X; param1*0*=charset1'language1'value1;\r\n"
+ " param1*1*=charset2'language2'value2;");
+
+ VASSERT_EQ("8.1", 1, p8.getParameterCount());
+ VASSERT_EQ("8.2", "param1", PARAM_NAME(p8, 0));
+ VASSERT_EQ("8.3", "charset1", PARAM_CHARSET(p8, 0));
+ VASSERT_EQ("8.4", "value1charset2'language2'value2", PARAM_BUFFER(p8, 0));
+
+ // Charset not specified in the first section (that is not encoded),
+ // but specified in the second one (legal)
+ parameterizedHeaderField p9;
+ p9.parse("X; param1*0=value1;\r\n"
+ " param1*1*=charset'language'value2;");
+
+ VASSERT_EQ("9.1", 1, p9.getParameterCount());
+ VASSERT_EQ("9.2", "param1", PARAM_NAME(p9, 0));
+ VASSERT_EQ("9.3", "charset", PARAM_CHARSET(p9, 0));
+ VASSERT_EQ("9.4", "value1value2", PARAM_BUFFER(p9, 0));
+
+ // Characters prefixed with '%' in a simple (not extended) section
+ // should not be decoded
+ parameterizedHeaderField p10;
+ p10.parse("X; param1=val%20ue1");
+
+ VASSERT_EQ("10.1", 1, p10.getParameterCount());
+ VASSERT_EQ("10.2", "param1", PARAM_NAME(p10, 0));
+ VASSERT_EQ("10.3", "val%20ue1", PARAM_VALUE(p10, 0));
+
+ // Multiple sections + charset specified and encoding
+ parameterizedHeaderField p11;
+ p11.parse("X; param1*0*=charset'language'value1a%20;"
+ " param1*1*=value1b%20;"
+ " param1*2=value1c");
+
+ VASSERT_EQ("11.1", 1, p11.getParameterCount());
+ VASSERT_EQ("11.2", "param1", PARAM_NAME(p11, 0));
+ VASSERT_EQ("11.3", "charset", PARAM_CHARSET(p11, 0));
+ VASSERT_EQ("11.4", "value1a value1b value1c", PARAM_BUFFER(p11, 0));
+
+ // No charset specified: defaults to US-ASCII
+ parameterizedHeaderField p12;
+ p12.parse("X; param1*='language'value1");
+
+ VASSERT_EQ("12.1", 1, p12.getParameterCount());
+ VASSERT_EQ("12.2", "param1", PARAM_NAME(p12, 0));
+ VASSERT_EQ("12.3", "us-ascii", PARAM_CHARSET(p12, 0));
+ VASSERT_EQ("12.4", "value1", PARAM_BUFFER(p12, 0));
+ }
+
+ void testGenerate()
+ {
+ // Simple parameter/value
+ parameterizedHeaderField p1;
+ p1.appendParameter(vmime::parameterFactory::getInstance()->create("param1", "value1"));
- void testGenerate()
- {
- // Simple parameter/value
- parameterizedHeaderField p1;
- p1.appendParameter(vmime::parameterFactory::getInstance()->create("param1", "value1"));
-
- assert_eq("1", "F: X; param1=value1", p1.generate());
-
- // Value that needs quoting (1/2)
- parameterizedHeaderField p2a;
- p2a.appendParameter(vmime::parameterFactory::getInstance()->create("param1", "value1a;value1b"));
-
- assert_eq("2a", "F: X; param1=\"value1a;value1b\"", p2a.generate());
-
- // Value that needs quoting (2/2)
- parameterizedHeaderField p2b;
- p2b.appendParameter(vmime::parameterFactory::getInstance()->create("param1", "va\\lue\"1"));
-
- assert_eq("2b", "F: X; param1=\"va\\\\lue\\\"1\"", p2b.generate());
-
- // Extended parameter with charset specifier
- parameterizedHeaderField p3;
- p3.appendParameter(vmime::parameterFactory::getInstance()->create("param1",
- vmime::word("value 1\xe9", vmime::charset("charset"))));
-
- assert_eq("3", "F: X; param1=\"value 1\";param1*=charset''value%201%E9", p3.generate());
-
- // Value that spans on multiple lines
- parameterizedHeaderField p4;
- p4.appendParameter(vmime::parameterFactory::getInstance()->create("param1",
- vmime::word("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
- vmime::charset("charset"))));
-
- assert_eq("4", "F: X; \r\n "
- "param1=abcdefghijklm;\r\n "
- "param1*0*=charset''abc;\r\n "
- "param1*1*=defghijkl;\r\n "
- "param1*2*=mnopqrstu;\r\n "
- "param1*3*=vwxyzABCD;\r\n "
- "param1*4*=EFGHIJKLM;\r\n "
- "param1*5*=NOPQRSTUV;\r\n "
- "param1*6*=WXYZ", p4.generate(25)); // max line length = 25
- }
+ VASSERT_EQ("1", "F: X; param1=value1", p1.generate());
- public:
+ // Value that needs quoting (1/2)
+ parameterizedHeaderField p2a;
+ p2a.appendParameter(vmime::parameterFactory::getInstance()->create("param1", "value1a;value1b"));
- parameterTest() : suite("vmime::path")
- {
- vmime::platformDependant::setHandler<vmime::platforms::posix::posixHandler>();
+ VASSERT_EQ("2a", "F: X; param1=\"value1a;value1b\"", p2a.generate());
- add("Parse", testcase(this, "Parse", &parameterTest::testParse));
- add("Generate", testcase(this, "Generate", &parameterTest::testGenerate));
+ // Value that needs quoting (2/2)
+ parameterizedHeaderField p2b;
+ p2b.appendParameter(vmime::parameterFactory::getInstance()->create("param1", "va\\lue\"1"));
- suite::main().add("vmime::parameter", this);
- }
+ VASSERT_EQ("2b", "F: X; param1=\"va\\\\lue\\\"1\"", p2b.generate());
- };
+ // Extended parameter with charset specifier
+ parameterizedHeaderField p3;
+ p3.appendParameter(vmime::parameterFactory::getInstance()->create("param1",
+ vmime::word("value 1\xe9", vmime::charset("charset"))));
+
+ VASSERT_EQ("3", "F: X; param1=\"value 1\";param1*=charset''value%201%E9", p3.generate());
+
+ // Value that spans on multiple lines
+ parameterizedHeaderField p4;
+ p4.appendParameter(vmime::parameterFactory::getInstance()->create("param1",
+ vmime::word("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
+ vmime::charset("charset"))));
+
+ VASSERT_EQ("4", "F: X; \r\n "
+ "param1=abcdefghijklm;\r\n "
+ "param1*0*=charset''abc;\r\n "
+ "param1*1*=defghijkl;\r\n "
+ "param1*2*=mnopqrstu;\r\n "
+ "param1*3*=vwxyzABCD;\r\n "
+ "param1*4*=EFGHIJKLM;\r\n "
+ "param1*5*=NOPQRSTUV;\r\n "
+ "param1*6*=WXYZ", p4.generate(25)); // max line length = 25
+ }
+
+VMIME_TEST_SUITE_END
- parameterTest* theTest = new parameterTest();
-}
diff --git a/tests/parser/pathTest.cpp b/tests/parser/pathTest.cpp
index a2fc76b8..aca18489 100644
--- a/tests/parser/pathTest.cpp
+++ b/tests/parser/pathTest.cpp
@@ -17,103 +17,87 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
-#include "../lib/unit++/unit++.h"
+#include "tests/testUtils.hpp"
-#include <iostream>
-#include <ostream>
-#include "vmime/vmime.hpp"
-#include "vmime/platforms/posix/posixHandler.hpp"
+#define VMIME_TEST_SUITE pathTest
+#define VMIME_TEST_SUITE_MODULE "Parser"
-#include "tests/parser/testUtils.hpp"
-using namespace unitpp;
+VMIME_TEST_SUITE_BEGIN
+ VMIME_TEST_LIST_BEGIN
+ VMIME_TEST(testParse)
+ VMIME_TEST(testParse2)
+ VMIME_TEST(testGenerate)
+ VMIME_TEST_LIST_END
-namespace
-{
- class pathTest : public suite
- {
- void testParse()
- {
- vmime::path p1;
- p1.parse("<>");
-
- assert_eq("1.1", "", p1.getLocalPart());
- assert_eq("1.2", "", p1.getDomain());
-
- vmime::path p2;
- p2.parse("<domain>");
-
- assert_eq("2.1", "", p2.getLocalPart());
- assert_eq("2.2", "domain", p2.getDomain());
- vmime::path p3;
- p3.parse("<local@domain>");
+ void testParse()
+ {
+ vmime::path p1;
+ p1.parse("<>");
- assert_eq("3.1", "local", p3.getLocalPart());
- assert_eq("3.2", "domain", p3.getDomain());
- }
+ VASSERT_EQ("1.1", "", p1.getLocalPart());
+ VASSERT_EQ("1.2", "", p1.getDomain());
- void testParse2()
- {
- // Test some invalid paths (no '<>')
- vmime::path p1;
- p1.parse("");
+ vmime::path p2;
+ p2.parse("<domain>");
- assert_eq("1.1", "", p1.getLocalPart());
- assert_eq("1.2", "", p1.getDomain());
+ VASSERT_EQ("2.1", "", p2.getLocalPart());
+ VASSERT_EQ("2.2", "domain", p2.getDomain());
- vmime::path p2;
- p2.parse("domain");
+ vmime::path p3;
+ p3.parse("<local@domain>");
- assert_eq("2.1", "", p2.getLocalPart());
- assert_eq("2.2", "domain", p2.getDomain());
+ VASSERT_EQ("3.1", "local", p3.getLocalPart());
+ VASSERT_EQ("3.2", "domain", p3.getDomain());
+ }
- vmime::path p3;
- p3.parse("local@domain");
+ void testParse2()
+ {
+ // Test some invalid paths (no '<>')
+ vmime::path p1;
+ p1.parse("");
- assert_eq("3.1", "local", p3.getLocalPart());
- assert_eq("3.2", "domain", p3.getDomain());
- }
+ VASSERT_EQ("1.1", "", p1.getLocalPart());
+ VASSERT_EQ("1.2", "", p1.getDomain());
- void testGenerate()
- {
- vmime::path p1;
+ vmime::path p2;
+ p2.parse("domain");
- assert_eq("1", "<>", p1.generate());
+ VASSERT_EQ("2.1", "", p2.getLocalPart());
+ VASSERT_EQ("2.2", "domain", p2.getDomain());
- vmime::path p2;
- p2.setLocalPart("local");
+ vmime::path p3;
+ p3.parse("local@domain");
- assert_eq("2", "<local@>", p2.generate());
+ VASSERT_EQ("3.1", "local", p3.getLocalPart());
+ VASSERT_EQ("3.2", "domain", p3.getDomain());
+ }
- vmime::path p3;
- p3.setDomain("domain");
+ void testGenerate()
+ {
+ vmime::path p1;
- assert_eq("3", "<@domain>", p3.generate());
+ VASSERT_EQ("1", "<>", p1.generate());
- vmime::path p4;
- p4.setLocalPart("local");
- p4.setDomain("domain");
+ vmime::path p2;
+ p2.setLocalPart("local");
- assert_eq("4", "<local@domain>", p4.generate());
- }
+ VASSERT_EQ("2", "<local@>", p2.generate());
- public:
+ vmime::path p3;
+ p3.setDomain("domain");
- pathTest() : suite("vmime::path")
- {
- vmime::platformDependant::setHandler<vmime::platforms::posix::posixHandler>();
+ VASSERT_EQ("3", "<@domain>", p3.generate());
- add("Parse", testcase(this, "Parse", &pathTest::testParse));
- add("Parse2", testcase(this, "Parse2", &pathTest::testParse2));
- add("Generate", testcase(this, "Generate", &pathTest::testGenerate));
+ vmime::path p4;
+ p4.setLocalPart("local");
+ p4.setDomain("domain");
- suite::main().add("vmime::path", this);
- }
+ VASSERT_EQ("4", "<local@domain>", p4.generate());
+ }
- };
+VMIME_TEST_SUITE_END
- pathTest* theTest = new pathTest();
-}
diff --git a/tests/parser/testUtils.hpp b/tests/parser/testUtils.hpp
deleted file mode 100644
index 15b6840e..00000000
--- a/tests/parser/testUtils.hpp
+++ /dev/null
@@ -1,123 +0,0 @@
-//
-// VMime library (http://www.vmime.org)
-// Copyright (C) 2002-2005 Vincent Richard <[email protected]>
-//
-// 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);
-}
-
-
-std::ostream& operator<<(std::ostream& os, const vmime::datetime& d)
-{
- os << "[datetime: " << d.getYear() << "/" << d.getMonth() << "/" << d.getDay();
- os << " " << d.getHour() << ":" << d.getMinute() << ":" << d.getSecond();
- os << " #" << d.getZone() << "]";
-
- return (os);
-}
-
-
-}
diff --git a/tests/parser/textTest.cpp b/tests/parser/textTest.cpp
index d07208fb..7109a0b5 100644
--- a/tests/parser/textTest.cpp
+++ b/tests/parser/textTest.cpp
@@ -17,255 +17,238 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
-#include "../lib/unit++/unit++.h"
+#include "tests/testUtils.hpp"
-#include <iostream>
-#include <ostream>
-#include <sstream>
-#include "vmime/vmime.hpp"
-#include "vmime/platforms/posix/posixHandler.hpp"
+#define VMIME_TEST_SUITE textTest
+#define VMIME_TEST_SUITE_MODULE "Parser"
-#include "tests/parser/testUtils.hpp"
-using namespace unitpp;
+VMIME_TEST_SUITE_BEGIN
+ VMIME_TEST_LIST_BEGIN
+ VMIME_TEST(testConstructors)
+ VMIME_TEST(testCopy)
+ VMIME_TEST(testNewFromString)
+ VMIME_TEST(testDisplayForm)
+ VMIME_TEST(testParse)
+ VMIME_TEST(testGenerate)
-namespace
-{
- class textTest : public suite
+ VMIME_TEST(testWordConstructors)
+ VMIME_TEST(testWordParse)
+ VMIME_TEST(testWordGenerate)
+ VMIME_TEST_LIST_END
+
+
+ void testConstructors()
{
- void testConstructors()
- {
- vmime::text t1;
+ vmime::text t1;
- assert_eq("1.1", 0, t1.getWordCount());
+ VASSERT_EQ("1.1", 0, t1.getWordCount());
- vmime::text t2("Test\xa9\xc3");
+ 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());
+ VASSERT_EQ("2.1", 1, t2.getWordCount());
+ VASSERT_EQ("2.2", "Test\xa9\xc3", t2.getWordAt(0)->getBuffer());
+ VASSERT_EQ("2.3", vmime::charset::getLocaleCharset(), t2.getWordAt(0)->getCharset());
- vmime::text t3("Test\xa9\xc3", vmime::charset(vmime::charsets::ISO8859_13));
+ 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());
+ VASSERT_EQ("3.1", 1, t3.getWordCount());
+ VASSERT_EQ("3.2", "Test\xa9\xc3", t3.getWordAt(0)->getBuffer());
+ VASSERT_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);
+ 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());
+ VASSERT_EQ("4.1", 1, t4.getWordCount());
+ VASSERT_EQ("4.2", w1.getBuffer(), t4.getWordAt(0)->getBuffer());
+ VASSERT_EQ("4.3", w1.getCharset(), t4.getWordAt(0)->getCharset());
- vmime::word w2("Other", vmime::charset(vmime::charsets::US_ASCII));
- t4.appendWord(vmime::create <vmime::word>(w2));
+ vmime::word w2("Other", vmime::charset(vmime::charsets::US_ASCII));
+ t4.appendWord(vmime::create <vmime::word>(w2));
- vmime::text t5(t4);
+ 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());
- }
+ VASSERT_EQ("5.1", 2, t5.getWordCount());
+ VASSERT_EQ("5.2", w1.getBuffer(), t5.getWordAt(0)->getBuffer());
+ VASSERT_EQ("5.3", w1.getCharset(), t5.getWordAt(0)->getCharset());
+ VASSERT_EQ("5.4", w2.getBuffer(), t5.getWordAt(1)->getBuffer());
+ VASSERT_EQ("5.5", w2.getCharset(), t5.getWordAt(1)->getCharset());
+ }
- void testCopy()
- {
- vmime::text t1("Test: \xa9\xc3");
+ void testCopy()
+ {
+ vmime::text t1("Test: \xa9\xc3");
- assert_true("operator==", t1 == t1);
- assert_true("clone", *vmime::clone(t1) == t1);
+ VASSERT("operator==", t1 == t1);
+ VASSERT("clone", *vmime::clone(t1) == t1);
- vmime::text t2;
- t2.copyFrom(t1);
+ vmime::text t2;
+ t2.copyFrom(t1);
- assert_true("copyFrom", t1 == t2);
- }
+ VASSERT("copyFrom", t1 == t2);
+ }
- void testNewFromString()
- {
- vmime::string s1 = "only ASCII characters";
- vmime::charset c1("test");
- vmime::text t1;
+ void testNewFromString()
+ {
+ vmime::string s1 = "only ASCII characters";
+ vmime::charset c1("test");
+ vmime::text t1;
+
+ t1.createFromString(s1, c1);
+
+ VASSERT_EQ("1.1", 1, t1.getWordCount());
+ VASSERT_EQ("1.2", s1, t1.getWordAt(0)->getBuffer());
+ VASSERT_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;
+
+ t2.createFromString(s2, c2);
+
+ VASSERT_EQ("2.1", 3, t2.getWordCount());
+ VASSERT_EQ("2.2", s2_1, t2.getWordAt(0)->getBuffer());
+ VASSERT_EQ("2.3", vmime::charset(vmime::charsets::US_ASCII), t2.getWordAt(0)->getCharset());
+ VASSERT_EQ("2.4", s2_2, t2.getWordAt(1)->getBuffer());
+ VASSERT_EQ("2.5", c2, t2.getWordAt(1)->getCharset());
+ VASSERT_EQ("2.6", s2_3, t2.getWordAt(2)->getBuffer());
+ VASSERT_EQ("2.7", vmime::charset(vmime::charsets::US_ASCII), t2.getWordAt(2)->getCharset());
+ }
+
+ static const vmime::string parseText(const vmime::string& buffer)
+ {
+ vmime::text t;
+ t.parse(buffer);
- t1.createFromString(s1, c1);
+ std::ostringstream oss;
+ oss << t;
- 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());
+ return (oss.str());
+ }
- 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;
+ void testParse()
+ {
+ // From RFC-2047
+ VASSERT_EQ("1", "[text: [[word: charset=US-ASCII, buffer=Keith Moore]]]",
+ parseText("=?US-ASCII?Q?Keith_Moore?="));
- t2.createFromString(s2, c2);
+ VASSERT_EQ("2", "[text: [[word: charset=ISO-8859-1, buffer=Keld J\xf8rn Simonsen]]]",
+ parseText("=?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?="));
- 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());
- }
+ VASSERT_EQ("3", "[text: [[word: charset=ISO-8859-1, buffer=Andr\xe9]," \
+ "[word: charset=us-ascii, buffer= Pirard]]]",
+ parseText("=?ISO-8859-1?Q?Andr=E9?= Pirard"));
- static const vmime::string parseText(const vmime::string& buffer)
- {
- vmime::text t;
- t.parse(buffer);
+ VASSERT_EQ("4", "[text: [[word: charset=ISO-8859-1, buffer=If you can read this yo]," \
+ "[word: charset=ISO-8859-2, buffer=u understand the example.]]]",
+ parseText("=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=\r\n " \
+ "=?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?="));
- std::ostringstream oss;
- oss << t;
+ // Bugfix: in "=?charset?q?=XX=YY?=", the "?=" finish
+ // sequence was not correctly found (should be the one
+ // after '=YY' and not the one after '?q').
+ VASSERT_EQ("5", "[text: [[word: charset=abc, buffer=\xe9\xe9]]]",
+ parseText("=?abc?q?=E9=E9?="));
- return (oss.str());
- }
+ // Question marks (?) in the middle of the string
+ VASSERT_EQ("6", "[text: [[word: charset=iso-8859-1, buffer=Know wh\xe4t? It works!]]]",
+ parseText("=?iso-8859-1?Q?Know_wh=E4t?_It_works!?="));
- void testParse()
- {
- // From RFC-2047
- assert_eq("1", "[text: [[word: charset=US-ASCII, buffer=Keith Moore]]]",
- parseText("=?US-ASCII?Q?Keith_Moore?="));
+ // TODO: add more
+ }
- assert_eq("2", "[text: [[word: charset=ISO-8859-1, buffer=Keld J\xf8rn Simonsen]]]",
- parseText("=?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?="));
+ void testGenerate()
+ {
+ // TODO
+ }
- assert_eq("3", "[text: [[word: charset=ISO-8859-1, buffer=Andr\xe9]," \
- "[word: charset=us-ascii, buffer= Pirard]]]",
- parseText("=?ISO-8859-1?Q?Andr=E9?= Pirard"));
+ static const vmime::string getDisplayText(const vmime::text& t)
+ {
+ vmime::string res;
- assert_eq("4", "[text: [[word: charset=ISO-8859-1, buffer=If you can read this yo]," \
- "[word: charset=ISO-8859-2, buffer=u understand the example.]]]",
- parseText("=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=\r\n " \
- "=?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?="));
+ for (int i = 0 ; i < t.getWordCount() ; ++i)
+ res += t.getWordAt(i)->getBuffer();
- // Bugfix: in "=?charset?q?=XX=YY?=", the "?=" finish
- // sequence was not correctly found (should be the one
- // after '=YY' and not the one after '?q').
- assert_eq("5", "[text: [[word: charset=abc, buffer=\xe9\xe9]]]",
- parseText("=?abc?q?=E9=E9?="));
-
- // Question marks (?) in the middle of the string
- assert_eq("6", "[text: [[word: charset=iso-8859-1, buffer=Know wh\xe4t? It works!]]]",
- parseText("=?iso-8859-1?Q?Know_wh=E4t?_It_works!?="));
-
- // TODO: add more
- }
-
- void testGenerate()
- {
- // TODO
- }
-
- static const vmime::string getDisplayText(const vmime::text& t)
- {
- vmime::string res;
-
- for (int i = 0 ; i < t.getWordCount() ; ++i)
- res += t.getWordAt(i)->getBuffer();
-
- return res;
- }
+ return res;
+ }
- void testDisplayForm()
- {
+ void testDisplayForm()
+ {
#define DISPLAY_FORM(x) getDisplayText(*vmime::text::decodeAndUnfold(x))
- // From RFC-2047
- assert_eq("1", "a", DISPLAY_FORM("=?ISO-8859-1?Q?a?="));
- assert_eq("2", "a b", DISPLAY_FORM("=?ISO-8859-1?Q?a?= b"));
- assert_eq("3", "ab", DISPLAY_FORM("=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?="));
- assert_eq("4", "ab", DISPLAY_FORM("=?ISO-8859-1?Q?a?= \t =?ISO-8859-1?Q?b?="));
- assert_eq("5", "ab", DISPLAY_FORM("=?ISO-8859-1?Q?a?= \r\n \t =?ISO-8859-1?Q?b?="));
- assert_eq("6", "a b", DISPLAY_FORM("=?ISO-8859-1?Q?a_b?="));
- assert_eq("7", "a b", DISPLAY_FORM("=?ISO-8859-1?Q?a?= =?ISO-8859-2?Q?_b?="));
+ // From RFC-2047
+ VASSERT_EQ("1", "a", DISPLAY_FORM("=?ISO-8859-1?Q?a?="));
+ VASSERT_EQ("2", "a b", DISPLAY_FORM("=?ISO-8859-1?Q?a?= b"));
+ VASSERT_EQ("3", "ab", DISPLAY_FORM("=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?="));
+ VASSERT_EQ("4", "ab", DISPLAY_FORM("=?ISO-8859-1?Q?a?= \t =?ISO-8859-1?Q?b?="));
+ VASSERT_EQ("5", "ab", DISPLAY_FORM("=?ISO-8859-1?Q?a?= \r\n \t =?ISO-8859-1?Q?b?="));
+ VASSERT_EQ("6", "a b", DISPLAY_FORM("=?ISO-8859-1?Q?a_b?="));
+ VASSERT_EQ("7", "a b", DISPLAY_FORM("=?ISO-8859-1?Q?a?= =?ISO-8859-2?Q?_b?="));
- // Some more tests...
- assert_eq("8", "a b", DISPLAY_FORM(" a =?ISO-8859-1?Q?b?= "));
- assert_eq("9", "a b ", DISPLAY_FORM(" \t =?ISO-8859-1?Q?a?= b "));
- assert_eq("10", "a b", DISPLAY_FORM(" a\r\n\t b"));
+ // Some more tests...
+ VASSERT_EQ("8", "a b", DISPLAY_FORM(" a =?ISO-8859-1?Q?b?= "));
+ VASSERT_EQ("9", "a b ", DISPLAY_FORM(" \t =?ISO-8859-1?Q?a?= b "));
+ VASSERT_EQ("10", "a b", DISPLAY_FORM(" a\r\n\t b"));
#undef DISPLAY_FORM
- }
+ }
- void testWordConstructors()
- {
- assert_eq("1.1", vmime::charset::getLocaleCharset(), vmime::word().getCharset());
- assert_eq("1.2", "", vmime::word().getBuffer());
-
- assert_eq("2.1", vmime::charset::getLocaleCharset(), vmime::word("foo").getCharset());
- assert_eq("2.2", "foo", vmime::word("foo").getBuffer());
-
- assert_eq("3.1", "bar", vmime::word("foo", vmime::charset("bar")).getCharset().getName());
- assert_eq("3.2", "foo", vmime::word("foo", vmime::charset("bar")).getBuffer());
- }
-
- void testWordParse()
- {
- // Simple encoded word
- vmime::word w1;
- w1.parse("=?foo?q?bar=E9 baz?=");
-
- assert_eq("1.1", "foo", w1.getCharset().getName());
- assert_eq("1.2", "bar\xe9 baz", w1.getBuffer());
-
- // Unencoded text
- vmime::word w2;
- w2.parse(" foo bar \tbaz...");
+ void testWordConstructors()
+ {
+ VASSERT_EQ("1.1", vmime::charset::getLocaleCharset(), vmime::word().getCharset());
+ VASSERT_EQ("1.2", "", vmime::word().getBuffer());
- assert_eq("2.1", vmime::charset(vmime::charsets::US_ASCII), w2.getCharset());
- assert_eq("2.2", " foo bar \tbaz...", w2.getBuffer());
+ VASSERT_EQ("2.1", vmime::charset::getLocaleCharset(), vmime::word("foo").getCharset());
+ VASSERT_EQ("2.2", "foo", vmime::word("foo").getBuffer());
- // Malformed word
- vmime::word w3;
- w3.parse("=?foo bar");
+ VASSERT_EQ("3.1", "bar", vmime::word("foo", vmime::charset("bar")).getCharset().getName());
+ VASSERT_EQ("3.2", "foo", vmime::word("foo", vmime::charset("bar")).getBuffer());
+ }
- assert_eq("3.1", vmime::charset(vmime::charsets::US_ASCII), w3.getCharset());
- assert_eq("3.2", "=?foo bar", w3.getBuffer());
+ void testWordParse()
+ {
+ // Simple encoded word
+ vmime::word w1;
+ w1.parse("=?foo?q?bar=E9 baz?=");
- // Unknown encoding
- vmime::word w4;
- w4.parse("=?whatever?not_q_or_b?whatever?=");
+ VASSERT_EQ("1.1", "foo", w1.getCharset().getName());
+ VASSERT_EQ("1.2", "bar\xe9 baz", w1.getBuffer());
- assert_eq("4.1", vmime::charset(vmime::charsets::US_ASCII), w4.getCharset());
- assert_eq("4.2", "=?whatever?not_q_or_b?whatever?=", w4.getBuffer());
- }
+ // Unencoded text
+ vmime::word w2;
+ w2.parse(" foo bar \tbaz...");
- void testWordGenerate()
- {
- assert_eq("1", "=?foo?Q?bar=E9_baz?=",
- vmime::word("bar\xe9 baz", vmime::charset("foo")).generate());
+ VASSERT_EQ("2.1", vmime::charset(vmime::charsets::US_ASCII), w2.getCharset());
+ VASSERT_EQ("2.2", " foo bar \tbaz...", w2.getBuffer());
- assert_eq("2", "=?foo?B?8fLz9PU=?=",
- vmime::word("\xf1\xf2\xf3\xf4\xf5", vmime::charset("foo")).generate());
- }
+ // Malformed word
+ vmime::word w3;
+ w3.parse("=?foo bar");
- public:
+ VASSERT_EQ("3.1", vmime::charset(vmime::charsets::US_ASCII), w3.getCharset());
+ VASSERT_EQ("3.2", "=?foo bar", w3.getBuffer());
- textTest() : suite("vmime::text")
- {
- vmime::platformDependant::setHandler<vmime::platforms::posix::posixHandler>();
+ // Unknown encoding
+ vmime::word w4;
+ w4.parse("=?whatever?not_q_or_b?whatever?=");
- add("Constructors", testcase(this, "Constructors", &textTest::testConstructors));
- add("Copy", testcase(this, "Copy", &textTest::testCopy));
- add("NewFromString", testcase(this, "NewFromString", &textTest::testNewFromString));
- add("DisplayForm", testcase(this, "DisplayForm", &textTest::testDisplayForm));
- add("Parse", testcase(this, "Parse", &textTest::testParse));
- add("Generate", testcase(this, "Generate", &textTest::testGenerate));
+ VASSERT_EQ("4.1", vmime::charset(vmime::charsets::US_ASCII), w4.getCharset());
+ VASSERT_EQ("4.2", "=?whatever?not_q_or_b?whatever?=", w4.getBuffer());
+ }
- add("WordConstructors", testcase(this, "WordConstructors", &textTest::testWordConstructors));
- add("WordParse", testcase(this, "WordParse", &textTest::testWordParse));
- add("WordGenerate", testcase(this, "WordGenerate", &textTest::testWordGenerate));
+ void testWordGenerate()
+ {
+ VASSERT_EQ("1", "=?foo?Q?bar=E9_baz?=",
+ vmime::word("bar\xe9 baz", vmime::charset("foo")).generate());
- suite::main().add("vmime::text", this);
- }
+ VASSERT_EQ("2", "=?foo?B?8fLz9PU=?=",
+ vmime::word("\xf1\xf2\xf3\xf4\xf5", vmime::charset("foo")).generate());
+ }
- };
+VMIME_TEST_SUITE_END
- textTest* theTest = new textTest();
-}