Mercurial > thymian
comparison 3rdparty/vmime/tests/utility/stringProxyTest.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(stringProxyTest) | |
| 28 | |
| 29 VMIME_TEST_LIST_BEGIN | |
| 30 VMIME_TEST(testConstruct) | |
| 31 VMIME_TEST(testConstruct2) | |
| 32 | |
| 33 VMIME_TEST(testDetach) | |
| 34 | |
| 35 VMIME_TEST(testSet) | |
| 36 | |
| 37 VMIME_TEST(testExtract) | |
| 38 | |
| 39 VMIME_TEST(testOperatorLTLT1) | |
| 40 VMIME_TEST(testOperatorLTLT2) | |
| 41 VMIME_TEST_LIST_END | |
| 42 | |
| 43 | |
| 44 void testConstruct() | |
| 45 { | |
| 46 vmime::utility::stringProxy s; | |
| 47 | |
| 48 VASSERT_EQ("1", static_cast <vmime::size_t>(0), s.length()); | |
| 49 VASSERT_EQ("2", static_cast <vmime::size_t>(0), s.start()); | |
| 50 VASSERT_EQ("3", static_cast <vmime::size_t>(0), s.end()); | |
| 51 } | |
| 52 | |
| 53 void testConstruct2() | |
| 54 { | |
| 55 vmime::string str("This is a test string."); | |
| 56 | |
| 57 vmime::utility::stringProxy s1(str); | |
| 58 | |
| 59 VASSERT_EQ("1", str.length(), s1.length()); | |
| 60 VASSERT_EQ("2", static_cast <vmime::size_t>(0), s1.start()); | |
| 61 VASSERT_EQ("3", str.length(), s1.end()); | |
| 62 | |
| 63 vmime::utility::stringProxy s2(str, 10); | |
| 64 | |
| 65 VASSERT_EQ("4", str.length() - 10, s2.length()); | |
| 66 VASSERT_EQ("5", static_cast <vmime::size_t>(10), s2.start()); | |
| 67 VASSERT_EQ("6", str.length(), s2.end()); | |
| 68 | |
| 69 vmime::utility::stringProxy s3(str, 10, 14); | |
| 70 | |
| 71 VASSERT_EQ("7", static_cast <vmime::size_t>(4), s3.length()); | |
| 72 VASSERT_EQ("8", static_cast <vmime::size_t>(10), s3.start()); | |
| 73 VASSERT_EQ("9", static_cast <vmime::size_t>(14), s3.end()); | |
| 74 | |
| 75 VASSERT_EQ("10", 't', *s3.it_begin()); | |
| 76 VASSERT_EQ("11", 'e', *(s3.it_begin() + 1)); | |
| 77 VASSERT_EQ("12", 's', *(s3.it_begin() + 2)); | |
| 78 VASSERT_EQ("13", 't', *(s3.it_begin() + 3)); | |
| 79 } | |
| 80 | |
| 81 void testDetach() | |
| 82 { | |
| 83 vmime::utility::stringProxy s; | |
| 84 s = "foo"; | |
| 85 | |
| 86 s.detach(); | |
| 87 | |
| 88 VASSERT_EQ("1", static_cast <vmime::size_t>(0), s.length()); | |
| 89 VASSERT_EQ("2", static_cast <vmime::size_t>(0), s.start()); | |
| 90 VASSERT_EQ("3", static_cast <vmime::size_t>(0), s.end()); | |
| 91 } | |
| 92 | |
| 93 void testSet() | |
| 94 { | |
| 95 vmime::string str("This is a test string."); | |
| 96 | |
| 97 vmime::utility::stringProxy s1; | |
| 98 s1.set(str); | |
| 99 | |
| 100 VASSERT_EQ("1", str.length(), s1.length()); | |
| 101 VASSERT_EQ("2", static_cast <vmime::size_t>(0), s1.start()); | |
| 102 VASSERT_EQ("3", str.length(), s1.end()); | |
| 103 | |
| 104 vmime::utility::stringProxy s2; | |
| 105 s2.set(str, 10); | |
| 106 | |
| 107 VASSERT_EQ("4", str.length() - 10, s2.length()); | |
| 108 VASSERT_EQ("5", static_cast <vmime::size_t>(10), s2.start()); | |
| 109 VASSERT_EQ("6", str.length(), s2.end()); | |
| 110 | |
| 111 vmime::utility::stringProxy s3; | |
| 112 s3.set(str, 10, 14); | |
| 113 | |
| 114 VASSERT_EQ("7", static_cast <vmime::size_t>(4), s3.length()); | |
| 115 VASSERT_EQ("8", static_cast <vmime::size_t>(10), s3.start()); | |
| 116 VASSERT_EQ("9", static_cast <vmime::size_t>(14), s3.end()); | |
| 117 | |
| 118 VASSERT_EQ("10", 't', *s3.it_begin()); | |
| 119 VASSERT_EQ("11", 'e', *(s3.it_begin() + 1)); | |
| 120 VASSERT_EQ("12", 's', *(s3.it_begin() + 2)); | |
| 121 VASSERT_EQ("13", 't', *(s3.it_begin() + 3)); | |
| 122 } | |
| 123 | |
| 124 void testExtract() | |
| 125 { | |
| 126 vmime::string str("This is a test string."); | |
| 127 | |
| 128 vmime::utility::stringProxy s1(str, 10, 14); | |
| 129 | |
| 130 std::ostringstream oss1; | |
| 131 vmime::utility::outputStreamAdapter osa1(oss1); | |
| 132 | |
| 133 s1.extract(osa1); | |
| 134 | |
| 135 VASSERT_EQ("1", "test", oss1.str()); | |
| 136 | |
| 137 vmime::utility::stringProxy s2(str); | |
| 138 | |
| 139 std::ostringstream oss2; | |
| 140 vmime::utility::outputStreamAdapter osa2(oss2); | |
| 141 | |
| 142 s2.extract(osa2); | |
| 143 | |
| 144 VASSERT_EQ("2", str, oss2.str()); | |
| 145 } | |
| 146 | |
| 147 void testOperatorLTLT1() | |
| 148 { | |
| 149 vmime::string str("This is a test string."); | |
| 150 | |
| 151 vmime::utility::stringProxy s1(str, 10, 14); | |
| 152 | |
| 153 std::ostringstream oss1; | |
| 154 oss1 << s1; | |
| 155 | |
| 156 VASSERT_EQ("1", "test", oss1.str()); | |
| 157 | |
| 158 vmime::utility::stringProxy s2(str); | |
| 159 | |
| 160 std::ostringstream oss2; | |
| 161 oss2 << s2; | |
| 162 | |
| 163 VASSERT_EQ("2", str, oss2.str()); | |
| 164 } | |
| 165 | |
| 166 void testOperatorLTLT2() | |
| 167 { | |
| 168 vmime::string str("This is a test string."); | |
| 169 | |
| 170 vmime::utility::stringProxy s1(str, 10, 14); | |
| 171 | |
| 172 std::ostringstream oss1; | |
| 173 vmime::utility::outputStreamAdapter osa1(oss1); | |
| 174 | |
| 175 osa1 << s1; | |
| 176 | |
| 177 VASSERT_EQ("1", "test", oss1.str()); | |
| 178 | |
| 179 vmime::utility::stringProxy s2(str); | |
| 180 | |
| 181 std::ostringstream oss2; | |
| 182 vmime::utility::outputStreamAdapter osa2(oss2); | |
| 183 | |
| 184 osa2 << s2; | |
| 185 | |
| 186 VASSERT_EQ("2", str, oss2.str()); | |
| 187 } | |
| 188 | |
| 189 VMIME_TEST_SUITE_END | |
| 190 |
