Пример #1
0
        public void PrivateメンバのimportDatとexportDatの整合性を確認する()
        {
            //const bool isJp = true;

            var list = new ListVal();
            list.Add(new OneVal("combo", 0, Crlf.Nextline,
                                new CtrlComboBox("コンボボックス", new[]{"DOWN", "PU", "FULL"}, 200)));
            list.Add(new OneVal("fileName2", "c:\\work", Crlf.Nextline,
                                new CtrlFolder("フォルダ", 30, new Kernel())));
            list.Add(new OneVal("text", "user1", Crlf.Nextline, new CtrlTextBox("テキスト入力", 30)));
            list.Add(new OneVal("hidden", "123", Crlf.Nextline, new CtrlHidden("パスワード", 30)));
            var sut = new CtrlDat("help", list, 100, LangKind.Jp);
            var tabindex = 0;
            sut.Create(null, 0, 0, null,ref tabindex);

            var input = new List<String>();
            input.Add("#	0	c:\\work	user1	c3a5e1369325e2ca");
            input.Add(" 	1	c:\\work	user2	b867684066caf9dc");
            input.Add(" 	2	c:\\work	user3	4911d0d49c8911ed");

            try{
                //リフレクションによるprivateメンバへのアクセス
                var cls = sut;
                var type = cls.GetType();
                var exportDat = type.GetMethod("ExportDat", BindingFlags.NonPublic | BindingFlags.Instance);
                var importDat = type.GetMethod("ImportDat", BindingFlags.NonPublic | BindingFlags.Instance);
                importDat.Invoke(cls, new object[]{input});
                var output = (List<String>) exportDat.Invoke(cls, new object[]{});
                for (var i = 0; i < input.Count; i++){
                    Assert.That(input[i], Is.EqualTo(output[i]));
                }
            }
            catch (Exception e){
                Assert.Fail(e.Message);
            }
        }
Пример #2
0
        //OneValの生成
        //デフォルト値(nullを設定した場合、適切な値を自動でセットする)
        public static OneVal CreateOneVal(CtrlType ctrlType, Object val)
        {
            //Kernel kernel = new Kernel();
            const string help = "help";
            OneCtrl oneCtrl;
            switch (ctrlType) {
                case CtrlType.CheckBox:
                    if (val == null) {
                        val = true;
                    }
                    oneCtrl = new CtrlCheckBox(help);
                    break;
                case CtrlType.Int:
                    if (val == null) {
                        val = 1;
                    }
                    oneCtrl = new CtrlInt(help, 3); // 3桁で決め打ち
                    break;
                case CtrlType.File:
                    if (val == null) {
                        val = "1.txt";
                    }
                    oneCtrl = new CtrlFile(help, 200, new Kernel());
                    break;
                case CtrlType.Folder:
                    if (val == null) {
                        val = "c:\temp";
                    }
                    oneCtrl = new CtrlFolder(help, 200,  new Kernel());
                    break;
                case CtrlType.TextBox:
                    if (val == null) {
                        val = "abc";
                    }
                    oneCtrl = new CtrlTextBox(help, 20);
                    break;
                case CtrlType.Radio:
                    if (val == null) {
                        val = 0;
                    }
                    oneCtrl = new CtrlRadio(help, new[] { "1", "2", "3" }, 30, 3);
                    break;
                case CtrlType.Font:
                    if (val == null){
                        val = new Font("MS ゴシック", 10f);
                    }
                    oneCtrl = new CtrlFont(help, LangKind.Jp);
                    break;
                case CtrlType.Memo:
                    if (val == null) {
                        val = "1";
                    }
                    oneCtrl = new CtrlMemo(help, 10, 10);
                    break;
                case CtrlType.Hidden:
                    if (val == null) {
                        val = "";
                    }
                    oneCtrl = new CtrlHidden(help, 30);
                    break;
                case CtrlType.AddressV4:
                    if (val == null) {
                        val = "";
                    }
                    oneCtrl = new CtrlAddress(help);
                    break;
                case CtrlType.BindAddr:
                    if (val == null) {
                        val = "V4ONLY,INADDR_ANY,IN6ADDR_ANY_INIT";
                    }
                    var list = new List<Ip>();
                    try {
                        list.Add(new Ip(IpKind.InAddrAny));
                        list.Add(new Ip("192.168.0.1"));
                    } catch (ValidObjException ex) {
                        Assert.Fail(ex.Message);

                    }
                    oneCtrl = new CtrlBindAddr(help, list.ToArray(), list.ToArray());
                    break;
                case CtrlType.ComboBox:
                    //listを{"1","2"}で決め打ち

                    if (val == null) {
                        val = 0;
                    }
                    oneCtrl = new CtrlComboBox(help, new[] { "1", "2" }, 10);
                    break;
                case CtrlType.Dat:
                    //カラムはTEXTBOX×2で決め打ち
                    var listVal = new ListVal{
                        new OneVal("name1", true, Crlf.Nextline, new CtrlCheckBox("help")),
                        new OneVal("name2", true, Crlf.Nextline, new CtrlCheckBox("help"))
                    };

                    if (val == null) {
                        val = new Dat(new[] { CtrlType.CheckBox, CtrlType.CheckBox });
                    }

                    oneCtrl = new CtrlDat(help, listVal, 300, LangKind.Jp);
                    break;
                default:
                    throw new Exception(ctrlType.ToString());
            }
            return new OneVal("name", val, Crlf.Nextline, oneCtrl);
        }