Debian Codegraph @

contrib/C#/NGraphiteTests/FaceTests.cs

raw
1 // SPDX-License-Identifier: MIT OR MPL-2.0 OR LGPL-2.1-or-later OR GPL-2.0-or-later
2 // Copyright (C) 2012 SIL International
3 using System;
4 using NUnit.Framework;
5 using NGraphite;
6 using System.IO;
7
8 namespace NGraphiteTests
9 {
10 [TestFixture()]
11 public class FaceTests
12 {
13 [Test()]
14 public void Face_ConstructPaduakFaceInstance_DoesNotThrowException()
15 {
16 new Face(TestConstants.PaduakFontLocation, FaceOptions.face_default).Dispose();
17 }
18
19 [Test()]
20 public void Face_ConstructPaduakFaceInstanceWithSegCache_DoesNotThrowException()
21 {
22 new Face(TestConstants.PaduakFontLocation, 100, FaceOptions.face_default).Dispose();
23 }
24
25 [Test()]
26 public void Face_ConstructWithNonGraphiteFont_ThrowsArgumentException()
27 {
28 Assert.Throws<ArgumentException>(() => new Face(TestConstants.DejaVuSansLocation, FaceOptions.face_default));
29 }
30
31 [Test()]
32 public void Face_ConstructWithNonInvalidFileName_ThrowsArgumentException()
33 {
34 Assert.Throws<ArgumentException>(() => new Face(TestConstants.DejaVuSansLocation, FaceOptions.face_default));
35 }
36
37 [Test()]
38 public void Face_ConstructWithNonGraphiteFontWithSegCache_ThrowsArgumentException()
39 {
40 Assert.Throws<ArgumentException>(() => new Face(TestConstants.DejaVuSansLocation, 50, FaceOptions.face_default));
41 }
42
43 [Test()]
44 public void Face_ConstructWithNonInvalidFileNameWithSegCache_ThrowsArgumentException()
45 {
46 Assert.Throws<ArgumentException>(() => new Face(TestConstants.DejaVuSansLocation, 50, FaceOptions.face_default));
47 }
48
49 [Test()]
50 public void IsGraphiteFont_WithGraphiteFont_ReturnsTrue()
51 {
52 Assert.IsTrue(Face.IsGraphiteFont(TestConstants.PaduakFontLocation));
53 }
54
55 [Test()]
56 public void IsGraphiteFont_WithNonGraphiteFont_ReturnsFalse()
57 {
58 Assert.IsFalse(Face.IsGraphiteFont(TestConstants.DejaVuSansLocation));
59 }
60
61 [Test()]
62 public void FeaturevalForLang_EnLang_ReturnsNonNullFeatureval()
63 {
64 using (var face = new Face(TestConstants.PaduakFontLocation, FaceOptions.face_default))
65 {
66 Featureval val = face.FeaturevalForLang("en");
67 Assert.NotNull(val);
68 }
69 }
70
71 [Test()]
72 public void FindFref_FindFreatureForkdotString_ReturnsNonNullFeatureRef()
73 {
74 using (var face = new Face(TestConstants.PaduakFontLocation, FaceOptions.face_default))
75 {
76 FeatureRef featureRef = face.FindFref(1801744244);
77 Assert.NotNull(featureRef);
78 }
79 }
80
81 [Test()]
82 public void NFref_PaduakFace_ReturnNineOrMoreFeatures()
83 {
84 using (var face = new Face(TestConstants.PaduakFontLocation, FaceOptions.face_default))
85 {
86 Assert.GreaterOrEqual(face.NFref(), 9);
87 }
88 }
89
90 [Test()]
91 public void Fref_PaduakFace_ReturnNonNullFeatureRef()
92 {
93 using (var face = new Face(TestConstants.PaduakFontLocation, FaceOptions.face_default))
94 {
95 FeatureRef featureRef = face.Fref(0);
96 Assert.NotNull(featureRef);
97 }
98 }
99
100 [Test()]
101 public void NLanguages_PaduakFace_ReturnsExpectedNumberOfLanguages()
102 {
103 using (var face = new Face(TestConstants.PaduakFontLocation, FaceOptions.face_default))
104 {
105 Assert.AreEqual(3, face.NLanguages());
106 }
107 }
108
109 [Test()]
110 public void LangByIndex_PaduakFaceIndexZero_ReturnsNonZeroLangId()
111 {
112 using (var face = new Face(TestConstants.PaduakFontLocation, FaceOptions.face_default))
113 {
114 Assert.AreNotEqual(0, face.LangByIndex(0));
115 }
116
117 }
118
119 [Test()]
120 public void NGlyphs_PaduakFace_ReturnsExpectedNumberOfGlyphs()
121 {
122 using (var face = new Face(TestConstants.PaduakFontLocation, FaceOptions.face_default))
123 {
124 Assert.AreEqual(445, face.NGlyphs());
125 }
126 }
127
128 [Test()]
129 public void StartLogging_PaduakFace_LogFileIsCreated()
130 {
131 int major, minor, bugfix;
132 Graphite2Api.EngineVersion(out major, out minor, out bugfix);
133
134 if (major <= 1 && minor < 2)
135 {
136 using (var face = new Face(TestConstants.PaduakFontLocation, FaceOptions.face_default))
137 {
138 Assert.Throws<NotSupportedException>(() => face.StartLogging(String.Empty));
139 Assert.Throws<NotSupportedException>(() => face.StopLogging());
140 }
141 return;
142 }
143
144 using (var face = new Face(TestConstants.PaduakFontLocation, FaceOptions.face_default))
145 {
146 string filename = Path.GetTempPath() + Guid.NewGuid().ToString();
147 Assert.IsTrue(face.StartLogging(filename));
148 Assert.IsTrue(File.Exists(filename));
149 face.StopLogging();
150 File.Delete(filename);
151 }
152 }
153 }
154 }
155