1 // OpenTween - Client of Twitter
2 // Copyright (c) 2013 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;
29 using Xunit.Extensions;
33 public class ToolStripAPIGaugeTest
36 public void GaugeHeightTest()
38 using (var toolStrip = new ToolStripAPIGauge())
40 toolStrip.AutoSize = false;
41 toolStrip.Size = new Size(100, 10);
42 toolStrip.ApiLimit = new ApiLimit(150, 150, DateTime.MaxValue);
44 toolStrip.GaugeHeight = 5;
46 Assert.Equal(new Rectangle(0, 0, 100, 5), toolStrip.apiGaugeBounds);
47 Assert.Equal(new Rectangle(0, 5, 100, 5), toolStrip.timeGaugeBounds);
49 toolStrip.GaugeHeight = 3;
51 Assert.Equal(new Rectangle(0, 2, 100, 3), toolStrip.apiGaugeBounds);
52 Assert.Equal(new Rectangle(0, 5, 100, 3), toolStrip.timeGaugeBounds);
54 toolStrip.GaugeHeight = 0;
56 Assert.Equal(Rectangle.Empty, toolStrip.apiGaugeBounds);
57 Assert.Equal(Rectangle.Empty, toolStrip.timeGaugeBounds);
62 public void TextTest()
64 using (var toolStrip = new ToolStripAPIGauge())
66 // toolStrip.ApiLimit の初期値は null
68 Assert.Equal("API ???/???", toolStrip.Text);
69 Assert.Equal("API rest ???/???" + Environment.NewLine + "(reset after ??? minutes)", toolStrip.ToolTipText);
71 toolStrip.ApiLimit = new ApiLimit(15, 14, DateTime.Now.AddMinutes(15));
73 Assert.Equal("API 14/15", toolStrip.Text);
74 Assert.Equal("API rest 14/15" + Environment.NewLine + "(reset after 15 minutes)", toolStrip.ToolTipText);
76 toolStrip.ApiLimit = null;
78 Assert.Equal("API ???/???", toolStrip.Text);
79 Assert.Equal("API rest ???/???" + Environment.NewLine + "(reset after ??? minutes)", toolStrip.ToolTipText);
83 class TestToolStripAPIGauge : ToolStripAPIGauge
85 protected override void UpdateRemainMinutes()
87 if (this.ApiLimit != null)
88 // DateTime の代わりに Clock.Now を使用することで FreezeClock 属性の影響を受けるようになる
89 this.remainMinutes = (this.ApiLimit.AccessLimitResetDate - Clock.Now).TotalMinutes;
91 this.remainMinutes = -1;
97 public void GaugeBoundsTest()
99 using (var toolStrip = new TestToolStripAPIGauge())
101 toolStrip.AutoSize = false;
102 toolStrip.Size = new Size(100, 10);
103 toolStrip.GaugeHeight = 5;
105 // toolStrip.ApiLimit の初期値は null
107 Assert.Equal(Rectangle.Empty, toolStrip.apiGaugeBounds);
108 Assert.Equal(Rectangle.Empty, toolStrip.timeGaugeBounds);
110 toolStrip.ApiLimit = new ApiLimit(150, 60, Clock.Now.AddMinutes(15));
112 Assert.Equal(new Rectangle(0, 0, 40, 5), toolStrip.apiGaugeBounds); // 40% (60/150)
113 Assert.Equal(new Rectangle(0, 5, 25, 5), toolStrip.timeGaugeBounds); // 25% (15/60)
115 toolStrip.ApiLimit = null;
117 Assert.Equal(Rectangle.Empty, toolStrip.apiGaugeBounds);
118 Assert.Equal(Rectangle.Empty, toolStrip.timeGaugeBounds);