Exemple #1
0
static void
_adg_property_level(void)
{
    AdgDim *dim;
    gdouble valid_value_1, valid_value_2;
    gdouble level;

    dim = ADG_DIM(adg_ldim_new());
    valid_value_1 = 4321;
    valid_value_2 = 1234;

    /* Using the public APIs */
    adg_dim_set_level(dim, valid_value_1);
    level = adg_dim_get_level(dim);
    adg_assert_isapprox(level, valid_value_1);

    adg_dim_set_level(dim, valid_value_2);
    level = adg_dim_get_level(dim);
    adg_assert_isapprox(level, valid_value_2);

    /* Using GObject property methods */
    g_object_set(dim, "level", valid_value_1, NULL);
    g_object_get(dim, "level", &level, NULL);
    adg_assert_isapprox(level, valid_value_1);

    g_object_set(dim, "level", valid_value_2, NULL);
    g_object_get(dim, "level", &level, NULL);
    adg_assert_isapprox(level, valid_value_2);

    adg_entity_destroy(ADG_ENTITY(dim));
}
Exemple #2
0
static void
_adg_property_dim_dress(void)
{
    AdgDim *dim;
    AdgDress valid_dress, incompatible_dress;
    AdgDress dim_dress;

    dim = ADG_DIM(adg_adim_new());
    valid_dress = ADG_DRESS_DIMENSION;
    incompatible_dress = ADG_DRESS_LINE;

    /* Using the public APIs */
    adg_dim_set_dim_dress(dim, valid_dress);
    dim_dress = adg_dim_get_dim_dress(dim);
    g_assert_cmpint(dim_dress, ==, valid_dress);

    adg_dim_set_dim_dress(dim, incompatible_dress);
    dim_dress = adg_dim_get_dim_dress(dim);
    g_assert_cmpint(dim_dress, ==, valid_dress);

    /* Using GObject property methods */
    g_object_set(dim, "dim-dress", valid_dress, NULL);
    g_object_get(dim, "dim-dress", &dim_dress, NULL);
    g_assert_cmpint(dim_dress, ==, valid_dress);

    g_object_set(dim, "dim-dress", incompatible_dress, NULL);
    g_object_get(dim, "dim-dress", &dim_dress, NULL);
    g_assert_cmpint(dim_dress, ==, valid_dress);

    adg_entity_destroy(ADG_ENTITY(dim));
}
Exemple #3
0
static void
_adg_behavior_misc(void)
{
    AdgContainer *container;
    AdgEntity *entity1, *entity2;
    GSList *children;

    container = adg_container_new();
    entity1 = ADG_ENTITY(adg_toy_text_new("Testing..."));
    entity2 = ADG_ENTITY(adg_title_block_new());

    children = adg_container_children(container);
    g_assert_null(children);

    adg_container_add(container, entity1);
    children = adg_container_children(container);
    g_assert_nonnull(children);
    g_assert_cmpint(g_slist_length(children), ==, 1);
    g_slist_free(children);

    adg_container_add(container, entity2);
    children = adg_container_children(container);
    g_assert_nonnull(children);
    g_assert_cmpint(g_slist_length(children), ==, 2);
    g_slist_free(children);

    adg_entity_destroy(entity1);
    children = adg_container_children(container);
    g_assert_nonnull(children);
    g_assert_cmpint(g_slist_length(children), ==, 1);
    g_slist_free(children);

    adg_entity_destroy(entity2);
    children = adg_container_children(container);
    g_assert_null(children);

    adg_entity_destroy(ADG_ENTITY(container));
}
Exemple #4
0
static void
_adg_property_value(void)
{
    AdgDim *dim;
    const gchar *valid_text, *latin1_text;
    const gchar *value;
    gchar *value_dup;

    dim = ADG_DIM(adg_ldim_new());
    valid_text = "This is some text...";
    latin1_text = "This is some àèìòù Latin1 text...";

    /* Using the public APIs */
    adg_dim_set_value(dim, valid_text);
    value = adg_dim_get_value(dim);
    g_assert_cmpstr(value, ==, valid_text);

    adg_dim_set_value(dim, latin1_text);
    value = adg_dim_get_value(dim);
    g_assert_cmpstr(value, ==, latin1_text);

    adg_dim_set_value(dim, NULL);
    value = adg_dim_get_value(dim);
    g_assert_null(value);

    /* Using GObject property methods */
    g_object_set(dim, "value", valid_text, NULL);
    g_object_get(dim, "value", &value_dup, NULL);
    g_assert_cmpstr(value_dup, ==, valid_text);
    g_free(value_dup);

    g_object_set(dim, "value", latin1_text, NULL);
    g_object_get(dim, "value", &value_dup, NULL);
    g_assert_cmpstr(value_dup, ==, latin1_text);
    g_free(value_dup);

    g_object_set(dim, "value", NULL, NULL);
    g_object_get(dim, "value", &value_dup, NULL);
    g_assert_null(value_dup);

    adg_entity_destroy(ADG_ENTITY(dim));
}
Exemple #5
0
static void
_adg_property_fill_dress(void)
{
    AdgHatch *hatch;
    AdgDress valid_dress_1, valid_dress_2, incompatible_dress;
    AdgDress fill_dress;

    hatch = adg_hatch_new(NULL);
    valid_dress_1 = ADG_DRESS_FILL;
    valid_dress_2 = ADG_DRESS_FILL_HATCH;
    incompatible_dress = ADG_DRESS_FONT_TEXT;

    /* Using the public APIs */
    adg_hatch_set_fill_dress(hatch, valid_dress_1);
    fill_dress = adg_hatch_get_fill_dress(hatch);
    g_assert_cmpint(fill_dress, ==, valid_dress_1);

    adg_hatch_set_fill_dress(hatch, incompatible_dress);
    fill_dress = adg_hatch_get_fill_dress(hatch);
    g_assert_cmpint(fill_dress, ==, valid_dress_1);

    adg_hatch_set_fill_dress(hatch, valid_dress_2);
    fill_dress = adg_hatch_get_fill_dress(hatch);
    g_assert_cmpint(fill_dress, ==, valid_dress_2);

    /* Using GObject property methods */
    g_object_set(hatch, "fill-dress", valid_dress_1, NULL);
    g_object_get(hatch, "fill-dress", &fill_dress, NULL);
    g_assert_cmpint(fill_dress, ==, valid_dress_1);

    g_object_set(hatch, "fill-dress", incompatible_dress, NULL);
    g_object_get(hatch, "fill-dress", &fill_dress, NULL);
    g_assert_cmpint(fill_dress, ==, valid_dress_1);

    g_object_set(hatch, "fill-dress", valid_dress_2, NULL);
    g_object_get(hatch, "fill-dress", &fill_dress, NULL);
    g_assert_cmpint(fill_dress, ==, valid_dress_2);

    adg_entity_destroy(ADG_ENTITY(hatch));
}
Exemple #6
0
static void
_adg_property_detached(void)
{
    AdgDim *dim;
    AdgThreeState valid_three_state_1, valid_three_state_2, invalid_three_state;
    AdgThreeState detached;

    dim = ADG_DIM(adg_adim_new());
    valid_three_state_1 = ADG_THREE_STATE_UNKNOWN;
    valid_three_state_2 = ADG_THREE_STATE_OFF;
    invalid_three_state = 1234;

    /* Using the public APIs */
    adg_dim_set_detached(dim, valid_three_state_1);
    detached = adg_dim_get_detached(dim);
    g_assert_cmpint(detached, ==, valid_three_state_1);

    adg_dim_set_detached(dim, invalid_three_state);
    detached = adg_dim_get_detached(dim);
    g_assert_cmpint(detached, ==, valid_three_state_1);

    adg_dim_set_detached(dim, valid_three_state_2);
    detached = adg_dim_get_detached(dim);
    g_assert_cmpint(detached, ==, valid_three_state_2);

    /* Using GObject property methods */
    g_object_set(dim, "detached", valid_three_state_1, NULL);
    g_object_get(dim, "detached", &detached, NULL);
    g_assert_cmpint(detached, ==, valid_three_state_1);

    g_object_set(dim, "detached", invalid_three_state, NULL);
    g_object_get(dim, "detached", &detached, NULL);
    g_assert_cmpint(detached, ==, valid_three_state_1);

    g_object_set(dim, "detached", valid_three_state_2, NULL);
    g_object_get(dim, "detached", &detached, NULL);
    g_assert_cmpint(detached, ==, valid_three_state_2);

    adg_entity_destroy(ADG_ENTITY(dim));
}
Exemple #7
0
static void
_adg_behavior_entity(void)
{
    AdgCanvas *canvas;
    const CpmlExtents *extents;
    AdgTitleBlock *title_block;

    canvas = ADG_CANVAS(adg_test_canvas());

    adg_entity_arrange(ADG_ENTITY(canvas));
    extents = adg_entity_get_extents(ADG_ENTITY(canvas));
    g_assert_true(extents->is_defined);
    adg_assert_isapprox(extents->size.x, 1);
    adg_assert_isapprox(extents->size.y, 1);

    adg_entity_invalidate(ADG_ENTITY(canvas));
    extents = adg_entity_get_extents(ADG_ENTITY(canvas));
    g_assert_false(extents->is_defined);

    title_block = adg_title_block_new();
    adg_canvas_set_title_block(canvas, title_block);
    adg_entity_arrange(ADG_ENTITY(canvas));
    extents = adg_entity_get_extents(ADG_ENTITY(canvas));
    g_assert_true(extents->is_defined);
    g_assert_cmpfloat(extents->size.x, >, 1);
    g_assert_cmpfloat(extents->size.y, >, 1);
    g_assert_cmpfloat(extents->size.x, <, 5000);
    g_assert_cmpfloat(extents->size.y, <, 5000);

    adg_canvas_set_size_explicit(canvas, 5000, 5000);
    adg_entity_arrange(ADG_ENTITY(canvas));
    extents = adg_entity_get_extents(ADG_ENTITY(canvas));
    g_assert_true(extents->is_defined);
    adg_assert_isapprox(extents->size.x, 5000);
    adg_assert_isapprox(extents->size.y, 5000);

    adg_entity_destroy(ADG_ENTITY(canvas));
}
Exemple #8
0
static void
_adg_property_has_extension2(void)
{
    AdgADim *adim;
    gboolean invalid_boolean;
    gboolean has_extension2;

    adim = adg_adim_new();
    invalid_boolean = (gboolean) 1234;

    /* Using the public APIs */
    adg_adim_switch_extension2(adim, FALSE);
    has_extension2 = adg_adim_has_extension2(adim);
    g_assert_false(has_extension2);

    adg_adim_switch_extension2(adim, invalid_boolean);
    has_extension2 = adg_adim_has_extension2(adim);
    g_assert_false(has_extension2);

    adg_adim_switch_extension2(adim, TRUE);
    has_extension2 = adg_adim_has_extension2(adim);
    g_assert_true(has_extension2);

    /* Using GObject property methods */
    g_object_set(adim, "has-extension2", FALSE, NULL);
    g_object_get(adim, "has-extension2", &has_extension2, NULL);
    g_assert_false(has_extension2);

    g_object_set(adim, "has-extension2", invalid_boolean, NULL);
    g_object_get(adim, "has-extension2", &has_extension2, NULL);
    g_assert_false(has_extension2);

    g_object_set(adim, "has-extension2", TRUE, NULL);
    g_object_get(adim, "has-extension2", &has_extension2, NULL);
    g_assert_true(has_extension2);

    adg_entity_destroy(ADG_ENTITY(adim));
}
Exemple #9
0
static void
_adg_property_child(void)
{
    AdgContainer *container;
    AdgEntity *valid_entity, *invalid_entity;
    GSList *children;

    container = adg_container_new();
    valid_entity = ADG_ENTITY(adg_logo_new());
    invalid_entity = adg_test_invalid_pointer();

    /* Keep alive the entity between all the tests */
    g_object_ref(valid_entity);

    /* Using the public APIs */
    adg_container_add(container, NULL);
    children = adg_container_children(container);
    g_assert_null(children);

    adg_container_add(container, invalid_entity);
    children = adg_container_children(container);
    g_assert_null(children);

    adg_container_add(container, valid_entity);
    children = adg_container_children(container);
    g_assert_nonnull(children);
    g_assert_true(children->data == valid_entity);
    g_slist_free(children);

    adg_container_remove(container, invalid_entity);
    children = adg_container_children(container);
    g_assert_nonnull(children);
    g_assert_true(children->data == valid_entity);
    g_slist_free(children);

    adg_container_remove(container, valid_entity);
    children = adg_container_children(container);
    g_assert_null(children);

    /* Using GObject property methods */
    g_object_set(container, "child", NULL, NULL);
    children = adg_container_children(container);
    g_assert_null(children);

    g_object_set(container, "child", invalid_entity, NULL);
    children = adg_container_children(container);
    g_assert_null(children);

    g_object_set(container, "child", valid_entity, NULL);
    children = adg_container_children(container);
    g_assert_nonnull(children);
    g_assert_true(children->data == valid_entity);
    g_slist_free(children);

    adg_container_remove(container, valid_entity);
    children = adg_container_children(container);
    g_assert_null(children);

    adg_entity_destroy(ADG_ENTITY(container));
    adg_entity_destroy(valid_entity);
}
Exemple #10
0
static void
_adg_property_org1(void)
{
    AdgADim *adim;
    AdgModel *model;
    AdgPoint *origin, *explicit_point, *model_point;
    AdgPoint *org1;

    adim = adg_adim_new();
    model = ADG_MODEL(adg_path_new());
    origin = adg_point_new();
    explicit_point = adg_point_new();
    model_point = adg_point_new();

    adg_point_set_pair_explicit(origin, 0, 0);
    adg_point_set_pair_explicit(explicit_point, 123, 321);
    adg_model_set_named_pair(model, "named-pair", (CpmlPair *) explicit_point);
    adg_point_set_pair_from_model(model_point, model, "named-pair");

    /* Ensure ADG does not consider an explicit point equals to
     * a point bound to a named pair with the same coordinates */
    g_assert_false(adg_point_equal(explicit_point, model_point));

    org1 = adg_adim_get_org1(adim);
    g_assert_null(org1);

    /* Using the public APIs */
    adg_adim_set_org1_explicit(adim, 0, 0);
    org1 = adg_adim_get_org1(adim);
    g_assert_true(adg_point_equal(org1, origin));

    adg_adim_set_org1(adim, NULL);
    org1 = adg_adim_get_org1(adim);
    g_assert_null(org1);

    adg_adim_set_org1(adim, explicit_point);
    org1 = adg_adim_get_org1(adim);
    g_assert_true(adg_point_equal(org1, explicit_point));

    adg_adim_set_org1_from_model(adim, model, "dummy");
    org1 = adg_adim_get_org1(adim);
    g_assert_nonnull(org1);

    adg_adim_set_org1_from_model(adim, model, "named-pair");
    org1 = adg_adim_get_org1(adim);
    g_assert_true(adg_point_equal(org1, model_point));

    /* Using GObject property methods */
    g_object_set(adim, "org1", origin, NULL);
    g_object_get(adim, "org1", &org1, NULL);
    g_assert_true(adg_point_equal(org1, origin));
    adg_point_destroy(org1);

    g_object_set(adim, "org1", NULL, NULL);
    g_object_get(adim, "org1", &org1, NULL);
    g_assert_null(org1);

    g_object_set(adim, "org1", explicit_point, NULL);
    g_object_get(adim, "org1", &org1, NULL);
    g_assert_true(adg_point_equal(org1, explicit_point));
    adg_point_destroy(org1);

    adg_adim_set_org1_from_model(adim, model, "dummy");
    g_object_get(adim, "org1", &org1, NULL);
    g_assert_nonnull(org1);
    adg_point_destroy(org1);

    g_object_set(adim, "org1", model_point, NULL);
    g_object_get(adim, "org1", &org1, NULL);
    g_assert_true(adg_point_equal(org1, model_point));
    adg_point_destroy(org1);

    adg_point_destroy(origin);
    adg_point_destroy(explicit_point);
    adg_point_destroy(model_point);
    adg_entity_destroy(ADG_ENTITY(adim));
    g_object_unref(model);
}