| 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 |
|
| 7 |
namespace NGraphiteTests |
| 8 |
{ |
| 9 |
[TestFixture()] |
| 10 |
public class SlotTests |
| 11 |
{ |
| 12 |
Face _face; |
| 13 |
Font _font; |
| 14 |
Featureval _featureval; |
| 15 |
Segment _segment; |
| 16 |
|
| 17 |
[SetUp] |
| 18 |
public void PerTestSetup() |
| 19 |
{ |
| 20 |
_face = new Face(TestConstants.PaduakFontLocation, FaceOptions.face_default); |
| 21 |
_font = new Font(20.0f, _face); |
| 22 |
_featureval = _face.FeaturevalForLang("en"); |
| 23 |
_segment = _font.MakeSeg(0, _featureval, "hello world", Bidirtl.Nobidi); |
| 24 |
} |
| 25 |
|
| 26 |
[TearDown] |
| 27 |
public void PerTestTearDown() |
| 28 |
{ |
| 29 |
_face.Dispose(); |
| 30 |
_font.Dispose(); |
| 31 |
_featureval.Dispose(); |
| 32 |
_segment.Dispose(); |
| 33 |
} |
| 34 |
|
| 35 |
[Test()] |
| 36 |
public void NextInSegment_OnFirstSlotInTestSegment_ReturnsNonNullSlot() |
| 37 |
{ |
| 38 |
Assert.NotNull(_segment.FirstSlot.NextInSegment); |
| 39 |
} |
| 40 |
|
| 41 |
[Test()] |
| 42 |
public void PrevInSegment_OnLastSlotInTestSegment_ReturnsNonNullSlot() |
| 43 |
{ |
| 44 |
Assert.NotNull(_segment.LastSlot.PrevInSegment); |
| 45 |
} |
| 46 |
|
| 47 |
[Test()] |
| 48 |
public void AttachedTo_OnFirstSlotInTestSegment_ReturnsNullSlot() |
| 49 |
{ |
| 50 |
Assert.IsNull(_segment.FirstSlot.AttachedTo); |
| 51 |
} |
| 52 |
|
| 53 |
[Test()] |
| 54 |
public void FirstAttachment_OnFirstSlotInTestSegment_ReturnsNullSlot() |
| 55 |
{ |
| 56 |
Assert.IsNull(_segment.FirstSlot.FirstAttachment); |
| 57 |
} |
| 58 |
|
| 59 |
[Test()] |
| 60 |
public void NextSiblingAttachment_OnFirstSlotInTestSegment_ReturnsNonNullSlot() |
| 61 |
{ |
| 62 |
Assert.IsNotNull(_segment.FirstSlot.NextSiblingAttachment); |
| 63 |
} |
| 64 |
|
| 65 |
[Test()] |
| 66 |
public void Gid_OnFirstSlotInTestSegment_ReturnsExpectedId() |
| 67 |
{ |
| 68 |
Assert.AreEqual(75, _segment.FirstSlot.Gid); |
| 69 |
} |
| 70 |
|
| 71 |
[Test()] |
| 72 |
public void OriginX_OnFirstSlotInTestSegment_ReturnsExpectedValue() |
| 73 |
{ |
| 74 |
Assert.AreEqual(0f, _segment.FirstSlot.OriginX); |
| 75 |
} |
| 76 |
|
| 77 |
[Test()] |
| 78 |
public void OriginY_OnFirstSlotInTestSegment_ReturnsExpectedValue() |
| 79 |
{ |
| 80 |
Assert.AreEqual(0f, _segment.FirstSlot.OriginY); |
| 81 |
} |
| 82 |
|
| 83 |
[Test()] |
| 84 |
public void AdvanceX_OnFirstSlotInTestSegment_ReturnsExpectedValue() |
| 85 |
{ |
| 86 |
Assert.AreEqual(9.9609375f, _segment.FirstSlot.AdvanceX(_face, _font)); |
| 87 |
} |
| 88 |
|
| 89 |
[Test()] |
| 90 |
public void AdvanceY_OnFirstSlotInTestSegment_ReturnsExpectedValue() |
| 91 |
{ |
| 92 |
Assert.AreEqual(0f, _segment.FirstSlot.AdvanceY(_face, _font)); |
| 93 |
} |
| 94 |
|
| 95 |
[Test()] |
| 96 |
public void Before_OnFirstSlotInTestSegment_ReturnsZero() |
| 97 |
{ |
| 98 |
Assert.AreEqual(0, _segment.FirstSlot.Before); |
| 99 |
} |
| 100 |
|
| 101 |
[Test()] |
| 102 |
public void After_OnFirstSlotInTestSegment_ReturnsZero() |
| 103 |
{ |
| 104 |
Assert.AreEqual(0, _segment.FirstSlot.After); |
| 105 |
} |
| 106 |
|
| 107 |
[Test()] |
| 108 |
public void Index_OnFirstSlotInTestSegment_ReturnsZero() |
| 109 |
{ |
| 110 |
Assert.AreEqual(0, _segment.FirstSlot.Index); |
| 111 |
} |
| 112 |
|
| 113 |
[Test()] |
| 114 |
public void Attr_OnFirstSlotInTestSegment_ReturnsExpectedAttributeValue() |
| 115 |
{ |
| 116 |
Assert.AreEqual(510, _segment.FirstSlot.Attr(_segment, AttrCode.SlatAdvX, 0)); |
| 117 |
} |
| 118 |
|
| 119 |
[Test()] |
| 120 |
public void CanInsertBefore_OnFirstSlotInTestSegment_ReturnsTrue() |
| 121 |
{ |
| 122 |
Assert.IsTrue(_segment.FirstSlot.CanInsertBefore); |
| 123 |
} |
| 124 |
|
| 125 |
[Test()] |
| 126 |
public void Original_OnFirstSlotInTestSegment_ReturnsExpectedCharInfoValue() |
| 127 |
{ |
| 128 |
Assert.AreEqual(0, _segment.FirstSlot.Original); |
| 129 |
} |
| 130 |
|
| 131 |
[Test()] |
| 132 |
public void LineBreakBefore_OnLastSlotInTestSegment_DoesNotThrowException() |
| 133 |
{ |
| 134 |
// note: if we call LineBreakBefore on FirstSlot it graphite seg faults |
| 135 |
// eg: _segment.FirstSlot.LineBreakBefore(); |
| 136 |
|
| 137 |
_segment.LastSlot.LineBreakBefore(); |
| 138 |
} |
| 139 |
} |
| 140 |
} |
| 141 |
|