Пример #1
0
void
test_pending (void)
{
    CutTestContainer *container;

    test_iterator = cut_test_iterator_new("pending test iterator",
                                          stub_pending_iterated_test,
                                          stub_iterated_data);
    container = CUT_TEST_CONTAINER(test_iterator);
    cut_assert_equal_uint(0, cut_test_container_get_n_tests(container, NULL));
    cut_assert_false(run());
    cut_assert_equal_uint(3, cut_test_container_get_n_tests(container, NULL));

    cut_assert_n_signals(1, 1, 3, 3, 3, 0, 0, 0, 0, 1, 0, 0);
    cut_assert_test_result_summary(run_context, 3, 5, 2, 0, 0, 1, 0, 0);
    cut_assert_test_result(run_context, 0, CUT_TEST_RESULT_SUCCESS,
                           "pending test iterator (First)",
                           NULL, NULL,
                           NULL, NULL,
                           NULL,
                           NULL);
    cut_assert_test_result(run_context, 1, CUT_TEST_RESULT_PENDING,
                           "pending test iterator (Second)",
                           "PENDING!",
                           NULL,
                           NULL, NULL,
                           FAIL_LOCATION, "stub_pending_iterated_test",
                           NULL);
    cut_assert_test_result(run_context, 2, CUT_TEST_RESULT_SUCCESS,
                           "pending test iterator (Third)",
                           NULL, NULL,
                           NULL, NULL,
                           NULL,
                           NULL);
}
Пример #2
0
void
test_load_cpp_data_driven_test (void)
{
    GList *test_cases, *test_case_node;
    gchar *expected_functions[] = {
        "data_driven_test::test_string",
        NULL
    };

    loader = loader_new("cpp", "stub-data-driven-test." G_MODULE_SUFFIX);
    test_cases = cut_loader_load_test_cases(loader);
    cut_assert_equal_int(1, g_list_length(test_cases));

    test_names = g_ptr_array_new_with_free_func(g_free);
    for (test_case_node = test_cases;
         test_case_node;
         test_case_node = g_list_next(test_case_node)) {
        CutTestContainer *container;
        GList *tests, *test_node;

        container = CUT_TEST_CONTAINER(test_case_node->data);
        tests = (GList *)cut_test_container_get_children(container);
        for (test_node = tests; test_node; test_node = g_list_next(test_node)) {
            CutTest *test = test_node->data;

            cut_assert(CUT_IS_TEST(test));
            g_ptr_array_add(test_names, g_strdup(cut_test_get_name(test)));
        }
    }
    g_ptr_array_sort(test_names, compare_test_name);
    g_ptr_array_add(test_names, NULL);
    cut_assert_equal_string_array(expected_functions,
                                  (gchar **)test_names->pdata);
}
Пример #3
0
void
test_load_test_iterator (void)
{
    const GList *tests;
    CutTestContainer *container;
    CutTestIterator *test_iterator;
    CutIteratedTestFunction iterated_test_function = NULL;
    CutDataSetupFunction data_setup_function = NULL;

    loader = loader_new("iterator", "success-iterated-test." G_MODULE_SUFFIX);
    cut_assert_not_null(loader);

    test_case = cut_loader_load_test_case(loader);
    cut_assert_not_null(test_case);
    container = CUT_TEST_CONTAINER(test_case);
    cut_assert_equal_int(1, cut_test_container_get_n_tests(container, NULL));

    tests = cut_test_container_get_children(container);
    cut_assert_not_null(tests);

    test_iterator = tests->data;
    cut_assert_not_null(test_iterator);

    g_object_get(test_iterator,
                 "iterated-test-function", &iterated_test_function,
                 "data-setup-function", &data_setup_function,
                 NULL);
    cut_assert_not_null(iterated_test_function);
    cut_assert_not_null(data_setup_function);

    cut_assert_true(run());
    cut_assert_test_result_summary(run_context, 2, 2, 2, 0, 0, 0, 0, 0);
}
Пример #4
0
void
test_success (void)
{
    CutTestContainer *container;

    test_iterator = cut_test_iterator_new("success test iterator",
                                          stub_success_iterated_test,
                                          stub_iterated_data);
    container = CUT_TEST_CONTAINER(test_iterator);
    cut_assert_equal_uint(0, cut_test_container_get_n_tests(container, NULL));
    cut_assert_true(run());
    cut_assert_equal_uint(3, cut_test_container_get_n_tests(container, NULL));

    cut_assert_n_signals(1, 1, 3, 3, 3, 0, 1, 0, 0, 0, 0, 0);
    cut_assert_test_result_summary(run_context, 3, 6, 3, 0, 0, 0, 0, 0);
}
Пример #5
0
void
test_load_function (void)
{
    CutTestContainer *container;
    GList *tests, *list;
    gint i;
    const gchar *target_test_names[] = {"/.*/", NULL};
    gchar *expected_functions[] = {
        "test_abcdefghijklmnopqratuvwzyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789",
        "test_stub_function1",
        "test_stub_function2",
        "test_stub_function3",
        NULL
    };

    loader = loader_new("test", "stub-test-functions." G_MODULE_SUFFIX);
    test_case = cut_loader_load_test_case(loader);
    cut_assert(test_case);

    container = CUT_TEST_CONTAINER(test_case);
    cut_assert_equal_int(4,
                         cut_test_container_get_n_tests(container, NULL));

    run_context = cut_test_runner_new();
    cut_run_context_set_target_test_names(run_context, target_test_names);
    cut_assert_equal_int(4,
                         cut_test_container_get_n_tests(container, run_context));

    tests = (GList *)cut_test_container_get_children(container);
    cut_assert(tests);

    test_names = g_ptr_array_new_with_free_func(g_free);
    for (list = tests, i = 0; list; list = g_list_next(list), i++) {
        CutTest *test;

        cut_assert(list->data);
        cut_assert(CUT_IS_TEST(list->data));

        test = CUT_TEST(list->data);
        g_ptr_array_add(test_names, g_strdup(cut_test_get_name(test)));
    }
    g_ptr_array_sort(test_names, compare_test_name);
    g_ptr_array_add(test_names, NULL);
    cut_assert_equal_string_array(expected_functions,
                                  (gchar **)test_names->pdata);
}
Пример #6
0
void
test_error_in_data_setup (void)
{
    CutTestContainer *container;

    test_iterator =
        cut_test_iterator_new("error in data setup test iterator",
                              stub_error_in_data_setup_iterated_test,
                              stub_error_in_data_setup_iterated_data);
    container = CUT_TEST_CONTAINER(test_iterator);
    cut_assert_equal_uint(0, cut_test_container_get_n_tests(container, NULL));
    cut_assert_false(run());
    cut_assert_equal_uint(0, cut_test_container_get_n_tests(container, NULL));

    cut_assert_n_signals(0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0);
    cut_assert_test_result_summary(run_context, 0, 0, 0, 0, 0, 0, 0, 0);
}
Пример #7
0
void
test_load_cpp_namespace (void)
{
    CutTestContainer *container;
    GList *tests, *list;
    gint i;
    const gchar *target_test_names[] = {"/.*/", NULL};
    gchar *expected_functions[] = {
        "calc::test_add",
        "calc::test_sub",
        NULL
    };

    loader = loader_new("cpp", "stub-namespace." G_MODULE_SUFFIX);
    test_case = cut_loader_load_test_case(loader);
    cut_assert(test_case);

    container = CUT_TEST_CONTAINER(test_case);
    cut_assert_equal_int(2,
                         cut_test_container_get_n_tests(container, NULL));

    run_context = cut_test_runner_new();
    cut_run_context_set_target_test_names(run_context, target_test_names);
    cut_assert_equal_int(2,
                         cut_test_container_get_n_tests(container, run_context));

    tests = (GList *)cut_test_container_get_children(container);
    cut_assert(tests);

    test_names = g_ptr_array_new_with_free_func(g_free);
    for (list = tests, i = 0; list; list = g_list_next(list), i++) {
        CutTest *test;

        cut_assert(list->data);
        cut_assert(CUT_IS_TEST(list->data));

        test = CUT_TEST(list->data);
        g_ptr_array_add(test_names, g_strdup(cut_test_get_name(test)));
    }
    g_ptr_array_sort(test_names, compare_test_name);
    g_ptr_array_add(test_names, NULL);
    cut_assert_equal_string_array(expected_functions,
                                  (gchar **)test_names->pdata);
}
Пример #8
0
void
test_omission (void)
{
    CutTestContainer *container;

    test_iterator = cut_test_iterator_new("omission test iterator",
                                          stub_omission_iterated_test,
                                          stub_iterated_data);
    container = CUT_TEST_CONTAINER(test_iterator);
    cut_assert_equal_uint(0, cut_test_container_get_n_tests(container, NULL));
    cut_assert_true(run());
    cut_assert_equal_uint(3, cut_test_container_get_n_tests(container, NULL));

    cut_assert_n_signals(1, 1, 3, 3, 3, 0, 0, 0, 0, 0, 0, 1);
    cut_assert_test_result_summary(run_context, 3, 5, 3, 0, 0, 0, 0, 1);
    cut_assert_test_result(run_context, 0, CUT_TEST_RESULT_SUCCESS,
                           "omission test iterator (First)",
                           NULL, NULL,
                           NULL, NULL,
                           NULL,
                           NULL);
    cut_assert_test_result(run_context, 1, CUT_TEST_RESULT_OMISSION,
                           "omission test iterator (Second)",
                           "OMISSION!",
                           NULL,
                           NULL, NULL,
                           FAIL_LOCATION, "stub_omission_iterated_test",
                           NULL);
    cut_assert_test_result(run_context, 2, CUT_TEST_RESULT_SUCCESS,
                           "omission test iterator (Second)",
                           NULL, NULL,
                           NULL, NULL,
                           NULL,
                           NULL);
    cut_assert_test_result(run_context, 3, CUT_TEST_RESULT_SUCCESS,
                           "omission test iterator (Third)",
                           NULL, NULL,
                           NULL, NULL,
                           NULL,
                           NULL);
}
Пример #9
0
void
test_failure (void)
{
    CutTestContainer *container;

    test_iterator = cut_test_iterator_new("failure test iterator",
                                          stub_failure_iterated_test,
                                          stub_iterated_data);
    container = CUT_TEST_CONTAINER(test_iterator);
    cut_assert_equal_uint(0, cut_test_container_get_n_tests(container, NULL));
    cut_assert_false(run());
    cut_assert_equal_uint(3, cut_test_container_get_n_tests(container, NULL));

    cut_assert_n_signals(1, 1, 3, 3, 3, 0, 0, 1, 0, 0, 0, 0);
    cut_assert_test_result_summary(run_context, 3, 5, 1, 2, 0, 0, 0, 0);
    cut_assert_test_result(run_context, 0, CUT_TEST_RESULT_FAILURE,
                           "failure test iterator (First)",
                           NULL,
                           "<2 == GPOINTER_TO_INT(data)>",
                           "2", "1",
                           FAIL_LOCATION, "stub_failure_iterated_test",
                           NULL);
    cut_assert_test_result(run_context, 1, CUT_TEST_RESULT_SUCCESS,
                           "failure test iterator (Second)",
                           NULL, NULL,
                           NULL, NULL,
                           NULL,
                           NULL);
    cut_assert_test_result(run_context, 2, CUT_TEST_RESULT_FAILURE,
                           "failure test iterator (Third)",
                           NULL,
                           "<2 == GPOINTER_TO_INT(data)>",
                           "2", "3",
                           FAIL_LOCATION, "stub_failure_iterated_test",
                           NULL);
}