xref: /aosp_15_r20/external/harfbuzz_ng/src/test-cff.cc (revision 2d1272b857b1f7575e6e246373e1cb218663db8a)
1 /*
2  * Copyright © 2024  David Corbett
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 #include "hb.hh"
26 #include "hb-ot-cff-common.hh"
27 #include "hb-subset-cff-common.hh"
28 
29 int
main(int argc,char ** argv)30 main (int argc, char **argv)
31 {
32   /* Test encode_num_tp */
33   {
34     CFF::str_buff_t buff;
35     CFF::str_encoder_t encoder (buff);
36     CFF::number_t number;
37     struct num_tp_test {
38       double input;
39       unsigned length;
40       unsigned char output[7];
41     };
42     struct num_tp_test num_tp_tests[] = {
43       { -9.399999999999999, 4, { 0x1E, 0xE9, 0xA4, 0xFF } }, // -9.4
44       { 9.399999999999999999, 3, { 0x1E, 0x9A, 0x4F } }, // 9.4
45       { 456.8, 4, { 0x1E, 0x45, 0x6A, 0x8F } }, // 456.8
46       { 98765.37e2, 5, { 0x1E, 0x98, 0x76, 0x53, 0x7F } }, // 9876537
47       { 1234567890.0, 7, { 0x1E, 0x12, 0x34, 0x56, 0x79, 0xB2, 0xFF } }, // 12345679E2
48       { 9.876537e-4, 7, { 0x1E, 0x98, 0x76, 0x53, 0x7C, 0x10, 0xFF } }, // 9876537E-10
49       { 9.876537e4, 6, { 0x1E, 0x98, 0x76, 0x5A, 0x37, 0xFF } }, // 98765.37
50       { 1e8, 3, { 0x1E, 0x1B, 0x8F } }, // 1E8
51       { 1e-5, 3, { 0x1E, 0x1C, 0x5F } }, // 1E-5
52       { 1.2e8, 4, { 0x1E, 0x12, 0xB7, 0xFF } }, // 12E7
53       { 1.2345e-5, 5, { 0x1E, 0x12, 0x34, 0x5C, 0x9F } }, // 12345E-9
54       { 9.0987654e8, 6, { 0x1E, 0x90, 0x98, 0x76, 0x54, 0x0F } }, // 909876540
55       { 0.1, 3, { 0x1E, 0xA1, 0xFF } }, // .1
56       { -0.1, 3, { 0x1E, 0xEA, 0x1F } }, // -.1
57       { 0.01, 3, { 0x1E, 0x1C, 0x2F } }, // 1E-2
58       { -0.01, 4, { 0x1E, 0xE1, 0xC2, 0xFF } }, // -1E-2
59       { 0.0123, 4, { 0x1E, 0x12, 0x3C, 0x4F } }, // 123E-4
60       { -0.0123, 5, { 0x1E, 0xE1, 0x23, 0xC4, 0xFF } }, // -123E-4
61     };
62     for (size_t t = 0; t < sizeof num_tp_tests / sizeof num_tp_tests[0]; t++)
63     {
64       struct num_tp_test num_tp_test = num_tp_tests[t];
65       number.set_real (num_tp_test.input);
66       encoder.encode_num_tp (number);
67       assert (buff.length == num_tp_test.length);
68       for (unsigned i = 0; i < buff.length; i++)
69 	assert (buff[i] == num_tp_test.output[i]);
70       encoder.reset ();
71     }
72   }
73 
74   return 0;
75 }
76