-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathImageViewTests.cs
68 lines (62 loc) · 2.14 KB
/
ImageViewTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
namespace NETMapnik.Test
{
[TestClass]
public class ImageViewTests
{
[TestMethod]
public void ImageView_Init()
{
Map m = new Map(256, 256);
Image i = new Image(256, 256);
ImageView iv = i.View(0, 0, 256, 256);
Assert.IsTrue(iv.IsSolid());
Color pixel = iv.GetPixel(0, 0);
Assert.AreEqual(pixel.ToString(), "rgba(0,0,0,0.0)");
m.Background = new Color(255, 255, 255);
m.Render(i);
iv = i.View(0, 0, 256, 256);
Assert.IsTrue(iv.IsSolid());
pixel = iv.GetPixel(0, 0);
Assert.AreEqual(pixel.ToString(), "rgb(255,255,255)");
}
[TestMethod]
public void ImageView_IsSolid()
{
Image i = new Image(256, 256);
ImageView iv = i.View(0, 0, 256, 256);
Assert.IsTrue(iv.IsSolid());
i.SetPixel(0, 0, new Color("red"));
iv = i.View(0, 0, 256, 256);
Assert.IsFalse(iv.IsSolid());
}
[TestMethod]
public void ImageView_Save()
{
Map m = new Map(100, 100);
Image i = new Image(100, 100);
m.Background = new Color("green");
m.Render(i);
ImageView iv = i.View(0,0,10,10);
string filename = @".\data\tmp\" + Guid.NewGuid().ToString() + ".png";
iv.Save(filename);
byte[] bytes1 = File.ReadAllBytes(filename);
byte[] bytes2 = File.ReadAllBytes(@".\data\10x10green.png");
CollectionAssert.AreEqual(bytes1, bytes2);
}
[TestMethod]
public void ImageView_Encode()
{
Map m = new Map(100, 100);
Image i = new Image(100, 100);
m.Background = new Color("green");
m.Render(i);
ImageView iv = i.View(0, 0, 10, 10);
byte[] bytes1 = iv.Encode("png");
byte[] bytes2 = File.ReadAllBytes(@".\data\10x10green.png");
CollectionAssert.AreEqual(bytes1, bytes2);
}
}
}