Imported Upstream version 2.14.2
[platform/upstream/fontconfig.git] / test / test-name-parse.c
1 #include <fontconfig/fontconfig.h>
2 #include <stdio.h>
3
4 static int
5 test (const FcChar8 *query, const FcPattern *expect)
6 {
7     FcPattern *pat;
8     int c = 0;
9
10     c++;
11     pat = FcNameParse (query);
12     if (!pat)
13         goto bail;
14     c++;
15     if (!FcPatternEqual (pat, expect))
16         goto bail;
17     c = 0;
18 bail:
19     FcPatternDestroy (pat);
20
21     return c;
22 }
23
24 #define BEGIN(x)        (x) = FcPatternCreate (); c++;
25 #define END(x)          FcPatternDestroy (x); (x) = NULL
26 int
27 main (void)
28 {
29     FcPattern *expect;
30     int c = 0, ret;
31
32     BEGIN (expect) {
33         FcPatternAddString (expect, FC_FAMILY, (const FcChar8 *)"sans-serif");
34         if ((ret = test ((const FcChar8 *)"sans\\-serif", expect)) != 0)
35             goto bail;
36     } END (expect);
37     BEGIN (expect) {
38         FcPatternAddString (expect, FC_FAMILY, (const FcChar8 *)"Foo");
39         FcPatternAddInteger (expect, FC_SIZE, 10);
40         if ((ret = test ((const FcChar8 *)"Foo-10", expect)) != 0)
41             goto bail;
42     } END (expect);
43     BEGIN (expect) {
44         FcPatternAddString (expect, FC_FAMILY, (const FcChar8 *)"Foo");
45         FcPatternAddString (expect, FC_FAMILY, (const FcChar8 *)"Bar");
46         FcPatternAddInteger (expect, FC_SIZE, 10);
47         if ((ret = test ((const FcChar8 *)"Foo,Bar-10", expect)) != 0)
48             goto bail;
49     } END (expect);
50     BEGIN (expect) {
51         FcPatternAddString (expect, FC_FAMILY, (const FcChar8 *)"Foo");
52         FcPatternAddInteger (expect, FC_WEIGHT, FC_WEIGHT_MEDIUM);
53         if ((ret = test ((const FcChar8 *)"Foo:weight=medium", expect)) != 0)
54             goto bail;
55     } END (expect);
56     BEGIN (expect) {
57         FcPatternAddString (expect, FC_FAMILY, (const FcChar8 *)"Foo");
58         FcPatternAddInteger (expect, FC_WEIGHT, FC_WEIGHT_MEDIUM);
59         if ((ret = test ((const FcChar8 *)"Foo:weight_medium", expect)) != 0)
60             goto bail;
61     } END (expect);
62     BEGIN (expect) {
63         FcPatternAddInteger (expect, FC_WEIGHT, FC_WEIGHT_MEDIUM);
64         if ((ret = test ((const FcChar8 *)":medium", expect)) != 0)
65             goto bail;
66     } END (expect);
67     BEGIN (expect) {
68         FcPatternAddInteger (expect, FC_WEIGHT, FC_WEIGHT_NORMAL);
69         if ((ret = test ((const FcChar8 *)":weight=normal", expect)) != 0)
70             goto bail;
71     } END (expect);
72     BEGIN (expect) {
73         FcPatternAddInteger (expect, FC_WIDTH, FC_WIDTH_NORMAL);
74         if ((ret = test ((const FcChar8 *)":width=normal", expect)) != 0)
75             goto bail;
76     } END (expect);
77     BEGIN (expect) {
78         FcRange *r = FcRangeCreateDouble (FC_WEIGHT_MEDIUM, FC_WEIGHT_BOLD);
79         FcPatternAddRange (expect, FC_WEIGHT, r);
80         FcRangeDestroy (r);
81         if ((ret = test ((const FcChar8 *)":weight=[medium bold]", expect)) != 0)
82             goto bail;
83     } END (expect);
84
85 bail:
86     if (expect)
87         FcPatternDestroy (expect);
88
89     return ret == 0 ? 0 : (c - 1) * 2 + ret;
90 }