[mapserver-commits] r7209 -
trunk/mapserver/mapscript/csharp/examples
svn at osgeo.org
svn at osgeo.org
Sun Dec 23 15:29:33 EST 2007
Author: tamas
Date: 2007-12-23 15:29:33 -0500 (Sun, 23 Dec 2007)
New Revision: 7209
Modified:
trunk/mapserver/mapscript/csharp/examples/RFC24.cs
Log:
Added tests for the object destruction
Modified: trunk/mapserver/mapscript/csharp/examples/RFC24.cs
===================================================================
--- trunk/mapserver/mapscript/csharp/examples/RFC24.cs 2007-12-22 22:19:55 UTC (rev 7208)
+++ trunk/mapserver/mapscript/csharp/examples/RFC24.cs 2007-12-23 20:29:33 UTC (rev 7209)
@@ -9,6 +9,7 @@
class RFC24 {
string mapfile;
+ int fails = 0;
public static void Main(string[] args) {
new RFC24(args[0]).run();
@@ -21,12 +22,29 @@
public void run() {
Console.WriteLine("Running RFC24");
testLayerObj();
+ testLayerObjDestroy();
testClassObj();
+ testClassObjDestroy();
testInsertLayerObj();
+ testInsertLayerObjDestroy();
testInsertClassObj();
+ testInsertClassObjDestroy();
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();
+ 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(); }
@@ -41,12 +59,10 @@
catch (Exception e) { Console.WriteLine("\t- testsymbolSetObj exception:" + e.Message); }
try { testimageObj(); }
catch (Exception e) { Console.WriteLine("\t- testimageObj exception:" + e.Message); }
- try { testStyleObj(); }
- catch (Exception e) { Console.WriteLine("\t- testStyleObj exception:" + e.Message); }
- try { testInsertStyleObj(); }
- catch (Exception e) { Console.WriteLine("\t- testInsertStyleObj exception:" + e.Message); }
- try { testGetStyleObj(); }
- catch (Exception e) { Console.WriteLine("\t- testGetStyleObj exception:" + e.Message); }
+
+ if (fails > 0)
+ Console.WriteLine("\n " + fails + " tests were FAILED!!!\n");
+
Console.WriteLine("Finished RFC24");
}
@@ -139,6 +155,18 @@
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(reference.refcount == 3, "testLayerObjDestroy precondition");
+ newLayer=null;
+ gc();
+ assert(reference.refcount == 2, "testLayerObjDestroy");
+ }
public void testInsertLayerObj() {
mapObj map=new mapObj(mapfile);
@@ -150,6 +178,19 @@
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(reference.refcount == 3, "testInsertLayerObjDestroy precondition");
+ newLayer=null;
+ gc();
+ assert(reference.refcount == 2, "testInsertLayerObjDestroy");
+ }
public void testGetLayerObj() {
mapObj map=new mapObj(mapfile);
@@ -161,6 +202,18 @@
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(reference.refcount == 3, "testGetLayerObjDestroy precondition");
+ newLayer=null;
+ gc();
+ assert(reference.refcount == 2, "testGetLayerObjDestroy");
+ }
+
public void testGetLayerObjByName() {
mapObj map=new mapObj(mapfile);
layerObj newLayer=map.getLayerByName("POLYGON");
@@ -171,6 +224,18 @@
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(reference.refcount == 3, "testGetLayerObjByNameDestroy precondition");
+ newLayer=null;
+ gc();
+ assert(reference.refcount == 2, "testGetLayerObjByNameDestroy");
+ }
+
public void testClassObj() {
mapObj map=new mapObj(mapfile);
layerObj layer=map.getLayer(1);
@@ -182,6 +247,19 @@
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(reference.refcount == 3, "testClassObjDestroy precondition");
+ map=null; layer=null; newClass=null;
+ gc();
+ assert(reference.refcount == 2, "testClassObjDestroy precondition");
+ }
+
public void testStyleObj()
{
mapObj map=new mapObj(mapfile);
@@ -194,6 +272,20 @@
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(reference.refcount == 3, "testStyleObjDestroy");
+ 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);
@@ -207,6 +299,20 @@
assert(newClass.refcount == 2, "testInsertClassObj refcount");
}
+ 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(reference.refcount == 3, "testInsertClassObjDestroy precondition");
+ map=null; layer=null; newClass=null;
+ gc();
+ assert(reference.refcount == 2, "testInsertClassObjDestroy");
+ }
+
public void testInsertStyleObj()
{
mapObj map=new mapObj(mapfile);
@@ -221,6 +327,21 @@
assert(newStyle.refcount == 2, "testInsertStyleObj");
}
+ 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(reference.refcount == 3, "testInsertStyleObjDestroy precondition");
+ 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);
@@ -232,6 +353,19 @@
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(reference.refcount == 3, "testGetClassObjDestroy precondition");
+ map=null; layer=null; newClass=null;
+ gc();
+ assert(reference.refcount == 2, "testGetClassObjDestroy");
+ }
+
public void testGetStyleObj()
{
mapObj map=new mapObj(mapfile);
@@ -244,6 +378,20 @@
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(reference.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();
@@ -255,7 +403,10 @@
if ( o != null )
Console.WriteLine("\t- "+test+" PASSED");
else
+ {
Console.WriteLine("\t- "+test+" FAILED");
+ ++fails;
+ }
}
public void assert(bool val, string test)
@@ -263,6 +414,9 @@
if ( val )
Console.WriteLine("\t- "+test+" PASSED");
else
+ {
Console.WriteLine("\t- "+test+" FAILED");
+ ++fails;
+ }
}
}
More information about the mapserver-commits
mailing list