• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2011  Google, Inc.
3  * Copyright © 2022  Behdad Esfahbod
4  *
5  *  This is part of HarfBuzz, a text shaping library.
6  *
7  * Permission is hereby granted, without written agreement and without
8  * license or royalty fees, to use, copy, modify, and distribute this
9  * software and its documentation for any purpose, provided that the
10  * above copyright notice and the following two paragraphs appear in
11  * all copies of this software.
12  *
13  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
17  * DAMAGE.
18  *
19  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
22  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24  *
25  * Google Author(s): Behdad Esfahbod
26  */
27 
28 /* This file tests that all headers can be included from C++ files,
29  * as well as test the C++ API. */
30 
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
34 
35 #include <hb.h>
36 #include <hb-subset.h>
37 #include <hb-ot.h>
38 #include <hb-aat.h>
39 
40 #ifdef HAVE_GLIB
41 #include <hb-glib.h>
42 #endif
43 
44 #ifdef HAVE_ICU
45 #include <hb-icu.h>
46 #endif
47 
48 #ifdef HAVE_FREETYPE
49 #include <hb-ft.h>
50 #endif
51 
52 #ifdef HAVE_UNISCRIBE
53 #include <hb-uniscribe.h>
54 #endif
55 
56 #ifdef HAVE_CORETEXT
57 #include <hb-coretext.h>
58 #endif
59 
60 
61 /* Test C++ API. */
62 
63 #include "hb-cplusplus.hh"
64 
65 #include <cassert>
66 #include <functional>
67 #include <utility>
68 
69 int
main()70 main ()
71 {
72   hb_buffer_t *b = hb_buffer_create ();
73   hb::shared_ptr<hb_buffer_t> pb {b};
74 
75   /* Test copy-construction. */
76   assert (bool (pb));
77   hb::shared_ptr<hb_buffer_t> pb2 {pb};
78   assert (bool (pb2));
79   assert (bool (pb));
80 
81   /* Test move-construction. */
82   assert (bool (pb2));
83   hb::shared_ptr<hb_buffer_t> pb4 {std::move (pb2)};
84   assert (!bool (pb2));
85   assert (bool (pb4));
86 
87   /* Test copy-assignment. */
88   hb::shared_ptr<hb_buffer_t> pb3;
89   assert (!bool (pb3));
90   pb3 = pb;
91   assert (bool (pb3));
92   assert (bool (pb));
93 
94   /* Test move-assignment. */
95   assert (bool (pb));
96   pb2 = std::move (pb);
97   assert (!bool (pb));
98 
99   pb.reference ();
100   pb.destroy ();
101 
102   pb3.reference ();
103   pb3.destroy ();
104 
105   pb3.swap (pb4);
106 
107   hb_user_data_key_t key;
108   pb.set_user_data (&key, b, nullptr, true);
109   (void) pb.get_user_data (&key);
110 
111   hb::unique_ptr<hb_buffer_t> pb5 {pb3.reference ()};
112 
113 
114   /* Test that shared_ptr / unique_ptr are std::hash'able, and that they
115    * return the same hash (which is the underlying pointer's hash. */
116   std::hash<hb_buffer_t *> hash {};
117   std::hash<hb::shared_ptr<hb_buffer_t>> hash2 {};
118   std::hash<hb::unique_ptr<hb_buffer_t>> hash3 {};
119 
120   assert (hash (b) == hash2 (pb4));
121   assert (hash2 (pb4) == hash2 (pb2));
122   assert (hash (b) == hash3 (pb5));
123 
124   return pb == pb.get_empty () || pb == pb2;
125 }
126