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);
\r
233 label.Font = ShipLabel.Name.BaseFont;
\r
234 for (var i = 0; i < data[zoom].Length; i++)
\r
236 var entry = data[zoom][i];
\r
237 if (string.IsNullOrEmpty(entry.Origin))
\r
238 entry = data[100][i];
\r
239 label.SetName(entry.Origin);
\r
240 Assert.AreEqual(entry.Result, label.Text, $"{entry.Origin}: scale {zoom}");
\r
245 private static void SetScaleFactor(int zoom)
\r
247 var form = new Form {AutoScaleMode = AutoScaleMode.Font};
\r
250 Scaler.Factor = new SizeF(1, 1);
\r
251 ShipLabel.Name.BaseFont = form.Font;
\r
252 ShipLabel.Name.LatinFont = LatinFont(100);
\r
255 var prev = form.CurrentAutoScaleDimensions;
\r
256 form.Font = new Font(form.Font.FontFamily, form.Font.Size * zoom / 100);
\r
257 ShipLabel.Name.BaseFont = form.Font;
\r
258 ShipLabel.Name.LatinFont = LatinFont(zoom);
\r
259 var cur = form.CurrentAutoScaleDimensions;
\r
260 Scaler.Factor = new SizeF(cur.Width / prev.Width, cur.Height / prev.Height);
\r
263 private static Font LatinFont(int zoom)
\r
265 return new Font("Tahoma", 8f * zoom / 100);
\r
273 public void SetName()
\r
275 var label = new ShipLabel.Name(Point.Empty, ShipNameWidth.AkashiTimer) {Parent = new Panel()};
\r
276 Scaler.Factor = new SizeF(1, 1);
\r
277 label.Set(new ShipStatus
\r
279 Spec = new ShipSpec {Name = "綾波改二"},
\r
282 PAssert.That(() => label.Text == "[避]綾波改二");
\r
283 label.Set(new ShipStatus
\r
285 Spec = new ShipSpec {Name = "朝潮改二丁"},
\r
288 PAssert.That(() => label.Text == "[避]朝潮改二");
\r
295 public void RoundOffFractionOfPercent()
\r
297 var label = new ShipLabel.Hp {Parent = new Panel()};
\r
298 label.SetHp(104, 105);
\r
299 label.ToggleHpPercent();
\r
300 PAssert.That(() => label.Text == "99%");
\r
308 public void SlotStatus()
\r
310 var ship = new ShipStatus
\r
313 Slot = new[] {new ItemStatus(), new ItemStatus(), new ItemStatus()}, SlotEx = new ItemStatus(0),
\r
314 Spec = new ShipSpec {SlotNum = 3}
\r
316 Assert.AreEqual(2, GetSlotStatus(ship)); // NormalEmpty
\r
317 ship.SlotEx.Id = -1;
\r
318 Assert.AreEqual(2 | 4, GetSlotStatus(ship)); // | ExtraEmpty
\r
319 ship.SlotEx.Id = 1;
\r
320 Assert.AreEqual(2, GetSlotStatus(ship)); // NormalEmpty
\r
321 ship.Slot[0].Id = ship.Slot[1].Id = ship.Slot[2].Id = 1;
\r
322 Assert.AreEqual(0, GetSlotStatus(ship)); // Equipped
\r
323 ship.Slot[2].Id = -1;
\r
324 Assert.AreEqual(1, GetSlotStatus(ship)); // SemiEquipped
\r
325 ship.Spec.SlotNum = 2;
\r
326 Assert.AreEqual(0, GetSlotStatus(ship)); // Equipped
\r
327 ship.Spec.SlotNum = 0;
\r
328 Assert.AreEqual(0, GetSlotStatus(ship)); // Equipped (まるゆ)
\r
331 private static int GetSlotStatus(ShipStatus ship)
\r
334 typeof(ShipLabel.Name).GetMethod("GetSlotStatus", BindingFlags.NonPublic | BindingFlags.Static);
\r
335 // ReSharper disable once PossibleNullReferenceException
\r
336 return (int)Convert.ChangeType(method.Invoke(null, new object[] {ship}), TypeCode.Int32);
\r