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;
27 using NUnit.Framework;
33 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.That(toolStrip.apiGaugeBounds, Is.EqualTo(new Rectangle(0, 0, 100, 5)));
47 Assert.That(toolStrip.timeGaugeBounds, Is.EqualTo(new Rectangle(0, 5, 100, 5)));
49 toolStrip.GaugeHeight = 3;
51 Assert.That(toolStrip.apiGaugeBounds, Is.EqualTo(new Rectangle(0, 2, 100, 3)));
52 Assert.That(toolStrip.timeGaugeBounds, Is.EqualTo(new Rectangle(0, 5, 100, 3)));
54 toolStrip.GaugeHeight = 0;
56 Assert.That(toolStrip.apiGaugeBounds, Is.EqualTo(Rectangle.Empty));
57 Assert.That(toolStrip.timeGaugeBounds, Is.EqualTo(Rectangle.Empty));
62 public void TextTest()
64 using (var toolStrip = new ToolStripAPIGauge())
66 // toolStrip.ApiLimit の初期値は null
68 Assert.That(toolStrip.Text, Is.EqualTo("API ???/???"));
69 Assert.That(toolStrip.ToolTipText, Is.EqualTo("API rest ???/???" + Environment.NewLine + "(reset after ??? minutes)"));
71 toolStrip.ApiLimit = new ApiLimit(15, 14, DateTime.Now.AddMinutes(15));
73 Assert.That(toolStrip.Text, Is.EqualTo("API 14/15"));
74 Assert.That(toolStrip.ToolTipText, Is.EqualTo("API rest 14/15" + Environment.NewLine + "(reset after 15 minutes)"));
76 toolStrip.ApiLimit = null;
78 Assert.That(toolStrip.Text, Is.EqualTo("API ???/???"));
79 Assert.That(toolStrip.ToolTipText, Is.EqualTo("API rest ???/???" + Environment.NewLine + "(reset after ??? minutes)"));
83 class TestToolStripAPIGauge : ToolStripAPIGauge
85 public DateTime Now { get; set; } // 現在時刻
87 protected override void UpdateRemainMinutes()
89 if (this.ApiLimit != null)
90 this.remainMinutes = (this.ApiLimit.AccessLimitResetDate - this.Now).TotalMinutes;
92 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;
106 toolStrip.Now = new DateTime(2013, 1, 1, 0, 0, 0);
108 // toolStrip.ApiLimit の初期値は null
110 Assert.That(toolStrip.apiGaugeBounds, Is.EqualTo(Rectangle.Empty));
111 Assert.That(toolStrip.timeGaugeBounds, Is.EqualTo(Rectangle.Empty));
113 toolStrip.ApiLimit = new ApiLimit(150, 60, toolStrip.Now.AddMinutes(15));
115 Assert.That(toolStrip.apiGaugeBounds, Is.EqualTo(new Rectangle(0, 0, 40, 5))); // 40% (60/150)
116 Assert.That(toolStrip.timeGaugeBounds, Is.EqualTo(new Rectangle(0, 5, 25, 5))); // 25% (15/60)
118 toolStrip.ApiLimit = null;
120 Assert.That(toolStrip.apiGaugeBounds, Is.EqualTo(Rectangle.Empty));
121 Assert.That(toolStrip.timeGaugeBounds, Is.EqualTo(Rectangle.Empty));