1 // Copyright (C) 2014, 2015 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
18 using ExpressionToCodeLib;
\r
19 using Microsoft.VisualStudio.TestTools.UnitTesting;
\r
22 namespace KancolleSniffer.Test
\r
25 public class LoggerTest
\r
28 public void InspectMissionResult()
\r
30 var sniffer = new Sniffer();
\r
33 sniffer.SetLogWriter((path, s, h) =>
\r
37 }, () => new DateTime(2015, 1, 1));
\r
38 sniffer.SkipMaster();
\r
39 sniffer.EnableLog(LogType.Mission);
\r
40 SnifferTest.SniffLogFile(sniffer, "mission_result_001");
\r
41 PAssert.That(() => "日付,結果,遠征,燃料,弾薬,鋼材,ボーキ,開発資材,高速修復材,高速建造材" == header);
\r
42 PAssert.That(() => "2015-01-01 00:00:00,成功,長距離練習航海,0,100,30,0,0,0,0|" +
\r
43 "2015-01-01 00:00:00,成功,長距離練習航海,0,100,30,0,0,1,0|" +
\r
44 "2015-01-01 00:00:00,大成功,MO作戦,0,0,360,420,1,0,0|" +
\r
45 "2015-01-01 00:00:00,失敗,東京急行(弐),0,0,0,0,0,0,0|"
\r
50 /// 出力先に書けないときは一時ファイルに書き込む
\r
53 public void WriteTmpFileWhenCantWriteTarget()
\r
55 var mock = new Mock<LogWriter.IFile>();
\r
56 var writer = new LogWriter(null, mock.Object);
\r
58 const string str = "2015-01-01 00:00:00,成功,長距離練習航海,0,100,30,0,0,0,0";
\r
60 mock.Setup(l => l.AppendAllText(It.IsAny<string>(), It.IsAny<string>()))
\r
61 .Callback<string, string>((file, s) =>
\r
63 if (file.EndsWith(".csv"))
\r
64 throw new IOException();
\r
65 if (file.EndsWith(".tmp"))
\r
68 mock.SetupSequence(l => l.Exists(It.IsAny<string>())).Returns(false).Returns(true);
\r
69 writer.Write("遠征報告書", str, "");
\r
70 PAssert.That(() => "2015-01-01 00:00:00,成功,長距離練習航海,0,100,30,0,0,0,0\r\n" == tmp);
\r
74 public void MergeTmpFile()
\r
76 MergeTmpFileMain(false);
\r
80 public void FaileToMergeTmpFile()
\r
82 MergeTmpFileMain(true);
\r
85 private void MergeTmpFileMain(bool failToMerge)
\r
87 var mock = new Mock<LogWriter.IFile>();
\r
88 var writer = new LogWriter(null, mock.Object);
\r
90 var tmp = "2015-01-01 00:00:00,成功,長距離練習航海,0,100,30,0,0,0,0\r\n";
\r
92 mock.Setup(l => l.Exists(It.IsAny<string>())).Returns(true);
\r
93 mock.Setup(l => l.ReadAllText(It.IsAny<string>()))
\r
94 .Returns((string path) => path.EndsWith(".tmp") ? tmp : "");
\r
95 mock.Setup(l => l.AppendAllText(It.IsAny<string>(), It.IsAny<string>()))
\r
96 .Callback<string, string>((file, s) =>
\r
98 if (file.EndsWith(".tmp"))
\r
100 if (file.EndsWith(".csv"))
\r
103 throw new IOException();
\r
107 const string str = "2015-01-01 00:00:00,成功,長距離練習航海,0,100,30,0,0,1,0";
\r
108 writer.Write("遠征報告書", str, "");
\r
109 var result = failToMerge ? tmp : csv;
\r
111 "2015-01-01 00:00:00,成功,長距離練習航海,0,100,30,0,0,0,0\r\n" +
\r
112 "2015-01-01 00:00:00,成功,長距離練習航海,0,100,30,0,0,1,0\r\n" == result);
\r
116 public void InspectBattleResult()
\r
118 var sniffer = new Sniffer();
\r
120 sniffer.SetLogWriter((path, s, h) => { result += s + "|"; }, () => new DateTime(2017, 1, 1));
\r
121 sniffer.EnableLog(LogType.Battle);
\r
122 SnifferTest.SniffLogFile(sniffer, "battle_001");
\r
124 "2017-01-01 00:00:00,カレー洋制圧戦,1,出撃,A,T字戦(有利),警戒陣,梯形陣,敵潜水教導艦隊,,," +
\r
125 "隼鷹改二(Lv157),57/62,利根改二(Lv151),66/66,千代田航改二(Lv159),50/65,千歳航改二(Lv159),65/65,大井改二(Lv57),40/43,秋月改(Lv142),42/42," +
\r
126 "潜水ヨ級(elite),34/34,潜水ヨ級,5/24,潜水ヨ級,0/24,潜水カ級(elite),0/27,潜水カ級,0/19,潜水カ級,0/19,248~249,0,制空権確保|"
\r
131 /// 7隻編成の場合は7隻目を6隻目に重ねる
\r
134 public void InspectShip7BattleResult()
\r
136 var sniffer = new Sniffer();
\r
138 sniffer.SetLogWriter((path, s, h) => { result += s + "|"; }, () => new DateTime(2017, 1, 1));
\r
139 sniffer.EnableLog(LogType.Battle);
\r
140 SnifferTest.SniffLogFile(sniffer, "ship7battle_001");
\r
142 "2017-01-01 00:00:00,台湾沖/ルソン島沖,5,出撃,S,同航戦,単縦陣,単縦陣,深海通商破部隊 前衛水雷戦隊,,," +
\r
143 "あきつ丸改(Lv81),40/40,那智改二(Lv151),63/63,Roma改(Lv99),83/92,阿武隈改二(Lv98),40/45,霞改二(Lv96),13/31,潮改二(Lv94)・不知火改(Lv85),31/33・32/32," +
\r
144 "軽巡ホ級(flagship),0/53,駆逐ロ級後期型,0/37,駆逐ロ級後期型,0/37,駆逐ロ級後期型,0/37,駆逐イ級,0/20,駆逐イ級,0/20,317~318,0,制空権確保|"
\r
149 public void InspectMaterial()
\r
151 var sniffer = new Sniffer();
\r
153 var first = new DateTime(2015, 1, 1, 0, 0, 0);
\r
155 new Queue<DateTime>(new[] {first, first.AddMinutes(10), first.AddMinutes(15), first.AddMinutes(20)});
\r
156 sniffer.SetLogWriter((path, s, h) => { result += s + "|"; }, queue.Dequeue);
\r
157 sniffer.EnableLog(LogType.Material);
\r
158 SnifferTest.SniffLogFile(sniffer, "material_001");
\r
159 PAssert.That(() => "2015-01-01 00:00:00,26178,26742,21196,33750,1426,1574,2185,10|" +
\r
160 "2015-01-01 00:10:00,24595,25353,18900,32025,1427,1576,2187,10|" +
\r
161 "2015-01-01 00:20:00,23463,25064,17314,31765,1427,1572,2187,10|"
\r
166 public void InspectCreateItem()
\r
168 var sniffer = new Sniffer();
\r
170 sniffer.SetLogWriter((path, s, h) => { result += s + "|"; }, () => new DateTime(2015, 1, 1));
\r
171 sniffer.EnableLog(LogType.CreateItem);
\r
172 SnifferTest.SniffLogFile(sniffer, "createitem_001");
\r
173 PAssert.That(() => "2015-01-01 00:00:00,12cm単装砲,小口径主砲,10,10,30,10,綾波改二(145),120|" +
\r
174 "2015-01-01 00:00:00,失敗,,10,10,30,10,綾波改二(145),120|"
\r
179 public void InspectGetShip()
\r
181 var sniffer = new Sniffer();
\r
183 sniffer.SetLogWriter((path, s, h) => { result += s + "|"; }, () => new DateTime(2015, 1, 1));
\r
184 sniffer.EnableLog(LogType.CreateShip);
\r
185 SnifferTest.SniffLogFile(sniffer, "createship_001");
\r
186 PAssert.That(() => "2015-01-01 00:00:00,通常艦建造,雷,駆逐艦,30,30,30,30,1,1,綾波改二(145),120|" +
\r
187 "2015-01-01 00:00:00,大型艦建造,霧島,巡洋戦艦,1500,1500,2000,1000,1,0,綾波改二(145),120|"
\r
192 public void InspectRemodelSlot()
\r
194 var sniffer = new Sniffer();
\r
196 sniffer.SetLogWriter((path, s, h) => { result += s + "|"; }, () => new DateTime(2015, 1, 1));
\r
197 sniffer.EnableLog(LogType.RemodelSlot);
\r
198 SnifferTest.SniffLogFile(sniffer, "remodel_slot_001");
\r
199 PAssert.That(() => "2015-01-01 00:00:00,12.7cm連装砲,4,○,,,,10,30,60,0,1,1,明石改(50),島風改(131)|" +
\r
200 "2015-01-01 00:00:00,12.7cm連装砲,5,×,,,,10,30,60,0,1,1,明石改(50),|" +
\r
201 "2015-01-01 00:00:00,12.7cm連装砲,7,○,,12.7cm連装砲,1,10,30,60,0,1,1,明石改(50),島風改(131)|" +
\r
202 "2015-01-01 00:00:00,91式高射装置,10,○,○,10cm連装高角砲,2,0,0,60,40,9,7,明石改(50),摩耶改(98)|"
\r
207 public void Achievement()
\r
209 var logger = new Logger(null, null, null);
\r
210 logger.EnableLog(LogType.Achivement);
\r
212 var dateEnum = new[]
\r
214 new DateTime(2017, 3, 31, 21, 0, 0),
\r
215 new DateTime(2017, 3, 31, 22, 0, 0),
\r
216 new DateTime(2017, 4, 1, 1, 0, 0),
\r
217 new DateTime(2017, 4, 1, 2, 0, 0),
\r
218 new DateTime(2017, 4, 1, 3, 0, 0),
\r
219 new DateTime(2017, 4, 2, 2, 0, 0),
\r
220 new DateTime(2017, 4, 2, 3, 0, 0),
\r
221 new DateTime(2017, 4, 2, 4, 0, 0)
\r
223 logger.SetWriter((path, s, h) => { result += s + "|"; }, () =>
\r
225 dateEnum.MoveNext();
\r
226 // ReSharper disable once PossibleNullReferenceException
\r
227 return (DateTime)dateEnum.Current;
\r
229 for (var i = 0; i < 6; i++)
\r
230 logger.InspectBasic(JsonParser.Parse($"{{\"api_experience\": {i * 1000}}}"));
\r
231 logger.InspectBattleResult(JsonParser.Parse("{\"api_get_exmap_rate\": \"100\"}"));
\r
232 logger.InspectMapNext(JsonParser.Parse("{\"api_get_eo_rate\": 75}"));
\r
234 "2017-03-31 21:00:00,0,0|2017-03-31 21:00:00,0,0|2017-03-31 22:00:00,1000,0|" +
\r
235 "2017-04-01 03:00:00,4000,0|2017-04-02 02:00:00,5000,0|" +
\r
236 "2017-04-02 03:00:00,5000,100|2017-04-02 04:00:00,5000,75|"
\r
241 public void InspectClearItemGet()
\r
243 var sniffer = new Sniffer();
\r
245 sniffer.SetLogWriter((path, s, h) => { result += s + "|"; }, () => new DateTime(2017, 5, 1));
\r
246 sniffer.EnableLog(LogType.Achivement);
\r
247 SnifferTest.SniffLogFile(sniffer, "clearitemget_001");
\r
249 "2017-05-01 00:00:00,45417045,0|2017-05-01 00:00:00,45417045,350|" == result);
\r
253 /// 晴嵐(六三一空)任務の場合はapi_bounus_countがない
\r
256 public void InspectClearItemGetSeiran631Ku()
\r
258 var sniffer = new Sniffer(true);
\r
259 sniffer.SetLogWriter((path, s, h) => { }, () => new DateTime(2017, 5, 1));
\r
260 sniffer.EnableLog(LogType.Achivement);
\r
261 sniffer.Sniff("/kcsapi/api_req_quest/clearitemget",
\r
262 "api%5Fquest%5Fid=656&api%5Fverno=1",
\r
264 @"{""api_result"":1,""api_result_msg"":""成功"",""api_data"":
\r
265 {""api_material"":[0,0,0,0],""api_bounus"":[
\r
266 {""api_type"":15,""api_count"":1,""api_item"":{""api_id_from"":9999,""api_id_to"":9999,
\r
267 ""api_message"":""第一潜水隊運用航空隊:「晴嵐(六三一空)」の新編成を<br>完了しました!""}}
\r