forked from SharpMap/SharpMap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSymbolizerTest.cs
More file actions
100 lines (81 loc) · 3.07 KB
/
SymbolizerTest.cs
File metadata and controls
100 lines (81 loc) · 3.07 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System.Collections.Generic;
using System.Drawing;
using NUnit.Framework;
using SharpMap.Rendering.Symbolizer;
namespace UnitTests.Serialization
{
[TestFixture]
public class SymbolizerTest : BaseSerializationTest
{
[Test]
public void TestCharacterPointSymbolizer()
{
var cps = new CharacterPointSymbolizer();
cps.CharacterIndex = (int) 'q';
cps.Font = new Font(FontFamily.GenericSansSerif, 12f, FontStyle.Bold);
cps.Foreground = new SolidBrush(Color.BlueViolet);
cps.Halo = 2;
cps.HaloBrush = new SolidBrush(Color.BlanchedAlmond);
cps.Offset = new PointF(6f, 6f);
CharacterPointSymbolizer cpsD = null;
Assert.DoesNotThrow(() => cpsD = SandD(cps, GetFormatter()));
var e = new CharacterPointSymbolizerEqualityComparer();
Assert.IsTrue(e.Equals(cps, cpsD));
}
}
internal class SymbolizerEqualityComparer<T> : EqualityComparer<T> where T : ISymbolizer
{
public override bool Equals(T lhs, T rhs)
{
if (lhs.PixelOffsetMode != rhs.PixelOffsetMode)
return false;
if (lhs.SmoothingMode != rhs.SmoothingMode)
return false;
return true;
}
public override int GetHashCode(T obj)
{
return obj.GetHashCode();
}
}
internal class PointSymbolizerEqualityComparer<T> : SymbolizerEqualityComparer<T>
where T: PointSymbolizer
{
public override bool Equals(T lhs, T rhs)
{
if (lhs.Offset != rhs.Offset)
return false;
if (lhs.Rotation != rhs.Rotation)
return false;
if (lhs.Scale != rhs.Scale)
return false;
if (lhs.Size != rhs.Size)
return false;
return base.Equals(lhs, rhs);
}
}
internal class CharacterPointSymbolizerEqualityComparer : PointSymbolizerEqualityComparer<CharacterPointSymbolizer>
{
public override bool Equals(CharacterPointSymbolizer lhs, CharacterPointSymbolizer rhs)
{
if (lhs.CharacterIndex != rhs.CharacterIndex)
return false;
if (!new FontEqualityComparer().Equals(lhs.Font, rhs.Font))
return false;
if (((SolidBrush)lhs.Foreground).Color != ((SolidBrush)rhs.Foreground).Color)
return false;
if (lhs.Halo != rhs.Halo)
return false;
if (lhs.HaloBrush != null ^ rhs.HaloBrush != null)
return false;
if (lhs.HaloBrush != null)
{
if (((SolidBrush) lhs.HaloBrush).Color != ((SolidBrush) rhs.HaloBrush).Color)
return false;
}
if (lhs.StringFormat.FormatFlags != rhs.StringFormat.FormatFlags)
return false;
return base.Equals(lhs, rhs);
}
}
}