1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <sal/config.h>
12 #include <cppunit/TestAssert.h>
13 #include <cppunit/TestFixture.h>
14 #include <cppunit/extensions/HelperMacros.h>
15 #include <cppunit/plugin/TestPlugIn.h>
17 #include <sal/types.h>
18 #include <svl/adrparse.hxx>
22 class Test
: public CppUnit::TestFixture
24 void testRfc822ExampleAddresses()
26 // Examples taken from section A.1 "Examples: Addresses" of
27 // <https://tools.ietf.org/html/rfc822> "Standard for the Format of ARPA Internet Text
30 SvAddressParser
p(u
"Alfred Neuman <Neuman@BBN-TENEXA>"_ustr
);
31 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), p
.Count());
32 CPPUNIT_ASSERT_EQUAL(u
"Neuman@BBN-TENEXA"_ustr
, p
.GetEmailAddress(0));
35 SvAddressParser
p(u
"Neuman@BBN-TENEXA"_ustr
);
36 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), p
.Count());
37 CPPUNIT_ASSERT_EQUAL(u
"Neuman@BBN-TENEXA"_ustr
, p
.GetEmailAddress(0));
40 SvAddressParser
p(u
"\"George, Ted\" <Shared@Group.Arpanet>"_ustr
);
41 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), p
.Count());
42 CPPUNIT_ASSERT_EQUAL(u
"Shared@Group.Arpanet"_ustr
, p
.GetEmailAddress(0));
45 SvAddressParser
p(u
"Wilt . (the Stilt) Chamberlain@NBA.US"_ustr
);
46 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), p
.Count());
47 CPPUNIT_ASSERT_EQUAL(u
"Wilt.Chamberlain@NBA.US"_ustr
, p
.GetEmailAddress(0));
50 SvAddressParser
p(u
"Gourmets: Pompous Person <WhoZiWhatZit@Cordon-Bleu>,\n"
51 " Childs@WGBH.Boston, Galloping Gourmet@\n"
52 " ANT.Down-Under (Australian National Television),\n"
53 " Cheapie@Discount-Liquors;,\n"
54 " Cruisers: Port@Portugal, Jones@SEA;,\n"
55 " Another@Somewhere.SomeOrg"_ustr
);
56 CPPUNIT_ASSERT_EQUAL(sal_Int32(7), p
.Count());
57 CPPUNIT_ASSERT_EQUAL(u
"WhoZiWhatZit@Cordon-Bleu"_ustr
, p
.GetEmailAddress(0));
58 CPPUNIT_ASSERT_EQUAL(u
"Childs@WGBH.Boston"_ustr
, p
.GetEmailAddress(1));
59 CPPUNIT_ASSERT_EQUAL(u
"Gourmet@ANT.Down-Under"_ustr
, p
.GetEmailAddress(2));
60 CPPUNIT_ASSERT_EQUAL(u
"Cheapie@Discount-Liquors"_ustr
, p
.GetEmailAddress(3));
61 CPPUNIT_ASSERT_EQUAL(u
"Port@Portugal"_ustr
, p
.GetEmailAddress(4));
62 CPPUNIT_ASSERT_EQUAL(u
"Jones@SEA"_ustr
, p
.GetEmailAddress(5));
63 CPPUNIT_ASSERT_EQUAL(u
"Another@Somewhere.SomeOrg"_ustr
, p
.GetEmailAddress(6));
67 CPPUNIT_TEST_SUITE(Test
);
68 CPPUNIT_TEST(testRfc822ExampleAddresses
);
69 CPPUNIT_TEST_SUITE_END();
72 CPPUNIT_TEST_SUITE_REGISTRATION(Test
);
75 CPPUNIT_PLUGIN_IMPLEMENT();
77 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */