Пример #1
0
        public void TestSimpleCount()
        {
            var testBitmap = TestingHelper.GetTestBitmap();
            using (var provider = new SlowBitmapPixelProvider(testBitmap, false))
            {
                var scanner = new DefaultScanner(provider);

                int count = scanner.Count();
                Assert.AreEqual(testBitmap.Width * testBitmap.Height, count);

                count = scanner.Count(Colors.Black);
                Assert.AreEqual(18, count); // There are exactly 18 Black pixels

                int trues = 0;

                count = scanner.Count((x, y, c) =>
                                          {
                                              if (TestingHelper.GetRandomBool())
                                              {
                                                  ++trues;
                                                  return true;
                                              }
                                              return false;
                                          });
                Assert.AreEqual(trues, count);
            }
        }
Пример #2
0
        public void TestSimpleFindPixels()
        {
            var testBitmap = TestingHelper.GetTestBitmap();
            using (var provider = new SlowBitmapPixelProvider(testBitmap, false))
            {
                var scanner = new DefaultScanner(provider);

                var iterator = scanner.FindPixels(Colors.White);
                int counter = 0;
                foreach (var pixel in iterator)
                {
                    Assert.AreEqual(4, pixel.X);
                    Assert.AreEqual(8, pixel.Y);
                    ++counter;
                }
                Assert.AreEqual(1, counter);
            }

            using (var provider = new SlowBitmapPixelProvider(testBitmap))
            {
                var scanner = new DefaultScanner(provider);

                var iterator = scanner.FindPixels(Colors.Black);
                int counter = iterator.Count();
                Assert.AreEqual(18, counter); // There are exactly 18 Black pixels
            }
        }
Пример #3
0
 public void TestSimple()
 {
     var testBitmap = TestingHelper.GetTestBitmap();
     using (var provider = new SlowBitmapPixelProvider(testBitmap))
     {
         var scanner = new DefaultScanner(provider);
     }
 }
Пример #4
0
        public void TestSimpleAny()
        {
            var testBitmap = TestingHelper.GetTestBitmap();
            using (var provider = new SlowBitmapPixelProvider(testBitmap))
            {
                var scanner = new DefaultScanner(provider);

                bool actual = scanner.Any(Colors.White);
                Assert.AreEqual(true, actual);

                actual = scanner.Any(new NativeColor(255, 255, 255, 255));
                Assert.AreEqual(true, actual);
            }
        }
 public void GetPixelSlow2()
 {
     var testBitmap = TestingHelper.GetTestBitmap2();
     using (var slow = new SlowBitmapPixelProvider(testBitmap, true))
     {
         for (int x = 0; x < testBitmap.Width; ++x)
         {
             for (int y = 0; y < testBitmap.Height; ++y)
             {
                 var expected = NativeColor.FromDrawingColor(testBitmap.GetPixel(x, y));
                 var actual = slow.GetPixel(x, y);
                 AssertEx.AreEqual<NativeColor>(expected, actual);
             }
         }
     }
 }
        public void SetPixelSlow2()
        {
            var testBitmap = TestingHelper.GetTestBitmap2();
            using (var slow = new SlowBitmapPixelProvider(testBitmap, true))
            {
                for (int x = 0; x < testBitmap.Width; ++x)
                {
                    for (int y = 0; y < testBitmap.Height; ++y)
                    {
                        NativeColor expected = TestingHelper.GetRandomColor();
                        slow.SetPixel(x, y, expected);

                        NativeColor actual = slow.GetPixel(x, y);

                        AssertEx.AreEqual<NativeColor>(expected, actual);
                    }
                }
            }
        }
Пример #7
0
        public void TestViewForEach()
        {
            var testBitmap = TestingHelper.GetTestBitmap();
            using (var provider = new SlowBitmapPixelProvider(testBitmap))
            {
                var scanner = new DefaultScanner(provider)
                                  {
                                      View = new Rectangle(3, 3, 2, 2)
                                  };

                var counter = 0;
                scanner.ForEach((x, y, c) => ++counter);

                int expected = scanner.View.Width * scanner.View.Height;
                int actual = counter;
                Assert.AreEqual(expected, actual);
            }
        }
Пример #8
0
        public void TestSimpleTolerance()
        {
            var testBitmap = TestingHelper.GetToleranceBitmap();
            using (var provider = new SlowBitmapPixelProvider(testBitmap, false))
            {
                var scanner = new DefaultScanner(provider);
                bool actual = scanner.Any(new NativeColor(255, 100, 100, 100), new ColorTolerance(60, true));
                Assert.AreEqual(true, actual);

                actual = scanner.Any(new NativeColor(255, 100, 100, 100), new ColorTolerance(60, false));
                Assert.AreEqual(true, actual);

                actual = scanner.Any(new NativeColor(255, 100, 100, 100), new ColorTolerance(30, true));
                Assert.AreEqual(false, actual);

                actual = scanner.Any(new NativeColor(255, 100, 100, 100), new ColorTolerance(30, false));
                Assert.AreEqual(false, actual);
            }
        }
Пример #9
0
        public void TestSimpleForEach()
        {
            var testBitmap = TestingHelper.GetTestBitmap();
            using (var provider = new SlowBitmapPixelProvider(testBitmap))
            {
                var scanner = new DefaultScanner(provider);
                var counter = 0;
                scanner.ForEach((x, y, c) => ++counter);

                int expected = testBitmap.Width * testBitmap.Height;
                int actual = counter;
                Assert.AreEqual(expected, actual);
            }
        }