예제 #1
0
        public void SetUp()
        {
            icon    = new Icon(TestBitmap.getInFile("bitmaps/VisualPng.ico"));
            iconStr = icon.ToString();

            icoConv      = new IconConverter();
            icoConvFrmTD = (IconConverter)TypeDescriptor.GetConverter(icon);

            Stream stream = new FileStream(TestBitmap.getInFile("bitmaps/VisualPng1.ico"), FileMode.Open);
            int    length = (int)stream.Length;

            iconBytes = new byte [length];

            try {
                if (stream.Read(iconBytes, 0, length) != length)
                {
                    Assert.Fail("SU#1: Read Failure");
                }
            } catch (Exception e) {
                Assert.Fail("SU#2 Exception thrown while reading. Exception is: " + e.Message);
            } finally {
                stream.Dispose();
            }

            stream.Dispose();
        }
        public void CreateMultipleIconFromSameHandle()
        {
            IntPtr handle;

            using (Icon icon = new Icon(TestBitmap.getInFile("bitmaps/16x16x16.ico")))
            {
                Assert.AreEqual(16, icon.Height, "Original.Height");
                Assert.AreEqual(16, icon.Width, "Original.Width");
                handle = icon.Handle;
                using (Icon icon2 = Icon.FromHandle(handle))
                {
                    Assert.AreEqual(16, icon2.Height, "2.Height");
                    Assert.AreEqual(16, icon2.Width, "2.Width");
                    Assert.AreEqual(handle, icon2.Handle, "2.Handle");
                    IconTest.SaveAndCompare("Handle2", icon2, false);
                }
                using (Icon icon3 = Icon.FromHandle(handle))
                {
                    Assert.AreEqual(16, icon3.Height, "3.Height");
                    Assert.AreEqual(16, icon3.Width, "3.Width");
                    Assert.AreEqual(handle, icon3.Handle, "3.Handle");
                    IconTest.SaveAndCompare("Handle3", icon3, false);
                }
            }
            // unlike other cases (HICON, HBITMAP) handle DOESN'T survives original icon disposal
            // commented / using freed memory is risky ;-)
        }
        public void SetUp()
        {
            image    = Image.FromFile(TestBitmap.getInFile("bitmaps/almogaver24bits.bmp"));
            imageStr = image.ToString();

            imgConv      = new ImageConverter();
            imgConvFrmTD = (ImageConverter)TypeDescriptor.GetConverter(image);

            Stream stream = new FileStream(TestBitmap.getInFile("bitmaps/almogaver24bits1.bmp"), FileMode.Open);
            int    length = (int)stream.Length;

            imageBytes = new byte [length];

            try {
                if (stream.Read(imageBytes, 0, length) != length)
                {
                    Assert.Fail("SU#1: Read Failure");
                }
            } catch (Exception e) {
                Assert.Fail("SU#2 Exception thrown while reading. Exception is: " + e.Message);
            } finally {
                stream.Dispose();
            }

            stream.Dispose();
        }
예제 #4
0
        [Test]         // bug #415581
        public void Icon256ToBitmap()
        {
            using (FileStream fs = File.OpenRead(TestBitmap.getInFile("bitmaps/415581.ico"))) {
                Icon icon = new Icon(fs, 48, 48);
                using (Bitmap b = icon.ToBitmap()) {
                    Assert.AreEqual(0, b.Palette.Entries.Length, "#A1");
                    Assert.AreEqual(48, b.Height, "#A2");
                    Assert.AreEqual(48, b.Width, "#A3");
                    Assert.IsTrue(b.RawFormat.Equals(ImageFormat.MemoryBmp), "#A4");
                    Assert.AreEqual(2, b.Flags, "#A5");
                }
                icon.Dispose();
            }

            using (FileStream fs = File.OpenRead(TestBitmap.getInFile("bitmaps/415581.ico"))) {
                Icon icon = new Icon(fs, 256, 256);
                using (Bitmap b = icon.ToBitmap()) {
                    Assert.AreEqual(0, b.Palette.Entries.Length, "#B1");
                    Assert.AreEqual(48, b.Height, "#B2");
                    Assert.AreEqual(48, b.Width, "#B3");
                    Assert.IsTrue(b.RawFormat.Equals(ImageFormat.MemoryBmp), "#B4");
                    Assert.AreEqual(2, b.Flags, "#B5");
                }
            }
        }
        public void CreateMultipleIconFromSameHICON()
        {
            IntPtr handle;

            using (Icon icon = new Icon(TestBitmap.getInFile("bitmaps/16x16x16.ico")))
            {
                Assert.AreEqual(16, icon.Height, "Original.Height");
                Assert.AreEqual(16, icon.Width, "Original.Width");
                handle = icon.ToBitmap().GetHicon();
            }
            // HICON survives
            using (Icon icon2 = Icon.FromHandle(handle))
            {
                Assert.AreEqual(16, icon2.Height, "2.Height");
                Assert.AreEqual(16, icon2.Width, "2.Width");
                Assert.AreEqual(handle, icon2.Handle, "2.Handle");
                IconTest.SaveAndCompare("HICON2", icon2, false);
            }
            using (Icon icon3 = Icon.FromHandle(handle))
            {
                Assert.AreEqual(16, icon3.Height, "3.Height");
                Assert.AreEqual(16, icon3.Width, "3.Width");
                Assert.AreEqual(handle, icon3.Handle, "3.Handle");
                IconTest.SaveAndCompare("HICON", icon3, false);
            }
        }
        public void HandleRoundtrip()
        {
            IntPtr handle;

            using (Icon icon = new Icon(TestBitmap.getInFile("bitmaps/16x16x16.ico")))
            {
                Assert.AreEqual(16, icon.Height, "Original.Height");
                Assert.AreEqual(16, icon.Width, "Original.Width");
                handle = icon.Handle;
                using (Icon icon2 = Icon.FromHandle(handle))
                {
                    Assert.AreEqual(16, icon2.Height, "FromHandle.Height");
                    Assert.AreEqual(16, icon2.Width, "FromHandle.Width");
                    Assert.AreEqual(handle, icon2.Handle, "FromHandle.Handle");
                    IconTest.SaveAndCompare("Handle", icon2, false);
                }
            }
            // unlike other cases (HICON, HBITMAP) handle DOESN'T survives original icon disposal
            // commented / using freed memory is risky ;-)

            /*using (Icon icon3 = Icon.FromHandle (handle)) {
             *      Assert.AreEqual (0, icon3.Height, "Survivor.Height");
             *      Assert.AreEqual (0, icon3.Width, "Survivor.Width");
             *      Assert.AreEqual (handle, icon3.Handle, "Survivor.Handle");
             * }*/
        }
예제 #7
0
        // OnPaint, WM_TIMER:	s = 2.4 ms
        // Threading timer:		s = 4.3 ms
        // MM Timer:			s = 0.25 s

        public void Start()
        {
            tbmp = new TestBitmap(this.BackColor, this.ForeColor);
            tbmp.Resize(this.ClientSize.Width, this.ClientSize.Height);            //, (float)PixelsInVRate);
            //painter.Assign(this.RazorGFX, this.ClientRectangle, tbmp.Bitmap);
            sw.Start();
            timer = new MultimediaTimer.AccurateTimer(TimerTick, 1);
        }
예제 #8
0
        public void FromFile_Metafile_Emf()
        {
            string filename = TestBitmap.getInFile("bitmaps/milkmateya01.emf");

            using (Image img = Image.FromFile(filename)) {
                Emf(img);
            }
        }
예제 #9
0
        public void FromFile_Metafile_Wmf()
        {
            string filename = TestBitmap.getInFile("bitmaps/telescope_01.wmf");

            using (Image img = Image.FromFile(filename)) {
                Wmf(img);
            }
        }
예제 #10
0
        [Category("NotWorking")]          // https://bugzilla.novell.com/show_bug.cgi?id=338779
        public void FromStream_Metafile_Emf_NotOrigin()
        {
            string filename = TestBitmap.getInFile("bitmaps/milkmateya01.emf");

            using (FileStream fs = File.OpenRead(filename)) {
                fs.Position = fs.Length / 2;
                Assert.Throws <ArgumentException> (() => Image.FromStream(fs));
            }
        }
예제 #11
0
        public void FromStream_Metafile_Emf_NotOrigin()
        {
            string filename = TestBitmap.getInFile("bitmaps/milkmateya01.emf");

            using (FileStream fs = File.OpenRead(filename)) {
                fs.Position = fs.Length / 2;
                Image.FromStream(fs);
            }
        }
예제 #12
0
        public void FromStream_Metafile_Wmf()
        {
            string filename = TestBitmap.getInFile("bitmaps/telescope_01.wmf");

            using (FileStream fs = File.OpenRead(filename)) {
                using (Image img = Image.FromStream(fs)) {
                    Wmf(img);
                }
            }
        }
예제 #13
0
 public void Only256InFile()
 {
     Assert.Throws <Exception>(() =>
     {
         using (FileStream fs = File.OpenRead(TestBitmap.getInFile("bitmaps/only256.ico")))
         {
             Icon icon = new Icon(fs, 0, 0);
         }
     });
 }
예제 #14
0
        public void FromStream_Metafile_Emf()
        {
            string filename = TestBitmap.getInFile("bitmaps/milkmateya01.emf");

            using (FileStream fs = File.OpenRead(filename)) {
                using (Image img = Image.FromStream(fs)) {
                    Emf(img);
                }
            }
        }
예제 #15
0
 [Category("NotWorking")]          // https://bugzilla.novell.com/show_bug.cgi?id=338779
 public void FromStream_Metafile_Wmf_NotOrigin()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         string filename = TestBitmap.getInFile("bitmaps/telescope_01.wmf");
         using (FileStream fs = File.OpenRead(filename)) {
             fs.Position = fs.Length / 2;
             Image.FromStream(fs);
         }
     });
 }
예제 #16
0
 public void SelectFromUnusualSize_Normal32()
 {
     using (FileStream fs = File.OpenRead(TestBitmap.getInFile("bitmaps/80509.ico"))) {
         using (Icon xp = new Icon(fs, 32, 32)) {
             Assert.AreEqual(22, xp.Height, "Height");
             Assert.AreEqual(11, xp.Width, "Width");
             Assert.AreEqual(11, xp.Size.Width, "Size.Width");
             Assert.AreEqual(22, xp.Size.Height, "Size.Height");
         }
     }
 }
        public async Task CreateAsyncShouldSetImageOnPriceViewModel()
        {
            IBitmap expected = new TestBitmap();
            var     price    = new Price();

            this.imageServiceMock.Setup(x => x.GetImageAsync(It.IsAny <Uri>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(expected);

            PriceViewModel result = await this.priceViewModelFactory.CreateAsync(price);

            Assert.That(result.Image, Is.EqualTo(expected));
        }
예제 #18
0
        public void SetUp()
        {
            String path = TestBitmap.getInFile("bitmaps/smiley.ico");

            icon = new Icon(path);
            fs1  = new FileStream(path, FileMode.Open);

            icon16 = new Icon(TestBitmap.getInFile("bitmaps/16x16x16.ico"));
            icon32 = new Icon(TestBitmap.getInFile("bitmaps/32x32x16.ico"));
            icon48 = new Icon(TestBitmap.getInFile("bitmaps/48x48x1.ico"));
            icon64 = new Icon(TestBitmap.getInFile("bitmaps/64x64x256.ico"));
            icon96 = new Icon(TestBitmap.getInFile("bitmaps/96x96x256.ico"));
        }
예제 #19
0
 public void Icon256ToBitmap_Request0()
 {
     // 415581.ico has 2 images, the 256 and 48
     using (FileStream fs = File.OpenRead(TestBitmap.getInFile("bitmaps/415581.ico"))) {
         Icon icon = new Icon(fs, 0, 0);
         using (Bitmap b = icon.ToBitmap()) {
             Assert.AreEqual(0, b.Palette.Entries.Length, "#B1");
             Assert.AreEqual(48, b.Height, "#B2");
             Assert.AreEqual(48, b.Width, "#B3");
             Assert.IsTrue(b.RawFormat.Equals(ImageFormat.MemoryBmp), "#B4");
             Assert.AreEqual(2, b.Flags, "#B5");
         }
     }
 }
예제 #20
0
        public void Constructor_Icon_GetNormalSizeFromIconWith256()
        {
            string filepath = TestBitmap.getInFile("bitmaps/323511.ico");

            Icon orig = new Icon(filepath);

            Assert.AreEqual(32, orig.Height);
            Assert.AreEqual(32, orig.Width);

            Icon ret = new Icon(orig, 48, 48);

            Assert.AreEqual(48, ret.Height);
            Assert.AreEqual(48, ret.Width);
        }
예제 #21
0
        public void Constructor_Icon_DoesntReturn256Passing1()
        {
            string filepath = TestBitmap.getInFile("bitmaps/323511.ico");

            Icon orig = new Icon(filepath);

            Assert.AreEqual(32, orig.Height);
            Assert.AreEqual(32, orig.Width);

            Icon ret = new Icon(orig, 1, 1);

            Assert.AreNotEqual(0, ret.Height);
            Assert.AreNotEqual(0, ret.Width);
        }
예제 #22
0
        public async Task GetImageAsyncShouldReturnCachedImage()
        {
            // arrange
            object obj = new TestBitmap();

            this.memoryCacheMock.Setup(x => x.TryGetValue(It.IsAny <object>(), out obj))
            .Returns(true);

            // act
            IBitmap result = await this.imageService.GetImageAsync(uri);

            // assert
            Assert.That(result, Is.EqualTo(obj));
            this.httpClientWrapperMock.Verify(x => x.GetAsync(uri, It.IsAny <CancellationToken>()), Times.Never);
        }
예제 #23
0
        [Test]         // bug #410608
        public void Save_256()
        {
            string filepath = TestBitmap.getInFile("bitmaps/323511.ico");

            using (Icon icon = new Icon(filepath)) {
                // bug #415809 fixed
                SaveAndCompare("256", icon, true);
            }

            // binary comparison
            var orig  = new MemoryStream(File.ReadAllBytes(filepath));
            var saved = new MemoryStream();

            using (Icon icon = new Icon(filepath))
                icon.Save(saved);
            FileAssert.AreEqual(orig, saved, "binary comparison");
        }
예제 #24
0
        public void HiconRoundtrip()
        {
            IntPtr handle;

            using (Icon icon = new Icon(TestBitmap.getInFile("bitmaps/16x16x16.ico"))) {
                Assert.AreEqual(16, icon.Height, "Original.Height");
                Assert.AreEqual(16, icon.Width, "Original.Width");
                handle = icon.ToBitmap().GetHicon();
            }
            // HICON survives
            using (Icon icon2 = Icon.FromHandle(handle)) {
                Assert.AreEqual(16, icon2.Height, "Survivor.Height");
                Assert.AreEqual(16, icon2.Width, "Survivor.Width");
                Assert.AreEqual(handle, icon2.Handle, "Survivor.Handle");
                IconTest.SaveAndCompare("HICON", icon2, false);
            }
        }
예제 #25
0
        private void XPIcon(int size)
        {
            // note: the Icon(string,Size) or Icon(string,int,int) doesn't exists under 1.x
            using (FileStream fs = File.OpenRead(TestBitmap.getInFile("bitmaps/32bpp.ico"))) {
                using (Icon xp = new Icon(fs, size, size)) {
                    Assert.AreEqual(size, xp.Height, "Height");
                    Assert.AreEqual(size, xp.Width, "Width");
                    Assert.AreEqual(size, xp.Size.Width, "Size.Width");
                    Assert.AreEqual(size, xp.Size.Height, "Size.Height");

                    Bitmap bmp = xp.ToBitmap();
                    Assert.AreEqual(size, bmp.Height, "Bitmap.Height");
                    Assert.AreEqual(size, bmp.Width, "Bitmap.Width");
                    Assert.AreEqual(size, bmp.Size.Width, "Bitmap.Size.Width");
                    Assert.AreEqual(size, bmp.Size.Height, "Bitmap.Size.Height");
                }
            }
        }
예제 #26
0
        public async Task GetImageAsyncShouldReturnImageIfHttpResponseIndicatesSuccess()
        {
            // arrange
            IBitmap expected = new TestBitmap();

            this.MockHttpClientGetAsyncSuccessResponse();

            this.memoryCacheMock.Setup(x => x.CreateEntry(It.IsAny <object>()))
            .Returns(Mock.Of <ICacheEntry>());

            this.bitmapFactoryMock.Setup(x => x.Create(It.IsAny <Stream>()))
            .Returns(expected);

            // act
            IBitmap result = await this.imageService.GetImageAsync(uri);

            // assert
            Assert.That(result, Is.EqualTo(expected));
        }
예제 #27
0
        public async Task GetImageAsyncShouldSetValueOnCacheEntry()
        {
            // arrange
            var expectedValue = new TestBitmap();

            this.MockHttpClientGetAsyncSuccessResponse();

            var cacheEntryMock = new Mock <ICacheEntry>();

            this.memoryCacheMock.Setup(x => x.CreateEntry(It.IsAny <object>()))
            .Returns(cacheEntryMock.Object);

            this.bitmapFactoryMock.Setup(x => x.Create(It.IsAny <Stream>()))
            .Returns(expectedValue);

            // act
            await this.imageService.GetImageAsync(uri);

            // assert
            cacheEntryMock.VerifySet(x => x.Value = expectedValue);
        }
예제 #28
0
파일: TestIcon.cs 프로젝트: raj581/Marvin
        [Test]         // bug #410608
        public void Save_256()
        {
            if (RunningOnUnix)
            {
                Assert.Ignore("Depends on bug #323511");
            }

            using (Icon icon = new Icon(TestBitmap.getInFile("bitmaps/323511.ico"))) {
                // FIXME: use this instead after bug #415809 is fixed
                //SaveAndCompare ("256", icon, true);

                MemoryStream ms = new MemoryStream();
                icon.Save(ms);
                ms.Position = 0;

                using (Icon loaded = new Icon(ms)) {
                    Assert.AreEqual(icon.Height, loaded.Height, "Loaded.Height");
                    Assert.AreEqual(icon.Width, loaded.Width, "Loaded.Width");
                }
            }
        }
예제 #29
0
 [Test, ExpectedException()]          //ToDo: System.ComponentModel.Win32Exception
 public void Only256InFile()
 {
     using (FileStream fs = File.OpenRead(TestBitmap.getInFile("bitmaps/only256.ico"))) {
         Icon icon = new Icon(fs, 0, 0);
     }
 }