Mercurial > thymian
comparison 3rdparty/vmime/tests/parser/datetimeTest.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(datetimeTest) | |
| 28 | |
| 29 VMIME_TEST_LIST_BEGIN | |
| 30 VMIME_TEST(testParse) | |
| 31 VMIME_TEST(testGenerate) | |
| 32 VMIME_TEST(testCompare) | |
| 33 VMIME_TEST_LIST_END | |
| 34 | |
| 35 | |
| 36 void testParse() | |
| 37 { | |
| 38 struct datetimePair | |
| 39 { | |
| 40 vmime::string parseBuffer; | |
| 41 vmime::datetime result; | |
| 42 }; | |
| 43 | |
| 44 // Here, we can't test all the possible structures for date/time, | |
| 45 // so we test some cases. Don't forget to add a new test case | |
| 46 // each time you encounter a bug in date/time parsing (after | |
| 47 // you have fixed it). | |
| 48 datetimePair pairs[] = | |
| 49 { | |
| 50 { /* 1 */ "Mon, 8 Nov 2004 13:42:56 +0000 (GMT)", | |
| 51 vmime::datetime(2004, 11, 8, 13, 42, 56, vmime::datetime::GMT) }, | |
| 52 | |
| 53 { /* 2 */ "Sun, 7 Nov 2004 00:43:22 -0500 (EST)", | |
| 54 vmime::datetime(2004, 11, 7, 0, 43, 22, vmime::datetime::GMT_5) }, | |
| 55 | |
| 56 { /* 3 */ "Thu Nov 18 12:11:16 2004", | |
| 57 vmime::datetime(vmime::datetime::now().getYear(), 11, 18, 12, 11, 16, vmime::datetime::GMT) }, | |
| 58 | |
| 59 { /* 4 */ "Sat, 18, 2004 22:36:32 -0400", | |
| 60 vmime::datetime(2004, 1, 18, 22, 36, 32, vmime::datetime::GMT_4) }, | |
| 61 | |
| 62 { /* 5 */ "Mon Dec 13 21:57:18 2004", | |
| 63 vmime::datetime(vmime::datetime::now().getYear(), 12, 13, 21, 57, 18, vmime::datetime::GMT) }, | |
| 64 | |
| 65 { /* 6 */ "18 Nov 2004 21:44:54 +0300", | |
| 66 vmime::datetime(2004, 11, 18, 21, 44, 54, vmime::datetime::GMT3) } | |
| 67 }; | |
| 68 | |
| 69 for (unsigned int i = 0 ; i < sizeof(pairs) / sizeof(pairs[0]) ; ++i) | |
| 70 { | |
| 71 vmime::datetime d; | |
| 72 d.parse(pairs[i].parseBuffer); | |
| 73 | |
| 74 std::ostringstream oss; | |
| 75 oss << (i + 1); | |
| 76 | |
| 77 VASSERT_EQ(oss.str(), pairs[i].result, d); | |
| 78 } | |
| 79 } | |
| 80 | |
| 81 void testGenerate() | |
| 82 { | |
| 83 vmime::datetime d1(2005, 7, 8, 4, 5, 6, 1 * 60 + 23); | |
| 84 | |
| 85 VASSERT_EQ("1", "Fri, 8 Jul 2005 04:05:06 +0123", d1.generate()); | |
| 86 } | |
| 87 | |
| 88 void testCompare() | |
| 89 { | |
| 90 // Date1 = Date2 | |
| 91 vmime::datetime d1(2005, 4, 22, 14, 6, 0, vmime::datetime::GMT2); | |
| 92 vmime::datetime d2(2005, 4, 22, 10, 6, 0, vmime::datetime::GMT_2); | |
| 93 | |
| 94 VASSERT_EQ("1.1", true, d1 == d2); | |
| 95 VASSERT_EQ("1.2", false, d1 != d2); | |
| 96 VASSERT_EQ("1.3", true, d1 <= d2); | |
| 97 VASSERT_EQ("1.4", false, d1 < d2); | |
| 98 VASSERT_EQ("1.5", true, d1 >= d2); | |
| 99 VASSERT_EQ("1.6", false, d1 > d2); | |
| 100 | |
| 101 // Date1 < Date2 | |
| 102 vmime::datetime d3(2005, 4, 22, 14, 6, 0); | |
| 103 vmime::datetime d4(2005, 4, 22, 15, 6, 0); | |
| 104 | |
| 105 VASSERT_EQ("2.1", false, d3 == d4); | |
| 106 VASSERT_EQ("2.2", true, d3 != d4); | |
| 107 VASSERT_EQ("2.3", true, d3 <= d4); | |
| 108 VASSERT_EQ("2.4", true, d3 < d4); | |
| 109 VASSERT_EQ("2.5", false, d3 >= d4); | |
| 110 VASSERT_EQ("2.6", false, d3 > d4); | |
| 111 | |
| 112 // Date1 > Date2 | |
| 113 vmime::datetime d5(2005, 4, 22, 15, 6, 0); | |
| 114 vmime::datetime d6(2005, 4, 22, 14, 6, 0); | |
| 115 | |
| 116 VASSERT_EQ("3.1", false, d5 == d6); | |
| 117 VASSERT_EQ("3.2", true, d5 != d6); | |
| 118 VASSERT_EQ("3.3", false, d5 <= d6); | |
| 119 VASSERT_EQ("3.4", false, d5 < d6); | |
| 120 VASSERT_EQ("3.5", true, d5 >= d6); | |
| 121 VASSERT_EQ("3.6", true, d5 > d6); | |
| 122 } | |
| 123 | |
| 124 VMIME_TEST_SUITE_END | |
| 125 |
