public void writeGenericChecked()
        {
            string    path = tmpFile("write.generic.checked");
            SkillFile sf   = SkillFile.open(path);

            reflectiveInit(sf);
            // write file
            sf.flush();

            // create a name -> type map
            Dictionary <string, IAccess> types = new Dictionary <string, IAccess>();

            foreach (IAccess t in sf.allTypes())
            {
                types[t.Name] = t;
            }

            // read file and check skill IDs
            SkillFile sf2 = SkillFile.open(path, Mode.Read);

            foreach (IAccess t in sf2.allTypes())
            {
                IEnumerator os = types[t.Name].GetEnumerator();
                foreach (SkillObject o in t)
                {
                    Assert.IsTrue(os.MoveNext(), "to few instances in read state");
                    Assert.AreEqual(o.SkillID, ((SkillObject)os.Current).SkillID);
                }
                Assert.IsFalse(os.MoveNext(), "to many instances in read state");
            }
            File.Delete(path);
        }
        public void writeGeneric()
        {
            string    path = tmpFile("write.generic");
            SkillFile sf   = SkillFile.open(path);

            reflectiveInit(sf);
            sf.close();
            File.Delete(path);
        }
Beispiel #3
0
        public void APITest_restrictions_enums_fail_instances()
        {
            string path = tmpFile("instances");

            try
            {
                SkillFile sf = SkillFile.open(path, Mode.Create, Mode.Write);

                // create objects
                enums.TestEnum enm_last    = (enums.TestEnum)sf.TestEnums().make();
                enums.TestEnum enm_second  = (enums.TestEnum)sf.TestEnums().make();
                enums.TestEnum enm_third   = (enums.TestEnum)sf.TestEnums().make();
                enums.TestEnum enm_default = (enums.TestEnum)sf.TestEnums().make();
                // set fields
                enm_last.next = (TestEnum)enm_default;
                enm_last.name = (string)"last";

                enm_second.next = (TestEnum)enm_third;
                enm_second.name = (string)"second";

                enm_third.next = (TestEnum)enm_last;
                enm_third.name = (string)"third";

                enm_default.next = (TestEnum)enm_second;
                enm_default.name = (string)"default";
                sf.close();

                { // read back and assert correctness
                    SkillFile sf2 = SkillFile.open(sf.currentPath(), Mode.Read, Mode.ReadOnly);
                    // check count per Type
                    Assert.AreEqual(4, sf.TestEnums().staticSize());
                    // create objects from file
                    enums.TestEnum enm_last_2    = (enums.TestEnum)sf2.TestEnums().getByID(enm_last.SkillID);
                    enums.TestEnum enm_second_2  = (enums.TestEnum)sf2.TestEnums().getByID(enm_second.SkillID);
                    enums.TestEnum enm_third_2   = (enums.TestEnum)sf2.TestEnums().getByID(enm_third.SkillID);
                    enums.TestEnum enm_default_2 = (enums.TestEnum)sf2.TestEnums().getByID(enm_default.SkillID);
                    // assert fields
                    Assert.IsTrue(enm_last_2.next == enm_default_2);

                    Assert.IsTrue(enm_second_2.next == enm_third_2);

                    Assert.IsTrue(enm_third_2.next == enm_last_2);

                    Assert.IsTrue(enm_default_2.next == enm_second_2);
                }
            }
            catch (SkillException)
            {
                return;
            }
            File.Delete(path);
        }
 public SkillFile read(string s)
 {
     return(SkillFile.open(basePath + s, Mode.Read, Mode.ReadOnly));
 }