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