Beispiel #1
0
        public void GetStructWithOneFieldSetTest()
        {
            FieldInfo f1 = typeof(Event <AB>).GetField("Value");
            FieldInfo f2 = typeof(AB).GetField("B");

            var    la           = new LayoutAnalyzer <Event <AB> >();
            object testInstance = la.GetStructWithOneFieldSet(new List <FieldInfo> {
                f1, f2
            }, 711);

            testInstance.Should().Not.Be.Null();
            testInstance.Should().Be.OfType <Event <AB> >();
            Event <AB> eab = (Event <AB>)testInstance;

            eab.Value.B.Should().Be(711);
            eab.Value.A.Should().Be(0);

            f2           = typeof(AB).GetField("A");
            testInstance = la.GetStructWithOneFieldSet(new List <FieldInfo> {
                f1, f2
            }, 411);

            testInstance.Should().Not.Be.Null();
            testInstance.Should().Be.OfType <Event <AB> >();
            eab = (Event <AB>)testInstance;
            eab.Value.B.Should().Be(0);
            eab.Value.A.Should().Be(411);
        }
Beispiel #2
0
        public void ExoticCoverageTest()
        {
            var la = new LayoutAnalyzer <AB>();

            Executing.This(() => la.GetOffset((byte *)0, null)).Should().Throw <ArgumentNullException>().Exception.Message.Contains("fieldPath");
            la.ReleaseHandleTestAccessor().Should().Be.True();
        }
Beispiel #3
0
        public void IsTimeTest()
        {
            var la     = new LayoutAnalyzer <Event <AB> >();
            var fields = la.AnalyzeLayout();

            fields.Count(f => f.FieldPath.Last.FieldType == typeof(Time)).Should().Be(1);
        }
Beispiel #4
0
        public void DateTimeOnlyAnalysisTest()
        {
            var la             = new LayoutAnalyzer <DateTimeOnly>();
            var analyzedFields = la.AnalyzeLayout();

            analyzedFields.ForEach(af => Console.WriteLine(af.ToString()));
            analyzedFields.Should().Have.Count.EqualTo(1);
        }
Beispiel #5
0
        public void GetFieldsOfStructTest()
        {
            var la     = new LayoutAnalyzer <Event <AB> >();
            var fields = la.AnalyzeLayout();

            fields.Select(f => f.Name).Should().Have.SameValuesAs("Time", "A", "B");
            fields.Select(f => f.Offset).Should().Have.SameValuesAs(0, 8, 16);
        }
Beispiel #6
0
        public void DotPathOfNestedStructTest()
        {
            var la     = new LayoutAnalyzer <Event <S4> >();
            var fields = la.AnalyzeLayout();

            fields.Select(f => f.Name).Should().Have.SameValuesAs("Time", "s3.s1.a", "s3.s2.b", "s1.a", "s2.b");
            fields.Select(f => f.FieldPath.DotPath).Should().Have.SameValuesAs("Time", "s3.s1.a", "s3.s2.b", "s1.a", "s2.b");
        }
Beispiel #7
0
        public void DottedPathIsFlattenedIfPossible()
        {
            var la     = new LayoutAnalyzer <Event <S3> >();
            var fields = la.AnalyzeLayout();

            fields.Select(f => f.Name).Should().Have.SameValuesAs("Time", "a", "b");
            fields.Select(f => f.FieldPath.DotPath).Should().Have.SameValuesAs("Time", "s1.a", "s2.b");
        }
Beispiel #8
0
        public void DecimalStructTest()
        {
            var la             = new LayoutAnalyzer <DecimalStruct>();
            var analyzedFields = la.AnalyzeLayout();

            analyzedFields.Select(af => af.Name).Should().Have.SameSequenceAs("dec");
            analyzedFields.Select(af => af.Offset).Should().Have.SameSequenceAs(191);

            analyzedFields.ForEach(af => Console.WriteLine(af.ToString()));
        }
Beispiel #9
0
        public void EventAB2Offsets()
        {
            var la             = new LayoutAnalyzer <Event <AB> >();
            var analyzedFields = la.AnalyzeLayout();

            analyzedFields.Select(f => f.FieldPath.DotPath).Should().Have.SameValuesAs("Time", "B", "A");
            analyzedFields.Select(f => f.Offset).Should().Have.SameValuesAs(0, 16, 8);

            analyzedFields.ForEach(af => Console.WriteLine(af.ToString()));
        }
Beispiel #10
0
        public void AnalyzeLayoutReturnsCorrectLayoutForEventT()
        {
            var la             = new LayoutAnalyzer <Event <long> >();
            var analyzedFields = la.AnalyzeLayout();

            analyzedFields.Select(f => f.Name).Should().Have.SameSequenceAs("Time", "Value");
            analyzedFields.Select(f => f.Offset).Should().Have.SameValuesAs(0, 8);
            la.ByteLength.Should().Be(16);

            analyzedFields.ForEach(af => Console.WriteLine(af.ToString()));
        }
Beispiel #11
0
        public void NestedFieldPathsTest()
        {
            var la         = new LayoutAnalyzer <Event <AB> >();
            var fieldpaths = la.GetPrimitiveFields().ToList();

            foreach (var fieldPath in fieldpaths)
            {
                Console.WriteLine(fieldPath);
            }

            fieldpaths.Should().Have.Count.EqualTo(3);
            fieldpaths.Select(fp => fp.ToString()).Should().Have.SameValuesAs("Time", "A", "B");
        }
Beispiel #12
0
        public void WeirdStructOffsetTest()
        {
            var la = new LayoutAnalyzer <WeirdStruct>();
            List <AnalyzedField> analyzedFields = la.AnalyzeLayout();

            analyzedFields.Select(af => af.Name).Should().Have.SameSequenceAs("dec1", "i8", "i16", "i32", "i64", "ui8", "ui16", "ui32", "ui64", "d", "f", "dt", "t", "dec");
            analyzedFields.Select(af => af.Offset).Should().Have.SameSequenceAs(3, 13, 21, 29, 39, 51, 57, 67, 75, 99, 120, 141, 153, 165);

            la.TypeSize.Should().Be.GreaterThanOrEqualTo(sizeof(WeirdStruct));
            (la.TypeSize - sizeof(WeirdStruct)).Should().Be.LessThanOrEqualTo(8);

            analyzedFields.ForEach(af => Console.WriteLine(af.ToString()));
        }
Beispiel #13
0
        public void TimeOnlyAnalysisTest()
        {
            var la             = new LayoutAnalyzer <TimeOnly>();
            var analyzedFields = la.AnalyzeLayout();

            analyzedFields.ForEach(Console.WriteLine);

            analyzedFields.Should().Have.Count.EqualTo(1);
            var af = analyzedFields.First();

            af.FieldPath.Last.FieldType.Should().Be(typeof(Time));
            af.Offset.Should().Be(0);
            af.Name.Should().Be("T");
        }
 public void UnsupportedTypeTest()
 {
     var la = new LayoutAnalyzer<InvalidFieldStruct>();
     Executing.This(() => la.AnalyzeLayout()).Should().Throw<ItemException>();
 }
Beispiel #15
0
        public void UnsupportedTypeTest()
        {
            var la = new LayoutAnalyzer <InvalidFieldStruct>();

            Executing.This(() => la.AnalyzeLayout()).Should().Throw <ItemException>();
        }
 public void GetFieldsOfStructTest()
 {
     var la = new LayoutAnalyzer<Event<AB>>();
     var fields = la.AnalyzeLayout();
     fields.Select(f => f.Name).Should().Have.SameValuesAs("Time", "A", "B");
     fields.Select(f => f.Offset).Should().Have.SameValuesAs(0, 8, 16);
 }
        public void DateTimeOnlyAnalysisTest()
        {
            var la = new LayoutAnalyzer<DateTimeOnly>();
            var analyzedFields = la.AnalyzeLayout();

            analyzedFields.ForEach(af => Console.WriteLine(af.ToString()));
            analyzedFields.Should().Have.Count.EqualTo(1);
        }
 public void ExoticCoverageTest()
 {
     var la = new LayoutAnalyzer<AB>();
     Executing.This(() => la.GetOffset((byte*)0, null)).Should().Throw<ArgumentNullException>().Exception.Message.Contains("fieldPath");
     la.ReleaseHandleTestAccessor().Should().Be.True();
 }
        public void EventAB2Offsets()
        {
            var la = new LayoutAnalyzer<Event<AB>>();
            var analyzedFields = la.AnalyzeLayout();

            analyzedFields.Select(f => f.FieldPath.DotPath).Should().Have.SameValuesAs("Time", "B", "A");
            analyzedFields.Select(f => f.Offset).Should().Have.SameValuesAs(0, 16, 8);

            analyzedFields.ForEach(af => Console.WriteLine(af.ToString()));
        }
 public void IsTimeTest()
 {
     var la = new LayoutAnalyzer<Event<AB>>();
     var fields = la.AnalyzeLayout();
     fields.Count(f => f.FieldPath.Last.FieldType == typeof (Time)).Should().Be(1);
 }
 public void DottedPathIsFlattenedIfPossible()
 {
     var la = new LayoutAnalyzer<Event<S3>>();
     var fields = la.AnalyzeLayout();
     fields.Select(f => f.Name).Should().Have.SameValuesAs("Time", "a", "b");
     fields.Select(f => f.FieldPath.DotPath).Should().Have.SameValuesAs("Time", "s1.a", "s2.b");
 }
 public void DotPathOfNestedStructTest()
 {
     var la = new LayoutAnalyzer<Event<S4>>();
     var fields = la.AnalyzeLayout();
     fields.Select(f => f.Name).Should().Have.SameValuesAs("Time", "s3.s1.a", "s3.s2.b", "s1.a", "s2.b");
     fields.Select(f => f.FieldPath.DotPath).Should().Have.SameValuesAs("Time", "s3.s1.a", "s3.s2.b", "s1.a", "s2.b");
 }
        public void TimeOnlyAnalysisTest()
        {
            var la = new LayoutAnalyzer<TimeOnly>();
            var analyzedFields = la.AnalyzeLayout();

            analyzedFields.ForEach(Console.WriteLine);

            analyzedFields.Should().Have.Count.EqualTo(1);
            var af = analyzedFields.First();
            af.FieldPath.Last.FieldType.Should().Be(typeof (Time));
            af.Offset.Should().Be(0);
            af.Name.Should().Be("T");
        }
        public void AnalyzeLayoutReturnsCorrectLayoutForEventT()
        {
            var la = new LayoutAnalyzer<Event<long>>();
            var analyzedFields = la.AnalyzeLayout();

            analyzedFields.Select(f => f.Name).Should().Have.SameSequenceAs("Time", "Value");
            analyzedFields.Select(f => f.Offset).Should().Have.SameValuesAs(0, 8);
            la.ByteLength.Should().Be(16);

            analyzedFields.ForEach(af => Console.WriteLine(af.ToString()));
        }
        public void DecimalStructTest()
        {
            var la = new LayoutAnalyzer<DecimalStruct>();
            var analyzedFields = la.AnalyzeLayout();

            analyzedFields.Select(af => af.Name).Should().Have.SameSequenceAs("dec");
            analyzedFields.Select(af => af.Offset).Should().Have.SameSequenceAs(191);

            analyzedFields.ForEach(af => Console.WriteLine(af.ToString()));
        }
        public void NestedFieldPathsTest()
        {
            var la = new LayoutAnalyzer<Event<AB>>();
            var fieldpaths = la.GetPrimitiveFields().ToList();

            foreach (var fieldPath in fieldpaths)
            {
                Console.WriteLine(fieldPath);
            }

            fieldpaths.Should().Have.Count.EqualTo(3);
            fieldpaths.Select(fp => fp.ToString()).Should().Have.SameValuesAs("Time", "A", "B");
        }
        public void GetStructWithOneFieldSetTest()
        {
            FieldInfo f1 = typeof (Event<AB>).GetField("Value");
            FieldInfo f2 = typeof (AB).GetField("B");

            var la = new LayoutAnalyzer<Event<AB>>();
            object testInstance = la.GetStructWithOneFieldSet(new List<FieldInfo> {f1, f2}, 711);

            testInstance.Should().Not.Be.Null();
            testInstance.Should().Be.OfType<Event<AB>>();
            Event<AB> eab = (Event<AB>)testInstance;
            eab.Value.B.Should().Be(711);
            eab.Value.A.Should().Be(0);

            f2 = typeof (AB).GetField("A");
            testInstance = la.GetStructWithOneFieldSet(new List<FieldInfo> {f1, f2}, 411);

            testInstance.Should().Not.Be.Null();
            testInstance.Should().Be.OfType<Event<AB>>();
            eab = (Event<AB>)testInstance;
            eab.Value.B.Should().Be(0);
            eab.Value.A.Should().Be(411);
        }
        public void WeirdStructOffsetTest()
        {
            var la = new LayoutAnalyzer<WeirdStruct>();
            List<AnalyzedField> analyzedFields = la.AnalyzeLayout();

            analyzedFields.Select(af => af.Name).Should().Have.SameSequenceAs("dec1", "i8", "i16", "i32", "i64", "ui8", "ui16", "ui32", "ui64", "d", "f", "dt", "t", "dec");
            analyzedFields.Select(af => af.Offset).Should().Have.SameSequenceAs(3, 13, 21, 29, 39, 51, 57, 67, 75, 99, 120, 141, 153, 165);

            la.TypeSize.Should().Be.GreaterThanOrEqualTo(sizeof (WeirdStruct));
            (la.TypeSize - sizeof (WeirdStruct)).Should().Be.LessThanOrEqualTo(8);

            analyzedFields.ForEach(af => Console.WriteLine(af.ToString()));
        }