Avoid potential negative array index access to cached text.
[LibreOffice.git] / svl / qa / unit / test_SvAddressParser.cxx
blobb015f9a1b38954c809619c7011899bc4fbe447d1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
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/.
8 */
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>
20 namespace
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
28 // Messages":
30 SvAddressParser p("Alfred Neuman <Neuman@BBN-TENEXA>");
31 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), p.Count());
32 CPPUNIT_ASSERT_EQUAL(OUString("Neuman@BBN-TENEXA"), p.GetEmailAddress(0));
35 SvAddressParser p("Neuman@BBN-TENEXA");
36 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), p.Count());
37 CPPUNIT_ASSERT_EQUAL(OUString("Neuman@BBN-TENEXA"), p.GetEmailAddress(0));
40 SvAddressParser p("\"George, Ted\" <Shared@Group.Arpanet>");
41 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), p.Count());
42 CPPUNIT_ASSERT_EQUAL(OUString("Shared@Group.Arpanet"), p.GetEmailAddress(0));
45 SvAddressParser p("Wilt . (the Stilt) Chamberlain@NBA.US");
46 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), p.Count());
47 CPPUNIT_ASSERT_EQUAL(OUString("Wilt.Chamberlain@NBA.US"), p.GetEmailAddress(0));
50 SvAddressParser p("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");
56 CPPUNIT_ASSERT_EQUAL(sal_Int32(7), p.Count());
57 CPPUNIT_ASSERT_EQUAL(OUString("WhoZiWhatZit@Cordon-Bleu"), p.GetEmailAddress(0));
58 CPPUNIT_ASSERT_EQUAL(OUString("Childs@WGBH.Boston"), p.GetEmailAddress(1));
59 CPPUNIT_ASSERT_EQUAL(OUString("Gourmet@ANT.Down-Under"), p.GetEmailAddress(2));
60 CPPUNIT_ASSERT_EQUAL(OUString("Cheapie@Discount-Liquors"), p.GetEmailAddress(3));
61 CPPUNIT_ASSERT_EQUAL(OUString("Port@Portugal"), p.GetEmailAddress(4));
62 CPPUNIT_ASSERT_EQUAL(OUString("Jones@SEA"), p.GetEmailAddress(5));
63 CPPUNIT_ASSERT_EQUAL(OUString("Another@Somewhere.SomeOrg"), 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: */