1 /*
2  * Copyright © 2019  Facebook, Inc.
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  * Facebook Author(s): Behdad Esfahbod
25  */
26 
27 #include "hb.hh"
28 #include "hb-algs.hh"
29 
30 
31 static char *
test_func(int a,char ** b)32 test_func (int a, char **b)
33 {
34   return b ? b[a] : nullptr;
35 }
36 
37 struct A
38 {
aA39   void a () {}
40 };
41 
42 int
main(int argc,char ** argv)43 main (int argc, char **argv)
44 {
45   int i = 1;
46   auto p = hb_pair (1, i);
47 
48   p.second = 2;
49   assert (i == 2);
50 
51   const int c = 3;
52   auto pc = hb_pair (1, c);
53   assert (pc.second == 3);
54 
55   auto q = p;
56   assert (&q != &p);
57   q.second = 4;
58   assert (i == 4);
59 
60   hb_invoke (test_func, 0, nullptr);
61 
62   A a;
63   hb_invoke (&A::a, a);
64 
65   assert (1 == hb_min (8, 1));
66   assert (8 == hb_max (8, 1));
67 
68   int x = 1, y = 2;
69   hb_min (x, 3);
70   hb_min (3, x);
71   hb_min (x, 4 + 3);
72   int &z = hb_min (x, y);
73   z = 3;
74   assert (x == 3);
75 
76   hb_pair_t<const int*, int> xp = hb_pair_t<int *, long> (nullptr, 0);
77   xp = hb_pair_t<int *, double> (nullptr, 1);
78   xp = hb_pair_t<const int*, int> (nullptr, 1);
79 
80   assert (3 == hb_partial (hb_min, 3) (4));
81   assert (3 == hb_partial<1> (hb_min, 4) (3));
82 
83   auto M0 = hb_partial<2> (hb_max, 0);
84   assert (M0 (-2) == 0);
85   assert (M0 (+2) == 2);
86 
87   assert (hb_add (2) (5) == 7);
88   assert (hb_add (5) (2) == 7);
89 
90   x = 1;
91   assert (++hb_inc (x) == 3);
92   assert (x == 3);
93 
94   return 0;
95 }
96