Example #1
0
ATF_TC_BODY(require_streq, tc)
{
    struct require_eq_test tests[] = {
        { H_REQUIRE_STREQ_HEAD_NAME(1_1), H_REQUIRE_STREQ_BODY_NAME(1_1),
          "1", "1", "\"1\" != \"1\" \\(1 != 1\\)", true },
        { H_REQUIRE_STREQ_HEAD_NAME(1_2), H_REQUIRE_STREQ_BODY_NAME(1_2),
          "1", "2", "\"1\" != \"2\" \\(1 != 2\\)", false },
        { H_REQUIRE_STREQ_HEAD_NAME(2_1), H_REQUIRE_STREQ_BODY_NAME(2_1),
          "2", "1", "\"2\" != \"1\" \\(2 != 1\\)", false },
        { H_REQUIRE_STREQ_HEAD_NAME(2_2), H_REQUIRE_STREQ_BODY_NAME(2_2),
          "2", "2", "\"2\" != \"2\" \\(2 != 2\\)", true },
        { H_REQUIRE_STREQ_MSG_HEAD_NAME(1_1),
          H_REQUIRE_STREQ_MSG_BODY_NAME(1_1),
          "1", "1", "\"1\" != \"1\" \\(1 != 1\\): 1 does not match 1", true },
        { H_REQUIRE_STREQ_MSG_HEAD_NAME(1_2),
          H_REQUIRE_STREQ_MSG_BODY_NAME(1_2),
          "1", "2", "\"1\" != \"2\" \\(1 != 2\\): 1 does not match 2", false },
        { H_REQUIRE_STREQ_MSG_HEAD_NAME(2_1),
          H_REQUIRE_STREQ_MSG_BODY_NAME(2_1),
          "2", "1", "\"2\" != \"1\" \\(2 != 1\\): 2 does not match 1", false },
        { H_REQUIRE_STREQ_MSG_HEAD_NAME(2_2),
          H_REQUIRE_STREQ_MSG_BODY_NAME(2_2),
          "2", "2", "\"2\" != \"2\" \\(2 != 2\\): 2 does not match 2", true },
        { H_REQUIRE_STREQ_HEAD_NAME(vars), H_REQUIRE_STREQ_BODY_NAME(vars),
          require_streq_var1, require_streq_var2,
          "require_streq_var1 != require_streq_var2 \\("
          REQUIRE_STREQ_VAR1 " != " REQUIRE_STREQ_VAR2 "\\)", false },
        { NULL, NULL, 0, 0, "", false }
    };
    do_require_eq_tests(tests);
}
Example #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");
        }
    }
}