forked from pipeline-foundation/itext7-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into devsecops
- Loading branch information
Showing
23 changed files
with
1,195 additions
and
152 deletions.
There are no files selected for viewing
213 changes: 213 additions & 0 deletions
213
....tests/itext.commons.tests/itext/commons/datastructures/portable/NullUnlimitedListTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
/* | ||
This file is part of the iText (R) project. | ||
Copyright (c) 1998-2024 Apryse Group NV | ||
Authors: Apryse Software. | ||
This program is offered under a commercial and under the AGPL license. | ||
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. | ||
AGPL licensing: | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
using System; | ||
using System.Collections.Generic; | ||
using iText.Commons.Datastructures; | ||
using iText.Test; | ||
|
||
namespace iText.Commons.Datastructures.Portable { | ||
[NUnit.Framework.Category("UnitTest")] | ||
public class NullUnlimitedListTest : ExtendedITextTest { | ||
[NUnit.Framework.Test] | ||
public virtual void NullUnlimitedListAddTest() { | ||
NullUnlimitedList<String> list = new NullUnlimitedList<String>(); | ||
list.Add("hey"); | ||
list.Add("bye"); | ||
NUnit.Framework.Assert.AreEqual(2, list.Size()); | ||
list.Add(-1, "hello"); | ||
list.Add(3, "goodbye"); | ||
NUnit.Framework.Assert.AreEqual(2, list.Size()); | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void NullUnlimitedListIndexOfTest() { | ||
NullUnlimitedList<String> list = new NullUnlimitedList<String>(); | ||
list.Add("hey"); | ||
list.Add(null); | ||
list.Add("bye"); | ||
list.Add(null); | ||
NUnit.Framework.Assert.AreEqual(4, list.Size()); | ||
NUnit.Framework.Assert.AreEqual(1, list.IndexOf(null)); | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void NullUnlimitedListRemoveTest() { | ||
NullUnlimitedList<String> list = new NullUnlimitedList<String>(); | ||
list.Add("hey"); | ||
list.Add("bye"); | ||
NUnit.Framework.Assert.AreEqual(2, list.Size()); | ||
list.Remove(-1); | ||
list.Remove(2); | ||
NUnit.Framework.Assert.AreEqual(2, list.Size()); | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void TestIsEmpty() { | ||
NullUnlimitedList<String> list = new NullUnlimitedList<String>(); | ||
NUnit.Framework.Assert.IsTrue(list.IsEmpty()); | ||
list.Add("hey"); | ||
NUnit.Framework.Assert.IsFalse(list.IsEmpty()); | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void TestSameBehaviour01() { | ||
IList<Action<ISimpleList<String>>> actionList = new List<Action<ISimpleList<String>>>(); | ||
actionList.Add((list) => list.Add("1")); | ||
actionList.Add((list) => list.Add(null)); | ||
actionList.Add((list) => list.Add("1")); | ||
actionList.Add((list) => list.Add("1")); | ||
actionList.Add((list) => NUnit.Framework.Assert.AreEqual(1, list.IndexOf(null))); | ||
ExecuteActions(actionList); | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void TestSameBehaviour02() { | ||
IList<Action<ISimpleList<String>>> actionList = new List<Action<ISimpleList<String>>>(); | ||
actionList.Add((list) => list.Add("1")); | ||
actionList.Add((list) => list.Add(null)); | ||
actionList.Add((list) => list.Add("1")); | ||
actionList.Add((list) => list.Add("1")); | ||
actionList.Add((list) => NUnit.Framework.Assert.AreEqual(4, list.Size())); | ||
ExecuteActions(actionList); | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void TestSameBehaviour03() { | ||
IList<Action<ISimpleList<String>>> actionList = new List<Action<ISimpleList<String>>>(); | ||
actionList.Add((list) => list.Add("1")); | ||
actionList.Add((list) => list.Add(null)); | ||
actionList.Add((list) => list.Add("1")); | ||
actionList.Add((list) => list.Add("1")); | ||
actionList.Add((list) => list.Add(null)); | ||
actionList.Add((list) => list.Set(1, "4")); | ||
actionList.Add((list) => NUnit.Framework.Assert.AreEqual(list.Get(1), "4")); | ||
ExecuteActions(actionList); | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void TestSameBehaviour04() { | ||
IList<Action<ISimpleList<String>>> actionList = new List<Action<ISimpleList<String>>>(); | ||
actionList.Add((list) => list.Add("1")); | ||
actionList.Add((list) => list.Add(null)); | ||
actionList.Add((list) => list.Add("1")); | ||
actionList.Add((list) => list.Add("1")); | ||
actionList.Add((list) => list.Add(null)); | ||
actionList.Add((list) => NUnit.Framework.Assert.AreEqual(1, list.IndexOf(null))); | ||
ExecuteActions(actionList); | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void TestSameBehaviour05() { | ||
IList<Action<ISimpleList<String>>> actionList = new List<Action<ISimpleList<String>>>(); | ||
actionList.Add((list) => list.Add("1")); | ||
actionList.Add((list) => list.Add("1")); | ||
actionList.Add((list) => list.Add("1")); | ||
actionList.Add((list) => list.Add("1")); | ||
actionList.Add((list) => list.Add("1")); | ||
actionList.Add((list) => NUnit.Framework.Assert.AreEqual(-1, list.IndexOf(null))); | ||
ExecuteActions(actionList); | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void TestSameBehaviour06() { | ||
IList<Action<ISimpleList<String>>> actionList = new List<Action<ISimpleList<String>>>(); | ||
actionList.Add((list) => list.Add("1")); | ||
actionList.Add((list) => list.Add("2")); | ||
actionList.Add((list) => list.Add("3")); | ||
actionList.Add((list) => list.Add("4")); | ||
actionList.Add((list) => list.Add("5")); | ||
actionList.Add((list) => NUnit.Framework.Assert.AreEqual(4, list.IndexOf("5"))); | ||
ExecuteActions(actionList); | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void TestSameBehaviour07() { | ||
IList<Action<ISimpleList<String>>> actionList = new List<Action<ISimpleList<String>>>(); | ||
actionList.Add((list) => list.Add("1")); | ||
actionList.Add((list) => list.Add("2")); | ||
actionList.Add((list) => list.Add("3")); | ||
actionList.Add((list) => list.Add("4")); | ||
actionList.Add((list) => list.Add("5")); | ||
actionList.Add((list) => NUnit.Framework.Assert.AreEqual(-1, list.IndexOf("6"))); | ||
ExecuteActions(actionList); | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void TestSameBehaviour08() { | ||
IList<Action<ISimpleList<String>>> actionList = new List<Action<ISimpleList<String>>>(); | ||
actionList.Add((list) => list.Add("1")); | ||
actionList.Add((list) => list.Add("2")); | ||
actionList.Add((list) => list.Add("3")); | ||
actionList.Add((list) => list.Add("4")); | ||
actionList.Add((list) => list.Add(2, "5")); | ||
actionList.Add((list) => NUnit.Framework.Assert.AreEqual(5, list.Size())); | ||
ExecuteActions(actionList); | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void TestSameBehaviour09() { | ||
IList<Action<ISimpleList<String>>> actionList = new List<Action<ISimpleList<String>>>(); | ||
actionList.Add((list) => list.Add("1")); | ||
actionList.Add((list) => list.Add("2")); | ||
actionList.Add((list) => list.Add("3")); | ||
actionList.Add((list) => list.Add("4")); | ||
actionList.Add((list) => list.Set(2, null)); | ||
actionList.Add((list) => NUnit.Framework.Assert.AreEqual(4, list.Size())); | ||
ExecuteActions(actionList); | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void TestSameBehaviour10() { | ||
IList<Action<ISimpleList<String>>> actionList = new List<Action<ISimpleList<String>>>(); | ||
actionList.Add((list) => list.Add("1")); | ||
actionList.Add((list) => list.Add("2")); | ||
actionList.Add((list) => list.Add("3")); | ||
actionList.Add((list) => list.Add("4")); | ||
actionList.Add((list) => list.Remove(2)); | ||
actionList.Add((list) => NUnit.Framework.Assert.AreEqual(3, list.Size())); | ||
ExecuteActions(actionList); | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void TestSameBehaviour11() { | ||
IList<Action<ISimpleList<String>>> actionList = new List<Action<ISimpleList<String>>>(); | ||
actionList.Add((list) => NUnit.Framework.Assert.IsTrue(list.IsEmpty())); | ||
actionList.Add((list) => list.Add("1")); | ||
actionList.Add((list) => NUnit.Framework.Assert.IsFalse(list.IsEmpty())); | ||
actionList.Add((list) => list.Add("2")); | ||
actionList.Add((list) => list.Add("3")); | ||
actionList.Add((list) => list.Add("4")); | ||
actionList.Add((list) => NUnit.Framework.Assert.IsFalse(list.IsEmpty())); | ||
ExecuteActions(actionList); | ||
} | ||
|
||
public virtual void ExecuteActions(IList<Action<ISimpleList<String>>> actionList) { | ||
NullUnlimitedList<String> list = new NullUnlimitedList<String>(); | ||
SimpleArrayList<String> list2 = new SimpleArrayList<String>(); | ||
foreach (Action<ISimpleList<String>> action in actionList) { | ||
action(list); | ||
action(list2); | ||
} | ||
} | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
itext.tests/itext.commons.tests/itext/commons/datastructures/portable/SimpleArrayListTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
This file is part of the iText (R) project. | ||
Copyright (c) 1998-2024 Apryse Group NV | ||
Authors: Apryse Software. | ||
This program is offered under a commercial and under the AGPL license. | ||
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. | ||
AGPL licensing: | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
using iText.Commons.Datastructures; | ||
using iText.Test; | ||
|
||
namespace iText.Commons.Datastructures.Portable { | ||
[NUnit.Framework.Category("UnitTest")] | ||
public class SimpleArrayListTest : ExtendedITextTest { | ||
[NUnit.Framework.Test] | ||
public virtual void Add01() { | ||
SimpleArrayList<int> list = new SimpleArrayList<int>(); | ||
list.Add(1); | ||
list.Add(2); | ||
list.Add(3); | ||
NUnit.Framework.Assert.AreEqual(3, list.Size()); | ||
NUnit.Framework.Assert.AreEqual(1, list.Get(0)); | ||
NUnit.Framework.Assert.AreEqual(2, list.Get(1)); | ||
NUnit.Framework.Assert.AreEqual(3, list.Get(2)); | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void Add02() { | ||
SimpleArrayList<int> list = new SimpleArrayList<int>(); | ||
list.Add(1); | ||
list.Add(3); | ||
list.Add(2, 2); | ||
NUnit.Framework.Assert.AreEqual(3, list.Size()); | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void Set01() { | ||
SimpleArrayList<int> list = new SimpleArrayList<int>(); | ||
list.Add(1); | ||
list.Add(2); | ||
list.Add(3); | ||
NUnit.Framework.Assert.AreEqual(2, list.Set(1, 4)); | ||
NUnit.Framework.Assert.AreEqual(4, list.Get(1)); | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void IndexOf01() { | ||
SimpleArrayList<int> list = new SimpleArrayList<int>(); | ||
list.Add(1); | ||
list.Add(2); | ||
list.Add(3); | ||
NUnit.Framework.Assert.AreEqual(0, list.IndexOf(1)); | ||
NUnit.Framework.Assert.AreEqual(1, list.IndexOf(2)); | ||
NUnit.Framework.Assert.AreEqual(2, list.IndexOf(3)); | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void Remove() { | ||
SimpleArrayList<int> list = new SimpleArrayList<int>(); | ||
list.Add(1); | ||
list.Add(2); | ||
list.Add(3); | ||
list.Remove(1); | ||
NUnit.Framework.Assert.AreEqual(2, list.Size()); | ||
NUnit.Framework.Assert.AreEqual(1, list.Get(0)); | ||
NUnit.Framework.Assert.AreEqual(3, list.Get(1)); | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void Size() { | ||
SimpleArrayList<int> list = new SimpleArrayList<int>(); | ||
list.Add(1); | ||
list.Add(2); | ||
list.Add(3); | ||
NUnit.Framework.Assert.AreEqual(3, list.Size()); | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void InitializeWithCapacity() { | ||
SimpleArrayList<int> list = new SimpleArrayList<int>(20); | ||
list.Add(1); | ||
list.Add(2); | ||
list.Add(3); | ||
NUnit.Framework.Assert.AreEqual(3, list.Size()); | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void IsEmpty() { | ||
SimpleArrayList<int> list = new SimpleArrayList<int>(); | ||
NUnit.Framework.Assert.IsTrue(list.IsEmpty()); | ||
list.Add(1); | ||
NUnit.Framework.Assert.IsFalse(list.IsEmpty()); | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
itext.tests/itext.commons.tests/itext/commons/utils/FileUtilTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
This file is part of the iText (R) project. | ||
Copyright (c) 1998-2024 Apryse Group NV | ||
Authors: Apryse Software. | ||
This program is offered under a commercial and under the AGPL license. | ||
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. | ||
AGPL licensing: | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
using System; | ||
using System.IO; | ||
using iText.Test; | ||
|
||
namespace iText.Commons.Utils { | ||
[NUnit.Framework.Category("UnitTest")] | ||
public class FileUtilTest : ExtendedITextTest { | ||
public static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory | ||
+ "/test/itext/commons/utils/FileUtilTest/"; | ||
|
||
[NUnit.Framework.OneTimeSetUp] | ||
public static void BeforeClass() { | ||
CreateOrClearDestinationFolder(DESTINATION_FOLDER); | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void GetBufferedOutputStreamTest() { | ||
String filePath = DESTINATION_FOLDER + "bufferedOutput.txt"; | ||
String text = "Hello world!"; | ||
using (Stream @out = FileUtil.GetBufferedOutputStream(filePath)) { | ||
@out.Write(text.GetBytes(System.Text.Encoding.UTF8)); | ||
} | ||
byte[] resultBytes = File.ReadAllBytes(System.IO.Path.Combine(filePath)); | ||
NUnit.Framework.Assert.AreEqual(text, iText.Commons.Utils.JavaUtil.GetStringForBytes(resultBytes, System.Text.Encoding | ||
.UTF8)); | ||
} | ||
|
||
[NUnit.Framework.Test] | ||
public virtual void GetFileOutputStreamTest() { | ||
String filePath = DESTINATION_FOLDER + "fileOutput.txt"; | ||
FileInfo file = new FileInfo(filePath); | ||
String text = "Hello world!"; | ||
using (Stream @out = FileUtil.GetFileOutputStream(file)) { | ||
@out.Write(text.GetBytes(System.Text.Encoding.UTF8)); | ||
} | ||
byte[] resultBytes = File.ReadAllBytes(System.IO.Path.Combine(filePath)); | ||
NUnit.Framework.Assert.AreEqual(text, iText.Commons.Utils.JavaUtil.GetStringForBytes(resultBytes, System.Text.Encoding | ||
.UTF8)); | ||
} | ||
} | ||
} |
Oops, something went wrong.