• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

開発に使用するリポジトリ


Commit MetaInfo

Révisionc1232a8172a47a88704f43e12a49982c34c96e17 (tree)
l'heure2012-11-29 10:38:27
AuteurKimura Youichi <kim.upsilon@bucy...>
CommiterKimura Youichi

Message de Log

テストケース追加

Change Summary

Modification

--- a/OpenTween.Tests/MyCommonTest.cs
+++ b/OpenTween.Tests/MyCommonTest.cs
@@ -3,13 +3,154 @@ using System.Collections.Generic;
33 using System.Linq;
44 using System.Text;
55 using NUnit.Framework;
6+using NSubstitute;
67 using OpenTween;
8+using System.Runtime.InteropServices;
9+using System.Reflection;
10+using System.Windows.Forms;
11+using System.Runtime.Serialization;
712
813 namespace OpenTween
914 {
1015 [TestFixture]
1116 public class MyCommonTest
1217 {
18+ [TestCase("http://ja.wikipedia.org/wiki/Wikipedia", Result = "http://ja.wikipedia.org/wiki/Wikipedia")]
19+ [TestCase("http://ja.wikipedia.org/wiki/メインページ",
20+ Result = "http://ja.wikipedia.org/wiki/%E3%83%A1%E3%82%A4%E3%83%B3%E3%83%9A%E3%83%BC%E3%82%B8")]
21+ [TestCase("http://fr.wikipedia.org/wiki/Café", Result = "http://fr.wikipedia.org/wiki/Caf%E9")]
22+ [TestCase("http://ja.wikipedia.org/wiki/勇気100%", Result = "http://ja.wikipedia.org/wiki/%E5%8B%87%E6%B0%97100%25")]
23+ [TestCase("http://ja.wikipedia.org/wiki/Bio_100%", Result = "http://ja.wikipedia.org/wiki/Bio_100%25")]
24+ public string urlEncodeMultibyteCharTest(string uri)
25+ {
26+ return MyCommon.urlEncodeMultibyteChar(uri);
27+ }
28+
29+ [TestCase("http://日本語.idn.icann.org/", Result = "http://xn--wgv71a119e.idn.icann.org/")]
30+ [TestCase("http://例え.テスト/", Result = "http://xn--r8jz45g.xn--zckzah/")]
31+ public string IDNDecodeTest(string uri)
32+ {
33+ return MyCommon.IDNDecode(uri);
34+ }
35+
36+ [TestCase(new int[] { 1, 2, 3, 4 }, 0, 3, Result = new int[] { 2, 3, 4, 1 })] // 左ローテイト?
37+ [TestCase(new int[] { 1, 2, 3, 4 }, 3, 0, Result = new int[] { 4, 1, 2, 3 })] // 右ローテイト?
38+ [TestCase(new int[] { 1, 2, 3, 4, 5 }, 1, 3, Result = new int[] { 1, 3, 4, 2, 5 })]
39+ [TestCase(new int[] { 1, 2, 3, 4, 5 }, 3, 1, Result = new int[] { 1, 4, 2, 3, 5 })]
40+ public int[] MoveArrayItemTest(int[] values, int idx_fr, int idx_to)
41+ {
42+ // MoveArrayItem は values を直接変更するため複製を用意する
43+ var copy = new int[values.Length];
44+ Array.Copy(values, copy, values.Length);
45+
46+ MyCommon.MoveArrayItem(copy, idx_fr, idx_to);
47+ return copy;
48+ }
49+
50+ [Test]
51+ public void EncryptStringTest()
52+ {
53+ var str = "hogehoge";
54+
55+ var crypto = MyCommon.EncryptString(str);
56+ Assert.That(crypto, Is.Not.EqualTo(str));
57+
58+ var decrypt = MyCommon.DecryptString(crypto);
59+ Assert.That(decrypt, Is.EqualTo(str));
60+ }
61+
62+ [TestCase(new byte[] { 0x01, 0x02 }, 3, Result = new byte[] { 0x01, 0x02, 0x00 })]
63+ [TestCase(new byte[] { 0x01, 0x02 }, 2, Result = new byte[] { 0x01, 0x02 })]
64+ [TestCase(new byte[] { 0x01, 0x02 }, 1, Result = new byte[] { 0x03 })]
65+ public byte[] ResizeBytesArrayTest(byte[] bytes, int size)
66+ {
67+ return MyCommon.ResizeBytesArray(bytes, size);
68+ }
69+
70+ [TestCase("Resources/re.gif", Result = true)]
71+ [TestCase("Resources/re1.gif", Result = false)]
72+ [TestCase("Resources/re1.png", Result = false)]
73+ public bool IsAnimatedGifTest(string filename)
74+ {
75+ return MyCommon.IsAnimatedGif(filename);
76+ }
77+
78+ static object[] DateTimeParse_TestCase =
79+ {
80+ new object[] {
81+ "Sun Nov 25 06:10:00 +00:00 2012",
82+ new DateTime(2012, 11, 25, 6, 10, 0, DateTimeKind.Utc)
83+ },
84+ new object[] {
85+ "Sun, 25 Nov 2012 06:10:00 +00:00",
86+ new DateTime(2012, 11, 25, 6, 10, 0, DateTimeKind.Utc)
87+ },
88+ };
89+ [TestCaseSource("DateTimeParse_TestCase")]
90+ public void DateTimeParseTest(string date, DateTime except)
91+ {
92+ Assert.That(MyCommon.DateTimeParse(date).ToUniversalTime(), Is.EqualTo(except));
93+ }
94+
95+ [DataContract]
96+ public struct JsonData
97+ {
98+ [DataMember(Name = "id")] public string Id { get; set; }
99+ [DataMember(Name = "body")] public string Body { get; set; }
100+ }
101+ static object[] CreateDataFromJson_TestCase =
102+ {
103+ new object[] {
104+ @"{""id"":""1"", ""body"":""hogehoge""}",
105+ new JsonData { Id = "1", Body = "hogehoge" },
106+ },
107+ };
108+ [TestCaseSource("CreateDataFromJson_TestCase")]
109+ public void CreateDataFromJsonTest<T>(string json, T expect)
110+ {
111+ Assert.That(MyCommon.CreateDataFromJson<T>(json), Is.EqualTo(expect));
112+ }
113+
114+ [TestCase("hoge123@example.com", Result = true)]
115+ [TestCase("hogehoge", Result = false)]
116+ [TestCase("foo.bar@example.com", Result = true)]
117+ [TestCase("foo..bar@example.com", Result = false)]
118+ [TestCase("foobar.@example.com", Result = false)]
119+ [TestCase("foo+bar@example.com", Result = true)]
120+ public bool IsValidEmailTest(string email)
121+ {
122+ return MyCommon.IsValidEmail(email);
123+ }
124+
125+ [TestCase(Keys.Shift, Keys.Shift, Result = true)]
126+ [TestCase(Keys.Shift, Keys.Control, Result = false)]
127+ [TestCase(Keys.Control | Keys.Alt, Keys.Control, Result = true)]
128+ [TestCase(Keys.Control | Keys.Alt, Keys.Alt, Result = true)]
129+ [TestCase(Keys.Control | Keys.Alt, Keys.Control, Keys.Alt, Result = true)]
130+ [TestCase(Keys.Control | Keys.Alt, Keys.Shift, Result = false)]
131+ public bool IsKeyDownTest(Keys modifierKeys, params Keys[] checkKeys)
132+ {
133+ return MyCommon._IsKeyDown(modifierKeys, checkKeys);
134+ }
135+
136+ [Test]
137+ public void GetAssemblyNameTest()
138+ {
139+ var mockAssembly = Substitute.For<_Assembly>();
140+ mockAssembly.GetName().Returns(new AssemblyName("OpenTween"));
141+ MyCommon.EntryAssembly = mockAssembly;
142+
143+ Assert.That(MyCommon.GetAssemblyName(), Is.EqualTo("OpenTween"));
144+ }
145+
146+ [TestCase("", "")]
147+ [TestCase("%AppName%", "OpenTween")]
148+ [TestCase("%AppName% %AppName%", "OpenTween OpenTween")]
149+ public void ReplaceAppNameTest(string str, string except)
150+ {
151+ Assert.That(MyCommon.ReplaceAppName(str, "OpenTween"), Is.EqualTo(except));
152+ }
153+
13154 [TestCase("1.0.0.0", "1.0.0")]
14155 [TestCase("1.0.0.1", "1.0.1-beta1")]
15156 [TestCase("1.0.0.9", "1.0.1-beta9")]
@@ -21,5 +162,29 @@ namespace OpenTween
21162 {
22163 Assert.That(OpenTween.MyCommon.GetReadableVersion(fileVersion), Is.EqualTo(expect));
23164 }
165+
166+ static object[] GetStatusUrlTest1_TestCase =
167+ {
168+ new object[] {
169+ new PostClass { StatusId = 249493863826350080L, ScreenName = "Favstar_LM", RetweetedId = 0L, RetweetedBy = null },
170+ "https://twitter.com/Favstar_LM/status/249493863826350080",
171+ },
172+ new object[] {
173+ new PostClass { StatusId = 216033842434289664L, ScreenName = "haru067", RetweetedId = 200245741443235840L, RetweetedBy = "re4k"},
174+ "https://twitter.com/haru067/status/200245741443235840",
175+ },
176+ };
177+ [TestCaseSource("GetStatusUrlTest1_TestCase")]
178+ public void GetStatusUrlTest1(PostClass post, string except)
179+ {
180+ Assert.That(MyCommon.GetStatusUrl(post), Is.EqualTo(except));
181+ }
182+
183+ [TestCase("Favstar_LM", 249493863826350080L, "https://twitter.com/Favstar_LM/status/249493863826350080")]
184+ [TestCase("haru067", 200245741443235840L, "https://twitter.com/haru067/status/200245741443235840")]
185+ public void GetStatusUrlTest2(string screenName, long statusId, string except)
186+ {
187+ Assert.That(MyCommon.GetStatusUrl(screenName, statusId), Is.EqualTo(except));
188+ }
24189 }
25190 }
--- a/OpenTween.Tests/OpenTween.Tests.csproj
+++ b/OpenTween.Tests/OpenTween.Tests.csproj
@@ -41,6 +41,8 @@
4141 </Reference>
4242 <Reference Include="System" />
4343 <Reference Include="System.Core" />
44+ <Reference Include="System.Runtime.Serialization" />
45+ <Reference Include="System.Windows.Forms" />
4446 <Reference Include="System.Xml.Linq" />
4547 <Reference Include="System.Data.DataSetExtensions" />
4648 <Reference Include="Microsoft.CSharp" />
@@ -60,7 +62,17 @@
6062 <ItemGroup>
6163 <Content Include="dlls\NSubstitute.dll" />
6264 <Content Include="dlls\nunit.framework.dll" />
65+ <Content Include="Resources\re.gif">
66+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
67+ </Content>
68+ <Content Include="Resources\re1.gif">
69+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
70+ </Content>
71+ <Content Include="Resources\re1.png">
72+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
73+ </Content>
6374 </ItemGroup>
75+ <ItemGroup />
6476 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
6577 <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
6678 Other similar extension points exist, see Microsoft.Common.targets.
Binary files /dev/null and b/OpenTween.Tests/Resources/re.gif differ
Binary files /dev/null and b/OpenTween.Tests/Resources/re1.gif differ
Binary files /dev/null and b/OpenTween.Tests/Resources/re1.png differ
--- a/OpenTween/MyCommon.cs
+++ b/OpenTween/MyCommon.cs
@@ -43,6 +43,7 @@ using System.Reflection;
4343 using System.Diagnostics;
4444 using System.Text.RegularExpressions;
4545 using System.Net.NetworkInformation;
46+using System.Runtime.InteropServices;
4647
4748 namespace OpenTween
4849 {
@@ -762,7 +763,7 @@ namespace OpenTween
762763 }
763764 }
764765
765- static bool IsValidEmail(string strIn)
766+ public static bool IsValidEmail(string strIn)
766767 {
767768 // Return true if strIn is in valid e-mail format.
768769 return Regex.IsMatch(strIn,
@@ -777,9 +778,14 @@ namespace OpenTween
777778 /// <returns><paramref name="keys"/> で指定された修飾キーがすべて押されている状態であれば true。それ以外であれば false。</returns>
778779 public static bool IsKeyDown(params Keys[] keys)
779780 {
780- foreach (Keys key in keys)
781+ return MyCommon._IsKeyDown(Control.ModifierKeys, keys);
782+ }
783+
784+ internal static bool _IsKeyDown(Keys modifierKeys, Keys[] targetKeys)
785+ {
786+ foreach (Keys key in targetKeys)
781787 {
782- if ((Control.ModifierKeys & key) != key)
788+ if ((modifierKeys & key) != key)
783789 {
784790 return false;
785791 }
@@ -796,9 +802,11 @@ namespace OpenTween
796802 /// <returns>アプリケーションのアセンブリ名</returns>
797803 public static string GetAssemblyName()
798804 {
799- return Assembly.GetEntryAssembly().GetName().Name;
805+ return MyCommon.EntryAssembly.GetName().Name;
800806 }
801807
808+ internal static _Assembly EntryAssembly = Assembly.GetEntryAssembly();
809+
802810 /// <summary>
803811 /// 文字列中に含まれる %AppName% をアプリケーション名に置換する
804812 /// </summary>
@@ -806,7 +814,18 @@ namespace OpenTween
806814 /// <returns>置換後の文字列</returns>
807815 public static string ReplaceAppName(string orig)
808816 {
809- return orig.Replace("%AppName%", Application.ProductName);
817+ return MyCommon.ReplaceAppName(orig, Application.ProductName);
818+ }
819+
820+ /// <summary>
821+ /// 文字列中に含まれる %AppName% をアプリケーション名に置換する
822+ /// </summary>
823+ /// <param name="orig">対象となる文字列</param>
824+ /// <param name="appname">アプリケーション名</param>
825+ /// <returns>置換後の文字列</returns>
826+ public static string ReplaceAppName(string orig, string appname)
827+ {
828+ return orig.Replace("%AppName%", appname);
810829 }
811830
812831 /// <summary>