Esempio n. 1
0
 public void TestParserReadBeyondEof()
 {
     using (Parser parser = new Parser())
     {
         parser.Load("Tests", _testdata);
         parser.Read(6);
     }
 }
Esempio n. 2
0
 public void TestParserReadFull()
 {
     using (Parser parser = new Parser())
     {
         parser.Load("Tests", _testdata);
         byte[] testassert = parser.Read(5);
         CollectionAssert.AreEqual(_testdata, testassert,
             string.Format("Read Function did not return correct result: Expected: {0}, Actual: {1}", _testdata,
                 testassert));
     }
 }
Esempio n. 3
0
        public IEnumerable Characters()
        {
            //returns an iterator for the characters in this file

            using (Parser parser = new Parser())
            {
                parser.Load(_fname);
                int count = parser.ReadHeader();

                for(int i = 0; i < count; i++)
                {
                    Character c = new Character();
                    foreach (Properties.IProperty p in parser)
                    {
                        c.AddProperty(p);
                    }
                    yield return c;
                }
            }
        }
Esempio n. 4
0
 public void TestParserReadPartial()
 {
     using (Parser parser = new Parser())
     {
         parser.Load("Tests", _testdata);
         byte[] testassert1 = parser.Read(4);
         byte[] firstdata = new byte[4];
         Array.Copy(_testdata, 0, firstdata, 0, 4);
         CollectionAssert.AreEqual(firstdata, testassert1,
             string.Format("Read Function did not return correct result: Expected: {0}, Actual: {1}", firstdata,
                 testassert1));
         byte[] testassert2 = parser.Read(0);
         byte[] empty = {};
         CollectionAssert.AreEqual(empty, testassert2,
             string.Format("Read Function did not return correct result: Expected: {0}, Actual: {1}", empty,
                 testassert2));
         byte[] testassert3 = parser.Read(1);
         byte[] lastdata = new byte[1];
         Array.Copy(_testdata, 4, lastdata, 0, 1);
         CollectionAssert.AreEqual(lastdata, testassert3,
             string.Format("Read Function did not return correct result: Expected: {0}, Actual: {1}", lastdata,
                 testassert3));
     }
 }
Esempio n. 5
0
 public void TestReadHeader()
 {
     using (Parser parser = new Parser())
     {
         parser.Load(@"c:\tmp\Empty.bin");
         int header = parser.ReadHeader();
         Assert.AreEqual(header, 0);
     }
 }
Esempio n. 6
0
 public void TestReadStringTruncated()
 {
     byte[] data = { 0x07, 0x00, 0x00, 0x00, Convert.ToByte('H'), Convert.ToByte('e'), Convert.ToByte('l'), Convert.ToByte('l'), Convert.ToByte('o'), 0x00 };
     using (Parser parser = new Parser())
     {
         parser.Load("Tests", data);
         parser.ReadStr();
     }
 }
Esempio n. 7
0
 public void TestReadStringMultiple()
 {
     byte[] data = { 0x06, 0x00, 0x00, 0x00, Convert.ToByte('H'), Convert.ToByte('e'), Convert.ToByte('l'), Convert.ToByte('l'), Convert.ToByte('o'), 0x00, 0x07, 0x00, 0x00, 0x00, Convert.ToByte('W'), Convert.ToByte('o'), Convert.ToByte('r'), Convert.ToByte('l'), Convert.ToByte('d'), Convert.ToByte('!'), 0x00 };
     using (Parser parser = new Parser())
     {
         parser.Load("Tests", data);
         string result1 = parser.ReadStr();
         Assert.AreEqual("Hello", result1,
             string.Format("First Part did not match: Expected: {0}, Actual: {1}", "Hello", result1));
         string result2 = parser.ReadStr();
         Assert.AreEqual("World!", result2,
             string.Format("Second Part did not match: Expected: {0}, Actual: {1}", "World!", result2));
     }
 }
Esempio n. 8
0
 public void TestReadString()
 {
     byte[] data = { 0x06, 0x00, 0x00, 0x00, Convert.ToByte('H'), Convert.ToByte('e'), Convert.ToByte('l'), Convert.ToByte('l'), Convert.ToByte('o'), 0x00 };
     using (Parser parser = new Parser())
     {
         parser.Load("Tests", data);
         string result = parser.ReadStr();
         Assert.AreEqual("Hello", result,
             string.Format("Read String did not match: Expected: {0}, Actual: {1}", "Hello", result));
     }
 }
Esempio n. 9
0
 public void TestReadNull()
 {
     byte[] data = { 0x00, 0x00, 0x00, 0x00 };
     using (Parser parser = new Parser())
     {
         parser.Load("Tests", data);
         string result = parser.ReadStr();
         Assert.AreEqual("", result,
             string.Format("Read String did not match: Expected: {0}, Actual: {1}", "", result));
     }
 }
Esempio n. 10
0
 public void TestReadIncorrectSize()
 {
     byte[] data = { 0x04, 0x00, 0x00, 0x00, Convert.ToByte('H'), Convert.ToByte('e'), Convert.ToByte('l'), Convert.ToByte('l'), Convert.ToByte('o'), 0x00 };
     using (Parser parser = new Parser())
     {
         parser.Load("Tests", data);
         parser.ReadStr();
     }
 }
Esempio n. 11
0
        public void TestReadPropertyMultiple()
        {
            byte[] data1 = Combine(_nameData1, _typeData, _sizeData1, _valueData1);
            byte[] data2 = Combine(_nameData2, _typeData, _sizeData2, _valueData2);
            byte[] both = new byte[data1.Length + data2.Length];
            Buffer.BlockCopy(data1, 0, both, 0, data1.Length);
            Buffer.BlockCopy(data2, 0, both, data1.Length, data2.Length);

            using (Parser parser = new Parser())
            {
                parser.Load("Tests", both);
                IProperty returnedProp1 = parser.ReadProperty();
                Assert.AreEqual("strFirstName", returnedProp1.Name,
                    string.Format("Property Name did not match: Expected: {0}, Actual: {1}", "strFirstName",
                        returnedProp1.Name));
                Assert.AreEqual("StrProperty", returnedProp1.TypeName,
                    string.Format("Property Type did not match: Expected: {0}, Actual: {1}", "StrProperty",
                        returnedProp1.TypeName));
                Assert.AreEqual("Ana", returnedProp1.Value,
                    string.Format("Property Value did not match: Expected: {0}, Actual: {1}", "Ana",
                        returnedProp1.Value));
                IProperty returnedProp2 = parser.ReadProperty();
                Assert.AreEqual("strLastName", returnedProp2.Name,
                    string.Format("Property Name did not match: Expected: {0}, Actual: {1}", "strLastName",
                        returnedProp2.Name));
                Assert.AreEqual("StrProperty", returnedProp2.TypeName,
                    string.Format("Property Type did not match: Expected: {0}, Actual: {1}", "StrProperty",
                        returnedProp2.TypeName));
                Assert.AreEqual("Ramirez", returnedProp2.Value,
                    string.Format("Property Value did not match: Expected: {0}, Actual: {1}", "Ramirez",
                        returnedProp2.Value));
            }
        }
Esempio n. 12
0
 public void TestReadProperty()
 {
     byte[] data1 = Combine(_nameData1, _typeData, _sizeData1, _valueData1);
     using (Parser parser = new Parser())
     {
         parser.Load("Tests", data1);
         IProperty returnedProp = parser.ReadProperty();
         Assert.AreEqual("strFirstName", returnedProp.Name,
             string.Format("Property Name did not match: Expected: {0}, Actual: {1}", "strFirstName",
                 returnedProp.Name));
         Assert.AreEqual("StrProperty", returnedProp.TypeName,
             string.Format("Property Type did not match: Expected: {0}, Actual: {1}", "StrProperty",
                 returnedProp.TypeName));
         Assert.AreEqual("Ana", returnedProp.Value,
             string.Format("Property Value did not match: Expected: {0}, Actual: {1}", "Ana",
                 returnedProp.Value));
     }
 }
Esempio n. 13
0
 public void TestReadIntMultiple()
 {
     byte[] data = { 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 };
     using (Parser parser = new Parser())
     {
         parser.Load("Tests", data);
         int result1 = parser.ReadInt();
         Assert.AreEqual(0, result1,
             string.Format("Read Int did not match: Expected: {0}, Actual: {1}", "0", result1));
         int result2 = parser.ReadInt();
         Assert.AreEqual(1, result2,
             string.Format("Read Int did not match: Expected: {0}, Actual: {1}", "1", result2));
     }
 }
Esempio n. 14
0
        public void TestReadInt()
        {
            Dictionary<byte[], int> testCases = new Dictionary<byte[], int>
            {
                {new byte[] {0x00,0x00,0x00,0x00}, 0},
                {new byte[] {0x01,0x00,0x00,0x00}, 1},
                {new byte[] {0xff,0xff,0xff,0xff}, -1}
            };
            using (Parser parser = new Parser())
            {
                foreach (KeyValuePair<byte[], int> entry in testCases)
                {

                    parser.Load("Tests", entry.Key);
                    int result = parser.ReadInt();
                    Assert.AreEqual(entry.Value, result,
                        string.Format("Read Int did not match: Expected: {0}, Actual: {1}", entry.Value, result));
                }
            }
        }
Esempio n. 15
0
 static Parser()
 {
     Instance = new Parser();
 }