Commit 7afdb8f4 authored by nanahira's avatar nanahira

add test methods

parent 1b31d771
...@@ -34,11 +34,13 @@ public static class GameStringManager ...@@ -34,11 +34,13 @@ public static class GameStringManager
return return_value; return return_value;
} }
public static void initialize(string path) public static bool initialize(string path, bool test = false)
{ {
string text = System.IO.File.ReadAllText(path); string text = System.IO.File.ReadAllText(path);
string st = text.Replace("\r", ""); string st = text.Replace("\r", "");
string[] lines = st.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); string[] lines = st.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
bool success = true;
bool found = false;
foreach (string line in lines) foreach (string line in lines)
{ {
if (line.Length > 1 && line.Substring(0, 1) == "!") if (line.Length > 1 && line.Substring(0, 1) == "!")
...@@ -46,6 +48,7 @@ public static class GameStringManager ...@@ -46,6 +48,7 @@ public static class GameStringManager
string[] mats = line.Substring(1, line.Length - 1).Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); string[] mats = line.Substring(1, line.Length - 1).Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
if (mats.Length > 2) if (mats.Length > 2)
{ {
found = true;
hashedString a = new hashedString(); hashedString a = new hashedString();
a.region = mats[0]; a.region = mats[0];
try try
...@@ -54,6 +57,7 @@ public static class GameStringManager ...@@ -54,6 +57,7 @@ public static class GameStringManager
} }
catch (Exception e) catch (Exception e)
{ {
success = false;
Program.DEBUGLOG(e); Program.DEBUGLOG(e);
} }
a.content = ""; a.content = "";
...@@ -62,14 +66,17 @@ public static class GameStringManager ...@@ -62,14 +66,17 @@ public static class GameStringManager
a.content += mats[i] + " "; a.content += mats[i] + " ";
} }
a.content = a.content.Substring(0, a.content.Length - 1); a.content = a.content.Substring(0, a.content.Length - 1);
hashedStrings.Add(a); if(!test) {
if (a.region == "setname") hashedStrings.Add(a);
{ if (a.region == "setname")
xilies.Add(a); {
xilies.Add(a);
}
} }
} }
} }
} }
return (success && found);
} }
public static string get(string region, int hashCode) public static string get(string region, int hashCode)
...@@ -148,4 +155,3 @@ public static class GameStringManager ...@@ -148,4 +155,3 @@ public static class GameStringManager
return formatLocation(gps.location, gps.sequence); return formatLocation(gps.location, gps.sequence);
} }
} }
...@@ -7,11 +7,12 @@ namespace YGOSharp ...@@ -7,11 +7,12 @@ namespace YGOSharp
{ {
public static List<Banlist> Banlists { get; private set; } public static List<Banlist> Banlists { get; private set; }
public static void initialize(string fileName) public static bool initialize(string fileName, bool test = false)
{ {
Banlists = new List<Banlist>(); List<Banlist> new_list = new List<Banlist>();
Banlist current = null; Banlist current = null;
StreamReader reader = new StreamReader(fileName); StreamReader reader = new StreamReader(fileName);
bool success = true;
while (!reader.EndOfStream) while (!reader.EndOfStream)
{ {
string line = reader.ReadLine(); string line = reader.ReadLine();
...@@ -25,7 +26,7 @@ namespace YGOSharp ...@@ -25,7 +26,7 @@ namespace YGOSharp
{ {
current = new Banlist(); current = new Banlist();
current.Name = line.Substring(1, line.Length - 1); current.Name = line.Substring(1, line.Length - 1);
Banlists.Add(current); new_list.Add(current);
continue; continue;
} }
if (!line.Contains(" ")) if (!line.Contains(" "))
...@@ -39,13 +40,18 @@ namespace YGOSharp ...@@ -39,13 +40,18 @@ namespace YGOSharp
} }
catch (System.Exception e) catch (System.Exception e)
{ {
success = false;
UnityEngine.Debug.Log(line); UnityEngine.Debug.Log(line);
UnityEngine.Debug.Log(e); UnityEngine.Debug.Log(e);
} }
} }
current = new Banlist(); current = new Banlist();
current.Name ="N/A"; current.Name ="N/A";
Banlists.Add(current); new_list.Add(current);
if(!test) {
Banlists = new_list;
}
return (success && new_list.Count > 1);
} }
public static int GetIndex(uint hash) public static int GetIndex(uint hash)
...@@ -101,4 +107,4 @@ namespace YGOSharp ...@@ -101,4 +107,4 @@ namespace YGOSharp
} }
} }
} }
\ No newline at end of file
...@@ -16,17 +16,19 @@ namespace YGOSharp ...@@ -16,17 +16,19 @@ namespace YGOSharp
public static string nullString = ""; public static string nullString = "";
internal static bool initialize(string databaseFullPath) internal static bool initialize(string databaseFullPath, bool test = false)
{ {
nullName = InterString.Get("未知卡片"); if(!test) {
nullString = ""; nullName = InterString.Get("未知卡片");
nullString += "欢迎使用 KoishiPro2 iOS,本软件免责声明:[url=http://koishi.222diy.gdn/lab.html][u]http://koishi.222diy.gdn/lab.html[/u][/url]"; nullString = "";
nullString += "\r\n\r\n"; nullString += "欢迎使用 KoishiPro2 iOS,本软件免责声明:[url=http://koishi.222diy.gdn/lab.html][u]http://koishi.222diy.gdn/lab.html[/u][/url]";
nullString += "KoishiPro2 iOS的用户QQ群627975038,游戏中遇到任何bug欢迎提交"; nullString += "\r\n\r\n";
nullString += "\r\n\r\n"; nullString += "KoishiPro2 iOS的用户QQ群627975038,游戏中遇到任何bug欢迎提交";
nullString += "更多关于电脑/安卓版KoishiPro及7210服务器的信息可加QQ群338443272"; nullString += "\r\n\r\n";
nullString += "\r\n\r\n"; nullString += "更多关于电脑/安卓版KoishiPro及7210服务器的信息可加QQ群338443272";
nullString += "喜欢游戏王DIY的朋友欢迎来222服QQ群642043095"; nullString += "\r\n\r\n";
nullString += "喜欢游戏王DIY的朋友欢迎来222服QQ群642043095";
}
bool success = true; bool success = true;
try { try {
using (SqliteConnection connection = new SqliteConnection("Data Source=" + databaseFullPath)) using (SqliteConnection connection = new SqliteConnection("Data Source=" + databaseFullPath))
...@@ -39,7 +41,7 @@ namespace YGOSharp ...@@ -39,7 +41,7 @@ namespace YGOSharp
{ {
while (reader.Read()) while (reader.Read())
{ {
LoadCard(reader); LoadCard(reader, test);
} }
} }
} }
...@@ -86,10 +88,10 @@ namespace YGOSharp ...@@ -86,10 +88,10 @@ namespace YGOSharp
return returnValue; return returnValue;
} }
private static void LoadCard(IDataRecord reader) private static void LoadCard(IDataRecord reader, bool test = false)
{ {
Card card = new Card(reader); Card card = new Card(reader);
if (!_cards.ContainsKey(card.Id)) if (!_cards.ContainsKey(card.Id) && !test)
{ {
_cards.Add(card.Id, card); _cards.Add(card.Id, card);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment