bl_test_context_simple.cpp (3942B)
1 // This file is part of Blend2D project <https://blend2d.com> 2 // 3 // See blend2d.h or LICENSE.md for license and copyright information 4 // SPDX-License-Identifier: Zlib 5 6 #include <blend2d.h> 7 #include <cmath> 8 #include <stdio.h> 9 #include <stdlib.h> 10 #include <string.h> 11 12 #include "bl_test_context_baseapp.h" 13 #include "bl_test_context_utilities.h" 14 15 #include "../commons/imagediff.h" 16 #include "../resources/abeezee_regular_ttf.h" 17 18 namespace ContextTests { 19 20 class SimpleTestApp : public BaseTestApp { 21 public: 22 SimpleTestApp() 23 : BaseTestApp() {} 24 25 int help() { 26 using StringUtils::bool_to_string; 27 28 printf("Usage:\n"); 29 printf(" bl_test_context_simple [options] [--help for help]\n"); 30 printf("\n"); 31 32 printf("Purpose:\n"); 33 printf(" Simple rendering context tester is designed to verify whether the rendering\n"); 34 printf(" context can process input commands without crashing or causing undefined\n"); 35 printf(" behavior. It's also designed to be run with instrumentation such as ASAN,\n"); 36 printf(" UBSAN, MSAN, and Valgrind.\n"); 37 printf("\n"); 38 printf(" Simple rendering context tester doesn't do any verification of the rendered\n"); 39 printf(" output like other testers do, because it's not its purpose.\n"); 40 printf("\n"); 41 42 print_common_options(default_options); 43 print_commands(); 44 print_formats(); 45 print_comp_ops(); 46 print_opacity_ops(); 47 print_style_ids(); 48 print_style_ops(); 49 50 fflush(stdout); 51 return 0; 52 } 53 54 int run(CmdLine cmd_line) { 55 print_app_info("Blend2D Rendering Context Tester", cmd_line.has_arg("--quiet")); 56 57 if (cmd_line.has_arg("--help")) 58 return help(); 59 60 if (!parse_common_options(cmd_line)) 61 return 1; 62 63 for (BLFormat format : test_cases.format_ids) { 64 ContextTester tester(test_cases, "simple"); 65 66 tester.seed(options.seed); 67 tester.set_font_data(font_data); 68 tester.set_flush_sync(options.flush_sync); 69 70 BLContextCreateInfo cci {}; 71 cci.thread_count = options.thread_count; 72 73 if (tester.init(int(options.width), int(options.height), format, cci) != BL_SUCCESS) { 74 printf("Failed to initialize the rendering context\n"); 75 return 1; 76 } 77 78 TestInfo info; 79 dispatch_runs([&](CommandId command_id, StyleId style_id, StyleOp style_op, CompOp comp_op, OpacityOp opacity_op) { 80 BLString s0; 81 s0.append_format("%s/%s", 82 StringUtils::style_id_to_string(style_id), 83 StringUtils::style_op_to_string(style_op)); 84 85 BLString s1; 86 s1.append_format("%s/%s", 87 StringUtils::comp_op_to_string(comp_op), 88 StringUtils::opacity_op_to_string(opacity_op)); 89 90 info.name.assign_format( 91 "%-21s | fmt=%-7s| style+api=%-30s| comp+op=%-20s", 92 StringUtils::command_id_to_string(command_id), 93 StringUtils::format_to_string(format), 94 s0.data(), 95 s1.data()); 96 97 if (!options.quiet) { 98 printf("Running [%s]\n", info.name.data()); 99 } 100 101 info.id.assign_format("ctx-simple-%s-%s-%s-%s-%s-%s", 102 StringUtils::format_to_string(format), 103 StringUtils::command_id_to_string(command_id), 104 StringUtils::style_id_to_string(style_id), 105 StringUtils::style_op_to_string(style_op), 106 StringUtils::comp_op_to_string(comp_op), 107 StringUtils::opacity_op_to_string(opacity_op)); 108 109 tester.clear(); 110 tester.set_options(comp_op, opacity_op, style_id, options.style_op); 111 tester.render(command_id, options.count, options); 112 113 if (options.store_images) { 114 store_image(tester.image(), info.id.data()); 115 } 116 }); 117 118 tester.reset(); 119 } 120 121 printf("Testing finished...\n"); 122 return 0; 123 } 124 }; 125 126 } // {ContextTests} 127 128 int main(int argc, char* argv[]) { 129 BLRuntimeScope rt_scope; 130 ContextTests::SimpleTestApp app; 131 132 return app.run(CmdLine(argc, argv)); 133 }