annotate 3rdparty/vmime/tests/parser/headerFieldTest.cpp @ 0:a4671277546c tip

created the repository for the thymian project
author ferencd
date Tue, 17 Aug 2021 11:19:54 +0200
parents
children
rev   line source
ferencd@0 1 //
ferencd@0 2 // VMime library (http://www.vmime.org)
ferencd@0 3 // Copyright (C) 2002-2013 Vincent Richard <vincent@vmime.org>
ferencd@0 4 //
ferencd@0 5 // This program is free software; you can redistribute it and/or
ferencd@0 6 // modify it under the terms of the GNU General Public License as
ferencd@0 7 // published by the Free Software Foundation; either version 3 of
ferencd@0 8 // the License, or (at your option) any later version.
ferencd@0 9 //
ferencd@0 10 // This program is distributed in the hope that it will be useful,
ferencd@0 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
ferencd@0 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ferencd@0 13 // General Public License for more details.
ferencd@0 14 //
ferencd@0 15 // You should have received a copy of the GNU General Public License along
ferencd@0 16 // with this program; if not, write to the Free Software Foundation, Inc.,
ferencd@0 17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
ferencd@0 18 //
ferencd@0 19 // Linking this library statically or dynamically with other modules is making
ferencd@0 20 // a combined work based on this library. Thus, the terms and conditions of
ferencd@0 21 // the GNU General Public License cover the whole combination.
ferencd@0 22 //
ferencd@0 23
ferencd@0 24 #include "tests/testUtils.hpp"
ferencd@0 25
ferencd@0 26
ferencd@0 27 VMIME_TEST_SUITE_BEGIN(headerFieldTest)
ferencd@0 28
ferencd@0 29 VMIME_TEST_LIST_BEGIN
ferencd@0 30 VMIME_TEST(testBadValueType)
ferencd@0 31 VMIME_TEST(testValueOnNextLine)
ferencd@0 32 VMIME_TEST(testStripSpacesAtEnd)
ferencd@0 33 VMIME_TEST(testValueWithEmptyLine)
ferencd@0 34 VMIME_TEST_LIST_END
ferencd@0 35
ferencd@0 36
ferencd@0 37 void testBadValueType()
ferencd@0 38 {
ferencd@0 39 vmime::shared_ptr <vmime::headerFieldFactory> hfactory =
ferencd@0 40 vmime::headerFieldFactory::getInstance();
ferencd@0 41
ferencd@0 42 // "To" header field accepts values of type "addressList"
ferencd@0 43 vmime::shared_ptr <vmime::headerField> to = hfactory->create(vmime::fields::TO);
ferencd@0 44 VASSERT_THROW("to",
ferencd@0 45 to->setValue(vmime::mailbox("email@vmime.org")),
ferencd@0 46 vmime::exceptions::bad_field_value_type);
ferencd@0 47
ferencd@0 48 // Unregistered header field accepts any value type
ferencd@0 49 vmime::shared_ptr <vmime::headerField> custom = hfactory->create("X-MyCustomHeader");
ferencd@0 50 VASSERT_NO_THROW("custom/1",
ferencd@0 51 custom->setValue(vmime::mailbox("email@vmime.org")));
ferencd@0 52 VASSERT_NO_THROW("custom/2",
ferencd@0 53 custom->setValue(vmime::text("field value text")));
ferencd@0 54 }
ferencd@0 55
ferencd@0 56 void testValueOnNextLine()
ferencd@0 57 {
ferencd@0 58 vmime::parsingContext ctx;
ferencd@0 59
ferencd@0 60 const vmime::string buffer = "Field: \r\n\tfield data";
ferencd@0 61
ferencd@0 62 vmime::shared_ptr <vmime::headerField> hfield =
ferencd@0 63 vmime::headerField::parseNext(ctx, buffer, 0, buffer.size());
ferencd@0 64
ferencd@0 65 vmime::shared_ptr <vmime::text> hvalue =
ferencd@0 66 hfield->getValue <vmime::text>();
ferencd@0 67
ferencd@0 68 VASSERT_EQ("Field name", "Field", hfield->getName());
ferencd@0 69 VASSERT_EQ("Field value", "field data", hvalue->getWholeBuffer());
ferencd@0 70 }
ferencd@0 71
ferencd@0 72 void testStripSpacesAtEnd()
ferencd@0 73 {
ferencd@0 74 vmime::parsingContext ctx;
ferencd@0 75
ferencd@0 76 const vmime::string buffer = "Field: \r\n\tfield data ";
ferencd@0 77
ferencd@0 78 vmime::shared_ptr <vmime::headerField> hfield =
ferencd@0 79 vmime::headerField::parseNext(ctx, buffer, 0, buffer.size());
ferencd@0 80
ferencd@0 81 vmime::shared_ptr <vmime::text> hvalue =
ferencd@0 82 hfield->getValue <vmime::text>();
ferencd@0 83
ferencd@0 84 VASSERT_EQ("Field name", "Field", hfield->getName());
ferencd@0 85 VASSERT_EQ("Field value", toHex("field data"), toHex(hvalue->getWholeBuffer()));
ferencd@0 86 }
ferencd@0 87
ferencd@0 88 void testValueWithEmptyLine()
ferencd@0 89 {
ferencd@0 90 vmime::parsingContext ctx;
ferencd@0 91
ferencd@0 92 const vmime::string buffer = "Field: \r\n\tdata1\r\n\tdata2\r\n\t\r\n\tdata3";
ferencd@0 93
ferencd@0 94 vmime::shared_ptr <vmime::headerField> hfield =
ferencd@0 95 vmime::headerField::parseNext(ctx, buffer, 0, buffer.size());
ferencd@0 96
ferencd@0 97 vmime::shared_ptr <vmime::text> hvalue =
ferencd@0 98 hfield->getValue <vmime::text>();
ferencd@0 99
ferencd@0 100 VASSERT_EQ("Field name", "Field", hfield->getName());
ferencd@0 101 VASSERT_EQ("Field value", "data1 data2 data3", hvalue->getWholeBuffer());
ferencd@0 102 }
ferencd@0 103
ferencd@0 104 VMIME_TEST_SUITE_END