public void FromHandleTest() { using (var profile = Profile.CreatePlaceholder(null)) { ScreeningFlags expectedFlag = ScreeningFlags.FrequencyUnitLinesCm; uint expectedNChannels = 1; ScreeningChannel[] expectedChannels = new ScreeningChannel[16]; expectedChannels[0].Frequency = 2.0; expectedChannels[0].ScreenAngle = 3.0; expectedChannels[0].SpotShape = SpotShape.Ellipse; var expected = new Screening(expectedFlag, expectedNChannels, expectedChannels); profile.WriteTag(TagSignature.Screening, expected); // Act // implicit call to FromHandle var target = profile.ReadTag <Screening>(TagSignature.Screening); var actualFlag = target.Flag; var actualNChannels = target.nChannels; var actualChannels = target.Channels; // Assert Assert.AreEqual(expectedFlag, actualFlag); Assert.AreEqual(expectedNChannels, actualNChannels); for (int i = 0; i < 16; i++) { Assert.AreEqual(expectedChannels[i], actualChannels[i]); } } }
public void FromHandleTest() { using (var profile = Profile.CreatePlaceholder(null)) { uint expectedFlag = 0; uint expectedNChannels = 1; ScreeningChannel[] expectedChannels = new ScreeningChannel[16]; expectedChannels[0].Frequency = 2.0; expectedChannels[0].ScreenAngle = 3.0; expectedChannels[0].SpotShape = SpotShape.Ellipse; // Act var expected = new Screening(expectedFlag, expectedNChannels, expectedChannels); int size = Marshal.SizeOf(expected); IntPtr data = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(expected, data, false); try { profile.WriteTag(TagSignature.Screening, data); var tag = profile.ReadTag(TagSignature.Screening); // Act var target = Screening.FromHandle(tag); var actualFlag = target.Flag; var actualNChannels = target.nChannels; var actualChannels = target.Channels; // Assert Assert.AreEqual(expectedFlag, actualFlag); Assert.AreEqual(expectedNChannels, actualNChannels); for (int i = 0; i < 16; i++) { Assert.AreEqual(expectedChannels[i], actualChannels[i]); } } finally { Marshal.FreeHGlobal(data); } } }
public void ConstructorTest() { // Arrange uint expectedFlag = 2; uint expectedNChannels = 1; ScreeningChannel[] expectedChannels = new ScreeningChannel[16]; expectedChannels[0].Frequency = 2.0; expectedChannels[0].ScreenAngle = 3.0; expectedChannels[0].SpotShape = SpotShape.Ellipse; // Act var target = new Screening(expectedFlag, expectedNChannels, expectedChannels); var actualFlag = target.Flag; var actualNChannels = target.nChannels; var actualChannels = target.Channels; // Assert Assert.AreEqual(expectedFlag, actualFlag); Assert.AreEqual(expectedNChannels, actualNChannels); Assert.AreEqual(expectedChannels, actualChannels); }