コード例 #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 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;
        }
コード例 #3
0
ファイル: ItemComposite.cs プロジェクト: rrajaguk/arrayParser
 public void addBitItem(BitItem val)
 {
     Items.Add(val);
 }