test-set.cc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #include "hb.hh"
  25. #include "hb-set.hh"
  26. int
  27. main (int argc, char **argv)
  28. {
  29. /* Test copy constructor. */
  30. {
  31. hb_set_t v1 {1, 2};
  32. hb_set_t v2 {v1};
  33. assert (v1.get_population () == 2);
  34. assert (hb_len (hb_iter (v1)) == 2);
  35. assert (v2.get_population () == 2);
  36. }
  37. /* Test copy assignment. */
  38. {
  39. hb_set_t v1 {1, 2};
  40. hb_set_t v2;
  41. v2 = v1;
  42. assert (v1.get_population () == 2);
  43. assert (v2.get_population () == 2);
  44. }
  45. /* Test move constructor. */
  46. {
  47. hb_set_t s {1, 2};
  48. hb_set_t v (std::move (s));
  49. assert (s.get_population () == 0);
  50. assert (hb_len (hb_iter (s)) == 0);
  51. assert (v.get_population () == 2);
  52. }
  53. /* Test move assignment. */
  54. {
  55. hb_set_t s = hb_set_t {1, 2};
  56. hb_set_t v;
  57. v = std::move (s);
  58. assert (s.get_population () == 0);
  59. assert (v.get_population () == 2);
  60. }
  61. /* Test initializing from iterable. */
  62. {
  63. hb_set_t s;
  64. s.add (18);
  65. s.add (12);
  66. hb_vector_t<hb_codepoint_t> v (s);
  67. hb_set_t v0 (v);
  68. hb_set_t v1 (s);
  69. hb_set_t v2 (std::move (s));
  70. assert (s.get_population () == 0);
  71. assert (v0.get_population () == 2);
  72. assert (v1.get_population () == 2);
  73. assert (v2.get_population () == 2);
  74. }
  75. /* Test initializing from iterator. */
  76. {
  77. hb_set_t s;
  78. s.add (18);
  79. s << 12;
  80. /* Sink a range. */
  81. s << hb_pair_t<hb_codepoint_t, hb_codepoint_t> {1, 3};
  82. hb_set_t v (hb_iter (s));
  83. assert (v.get_population () == 5);
  84. }
  85. /* Test initializing from initializer list and swapping. */
  86. {
  87. hb_set_t v1 {1, 2, 3};
  88. hb_set_t v2 {4, 5};
  89. hb_swap (v1, v2);
  90. assert (v1.get_population () == 2);
  91. assert (v2.get_population () == 3);
  92. }
  93. return 0;
  94. }