Пример #1
0
        public void Test_NormalItemFactory_CompositeData()
        {
            List<string> val = new List<string> { "composite val,    1  ,C", ">byte 1, 2", ">byte 3, 3" ,
            "composite val 2,    1  ,C", ">byte 1, 2", ">byte 3, 3" };

            StreamReader testBed = TestHelper.prepareTestDouble(val);
            NormalItemFactory normalItemFactory = new NormalItemFactory(testBed);
            List<Item> items =  normalItemFactory.GetItems();
            List<Item> expectedItems = new List<Item>();

            var IC = new ItemComposite();
            IC.Length = 1;
            IC.Name = "composite val";
            BitItem BI1 = new BitItem() { isChecked = false, location = 2, name = "byte 1" };
            BitItem BI2 = new BitItem() { isChecked = false, location = 2, name = "byte 1" };
            IC.addBitItem(BI1);
            IC.addBitItem(BI2);
            expectedItems.Add(IC);

            var IC2 = new ItemComposite();
            IC2.Length = 1;
            IC2.Name = "composite val 2";
            BitItem BI2_1 = new BitItem() { isChecked = false, location = 2, name = "byte 1" };
            BitItem BI2_2 = new BitItem() { isChecked = false, location = 2, name = "byte 1" };
            IC.addBitItem(BI2_1);
            IC.addBitItem(BI2_2);
            expectedItems.Add(IC2);

            // start asserting;
            TestHelper.Compare(expectedItems, items);
        }
Пример #2
0
        public void Test_CompositeItem_Normal()
        {
            ItemComposite CI = new ItemComposite();
            CI.addBitItem(new BitItem() { isChecked = false, location = 2, name = "bit 2" });
            CI.addBitItem(new BitItem() { isChecked = true, location = 3, name = "bit 3" });
            CI.addBitItem(new BitItem() { isChecked = true, location = 4, name = "bit 4" });

            Assert.AreEqual("0C", CI.Value);
        }
Пример #3
0
        public void Test_ItemDecorator_GetBase1Level()
        {
            RegularItem RI = new RegularItem();
            RegularItem RI2 = new RegularItem();
            OtherItemNotNull_Decorator decWithRegularItem = new OtherItemNotNull_Decorator(RI, RI2);

            Assert.IsInstanceOfType(decWithRegularItem.getBaseClass(), typeof(RegularItem));

            ItemComposite itemComposite = new ItemComposite();
            OtherItemNotNull_Decorator decWithComposite = new OtherItemNotNull_Decorator(itemComposite, RI2);
            Assert.IsInstanceOfType(decWithComposite.getBaseClass(), typeof(ItemComposite));
        }
Пример #4
0
 public CompositeInput(ItemComposite CV)
 {
     InitializeComponent();
     this.CV = CV;
     lisfOfItems = CV.getItems();
     for(int i = 0; i<lisfOfItems .Count;i++ ){
         BitItem currentItem = lisfOfItems[i];
         CheckBox CB = new CheckBox();
         CB.Text = currentItem.name;
         CB.Name = currentItem.location.ToString();
         CB.Size = new System.Drawing.Size(80, 17);
         CB.AutoSize = true;
         CB.Location = new Point(7, 20 * i);
         CB.DataBindings.Add("Checked", currentItem, "isChecked");
         this.panel1.Controls.Add(CB);
     }
 }
Пример #5
0
        public override List<ItemObject.Item> GetItems()
        {
            List<Item> result = new List<Item>();
            Item prev = null;
            Item prevTemp = null;

            string line = " ";
            int defaultValuePosition;
            while (line != null)
            {
                // setting of default value
                defaultValuePosition = 3;
                Item currentItem = null;
                prevTemp = null;

                // do the checking of string
                line = dataSource.ReadLine();
                if (line == null)
                    continue;
                line = line.Trim();

                // check for comment or empty line
                if (line.Length <= 0 || line[0] == '#')
                {
                    continue;
                }

                // chop the string into several string separated by ',' (comma)
                string[] lines = line.Split(',');

                // remove the ending and trailing space
                for(int i = 0;i< lines.Length;i++){
                    lines[i] = lines[i].Trim();
                }

                // if there is a composite item detected at the previous attempt then start adding it's member
                if ((line[0] == '>') && (prev != null) && (prev is ItemComposite))
                {
                    BitItem BI= new BitItem();
                    BI.name = lines[0].Substring(1);
                    BI.location = int.Parse(lines[1]);
                    (prev as ItemComposite).addBitItem(BI);
                    continue;
                }

                // if there is no type provided then create a regular item
                if (lines.Length <= 2)
                {
                    currentItem = new RegularItem();
                }
                else
                {
                     // build the basic type based on first character
                    switch (lines[2].ToUpper()[0])
                    {
                        case 'N':
                            currentItem = new ItemValueAffectedNextItemLength();
                            prevTemp = currentItem;
                            break;
                        case 'C':
                            currentItem = new ItemComposite();
                            prevTemp= (ItemComposite)currentItem;
                            break;
                        case 'R':
                        default :
                            currentItem = new RegularItem();
                            break;
                    }

                    // build the decorator
                    if (lines[2].Length > 1)
                    {
                        switch (lines[2][1])
                        {
                            case 'P' :
                                currentItem = new OtherItemNotNull_Decorator(currentItem,findItem(result, lines[3]));
                                defaultValuePosition++;
                                break;
                            default:
                                break;
                        }
                    }

                }

                // get the default value (in case it exist)
                if (lines.Length >= defaultValuePosition + 1)
                {
                    currentItem.Value = lines[defaultValuePosition];
                }

                // set the item name and length
                currentItem.Name = lines[0];
                currentItem.Length = int.Parse(lines[1]);
                result.Add(currentItem);

                // set the relationship
                if (prev != null)
                {
                    if (prev is ItemValueAffectedNextItemLength)
                    {
                        (prev as ItemValueAffectedNextItemLength).setAffectedItem((RegularItem)currentItem);
                        prevTemp = null;
                    }
                }
                prev = prevTemp;

            }
            return result;
        }