-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImporterTests.cs
More file actions
113 lines (106 loc) · 4.39 KB
/
ImporterTests.cs
File metadata and controls
113 lines (106 loc) · 4.39 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
101
102
103
104
105
106
107
108
109
110
111
112
113
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FreeFrame;
using FreeFrame.Components;
using System.Collections.Generic;
using FreeFrame.Components.Shapes;
using System;
using OpenTK.Windowing.Desktop;
using OpenTK.Graphics.OpenGL4;
using OpenTK.Windowing.GraphicsLibraryFramework;
namespace FreeFrameTests
{
[TestClass]
public class ImporterTests
{
[TestMethod]
public void ImportFromStream_Test_Circle()
{
// Arrange
string svgString = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"1000\" height=\"1000\">" +
"<circle cx=\"600\" cy=\"200\" r=\"100\" fill=\"red\" stroke=\"blue\" stroke-width=\"10\"/>" +
"</svg>";
(List<Shape> result, _) = Importer.ImportFromString(svgString);
// Assert
Assert.AreEqual("cx: 600, cy: 200, r: 100", ((SVGCircle)result[0]).ToString());
}
[TestMethod]
public void ImportFromStream_Test_Path()
{
// Arrange
string svgString = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"1000\" height=\"1000\">" +
"<path d=\"M 20,0 C 0,100 200,100 180,0 m 50,10 L 10,21 H 10 V 10 s 20,20 10,10 Q 10,10 0,0 t 10,10 A 100 100 60 1 0 20,20 z\" stroke=\"black\"/>" +
"</svg>";
(List<Shape> result, _) = Importer.ImportFromString(svgString);
// Assert
Assert.AreEqual("d: M 20,0 C 0,100 200,100 180,0 m 50,10 L 10,21 H 10 V 10 s 20,20 10,10 Q 10,10 0,0 t 10,10 A 100 100 60 1 0 20,20 z", ((SVGPath)result[0]).ToString());
}
[TestMethod]
public void ImportFromStream_Test_Polygon()
{
// Arrange
string svgString = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"1000\" height=\"1000\">" +
"<polygon points=\"50,0 21,90 98,35 2,35 79,90\" stroke=\"black\"/>" +
"</svg>";
(List<Shape> result, _) = Importer.ImportFromString(svgString);
// Assert
Assert.AreEqual("points: 50,0 21,90 98,35 2,35 79,90", ((SVGPolygon)result[0]).ToString());
}
[TestMethod]
public void ImportFromStream_Test_Rectangle()
{
// Arrange
string svgString = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"1000\" height=\"1000\">" +
"<rect width=\"100\" height=\"50\" fill=\"green\"/>" +
"</svg>";
(List<Shape> result, _) = Importer.ImportFromString(svgString);
// Assert
Assert.AreEqual("x: 0, y: 0, width: 100, height: 50, rx: 0, ry: 0", ((SVGRectangle)result[0]).ToString());
}
[TestMethod]
public void ImportFromStream_Test_CountElements()
{
// Arrange
string svgString = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<svg>" +
"<circle/>" +
"<rect/>" +
"<path/>" +
"</svg>";
(List<Shape> result, _) = Importer.ImportFromString(svgString);
// Assert
Assert.AreEqual(3, result.Count);
}
[TestMethod]
public void ImportFromStream_Test_KnownElement()
{
// Arrange
string svgString = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<svg>" +
"<circle/>" +
"<rect/>" +
"<path/>" +
"</svg>";
(_, bool compatibilityFlag) = Importer.ImportFromString(svgString);
// Assert
Assert.AreEqual(false, compatibilityFlag);
}
[TestMethod]
public void ImportFromStream_Test_UnknownElement()
{
// Arrange
string svgString = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<svg>" +
"<circle/>" +
"<hello/>" +
"<path/>" +
"</svg>";
(_, bool compatibilityFlag) = Importer.ImportFromString(svgString);
// Assert
Assert.AreEqual(true, compatibilityFlag);
}
}
}