<Compile Include="Thumbnail\Services\MetaThumbnailServiceTest.cs" />\r
<Compile Include="Thumbnail\Services\SimpleThumbnailServiceTest.cs" />\r
<Compile Include="Thumbnail\Services\TinamiTest.cs" />\r
+ <Compile Include="TweetThumbnailTest.cs" />\r
</ItemGroup>\r
<ItemGroup>\r
<ProjectReference Include="..\OpenTween\OpenTween.csproj">\r
using System.Linq;
using System.Text;
using NUnit.Framework;
+using System.Net;
namespace OpenTween.Thumbnail.Services
{
{
class TestImgAzyobuziNet : ImgAzyobuziNet
{
+ public TestImgAzyobuziNet()
+ : base()
+ {
+ this.ApiHosts = new[] { "http://img.azyobuzi.net/api/" };
+ }
+
+ public TestImgAzyobuziNet(string[] apiHosts)
+ : base()
+ {
+ this.ApiHosts = apiHosts;
+ }
+
+ public string GetApiBase()
+ {
+ return this.ApiBase;
+ }
+
protected override byte[] FetchRegex(string apiBase)
{
+ if (apiBase == "http://down.example.com/api/")
+ throw new WebException();
+
return Encoding.UTF8.GetBytes("[{\"name\": \"hogehoge\", \"regex\": \"^https?://example.com/(.+)$\"}]");
}
}
[Test]
+ public void HostFallbackTest()
+ {
+ var service = new TestImgAzyobuziNet(new[] { "http://down.example.com/api/", "http://avail.example.com/api/" });
+
+ service.LoadRegex();
+ Assert.That(service.GetApiBase(), Is.EqualTo("http://avail.example.com/api/"));
+ }
+
+ [Test]
public void MatchTest()
{
var service = new TestImgAzyobuziNet();
Assert.That(thumbinfo.ThumbnailUrl, Is.EqualTo("http://img.tinami.com/hogehoge_150.gif"));
Assert.That(thumbinfo.TooltipText, Is.EqualTo("説明"));
}
+
+ [Test]
+ public void ApiErrorTest()
+ {
+ var service = new TestTinami(@"^http://www\.tinami\.com/view/(?<ContentId>\d+)$",
+ "http://api.tinami.com/content/info?cont_id=${ContentId}&api_key=" + ApplicationSettings.TINAMIApiKey);
+
+ service.FakeXml = @"<?xml version='1.0' encoding='utf-8'?>
+<rsp stat='user_only'>
+ <err msg='この作品は登録ユーザー限定の作品です。'/>
+</rsp>";
+ var thumbinfo = service.GetThumbnailInfo("http://www.tinami.com/view/12345", null);
+
+ Assert.That(thumbinfo, Is.Null);
+ }
}
}
--- /dev/null
+// OpenTween - Client of Twitter
+// Copyright (c) 2012 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
+// All rights reserved.
+//
+// This file is part of OpenTween.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
+// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using System.Reflection;
+using System.Windows.Forms;
+using OpenTween.Thumbnail;
+
+namespace OpenTween
+{
+ [TestFixture]
+ class TweetThumbnailTest
+ {
+ [Test]
+ public void CreatePictureBoxTest()
+ {
+ using (var thumbBox = new TweetThumbnail())
+ {
+ var method = typeof(TweetThumbnail).GetMethod("CreatePictureBox", BindingFlags.Instance | BindingFlags.NonPublic);
+ var picbox = method.Invoke(thumbBox, new[] { "pictureBox1" }) as PictureBox;
+
+ Assert.That(picbox, Is.Not.Null);
+ Assert.That(picbox.Name, Is.EqualTo("pictureBox1"));
+ Assert.That(picbox.SizeMode, Is.EqualTo(PictureBoxSizeMode.Zoom));
+ Assert.That(picbox.WaitOnLoad, Is.False);
+ Assert.That(picbox.Dock, Is.EqualTo(DockStyle.Fill));
+ Assert.That(picbox.Visible, Is.False);
+
+ picbox.Dispose();
+ }
+ }
+
+ class TestTweetThumbnail : TweetThumbnail
+ {
+ protected override List<ThumbnailInfo> GetThumbailInfo(PostClass post)
+ {
+ return new List<ThumbnailInfo>
+ {
+ new ThumbnailInfo
+ {
+ ImageUrl = "http://example.com/abcd",
+ ThumbnailUrl = "dot.gif", // 1x1の黒画像
+ TooltipText = "ほげほげ",
+ },
+ };
+ }
+ }
+
+ [Test]
+ public void CancelAsyncTest()
+ {
+ using (var thumbbox = new TestTweetThumbnail())
+ {
+ var post = new PostClass();
+ var task = thumbbox.ShowThumbnailAsync(post);
+
+ thumbbox.CancelAsync();
+
+ Assert.That(task.IsCanceled, Is.True);
+ }
+ }
+
+ [Test]
+ public void SetThumbnailCountTest(
+ [Values(0, 1, 2)] int count)
+ {
+ using (var thumbbox = new TweetThumbnail())
+ {
+ var method = typeof(TweetThumbnail).GetMethod("SetThumbnailCount", BindingFlags.Instance | BindingFlags.NonPublic);
+ method.Invoke(thumbbox, new[] { (object)count });
+
+ Assert.That(thumbbox.pictureBox.Count, Is.EqualTo(count));
+
+ var num = 0;
+ foreach (var picbox in thumbbox.pictureBox)
+ {
+ Assert.That(picbox.Name, Is.EqualTo("pictureBox" + num));
+ num++;
+ }
+
+ Assert.That(thumbbox.scrollBar.Minimum, Is.EqualTo(0));
+ Assert.That(thumbbox.scrollBar.Maximum, Is.EqualTo(count));
+ }
+ }
+ }
+}
{
class ImgAzyobuziNet : IThumbnailService
{
- private readonly string[] ApiHosts = { "http://img.azyobuzi.net/api/", "http://img.opentween.org/api/" };
+ protected string[] ApiHosts = { "http://img.azyobuzi.net/api/", "http://img.opentween.org/api/" };
- private string ApiBase;
- private IEnumerable<Regex> UrlRegex = new Regex[] {};
+ protected string ApiBase;
+ protected IEnumerable<Regex> UrlRegex = new Regex[] {};
private object LockObj = new object();
protected static string[] propertyNames = { "twitter:image", "og:image" };
public MetaThumbnailService(string url)
- : base(url, "${0}")
+ : this(url, "${0}")
{
}
#endregion
- private System.Windows.Forms.VScrollBar scrollBar;
private System.Windows.Forms.ToolTip toolTip;
+ protected internal System.Windows.Forms.VScrollBar scrollBar;
}
}
{
public partial class TweetThumbnail : UserControl
{
- private List<PictureBox> pictureBox = new List<PictureBox>();
+ protected internal List<PictureBox> pictureBox = new List<PictureBox>();
private Task task = null;
private CancellationTokenSource cancelTokenSource;
this.cancelTokenSource = new CancellationTokenSource();
var cancelToken = this.cancelTokenSource.Token;
- this.task = Task.Factory.StartNew(() => ThumbnailGenerator.GetThumbnails(post), cancelToken)
+ this.task = Task.Factory.StartNew(() => this.GetThumbailInfo(post), cancelToken)
.ContinueWith( /* await使いたい */
t =>
{
return this.task;
}
+ protected virtual List<ThumbnailInfo> GetThumbailInfo(PostClass post)
+ {
+ return ThumbnailGenerator.GetThumbnails(post);
+ }
+
public void CancelAsync()
{
if (this.task != null && !this.task.IsCompleted)
for (int i = 0; i < count; i++)
{
- var picbox = new PictureBox()
- {
- Name = "pictureBox" + i,
- SizeMode = PictureBoxSizeMode.Zoom,
- WaitOnLoad = false,
- Dock = DockStyle.Fill,
- Visible = false,
- };
+ var picbox = CreatePictureBox("pictureBox" + i);
picbox.DoubleClick += this.pictureBox_DoubleClick;
this.Controls.Add(picbox);
this.ResumeLayout(false);
}
+ protected virtual PictureBox CreatePictureBox(string name)
+ {
+ return new PictureBox()
+ {
+ Name = name,
+ SizeMode = PictureBoxSizeMode.Zoom,
+ WaitOnLoad = false,
+ Dock = DockStyle.Fill,
+ Visible = false,
+ };
+ }
+
public void ScrollUp()
{
var newval = this.scrollBar.Value + this.scrollBar.SmallChange;