The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

TestRunner.vala in birdfont-test

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git

Revisions

View the latest version of birdfont-test/TestRunner.vala.
Remove old benchmark
1 using BirdFont; 2 using Cairo; 3 4 namespace BirdFont { 5 6 public class TestRunner : NativeWindow, GLib.Object { 7 8 public static void run (string[] args) { 9 if (args.length < 2) { 10 print_usage (args); 11 Process.exit (0); 12 } 13 14 string type = args[1]; 15 16 if (type == "SVG" || type == "BF") { 17 fuzz_test (args); 18 } else if (type == "speed") { 19 speed_test (); 20 } else { 21 print_usage (args); 22 } 23 24 } 25 26 static void print_usage (string[] args) { 27 print ("Usage: " + args[0] + " TEST FILE\n"); 28 print ("TEST parameter can be BF SVG or speed\n"); 29 } 30 31 public static void fuzz_test (string[] arg) { 32 return_if_fail (arg.length == 3); 33 34 string type = arg[1]; 35 string file = arg[2]; 36 37 if (type == "SVG") { 38 File f = File.new_for_path (file); 39 Font font = new Font (); 40 import_svg_file (font, f); 41 } else if (type == "BF") { 42 Font font = new Font (); 43 font.set_font_file (file); 44 font.load (); 45 } 46 47 Process.exit (0); 48 } 49 50 static void speed_test () { 51 Test test_object = new Test.time ("GObject"); 52 53 for (uint i = 0; i < 3000; i++) { 54 for (uint j = 0; j < 300; j++) { 55 GLib.Object o = new GLib.Object (); 56 o.ref (); 57 o.unref (); 58 } 59 } 60 61 test_object.print (); 62 63 Test test_ref = new Test.time ("GObject ref"); 64 65 for (uint i = 0; i < 3000; i++) { 66 for (uint k = 0; k < 300; k++) { 67 GLib.Object o = new GLib.Object (); 68 69 for (int j = 0; j < 7; j++) { 70 o.ref (); 71 } 72 73 for (int j = 0; j < 7; j++) { 74 o.unref (); 75 } 76 } 77 } 78 79 test_ref.print (); 80 81 Test test_edit_point = new Test.time ("EditPoint creation"); 82 83 for (uint i = 0; i < 3000; i++) { 84 for (uint j = 0; j < 300; j++) { 85 EditPoint ep = new EditPoint (); 86 ep.ref (); 87 ep.unref (); 88 } 89 } 90 91 test_edit_point.print (); 92 93 Test test_path = new Test.time ("Simple path creation"); 94 95 for (uint i = 0; i < 3000; i++) { 96 for (uint j = 0; j < 300; j++) { 97 Path p = new Path (); 98 p.ref (); 99 p.unref (); 100 } 101 } 102 103 test_path.print (); 104 105 Test test_points = new Test.time ("Simple path with points"); 106 107 for (int i = 0; i < 3000; i++) { 108 Path p = new Path (); 109 for (int j = 0; j < 300; j++) { 110 p.add (0, 0); 111 } 112 } 113 114 test_points.print (); 115 116 Test test_cairo = new Test.time ("Simple Cairo"); 117 118 for (int i = 0; i < 300; i++) { 119 ImageSurface s; 120 Context c; 121 122 s = Screen.create_background_surface (1000, 1000); 123 c = new Context (s); 124 125 for (int j = 0; j < 300; j++) { 126 c.save (); 127 c.rectangle (100, 100, 100, 100); 128 c.fill (); 129 c.restore (); 130 } 131 } 132 133 test_cairo.print (); 134 135 136 Test test_toolbox = new Test.time ("Toolbox"); 137 138 for (int i = 0; i < 3000; i++) { 139 ImageSurface s; 140 Context c; 141 142 s = Screen.create_background_surface (1000, 1000); 143 c = new Context (s); 144 MainWindow.get_toolbox ().draw (300, 500, c); 145 } 146 147 test_toolbox.print (); 148 149 Test test_tool_drawing = new Test.time ("Draw Tool"); 150 151 for (int i = 0; i < 3000; i++) { 152 ImageSurface s; 153 Context c; 154 Tool tool; 155 156 tool = new Tool (); 157 s = Screen.create_background_surface (100, 100); 158 c = new Context (s); 159 MainWindow.get_toolbox ().draw (300, 500, c); 160 } 161 162 test_tool_drawing.print (); 163 164 Test test_tool = new Test.time ("Create Tool"); 165 166 for (int i = 0; i < 3000; i++) { 167 Tool tool; 168 tool = new Tool (); 169 tool.set_tool_visibility (true); 170 } 171 172 test_tool.print (); 173 174 175 Test test_text = new Test.time ("Text"); 176 177 for (int i = 0; i < 30; i++) { 178 ImageSurface s; 179 Context c; 180 181 s = Screen.create_background_surface (100, 100); 182 c = new Context (s); 183 184 Text text = new Text ("This is a test."); 185 text.draw_at_top (c, 0, 0); 186 } 187 188 test_text.print (); 189 } 190 191 public void file_chooser (string title, FileChooser file_chooser_callback, uint flags) { 192 } 193 194 public void update_window_size () { 195 } 196 197 public string get_clipboard_data (){ 198 return ""; 199 } 200 201 public void set_clipboard (string data) { 202 } 203 204 public void set_inkscape_clipboard (string data) { 205 } 206 207 public void set_scrollbar_size (double size) { 208 } 209 210 public void set_scrollbar_position (double position) { 211 } 212 213 public void font_loaded () { 214 } 215 216 public void quit () { 217 Process.exit (0); 218 } 219 220 public bool convert_to_png (string from, string to) { 221 return false; 222 } 223 224 public void export_font () { 225 } 226 227 public void load () { 228 } 229 230 public void save () { 231 } 232 233 public void load_background_image () { 234 } 235 236 public void run_background_thread (Task t) { 237 unowned Thread<void*> bg; 238 239 MenuTab.start_background_thread (); 240 241 try { 242 bg = Thread.create<void*> (t.perform_task, true); 243 } catch (GLib.Error e) { 244 warning (e.message); 245 } 246 } 247 248 public void run_non_blocking_background_thread (Task t) { 249 unowned Thread<void*> bg; 250 251 try { 252 bg = Thread.create<void*> (t.perform_task, true); 253 } catch (GLib.Error e) { 254 warning (e.message); 255 } 256 } 257 258 public void set_clipboard_text (string text) { 259 } 260 261 public string get_clipboard_text () { 262 return ""; 263 } 264 265 public bool can_export () { 266 return true; 267 } 268 269 public void set_cursor (int visible) { 270 } 271 272 public double get_screen_scale () { 273 return 1; 274 } 275 } 276 277 } 278 279 public static int main (string[] arg) { 280 TestRunner runner; 281 MainWindow window; 282 BirdFont.BirdFont birdfont; 283 string[] birdfont_args = new string[1]; 284 285 birdfont_args[0] = arg[0]; 286 birdfont = new BirdFont.BirdFont (); 287 birdfont.init (birdfont_args, null, "birdfont"); 288 289 window = new MainWindow (); 290 runner = new TestRunner (); 291 292 window.set_native (runner); 293 TestRunner.run (arg); 294 295 return 0; 296 } 297