1 // OpenTween - Client of Twitter
2 // Copyright (c) 2020 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3 // All rights reserved.
5 // This file is part of OpenTween.
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)
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
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.
23 using System.Collections.Generic;
26 using System.Text.RegularExpressions;
27 using System.Threading;
28 using System.Threading.Tasks;
29 using OpenTween.Models;
32 namespace OpenTween.Thumbnail.Services
34 public class PbsTwimgComTest
37 public void ModernUrlPattern_Test()
39 var mediaUrl = "https://pbs.twimg.com/media/DYlFv51VwAUdqWr?format=jpg&name=large";
40 var matches = PbsTwimgCom.ModernUrlPattern.Match(mediaUrl);
42 Assert.True(matches.Success);
43 Assert.Equal("https://pbs.twimg.com/media/DYlFv51VwAUdqWr", matches.Groups["base_url"].Value);
44 Assert.Equal("jpg", matches.Groups["format"].Value);
48 public void ModernUrlPattern_UnorderedTest()
50 var mediaUrl = "https://pbs.twimg.com/media/DYlFv51VwAUdqWr?name=large&format=jpg";
51 var matches = PbsTwimgCom.ModernUrlPattern.Match(mediaUrl);
53 Assert.True(matches.Success);
54 Assert.Equal("https://pbs.twimg.com/media/DYlFv51VwAUdqWr", matches.Groups["base_url"].Value);
55 Assert.Equal("jpg", matches.Groups["format"].Value);
59 public void ModernUrlPattern_LegacyUrlTest()
61 var mediaUrl = "https://pbs.twimg.com/media/DYlFv51VwAUdqWr.jpg:large";
62 var matches = PbsTwimgCom.ModernUrlPattern.Match(mediaUrl);
64 Assert.False(matches.Success);
68 public void LegacyUrlPattern_Test()
70 var mediaUrl = "https://pbs.twimg.com/media/DYlFv51VwAUdqWr.jpg";
71 var matches = PbsTwimgCom.LegacyUrlPattern.Match(mediaUrl);
73 Assert.True(matches.Success);
74 Assert.Equal("https://pbs.twimg.com/media/DYlFv51VwAUdqWr", matches.Groups["base_url"].Value);
75 Assert.Equal("jpg", matches.Groups["format"].Value);
79 public void LegacyUrlPattern_SizeNameTest()
81 var mediaUrl = "https://pbs.twimg.com/media/DYlFv51VwAUdqWr.jpg:large";
82 var matches = PbsTwimgCom.LegacyUrlPattern.Match(mediaUrl);
84 Assert.True(matches.Success);
85 Assert.Equal("https://pbs.twimg.com/media/DYlFv51VwAUdqWr", matches.Groups["base_url"].Value);
86 Assert.Equal("jpg", matches.Groups["format"].Value);
90 public void LegacyUrlPattern_ModernUrlTest()
92 var mediaUrl = "https://pbs.twimg.com/media/DYlFv51VwAUdqWr?format=jpg&name=large";
93 var matches = PbsTwimgCom.LegacyUrlPattern.Match(mediaUrl);
95 Assert.False(matches.Success);
99 public async Task GetThumbnailInfoAsync_ModernUrlTest()
101 var mediaUrl = "https://pbs.twimg.com/media/DYlFv51VwAUdqWr?format=jpg&name=large";
103 var service = new PbsTwimgCom();
104 var thumb = await service.GetThumbnailInfoAsync(mediaUrl, new PostClass(), CancellationToken.None)
105 .ConfigureAwait(false);
107 Assert.NotNull(thumb);
108 Assert.Equal("https://pbs.twimg.com/media/DYlFv51VwAUdqWr?format=jpg&name=large", thumb!.ThumbnailImageUrl);
109 Assert.Equal("https://pbs.twimg.com/media/DYlFv51VwAUdqWr?format=jpg&name=orig", thumb!.FullSizeImageUrl);
113 public async Task GetThumbnailInfoAsync_LegacyUrlTest()
115 var mediaUrl = "https://pbs.twimg.com/media/DYlFv51VwAUdqWr.jpg";
117 var service = new PbsTwimgCom();
118 var thumb = await service.GetThumbnailInfoAsync(mediaUrl, new PostClass(), CancellationToken.None)
119 .ConfigureAwait(false);
121 Assert.NotNull(thumb);
122 Assert.Equal("https://pbs.twimg.com/media/DYlFv51VwAUdqWr?format=jpg&name=large", thumb!.ThumbnailImageUrl);
123 Assert.Equal("https://pbs.twimg.com/media/DYlFv51VwAUdqWr?format=jpg&name=orig", thumb!.FullSizeImageUrl);