File: RFC24.cs

package info (click to toggle)
mapserver 6.4.1-5%2Bdeb8u3
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 12,960 kB
  • ctags: 19,791
  • sloc: ansic: 119,501; cpp: 54,044; python: 3,055; xml: 1,676; cs: 875; lex: 741; yacc: 707; java: 588; perl: 428; makefile: 382; sh: 373; tcl: 158; ruby: 55
file content (503 lines) | stat: -rw-r--r-- 14,793 bytes parent folder | download | duplicates (11)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
/******************************************************************************
 * $Id$
 *
 * Project:  MapServer
 * Purpose:  Tests for RFC24 implementation. 
 *           (http://mapserver.gis.umn.edu/development/rfc/ms-rfc-24/).
 * Author:   Tamas Szekeres, szekerest@gmail.com
 *           Umberto Nicoletti, umberto.nicoletti@gmail.com
 *
 ******************************************************************************
 * Copyright (c) 1996-2008 Regents of the University of Minnesota.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in 
 * all copies of this Software or works derived from this Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *****************************************************************************/

using System;
using OSGeo.MapServer;

/**
 * <p>Title: Mapscript RFC24 tests.</p>
 * <p>Description: Tests for RFC24 implementation. (http://mapserver.gis.umn.edu/development/rfc/ms-rfc-24/)</p>
 * @author Umberto Nicoletti (umberto.nicoletti@gmail.com)
 */

class RFC24 {
	string mapfile;
	int fails = 0;

	public static void Main(string[] args) {
		new RFC24(args[0]).run();
	}
	
	public RFC24(string mapfile) {
		this.mapfile=mapfile;
	}
	
	public void run() {
		Console.WriteLine("Running RFC24");
		testLayerObj();
		testLayerObjDestroy();
		testClassObj();
		testClassObjDestroy();
		testInsertLayerObj();
		testInsertLayerObjDestroy();
		testRemoveLayerObj();
		testInsertClassObj();
		testInsertClassObjDestroy();
		testRemoveClassObj();
		testGetLayerObj();
		testGetLayerObjDestroy();
		testGetLayerObjByName();
		testGetLayerObjByNameDestroy();
		testGetClassObj();
		testGetClassObjDestroy();
		try { testStyleObj(); }
		catch (Exception e) { Console.WriteLine("\t- testStyleObj exception:" + e.Message); }
		testStyleObjDestroy();
		try { testInsertStyleObj(); }
		catch (Exception e) { Console.WriteLine("\t- testInsertStyleObj exception:" + e.Message); }
		testInsertStyleObjDestroy();
		testRemoveStyleObj();
		try { testGetStyleObj(); }
		catch (Exception e) { Console.WriteLine("\t- testGetStyleObj exception:" + e.Message); }
		testGetStyleObjDestroy();

		try { testlegendObj(); }
		catch (Exception e) { Console.WriteLine("\t- testlegendObj exception:" + e.Message); }
		try { testreferenceMapObj(); } 
		catch (Exception e) { Console.WriteLine("\t- testreferenceMapObj exception:" + e.Message); }
		try { testwebObj(); }
		catch (Exception e) { Console.WriteLine("\t- testwebObj exception:" + e.Message); }
		try { testqueryMapObj(); }
		catch (Exception e) { Console.WriteLine("\t- testqueryMapObj exception:" + e.Message); }
		try { testmapObjHashTable(); }
		catch (Exception e) { Console.WriteLine("\t- testmapObjHashTable exception:" + e.Message); }
		try { testsymbolSetObj(); }
		catch (Exception e) { Console.WriteLine("\t- testsymbolSetObj exception:" + e.Message); }
		try { testimageObj(); }
		catch (Exception e) { Console.WriteLine("\t- testimageObj exception:" + e.Message); }

		if (fails > 0)
			Console.WriteLine("\n     " + fails + " tests were FAILED!!!\n");

		Console.WriteLine("Finished RFC24");
	}

	public void testlegendObj() 
	{
		mapObj map=new mapObj(mapfile);
		legendObj legend = map.legend;
		legend.template = "This is a sample!";

		map=null;
		gc();	
		assert(legend.template == "This is a sample!", "testlegendObj");
	}

	public void testmapObjHashTable() 
	{
		mapObj map=new mapObj(mapfile);
		hashTableObj configoptions = map.configoptions;
		configoptions.set("key", "test value");

		map=null;
		gc();
	
		assert(configoptions.get("key", "") == "test value", "testmapObjHashTable");
	}

	public void testsymbolSetObj() 
	{
		mapObj map=new mapObj(mapfile);
		symbolSetObj symbolset = map.symbolset;
		symbolset.filename = "filename";

		map=null;
		gc();
	
		assert(symbolset.filename == "filename", "testsymbolSetObj");
	}

	public void testreferenceMapObj() 
	{
		mapObj map=new mapObj(mapfile);
		referenceMapObj refmap = map.reference;
		refmap.markername = "This is a sample!";

		map=null;
		gc();
	    assert(refmap.markername == "This is a sample!", "testreferenceMapObj");
	}

	public void testwebObj() 
	{
		mapObj map=new mapObj(mapfile);
		webObj web = map.web;
		web.template = "This is a sample!";

		map=null;
		gc();
		assert(web.template == "This is a sample!", "testwebObj");
	}

	public void testqueryMapObj() 
	{
		mapObj map=new mapObj(mapfile);
		queryMapObj querymap = map.querymap;
		querymap.color.setHex( "#13ba88" );

		map=null;
		gc();
		assert(querymap.color.toHex() == "#13ba88", "testqueryMapObj");
	}

	public void testimageObj() 
	{
		mapObj map=new mapObj(mapfile);
		imageObj image = map.draw();
		outputFormatObj format = image.format;
		format.setOption( "INTERLACE", "OFF");

		map=null;
		gc();
		assert(format.getOption("INTERLACE", "") == "OFF", "testimageObj");
	}
	
	public void testLayerObj() {
		mapObj map=new mapObj(mapfile);
		layerObj newLayer=new layerObj(map);

		map=null;
		gc();
		assertNotNull(newLayer.map, "testLayerObj");
		assert(newLayer.refcount == 2, "testLayerObj refcount");
	}

	public void testLayerObjDestroy() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj newLayer=new layerObj(map);
		layerObj reference = map.getLayer(map.numlayers-1);

		assert(newLayer.refcount == 3, "testLayerObjDestroy precondition");
		newLayer.Dispose(); // force the destruction for Mono on Windows because of the constructor overload
		newLayer = null;
		gc();
		assert(reference.refcount == 2, "testLayerObjDestroy");
	}
	
	public void testInsertLayerObj() {
		mapObj map=new mapObj(mapfile);
		layerObj newLayer=new layerObj(null);
		map.insertLayer(newLayer,-1);
		
		map=null;
		gc();
		assertNotNull(newLayer.map, "testInsertLayerObj");
		assert(newLayer.refcount == 2, "testInsertLayerObj refcount");
	}

	public void testInsertLayerObjDestroy() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj newLayer=new layerObj(null);
		map.insertLayer(newLayer,0);
		layerObj reference = map.getLayer(0);

		assert(newLayer.refcount == 3, "testInsertLayerObjDestroy precondition");
		newLayer.Dispose(); // force the destruction for Mono on Windows because of the constructor overload
		newLayer=null;
		gc();
		assert(reference.refcount == 2, "testInsertLayerObjDestroy");
	}

	public void testRemoveLayerObj() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj newLayer=new layerObj(null);
		map.insertLayer(newLayer,0);
		map.removeLayer(0);

		map=null;
		gc();
		assert(newLayer.refcount == 1, "testRemoveLayerObj");
	}
	
	public void testGetLayerObj() {
		mapObj map=new mapObj(mapfile);
		layerObj newLayer=map.getLayer(1);
		
		map=null;
		gc();
		assertNotNull(newLayer.map, "testGetLayerObj");
		assert(newLayer.refcount == 2, "testGetLayerObj refcount");
	}

	public void testGetLayerObjDestroy() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj newLayer=map.getLayer(1);
		layerObj reference = map.getLayer(1);
		
		assert(newLayer.refcount == 3, "testGetLayerObjDestroy precondition");
		//newLayer.Dispose(); // force the destruction needed for Mono on Windows
		newLayer=null;
		gc();
		assert(reference.refcount == 2, "testGetLayerObjDestroy");
	}

	public void testGetLayerObjByName() {
		mapObj map=new mapObj(mapfile);
		layerObj newLayer=map.getLayerByName("POLYGON");
		
		map=null;
		gc();
		assertNotNull(newLayer.map, "testGetLayerObjByName");
		assert(newLayer.refcount == 2, "testGetLayerObjByName refcount");
	}

	public void testGetLayerObjByNameDestroy() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj newLayer=map.getLayerByName("POLYGON");
		layerObj reference=map.getLayerByName("POLYGON");
		
		assert(newLayer.refcount == 3, "testGetLayerObjByNameDestroy precondition");
		//newLayer.Dispose(); // force the destruction needed for Mono on Windows
		newLayer=null;
		gc();
		assert(reference.refcount == 2, "testGetLayerObjByNameDestroy");
	}

	public void testClassObj() {
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj newClass=new classObj(layer);
		
		map=null; layer=null;
		gc();
		assertNotNull(newClass.layer, "testClassObj");
		assert(newClass.refcount == 2, "testClassObj refcount");
	}

	public void testClassObjDestroy() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj newClass=new classObj(layer);
		classObj reference=layer.getClass(layer.numclasses-1);
		
		assert(newClass.refcount == 3, "testClassObjDestroy precondition");
		newClass.Dispose(); // force the destruction for Mono on Windows because of the constructor overload
		map=null; layer=null; newClass=null;
		gc();
		assert(reference.refcount == 2, "testClassObjDestroy");
	}

	public void testStyleObj() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj classobj=layer.getClass(0);
		styleObj newStyle=new styleObj(classobj);
		
		map=null; layer=null; classobj=null;
		gc();
		assert(newStyle.refcount == 2, "testStyleObj");
	}

	public void testStyleObjDestroy() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj classobj=layer.getClass(0);
		styleObj newStyle=new styleObj(classobj);
		styleObj reference=classobj.getStyle(classobj.numstyles-1);
		
		assert(newStyle.refcount == 3, "testStyleObjDestroy");
		newStyle.Dispose(); // force the destruction for Mono on Windows because of the constructor overload
		map=null; layer=null; classobj=null; newStyle=null;
		gc();
		assert(reference.refcount == 2, "testStyleObjDestroy");
	}

	public void testInsertClassObj() {
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj newClass=new classObj(null);
		layer.insertClass(newClass,-1);
		
		assertNotNull(newClass.layer, "testInsertClassObj precondition");
		map=null; layer=null;
		gc();
		assertNotNull(newClass.layer, "testInsertClassObj");
		assert(newClass.refcount == 2, "testInsertClassObj refcount");
	}

	public void testRemoveClassObj() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj newClass=new classObj(null);
		layer.insertClass(newClass,0);
		layer.removeClass(0);
		
		map=null; layer=null;
		gc();
		assert(newClass.refcount == 1, "testRemoveClassObj");
	}

	public void testInsertClassObjDestroy() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj newClass=new classObj(null);
		layer.insertClass(newClass,0);
		classObj reference = layer.getClass(0);

		assert(newClass.refcount == 3, "testInsertClassObjDestroy precondition");
		newClass.Dispose(); // force the destruction for Mono on Windows because of the constructor overload
		map=null; layer=null; newClass=null;
		gc();
		assert(reference.refcount == 2, "testInsertClassObjDestroy");
	}

	public void testInsertStyleObj() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj classobj=layer.getClass(0);
		styleObj newStyle = new styleObj(null);
		classobj.insertStyle(newStyle,-1);
		
		assert(newStyle.refcount == 2, "testInsertStyleObj precondition");
		map=null; layer=null; classobj=null;
		gc();
		assert(newStyle.refcount == 2, "testInsertStyleObj");
	}

	public void testRemoveStyleObj() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj classobj=layer.getClass(0);
		styleObj newStyle = new styleObj(null);
		classobj.insertStyle(newStyle,0);
		classobj.removeStyle(0);
		
		map=null; layer=null; classobj=null;
		gc();
		assert(newStyle.refcount == 1, "testRemoveStyleObj");
	}

	public void testInsertStyleObjDestroy() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj classobj=layer.getClass(0);
		styleObj newStyle = new styleObj(null);
		classobj.insertStyle(newStyle,0);
		styleObj reference = classobj.getStyle(0);
		
		assert(newStyle.refcount == 3, "testInsertStyleObjDestroy precondition");
		newStyle.Dispose(); // force the destruction for Mono on Windows because of the constructor overload
		map=null; layer=null; classobj=null; newStyle=null;
		gc();
		assert(reference.refcount == 2, "testInsertStyleObjDestroy");
	}

	public void testGetClassObj() {
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj newClass=layer.getClass(0);
		
		map=null; layer=null;
		gc();
		assertNotNull(newClass.layer, "testGetClassObj");
		assert(newClass.refcount == 2, "testGetClassObj refcount");
	}

	public void testGetClassObjDestroy() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj newClass=layer.getClass(0);
		classObj reference = layer.getClass(0);
		
		assert(newClass.refcount == 3, "testGetClassObjDestroy precondition");
		map=null; layer=null; newClass=null;
		gc();
		assert(reference.refcount == 2, "testGetClassObjDestroy");
	}

	public void testGetStyleObj() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj classobj=layer.getClass(0);
		styleObj style=classobj.getStyle(0);
		
		map=null; layer=null; classobj=null;
		gc();
		assert(style.refcount == 2, "testGetStyleObj");
	}

	public void testGetStyleObjDestroy() 
	{
		mapObj map=new mapObj(mapfile);
		layerObj layer=map.getLayer(1);
		classObj classobj=layer.getClass(0);
		styleObj style=classobj.getStyle(0);
		styleObj reference=classobj.getStyle(0);
		
		assert(style.refcount == 3, "testGetStyleObjDestroy precondition");
		map=null; layer=null; classobj=null; style=null;
		gc();
		assert(reference.refcount == 2, "testGetStyleObjDestroy");
	}

	public void gc() {
		for (int i=0; i<100; i++) {
			GC.Collect();
			GC.WaitForPendingFinalizers();
		}
	}
	
	public void assertNotNull(object o, string test) {
		if ( o != null )
			Console.WriteLine("\t- "+test+" PASSED");
		else
		{
			Console.WriteLine("\t- "+test+" FAILED");
			++fails;
		}
	}

	public void assert(bool val, string test) 
	{
		if ( val )
			Console.WriteLine("\t- "+test+" PASSED");
		else
		{
			Console.WriteLine("\t- "+test+" FAILED");
			++fails;
		}
	}
}