1 // Copyright (C) 2016 Kazuhiro Fujieda <fujieda@users.osdn.me>
\r
3 // Licensed under the Apache License, Version 2.0 (the "License");
\r
4 // you may not use this file except in compliance with the License.
\r
5 // You may obtain a copy of the License at
\r
7 // http://www.apache.org/licenses/LICENSE-2.0
\r
9 // Unless required by applicable law or agreed to in writing, software
\r
10 // distributed under the License is distributed on an "AS IS" BASIS,
\r
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
12 // See the License for the specific language governing permissions and
\r
13 // limitations under the License.
\r
16 using System.Collections.Generic;
\r
17 using System.Drawing;
\r
18 using System.Reflection;
\r
19 using System.Windows.Forms;
\r
20 using ExpressionToCodeLib;
\r
21 using KancolleSniffer.Model;
\r
22 using KancolleSniffer.View;
\r
23 using Microsoft.VisualStudio.TestTools.UnitTesting;
\r
25 namespace KancolleSniffer.Test
\r
28 public class ShipLabelTest
\r
31 public class TruncateTest
\r
33 private class TestData : Dictionary<int, Pair[]>
\r
39 public readonly string Origin;
\r
40 public readonly string Result;
\r
48 public Pair(string origin, string result)
\r
59 public void Unlimited()
\r
61 var label = new ShipLabel.Name(Point.Empty, ShipNameWidth.Max){Parent = new Panel()};
\r
62 var str = "一二三四五六七八九〇一二三四五六七八九〇一二三四五六七八九〇";
\r
64 Assert.AreEqual(str, label.Text);
\r
68 /// 明石タイマー表示中の艦娘の名前を縮める
\r
71 public void ForAkashiTimer()
\r
73 var data = new TestData
\r
79 new Pair("夕立改二", "夕立改二"),
\r
80 new Pair("千代田航改", "千代田航"),
\r
81 new Pair("千代田航改二", "千代田航"),
\r
82 new Pair("Bismarck改", "Bismarck"),
\r
83 new Pair("Bismarck zwei", "Bismarck"),
\r
84 new Pair("Bismarck drei", "Bismarck"),
\r
85 new Pair("Prinz Eugen", "Prinz Eug"),
\r
86 new Pair("Prinz Eugen改", "Prinz Eug"),
\r
87 new Pair("Graf Zeppelin", "Graf Zep"),
\r
88 new Pair("Graf Zeppelin改", "Graf Zep"),
\r
89 new Pair("Libeccio改", "Libeccio")
\r
104 new Pair("Graf Zeppelin", "Graf Zepp"),
\r
105 new Pair("Graf Zeppelin改", "Graf Zepp"),
\r
106 new Pair("Libeccio改", "Libeccio改")
\r
110 TestTruncate(data, ShipNameWidth.AkashiTimer);
\r
117 public void ForNDock()
\r
119 var data = new TestData
\r
124 new Pair("千歳航改二", "千歳航改二"),
\r
125 new Pair("千代田航改二", "千代田航改"),
\r
126 new Pair("Graf Zeppelin", "Graf Zeppeli"),
\r
127 new Pair("Graf Zeppelin改", "Graf Zeppeli")
\r
135 new Pair("Graf Zeppelin", "Graf Zeppelin"),
\r
136 new Pair("Graf Zeppelin改", "Graf Zeppelin")
\r
140 TestTruncate(data, ShipNameWidth.NDock);
\r
144 /// 一覧ウィンドウの要修復一覧の艦娘の名前を縮める
\r
147 public void ForRepairListFull()
\r
149 var data = new TestData
\r
155 new Pair("Graf Zeppelin", "Graf Zeppelin"),
\r
156 new Pair("Graf Zeppelin改", "Graf Zeppelin"),
\r
157 new Pair("千代田航改二", "千代田航改")
\r
166 new Pair("千代田航改二", "千代田航改二")
\r
170 TestTruncate(data, ShipNameWidth.RepairListFull);
\r
174 /// メインパネルの艦娘の名前を縮める
\r
177 public void ForMainPanel()
\r
179 var data = new TestData
\r
185 new Pair("Commandant Teste", "Commandant Tes")
\r
192 new Pair("Commandant Teste", "Commandant Test")
\r
196 TestTruncate(data, ShipNameWidth.MainPanel);
\r
200 /// 一覧ウィンドウの艦娘一覧の名前を縮める
\r
203 public void ForShipList()
\r
205 var data = new TestData
\r
211 new Pair("Commandant Teste", "Commandant T"),
\r
212 new Pair("Graf Zeppelin改", "Graf Zeppelin")
\r
220 new Pair("Graf Zeppelin改", "Graf Zeppelin改")
\r
224 TestTruncate(data, ShipNameWidth.ShipList);
\r
227 private static void TestTruncate(TestData data, ShipNameWidth width)
\r
229 foreach (var zoom in data.Keys)
\r
231 SetScaleFactor(zoom);
\r
232 var label = new ShipLabel.Name(Point.Empty, width) {Font = ShipLabel.Name.BaseFont};
\r
233 for (var i = 0; i < data[zoom].Length; i++)
\r
235 var entry = data[zoom][i];
\r
236 if (string.IsNullOrEmpty(entry.Origin))
\r
237 entry = data[100][i];
\r
238 label.SetName(entry.Origin);
\r
239 Assert.AreEqual(entry.Result, label.Text, $"{entry.Origin}: scale {zoom}");
\r
244 private static void SetScaleFactor(int zoom)
\r
246 var form = new Form {AutoScaleMode = AutoScaleMode.Font};
\r
249 Scaler.Factor = new SizeF(1, 1);
\r
250 ShipLabel.Name.BaseFont = form.Font;
\r
251 ShipLabel.Name.LatinFont = LatinFont(100);
\r
254 var prev = form.CurrentAutoScaleDimensions;
\r
255 form.Font = new Font(form.Font.FontFamily, form.Font.Size * zoom / 100);
\r
256 ShipLabel.Name.BaseFont = form.Font;
\r
257 ShipLabel.Name.LatinFont = LatinFont(zoom);
\r
258 var cur = form.CurrentAutoScaleDimensions;
\r
259 Scaler.Factor = new SizeF(cur.Width / prev.Width, cur.Height / prev.Height);
\r
262 private static Font LatinFont(int zoom)
\r
264 return new Font("Tahoma", 8f * zoom / 100);
\r
272 public void SetName()
\r
274 var label = new ShipLabel.Name(Point.Empty, ShipNameWidth.AkashiTimer) {Parent = new Panel()};
\r
275 Scaler.Factor = new SizeF(1, 1);
\r
276 label.Set(new ShipStatus
\r
278 Spec = new ShipSpec {Name = "綾波改二"},
\r
281 PAssert.That(() => label.Text == "[避]綾波改二");
\r
282 label.Set(new ShipStatus
\r
284 Spec = new ShipSpec {Name = "朝潮改二丁"},
\r
287 PAssert.That(() => label.Text == "[避]朝潮改二");
\r
294 public void RoundOffFractionOfPercent()
\r
296 var label = new ShipLabel.Hp {Parent = new Panel()};
\r
297 label.SetHp(104, 105);
\r
298 label.ToggleHpPercent();
\r
299 PAssert.That(() => label.Text == "99%");
\r
307 public void SlotStatus()
\r
309 var ship = new ShipStatus
\r
312 Slot = new[] {new ItemStatus(), new ItemStatus(), new ItemStatus()}, SlotEx = new ItemStatus(0),
\r
313 Spec = new ShipSpec {SlotNum = 3}
\r
315 Assert.AreEqual(2, GetSlotStatus(ship)); // NormalEmpty
\r
316 ship.SlotEx.Id = -1;
\r
317 Assert.AreEqual(2 | 4, GetSlotStatus(ship)); // | ExtraEmpty
\r
318 ship.SlotEx.Id = 1;
\r
319 Assert.AreEqual(2, GetSlotStatus(ship)); // NormalEmpty
\r
320 ship.Slot[0].Id = ship.Slot[1].Id = ship.Slot[2].Id = 1;
\r
321 Assert.AreEqual(0, GetSlotStatus(ship)); // Equipped
\r
322 ship.Slot[2].Id = -1;
\r
323 Assert.AreEqual(1, GetSlotStatus(ship)); // SemiEquipped
\r
324 ship.Spec.SlotNum = 2;
\r
325 Assert.AreEqual(0, GetSlotStatus(ship)); // Equipped
\r
326 ship.Spec.SlotNum = 0;
\r
327 Assert.AreEqual(0, GetSlotStatus(ship)); // Equipped (まるゆ)
\r
330 private static int GetSlotStatus(ShipStatus ship)
\r
333 typeof(ShipLabel.Name).GetMethod("GetSlotStatus", BindingFlags.NonPublic | BindingFlags.Static);
\r
334 // ReSharper disable once PossibleNullReferenceException
\r
335 return (int)Convert.ChangeType(method.Invoke(null, new object[] {ship}), TypeCode.Int32);
\r