示例#1
0
        public void MultipleFromRelations()
        {
            string xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<Peach>\n" +
                         "	<DataModel name=\"TheDataModel\">"+
                         "		<Number name=\"num\" size=\"8\">"+
                         "			<Relation type=\"size\" of=\"Data1\" />"+
                         "			<Relation type=\"size\" of=\"Data2\" />"+
                         "		</Number>"+
                         "		<Blob name=\"Data1\" />"+
                         "		<Blob name=\"Data2\" />"+
                         "	</DataModel>"+
                         "</Peach>";

            PitParser parser = new PitParser();

            Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml)));

            var data = Bits.Fmt("{0:L8}{1}", 5, "HelloWorldMore");

            DataCracker cracker = new DataCracker();

            cracker.CrackData(dom.dataModels[0], data);

            Assert.AreEqual(3, dom.dataModels[0].Count);

            Number  num = dom.dataModels[0][0] as Number;
            Variant val = num.InternalValue;

            Assert.AreEqual(5, (int)val);

            Blob    blob1 = dom.dataModels[0][1] as Blob;
            Variant val2  = blob1.InternalValue;

            Assert.AreEqual("Hello", val2.BitsToString());

            Blob    blob2 = dom.dataModels[0][2] as Blob;
            Variant val3  = blob2.InternalValue;

            Assert.AreEqual("World", val3.BitsToString());
        }