Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/harfbuzz/src/test-vector.cc @ 3:2c135c81b16c
MERGE: upstream PyMuPDF 1.26.4 with MuPDF 1.26.7
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:44:09 +0200 |
| parents | b50eed0cc0ef |
| children |
comparison
equal
deleted
inserted
replaced
| 0:6015a75abc2d | 3:2c135c81b16c |
|---|---|
| 1 /* | |
| 2 * Copyright © 2021 Behdad Esfahbod | |
| 3 * | |
| 4 * This is part of HarfBuzz, a text shaping library. | |
| 5 * | |
| 6 * Permission is hereby granted, without written agreement and without | |
| 7 * license or royalty fees, to use, copy, modify, and distribute this | |
| 8 * software and its documentation for any purpose, provided that the | |
| 9 * above copyright notice and the following two paragraphs appear in | |
| 10 * all copies of this software. | |
| 11 * | |
| 12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR | |
| 13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES | |
| 14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN | |
| 15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH | |
| 16 * DAMAGE. | |
| 17 * | |
| 18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, | |
| 19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
| 20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS | |
| 21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO | |
| 22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
| 23 * | |
| 24 */ | |
| 25 | |
| 26 #include "hb.hh" | |
| 27 #include "hb-vector.hh" | |
| 28 #include "hb-set.hh" | |
| 29 #include "hb-map.hh" | |
| 30 #include <string> | |
| 31 | |
| 32 | |
| 33 int | |
| 34 main (int argc, char **argv) | |
| 35 { | |
| 36 assert (sizeof (hb_vector_t<int>) == sizeof (hb_sorted_vector_t<int>)); | |
| 37 | |
| 38 /* Test copy constructor. */ | |
| 39 { | |
| 40 hb_vector_t<int> v1 {1, 2}; | |
| 41 hb_vector_t<int> v2 {v1}; | |
| 42 hb_vector_t<int> V2 {v1}; | |
| 43 assert (v1.length == 2); | |
| 44 assert (v1[0] == 1); | |
| 45 assert (v1[1] == 2); | |
| 46 assert (v2.length == 2); | |
| 47 assert (v2[0] == 1); | |
| 48 assert (v2[1] == 2); | |
| 49 } | |
| 50 | |
| 51 /* Test copy assignment. */ | |
| 52 { | |
| 53 hb_vector_t<int> v1 {1, 2}; | |
| 54 hb_vector_t<int> v2 = v1; | |
| 55 hb_vector_t<int> V2 = v1; | |
| 56 assert (v1.length == 2); | |
| 57 assert (v1[0] == 1); | |
| 58 assert (v1[1] == 2); | |
| 59 assert (v2.length == 2); | |
| 60 assert (v2[0] == 1); | |
| 61 assert (v2[1] == 2); | |
| 62 } | |
| 63 | |
| 64 /* Test move constructor. */ | |
| 65 { | |
| 66 hb_vector_t<int> s {1, 2}; | |
| 67 hb_sorted_vector_t<int> S {1, 2}; | |
| 68 hb_vector_t<int> v (std::move (s)); | |
| 69 hb_sorted_vector_t<int> V (std::move (S)); | |
| 70 assert (s.length == 0); | |
| 71 assert (S.length == 0); | |
| 72 assert (v.length == 2); | |
| 73 assert (v[0] == 1); | |
| 74 assert (v[1] == 2); | |
| 75 } | |
| 76 | |
| 77 /* Test move assignment. */ | |
| 78 { | |
| 79 hb_vector_t<int> s {1, 2}; | |
| 80 hb_sorted_vector_t<int> S {1, 2}; | |
| 81 hb_vector_t<int> v; | |
| 82 hb_sorted_vector_t<int> V; | |
| 83 v = std::move (s); | |
| 84 V = std::move (S); | |
| 85 assert (s.length == 0); | |
| 86 assert (S.length == 0); | |
| 87 assert (v.length == 2); | |
| 88 assert (V.length == 2); | |
| 89 assert (v[0] == 1); | |
| 90 assert (v[1] == 2); | |
| 91 } | |
| 92 | |
| 93 /* Test initializing from iterable. */ | |
| 94 { | |
| 95 hb_set_t s; | |
| 96 | |
| 97 s.add (18); | |
| 98 s.add (12); | |
| 99 | |
| 100 hb_vector_t<int> v (s); | |
| 101 hb_sorted_vector_t<int> V (s); | |
| 102 | |
| 103 assert (v.length == 2); | |
| 104 assert (V.length == 2); | |
| 105 assert (v[0] == 12); | |
| 106 assert (V[0] == 12); | |
| 107 assert (v[1] == 18); | |
| 108 assert (V[1] == 18); | |
| 109 } | |
| 110 | |
| 111 /* Test initializing from iterator. */ | |
| 112 { | |
| 113 hb_set_t s; | |
| 114 | |
| 115 s.add (18); | |
| 116 s.add (12); | |
| 117 | |
| 118 hb_vector_t<int> v (hb_iter (s)); | |
| 119 hb_vector_t<int> V (hb_iter (s)); | |
| 120 | |
| 121 assert (v.length == 2); | |
| 122 assert (V.length == 2); | |
| 123 assert (v[0] == 12); | |
| 124 assert (V[0] == 12); | |
| 125 assert (v[1] == 18); | |
| 126 assert (V[1] == 18); | |
| 127 } | |
| 128 | |
| 129 /* Test initializing from initializer list and swapping. */ | |
| 130 { | |
| 131 hb_vector_t<int> v1 {1, 2, 3}; | |
| 132 hb_vector_t<int> v2 {4, 5}; | |
| 133 hb_swap (v1, v2); | |
| 134 assert (v1.length == 2); | |
| 135 assert (v1[0] == 4); | |
| 136 assert (v2.length == 3); | |
| 137 assert (v2[2] == 3); | |
| 138 } | |
| 139 | |
| 140 /* Test initializing sorted-vector from initializer list and swapping. */ | |
| 141 { | |
| 142 hb_sorted_vector_t<int> v1 {1, 2, 3}; | |
| 143 hb_sorted_vector_t<int> v2 {4, 5}; | |
| 144 hb_swap (v1, v2); | |
| 145 assert (v1.length == 2); | |
| 146 assert (v1[0] == 4); | |
| 147 assert (v2.length == 3); | |
| 148 assert (v2[2] == 3); | |
| 149 } | |
| 150 | |
| 151 { | |
| 152 hb_vector_t<std::string> v; | |
| 153 | |
| 154 std::string s; | |
| 155 for (unsigned i = 1; i < 100; i++) | |
| 156 { | |
| 157 s += "x"; | |
| 158 v.push (s); | |
| 159 } | |
| 160 | |
| 161 hb_vector_t<std::string> v2; | |
| 162 | |
| 163 v2 = v; | |
| 164 | |
| 165 v2.remove_ordered (50); | |
| 166 v2.remove_unordered (50); | |
| 167 } | |
| 168 | |
| 169 { | |
| 170 hb_vector_t<hb_set_t> v; | |
| 171 hb_set_t s {1, 5, 7}; | |
| 172 v.push (s); | |
| 173 v << s; | |
| 174 assert (s.get_population () == 3); | |
| 175 v << std::move (s); | |
| 176 assert (s.get_population () == 0); | |
| 177 } | |
| 178 | |
| 179 { | |
| 180 hb_vector_t<hb_map_t> v; | |
| 181 hb_map_t m; | |
| 182 v.push (m); | |
| 183 } | |
| 184 | |
| 185 return 0; | |
| 186 } |
