Skip to content

Commit e0d0c1e

Browse files
增加UT。
1 parent cc29199 commit e0d0c1e

File tree

2 files changed

+245
-0
lines changed

2 files changed

+245
-0
lines changed
Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
require('../../../src/common/iServer/ServerGeometry');
2+
describe('testServerGeometry', function () {
3+
it('constructor and destroy', function () {
4+
var options = {
5+
id: 1,
6+
parts: [1],
7+
points: [{"y": -4377.027184298267, "x": 4020.0045221720466}],
8+
type: SuperMap.GeometryType.POINT
9+
};
10+
var serverGeometry = new SuperMap.ServerGeometry(options);
11+
expect(serverGeometry).not.toBeNull();
12+
expect(serverGeometry.CLASS_NAME).toBe("SuperMap.ServerGeometry");
13+
expect(serverGeometry.id).toEqual(1);
14+
expect(serverGeometry.parts.length).toEqual(1);
15+
expect(serverGeometry.points.length).toEqual(1);
16+
expect(serverGeometry.type).toBe("POINT");
17+
expect(serverGeometry.style).toBeNull();
18+
expect(serverGeometry.prjCoordSys).toBeNull();
19+
serverGeometry.destroy();
20+
expect(serverGeometry.id).toBeNull();
21+
expect(serverGeometry.parts).toBeNull();
22+
expect(serverGeometry.points).toBeNull();
23+
expect(serverGeometry.type).toBeNull();
24+
});
25+
26+
it('toGeometry', function () {
27+
var options_POINT = {
28+
type: SuperMap.GeometryType.POINT
29+
};
30+
var serverGeometry_POINT = new SuperMap.ServerGeometry(options_POINT);
31+
var toGeometry_POINT = serverGeometry_POINT.toGeometry();
32+
expect(toGeometry_POINT).toBeNull();
33+
serverGeometry_POINT.destroy();
34+
var options_LINE = {
35+
type: SuperMap.GeometryType.LINE
36+
};
37+
var serverGeometry_LINE = new SuperMap.ServerGeometry(options_LINE);
38+
var toGeometry_LINE = serverGeometry_LINE.toGeometry();
39+
expect(toGeometry_LINE).toBeNull();
40+
serverGeometry_LINE.destroy();
41+
var options_LINEM = {
42+
type: SuperMap.GeometryType.LINEM
43+
};
44+
var serverGeometry_LINEM = new SuperMap.ServerGeometry(options_LINEM);
45+
var toGeometry_LINEM = serverGeometry_LINEM.toGeometry();
46+
expect(toGeometry_LINEM).not.toBeNull();
47+
serverGeometry_LINEM.destroy();
48+
var options_REGION = {
49+
type: SuperMap.GeometryType.REGION
50+
};
51+
var serverGeometry_REGION = new SuperMap.ServerGeometry(options_REGION);
52+
var toGeometry_REGION = serverGeometry_REGION.toGeometry();
53+
expect(toGeometry_REGION).toBeNull();
54+
serverGeometry_REGION.destroy();
55+
});
56+
57+
it('toGeoPoint_Null', function () {
58+
var options = {
59+
id: 1,
60+
parts: [],
61+
points: [],
62+
type: SuperMap.GeometryType.POINT
63+
};
64+
var serverGeometry = new SuperMap.ServerGeometry(options);
65+
var geoPointNull = serverGeometry.toGeoPoint();
66+
expect(geoPointNull).toBeNull();
67+
serverGeometry.destroy();
68+
});
69+
70+
it('toGeoPoint', function () {
71+
var options = {
72+
id: 1,
73+
parts: [1],
74+
points: [{"y": -4377.027184298267, "x": 4020.0045221720466}],
75+
type: SuperMap.GeometryType.POINT
76+
};
77+
var serverGeometry = new SuperMap.ServerGeometry(options);
78+
var toGeoPoint = serverGeometry.toGeoPoint();
79+
expect(toGeoPoint).not.toBeNull();
80+
expect(toGeoPoint.CLASS_NAME).toBe("SuperMap.Geometry.Point");
81+
expect(toGeoPoint.id).toContain("SuperMap.Geometry_");
82+
expect(toGeoPoint.x).toEqual(4020.0045221720466);
83+
expect(toGeoPoint.y).toEqual(-4377.027184298267);
84+
serverGeometry.destroy();
85+
});
86+
87+
it('toGeoPoint_MultiPoint', function () {
88+
var options = {
89+
id: 1,
90+
parts: [1, 1],
91+
points: [{"y": -4377.027184298267, "x": 4020.0045221720466},
92+
{"y": -4381.569363260499, "x": 4057.0600591960642}],
93+
type: SuperMap.GeometryType.POINT
94+
};
95+
var serverGeometry = new SuperMap.ServerGeometry(options);
96+
var toGeoPointMulti = serverGeometry.toGeoPoint();
97+
expect(toGeoPointMulti).not.toBeNull();
98+
expect(toGeoPointMulti.CLASS_NAME).toBe("SuperMap.Geometry.MultiPoint");
99+
expect(toGeoPointMulti.id).toContain("SuperMap.Geometry_");
100+
var components = toGeoPointMulti.components;
101+
expect(components.length).toEqual(2);
102+
expect(components[0].CLASS_NAME).toBe("SuperMap.Geometry.Point");
103+
expect(components[0].id).toContain("SuperMap.Geometry_");
104+
expect(components[0].x).toEqual(4020.0045221720466);
105+
expect(components[0].y).toEqual(-4377.027184298267);
106+
expect(components[1].CLASS_NAME).toBe("SuperMap.Geometry.Point");
107+
expect(components[1].id).toContain("SuperMap.Geometry_");
108+
expect(components[1].x).toEqual(4057.0600591960642);
109+
expect(components[1].y).toEqual(-4381.569363260499);
110+
serverGeometry.destroy();
111+
});
112+
113+
it('toGeoLine_Null', function () {
114+
var serverGeometry = new SuperMap.ServerGeometry({parts: []});
115+
var geoLine_Null = serverGeometry.toGeoLine();
116+
expect(geoLine_Null).toBeNull();
117+
serverGeometry.destroy();
118+
});
119+
120+
it('toGeoLine_LineRing', function () {
121+
var options = {
122+
id: 1,
123+
parts: [4],
124+
points: [{"y": -4377.027184298267, "x": 4020.0045221720466},
125+
{"y": -4381.569363260499, "x": 4057.0600591960642},
126+
{"y": -4382.60877717323, "x": 4064.595810063362},
127+
{"y": -4377.027184298267, "x": 4020.0045221720466}],
128+
type: SuperMap.GeometryType.LINE
129+
};
130+
var serverGeometry = new SuperMap.ServerGeometry(options);
131+
var geoLine_LineRing = serverGeometry.toGeoLine();
132+
expect(geoLine_LineRing).not.toBeNull();
133+
expect(geoLine_LineRing.CLASS_NAME).toBe("SuperMap.Geometry.LinearRing");
134+
expect(geoLine_LineRing.id).toContain("SuperMap.Geometry_");
135+
var components = geoLine_LineRing.components;
136+
expect(components.length).toEqual(4);
137+
for (var i = 0; i < components.length; i++) {
138+
expect(components[i].CLASS_NAME).toBe("SuperMap.Geometry.Point");
139+
expect(components[i].id).toContain("SuperMap.Geometry_");
140+
}
141+
expect(components[0].x).toEqual(4020.0045221720466);
142+
expect(components[0].y).toEqual(-4377.027184298267);
143+
expect(components[1].x).toEqual(4057.0600591960642);
144+
expect(components[1].y).toEqual(-4381.569363260499);
145+
expect(components[2].x).toEqual(4064.595810063362);
146+
expect(components[2].y).toEqual(-4382.60877717323);
147+
expect(components[3].x).toEqual(4020.0045221720466);
148+
expect(components[3].y).toEqual(-4377.027184298267);
149+
serverGeometry.destroy();
150+
});
151+
152+
it('toGeoLine_LineString', function () {
153+
var options = {
154+
id: 1,
155+
parts: [4],
156+
points: [{"y": -4377.027184298267, "x": 4020.0045221720466},
157+
{"y": -4381.569363260499, "x": 4057.0600591960642},
158+
{"y": -4382.60877717323, "x": 4064.595810063362},
159+
{"y": -4382.939424428795, "x": 4076.2655245045335}],
160+
type: SuperMap.GeometryType.LINE
161+
};
162+
var serverGeometry = new SuperMap.ServerGeometry(options);
163+
var geoLine_LineString = serverGeometry.toGeoLine();
164+
expect(geoLine_LineString).not.toBeNull();
165+
expect(geoLine_LineString.CLASS_NAME).toBe("SuperMap.Geometry.LineString");
166+
expect(geoLine_LineString.id).toContain("SuperMap.Geometry_");
167+
var components = geoLine_LineString.components;
168+
expect(components.length).toEqual(4);
169+
for (var i = 0; i < components.length; i++) {
170+
expect(components[i].CLASS_NAME).toBe("SuperMap.Geometry.Point");
171+
expect(components[i].id).toContain("SuperMap.Geometry_");
172+
}
173+
expect(components[0].x).toEqual(4020.0045221720466);
174+
expect(components[0].y).toEqual(-4377.027184298267);
175+
expect(components[1].x).toEqual(4057.0600591960642);
176+
expect(components[1].y).toEqual(-4381.569363260499);
177+
expect(components[2].x).toEqual(4064.595810063362);
178+
expect(components[2].y).toEqual(-4382.60877717323);
179+
expect(components[3].x).toEqual(4076.2655245045335);
180+
expect(components[3].y).toEqual(-4382.939424428795);
181+
serverGeometry.destroy();
182+
});
183+
184+
it('toGeoLine_MultiLineString', function () {
185+
var options = {
186+
id: 1,
187+
parts: [4, 4],
188+
points: [{"y": -4377.027184298267, "x": 4020.0045221720466},
189+
{"y": -4381.569363260499, "x": 4057.0600591960642},
190+
{"y": -4382.60877717323, "x": 4064.595810063362},
191+
{"y": -4382.939424428795, "x": 4076.2655245045335},
192+
{"y": -4382.333381109672, "x": 4215.049444583775},
193+
{"y": -4382.389670274902, "x": 4247.756955878764},
194+
{"y": -4382.285032149534, "x": 4428.153084011883},
195+
{"y": -4383.017499027105, "x": 4647.579232906979}],
196+
type: SuperMap.GeometryType.LINE
197+
};
198+
var serverGeometry = new SuperMap.ServerGeometry(options);
199+
var geoLine_MultiLineString = serverGeometry.toGeoLine();
200+
expect(geoLine_MultiLineString).not.toBeNull();
201+
expect(geoLine_MultiLineString.CLASS_NAME).toBe("SuperMap.Geometry.MultiLineString");
202+
expect(geoLine_MultiLineString.id).toContain("SuperMap.Geometry_");
203+
var components1 = geoLine_MultiLineString.components;
204+
expect(components1.length).toEqual(2);
205+
for (var i = 0; i < components1.length; i++) {
206+
expect(components1[i].CLASS_NAME).toBe("SuperMap.Geometry.LineString");
207+
expect(components1[i].id).toContain("SuperMap.Geometry_");
208+
expect(components1[i].components.length).toEqual(4);
209+
for (var j = 0; j < components1[i].components.length; j++) {
210+
expect(components1[i].components[j].CLASS_NAME).toBe("SuperMap.Geometry.Point");
211+
expect(components1[i].components[j].id).toContain("SuperMap.Geometry_");
212+
}
213+
}
214+
serverGeometry.destroy();
215+
});
216+
217+
it('toGeoLineEPS_Null', function () {
218+
var serverGeometry = new SuperMap.ServerGeometry({parts: []});
219+
var geoLineEPS_Null = serverGeometry.toGeoLineEPS();
220+
expect(geoLineEPS_Null).toBeNull();
221+
serverGeometry.destroy();
222+
});
223+
224+
it('toGeoLinem', function () {
225+
var options = {
226+
id: 1,
227+
parts: [3],
228+
points: [{"y": -4377.027184298267, "x": 4020.0045221720466},
229+
{"y": -4381.569363260499, "x": 4057.0600591960642},
230+
{"y": -4382.60877717323, "x": 4064.595810063362}],
231+
type: SuperMap.GeometryType.LINEM
232+
};
233+
var serverGeometry = new SuperMap.ServerGeometry(options);
234+
var geoLinem = serverGeometry.toGeoLinem();
235+
expect(geoLinem).not.toBeNull();
236+
expect(geoLinem.CLASS_NAME).toBe("SuperMap.Route");
237+
expect(geoLinem.id).toEqual(1);
238+
expect(geoLinem.type).toBe("LINEM");
239+
expect(geoLinem.components.length).toEqual(1);
240+
expect(geoLinem.components[0].CLASS_NAME).toBe("SuperMap.Geometry.LineString");
241+
expect(geoLinem.components[0].components.length).toEqual(3);
242+
serverGeometry.destroy();
243+
});
244+
});

test/test-main-common.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ require('./common/iServer/RouteLocatorServiceSpec.js');
6666
require('./common/iServer/SetLayerStatusServiceSpec.js');
6767
require('./common/iServer/StopQueryServiceSpec.js');
6868
//require('./common/iServer/SurfaceAnalystServiceSpec.js'); //待开发将等值线LinearRing添加到GeoJason后再补充对应测试
69+
require('./common/iServer/ServerGeometrySpec.js');
6970

7071
require('./common/iServer/TerrainCurvatureCalculationServiceSpec.js');
7172
require('./common/iServer/ThemeServiceSpec.js');

0 commit comments

Comments
 (0)