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 <string>
30
31
32 int
main(int argc,char ** argv)33 main (int argc, char **argv)
34 {
35
36 /* Test copy constructor. */
37 {
38 hb_vector_t<int> v1 {1, 2};
39 hb_vector_t<int> v2 {v1};
40 hb_vector_t<int> V2 {v1};
41 assert (v1.length == 2);
42 assert (v1[0] == 1);
43 assert (v1[1] == 2);
44 assert (v2.length == 2);
45 assert (v2[0] == 1);
46 assert (v2[1] == 2);
47 }
48
49 /* Test copy assignment. */
50 {
51 hb_vector_t<int> v1 {1, 2};
52 hb_vector_t<int> v2 = v1;
53 hb_vector_t<int> V2 = v1;
54 assert (v1.length == 2);
55 assert (v1[0] == 1);
56 assert (v1[1] == 2);
57 assert (v2.length == 2);
58 assert (v2[0] == 1);
59 assert (v2[1] == 2);
60 }
61
62 /* Test move constructor. */
63 {
64 hb_vector_t<int> v {hb_vector_t<int> {1, 2}};
65 hb_vector_t<int> V {hb_vector_t<int> {1, 2}};
66 assert (v.length == 2);
67 assert (v[0] == 1);
68 assert (v[1] == 2);
69 }
70
71 /* Test move assignment. */
72 {
73 hb_vector_t<int> v;
74 hb_sorted_vector_t<int> V;
75 v = hb_vector_t<int> {1, 2};
76 V = hb_sorted_vector_t<int> {1, 2};
77 assert (v.length == 2);
78 assert (v[0] == 1);
79 assert (v[1] == 2);
80 }
81
82 /* Test initializing from iterable. */
83 {
84 hb_set_t s;
85
86 s.add (18);
87 s.add (12);
88
89 hb_vector_t<int> v (s);
90 hb_sorted_vector_t<int> V (s);
91
92 assert (v.length == 2);
93 assert (V.length == 2);
94 assert (v[0] == 12);
95 assert (V[0] == 12);
96 assert (v[1] == 18);
97 assert (V[1] == 18);
98 }
99
100 /* Test initializing from iterator. */
101 {
102 hb_set_t s;
103
104 s.add (18);
105 s.add (12);
106
107 hb_vector_t<int> v (hb_iter (s));
108 hb_vector_t<int> V (hb_iter (s));
109
110 assert (v.length == 2);
111 assert (V.length == 2);
112 assert (v[0] == 12);
113 assert (V[0] == 12);
114 assert (v[1] == 18);
115 assert (V[1] == 18);
116 }
117
118 /* Test initializing from initializer list and swapping. */
119 {
120 hb_vector_t<int> v1 {1, 2, 3};
121 hb_vector_t<int> v2 {4, 5};
122 hb_swap (v1, v2);
123 assert (v1.length == 2);
124 assert (v1[0] == 4);
125 assert (v2.length == 3);
126 assert (v2[2] == 3);
127 }
128
129 /* Test initializing sorted-vector from initializer list and swapping. */
130 {
131 hb_sorted_vector_t<int> v1 {1, 2, 3};
132 hb_sorted_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 #if 0
141 {
142 hb_vector_t<std::string> v;
143
144 std::string s;
145 for (unsigned i = 1; i < 100; i++)
146 {
147 s += "x";
148 v.push (s);
149 }
150 }
151 #endif
152
153 return 0;
154 }
155