| 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.Text; |
| 7 |
using System.Runtime.InteropServices; |
| 8 |
using System.IO; |
| 9 |
|
| 10 |
namespace NGraphiteTests |
| 11 |
{ |
| 12 |
[TestFixture] |
| 13 |
public class Graphite2ApiTests |
| 14 |
{ |
| 15 |
const string PaduakFontLocation = TestConstants.PaduakFontLocation; |
| 16 |
|
| 17 |
#region FONT tests |
| 18 |
[Test] |
| 19 |
public void EngineVersion_ReturnsSensibleVersionValues() |
| 20 |
{ |
| 21 |
int major, minor, bugfix; |
| 22 |
Graphite2Api.EngineVersion(out major, out minor, out bugfix); |
| 23 |
Assert.AreEqual(1, major, "Major"); |
| 24 |
if (major == 1) |
| 25 |
Assert.GreaterOrEqual(minor, 0, "Minor"); |
| 26 |
} |
| 27 |
|
| 28 |
[Test] |
| 29 |
public void MakeFace_WithNullOpGetTableFn_ReturnedFaceIsNull() |
| 30 |
{ |
| 31 |
Graphite2Api.GetTableFn returnFace = (IntPtr appFaceHandle, uint name, out int len) => |
| 32 |
{ |
| 33 |
len = 0; |
| 34 |
return IntPtr.Zero; |
| 35 |
}; |
| 36 |
|
| 37 |
IntPtr gr_face = Graphite2Api.MakeFace(IntPtr.Zero,returnFace, 0); |
| 38 |
|
| 39 |
Assert.AreEqual(IntPtr.Zero, gr_face); |
| 40 |
} |
| 41 |
|
| 42 |
[Test] |
| 43 |
public void MakeFaceWithSegCache_WithNullOpGetTableFn_ReturnedFaceIsNull() |
| 44 |
{ |
| 45 |
Graphite2Api.GetTableFn returnFace = (IntPtr appFaceHandle, uint name, out int len) => |
| 46 |
{ |
| 47 |
len = 0; |
| 48 |
return IntPtr.Zero; |
| 49 |
}; |
| 50 |
|
| 51 |
IntPtr gr_face = Graphite2Api.MakeFaceWithSegCache(IntPtr.Zero,returnFace, 100, 0); |
| 52 |
|
| 53 |
Assert.AreEqual(IntPtr.Zero, gr_face); |
| 54 |
} |
| 55 |
|
| 56 |
[Test] |
| 57 |
public void StrToTag_VariousValues_ReturnsExpectedResults() |
| 58 |
{ |
| 59 |
Assert.AreEqual(1181049204, Graphite2Api.StrToTag("Feat"), "Feat"); |
| 60 |
Assert.AreEqual(0, Graphite2Api.StrToTag(String.Empty), "Empty String"); |
| 61 |
// more the 4 chars should be ignored. |
| 62 |
Assert.AreEqual(1181049204, Graphite2Api.StrToTag("FeatOverflow"), "FeatOverflow"); |
| 63 |
} |
| 64 |
|
| 65 |
[Test] |
| 66 |
public void TagToStr_PassFeatEncodedAsId_ReturnsPtrToFeatString() |
| 67 |
{ |
| 68 |
IntPtr ptr = Marshal.StringToCoTaskMemAnsi(" "); |
| 69 |
Graphite2Api.TagToStr(1181049204, ptr); |
| 70 |
var str = Marshal.PtrToStringAnsi(ptr); |
| 71 |
Assert.AreEqual("Feat", str); |
| 72 |
Marshal.FreeCoTaskMem(ptr); |
| 73 |
} |
| 74 |
|
| 75 |
[Test] |
| 76 |
public void FaceFeaturevalForLang_PaduakFontWithEnLang_NonNullFeatureValReturned() |
| 77 |
{ |
| 78 |
using(var face = new PaduakDisposableFace()) |
| 79 |
{ |
| 80 |
uint lang = Graphite2Api.StrToTag("en"); |
| 81 |
IntPtr gr_feature_val = Graphite2Api.FaceFeaturevalForLang(face.Face, lang); |
| 82 |
Assert.AreNotEqual(IntPtr.Zero, gr_feature_val); |
| 83 |
|
| 84 |
Graphite2Api.FeatureValDestroy(gr_feature_val); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
[Test] |
| 89 |
public void FaceFindFref_FindFreatureForkdotString_ReturnsNonNullFeatureRef() |
| 90 |
{ |
| 91 |
using(var face = new PaduakDisposableFace()) |
| 92 |
{ |
| 93 |
IntPtr gr_feature_ref = Graphite2Api.FaceFindFref(face.Face, 1801744244); |
| 94 |
Assert.AreNotEqual(IntPtr.Zero, gr_feature_ref); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
[Test] |
| 99 |
public void FaceNFref_PaduakFace_ReturnNineOrMoreFeatures() |
| 100 |
{ |
| 101 |
using(var face = new PaduakDisposableFace()) |
| 102 |
{ |
| 103 |
int num = Graphite2Api.FaceNFref(face.Face); |
| 104 |
Assert.GreaterOrEqual(num, 9); |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
[Test] |
| 109 |
public void FaceFref_PaduakFace_ReturnsNonNullForEachFeature() |
| 110 |
{ |
| 111 |
using(var face = new PaduakDisposableFace()) |
| 112 |
{ |
| 113 |
int num = Graphite2Api.FaceNFref(face.Face); |
| 114 |
for(ushort i = 0; i < num; ++i) |
| 115 |
{ |
| 116 |
IntPtr gr_feature_ref = Graphite2Api.FaceFref(face.Face, i); |
| 117 |
Assert.AreNotEqual(IntPtr.Zero, gr_feature_ref); |
| 118 |
} |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
[Test] |
| 123 |
public void FaceNLanguages_Paduak_ReturnsExpectedNumberOfLanguages() |
| 124 |
{ |
| 125 |
using(var face = new PaduakDisposableFace()) |
| 126 |
{ |
| 127 |
Assert.AreEqual(3, Graphite2Api.FaceNLanguages(face.Face)); |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
[Test] |
| 132 |
public void FaceLangByIndex_IndexZero_ReturnsNonZeroLangId() |
| 133 |
{ |
| 134 |
using(var face = new PaduakDisposableFace()) |
| 135 |
{ |
| 136 |
uint langId = Graphite2Api.FaceLangByIndex(face.Face, 0); |
| 137 |
Assert.AreNotEqual(0, langId); |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
[Test] |
| 142 |
public void FaceDestroy_Null_NoExceptionThrown() |
| 143 |
{ |
| 144 |
Graphite2Api.FaceDestroy(IntPtr.Zero); |
| 145 |
} |
| 146 |
|
| 147 |
[Test] |
| 148 |
public void FaceNGlyphs_PaduakFace_ReturnsExpectedNumber() |
| 149 |
{ |
| 150 |
using(var face = new PaduakDisposableFace()) |
| 151 |
{ |
| 152 |
Assert.AreEqual(445, Graphite2Api.FaceNGlyphs(face.Face)); |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
[Test] |
| 157 |
public void MakeFileFace_UsingPadaukFont_NonNullFaceIsReturned() |
| 158 |
{ |
| 159 |
IntPtr gr_face = Graphite2Api.MakeFileFace(PaduakFontLocation, 0); |
| 160 |
Assert.AreNotEqual(IntPtr.Zero, gr_face); |
| 161 |
|
| 162 |
Graphite2Api.FaceDestroy(gr_face); |
| 163 |
} |
| 164 |
|
| 165 |
[Test] |
| 166 |
public void MakeFileFaceWithSegCache_UsingPadaukFont_NonNullFaceIsReturned() |
| 167 |
{ |
| 168 |
IntPtr gr_face = Graphite2Api.MakeFileFaceWithSegCache(PaduakFontLocation, 100, 0); |
| 169 |
Assert.AreNotEqual(IntPtr.Zero, gr_face); |
| 170 |
|
| 171 |
Graphite2Api.FaceDestroy(gr_face); |
| 172 |
} |
| 173 |
|
| 174 |
[Test] |
| 175 |
public void MakeFont_UsingPadaukFont_NonNullFontIsReturned() |
| 176 |
{ |
| 177 |
IntPtr gr_face = Graphite2Api.MakeFileFace(PaduakFontLocation, 0); |
| 178 |
IntPtr gr_font = Graphite2Api.MakeFont(20, gr_face); |
| 179 |
|
| 180 |
Assert.AreNotEqual(IntPtr.Zero, gr_font); |
| 181 |
|
| 182 |
Graphite2Api.FontDestroy(gr_font); |
| 183 |
Graphite2Api.FaceDestroy(gr_face); |
| 184 |
} |
| 185 |
|
| 186 |
[Test] |
| 187 |
public void MakeFontWithAdvanceFn_UsingPadaukFont_NonNullFontIsReturned() |
| 188 |
{ |
| 189 |
IntPtr gr_face = Graphite2Api.MakeFileFace(PaduakFontLocation, 0); |
| 190 |
|
| 191 |
Graphite2Api.AdvanceFn advance = (IntPtr appFontHandle, UInt16 glyphid) => 0; |
| 192 |
|
| 193 |
IntPtr gr_font = Graphite2Api.MakeFontWithAdvanceFn(20, IntPtr.Zero, advance, gr_face); |
| 194 |
|
| 195 |
Assert.AreNotEqual(IntPtr.Zero, gr_font); |
| 196 |
|
| 197 |
Graphite2Api.FontDestroy(gr_font); |
| 198 |
Graphite2Api.FaceDestroy(gr_face); |
| 199 |
} |
| 200 |
|
| 201 |
[Test] |
| 202 |
public void FontDestroy_Null_NoExceptionThrown() |
| 203 |
{ |
| 204 |
Graphite2Api.FontDestroy(IntPtr.Zero); |
| 205 |
} |
| 206 |
|
| 207 |
[Test] |
| 208 |
public void FrefFeatureValue_FirstPaduakFeature_ReturnsZero() |
| 209 |
{ |
| 210 |
using (var feature = new PaduakFeatureVal()) |
| 211 |
{ |
| 212 |
uint lang = Graphite2Api.StrToTag("en"); |
| 213 |
IntPtr gr_feature_val = Graphite2Api.FaceFeaturevalForLang(feature.Face, lang); |
| 214 |
|
| 215 |
UInt16 val = Graphite2Api.FrefFeatureValue(feature.FeatureRef, gr_feature_val); |
| 216 |
Assert.AreEqual(0, val); |
| 217 |
|
| 218 |
Graphite2Api.FeatureValDestroy(gr_feature_val); |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
[Test] |
| 223 |
public void FrefSetFeatureValue_SettingsThekdotFeature_FailsWithZeroReturnCode() |
| 224 |
{ |
| 225 |
using(var face = new PaduakDisposableFace()) |
| 226 |
{ |
| 227 |
uint lang = Graphite2Api.StrToTag("en"); |
| 228 |
IntPtr gr_feature_val = Graphite2Api.FaceFeaturevalForLang(face.Face, lang); |
| 229 |
IntPtr gr_feature_ref = Graphite2Api.FaceFindFref(face.Face, 1801744244); |
| 230 |
int ret = Graphite2Api.FrefSetFeatureValue(gr_feature_ref, 12, gr_feature_val); |
| 231 |
Assert.AreEqual(0, ret); |
| 232 |
|
| 233 |
Graphite2Api.FeatureValDestroy(gr_feature_val); |
| 234 |
} |
| 235 |
} |
| 236 |
|
| 237 |
[Test] |
| 238 |
public void FrefId_FirstPaduakFeature_ReturnsExpectedId() |
| 239 |
{ |
| 240 |
using (var feature = new PaduakFeatureVal()) |
| 241 |
{ |
| 242 |
UInt32 id = Graphite2Api.FrefId(feature.FeatureRef); |
| 243 |
Assert.AreEqual(1801744244, id); |
| 244 |
IntPtr ptr = Marshal.StringToCoTaskMemAnsi(" "); |
| 245 |
Graphite2Api.TagToStr(id, ptr); |
| 246 |
var str = Marshal.PtrToStringAnsi(ptr); |
| 247 |
Assert.AreEqual("kdot", str); |
| 248 |
Marshal.FreeCoTaskMem(ptr); |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
[Test] |
| 253 |
public void FrefNValues_FirstPaduakFeature_ReturnsTwo() |
| 254 |
{ |
| 255 |
using (var feature = new PaduakFeatureVal()) |
| 256 |
{ |
| 257 |
int numval = Graphite2Api.FrefNValues(feature.FeatureRef); |
| 258 |
Assert.AreEqual(2, numval); |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
[Test] |
| 263 |
public void FrefValue_FirstPaduakFeatureSettingOne_ReturnsOne() |
| 264 |
{ |
| 265 |
using (var feature = new PaduakFeatureVal()) |
| 266 |
{ |
| 267 |
UInt16 val = Graphite2Api.FrefValue(feature.FeatureRef, 1); |
| 268 |
Assert.AreEqual(1, val); |
| 269 |
} |
| 270 |
} |
| 271 |
|
| 272 |
[Test] |
| 273 |
public void FrefLabel_FirstPaduakFeature_ReturnsExpectedString() |
| 274 |
{ |
| 275 |
using (var feature = new PaduakFeatureVal()) |
| 276 |
{ |
| 277 |
ushort lang = (ushort)Graphite2Api.StrToTag("en"); |
| 278 |
UInt32 length; |
| 279 |
|
| 280 |
IntPtr labelPtr = Graphite2Api.FrefLabel(feature.FeatureRef, ref lang, Encform.Utf8, out length); |
| 281 |
string label = Marshal.PtrToStringAnsi(labelPtr); |
| 282 |
Assert.AreEqual("Khamti style dots", label); |
| 283 |
|
| 284 |
Graphite2Api.LabelDestroy(labelPtr); |
| 285 |
} |
| 286 |
} |
| 287 |
|
| 288 |
[Test] |
| 289 |
public void FrefValueLabel_FirstPaduakFeature_ReturnsFalseString() |
| 290 |
{ |
| 291 |
using (var feature = new PaduakFeatureVal()) |
| 292 |
{ |
| 293 |
uint length; |
| 294 |
ushort lang = (ushort)Graphite2Api.StrToTag("en"); |
| 295 |
IntPtr labelPtr = Graphite2Api.FrefValueLabel(feature.FeatureRef, 0, ref lang, Encform.Utf8, out length); |
| 296 |
Assert.AreEqual("False", Marshal.PtrToStringAnsi(labelPtr)); |
| 297 |
Assert.AreEqual(5, length); |
| 298 |
|
| 299 |
Graphite2Api.LabelDestroy(labelPtr); |
| 300 |
} |
| 301 |
} |
| 302 |
|
| 303 |
[Test] |
| 304 |
public void LabelDestroy_Null_DoesNotThrowException() |
| 305 |
{ |
| 306 |
Graphite2Api.LabelDestroy(IntPtr.Zero); |
| 307 |
} |
| 308 |
|
| 309 |
[Test] |
| 310 |
public void FeaturevalClone_CloneAFeature_ReturnADifferentInstance() |
| 311 |
{ |
| 312 |
using(var face = new PaduakDisposableFace()) |
| 313 |
{ |
| 314 |
uint lang = Graphite2Api.StrToTag("en"); |
| 315 |
IntPtr one = Graphite2Api.FaceFeaturevalForLang(face.Face, lang); |
| 316 |
IntPtr two = Graphite2Api.FeaturevalClone(one); |
| 317 |
Assert.NotNull(one, "one"); |
| 318 |
Assert.NotNull(two, "two"); |
| 319 |
Assert.AreNotEqual(one, two); |
| 320 |
|
| 321 |
Graphite2Api.FeatureValDestroy(one); |
| 322 |
Graphite2Api.FeatureValDestroy(two); |
| 323 |
} |
| 324 |
} |
| 325 |
|
| 326 |
[Test] |
| 327 |
public void FeatureValDestroy_Null_DoesNotThrowException() |
| 328 |
{ |
| 329 |
Graphite2Api.FeatureValDestroy(IntPtr.Zero); |
| 330 |
} |
| 331 |
|
| 332 |
#endregion |
| 333 |
|
| 334 |
#region Segment Tests |
| 335 |
|
| 336 |
[Test] |
| 337 |
public void CinfoUnicodeChar_OnTestCinfo_ReturnsExpectecCharacter() |
| 338 |
{ |
| 339 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 340 |
{ |
| 341 |
IntPtr firstSlot = Graphite2Api.SegFirstSlot(seg.Seg); |
| 342 |
IntPtr char_info = Graphite2Api.SegCinfo(seg.Seg, (uint)Graphite2Api.SlotBefore(firstSlot)); |
| 343 |
Assert.AreEqual(104, Graphite2Api.CinfoUnicodeChar(char_info)); |
| 344 |
} |
| 345 |
} |
| 346 |
|
| 347 |
[Test] |
| 348 |
public void CinfoBreakWeight_OnTestCharInfo_ReturnsExpectedBreakWeight() |
| 349 |
{ |
| 350 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 351 |
{ |
| 352 |
IntPtr firstSlot = Graphite2Api.SegFirstSlot(seg.Seg); |
| 353 |
IntPtr char_info = Graphite2Api.SegCinfo(seg.Seg, (uint)Graphite2Api.SlotBefore(firstSlot)); |
| 354 |
int bw = Graphite2Api.CinfoBreakWeight(char_info); |
| 355 |
Assert.AreEqual(-30, bw); |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
[Test] |
| 360 |
public void CinfoAfter_OnTestCinfo_ReturnsExpectedIndex() |
| 361 |
{ |
| 362 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 363 |
{ |
| 364 |
IntPtr firstSlot = Graphite2Api.SegFirstSlot(seg.Seg); |
| 365 |
IntPtr char_info = Graphite2Api.SegCinfo(seg.Seg, (uint)Graphite2Api.SlotBefore(firstSlot)); |
| 366 |
Assert.AreEqual(0, Graphite2Api.CinfoAfter(char_info)); |
| 367 |
} |
| 368 |
} |
| 369 |
|
| 370 |
[Test] |
| 371 |
public void CinfoBefore_OnTestCinfo_ReturnsExpectedIndex() |
| 372 |
{ |
| 373 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 374 |
{ |
| 375 |
IntPtr firstSlot = Graphite2Api.SegFirstSlot(seg.Seg); |
| 376 |
IntPtr char_info = Graphite2Api.SegCinfo(seg.Seg, (uint)Graphite2Api.SlotBefore(firstSlot)); |
| 377 |
Assert.AreEqual(0, Graphite2Api.CinfoBefore(char_info)); |
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
[Test] |
| 382 |
public void CinfoBase_OnTestCinfo_ReturnsExpectedIndex() |
| 383 |
{ |
| 384 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 385 |
{ |
| 386 |
IntPtr firstSlot = Graphite2Api.SegFirstSlot(seg.Seg); |
| 387 |
IntPtr char_info = Graphite2Api.SegCinfo(seg.Seg, (uint)Graphite2Api.SlotBefore(firstSlot)); |
| 388 |
Assert.AreEqual(0, Graphite2Api.CinfoBase(char_info)); |
| 389 |
} |
| 390 |
} |
| 391 |
|
| 392 |
[Test] |
| 393 |
public void CountUnicodeCharacters_TestString_ReturnsExpectedNumberOfChars() |
| 394 |
{ |
| 395 |
|
| 396 |
IntPtr str = Marshal.StringToCoTaskMemAnsi("hello world"); |
| 397 |
IntPtr error = new IntPtr(0); |
| 398 |
int numCodePoints = Graphite2Api.CountUnicodeCharacters(Encform.Utf8, str, IntPtr.Zero, ref error); |
| 399 |
Assert.AreEqual(11, numCodePoints); |
| 400 |
Marshal.FreeCoTaskMem(str); |
| 401 |
} |
| 402 |
|
| 403 |
[Test] |
| 404 |
public void MakeSeg_WithTestStringAndPaduakFont_ReturnsNonNullSegment() |
| 405 |
{ |
| 406 |
using (var font = new PaduakDisposableFont()) |
| 407 |
{ |
| 408 |
IntPtr str = Marshal.StringToCoTaskMemAnsi("hello world"); |
| 409 |
IntPtr error = new IntPtr(0); |
| 410 |
int numCodePoints = Graphite2Api.CountUnicodeCharacters(Encform.Utf8, str, IntPtr.Zero, ref error); |
| 411 |
IntPtr seg = Graphite2Api.MakeSeg(font.Font, font.Face, 0, IntPtr.Zero, Encform.Utf8, str, numCodePoints, 0); |
| 412 |
Assert.AreNotEqual(IntPtr.Zero, seg); |
| 413 |
|
| 414 |
Graphite2Api.SegDestroy(seg); |
| 415 |
Marshal.FreeCoTaskMem(str); |
| 416 |
} |
| 417 |
} |
| 418 |
|
| 419 |
[Test] |
| 420 |
public void SegDestroy_NULL_DoesNotThrowException() |
| 421 |
{ |
| 422 |
Graphite2Api.SegDestroy(IntPtr.Zero); |
| 423 |
} |
| 424 |
|
| 425 |
[Test] |
| 426 |
public void SegAdvanceX_OnTestSeg_ReturnsExpectedAdvance() |
| 427 |
{ |
| 428 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 429 |
{ |
| 430 |
Assert.AreEqual(90.234375f, Graphite2Api.SegAdvanceX(seg.Seg)); |
| 431 |
} |
| 432 |
} |
| 433 |
|
| 434 |
[Test] |
| 435 |
public void SegAdvanceY_OnTestSeg_ReturnsExpectedAdvance() |
| 436 |
{ |
| 437 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 438 |
{ |
| 439 |
Assert.AreEqual(0.0f, Graphite2Api.SegAdvanceY(seg.Seg)); |
| 440 |
} |
| 441 |
} |
| 442 |
|
| 443 |
[Test] |
| 444 |
public void SegNCinfo_OnTestSeg_ReturnsExpectedNumber() |
| 445 |
{ |
| 446 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 447 |
{ |
| 448 |
Assert.AreEqual(11, Graphite2Api.SegNCinfo(seg.Seg)); |
| 449 |
|
| 450 |
} |
| 451 |
} |
| 452 |
|
| 453 |
[Test] |
| 454 |
public void SegCinfo_OnATestSegAndSlot_ReturnsNonNullCharInfoPtr() |
| 455 |
{ |
| 456 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 457 |
{ |
| 458 |
IntPtr firstSlot = Graphite2Api.SegFirstSlot(seg.Seg); |
| 459 |
IntPtr char_info = Graphite2Api.SegCinfo(seg.Seg, (uint)Graphite2Api.SlotBefore(firstSlot)); |
| 460 |
Assert.AreNotEqual(IntPtr.Zero, char_info); |
| 461 |
} |
| 462 |
} |
| 463 |
|
| 464 |
[Test] |
| 465 |
public void SegNSlots_OnTestSeg_ReturnsExpectedNumberOfSlots() |
| 466 |
{ |
| 467 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 468 |
{ |
| 469 |
Assert.AreEqual(11, Graphite2Api.SegNSlots(seg.Seg)); |
| 470 |
} |
| 471 |
} |
| 472 |
|
| 473 |
[Test] |
| 474 |
public void SegFirstSlot_OnPaduakTestSegment_ReturnsNonNullSlot() |
| 475 |
{ |
| 476 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 477 |
{ |
| 478 |
IntPtr slot = Graphite2Api.SegFirstSlot(seg.Seg); |
| 479 |
Assert.AreNotEqual(IntPtr.Zero, slot); |
| 480 |
} |
| 481 |
} |
| 482 |
|
| 483 |
[Test] |
| 484 |
public void SegLastSlot_OnPaduakTestSegment_ReturnsNonNullSlot() |
| 485 |
{ |
| 486 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 487 |
{ |
| 488 |
IntPtr slot = Graphite2Api.SegLastSlot(seg.Seg); |
| 489 |
Assert.AreNotEqual(IntPtr.Zero, slot); |
| 490 |
} |
| 491 |
} |
| 492 |
|
| 493 |
[Test] |
| 494 |
public void SegJustify_OnATestSegment_DoesNotThrowException() |
| 495 |
{ |
| 496 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 497 |
{ |
| 498 |
IntPtr slot = Graphite2Api.SegFirstSlot(seg.Seg); |
| 499 |
Graphite2Api.SegJustify(seg.Seg, slot, seg.Font, 100, 0, IntPtr.Zero, IntPtr.Zero); |
| 500 |
} |
| 501 |
} |
| 502 |
|
| 503 |
[Test] |
| 504 |
public void SlotNextInSegment_OnFirstSlotInPaduakTestSegment_ReturnsNonNullSlot() |
| 505 |
{ |
| 506 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 507 |
{ |
| 508 |
IntPtr slot = Graphite2Api.SegFirstSlot(seg.Seg); |
| 509 |
Assert.AreNotEqual(IntPtr.Zero, Graphite2Api.SlotNextInSegment(slot)); |
| 510 |
} |
| 511 |
} |
| 512 |
|
| 513 |
[Test] |
| 514 |
public void SlotPrevInSegment_OnSecondSlotInPaduakTestSegment_ReturnsNonNullSlot() |
| 515 |
{ |
| 516 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 517 |
{ |
| 518 |
IntPtr firstSlot = Graphite2Api.SegFirstSlot(seg.Seg); |
| 519 |
IntPtr secondSlot = Graphite2Api.SlotNextInSegment(firstSlot); |
| 520 |
|
| 521 |
Assert.AreNotEqual(IntPtr.Zero, Graphite2Api.SlotPrevInSegment(secondSlot), "returned null slot"); |
| 522 |
Assert.AreEqual(firstSlot, Graphite2Api.SlotPrevInSegment(secondSlot), "should equal first slot"); |
| 523 |
} |
| 524 |
} |
| 525 |
|
| 526 |
[Test] |
| 527 |
public void SlotAttachedTo_TestSegFirstSlot_ReturnsNullSlotPtr() |
| 528 |
{ |
| 529 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 530 |
{ |
| 531 |
IntPtr firstSlot = Graphite2Api.SegFirstSlot(seg.Seg); |
| 532 |
IntPtr parentSlot = Graphite2Api.SlotAttachedTo(firstSlot); |
| 533 |
Assert.AreEqual(IntPtr.Zero, parentSlot); |
| 534 |
} |
| 535 |
} |
| 536 |
|
| 537 |
[Test] |
| 538 |
public void SlotFirstAttachment_TestSegFirstSlot_ReturnsNullSlotPtr() |
| 539 |
{ |
| 540 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 541 |
{ |
| 542 |
IntPtr firstSlot = Graphite2Api.SegFirstSlot(seg.Seg); |
| 543 |
IntPtr slot = Graphite2Api.SlotFirstAttachment(firstSlot); |
| 544 |
Assert.AreEqual(IntPtr.Zero, slot); |
| 545 |
} |
| 546 |
} |
| 547 |
|
| 548 |
[Test] |
| 549 |
public void SlotNextSiblingAttachment_TestSegFirstSlot_ReturnsNonNullSlotPtr() |
| 550 |
{ |
| 551 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 552 |
{ |
| 553 |
IntPtr firstSlot = Graphite2Api.SegFirstSlot(seg.Seg); |
| 554 |
IntPtr slot = Graphite2Api.SlotNextSiblingAttachment(firstSlot); |
| 555 |
Assert.AreNotEqual(IntPtr.Zero, slot); |
| 556 |
} |
| 557 |
} |
| 558 |
|
| 559 |
[Test] |
| 560 |
public void SlotGid_TestSegFirstSlot_ReturnsExpectedGid() |
| 561 |
{ |
| 562 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 563 |
{ |
| 564 |
IntPtr firstSlot = Graphite2Api.SegFirstSlot(seg.Seg); |
| 565 |
Assert.AreEqual(75, Graphite2Api.SlotGid(firstSlot)); |
| 566 |
} |
| 567 |
} |
| 568 |
|
| 569 |
[Test] |
| 570 |
public void SlotOriginX_TestSegFirstSlot_ReturnsExpectedOffset() |
| 571 |
{ |
| 572 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 573 |
{ |
| 574 |
IntPtr firstSlot = Graphite2Api.SegFirstSlot(seg.Seg); |
| 575 |
Assert.AreEqual(0, Graphite2Api.SlotOriginX(firstSlot)); |
| 576 |
} |
| 577 |
} |
| 578 |
|
| 579 |
[Test] |
| 580 |
public void SlotOriginY_TestSegFirstSlot_ReturnsExpectedOffset() |
| 581 |
{ |
| 582 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 583 |
{ |
| 584 |
IntPtr firstSlot = Graphite2Api.SegFirstSlot(seg.Seg); |
| 585 |
Assert.AreEqual(0, Graphite2Api.SlotOriginY(firstSlot)); |
| 586 |
} |
| 587 |
} |
| 588 |
|
| 589 |
[Test] |
| 590 |
public void SlotAdvanceX_OnTestSeg_ReturnsExpecedAdvance() |
| 591 |
{ |
| 592 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 593 |
{ |
| 594 |
IntPtr slot = Graphite2Api.SegFirstSlot(seg.Seg); |
| 595 |
Assert.AreEqual(9.9609375f, Graphite2Api.SlotAdvanceX(slot, seg.Face, seg.Font)); |
| 596 |
} |
| 597 |
} |
| 598 |
|
| 599 |
[Test] |
| 600 |
public void SlotAdvanceY_OnTestSeg_ReturnsExpecedAdvance() |
| 601 |
{ |
| 602 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 603 |
{ |
| 604 |
IntPtr slot = Graphite2Api.SegFirstSlot(seg.Seg); |
| 605 |
Assert.AreEqual(0.0f, Graphite2Api.SlotAdvanceY(slot, seg.Face, seg.Font)); |
| 606 |
} |
| 607 |
} |
| 608 |
|
| 609 |
[Test] |
| 610 |
public void SlotBefore_OnTestSlot_ReturnsExpectedIndex() |
| 611 |
{ |
| 612 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 613 |
{ |
| 614 |
IntPtr firstSlot = Graphite2Api.SegFirstSlot(seg.Seg); |
| 615 |
Assert.AreEqual(0, (uint)Graphite2Api.SlotBefore(firstSlot)); |
| 616 |
} |
| 617 |
} |
| 618 |
|
| 619 |
[Test] |
| 620 |
public void SlotAfter_OnTestSlot_ReturnsExpectedIndex() |
| 621 |
{ |
| 622 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 623 |
{ |
| 624 |
IntPtr firstSlot = Graphite2Api.SegFirstSlot(seg.Seg); |
| 625 |
Assert.AreEqual(0, (uint)Graphite2Api.SlotAfter(firstSlot)); |
| 626 |
} |
| 627 |
} |
| 628 |
|
| 629 |
[Test] |
| 630 |
public void SlotIndex_OnTestSlot_ReturnsExpectedIndex() |
| 631 |
{ |
| 632 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 633 |
{ |
| 634 |
IntPtr firstSlot = Graphite2Api.SegFirstSlot(seg.Seg); |
| 635 |
Assert.AreEqual(0, (uint)Graphite2Api.SlotIndex(firstSlot)); |
| 636 |
} |
| 637 |
} |
| 638 |
|
| 639 |
[Test] |
| 640 |
public void SlotAttr_OnTestSegLastSlot_ReturnsExpectedAttributeValue() |
| 641 |
{ |
| 642 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 643 |
{ |
| 644 |
IntPtr firstSlot = Graphite2Api.SegLastSlot(seg.Seg); |
| 645 |
Assert.AreEqual(526, Graphite2Api.SlotAttr(firstSlot, seg.Seg, 0, 0)); |
| 646 |
} |
| 647 |
} |
| 648 |
|
| 649 |
[Test] |
| 650 |
public void SlotCanInsertBefore_OnTestSegLastSlot_ReturnsTrue() |
| 651 |
{ |
| 652 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 653 |
{ |
| 654 |
IntPtr firstSlot = Graphite2Api.SegLastSlot(seg.Seg); |
| 655 |
Assert.AreEqual(1, Graphite2Api.SlotCanInsertBefore(firstSlot)); |
| 656 |
} |
| 657 |
} |
| 658 |
|
| 659 |
[Test] |
| 660 |
public void SlotOriginal_OnTestSegLastSlot_ReturnsExpectedCharInfoValue() |
| 661 |
{ |
| 662 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 663 |
{ |
| 664 |
IntPtr firstSlot = Graphite2Api.SegLastSlot(seg.Seg); |
| 665 |
Assert.AreEqual(10, Graphite2Api.SlotOriginal(firstSlot)); |
| 666 |
} |
| 667 |
} |
| 668 |
|
| 669 |
[Test] |
| 670 |
public void SlotLinebreakBefore_OnATestSlot_DoesNotThrowException() |
| 671 |
{ |
| 672 |
using(var seg = new PaduakDisposableTestSegment("hello world")) |
| 673 |
{ |
| 674 |
IntPtr firstSlot = Graphite2Api.SegLastSlot(seg.Seg); |
| 675 |
Graphite2Api.SlotLinebreakBefore(firstSlot); |
| 676 |
} |
| 677 |
} |
| 678 |
|
| 679 |
#endregion |
| 680 |
|
| 681 |
#region Log Tests |
| 682 |
|
| 683 |
[Test] |
| 684 |
public void StartLogging_WithTestFaceAndValidLogFileLocation_FileShouldBeCreated() |
| 685 |
{ |
| 686 |
int major, minor, bugfix; |
| 687 |
Graphite2Api.EngineVersion(out major, out minor, out bugfix); |
| 688 |
|
| 689 |
if (major <= 1 && minor < 2) |
| 690 |
Assert.Ignore("Need newer engine to support logging"); |
| 691 |
|
| 692 |
using(var face = new PaduakDisposableFace()) |
| 693 |
{ |
| 694 |
string filename = Path.GetTempPath() + Guid.NewGuid().ToString(); |
| 695 |
Assert.IsTrue(Graphite2Api.StartLogging(face.Face, filename)); |
| 696 |
Assert.IsTrue(File.Exists(filename)); |
| 697 |
Graphite2Api.StopLogging(face.Face); |
| 698 |
File.Delete(filename); |
| 699 |
} |
| 700 |
|
| 701 |
} |
| 702 |
|
| 703 |
#endregion |
| 704 |
|
| 705 |
#region test helpers |
| 706 |
|
| 707 |
internal class PaduakDisposableFace : IDisposable |
| 708 |
{ |
| 709 |
public IntPtr Face; |
| 710 |
const string PaduakFontLocation = Graphite2ApiTests.PaduakFontLocation; |
| 711 |
|
| 712 |
public PaduakDisposableFace() |
| 713 |
{ |
| 714 |
Face = Graphite2Api.MakeFileFace(PaduakFontLocation, 0); |
| 715 |
} |
| 716 |
|
| 717 |
#region IDisposable implementation |
| 718 |
public void Dispose() |
| 719 |
{ |
| 720 |
Graphite2Api.FaceDestroy(Face); |
| 721 |
} |
| 722 |
#endregion |
| 723 |
} |
| 724 |
|
| 725 |
internal class PaduakDisposableFont : IDisposable |
| 726 |
{ |
| 727 |
public IntPtr Font; |
| 728 |
PaduakDisposableFace _face; |
| 729 |
|
| 730 |
public IntPtr Face |
| 731 |
{ |
| 732 |
get { return _face.Face; } |
| 733 |
} |
| 734 |
|
| 735 |
public PaduakDisposableFont() |
| 736 |
{ |
| 737 |
_face = new PaduakDisposableFace(); |
| 738 |
Font = Graphite2Api.MakeFont(20, _face.Face); |
| 739 |
} |
| 740 |
|
| 741 |
#region IDisposable implementation |
| 742 |
public void Dispose() |
| 743 |
{ |
| 744 |
Graphite2Api.FontDestroy(Font); |
| 745 |
_face.Dispose(); |
| 746 |
} |
| 747 |
#endregion |
| 748 |
} |
| 749 |
|
| 750 |
internal class PaduakFeatureVal : IDisposable |
| 751 |
{ |
| 752 |
PaduakDisposableFace _face; |
| 753 |
public IntPtr FeatureRef; |
| 754 |
|
| 755 |
public IntPtr Face |
| 756 |
{ |
| 757 |
get { return _face.Face; } |
| 758 |
} |
| 759 |
|
| 760 |
public PaduakFeatureVal() : this(0) |
| 761 |
{ |
| 762 |
|
| 763 |
} |
| 764 |
|
| 765 |
public PaduakFeatureVal(ushort n) |
| 766 |
{ |
| 767 |
_face = new PaduakDisposableFace(); |
| 768 |
FeatureRef = Graphite2Api.FaceFref(_face.Face, n); |
| 769 |
} |
| 770 |
|
| 771 |
#region IDisposable implementation |
| 772 |
public void Dispose() |
| 773 |
{ |
| 774 |
_face.Dispose(); |
| 775 |
} |
| 776 |
#endregion |
| 777 |
} |
| 778 |
|
| 779 |
internal class PaduakDisposableTestSegment : IDisposable |
| 780 |
{ |
| 781 |
public IntPtr Seg; |
| 782 |
IntPtr _testData; |
| 783 |
PaduakDisposableFont _font; |
| 784 |
|
| 785 |
public IntPtr Font |
| 786 |
{ |
| 787 |
get { return _font.Font; } |
| 788 |
} |
| 789 |
|
| 790 |
public IntPtr Face |
| 791 |
{ |
| 792 |
get { return _font.Face; } |
| 793 |
} |
| 794 |
|
| 795 |
public PaduakDisposableTestSegment(string testData) |
| 796 |
{ |
| 797 |
_font = new PaduakDisposableFont(); |
| 798 |
_testData = Marshal.StringToCoTaskMemAnsi(testData); |
| 799 |
IntPtr error = new IntPtr(0); |
| 800 |
int numCodePoints = Graphite2Api.CountUnicodeCharacters(Encform.Utf8, _testData, IntPtr.Zero, ref error); |
| 801 |
Seg = Graphite2Api.MakeSeg(_font.Font, _font.Face, 0, IntPtr.Zero, Encform.Utf8, _testData, numCodePoints, 0); |
| 802 |
} |
| 803 |
|
| 804 |
#region IDisposable implementation |
| 805 |
public void Dispose() |
| 806 |
{ |
| 807 |
Graphite2Api.SegDestroy(Seg); |
| 808 |
Marshal.FreeCoTaskMem(_testData); |
| 809 |
_font.Dispose(); |
| 810 |
} |
| 811 |
#endregion |
| 812 |
|
| 813 |
} |
| 814 |
|
| 815 |
#endregion |
| 816 |
} |
| 817 |
} |