Пример #1
0
void test_arithmetic() {
  expect_int(3, 1 + 2);
  expect_int(5, 7 - 2);
  expect_int(6, 2 * 3);
  expect_int(3, 9 / 3);
  expect_int(2, 8 % 3);
}
Пример #2
0
void test_variable_redefinition() {
  int a = 1;
  {
    int a;
    a = 2;
    expect_int(2, a);
  }
  expect_int(1, a);
}
Пример #3
0
void test_decrement() {
  int n = 0;
  expect_int(0, n--);
  expect_int(-1, n);

  n = 0;
  expect_int(-1, --n);
  expect_int(-1, n);
}
Пример #4
0
void test_increment() {
  int n = 0;
  expect_int(0, n++);
  expect_int(1, n);

  n = 0;
  expect_int(1, ++n);
  expect_int(1, n);
}
Пример #5
0
void test_integer_types() {
  unsigned n;
  n = 3;
  expect_int(3, n);

  short unsigned m = 2;
  expect_int(2, m);

  long l = 1;
  expect_int(1, l);
}
Пример #6
0
void test_arithmetic_compound_assign() {
  int a = 1;
  a += 3;
  expect_int(4, a);
  a -= 2;
  expect_int(2, a);
  a *= 3;
  expect_int(6, a);
  a /= 2;
  expect_int(3, a);
  a %= 2;
  expect_int(1, a);
}
Пример #7
0
void test_not() {
  int n;
  if (!1)
    n = 1;
  else
    n = 2;
  expect_int(2, n);

  if (!n)
    n = 3;
  else
    n = 4;
  expect_int(4, n);
}
Пример #8
0
void test_struct_decl() {
  struct {
    int a;
    int b;
  } a;
  a.a = 3;
  a.b = 4;
  expect_int(12, a.a * a.b);
}
Пример #9
0
void
PlProxy::receive_begin_term(const char *name, int arity)
{ string s;
  expect_chr('c');
  receive(s);
  if ( s != name )
    throw(PlSerializationException(name, s));
  expect_int(arity);
}
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;
}
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;
}
Пример #12
0
void test_comma_operator() {
  int n = (2, 3);
  expect_int(3, n);
}
Пример #13
0
void test_funcall() {
  expect_int(10, sum_func(2, 3, 5));
}
Пример #14
0
void test_unary_minus() {
  expect_int(-3, -1 + -2);
}
Пример #15
0
void test_unary_plus() {
  expect_int(3, +1 + +2);
}
Пример #16
0
void test_factorial() {
  expect_int(120, factorial(5));
}
Пример #17
0
static void test_dump_typelib(const char *name)
{
    WCHAR wszName[MAX_PATH];
    ITypeLib *typelib;
    int ifcount = sizeof(info)/sizeof(info[0]);
    int iface, func;

    MultiByteToWideChar(CP_UTF8, 0, name, -1, wszName, MAX_PATH);
    ole_check(LoadTypeLibEx(wszName, REGKIND_NONE, &typelib));
    expect_eq(ITypeLib_GetTypeInfoCount(typelib), ifcount, UINT, "%d");
    for (iface = 0; iface < ifcount; iface++)
    {
        const interface_info *if_info = &info[iface];
        ITypeInfo *typeinfo;
        TYPEATTR *typeattr;
        BSTR bstrIfName;

        trace("Interface %s\n", if_info->name);
        ole_check(ITypeLib_GetTypeInfo(typelib, iface, &typeinfo));
        ole_check(ITypeLib_GetDocumentation(typelib, iface, &bstrIfName, NULL, NULL, NULL));
        expect_wstr_utf8val(bstrIfName, if_info->name);
        SysFreeString(bstrIfName);

        ole_check(ITypeInfo_GetTypeAttr(typeinfo, &typeattr));
        expect_int(typeattr->typekind, if_info->type);
        expect_hex(typeattr->wTypeFlags, if_info->wTypeFlags);
        expect_int(typeattr->cbAlignment, if_info->cbAlignment);
        expect_int(typeattr->cbSizeInstance, if_info->cbSizeInstance);
        expect_int(typeattr->cbSizeVft, if_info->cbSizeVft);
        expect_int(typeattr->cFuncs, if_info->cFuncs);

        for (func = 0; func < typeattr->cFuncs; func++)
        {
            function_info *fn_info = (function_info *)&if_info->funcs[func];
            FUNCDESC *desc;
            BSTR namesTab[256];
            UINT cNames;
            int i;

            trace("Function %s\n", fn_info->names[0]);
            ole_check(ITypeInfo_GetFuncDesc(typeinfo, func, &desc));
            expect_int(desc->memid, fn_info->memid);
            expect_int(desc->funckind, fn_info->funckind);
            expect_int(desc->invkind, fn_info->invkind);
            expect_int(desc->callconv, fn_info->callconv);
            expect_int(desc->cParams, fn_info->cParams);
            expect_int(desc->cParamsOpt, fn_info->cParamsOpt);
            expect_int(desc->oVft, fn_info->oVft);
            expect_int(desc->cScodes, fn_info->cScodes);
            expect_int(desc->wFuncFlags, fn_info->wFuncFlags);
            ole_check(ITypeInfo_GetNames(typeinfo, desc->memid, namesTab, 256, &cNames));
            for (i = 0; i < cNames; i++)
            {
                expect_wstr_utf8val(namesTab[i], fn_info->names[i]);
                SysFreeString(namesTab[i]);
            }
            expect_null(fn_info->names[cNames]);

            check_type(&desc->elemdescFunc, &fn_info->ret_type);
            for (i = 0 ; i < desc->cParams; i++)
            {
                check_type(&desc->lprgelemdescParam[i], &fn_info->params[i]);
            }
            expect_int(fn_info->params[desc->cParams].vt, (VARTYPE)-1);

            ITypeInfo_ReleaseFuncDesc(typeinfo, desc);
        }

        ITypeInfo_ReleaseTypeAttr(typeinfo, typeattr);
        ITypeInfo_Release(typeinfo);
    }
    ITypeLib_Release(typelib);
}
Пример #18
0
void test_anti_associativity() {
  int n = (2 + 3) * (3 - 1) / 5;
  expect_int(2, n);
}
Пример #19
0
void test_return() {
  expect_int(3, ret_func());
  expect_int(3, var_ret_func());
}
Пример #20
0
void test_variable_outside_comp_stmt() {
  int a = 1;
  {
    expect_int(1, a);
  }
}