開発に使用するリポジトリ
Revisión | c679601d9babbecb7fcda575da3627a7d8199b97 (tree) |
---|---|
Tiempo | 2012-12-30 19:25:05 |
Autor | Kimura Youichi <kim.upsilon@bucy...> |
Commiter | Kimura Youichi |
サムネイル関係のテストコード追加
@@ -62,6 +62,7 @@ | ||
62 | 62 | <Compile Include="Thumbnail\Services\MetaThumbnailServiceTest.cs" /> |
63 | 63 | <Compile Include="Thumbnail\Services\SimpleThumbnailServiceTest.cs" /> |
64 | 64 | <Compile Include="Thumbnail\Services\TinamiTest.cs" /> |
65 | + <Compile Include="TweetThumbnailTest.cs" /> | |
65 | 66 | </ItemGroup> |
66 | 67 | <ItemGroup> |
67 | 68 | <ProjectReference Include="..\OpenTween\OpenTween.csproj"> |
@@ -24,6 +24,7 @@ using System.Collections.Generic; | ||
24 | 24 | using System.Linq; |
25 | 25 | using System.Text; |
26 | 26 | using NUnit.Framework; |
27 | +using System.Net; | |
27 | 28 | |
28 | 29 | namespace OpenTween.Thumbnail.Services |
29 | 30 | { |
@@ -32,13 +33,42 @@ namespace OpenTween.Thumbnail.Services | ||
32 | 33 | { |
33 | 34 | class TestImgAzyobuziNet : ImgAzyobuziNet |
34 | 35 | { |
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 | + | |
35 | 53 | protected override byte[] FetchRegex(string apiBase) |
36 | 54 | { |
55 | + if (apiBase == "http://down.example.com/api/") | |
56 | + throw new WebException(); | |
57 | + | |
37 | 58 | return Encoding.UTF8.GetBytes("[{\"name\": \"hogehoge\", \"regex\": \"^https?://example.com/(.+)$\"}]"); |
38 | 59 | } |
39 | 60 | } |
40 | 61 | |
41 | 62 | [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] | |
42 | 72 | public void MatchTest() |
43 | 73 | { |
44 | 74 | var service = new TestImgAzyobuziNet(); |
@@ -55,5 +55,20 @@ namespace OpenTween.Thumbnail.Services | ||
55 | 55 | Assert.That(thumbinfo.ThumbnailUrl, Is.EqualTo("http://img.tinami.com/hogehoge_150.gif")); |
56 | 56 | Assert.That(thumbinfo.TooltipText, Is.EqualTo("説明")); |
57 | 57 | } |
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 | + } | |
58 | 73 | } |
59 | 74 | } |
@@ -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 | +} |
@@ -37,10 +37,10 @@ namespace OpenTween.Thumbnail.Services | ||
37 | 37 | { |
38 | 38 | class ImgAzyobuziNet : IThumbnailService |
39 | 39 | { |
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/" }; | |
41 | 41 | |
42 | - private string ApiBase; | |
43 | - private IEnumerable<Regex> UrlRegex = new Regex[] {}; | |
42 | + protected string ApiBase; | |
43 | + protected IEnumerable<Regex> UrlRegex = new Regex[] {}; | |
44 | 44 | |
45 | 45 | private object LockObj = new object(); |
46 | 46 |
@@ -37,7 +37,7 @@ namespace OpenTween.Thumbnail.Services | ||
37 | 37 | protected static string[] propertyNames = { "twitter:image", "og:image" }; |
38 | 38 | |
39 | 39 | public MetaThumbnailService(string url) |
40 | - : base(url, "${0}") | |
40 | + : this(url, "${0}") | |
41 | 41 | { |
42 | 42 | } |
43 | 43 |
@@ -58,7 +58,7 @@ | ||
58 | 58 | |
59 | 59 | #endregion |
60 | 60 | |
61 | - private System.Windows.Forms.VScrollBar scrollBar; | |
62 | 61 | private System.Windows.Forms.ToolTip toolTip; |
62 | + protected internal System.Windows.Forms.VScrollBar scrollBar; | |
63 | 63 | } |
64 | 64 | } |
@@ -36,7 +36,7 @@ namespace OpenTween | ||
36 | 36 | { |
37 | 37 | public partial class TweetThumbnail : UserControl |
38 | 38 | { |
39 | - private List<PictureBox> pictureBox = new List<PictureBox>(); | |
39 | + protected internal List<PictureBox> pictureBox = new List<PictureBox>(); | |
40 | 40 | |
41 | 41 | private Task task = null; |
42 | 42 | private CancellationTokenSource cancelTokenSource; |
@@ -63,7 +63,7 @@ namespace OpenTween | ||
63 | 63 | this.cancelTokenSource = new CancellationTokenSource(); |
64 | 64 | var cancelToken = this.cancelTokenSource.Token; |
65 | 65 | |
66 | - this.task = Task.Factory.StartNew(() => ThumbnailGenerator.GetThumbnails(post), cancelToken) | |
66 | + this.task = Task.Factory.StartNew(() => this.GetThumbailInfo(post), cancelToken) | |
67 | 67 | .ContinueWith( /* await使いたい */ |
68 | 68 | t => |
69 | 69 | { |
@@ -106,6 +106,11 @@ namespace OpenTween | ||
106 | 106 | return this.task; |
107 | 107 | } |
108 | 108 | |
109 | + protected virtual List<ThumbnailInfo> GetThumbailInfo(PostClass post) | |
110 | + { | |
111 | + return ThumbnailGenerator.GetThumbnails(post); | |
112 | + } | |
113 | + | |
109 | 114 | public void CancelAsync() |
110 | 115 | { |
111 | 116 | if (this.task != null && !this.task.IsCompleted) |
@@ -141,14 +146,7 @@ namespace OpenTween | ||
141 | 146 | |
142 | 147 | for (int i = 0; i < count; i++) |
143 | 148 | { |
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); | |
152 | 150 | picbox.DoubleClick += this.pictureBox_DoubleClick; |
153 | 151 | |
154 | 152 | this.Controls.Add(picbox); |
@@ -158,6 +156,18 @@ namespace OpenTween | ||
158 | 156 | this.ResumeLayout(false); |
159 | 157 | } |
160 | 158 | |
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 | + | |
161 | 171 | public void ScrollUp() |
162 | 172 | { |
163 | 173 | var newval = this.scrollBar.Value + this.scrollBar.SmallChange; |