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