public void SettingEnumerator() { var section = new Ini.Section("TestSection"); section.Add(new Ini.Setting() { Name = "Test1", Int = 5 }); section.Add(new Ini.Setting() { Name = "Test2", Int = 72 }); var results = new List <string>(); var resultInts = new List <string>(); foreach (Ini.Setting setting in section) { results.Add(setting.Name); resultInts.Add(setting.Value); } Assert.AreEqual("Test1", results[0]); Assert.AreEqual("5", resultInts[0]); Assert.AreEqual("Test2", results[1]); Assert.AreEqual("72", resultInts[1]); }
public void StoreValue() { try { var section = new Ini.Section("Test"); var key0 = new Ini.Setting { Name = "Key0", Value = "#\"bob\"", Comment = "string" }; Debug.WriteLine(key0.Value); Assert.AreEqual("#\"bob\"", key0.Value); var key1 = new Ini.Setting { Name = "Key1", Comment = "float" }; key1.Set(0.5f); Debug.WriteLine(key1.Value); Assert.AreEqual("0.5", key1.Value); var intarray = new Ini.ExposedSetting { Name = "IntArray", Comment = "ints" }; intarray.SetArray(new[] { 1, 2f, 3 }); Debug.WriteLine(intarray.ExposedEscapedValue); Assert.AreEqual("{ 1, 2, 3 }", intarray.ExposedEscapedValue); var strarray = new Ini.ExposedSetting { Name = "StringArray", Comment = "strings" }; strarray.SetArray(new[] { "abc", "xyz" }); Debug.WriteLine(strarray.ExposedEscapedValue); Assert.AreEqual("{ abc, xyz }", strarray.ExposedEscapedValue); var badarray = new Ini.ExposedSetting { Name = "BadArray", Comment = "bad strings" }; badarray.SetArray(new[] { "a#b#c", "x\"y\"z", "\"doop\"#", "good", " spaced", "#bad", "#\"test\"" }); Debug.WriteLine(badarray.ExposedEscapedValue); Assert.AreEqual("{ \"a#b#c\", \"x\\\"y\\\"z\", \"\\\"doop\\\"#\", good, \" spaced\", \"#bad\", \"#\\\"test\\\"\" }", badarray.ExposedEscapedValue); var quotedArray = new Ini.Setting { Name = "test", Value = "kakka\"bob\"" }; section.Add(key0); section.Add(key1); section.Add(intarray); section.Add(strarray); } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void Initialization() { var config = new Ini.Config(); var section = new Ini.Section("Test"); config.Add(section); section.Add(new Ini.Setting() { Name = "Key" }); // empty value var lines = config.GetLines(); foreach (var line in lines) { Debug.WriteLine(line); } Assert.AreEqual(3, lines.Length); Assert.AreEqual("[Test]\n", lines[0]); Assert.AreEqual(2, config.Changes); }
public void AddIniProperties(Ini.Section sec) { // Save conditions & actions foreach (CaBase cab in m_alsConditions) { if (!(cab is CommentCondition)) { sec.Add(new Ini.Property("C", cab.ToSaveString())); } } foreach (CaBase cab in m_alsActions) { if (!(cab is CommentTriggerAction)) { sec.Add(new Ini.Property("A", cab.ToSaveString())); } } }
public void NameChange() { var config = new Ini.Config(); var section = new Ini.Section("Test"); config.Add(section); var setting = new Ini.Setting() { Name = "Name" }; section.Add(setting); int mods = config.Changes; section.Name = "tseT"; Assert.AreEqual(mods + 1, config.Changes); setting.Name = "emaN"; Assert.AreEqual(mods + 2, config.Changes); }
public void AddIniProperties(Ini.Section sec) { // Save Name sec.Add(new Ini.Property("Name", Name)); // Save Side sec.Add(new Ini.Property("Side", "k" + m_side.ToString())); // Save Aggressiveness sec.Add(new Ini.Property("Aggressiveness", "knAggressiveness" + m_aggr.ToString())); // Save flags sec.Add(new Ini.Property("LoopForever", m_fLoopForever ? "1" : "0")); sec.Add(new Ini.Property("CreateAtLevelLoad", m_fCreateAtLevelLoad ? "1" : "0")); sec.Add(new Ini.Property("RandomGroup", m_fRandomGroup ? "1" : "0")); sec.Add(new Ini.Property("Spawn", m_fSpawn ? "1" : "0")); sec.Add(new Ini.Property("ReplaceGroup", m_fReplaceDestroyedGroup ? "1" : "0")); // Save SpawnArea int nSpawnArea = CaTypeArea.GetArea(m_strSpawnArea); if (nSpawnArea != -1) { sec.Add(new Ini.Property("SpawnArea", nSpawnArea.ToString())); } // Save Health sec.Add(new Ini.Property("Health", Health.ToString())); // Save unit list if (m_alsUnitTypeAndCounts.Count > 0) { // Write total # of units int cTotalUnits = 0; foreach (UnitTypeAndCount utc in m_alsUnitTypeAndCounts) { cTotalUnits += utc.c; } string str = cTotalUnits.ToString(); // Write unit/count pairs foreach (UnitTypeAndCount utc in m_alsUnitTypeAndCounts) { str += "," + utc.ToSaveString(); } sec.Add(new Ini.Property("Units", str)); } // Save actions foreach (CaBase cab in m_alsActions) { if (!(cab is CommentUnitGroupAction)) { sec.Add(new Ini.Property("A", cab.ToSaveString())); } } }
public Ini.Section GetIniSection(bool fDemoCheckTrigger) { // If asked create a trigger causes mission failure if running on // demo version side1 bool fModifiedSave = m_fModified; Trigger tgrDemo = new Trigger(); if (fDemoCheckTrigger) { // condition: persistent variable $demo is exactly 1 // action: end mission: lose // Condition tgrDemo.Sides = SideToMask(Side.side1); TestPvarCondition cdn = new TestPvarCondition(); cdn.Active = true; CaTypeText catText = (CaTypeText)cdn.GetTypes()[0]; catText.Text = "$demo"; CaTypeQualifiedNumber catQualNum = (CaTypeQualifiedNumber)cdn.GetTypes()[1]; catQualNum.Qualifier = Qualifier.Exactly; catQualNum.Value = 1; tgrDemo.Conditions.Add(cdn); // Action EndMissionTriggerAction acn = new EndMissionTriggerAction(); acn.Active = true; CaTypeWinLose catWinLose = (CaTypeWinLose)acn.GetTypes()[0]; catWinLose.Result = WinLoseType.Lose; tgrDemo.Actions.Add(acn); // Add this trigger temporarily // Move it up to first place AddTrigger(tgrDemo); while (MoveUpTrigger(Side.side1, tgrDemo) != -1) { ; } } // Save triggers Ini.Section sec = new Ini.Section("Triggers"); sec.Add(new Ini.Property("Count", m_alsTriggers.Count.ToString())); foreach (Trigger tgr in m_alsTriggers) { // Calc per side indexes string strT = ""; for (int n = 0; n < m_aalsSideTriggers.Length; n++) { ArrayList als = (ArrayList)m_aalsSideTriggers[n]; int j = als.IndexOf(tgr); if (j != -1) { if (strT != "") { strT += ","; } string strType = "k" + ((Side)n).ToString(); strT += strType + ":" + j.ToString(); } } sec.Add(new Ini.Property("T", strT)); // Save trigger contents tgr.AddIniProperties(sec); } // Restore order if (fDemoCheckTrigger) { m_fModified = fModifiedSave; RemoveTrigger(tgrDemo); } return(sec); }
public void RecursiveSaveAndLoad(int repeats) { if (repeats < 2) { repeats = 2; } if (repeats > 30) { repeats = 30; } var config = new Ini.Config(); var section1Name = "Number Tests"; var section2Name = "String Tests"; var section1Var1Name = "IntArray"; var section1Var2Name = "DoubleValue"; var section2Var1Name = "StringArray"; var section2Var2Name = "String"; var s1var1value = new int[] { 1, 2, 3 }; var s1var1valueEscaped = "{ 1, 2, 3 }"; var s1var2value = 0.5d; var s1var2valueFormatted = "0.5"; var s2var1value = new string[] { "abc", "xyz" }; var s2var1valueEscaped = "{ abc, xyz }"; var s2var2value = "Bad\"#"; var s2var2valueEscaped = "\"Bad\\\"#\""; var section1 = new Ini.Section(section1Name); section1.Add(new Ini.Setting() { Name = section1Var1Name, IntArray = s1var1value }); section1.Add(new Ini.Setting() { Name = section1Var2Name, Double = s1var2value }); config.Add(section1); var section2 = new Ini.Section(section2Name); section2.Add(new Ini.Setting() { Name = section2Var1Name, Array = s2var1value }); section2.Add(new Ini.Setting() { Name = section2Var2Name, Value = s2var2value }); config.Add(section2); const string incrName = "Incrementor"; const string rollName = "Roller"; var section3 = new Section(incrName); section3.Add(new Setting() { Name = rollName, Int = 0 }); config.Add(section3); var data = config.GetLines(); for (int i = 0; i < repeats; i++) { config = Ini.Config.FromData(data); // read written config Assert.AreEqual(3, config.ItemCount); var s1 = config.Get(section1Name); var s2 = config.Get(section2Name); Assert.IsNotNull(s1); Assert.IsNotNull(s2); var s1v1 = s1.Get(section1Var1Name); var s1v2 = s1.Get(section1Var2Name); var s2v1 = s2.Get(section2Var1Name); var s2v2 = s2.Get(section2Var2Name); Assert.IsNotNull(s1v1); Assert.IsNotNull(s1v2); Assert.IsNotNull(s2v1); Assert.IsNotNull(s2v2); Assert.AreEqual(s1var1valueEscaped, new ExposedSetting(s1v1).ExposedEscapedValue); Assert.AreEqual(s1var2valueFormatted, s1v2.Value); Assert.AreEqual(s2var1valueEscaped, new ExposedSetting(s2v1).ExposedEscapedValue); Assert.AreEqual(s2var2valueEscaped, new ExposedSetting(s2v2).ExposedEscapedValue); int num = config[incrName][rollName].Int; Assert.AreEqual(i, num); config[incrName][rollName].Int = num + 1; data = config.GetLines(); // re-write config } }