int test_brush_load_inputs(void *user_data) { char *input_json = read_file("brushes/modelling.myb"); float opaque_speed2[] = {0.0, 0.28, 0.518519, 0.032083, 1.888889, -0.16625, 4.0, -0.28}; Input opaque_setting_inputs[1]; opaque_setting_inputs[0].cname = "speed2"; opaque_setting_inputs[0].mapping_points = opaque_speed2; opaque_setting_inputs[0].no_mapping_points = 4; float opaque_multiply_pressure[] = { 0.0, 0.0, 1.0, 0.52}; Input opaque_multiply_setting_inputs[1]; opaque_multiply_setting_inputs[0].cname = "pressure"; opaque_multiply_setting_inputs[0].mapping_points = opaque_multiply_pressure; opaque_multiply_setting_inputs[0].no_mapping_points = 2; float radius_logarithmic_pressure[] = {0.0, 0.326667, 1.0, -0.49}; float radius_logarithmic_speed1[] = {0.0, 0.0, 1.0, 0.75}; float radius_logarithmic_speed2[] = { 0.0, -0.15, 4.0, 1.05}; Input radius_logarithmic_setting_inputs[] = { {"pressure", 2, radius_logarithmic_pressure}, {"speed1", 2, radius_logarithmic_speed1}, {"speed2", 2, radius_logarithmic_speed2} }; float smudge_pressure[] = {0.0, -0.0, 0.290123, -0.0375, 0.645062, -0.15, 1.0, -0.4}; Input smudge_setting_inputs[] = { {"pressure", 4, smudge_pressure} }; Inputs expected_inputs[] = { {"anti_aliasing", 0, NULL}, {"change_color_h", 0, NULL}, {"change_color_hsl_s", 0, NULL}, {"change_color_hsv_s", 0, NULL}, {"change_color_l", 0, NULL}, {"change_color_v", 0, NULL}, {"color_h", 0, NULL}, {"color_s", 0, NULL}, {"color_v", 0, NULL}, {"colorize", 0, NULL}, {"custom_input", 0, NULL}, {"custom_input_slowness", 0, NULL}, {"dabs_per_actual_radius", 0, NULL}, {"dabs_per_basic_radius", 0, NULL}, {"dabs_per_second", 0, NULL}, {"direction_filter", 0, NULL}, {"elliptical_dab_angle", 0, NULL}, {"elliptical_dab_ratio", 0, NULL}, {"eraser", 0, NULL}, {"hardness", 0, NULL}, {"lock_alpha", 0, NULL}, {"offset_by_random", 0, NULL}, {"offset_by_speed", 0, NULL}, {"offset_by_speed_slowness", 0, NULL}, {"opaque", 1, opaque_setting_inputs}, {"opaque_linearize", 0, NULL}, {"opaque_multiply", 1, opaque_multiply_setting_inputs}, {"radius_by_random", 0, NULL}, {"radius_logarithmic", 3, radius_logarithmic_setting_inputs}, {"restore_color", 0, NULL}, {"slow_tracking", 0, NULL}, {"slow_tracking_per_dab", 0, NULL}, {"smudge", 1, smudge_setting_inputs}, {"smudge_length", 0, NULL}, {"smudge_radius_log", 0, NULL}, {"speed1_gamma", 0, NULL}, {"speed1_slowness", 0, NULL}, {"speed2_gamma", 0, NULL}, {"speed2_slowness", 0, NULL}, {"stroke_duration_logarithmic", 0, NULL}, {"stroke_holdtime", 0, NULL}, {"stroke_threshold", 0, NULL}, {"tracking_noise", 0, NULL} }; int number_of_expected_inputs = sizeof(expected_inputs) / sizeof(Inputs); expect_int(MYPAINT_BRUSH_SETTINGS_COUNT, number_of_expected_inputs, "Warning: number of values tested does not match number of settings. Update test!"); MyPaintBrush *brush = mypaint_brush_new(); mypaint_brush_from_string(brush, input_json); int passed = 1; // Check input/dynamics values for (int i=0; i<number_of_expected_inputs; i++) { const Inputs *inputs = &expected_inputs[i]; MyPaintBrushSetting setting_id = mypaint_brush_setting_from_cname(inputs->cname); int correct = 1; if (inputs->inputs == NULL) { gboolean is_constant = mypaint_brush_is_constant(brush, setting_id); correct = expect_true(is_constant, "Setting %s should be constant (have 0 inputs)"); // TODO: expand %s for nicer errors } else { int number_of_inputs = inputs->no_inputs; expect_int(number_of_inputs, mypaint_brush_get_inputs_used_n(brush, setting_id), ""); for (int i=0; i<number_of_inputs; i++) { const Input *input = &(inputs->inputs[i]); //const char *input_name = input->cname; MyPaintBrushInput input_id = mypaint_brush_input_from_cname(input->cname); int expected_number_of_mapping_points = input->no_mapping_points; int actual_number_of_mapping_points = mypaint_brush_get_mapping_n(brush, setting_id, input_id); if (!expect_int(expected_number_of_mapping_points, actual_number_of_mapping_points, "Mapping points. ")) { correct = 0; } for (int i=0; i<expected_number_of_mapping_points; i++) { float expected_x = input->mapping_points[i*2]; float expected_y = input->mapping_points[(i*2)+1]; float actual_x; float actual_y; mypaint_brush_get_mapping_point(brush, setting_id, input_id, i, &actual_x, &actual_y); if (!expect_float(expected_x, actual_x, "")) correct = 0; if (!expect_float(expected_y, actual_y, "")) correct = 0; } } } if (correct != 1) { passed = 0; } } mypaint_brush_unref(brush); return passed; }
int test_brush_load_base_values(void *user_data) { char *input_json = read_file("brushes/impressionism.myb"); BaseValue expected_base_values[] = { {"anti_aliasing", 0.66}, {"change_color_h", 0.0}, {"change_color_hsl_s", 0.0}, {"change_color_hsv_s", 0.0}, {"change_color_l", 0.0}, {"change_color_v", 0.0}, {"color_h", 0.0}, {"color_s", 0.0}, {"color_v", 0.0}, {"colorize", 0.0}, {"custom_input", 0.0}, {"custom_input_slowness", 0.0}, {"dabs_per_actual_radius", 6.0}, {"dabs_per_basic_radius", 6.0}, {"dabs_per_second", 80.0}, {"direction_filter", 2.0}, {"elliptical_dab_angle", 0.0}, {"elliptical_dab_ratio", 7.1}, {"eraser", 0.0}, {"hardness", 0.8}, {"lock_alpha", 0.0}, {"offset_by_random", 0.6}, {"offset_by_speed", 0.0}, {"offset_by_speed_slowness", 1.0}, {"opaque", 1.0}, {"opaque_linearize", 0.9}, {"opaque_multiply", 0.0}, {"radius_by_random", 0.0}, {"radius_logarithmic", 2.0}, {"restore_color", 0.0}, {"slow_tracking", 0.0}, {"slow_tracking_per_dab", 0.0}, {"smudge", 0.9}, {"smudge_length", 0.0}, {"smudge_radius_log", 0.0}, {"speed1_gamma", 4.0}, {"speed1_slowness", 0.04}, {"speed2_gamma", 4.0}, {"speed2_slowness", 0.8}, {"stroke_duration_logarithmic", 6.0}, {"stroke_holdtime", 10.0}, {"stroke_threshold", 0.0}, {"tracking_noise", 0.2} }; int number_of_expected_base_values = sizeof(expected_base_values) / sizeof(BaseValue); expect_int(MYPAINT_BRUSH_SETTINGS_COUNT, number_of_expected_base_values, "Warning: Number of base values tested does not match number of settings. Update the test!"); MyPaintBrush *brush = mypaint_brush_new(); mypaint_brush_from_string(brush, input_json); int passed = 1; // Check base values for (int i=0; i<number_of_expected_base_values; i++) { const BaseValue *base_value = &expected_base_values[i]; int correct = -1; MyPaintBrushSetting id = mypaint_brush_setting_from_cname(base_value->cname); float expected = base_value->base_value; float actual = mypaint_brush_get_base_value(brush, id); correct = expect_float(expected, actual, "Wrong base value for %s"); // TODO: expand %s for nicer errors if (!correct) { passed = 0; } } mypaint_brush_unref(brush); return passed; }
static void test_getregiondata(void) { GpStatus status; GpRegion *region, *region2; RegionDataPoint *point; UINT needed; DWORD buf[100]; GpRect rect; GpPath *path; memset(buf, 0xee, sizeof(buf)); status = GdipCreateRegion(®ion); ok(status == Ok, "status %08x\n", status); status = GdipGetRegionDataSize(region, &needed); ok(status == Ok, "status %08x\n", status); expect(20, needed); status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed); ok(status == Ok, "status %08x\n", status); expect(20, needed); expect_dword(buf, 12); trace("buf[1] = %08x\n", buf[1]); expect_magic((DWORD*)(buf + 2)); expect_dword(buf + 3, 0); expect_dword(buf + 4, RGNDATA_INFINITE_RECT); status = GdipSetEmpty(region); ok(status == Ok, "status %08x\n", status); status = GdipGetRegionDataSize(region, &needed); ok(status == Ok, "status %08x\n", status); expect(20, needed); status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed); ok(status == Ok, "status %08x\n", status); expect(20, needed); expect_dword(buf, 12); trace("buf[1] = %08x\n", buf[1]); expect_magic((DWORD*)(buf + 2)); expect_dword(buf + 3, 0); expect_dword(buf + 4, RGNDATA_EMPTY_RECT); status = GdipSetInfinite(region); ok(status == Ok, "status %08x\n", status); status = GdipGetRegionDataSize(region, &needed); ok(status == Ok, "status %08x\n", status); expect(20, needed); status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed); ok(status == Ok, "status %08x\n", status); expect(20, needed); expect_dword(buf, 12); trace("buf[1] = %08x\n", buf[1]); expect_magic((DWORD*)(buf + 2)); expect_dword(buf + 3, 0); expect_dword(buf + 4, RGNDATA_INFINITE_RECT); status = GdipDeleteRegion(region); ok(status == Ok, "status %08x\n", status); rect.X = 10; rect.Y = 20; rect.Width = 100; rect.Height = 200; status = GdipCreateRegionRectI(&rect, ®ion); ok(status == Ok, "status %08x\n", status); status = GdipGetRegionDataSize(region, &needed); ok(status == Ok, "status %08x\n", status); expect(36, needed); status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed); ok(status == Ok, "status %08x\n", status); expect(36, needed); expect_dword(buf, 28); trace("buf[1] = %08x\n", buf[1]); expect_magic((DWORD*)(buf + 2)); expect_dword(buf + 3, 0); expect_dword(buf + 4, RGNDATA_RECT); expect_float(buf + 5, 10.0); expect_float(buf + 6, 20.0); expect_float(buf + 7, 100.0); expect_float(buf + 8, 200.0); rect.X = 50; rect.Y = 30; rect.Width = 10; rect.Height = 20; status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect); ok(status == Ok, "status %08x\n", status); rect.X = 100; rect.Y = 300; rect.Width = 30; rect.Height = 50; status = GdipCombineRegionRectI(region, &rect, CombineModeXor); ok(status == Ok, "status %08x\n", status); rect.X = 200; rect.Y = 100; rect.Width = 133; rect.Height = 266; status = GdipCreateRegionRectI(&rect, ®ion2); ok(status == Ok, "status %08x\n", status); rect.X = 20; rect.Y = 10; rect.Width = 40; rect.Height = 66; status = GdipCombineRegionRectI(region2, &rect, CombineModeUnion); ok(status == Ok, "status %08x\n", status); status = GdipCombineRegionRegion(region, region2, CombineModeComplement); ok(status == Ok, "status %08x\n", status); rect.X = 400; rect.Y = 500; rect.Width = 22; rect.Height = 55; status = GdipCombineRegionRectI(region, &rect, CombineModeExclude); ok(status == Ok, "status %08x\n", status); status = GdipGetRegionDataSize(region, &needed); ok(status == Ok, "status %08x\n", status); expect(156, needed); status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed); ok(status == Ok, "status %08x\n", status); expect(156, needed); expect_dword(buf, 148); trace("buf[1] = %08x\n", buf[1]); expect_magic((DWORD*)(buf + 2)); expect_dword(buf + 3, 10); expect_dword(buf + 4, CombineModeExclude); expect_dword(buf + 5, CombineModeComplement); expect_dword(buf + 6, CombineModeXor); expect_dword(buf + 7, CombineModeIntersect); expect_dword(buf + 8, RGNDATA_RECT); expect_float(buf + 9, 10.0); expect_float(buf + 10, 20.0); expect_float(buf + 11, 100.0); expect_float(buf + 12, 200.0); expect_dword(buf + 13, RGNDATA_RECT); expect_float(buf + 14, 50.0); expect_float(buf + 15, 30.0); expect_float(buf + 16, 10.0); expect_float(buf + 17, 20.0); expect_dword(buf + 18, RGNDATA_RECT); expect_float(buf + 19, 100.0); expect_float(buf + 20, 300.0); expect_float(buf + 21, 30.0); expect_float(buf + 22, 50.0); expect_dword(buf + 23, CombineModeUnion); expect_dword(buf + 24, RGNDATA_RECT); expect_float(buf + 25, 200.0); expect_float(buf + 26, 100.0); expect_float(buf + 27, 133.0); expect_float(buf + 28, 266.0); expect_dword(buf + 29, RGNDATA_RECT); expect_float(buf + 30, 20.0); expect_float(buf + 31, 10.0); expect_float(buf + 32, 40.0); expect_float(buf + 33, 66.0); expect_dword(buf + 34, RGNDATA_RECT); expect_float(buf + 35, 400.0); expect_float(buf + 36, 500.0); expect_float(buf + 37, 22.0); expect_float(buf + 38, 55.0); status = GdipDeleteRegion(region2); ok(status == Ok, "status %08x\n", status); status = GdipDeleteRegion(region); ok(status == Ok, "status %08x\n", status); /* Try some paths */ status = GdipCreatePath(FillModeAlternate, &path); ok(status == Ok, "status %08x\n", status); GdipAddPathRectangle(path, 12.5, 13.0, 14.0, 15.0); status = GdipCreateRegionPath(path, ®ion); ok(status == Ok, "status %08x\n", status); status = GdipGetRegionDataSize(region, &needed); ok(status == Ok, "status %08x\n", status); expect(72, needed); status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed); ok(status == Ok, "status %08x\n", status); expect(72, needed); expect_dword(buf, 64); trace("buf[1] = %08x\n", buf[1]); expect_magic((DWORD*)(buf + 2)); expect_dword(buf + 3, 0); expect_dword(buf + 4, RGNDATA_PATH); expect_dword(buf + 5, 0x00000030); expect_magic((DWORD*)(buf + 6)); expect_dword(buf + 7, 0x00000004); expect_dword(buf + 8, 0x00000000); expect_float(buf + 9, 12.5); expect_float(buf + 10, 13.0); expect_float(buf + 11, 26.5); expect_float(buf + 12, 13.0); expect_float(buf + 13, 26.5); expect_float(buf + 14, 28.0); expect_float(buf + 15, 12.5); expect_float(buf + 16, 28.0); expect_dword(buf + 17, 0x81010100); rect.X = 50; rect.Y = 30; rect.Width = 10; rect.Height = 20; status = GdipCombineRegionRectI(region, &rect, CombineModeIntersect); ok(status == Ok, "status %08x\n", status); status = GdipGetRegionDataSize(region, &needed); ok(status == Ok, "status %08x\n", status); expect(96, needed); status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed); ok(status == Ok, "status %08x\n", status); expect(96, needed); expect_dword(buf, 88); trace("buf[1] = %08x\n", buf[1]); expect_magic((DWORD*)(buf + 2)); expect_dword(buf + 3, 2); expect_dword(buf + 4, CombineModeIntersect); expect_dword(buf + 5, RGNDATA_PATH); expect_dword(buf + 6, 0x00000030); expect_magic((DWORD*)(buf + 7)); expect_dword(buf + 8, 0x00000004); expect_dword(buf + 9, 0x00000000); expect_float(buf + 10, 12.5); expect_float(buf + 11, 13.0); expect_float(buf + 12, 26.5); expect_float(buf + 13, 13.0); expect_float(buf + 14, 26.5); expect_float(buf + 15, 28.0); expect_float(buf + 16, 12.5); expect_float(buf + 17, 28.0); expect_dword(buf + 18, 0x81010100); expect_dword(buf + 19, RGNDATA_RECT); expect_float(buf + 20, 50.0); expect_float(buf + 21, 30.0); expect_float(buf + 22, 10.0); expect_float(buf + 23, 20.0); status = GdipDeleteRegion(region); ok(status == Ok, "status %08x\n", status); status = GdipDeletePath(path); ok(status == Ok, "status %08x\n", status); /* Test an empty path */ status = GdipCreatePath(FillModeAlternate, &path); expect(Ok, status); status = GdipCreateRegionPath(path, ®ion); expect(Ok, status); status = GdipGetRegionDataSize(region, &needed); expect(Ok, status); expect(36, needed); status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed); expect(Ok, status); expect(36, needed); expect_dword(buf, 28); trace("buf[1] = %08x\n", buf[1]); expect_magic((DWORD*)(buf + 2)); expect_dword(buf + 3, 0); expect_dword(buf + 4, RGNDATA_PATH); /* Second signature for pathdata */ expect_dword(buf + 5, 12); expect_magic((DWORD*)(buf + 6)); expect_dword(buf + 7, 0); expect_dword(buf + 8, 0x00004000); status = GdipDeleteRegion(region); expect(Ok, status); /* Test a simple triangle of INTs */ status = GdipAddPathLine(path, 5, 6, 7, 8); expect(Ok, status); status = GdipAddPathLine(path, 8, 1, 5, 6); expect(Ok, status); status = GdipClosePathFigure(path); expect(Ok, status); status = GdipCreateRegionPath(path, ®ion); expect(Ok, status); status = GdipGetRegionDataSize(region, &needed); expect(Ok, status); expect(56, needed); status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed); expect(Ok, status); expect(56, needed); expect_dword(buf, 48); trace("buf[1] = %08x\n", buf[1]); expect_magic((DWORD*)(buf + 2)); expect_dword(buf + 3 , 0); expect_dword(buf + 4 , RGNDATA_PATH); expect_dword(buf + 5, 32); expect_magic((DWORD*)(buf + 6)); expect_dword(buf + 7, 4); expect_dword(buf + 8, 0x00004000); /* ?? */ point = (RegionDataPoint*)buf + 9; expect(5, point[0].X); expect(6, point[0].Y); expect(7, point[1].X); /* buf + 10 */ expect(8, point[1].Y); expect(8, point[2].X); /* buf + 11 */ expect(1, point[2].Y); expect(5, point[3].X); /* buf + 12 */ expect(6, point[3].Y); expect_dword(buf + 13, 0x81010100); /* 0x01010100 if we don't close the path */ status = GdipDeletePath(path); expect(Ok, status); status = GdipDeleteRegion(region); expect(Ok, status); /* Test a floating-point triangle */ status = GdipCreatePath(FillModeAlternate, &path); expect(Ok, status); status = GdipAddPathLine(path, 5.6, 6.2, 7.2, 8.9); expect(Ok, status); status = GdipAddPathLine(path, 8.1, 1.6, 5.6, 6.2); expect(Ok, status); status = GdipCreateRegionPath(path, ®ion); expect(Ok, status); status = GdipGetRegionDataSize(region, &needed); expect(Ok, status); expect(72, needed); status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed); expect(Ok, status); expect(72, needed); expect_dword(buf, 64); trace("buf[1] = %08x\n", buf[1]); expect_magic((DWORD*)(buf + 2)); expect_dword(buf + 3, 0); expect_dword(buf + 4, RGNDATA_PATH); expect_dword(buf + 5, 48); expect_magic((DWORD*)(buf + 6)); expect_dword(buf + 7, 4); expect_dword(buf + 8, 0); expect_float(buf + 9, 5.6); expect_float(buf + 10, 6.2); expect_float(buf + 11, 7.2); expect_float(buf + 12, 8.9); expect_float(buf + 13, 8.1); expect_float(buf + 14, 1.6); expect_float(buf + 15, 5.6); expect_float(buf + 16, 6.2); status = GdipDeletePath(path); expect(Ok, status); status = GdipDeleteRegion(region); expect(Ok, status); /* Test for a path with > 4 points, and CombineRegionPath */ GdipCreatePath(FillModeAlternate, &path); status = GdipAddPathLine(path, 50, 70.2, 60, 102.8); expect(Ok, status); status = GdipAddPathLine(path, 55.4, 122.4, 40.4, 60.2); expect(Ok, status); status = GdipAddPathLine(path, 45.6, 20.2, 50, 70.2); expect(Ok, status); rect.X = 20; rect.Y = 25; rect.Width = 60; rect.Height = 120; status = GdipCreateRegionRectI(&rect, ®ion); expect(Ok, status); status = GdipCombineRegionPath(region, path, CombineModeUnion); expect(Ok, status); status = GdipGetRegionDataSize(region, &needed); expect(Ok, status); expect(116, needed); status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed); expect(Ok, status); expect(116, needed); expect_dword(buf, 108); trace("buf[1] = %08x\n", buf[1]); expect_magic((DWORD*)(buf + 2)); expect_dword(buf + 3, 2); expect_dword(buf + 4, CombineModeUnion); expect_dword(buf + 5, RGNDATA_RECT); expect_float(buf + 6, 20); expect_float(buf + 7, 25); expect_float(buf + 8, 60); expect_float(buf + 9, 120); expect_dword(buf + 10, RGNDATA_PATH); expect_dword(buf + 11, 68); expect_magic((DWORD*)(buf + 12)); expect_dword(buf + 13, 6); expect_float(buf + 14, 0x0); expect_float(buf + 15, 50); expect_float(buf + 16, 70.2); expect_float(buf + 17, 60); expect_float(buf + 18, 102.8); expect_float(buf + 19, 55.4); expect_float(buf + 20, 122.4); expect_float(buf + 21, 40.4); expect_float(buf + 22, 60.2); expect_float(buf + 23, 45.6); expect_float(buf + 24, 20.2); expect_float(buf + 25, 50); expect_float(buf + 26, 70.2); expect_dword(buf + 27, 0x01010100); expect_dword(buf + 28, 0x00000101); status = GdipDeletePath(path); expect(Ok, status); status = GdipDeleteRegion(region); expect(Ok, status); }