diff --git a/tests/Core/TestTwitterUtils.cs b/tests/Core/TestTwitterUtils.cs new file mode 100644 index 00000000..a1e8f62c --- /dev/null +++ b/tests/Core/TestTwitterUtils.cs @@ -0,0 +1,39 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TweetDuck.Core.Utils; + +namespace UnitTests.Core{ + [TestClass] + public class TestTwitterUtils{ + [TestMethod] + public void TestAccountRegex(){ + Assert.IsTrue(TwitterUtils.RegexAccount.IsMatch("http://twitter.com/chylexmc")); + Assert.IsTrue(TwitterUtils.RegexAccount.IsMatch("https://twitter.com/chylexmc")); + Assert.IsTrue(TwitterUtils.RegexAccount.IsMatch("http://twitter.com/chylexmc/")); + Assert.IsTrue(TwitterUtils.RegexAccount.IsMatch("https://twitter.com/chylexmc/")); + + Assert.AreEqual("chylexmc", TwitterUtils.RegexAccount.Match("http://twitter.com/chylexmc").Groups[1].Value); + Assert.AreEqual("123", TwitterUtils.RegexAccount.Match("http://twitter.com/123").Groups[1].Value); + Assert.AreEqual("_", TwitterUtils.RegexAccount.Match("http://twitter.com/_").Groups[1].Value); + + Assert.AreEqual("Abc_123", TwitterUtils.RegexAccount.Match("http://twitter.com/Abc_123").Groups[1].Value); + Assert.AreEqual("Abc_123", TwitterUtils.RegexAccount.Match("https://twitter.com/Abc_123/").Groups[1].Value); + + Assert.IsFalse(TwitterUtils.RegexAccount.IsMatch("http://twitter.com/")); + Assert.IsFalse(TwitterUtils.RegexAccount.IsMatch("http://twitter.com/chylexmc/status")); + Assert.IsFalse(TwitterUtils.RegexAccount.IsMatch("http://nottwitter.com/chylexmc")); + Assert.IsFalse(TwitterUtils.RegexAccount.IsMatch("www.twitter.com/chylexmc")); + } + + [TestMethod] + public void TestImageQualityLink(){ + Assert.AreEqual("https://pbs.twimg.com/profile_images/123.jpg", TwitterUtils.GetImageLink("https://pbs.twimg.com/profile_images/123.jpg", TwitterUtils.ImageQuality.Default)); + Assert.AreEqual("https://pbs.twimg.com/profile_images/123.jpg", TwitterUtils.GetImageLink("https://pbs.twimg.com/profile_images/123.jpg", TwitterUtils.ImageQuality.Orig)); + + Assert.AreEqual("https://pbs.twimg.com/media/123.jpg:small", TwitterUtils.GetImageLink("https://pbs.twimg.com/media/123.jpg:small", TwitterUtils.ImageQuality.Default)); + Assert.AreEqual("https://pbs.twimg.com/media/123.jpg:orig", TwitterUtils.GetImageLink("https://pbs.twimg.com/media/123.jpg:small", TwitterUtils.ImageQuality.Orig)); + + Assert.AreEqual("https://pbs.twimg.com/media/123.jpg:large", TwitterUtils.GetImageLink("https://pbs.twimg.com/media/123.jpg:large", TwitterUtils.ImageQuality.Default)); + Assert.AreEqual("https://pbs.twimg.com/media/123.jpg:orig", TwitterUtils.GetImageLink("https://pbs.twimg.com/media/123.jpg:large", TwitterUtils.ImageQuality.Orig)); + } + } +} diff --git a/tests/Data/TestCombinedFileStream.cs b/tests/Data/TestCombinedFileStream.cs index e49f5365..6e6a839e 100644 --- a/tests/Data/TestCombinedFileStream.cs +++ b/tests/Data/TestCombinedFileStream.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using TweetDuck.Data; @@ -139,5 +140,31 @@ public void TestEntryWriteWithDirectory(){ Directory.Delete("cfs_directory", true); } + + [TestMethod] + public void TestLongIdentifierSuccess(){ + TestUtils.WriteText("cfs_long_identifier_fail_in", "test"); + + string identifier = string.Join("", Enumerable.Repeat("x", 255)); + + using(CombinedFileStream cfs = new CombinedFileStream(TestUtils.WriteFile("cfs_long_identifier_success"))){ + cfs.WriteFile(identifier, "cfs_long_identifier_fail_in"); + cfs.Flush(); + } + + using(CombinedFileStream cfs = new CombinedFileStream(TestUtils.ReadFile("cfs_long_identifier_success"))){ + Assert.AreEqual(identifier, cfs.ReadFile().Identifier); + } + } + + [TestMethod] + [ExpectedException(typeof(ArgumentOutOfRangeException))] + public void TestLongIdentifierFail(){ + TestUtils.WriteText("cfs_long_identifier_fail_in", "test"); + + using(CombinedFileStream cfs = new CombinedFileStream(TestUtils.WriteFile("cfs_long_identifier_fail"))){ + cfs.WriteFile(string.Join("", Enumerable.Repeat("x", 256)), "cfs_long_identifier_fail_in"); + } + } } } diff --git a/tests/UnitTests.csproj b/tests/UnitTests.csproj index b4aa6eee..036a1ae8 100644 --- a/tests/UnitTests.csproj +++ b/tests/UnitTests.csproj @@ -48,6 +48,7 @@ </Choose> <ItemGroup> <Compile Include="Core\TestStringUtils.cs" /> + <Compile Include="Core\TestTwitterUtils.cs" /> <Compile Include="Data\TestCombinedFileStream.cs" /> <Compile Include="Core\TestBrowserUtils.cs" /> <Compile Include="Data\TestCommandLineArgs.cs" />