Bug 1760604 - fix bogus domain to be example.com which is part of our test PAC rules...
[gecko.git] / gfx / harfbuzz / src / test-map.cc
blobfd2b2f0e642b01140c43b4b6311c985ae9f3f165
1 /*
2 * Copyright © 2021 Behdad Esfahbod
4 * This is part of HarfBuzz, a text shaping library.
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.
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.
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.
26 #include "hb.hh"
27 #include "hb-map.hh"
28 #include <string>
30 static const std::string invalid{"invalid"};
32 int
33 main (int argc, char **argv)
36 /* Test copy constructor. */
38 hb_map_t v1;
39 v1.set (1, 2);
40 hb_map_t v2 {v1};
41 assert (v1.get_population () == 1);
42 assert (v2.get_population () == 1);
43 assert (v1[1] == 2);
44 assert (v2[1] == 2);
47 /* Test copy assignment. */
49 hb_map_t v1;
50 v1.set (1, 2);
51 hb_map_t v2 = v1;
52 assert (v1.get_population () == 1);
53 assert (v2.get_population () == 1);
54 assert (v1[1] == 2);
55 assert (v2[1] == 2);
58 /* Test move constructor. */
60 hb_map_t v {hb_map_t {}};
63 /* Test move assignment. */
65 hb_map_t v;
66 v = hb_map_t {};
69 /* Test initializing from iterable. */
71 hb_map_t s;
73 s.set (1, 2);
74 s.set (3, 4);
76 hb_map_t v (s);
78 assert (v.get_population () == 2);
81 /* Test call fini() twice. */
83 hb_map_t s;
84 for (int i = 0; i < 16; i++)
85 s.set(i, i+1);
86 s.fini();
89 /* Test initializing from iterator. */
91 hb_map_t s;
93 s.set (1, 2);
94 s.set (3, 4);
96 hb_map_t v (hb_iter (s));
98 assert (v.get_population () == 2);
101 /* Test initializing from initializer list and swapping. */
103 using pair_t = hb_pair_t<hb_codepoint_t, hb_codepoint_t>;
104 hb_map_t v1 {pair_t{1,2}, pair_t{4,5}};
105 hb_map_t v2 {pair_t{3,4}};
106 hb_swap (v1, v2);
107 assert (v1.get_population () == 1);
108 assert (v2.get_population () == 2);
111 /* Test class key / value types. */
113 hb_hashmap_t<hb_bytes_t, int, std::nullptr_t, int, nullptr, 0> m1;
114 hb_hashmap_t<int, hb_bytes_t, int, std::nullptr_t, 0, nullptr> m2;
115 hb_hashmap_t<hb_bytes_t, hb_bytes_t, std::nullptr_t, std::nullptr_t, nullptr, nullptr> m3;
116 assert (m1.get_population () == 0);
117 assert (m2.get_population () == 0);
118 assert (m3.get_population () == 0);
122 hb_hashmap_t<int, int, int, int, 0, 0> m0;
123 hb_hashmap_t<std::string, int, const std::string*, int, &invalid, 0> m1;
124 hb_hashmap_t<int, std::string, int, const std::string*, 0, &invalid> m2;
125 hb_hashmap_t<std::string, std::string, const std::string*, const std::string*, &invalid, &invalid> m3;
127 std::string s;
128 for (unsigned i = 1; i < 1000; i++)
130 s += "x";
131 m0.set (i, i);
132 m1.set (s, i);
133 m2.set (i, s);
134 m3.set (s, s);
138 return 0;