1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
#include <test.h>
#include <syntax.h>
#include <regex.h> /* StringMatchFull */
static void test_lookup_promise_type_agent_vars(void)
{
const PromiseTypeSyntax *s = PromiseTypeSyntaxGet("agent", "vars");
assert_true(s);
assert_string_equal("vars", s->promise_type);
}
static void test_lookup_promise_type_common_vars(void)
{
const PromiseTypeSyntax *s = PromiseTypeSyntaxGet("common", "vars");
assert_true(s);
assert_string_equal("vars", s->promise_type);
}
static void test_lookup_promise_type_edit_xml_build_xpath(void)
{
const PromiseTypeSyntax *s = PromiseTypeSyntaxGet("edit_xml", "build_xpath");
assert_true(s);
assert_string_equal("build_xpath", s->promise_type);
}
static void test_lookup_promise_type_edit_line_delete_lines(void)
{
const PromiseTypeSyntax *s = PromiseTypeSyntaxGet("edit_line", "delete_lines");
assert_true(s);
assert_string_equal("delete_lines", s->promise_type);
}
static void test_lookup_promise_type_edit_xml_commons(void)
{
const PromiseTypeSyntax *s = PromiseTypeSyntaxGet("edit_xml", "*");
assert_true(s);
assert_string_equal("edit_xml", s->bundle_type);
assert_string_equal("*", s->promise_type);
}
static void test_lookup_promise_type_global_commons(void)
{
const PromiseTypeSyntax *s = PromiseTypeSyntaxGet("*", "*");
assert_true(s);
assert_string_equal("*", s->bundle_type);
assert_string_equal("*", s->promise_type);
}
static void test_lookup_constraint_edit_xml_set_attribute_attribute_value(void)
{
const PromiseTypeSyntax *s = PromiseTypeSyntaxGet("edit_xml", "set_attribute");
assert_true(s);
assert_string_equal("set_attribute", s->promise_type);
const ConstraintSyntax *x = PromiseTypeSyntaxGetConstraintSyntax(s, "attribute_value");
assert_true(x);
assert_string_equal("attribute_value", x->lval);
}
static void test_lookup_body_classes(void)
{
const BodySyntax *x = BodySyntaxGet("classes");
assert_true(x);
const ConstraintSyntax *y = BodySyntaxGetConstraintSyntax(x->constraints, "promise_repaired");
assert_true(y);
assert_string_equal("promise_repaired", y->lval);
}
static void test_lookup_body_process_count(void)
{
const BodySyntax *x = BodySyntaxGet("process_count");
assert_true(x);
const ConstraintSyntax *y = BodySyntaxGetConstraintSyntax(x->constraints, "match_range");
assert_true(y);
assert_string_equal("match_range", y->lval);
}
static void test_lookup_body_delete_select(void)
{
const BodySyntax *x = BodySyntaxGet("delete_select");
assert_true(x);
const ConstraintSyntax *y = BodySyntaxGetConstraintSyntax(x->constraints, "delete_if_startwith_from_list");
assert_true(y);
assert_string_equal("delete_if_startwith_from_list", y->lval);
}
static void test_copy_from_servers(void)
{
const BodySyntax *x = BodySyntaxGet("copy_from");
assert_true(x);
const ConstraintSyntax *y = BodySyntaxGetConstraintSyntax(x->constraints, "servers");
assert_true(y);
assert_true(StringMatchFull(y->range.validation_string, "127.0.0.1"));
assert_true(StringMatchFull(y->range.validation_string, "www-dashed.stuff.com"));
assert_true(StringMatchFull(y->range.validation_string, "2604:2000:8441:e300:224:d7ff:fec5:338"));
}
static void test_typecheck_null_rval(void)
{
SyntaxTypeMatch err = CheckConstraintTypeMatch("whatever", (Rval) { NULL, RVAL_TYPE_NOPROMISEE },
CF_DATA_TYPE_STRING, "abc", 0);
assert_int_equal(SYNTAX_TYPE_MATCH_ERROR_GOT_NULL, err);
}
int main()
{
PRINT_TEST_BANNER();
const UnitTest tests[] =
{
unit_test(test_lookup_promise_type_agent_vars),
unit_test(test_lookup_promise_type_common_vars),
unit_test(test_lookup_promise_type_edit_xml_build_xpath),
unit_test(test_lookup_promise_type_edit_line_delete_lines),
unit_test(test_lookup_promise_type_edit_xml_commons),
unit_test(test_lookup_promise_type_global_commons),
unit_test(test_lookup_body_classes),
unit_test(test_lookup_body_process_count),
unit_test(test_lookup_body_delete_select),
unit_test(test_lookup_constraint_edit_xml_set_attribute_attribute_value),
unit_test(test_copy_from_servers),
unit_test(test_typecheck_null_rval),
};
return run_tests(tests);
}
|