示例#1
0
ATF_TC_BODY(check_streq, tc)
{
    struct check_eq_test tests[] = {
        { H_CHECK_STREQ_HEAD_NAME(1_1), H_CHECK_STREQ_BODY_NAME(1_1),
          "1", "1", "\"1\" != \"1\" \\(1 != 1\\)", true },
        { H_CHECK_STREQ_HEAD_NAME(1_2), H_CHECK_STREQ_BODY_NAME(1_2),
          "1", "2", "\"1\" != \"2\" \\(1 != 2\\)", false },
        { H_CHECK_STREQ_HEAD_NAME(2_1), H_CHECK_STREQ_BODY_NAME(2_1),
          "2", "1", "\"2\" != \"1\" \\(2 != 1\\)", false },
        { H_CHECK_STREQ_HEAD_NAME(2_2), H_CHECK_STREQ_BODY_NAME(2_2),
          "2", "2", "\"2\" != \"2\" \\(2 != 2\\)", true },
        { H_CHECK_STREQ_MSG_HEAD_NAME(1_1),
          H_CHECK_STREQ_MSG_BODY_NAME(1_1),
          "1", "1", "\"1\" != \"1\" \\(1 != 1\\): 1 does not match 1", true },
        { H_CHECK_STREQ_MSG_HEAD_NAME(1_2),
          H_CHECK_STREQ_MSG_BODY_NAME(1_2),
          "1", "2", "\"1\" != \"2\" \\(1 != 2\\): 1 does not match 2", false },
        { H_CHECK_STREQ_MSG_HEAD_NAME(2_1),
          H_CHECK_STREQ_MSG_BODY_NAME(2_1),
          "2", "1", "\"2\" != \"1\" \\(2 != 1\\): 2 does not match 1", false },
        { H_CHECK_STREQ_MSG_HEAD_NAME(2_2),
          H_CHECK_STREQ_MSG_BODY_NAME(2_2),
          "2", "2", "\"2\" != \"2\" \\(2 != 2\\): 2 does not match 2", true },
        { H_CHECK_STREQ_HEAD_NAME(vars), H_CHECK_STREQ_BODY_NAME(vars),
          check_streq_var1, check_streq_var2,
          "check_streq_var1 != check_streq_var2 \\("
          CHECK_STREQ_VAR1 " != " CHECK_STREQ_VAR2 "\\)", false },
        { NULL, NULL, 0, 0, "", false }
    };
    do_check_eq_tests(tests);
}
示例#2
0
ATF_TC_BODY(msg_embedded_fmt, tc)
{
    struct test {
        void (*head)(atf_tc_t *);
        void (*body)(const atf_tc_t *);
        bool fatal;
        const char *msg;
    } *t, tests[] = {
       {  H_CHECK_HEAD_NAME(msg), H_CHECK_BODY_NAME(msg), false,
          "aux_bool\\(\"%d\"\\) not met" },
       {  H_REQUIRE_HEAD_NAME(msg), H_REQUIRE_BODY_NAME(msg), true,
          "aux_bool\\(\"%d\"\\) not met" },
       {  H_CHECK_STREQ_HEAD_NAME(msg), H_CHECK_STREQ_BODY_NAME(msg), false,
          "aux_str\\(\"%d\"\\) != \"\" \\(foo != \\)" },
       {  H_REQUIRE_STREQ_HEAD_NAME(msg), H_REQUIRE_STREQ_BODY_NAME(msg), true,
          "aux_str\\(\"%d\"\\) != \"\" \\(foo != \\)" },
       { NULL, NULL, false, NULL }
    };

    for (t = &tests[0]; t->head != NULL; t++) {
        printf("Checking with an expected '%s' message\n", t->msg);

        init_and_run_h_tc("h_check", t->head, t->body);

        if (t->fatal) {
            bool matched =
                grep_file("result", "^failed: .*macros_test.c:[0-9]+: "
                          "%s$", t->msg);
            ATF_CHECK_MSG(matched, "couldn't find error string in result");
        } else {
            bool matched = grep_file("error", "Check failed: .*"
                "macros_test.c:[0-9]+: %s$", t->msg);
            ATF_CHECK_MSG(matched, "couldn't find error string in output");
        }
    }
}