示例#1
0
        public void Create()
        {
            int    width    = 10;
            int    height   = 10;
            ushort bitCount = 1;

            // Improper Bit Count throws
            Assert.ThrowsException <Exception>(() => ImageHeader.Create(width, height, 3));

            ImageHeader imageHeader;

            imageHeader = ImageHeader.Create(width, height, bitCount);

            Assert.AreEqual(ImageHeader.SizeInBytes, (int)imageHeader.headerSize);
            Assert.AreEqual(width, imageHeader.width);
            Assert.AreEqual(height, imageHeader.height);
            Assert.AreEqual(ImageHeader.DefaultPlanes, imageHeader.planes);
            Assert.AreEqual(bitCount, imageHeader.bitCount);
            Assert.AreEqual(BmpCompression.Uncompressed, imageHeader.compression);
            Assert.AreEqual(ImageHeader.DefaultImageSize, imageHeader.imageSize);
            Assert.AreEqual(ImageHeader.DefaultXResolution, imageHeader.xResolution);
            Assert.AreEqual(ImageHeader.DefaultYResolution, imageHeader.yResolution);
            Assert.AreEqual(ImageHeader.DefaultUsedColorMapEntries, imageHeader.usedColorMapEntries);
            Assert.AreEqual(ImageHeader.DefaultImportantColorCount, imageHeader.importantColorCount);
        }
示例#2
0
        public void Equality()
        {
            ImageHeader imageHeader1 = ImageHeader.Create(1, 1, 1);
            ImageHeader imageHeader2 = ImageHeader.Create(1, 1, 1);

            Assert.IsTrue(imageHeader1 == imageHeader2);
            Assert.IsFalse(imageHeader1 != imageHeader2);

            imageHeader2.bitCount = 8;
            Assert.IsFalse(imageHeader1 == imageHeader2);
            Assert.IsTrue(imageHeader1 != imageHeader2);
        }
示例#3
0
        public void Validate()
        {
            ImageHeader imageHeader = ImageHeader.Create(1, 1, 1);

            imageHeader.Validate();

            imageHeader.headerSize = ImageHeaderV4.SizeInBytes;
            TestInvalidImageHeaderSize(imageHeader, "version 4");

            imageHeader.headerSize = ImageHeaderV5.SizeInBytes;
            TestInvalidImageHeaderSize(imageHeader, "version 5");

            imageHeader.headerSize = 0;
            TestInvalidImageHeaderSize(imageHeader, "Unknown");

            imageHeader.headerSize = ImageHeader.SizeInBytes;

            //imageHeader.headerSize = 0;
            //Assert.ThrowsException<Exception>(() => imageHeader.Validate());
            //imageHeader.headerSize = ImageHeader.SizeInBytes;

            imageHeader.planes = 0;
            Assert.ThrowsException <Exception>(() => imageHeader.Validate());
            imageHeader.planes = ImageHeader.DefaultPlanes;

            imageHeader.bitCount = 3;
            Assert.ThrowsException <Exception>(() => imageHeader.Validate());
            imageHeader.bitCount = 1;

            imageHeader.usedColorMapEntries = 3;
            Assert.ThrowsException <Exception>(() => imageHeader.Validate());
            imageHeader.usedColorMapEntries = ImageHeader.DefaultUsedColorMapEntries;

            imageHeader.importantColorCount = 3;
            Assert.ThrowsException <Exception>(() => imageHeader.Validate());
            imageHeader.importantColorCount = ImageHeader.DefaultImportantColorCount;
        }