• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

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

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


Commit MetaInfo

Revisiónc679601d9babbecb7fcda575da3627a7d8199b97 (tree)
Tiempo2012-12-30 19:25:05
AutorKimura Youichi <kim.upsilon@bucy...>
CommiterKimura Youichi

Log Message

サムネイル関係のテストコード追加

Cambiar Resumen

Diferencia incremental

--- a/OpenTween.Tests/OpenTween.Tests.csproj
+++ b/OpenTween.Tests/OpenTween.Tests.csproj
@@ -62,6 +62,7 @@
6262 <Compile Include="Thumbnail\Services\MetaThumbnailServiceTest.cs" />
6363 <Compile Include="Thumbnail\Services\SimpleThumbnailServiceTest.cs" />
6464 <Compile Include="Thumbnail\Services\TinamiTest.cs" />
65+ <Compile Include="TweetThumbnailTest.cs" />
6566 </ItemGroup>
6667 <ItemGroup>
6768 <ProjectReference Include="..\OpenTween\OpenTween.csproj">
Binary files /dev/null and b/OpenTween.Tests/Resources/dot.gif differ
--- a/OpenTween.Tests/Thumbnail/Services/ImgAzyobuziNetTest.cs
+++ b/OpenTween.Tests/Thumbnail/Services/ImgAzyobuziNetTest.cs
@@ -24,6 +24,7 @@ using System.Collections.Generic;
2424 using System.Linq;
2525 using System.Text;
2626 using NUnit.Framework;
27+using System.Net;
2728
2829 namespace OpenTween.Thumbnail.Services
2930 {
@@ -32,13 +33,42 @@ namespace OpenTween.Thumbnail.Services
3233 {
3334 class TestImgAzyobuziNet : ImgAzyobuziNet
3435 {
36+ public TestImgAzyobuziNet()
37+ : base()
38+ {
39+ this.ApiHosts = new[] { "http://img.azyobuzi.net/api/" };
40+ }
41+
42+ public TestImgAzyobuziNet(string[] apiHosts)
43+ : base()
44+ {
45+ this.ApiHosts = apiHosts;
46+ }
47+
48+ public string GetApiBase()
49+ {
50+ return this.ApiBase;
51+ }
52+
3553 protected override byte[] FetchRegex(string apiBase)
3654 {
55+ if (apiBase == "http://down.example.com/api/")
56+ throw new WebException();
57+
3758 return Encoding.UTF8.GetBytes("[{\"name\": \"hogehoge\", \"regex\": \"^https?://example.com/(.+)$\"}]");
3859 }
3960 }
4061
4162 [Test]
63+ public void HostFallbackTest()
64+ {
65+ var service = new TestImgAzyobuziNet(new[] { "http://down.example.com/api/", "http://avail.example.com/api/" });
66+
67+ service.LoadRegex();
68+ Assert.That(service.GetApiBase(), Is.EqualTo("http://avail.example.com/api/"));
69+ }
70+
71+ [Test]
4272 public void MatchTest()
4373 {
4474 var service = new TestImgAzyobuziNet();
--- a/OpenTween.Tests/Thumbnail/Services/TinamiTest.cs
+++ b/OpenTween.Tests/Thumbnail/Services/TinamiTest.cs
@@ -55,5 +55,20 @@ namespace OpenTween.Thumbnail.Services
5555 Assert.That(thumbinfo.ThumbnailUrl, Is.EqualTo("http://img.tinami.com/hogehoge_150.gif"));
5656 Assert.That(thumbinfo.TooltipText, Is.EqualTo("説明"));
5757 }
58+
59+ [Test]
60+ public void ApiErrorTest()
61+ {
62+ var service = new TestTinami(@"^http://www\.tinami\.com/view/(?<ContentId>\d+)$",
63+ "http://api.tinami.com/content/info?cont_id=${ContentId}&api_key=" + ApplicationSettings.TINAMIApiKey);
64+
65+ service.FakeXml = @"<?xml version='1.0' encoding='utf-8'?>
66+<rsp stat='user_only'>
67+ <err msg='この作品は登録ユーザー限定の作品です。'/>
68+</rsp>";
69+ var thumbinfo = service.GetThumbnailInfo("http://www.tinami.com/view/12345", null);
70+
71+ Assert.That(thumbinfo, Is.Null);
72+ }
5873 }
5974 }
--- /dev/null
+++ b/OpenTween.Tests/TweetThumbnailTest.cs
@@ -0,0 +1,108 @@
1+// OpenTween - Client of Twitter
2+// Copyright (c) 2012 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3+// All rights reserved.
4+//
5+// This file is part of OpenTween.
6+//
7+// This program is free software; you can redistribute it and/or modify it
8+// under the terms of the GNU General Public License as published by the Free
9+// Software Foundation; either version 3 of the License, or (at your option)
10+// any later version.
11+//
12+// This program is distributed in the hope that it will be useful, but
13+// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14+// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15+// for more details.
16+//
17+// You should have received a copy of the GNU General Public License along
18+// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
19+// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20+// Boston, MA 02110-1301, USA.
21+
22+using System;
23+using System.Collections.Generic;
24+using System.Linq;
25+using System.Text;
26+using NUnit.Framework;
27+using System.Reflection;
28+using System.Windows.Forms;
29+using OpenTween.Thumbnail;
30+
31+namespace OpenTween
32+{
33+ [TestFixture]
34+ class TweetThumbnailTest
35+ {
36+ [Test]
37+ public void CreatePictureBoxTest()
38+ {
39+ using (var thumbBox = new TweetThumbnail())
40+ {
41+ var method = typeof(TweetThumbnail).GetMethod("CreatePictureBox", BindingFlags.Instance | BindingFlags.NonPublic);
42+ var picbox = method.Invoke(thumbBox, new[] { "pictureBox1" }) as PictureBox;
43+
44+ Assert.That(picbox, Is.Not.Null);
45+ Assert.That(picbox.Name, Is.EqualTo("pictureBox1"));
46+ Assert.That(picbox.SizeMode, Is.EqualTo(PictureBoxSizeMode.Zoom));
47+ Assert.That(picbox.WaitOnLoad, Is.False);
48+ Assert.That(picbox.Dock, Is.EqualTo(DockStyle.Fill));
49+ Assert.That(picbox.Visible, Is.False);
50+
51+ picbox.Dispose();
52+ }
53+ }
54+
55+ class TestTweetThumbnail : TweetThumbnail
56+ {
57+ protected override List<ThumbnailInfo> GetThumbailInfo(PostClass post)
58+ {
59+ return new List<ThumbnailInfo>
60+ {
61+ new ThumbnailInfo
62+ {
63+ ImageUrl = "http://example.com/abcd",
64+ ThumbnailUrl = "dot.gif", // 1x1の黒画像
65+ TooltipText = "ほげほげ",
66+ },
67+ };
68+ }
69+ }
70+
71+ [Test]
72+ public void CancelAsyncTest()
73+ {
74+ using (var thumbbox = new TestTweetThumbnail())
75+ {
76+ var post = new PostClass();
77+ var task = thumbbox.ShowThumbnailAsync(post);
78+
79+ thumbbox.CancelAsync();
80+
81+ Assert.That(task.IsCanceled, Is.True);
82+ }
83+ }
84+
85+ [Test]
86+ public void SetThumbnailCountTest(
87+ [Values(0, 1, 2)] int count)
88+ {
89+ using (var thumbbox = new TweetThumbnail())
90+ {
91+ var method = typeof(TweetThumbnail).GetMethod("SetThumbnailCount", BindingFlags.Instance | BindingFlags.NonPublic);
92+ method.Invoke(thumbbox, new[] { (object)count });
93+
94+ Assert.That(thumbbox.pictureBox.Count, Is.EqualTo(count));
95+
96+ var num = 0;
97+ foreach (var picbox in thumbbox.pictureBox)
98+ {
99+ Assert.That(picbox.Name, Is.EqualTo("pictureBox" + num));
100+ num++;
101+ }
102+
103+ Assert.That(thumbbox.scrollBar.Minimum, Is.EqualTo(0));
104+ Assert.That(thumbbox.scrollBar.Maximum, Is.EqualTo(count));
105+ }
106+ }
107+ }
108+}
--- a/OpenTween/Thumbnail/Services/ImgAzyobuziNet.cs
+++ b/OpenTween/Thumbnail/Services/ImgAzyobuziNet.cs
@@ -37,10 +37,10 @@ namespace OpenTween.Thumbnail.Services
3737 {
3838 class ImgAzyobuziNet : IThumbnailService
3939 {
40- private readonly string[] ApiHosts = { "http://img.azyobuzi.net/api/", "http://img.opentween.org/api/" };
40+ protected string[] ApiHosts = { "http://img.azyobuzi.net/api/", "http://img.opentween.org/api/" };
4141
42- private string ApiBase;
43- private IEnumerable<Regex> UrlRegex = new Regex[] {};
42+ protected string ApiBase;
43+ protected IEnumerable<Regex> UrlRegex = new Regex[] {};
4444
4545 private object LockObj = new object();
4646
--- a/OpenTween/Thumbnail/Services/MetaThumbnailService.cs
+++ b/OpenTween/Thumbnail/Services/MetaThumbnailService.cs
@@ -37,7 +37,7 @@ namespace OpenTween.Thumbnail.Services
3737 protected static string[] propertyNames = { "twitter:image", "og:image" };
3838
3939 public MetaThumbnailService(string url)
40- : base(url, "${0}")
40+ : this(url, "${0}")
4141 {
4242 }
4343
--- a/OpenTween/TweetThumbnail.Designer.cs
+++ b/OpenTween/TweetThumbnail.Designer.cs
@@ -58,7 +58,7 @@
5858
5959 #endregion
6060
61- private System.Windows.Forms.VScrollBar scrollBar;
6261 private System.Windows.Forms.ToolTip toolTip;
62+ protected internal System.Windows.Forms.VScrollBar scrollBar;
6363 }
6464 }
--- a/OpenTween/TweetThumbnail.cs
+++ b/OpenTween/TweetThumbnail.cs
@@ -36,7 +36,7 @@ namespace OpenTween
3636 {
3737 public partial class TweetThumbnail : UserControl
3838 {
39- private List<PictureBox> pictureBox = new List<PictureBox>();
39+ protected internal List<PictureBox> pictureBox = new List<PictureBox>();
4040
4141 private Task task = null;
4242 private CancellationTokenSource cancelTokenSource;
@@ -63,7 +63,7 @@ namespace OpenTween
6363 this.cancelTokenSource = new CancellationTokenSource();
6464 var cancelToken = this.cancelTokenSource.Token;
6565
66- this.task = Task.Factory.StartNew(() => ThumbnailGenerator.GetThumbnails(post), cancelToken)
66+ this.task = Task.Factory.StartNew(() => this.GetThumbailInfo(post), cancelToken)
6767 .ContinueWith( /* await使いたい */
6868 t =>
6969 {
@@ -106,6 +106,11 @@ namespace OpenTween
106106 return this.task;
107107 }
108108
109+ protected virtual List<ThumbnailInfo> GetThumbailInfo(PostClass post)
110+ {
111+ return ThumbnailGenerator.GetThumbnails(post);
112+ }
113+
109114 public void CancelAsync()
110115 {
111116 if (this.task != null && !this.task.IsCompleted)
@@ -141,14 +146,7 @@ namespace OpenTween
141146
142147 for (int i = 0; i < count; i++)
143148 {
144- var picbox = new PictureBox()
145- {
146- Name = "pictureBox" + i,
147- SizeMode = PictureBoxSizeMode.Zoom,
148- WaitOnLoad = false,
149- Dock = DockStyle.Fill,
150- Visible = false,
151- };
149+ var picbox = CreatePictureBox("pictureBox" + i);
152150 picbox.DoubleClick += this.pictureBox_DoubleClick;
153151
154152 this.Controls.Add(picbox);
@@ -158,6 +156,18 @@ namespace OpenTween
158156 this.ResumeLayout(false);
159157 }
160158
159+ protected virtual PictureBox CreatePictureBox(string name)
160+ {
161+ return new PictureBox()
162+ {
163+ Name = name,
164+ SizeMode = PictureBoxSizeMode.Zoom,
165+ WaitOnLoad = false,
166+ Dock = DockStyle.Fill,
167+ Visible = false,
168+ };
169+ }
170+
161171 public void ScrollUp()
162172 {
163173 var newval = this.scrollBar.Value + this.scrollBar.SmallChange;