2021-11-02 03:23:12 +01:00
|
|
|
/*
|
|
|
|
* Copyright © 2021 Behdad Esfahbod
|
|
|
|
*
|
|
|
|
* This is part of HarfBuzz, a text shaping library.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, without written agreement and without
|
|
|
|
* license or royalty fees, to use, copy, modify, and distribute this
|
|
|
|
* software and its documentation for any purpose, provided that the
|
|
|
|
* above copyright notice and the following two paragraphs appear in
|
|
|
|
* all copies of this software.
|
|
|
|
*
|
|
|
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
|
|
|
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
|
|
|
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
* DAMAGE.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
|
|
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
|
|
|
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "hb.hh"
|
|
|
|
#include "hb-vector.hh"
|
|
|
|
#include "hb-set.hh"
|
2022-11-16 00:27:56 +01:00
|
|
|
#include "hb-map.hh"
|
2022-01-14 00:05:42 +01:00
|
|
|
#include <string>
|
2021-11-02 03:23:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
2022-11-14 01:28:09 +01:00
|
|
|
assert (sizeof (hb_vector_t<int>) == sizeof (hb_sorted_vector_t<int>));
|
2021-11-02 03:36:55 +01:00
|
|
|
|
|
|
|
/* Test copy constructor. */
|
|
|
|
{
|
|
|
|
hb_vector_t<int> v1 {1, 2};
|
|
|
|
hb_vector_t<int> v2 {v1};
|
2021-11-02 04:49:32 +01:00
|
|
|
hb_vector_t<int> V2 {v1};
|
2021-11-02 03:36:55 +01:00
|
|
|
assert (v1.length == 2);
|
|
|
|
assert (v1[0] == 1);
|
|
|
|
assert (v1[1] == 2);
|
|
|
|
assert (v2.length == 2);
|
|
|
|
assert (v2[0] == 1);
|
|
|
|
assert (v2[1] == 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test copy assignment. */
|
|
|
|
{
|
|
|
|
hb_vector_t<int> v1 {1, 2};
|
|
|
|
hb_vector_t<int> v2 = v1;
|
2021-11-02 04:49:32 +01:00
|
|
|
hb_vector_t<int> V2 = v1;
|
2021-11-02 03:36:55 +01:00
|
|
|
assert (v1.length == 2);
|
|
|
|
assert (v1[0] == 1);
|
|
|
|
assert (v1[1] == 2);
|
|
|
|
assert (v2.length == 2);
|
|
|
|
assert (v2[0] == 1);
|
|
|
|
assert (v2[1] == 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test move constructor. */
|
|
|
|
{
|
2022-05-12 21:20:10 +02:00
|
|
|
hb_vector_t<int> s {1, 2};
|
|
|
|
hb_sorted_vector_t<int> S {1, 2};
|
|
|
|
hb_vector_t<int> v (std::move (s));
|
|
|
|
hb_sorted_vector_t<int> V (std::move (S));
|
|
|
|
assert (s.length == 0);
|
|
|
|
assert (S.length == 0);
|
2021-11-02 03:36:55 +01:00
|
|
|
assert (v.length == 2);
|
|
|
|
assert (v[0] == 1);
|
|
|
|
assert (v[1] == 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test move assignment. */
|
|
|
|
{
|
2022-05-12 21:20:10 +02:00
|
|
|
hb_vector_t<int> s {1, 2};
|
|
|
|
hb_sorted_vector_t<int> S {1, 2};
|
2021-11-02 03:36:55 +01:00
|
|
|
hb_vector_t<int> v;
|
2021-11-02 04:49:32 +01:00
|
|
|
hb_sorted_vector_t<int> V;
|
2022-05-12 21:20:10 +02:00
|
|
|
v = std::move (s);
|
|
|
|
V = std::move (S);
|
|
|
|
assert (s.length == 0);
|
|
|
|
assert (S.length == 0);
|
2021-11-02 03:36:55 +01:00
|
|
|
assert (v.length == 2);
|
2022-05-12 21:20:10 +02:00
|
|
|
assert (V.length == 2);
|
2021-11-02 03:36:55 +01:00
|
|
|
assert (v[0] == 1);
|
|
|
|
assert (v[1] == 2);
|
|
|
|
}
|
2021-11-02 05:29:14 +01:00
|
|
|
|
2021-11-02 04:49:32 +01:00
|
|
|
/* Test initializing from iterable. */
|
2021-11-02 03:23:12 +01:00
|
|
|
{
|
|
|
|
hb_set_t s;
|
|
|
|
|
|
|
|
s.add (18);
|
|
|
|
s.add (12);
|
|
|
|
|
|
|
|
hb_vector_t<int> v (s);
|
2021-11-02 04:49:32 +01:00
|
|
|
hb_sorted_vector_t<int> V (s);
|
2021-11-02 03:23:12 +01:00
|
|
|
|
|
|
|
assert (v.length == 2);
|
2021-11-02 04:49:32 +01:00
|
|
|
assert (V.length == 2);
|
2021-11-02 03:23:12 +01:00
|
|
|
assert (v[0] == 12);
|
2021-11-02 04:49:32 +01:00
|
|
|
assert (V[0] == 12);
|
2021-11-02 03:23:12 +01:00
|
|
|
assert (v[1] == 18);
|
2021-11-02 04:49:32 +01:00
|
|
|
assert (V[1] == 18);
|
2021-11-02 03:23:12 +01:00
|
|
|
}
|
|
|
|
|
2021-11-02 04:49:32 +01:00
|
|
|
/* Test initializing from iterator. */
|
2021-11-02 03:23:12 +01:00
|
|
|
{
|
|
|
|
hb_set_t s;
|
|
|
|
|
|
|
|
s.add (18);
|
|
|
|
s.add (12);
|
|
|
|
|
|
|
|
hb_vector_t<int> v (hb_iter (s));
|
2021-11-02 04:49:32 +01:00
|
|
|
hb_vector_t<int> V (hb_iter (s));
|
2021-11-02 03:23:12 +01:00
|
|
|
|
|
|
|
assert (v.length == 2);
|
2021-11-02 04:49:32 +01:00
|
|
|
assert (V.length == 2);
|
2021-11-02 03:23:12 +01:00
|
|
|
assert (v[0] == 12);
|
2021-11-02 04:49:32 +01:00
|
|
|
assert (V[0] == 12);
|
2021-11-02 03:23:12 +01:00
|
|
|
assert (v[1] == 18);
|
2021-11-02 04:49:32 +01:00
|
|
|
assert (V[1] == 18);
|
2021-11-02 03:23:12 +01:00
|
|
|
}
|
|
|
|
|
2021-11-02 04:49:32 +01:00
|
|
|
/* Test initializing from initializer list and swapping. */
|
2021-11-02 03:23:12 +01:00
|
|
|
{
|
|
|
|
hb_vector_t<int> v1 {1, 2, 3};
|
|
|
|
hb_vector_t<int> v2 {4, 5};
|
|
|
|
hb_swap (v1, v2);
|
|
|
|
assert (v1.length == 2);
|
|
|
|
assert (v1[0] == 4);
|
|
|
|
assert (v2.length == 3);
|
|
|
|
assert (v2[2] == 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test initializing sorted-vector from initializer list and swapping. */
|
|
|
|
{
|
|
|
|
hb_sorted_vector_t<int> v1 {1, 2, 3};
|
|
|
|
hb_sorted_vector_t<int> v2 {4, 5};
|
|
|
|
hb_swap (v1, v2);
|
|
|
|
assert (v1.length == 2);
|
|
|
|
assert (v1[0] == 4);
|
|
|
|
assert (v2.length == 3);
|
|
|
|
assert (v2[2] == 3);
|
|
|
|
}
|
|
|
|
|
2022-01-14 00:05:42 +01:00
|
|
|
{
|
|
|
|
hb_vector_t<std::string> v;
|
|
|
|
|
|
|
|
std::string s;
|
|
|
|
for (unsigned i = 1; i < 100; i++)
|
|
|
|
{
|
|
|
|
s += "x";
|
|
|
|
v.push (s);
|
|
|
|
}
|
2022-05-19 23:01:23 +02:00
|
|
|
|
|
|
|
hb_vector_t<std::string> v2;
|
|
|
|
|
|
|
|
v2 = v;
|
2022-05-19 23:51:18 +02:00
|
|
|
|
2022-11-26 22:48:57 +01:00
|
|
|
v2.remove_ordered (50);
|
|
|
|
v2.remove_unordered (50);
|
2022-01-14 00:05:42 +01:00
|
|
|
}
|
|
|
|
|
2022-11-16 00:27:56 +01:00
|
|
|
{
|
|
|
|
hb_vector_t<hb_set_t> v;
|
|
|
|
hb_set_t s {1, 5, 7};
|
|
|
|
v.push (s);
|
2022-11-19 02:20:50 +01:00
|
|
|
v << s;
|
2022-11-19 03:26:02 +01:00
|
|
|
assert (s.get_population () == 3);
|
|
|
|
v << std::move (s);
|
|
|
|
assert (s.get_population () == 0);
|
2022-11-16 00:27:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2022-11-16 20:47:05 +01:00
|
|
|
hb_vector_t<hb_map_t> v;
|
2022-11-16 00:27:56 +01:00
|
|
|
hb_map_t m;
|
|
|
|
v.push (m);
|
|
|
|
}
|
|
|
|
|
2021-11-02 03:23:12 +01:00
|
|
|
return 0;
|
|
|
|
}
|