Skip to content

Commit bd3a77f

Browse files
Samuel HuylebroeckiText-CI
authored andcommitted
Deprecate duplicate methods
Mark methods that had their duplicated logic consolidated inside a super-class Add extra test for SQ coverage DEVSIX-2864 Autoported commit. Original commit hash: [39d3d6ac8]
1 parent 98361c4 commit bd3a77f

File tree

8 files changed

+104
-10
lines changed

8 files changed

+104
-10
lines changed

itext.tests/itext.kernel.tests/itext/kernel/pdf/PdfCanvasTest.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,5 +1576,20 @@ private void SetColorTest(String pdfName, bool pattern) {
15761576
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destFile, cmpFile, destinationFolder, "diff_"
15771577
));
15781578
}
1579+
1580+
[NUnit.Framework.Test]
1581+
public virtual void EndPathNewPathTest() {
1582+
ByteArrayOutputStream boasEndPath = new ByteArrayOutputStream();
1583+
PdfDocument pdfDocEndPath = new PdfDocument(new PdfWriter(boasEndPath));
1584+
pdfDocEndPath.AddNewPage();
1585+
PdfCanvas endPathCanvas = new PdfCanvas(pdfDocEndPath.GetPage(1));
1586+
endPathCanvas.EndPath();
1587+
ByteArrayOutputStream boasNewPath = new ByteArrayOutputStream();
1588+
PdfDocument pdfDocNewPath = new PdfDocument(new PdfWriter(boasNewPath));
1589+
pdfDocNewPath.AddNewPage();
1590+
PdfCanvas newPathCanvas = new PdfCanvas(pdfDocNewPath.GetPage(1));
1591+
newPathCanvas.NewPath();
1592+
NUnit.Framework.Assert.AreEqual(boasNewPath.ToArray(), boasEndPath.ToArray());
1593+
}
15791594
}
15801595
}

itext.tests/itext.layout.tests/itext/layout/BorderTest.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,5 +262,61 @@ private void CloseDocumentAndCompareOutputs(Document document) {
262262
NUnit.Framework.Assert.Fail(compareResult);
263263
}
264264
}
265+
266+
public class TestDashedBorder : DashedBorder {
267+
public TestDashedBorder(BorderTest _enclosing, float width)
268+
: base(width) {
269+
this._enclosing = _enclosing;
270+
}
271+
272+
//When 7.2 release is in progress, remove the underlying code. It's here to pass A SQ line coverage quality gate and tests deprecated protected methods
273+
public virtual float PublicGetDotsGap(double distance, float initialGap) {
274+
return this.GetDotsGap(distance, initialGap);
275+
}
276+
277+
private readonly BorderTest _enclosing;
278+
}
279+
280+
public class TestDottedBorder : DottedBorder {
281+
public TestDottedBorder(BorderTest _enclosing, float width)
282+
: base(width) {
283+
this._enclosing = _enclosing;
284+
}
285+
286+
public virtual float PublicGetDotsGap(double distance, float initialGap) {
287+
return this.GetDotsGap(distance, initialGap);
288+
}
289+
290+
private readonly BorderTest _enclosing;
291+
}
292+
293+
public class TestRoundDotsBorder : RoundDotsBorder {
294+
public TestRoundDotsBorder(BorderTest _enclosing, float width)
295+
: base(width) {
296+
this._enclosing = _enclosing;
297+
}
298+
299+
public virtual float PublicGetDotsGap(double distance, float initialGap) {
300+
return this.GetDotsGap(distance, initialGap);
301+
}
302+
303+
private readonly BorderTest _enclosing;
304+
}
305+
306+
[NUnit.Framework.Test]
307+
public virtual void GetDotsGapTest() {
308+
float expected = 0.2f;
309+
double distance = 0.2;
310+
float initialGap = 0.2f;
311+
BorderTest.TestDashedBorder db = new BorderTest.TestDashedBorder(this, 1f);
312+
BorderTest.TestDottedBorder dotb = new BorderTest.TestDottedBorder(this, 1f);
313+
BorderTest.TestRoundDotsBorder rdb = new BorderTest.TestRoundDotsBorder(this, 1f);
314+
float dbActual = db.PublicGetDotsGap(distance, initialGap);
315+
float dotbActual = dotb.PublicGetDotsGap(distance, initialGap);
316+
float rdbActual = rdb.PublicGetDotsGap(distance, initialGap);
317+
NUnit.Framework.Assert.AreEqual(expected, dbActual, 0.0001f);
318+
NUnit.Framework.Assert.AreEqual(expected, dotbActual, 0.0001f);
319+
NUnit.Framework.Assert.AreEqual(expected, rdbActual, 0.0001f);
320+
}
265321
}
266322
}

itext.tests/itext.layout.tests/itext/layout/TableTest.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2379,6 +2379,26 @@ public virtual void CaptionedTableOfOnePageWithCollapsedBordersTest01() {
23792379
, testName + "_diff"));
23802380
}
23812381

2382+
/// <exception cref="System.IO.IOException"/>
2383+
/// <exception cref="System.Exception"/>
2384+
[NUnit.Framework.Test]
2385+
public virtual void TableWithDifferentStylesOfCollapsedBordersTest() {
2386+
String testName = "tableWithDifferentStylesOfCollapsedBordersTest.pdf";
2387+
String outFileName = destinationFolder + testName;
2388+
String cmpFileName = sourceFolder + "cmp_" + testName;
2389+
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName));
2390+
Document doc = new Document(pdfDoc);
2391+
Table table = CreateTestTable(2, 10, 2, 2, (UnitValue)null, BorderCollapsePropertyValue.COLLAPSE, new Style
2392+
().SetBorder(new DashedBorder(ColorConstants.RED, 10)));
2393+
table.GetHeader().SetBorder(new DottedBorder(ColorConstants.ORANGE, 5f));
2394+
table.GetFooter().SetBorder(new RoundDotsBorder(ColorConstants.ORANGE, 5f));
2395+
// no caption
2396+
AddTable(table, true, true, doc);
2397+
doc.Close();
2398+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
2399+
, testName + "_diff"));
2400+
}
2401+
23822402
/// <exception cref="System.IO.IOException"/>
23832403
/// <exception cref="System.Exception"/>
23842404
[NUnit.Framework.Test]

itext/itext.layout/itext/layout/borders/DashedBorder.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float
8989
float dx = x2 - x1;
9090
float dy = y2 - y1;
9191
double borderLength = Math.Sqrt(dx * dx + dy * dy);
92-
float adjustedGap = GetDotsGap(borderLength, initialGap + dash);
92+
float adjustedGap = base.GetDotsGap(borderLength, initialGap + dash);
9393
if (adjustedGap > dash) {
9494
adjustedGap -= dash;
9595
}
@@ -112,7 +112,7 @@ public override void DrawCellBorder(PdfCanvas canvas, float x1, float y1, float
112112
float dx = x2 - x1;
113113
float dy = y2 - y1;
114114
double borderLength = Math.Sqrt(dx * dx + dy * dy);
115-
float adjustedGap = GetDotsGap(borderLength, initialGap + dash);
115+
float adjustedGap = base.GetDotsGap(borderLength, initialGap + dash);
116116
if (adjustedGap > dash) {
117117
adjustedGap -= dash;
118118
}
@@ -130,7 +130,7 @@ public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float
130130
float dx = x2 - x1;
131131
float dy = y2 - y1;
132132
double borderLength = Math.Sqrt(dx * dx + dy * dy);
133-
float adjustedGap = GetDotsGap(borderLength, initialGap + dash);
133+
float adjustedGap = base.GetDotsGap(borderLength, initialGap + dash);
134134
if (adjustedGap > dash) {
135135
adjustedGap -= dash;
136136
}
@@ -152,6 +152,7 @@ public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float
152152
/// </param>
153153
/// <param name="initialGap">the initial size of the gap</param>
154154
/// <returns>the adjusted size of the gap</returns>
155+
[System.ObsoleteAttribute(@"logic moved to super-class")]
155156
protected internal override float GetDotsGap(double distance, float initialGap) {
156157
return base.GetDotsGap(distance, initialGap);
157158
}

itext/itext.layout/itext/layout/borders/DottedBorder.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float
9393
float dx = x2 - x1;
9494
float dy = y2 - y1;
9595
double borderLength = Math.Sqrt(dx * dx + dy * dy);
96-
float adjustedGap = GetDotsGap(borderLength, initialGap + width);
96+
float adjustedGap = base.GetDotsGap(borderLength, initialGap + width);
9797
if (adjustedGap > width) {
9898
adjustedGap -= width;
9999
}
@@ -116,7 +116,7 @@ public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float
116116
float dx = x2 - x1;
117117
float dy = y2 - y1;
118118
double borderLength = Math.Sqrt(dx * dx + dy * dy);
119-
float adjustedGap = GetDotsGap(borderLength, initialGap);
119+
float adjustedGap = base.GetDotsGap(borderLength, initialGap);
120120
if (adjustedGap > width) {
121121
adjustedGap -= width;
122122
}
@@ -137,7 +137,7 @@ public override void DrawCellBorder(PdfCanvas canvas, float x1, float y1, float
137137
float dx = x2 - x1;
138138
float dy = y2 - y1;
139139
double borderLength = Math.Sqrt(dx * dx + dy * dy);
140-
float adjustedGap = GetDotsGap(borderLength, initialGap + width);
140+
float adjustedGap = base.GetDotsGap(borderLength, initialGap + width);
141141
if (adjustedGap > width) {
142142
adjustedGap -= width;
143143
}
@@ -155,6 +155,7 @@ public override void DrawCellBorder(PdfCanvas canvas, float x1, float y1, float
155155
/// </param>
156156
/// <param name="initialGap">the initial size of the gap</param>
157157
/// <returns>the adjusted size of the gap</returns>
158+
[System.ObsoleteAttribute(@"logic moved to super-class")]
158159
protected internal override float GetDotsGap(double distance, float initialGap) {
159160
return base.GetDotsGap(distance, initialGap);
160161
}

itext/itext.layout/itext/layout/borders/RoundDotsBorder.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float
9090
float dx = x2 - x1;
9191
float dy = y2 - y1;
9292
double borderLength = Math.Sqrt(dx * dx + dy * dy);
93-
float adjustedGap = GetDotsGap(borderLength, initialGap);
93+
float adjustedGap = base.GetDotsGap(borderLength, initialGap);
9494
float[] startingPoints = GetStartingPointsForBorderSide(x1, y1, x2, y2, defaultSide);
9595
x1 = startingPoints[0];
9696
y1 = startingPoints[1];
@@ -109,7 +109,7 @@ public override void DrawCellBorder(PdfCanvas canvas, float x1, float y1, float
109109
float dx = x2 - x1;
110110
float dy = y2 - y1;
111111
double borderLength = Math.Sqrt(dx * dx + dy * dy);
112-
float adjustedGap = GetDotsGap(borderLength, initialGap);
112+
float adjustedGap = base.GetDotsGap(borderLength, initialGap);
113113
bool isHorizontal = false;
114114
if (Math.Abs(y2 - y1) < 0.0005f) {
115115
isHorizontal = true;
@@ -134,7 +134,7 @@ public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float
134134
float dx = x2 - x1;
135135
float dy = y2 - y1;
136136
double borderLength = Math.Sqrt(dx * dx + dy * dy);
137-
float adjustedGap = GetDotsGap(borderLength, initialGap);
137+
float adjustedGap = base.GetDotsGap(borderLength, initialGap);
138138
canvas.SaveState().SetStrokeColor(transparentColor.GetColor());
139139
transparentColor.ApplyStrokeTransparency(canvas);
140140
canvas.SetLineWidth(width).SetLineCapStyle(PdfCanvasConstants.LineCapStyle.ROUND).SetLineDash(0, adjustedGap
@@ -154,6 +154,7 @@ public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float
154154
/// </param>
155155
/// <param name="initialGap">the initial size of the gap</param>
156156
/// <returns>the adjusted size of the gap</returns>
157+
[System.ObsoleteAttribute(@"logic moved to super-class")]
157158
protected internal override float GetDotsGap(double distance, float initialGap) {
158159
return base.GetDotsGap(distance, initialGap);
159160
}

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
70c08bd6ad90e2c19c70c35dab017d76e1b4a3dd
1+
39d3d6ac80aff53f651ecc07ffa25cff9f87eba0

0 commit comments

Comments
 (0)