Пример #1
0
        public void TestCorrectConfig()
        {
            ConfigLoader cl = new ConfigLoader();
            cl.ParseConfig(StringToStreamReader(@"
            [section1]
            hoge = fuga
            asdf =aassddff
            [section2]
            hoge = fuga asdf

            [section3]
            hoge=fuga ahoaho

            [section4]
            h = fuga
            ho = fuga
            hog = fuga
            hoge = fuga   "));

            // セクションの取得
            List<string> sections = cl.GetSections();
            Assert.AreEqual(4, sections.Count);

            // note : 順序は保証されない
            Assert.AreEqual(true, sections.Exists(delegate(string s) { return s == "section1"; }));
            Assert.AreEqual(true, sections.Exists(delegate(string s) { return s == "section2"; }));
            Assert.AreEqual(true, sections.Exists(delegate(string s) { return s == "section3"; }));
            Assert.AreEqual(true, sections.Exists(delegate(string s) { return s == "section4"; }));
            Assert.AreEqual(false, sections.Exists(delegate(string s) { return s == "section5"; }));
            Assert.AreEqual(false, sections.Exists(delegate(string s) { return s == "section"; }));
            Assert.AreEqual(false, sections.Exists(delegate(string s) { return s == ""; }));

            // セクションから項目取得
            {
                Hashtable conf = cl.GetConfig("section1");
                Assert.AreEqual(2, conf.Count);
                Assert.AreEqual("fuga", (string)conf["hoge"]);
                Assert.AreEqual("aassddff", (string)conf["asdf"]);
            }
            {
                Hashtable conf = cl.GetConfig("section2");
                Assert.AreEqual(1, conf.Count);
                Assert.AreEqual("fuga asdf", (string)conf["hoge"]);
            }
            {
                Hashtable conf = cl.GetConfig("section3");
                Assert.AreEqual(1, conf.Count);
                Assert.AreEqual("fuga ahoaho", (string)conf["hoge"]);
            }
            {
                Hashtable conf = cl.GetConfig("section4");
                Assert.AreEqual(4, conf.Count);
                Assert.AreEqual("fuga", (string)conf["h"]);
                Assert.AreEqual("fuga", (string)conf["ho"]);
                Assert.AreEqual("fuga", (string)conf["hog"]);
                Assert.AreEqual("fuga", (string)conf["hoge"]);
            }
        }
Пример #2
0
        void InitializeByConfigFile(string filename)
        {
            m_ConfigFileName = filename;
            m_CommandManager.ClearCommands();

            ConfigLoader conf = new ConfigLoader();

            conf.LoadConfigFile(filename);
            List <string> sections = conf.GetSections();

            foreach (string section in sections)
            {
                Hashtable hashtable = conf.GetConfig(section);
                Command   cmd       = new Command();
                cmd.command   = section;
                cmd.execution = (string)hashtable["linkto"];
                if (cmd.execution == null)
                {
                    throw new MainWindowNotExistsLinkToException();
                }
                m_CommandManager.RegisterCommand(cmd);
            }
        }
Пример #3
0
        void TestLoadingMulticonfig()
        {
            ConfigLoader cl = new ConfigLoader();

            cl.ParseConfig(StringToStreamReader(@"
            [section1]
            hoge = fuga
            asdf =aassddff
            [section2]
            hoge = fuga asdf

            [section3]
            hoge=fuga ahoaho

            [section4]
            h = fuga
            ho = fuga
            hog = fuga
            hoge = fuga

            "));
            cl.ParseConfig(StringToStreamReader(@"
            [addedsection]
            hoku = hoku
            poka = poka

            "));

            // セクションの取得
            List<string> sections = cl.GetSections();
            Assert.AreEqual(5, sections.Count);

            Assert.AreEqual(true, sections.Exists(delegate(string s) { return s == "section1"; }));
            Assert.AreEqual(true, sections.Exists(delegate(string s) { return s == "section2"; }));
            Assert.AreEqual(true, sections.Exists(delegate(string s) { return s == "section3"; }));
            Assert.AreEqual(true, sections.Exists(delegate(string s) { return s == "section4"; }));
            Assert.AreEqual(true, sections.Exists(delegate(string s) { return s == "addedsection"; }));
            Assert.AreEqual(false, sections.Exists(delegate(string s) { return s == "section5"; }));
            Assert.AreEqual(false, sections.Exists(delegate(string s) { return s == "section"; }));
            Assert.AreEqual(false, sections.Exists(delegate(string s) { return s == ""; }));

            // セクションから項目取得
            {
                Hashtable conf = cl.GetConfig("section1");
                Assert.AreEqual(2, conf.Count);
                Assert.AreEqual("fuga", (string)conf["hoge"]);
                Assert.AreEqual("aassddff", (string)conf["asdf"]);
            }
            {
                Hashtable conf = cl.GetConfig("addedsection");
                Assert.AreEqual(2, conf.Count);
                Assert.AreEqual("hoku", (string)conf["hoku"]);
                Assert.AreEqual("poka", (string)conf["poka"]);
            }
        }
Пример #4
0
        public void TestIncorrectConfig()
        {
            {
                ConfigLoader cl = new ConfigLoader();

                bool catched = false;
                try
                {
                    cl.ParseConfig(StringToStreamReader(@"
            hoge = fuga

            [section]
            foo = bar

             "));
                }
                catch (ConfigLoaderNotExistsSectionException)
                {
                    catched = true;
                }
                finally
                {
                    Assert.AreEqual(true, catched);
                }
            }
            {
                ConfigLoader cl = new ConfigLoader();

                bool catched = false;
                try
                {
                    cl.ParseConfig(StringToStreamReader(@"
            [section]
            hoge = fuga
            hoge = aho

            "));
                }
                catch (ConfigLoaderMultiKeyException)
                {
                    catched = true;
                }
                finally
                {
                    Assert.AreEqual(true, catched);
                }
            }
            {
                ConfigLoader cl = new ConfigLoader();

                bool catched = false;
                try
                {
                    cl.ParseConfig(StringToStreamReader(@"
            [section1]
            hoge

            [section2]
            foo = bar

            "));
                }
                catch (ConfigLoaderNotKeyValueException)
                {
                    catched = true;
                }
                finally
                {
                    Assert.AreEqual(true, catched);
                }
            }
            {
                ConfigLoader cl = new ConfigLoader();

                bool catched = false;
                try
                {
                    cl.ParseConfig(StringToStreamReader(@"
            [section]
            hoge = fuga

            [section]
            foo = bar

            "));
                }
                catch (ConfigLoaderSameSectionException)
                {
                    catched = true;
                }
                finally
                {
                    Assert.AreEqual(true, catched);
                }
            }
        }
Пример #5
0
        void InitializeByConfigFile(string filename)
        {
            m_ConfigFileName = filename;
            m_CommandManager.ClearCommands();

            ConfigLoader conf = new ConfigLoader();
            conf.LoadConfigFile(filename);
            List<string> sections = conf.GetSections();
            foreach (string section in sections)
            {
                Hashtable hashtable = conf.GetConfig(section);
                Command cmd = new Command();
                cmd.command = section;
                cmd.execution = (string)hashtable["linkto"];
                if (cmd.execution == null)
                    throw new MainWindowNotExistsLinkToException();
                m_CommandManager.RegisterCommand(cmd);
            }
        }