comparison nodejs/examples/simple/testleak.js @ 939:a74b4d986a91

Move examples for nodejs into nodejs/examples/ sub-directories. See INSTALL.txt. Use nodejs/examples/run.sh to run examples. For example, cd nodejs/examples; ./run.sh examples/testsvg/testsvg.js
author Thinker K.F. Li <thinker@codemud.net>
date Fri, 12 Nov 2010 17:39:04 +0800
parents nodejs/testleak.js@586e50f82c1f
children
comparison
equal deleted inserted replaced
938:13b9acbbe9a3 939:a74b4d986a91
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*-
2 // vim: sw=4:ts=8:sts=4
3 var mbfly = require("mbfly");
4 var sys = require("sys");
5 var cproc = require("child_process");
6
7 function testcase1() {
8 var mbrt = new mbfly.mb_rt(":32.0", 300, 200);
9 var root = mbrt.root;
10 var coords = [];
11 var coord;
12 var i;
13
14 while(true) {
15 for(i = 0; i < 200; i++) {
16 coords.push(mbrt.coord_new(root));
17 }
18 mbrt.redraw_changed();
19 mbrt.flush();
20
21 while(coords.length > 0) {
22 coord = coords.pop();
23 coord.remove();
24 }
25 }
26 }
27
28 function testcase2() {
29 var mbrt = new mbfly.mb_rt(":32.0", 300, 200);
30 var root = mbrt.root;
31 var coords = [];
32 var coord;
33 var i, j;
34
35 while(true) {
36 for(i = 0; i < 200; i++) {
37 coords.push(mbrt.coord_new(root));
38 for(j = 0; j < 10; j++)
39 coord = mbrt.coord_new(coords[i]);
40 }
41 mbrt.redraw_changed();
42 mbrt.flush();
43
44 while(coords.length > 0) {
45 coord = coords.pop();
46 coord.remove();
47 }
48 }
49 }
50
51 function testcase3() {
52 var mbrt = new mbfly.mb_rt(":32.0", 300, 200);
53 var root = mbrt.root;
54 var coords = [];
55 var coord;
56 var shape;
57 var i, j;
58
59 while(true) {
60 for(i = 0; i < 200; i++) {
61 coords.push(mbrt.coord_new(root));
62 for(j = 0; j < 10; j++) {
63 coord = mbrt.coord_new(coords[i]);
64 shape = mbrt.rect_new(15, 15, 20, 20, 0, 0);
65 coord.add_shape(shape);
66 }
67 }
68 mbrt.redraw_changed();
69 mbrt.flush();
70
71 while(coords.length > 0) {
72 coord = coords.pop();
73 coord.remove();
74 }
75 }
76 }
77
78 function testcase4() {
79 var mbrt = new mbfly.mb_rt(":32.0", 300, 200);
80 var root = mbrt.root;
81 var coords = [];
82 var coord;
83 var shape;
84 var i, j;
85
86 while(true) {
87 for(i = 0; i < 200; i++) {
88 coords.push(mbrt.coord_new(root));
89 for(j = 0; j < 10; j++) {
90 coord = mbrt.coord_new(coords[i]);
91 shape = mbrt.path_new("m 10,10 l 55,27 l -30,-3 z");
92 coord.add_shape(shape);
93 }
94 }
95 mbrt.redraw_changed();
96 mbrt.flush();
97
98 while(coords.length > 0) {
99 coord = coords.pop();
100 coord.remove();
101 }
102 }
103 }
104
105 function testcase5() {
106 var mbrt = new mbfly.mb_rt(":32.0", 300, 200);
107 var root = mbrt.root;
108 var paint;
109
110 while(true) {
111 paint = mbrt.paint_color_new(0.5, 0.5, 0.5, 1);
112 }
113 }
114
115 function testcase6() {
116 var mbrt = new mbfly.mb_rt(":32.0", 300, 200);
117 var root = mbrt.root;
118 var coords = [];
119 var coord;
120 var shape;
121 var paint;
122 var i, j;
123
124 while(true) {
125 for(i = 0; i < 200; i++) {
126 coords.push(mbrt.coord_new(root));
127 /* Paint is free, but rdman is dirty */
128 paint = mbrt.paint_color_new(0.5, 0.5, 0.5, 1);
129 for(j = 0; j < 10; j++) {
130 coord = mbrt.coord_new(coords[i]);
131 shape = mbrt.rect_new(5, 5, 20, 20, 0, 0);
132 coord.add_shape(shape);
133 }
134 }
135 mbrt.redraw_changed();
136 mbrt.flush();
137
138 while(coords.length > 0) {
139 coord = coords.pop();
140 coord.remove();
141 }
142 }
143 }
144
145 function testcase7() {
146 var mbrt = new mbfly.mb_rt(":32.0", 300, 200);
147 var root = mbrt.root;
148 var coords = [];
149 var coord;
150 var shape;
151 var paint;
152 var i, j;
153
154 while(true) {
155 for(i = 0; i < 200; i++) {
156 coords.push(mbrt.coord_new(root));
157 for(j = 0; j < 10; j++) {
158 /* paint is not free, and rdman is dirty */
159 paint = mbrt.paint_color_new(0.5, 0.5, 0.5, 1);
160 coord = mbrt.coord_new(coords[i]);
161 shape = mbrt.path_new("M 100,100 L 30,30 L 0,30 z");
162 coord.add_shape(shape);
163 paint.stroke(shape);
164 }
165 }
166 mbrt.redraw_changed();
167 mbrt.flush();
168
169 while(coords.length > 0) {
170 coord = coords.pop();
171 coord.remove();
172 }
173 }
174 }
175
176 cproc.exec("killall -9 Xvfb; Xvfb :32 -screen 0 800x600x24");
177 setTimeout(function() {
178 if(process.argv.length == 1)
179 testcase1();
180 else if(process.argv.length == 3) {
181 sys.puts("testcase " + process.argv[2]);
182 switch(process.argv[2]) {
183 case "1":
184 testcase1();
185 break;
186
187 case "2":
188 testcase2();
189 break;
190
191 case "3":
192 testcase3();
193 break;
194
195 case "4":
196 testcase4();
197 break;
198
199 case "5":
200 testcase5();
201 break;
202
203 case "6":
204 testcase6();
205 break;
206
207 case "7":
208 testcase7();
209 break;
210
211 default:
212 sys.puts("Usage: node testleak.js [1|2|3...7]");
213 }
214 } else
215 sys.puts("Usage: node testleak.js [1|2|3...7]");
216 cproc.exec("killall -9 Xvfb");
217 }, 1500);