QtBase  v6.3.1
test-map.cc
Go to the documentation of this file.
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-map.hh"
28 #include <string>
29 
30 static const std::string invalid{"invalid"};
31 
32 int
33 main (int argc, char **argv)
34 {
35 
36  /* Test copy constructor. */
37  {
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);
45  }
46 
47  /* Test copy assignment. */
48  {
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);
56  }
57 
58  /* Test move constructor. */
59  {
60  hb_map_t v {hb_map_t {}};
61  }
62 
63  /* Test move assignment. */
64  {
65  hb_map_t v;
66  v = hb_map_t {};
67  }
68 
69  /* Test initializing from iterable. */
70  {
71  hb_map_t s;
72 
73  s.set (1, 2);
74  s.set (3, 4);
75 
76  hb_map_t v (s);
77 
78  assert (v.get_population () == 2);
79  }
80 
81  /* Test call fini() twice. */
82  {
83  hb_map_t s;
84  for (int i = 0; i < 16; i++)
85  s.set(i, i+1);
86  s.fini();
87  }
88 
89  /* Test initializing from iterator. */
90  {
91  hb_map_t s;
92 
93  s.set (1, 2);
94  s.set (3, 4);
95 
96  hb_map_t v (hb_iter (s));
97 
98  assert (v.get_population () == 2);
99  }
100 
101  /* Test initializing from initializer list and swapping. */
102  {
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);
109  }
110 
111  /* Test class key / value types. */
112  {
116  assert (m1.get_population () == 0);
117  assert (m2.get_population () == 0);
118  assert (m3.get_population () == 0);
119  }
120 
121  {
126 
127  std::string s;
128  for (unsigned i = 1; i < 1000; i++)
129  {
130  s += "x";
131  m0.set (i, i);
132  m1.set (s, i);
133  m2.set (i, s);
134  m3.set (s, s);
135  }
136  }
137 
138  return 0;
139 }
small capitals from c petite p scientific i
[1]
Definition: afcover.h:80
#define assert
Definition: qcborcommon_p.h:63
GLint GLfloat GLfloat GLfloat v2
GLsizei const GLfloat * v
[13]
GLint GLfloat GLfloat v1
GLdouble s
[6]
Definition: qopenglext.h:235
GLsizei const GLchar *const * string
[0]
Definition: qopenglext.h:694
#define v1
unsigned int get_population() const
Definition: hb-map.hh:238
bool set(K key, const V &value)
Definition: hb-map.hh:199
int main(int argc, char **argv)
[1]
Definition: test-map.cc:33