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_edit_point = new Test.time ("EditPoint creation"); 64 65 for (uint i = 0; i < 3000; i++) { 66 for (uint j = 0; j < 300; j++) { 67 EditPoint ep = new EditPoint (); 68 ep.ref (); 69 ep.unref (); 70 } 71 } 72 73 test_edit_point.print (); 74 75 Test test_path = new Test.time ("Simple path creation"); 76 77 for (uint i = 0; i < 3000; i++) { 78 for (uint j = 0; j < 300; j++) { 79 Path p = new Path (); 80 p.ref (); 81 p.unref (); 82 } 83 } 84 85 test_path.print (); 86 87 Test test_points = new Test.time ("Simple path with points"); 88 89 for (int i = 0; i < 3000; i++) { 90 Path p = new Path (); 91 for (int j = 0; j < 300; j++) { 92 p.add (0, 0); 93 } 94 } 95 96 test_points.print (); 97 98 Test test_cairo = new Test.time ("Simple Cairo"); 99 100 for (int i = 0; i < 300; i++) { 101 ImageSurface s; 102 Context c; 103 104 s = Screen.create_background_surface (1000, 1000); 105 c = new Context (s); 106 107 for (int j = 0; j < 300; j++) { 108 c.save (); 109 c.rectangle (100, 100, 100, 100); 110 c.fill (); 111 c.restore (); 112 } 113 } 114 115 test_cairo.print (); 116 117 118 Test test_toolbox = new Test.time ("Toolbox"); 119 120 for (int i = 0; i < 3000; i++) { 121 ImageSurface s; 122 Context c; 123 124 s = Screen.create_background_surface (1000, 1000); 125 c = new Context (s); 126 MainWindow.get_toolbox ().draw (300, 500, c); 127 } 128 129 test_toolbox.print (); 130 131 Test test_tool_drawing = new Test.time ("Draw Tool"); 132 133 for (int i = 0; i < 3000; i++) { 134 ImageSurface s; 135 Context c; 136 Tool tool; 137 138 tool = new Tool (); 139 s = Screen.create_background_surface (100, 100); 140 c = new Context (s); 141 MainWindow.get_toolbox ().draw (300, 500, c); 142 } 143 144 test_tool_drawing.print (); 145 146 Test test_tool = new Test.time ("Create Tool"); 147 148 for (int i = 0; i < 3000; i++) { 149 Tool tool; 150 tool = new Tool (); 151 tool.set_tool_visibility (true); 152 } 153 154 test_tool.print (); 155 156 157 Test test_text = new Test.time ("Text"); 158 159 for (int i = 0; i < 30; i++) { 160 ImageSurface s; 161 Context c; 162 163 s = Screen.create_background_surface (100, 100); 164 c = new Context (s); 165 166 Text text = new Text ("This is a test."); 167 text.draw_at_top (c, 0, 0); 168 } 169 170 test_text.print (); 171 } 172 173 public void file_chooser (string title, FileChooser file_chooser_callback, uint flags) { 174 } 175 176 public void update_window_size () { 177 } 178 179 public string get_clipboard_data (){ 180 return ""; 181 } 182 183 public void set_clipboard (string data) { 184 } 185 186 public void set_inkscape_clipboard (string data) { 187 } 188 189 public void set_scrollbar_size (double size) { 190 } 191 192 public void set_scrollbar_position (double position) { 193 } 194 195 public void font_loaded () { 196 } 197 198 public void quit () { 199 Process.exit (0); 200 } 201 202 public bool convert_to_png (string from, string to) { 203 return false; 204 } 205 206 public void export_font () { 207 } 208 209 public void load () { 210 } 211 212 public void save () { 213 } 214 215 public void load_background_image () { 216 } 217 218 public void run_background_thread (Task t) { 219 unowned Thread<void*> bg; 220 221 MenuTab.start_background_thread (); 222 223 try { 224 bg = Thread.create<void*> (t.perform_task, true); 225 } catch (GLib.Error e) { 226 warning (e.message); 227 } 228 } 229 230 public void run_non_blocking_background_thread (Task t) { 231 unowned Thread<void*> bg; 232 233 try { 234 bg = Thread.create<void*> (t.perform_task, true); 235 } catch (GLib.Error e) { 236 warning (e.message); 237 } 238 } 239 240 public void set_clipboard_text (string text) { 241 } 242 243 public string get_clipboard_text () { 244 return ""; 245 } 246 247 public bool can_export () { 248 return true; 249 } 250 251 public void set_cursor (int visible) { 252 } 253 254 public double get_screen_scale () { 255 return 1; 256 } 257 } 258 259 } 260 261 public static int main (string[] arg) { 262 TestRunner runner; 263 MainWindow window; 264 BirdFont.BirdFont birdfont; 265 string[] birdfont_args = new string[1]; 266 267 birdfont_args[0] = arg[0]; 268 birdfont = new BirdFont.BirdFont (); 269 birdfont.init (birdfont_args, null, "birdfont"); 270 271 window = new MainWindow (); 272 runner = new TestRunner (); 273 274 window.set_native (runner); 275 TestRunner.run (arg); 276 277 return 0; 278 } 279