public void TestEnumerators() { var complex = new ComplexFrame(); complex.Number.Value = 2; complex.Compile(); complex.Structures[0].Number.Value = 1; complex.Structures[1].Number.Value = 2; complex.Compile(); complex.SomeBytes[0] = 87; complex.SomeBytes[1] = 209; CollectionAssert.AreEqual(new byte[] { 87, 209 }, new List <byte>(((System.Collections.IEnumerable)complex.SomeBytes).Cast <byte>())); short i = 0; foreach (var structure in complex.Structures) { structure.Number.Value = i++; } i = 0; foreach (var structure in (IEnumerable)complex.Structures) { Assert.AreEqual(i++, ((ComplexStructure)structure).Number); } }
public void WriteComplex() { var complex = new ComplexFrame(); Assert.AreEqual(2, complex.Size); complex.Number.Value = 1; complex.Compile(); Assert.AreEqual(2 + 1 + (3), complex.Size); complex.Structures[0].Number.Value = 1; complex.Compile(); Assert.AreEqual(2 + 1 + (3 + 1), complex.Size); complex.Number.Value = 2; complex.Compile(); complex.Structures[0].Number.Value = 3; complex.Compile(); complex.Structures[1].Number.Value = 1; complex.Compile(); Assert.AreEqual(2 + 2 + (3 + 3) + (3 + 1), complex.Size); complex.SomeBytes[0] = 0x42; complex.SomeBytes[1] = 0x24; SetBitmapped(complex.Structures[0].OneBitmapped, 10, true, 3); SetBitmapped(complex.Structures[0].ManyBitmappeds[0], 15, false, 0); SetBitmapped(complex.Structures[0].ManyBitmappeds[1], 14, true, 1); SetBitmapped(complex.Structures[0].ManyBitmappeds[2], 13, false, 2); SetBitmapped(complex.Structures[1].OneBitmapped, 0, false, 0); SetBitmapped(complex.Structures[1].ManyBitmappeds[0], 15, true, 7); CheckFrame(ComplexBytes, complex); complex.Number.Value = 0; complex.Compile(); Assert.AreEqual(2, complex.Size); }
public void TestIndexOutOfRange() { var complex = new ComplexFrame(); complex.Number.Value = 1; complex.Compile(); var x = complex.SomeBytes[20]; // For now this returns 0 in these cases (instead of throwing), // because they can happen during a compile. Assert.AreEqual(0, x); }
public void TestOffsetAtEnd() { var complex = new ComplexFrame(); complex.Number.Value = 4; complex.Compile(); complex.Structures[0].Number.Value = 2; complex.Compile(); Assert.AreEqual(2, complex.Number.OffsetAtEnd); Assert.AreEqual(2 + 4, complex.SomeBytes.OffsetAtEnd); Assert.AreEqual(complex.Size, complex.Structures.OffsetAtEnd); Assert.AreEqual(2 + 4 + (2), complex.Structures[0].Number.OffsetAtEnd); Assert.AreEqual(2 + 4 + (2 + 1 + 2) + 3 + 3 + 2, complex.Structures[3].Number.OffsetAtEnd); }
public void ReadComplex() { var complex = new ComplexFrame(); complex.Buffer = ComplexBytes; complex.Compile(); // Test for GetEnumerator method //(complex as IEnumerable).GetEnumerator(); Assert.AreEqual(2 + 2 + (3 + 3) + (3 + 1), complex.Size); Assert.AreEqual(0x42, complex.SomeBytes[0]); Assert.AreEqual(0x24, complex.SomeBytes[1]); CheckBitmapped(complex.Structures[0].OneBitmapped, 10, true, 3); CheckBitmapped(complex.Structures[0].ManyBitmappeds[0], 15, false, 0); CheckBitmapped(complex.Structures[0].ManyBitmappeds[1], 14, true, 1); CheckBitmapped(complex.Structures[0].ManyBitmappeds[2], 13, false, 2); CheckBitmapped(complex.Structures[1].OneBitmapped, 0, false, 0); CheckBitmapped(complex.Structures[1].ManyBitmappeds[0], 15, true, 7); }