Skip to content

Commit

Permalink
Fix UDH fragmentation when length is within a fragment size boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
pruiz committed May 18, 2017
1 parent 1f74b87 commit 8da5fb2
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
*/*.??proj.user
*/bin
*/obj

Packages/
packages/
5 changes: 3 additions & 2 deletions AberrantSMPP.Tests/AberrantSMPP.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.6.2\lib\nunit.framework.dll</HintPath>
<Reference Include="nunit.framework, Version=3.6.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.6.1\lib\net40\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
Expand Down
20 changes: 12 additions & 8 deletions AberrantSMPP.Tests/GSMEncodingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,19 @@ public void Encode_Invalid_String()
}

[Test]
[ExpectedException(typeof(EncoderFallbackException))]
public void Encoding_Invalid_Char_Throws()
{
new GSMEncoding(true).GetBytes(new char[] { '\x03a2' });
Assert.Throws<EncoderFallbackException>(() =>
new GSMEncoding(true).GetBytes(new char[] { '\x03a2' })
);
}

[Test]
[ExpectedException(typeof(DecoderFallbackException))]
public void Decoding_Invalid_Char_Throws()
{
new GSMEncoding(true).GetString(new byte[] { 0x80 });
Assert.Throws<EncoderFallbackException>(() =>
new GSMEncoding(true).GetString(new byte[] { 0x80 })
);
}

[Test]
Expand All @@ -106,17 +108,19 @@ public void Encoding_Using_BestFit()
}

[Test]
[ExpectedException(typeof(EncoderFallbackException))]
public void Encoding_Invalid_Char_Using_BestFit_Throws_1()
{
new GSMEncoding(true, true).GetBytes(new char[] { 'º' });
Assert.Throws<EncoderFallbackException>(() =>
new GSMEncoding(true, true).GetBytes(new char[] { 'º' })
);
}

[Test]
[ExpectedException(typeof(EncoderFallbackException))]
public void Encoding_Invalid_Char_Using_BestFit_Throws_2()
{
new GSMEncoding(true, true).GetBytes(new char[] { '\x03a2' });
Assert.Throws<EncoderFallbackException>(() =>
new GSMEncoding(true, true).GetBytes(new char[] { '\x03a2' })
);
}

[Test]
Expand Down
32 changes: 32 additions & 0 deletions AberrantSMPP.Tests/PacketTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using AberrantSMPP.Packet;
using AberrantSMPP.Packet.Request;
using AberrantSMPP.Packet.Response;
using AberrantSMPP.Utility;

namespace AberrantSMPP.Tests
{
Expand All @@ -34,5 +35,36 @@ public void CanDecodeDeliverSm_01()
Assert.AreEqual("253092914522667372", pdu.ReceiptedMessageId);
}
#endregion

#region SmppSubmitSm

[TestCase(159, DataCoding.SMSCDefault, 1)]
[TestCase(161, DataCoding.SMSCDefault, 2)]
[TestCase(160, DataCoding.SMSCDefault, 1)]
[TestCase(305, DataCoding.SMSCDefault, 2)]
[TestCase(306, DataCoding.SMSCDefault, 2)]
[TestCase(307, DataCoding.SMSCDefault, 3)]
[TestCase(459, DataCoding.SMSCDefault, 3)]
[TestCase(69, DataCoding.UCS2, 1)]
[TestCase(70, DataCoding.UCS2, 1)]
[TestCase(71, DataCoding.UCS2, 2)]
[TestCase(133, DataCoding.UCS2, 2)]
[TestCase(134, DataCoding.UCS2, 2)]
[TestCase(135, DataCoding.UCS2, 3)]
public void Can_Fragment_Using_Udh(int length, DataCoding coding, int segmentsNumber)
{
var message = new String(Enumerable.Repeat('A', length).ToArray());

var submitSm = new SmppSubmitSm()
{
DataCoding = coding,
ShortMessage = message,
};

var segments = SmppUtil.SplitLongMessage(submitSm, SmppSarMethod.UserDataHeader, 0x1);
Assert.AreEqual(segmentsNumber, segments.Count());
}

#endregion
}
}
3 changes: 2 additions & 1 deletion AberrantSMPP.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="2.6.2" targetFramework="net40" />
<package id="NUnit" version="3.6.1" targetFramework="net40" />
<package id="NUnit3TestAdapter" version="3.7.0" targetFramework="net40" />
</packages>
17 changes: 0 additions & 17 deletions AberrantSMPP.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AberrantSMPP.Tests", "Aberr
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libs", "Libs", "{11BEF2CE-ED05-40B7-8241-53AD3C5CE82D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Gallio", "Gallio", "{1AA7F588-B76F-4B59-865D-EC1B6A400522}"
ProjectSection(SolutionItems) = preProject
Libs\Gallio\Gallio.dll = Libs\Gallio\Gallio.dll
Libs\Gallio\Gallio.pdb = Libs\Gallio\Gallio.pdb
Libs\Gallio\Gallio35.dll = Libs\Gallio\Gallio35.dll
Libs\Gallio\Gallio35.pdb = Libs\Gallio\Gallio35.pdb
Libs\Gallio\Gallio35.plugin = Libs\Gallio\Gallio35.plugin
Libs\Gallio\Gallio35.xml = Libs\Gallio\Gallio35.xml
Libs\Gallio\MbUnit.dll = Libs\Gallio\MbUnit.dll
Libs\Gallio\MbUnit.pdb = Libs\Gallio\MbUnit.pdb
Libs\Gallio\MbUnit35.dll = Libs\Gallio\MbUnit35.dll
Libs\Gallio\MbUnit35.pdb = Libs\Gallio\MbUnit35.pdb
Libs\Gallio\MbUnit35.plugin = Libs\Gallio\MbUnit35.plugin
Libs\Gallio\MbUnit35.xml = Libs\Gallio\MbUnit35.xml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Packages", "Packages", "{99427D87-ABCF-4A62-91B1-4822133B029C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{946069C5-ABA2-47AB-8BEE-7B84B130FFB9}"
Expand Down Expand Up @@ -90,6 +74,5 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{3B915387-7317-4F39-AE2B-05B549852BF6} = {07328239-94EF-4F55-A1F7-095CFB9E27E4}
{1AA7F588-B76F-4B59-865D-EC1B6A400522} = {11BEF2CE-ED05-40B7-8241-53AD3C5CE82D}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion AberrantSMPP/Utility/SmppUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static IEnumerable<byte[]> SplitMessage(byte[] bytes, int maxLen, byte? u
if (bytes.Length <= maxLen)
return new[] { bytes };

var totalSegments = (bytes.Length / maxLen);
var totalSegments = bytes.Length / maxLen - 1 + (bytes.Length % maxLen != 0 ? 1 : 0);
var segments = new List<byte[]>();

for (var i = 0; i <= totalSegments; i++)
Expand Down

0 comments on commit 8da5fb2

Please sign in to comment.