END_TEST START_TEST (document_type) { reset_errno(); size_t c = model_size(model); assert_noerr(); assert_uint_eq(1, c); reset_errno(); Document *d = model_document(model, 0); assert_noerr(); assert_not_null(d); reset_errno(); Node *bogus = model_document(model, 1); assert_errno(EINVAL); assert_null(bogus); reset_errno(); Node *r1 = model_document_root(model, 0); assert_noerr(); assert_not_null(r1); assert_node_kind(r1, MAPPING); reset_errno(); Node *r2 = document_root(d); assert_noerr(); assert_not_null(r2); assert_ptr_eq(r1, r2); }
void testAlarmInsertionOfThreeEvents(void) { int* e2_arg = malloc(sizeof(int)); *e2_arg = test_e2_arg; alarm_insert(test_e2_timeout, assign_handler, e2_arg); int* e3_arg = malloc(sizeof(int)); *e3_arg = test_e3_arg; alarm_insert(test_e3_timeout, assign_handler, e3_arg); event_bin_t* head = alarm_queue->head; if(!assert_not_null(head)) return; uint16_t acc_value = 0; event_bin_t* bin1 = head->next; if(!assert_not_null(bin1)) return; if(!assert_equal_uint16(test_e2_timeout - acc_value, bin1->e.rank)) return; if(!assert_equal_ptr(assign_handler, bin1->e.handler)) return; if(!assert_equal_ptr(e2_arg, bin1->e.arg_ptr)) return; acc_value += bin1->e.rank; event_bin_t* bin2 = bin1->next; if(!assert_not_null(bin2)) return; if(!assert_equal_uint16(test_e1_timeout - acc_value, bin2->e.rank)) return; if(!assert_equal_ptr(assign_handler, bin2->e.handler)) return; acc_value += bin2->e.rank; event_bin_t* bin3 = bin2->next; if(!assert_not_null(bin3)) return; if(!assert_equal_uint16(test_e3_timeout - acc_value, bin3->e.rank)) return; if(!assert_equal_ptr(assign_handler, bin3->e.handler)) return; assert_equal_ptr(e3_arg, bin3->e.arg_ptr); }
int t_load(struct t_tune *tune, const char *fmtfile) { int ret; char *errmsg; struct t_taglist *tlist; extern const struct t_format *Fflag; FILE *fp; assert_not_null(tune); assert_not_null(fmtfile); if (strlen(fmtfile) == 0 || strcmp(fmtfile, "-") == 0) fp = stdin; else { fp = fopen(fmtfile, "r"); if (fp == NULL) { warn("%s: fopen", fmtfile); return (-1); } } tlist = Fflag->fmt2tags(fp, &errmsg); if (fp != stdin) (void)fclose(fp); if (tlist == NULL) { warnx("%s", errmsg); free(errmsg); return (-1); } ret = t_tune_set_tags(tune, tlist); t_taglist_delete(tlist); return (ret); }
END_TEST START_TEST (load_from_file) { size_t yaml_size = strlen((char *)YAML); FILE *input = tmpfile(); size_t written = fwrite(YAML, sizeof(char), yaml_size, input); assert_uint_eq(written, yaml_size); int ret = fflush(input); assert_int_eq(0, ret); rewind(input); loader_context *loader = make_file_loader(input); assert_not_null(loader); assert_int_eq(LOADER_SUCCESS, loader_status(loader)); document_model *model = load(loader); assert_not_null(model); assert_model_state(loader, model); fclose(input); model_free(model); loader_free(loader); }
bool test_ipv4_icmp4( void ) { u_int8_t protocol; struct tuple tuple; struct sk_buff* skb = NULL; bool success = true; protocol = IPPROTO_ICMP; success &= init_tuple_for_test_ipv4( &tuple , protocol ); skb = init_skb_for_test( &tuple, protocol ); success &= assert_not_null(skb, "init_skb_for_test"); success &= assert_equals_int(NF_DROP, ipv4_icmp4( skb, &tuple ), "See if we discard an IPv4 ICMP packet, which tries to start a communication."); kfree_skb(skb); protocol = IPPROTO_ICMP; success &= init_tuple_for_test_ipv6( &tuple , protocol ); skb = init_skb_for_test( &tuple, protocol ); success &= assert_not_null(skb, "init_skb_for_test"); success &= assert_equals_int(NF_ACCEPT, ipv6_icmp6(skb, &tuple ), "See if we can process correctly an IPv6 ICMP packet."); kfree_skb(skb); protocol = IPPROTO_ICMP; success &= init_tuple_for_test_ipv4( &tuple , protocol ); skb = init_skb_for_test( &tuple, protocol ); success &= assert_not_null(skb, "init_skb_for_test"); success &= assert_equals_int(NF_ACCEPT, ipv4_icmp4( skb, &tuple ), "See if we can process correctly an expected IPv4 ICMP packet."); kfree_skb(skb); return success; }
END_TEST START_TEST (scalar_boolean) { reset_errno(); Node *r = model_document_root(model, 0); assert_noerr(); assert_not_null(r); assert_node_kind(r, MAPPING); reset_errno(); Node *three = mapping_get(mapping(r), (uint8_t *)"three", 5ul); assert_noerr(); assert_not_null(three); assert_node_kind(three, SCALAR); assert_true(scalar_boolean_is_false(scalar(three))); assert_false(scalar_boolean_is_true(scalar(three))); reset_errno(); Node *four = mapping_get(mapping(r), (uint8_t *)"four", 4ul); assert_noerr(); assert_not_null(four); assert_node_kind(four, SCALAR); assert_true(scalar_boolean_is_true(scalar(four))); assert_false(scalar_boolean_is_false(scalar(four))); }
void test_assertions () { char *c; assert(1+1 == 2); assert(1+1 == 3); assert_true(1+1 == 2); assert_true(1+1 == 3); assert_false(1+1 == 3); assert_false(1+1 == 2); assert_equals_int(1, 1); assert_equals_int(1, 2); assert_not_equals_int(1, 2); assert_not_equals_int(1, 1); assert_equals_int(1, 1); assert_equals_int(1, 2); assert_not_equals_int(1, 2); assert_not_equals_int(1, 1); assert_equals_str("abc", "abc"); assert_equals_str("abc", "def"); assert_not_equals_str("abc", "def"); assert_not_equals_str("abc", "abc"); c = NULL; assert_null(c); c = malloc(sizeof(char)); assert_null(c); c = malloc(sizeof(char)); assert_not_null(c); c = NULL; assert_not_null(c); assert_equals_float(2.0, 2.0); assert_equals_float(2.0, 2.1); assert_not_equals_float(2.0, 2.1); assert_not_equals_float(2.0, 2.0); assert_equals_double(2.0, 2.0); assert_equals_double(2.0, 2.1); assert_not_equals_double(2.0, 2.1); assert_not_equals_double(2.0, 2.0); }
void testFollowerOfHeadAfterInsertingOne(void) { int* e1_arg = malloc(sizeof(int)); *e1_arg = test_e1_arg; alarm_insert(test_e1_timeout, assign_handler, e1_arg); event_bin_t* head = alarm_queue->head; if(!assert_not_null(head)) return; event_bin_t* follow_head = head->next; if(!assert_not_null(follow_head)) return; if(!assert_equal_uint16(test_e1_timeout, follow_head->e.rank)) return; if(!assert_equal_ptr(assign_handler, follow_head->e.handler)) return; assert_equal_ptr(e1_arg, follow_head->e.arg_ptr); }
void test_that_pends() { void* pointer = (void*) 0x1; /* Asks dojo_unit to hold this tests execution but counts it */ pending(); /* Only verifies if point != NULL (or == NULL if assert_null) */ assert_not_null("0x1 should not be NULL", pointer); }
END_TEST START_TEST (test_loads_right_negative_examples) { Tagger *tagger = build_tagger(document, item_cache); assert_not_null(tagger->negative_examples); assert_equal_s("urn:peerworks.org:entry#880389", tagger->negative_examples[0]); }
/* * GUC array: one invalid guc + non-userset guc * return ArrayType contain non-userset guc, ignore invalid guc */ void test__GUCArrayReset__invalid_guc(void **state) { ArrayType *in; ArrayType *out; Datum d; List *guc_list; int elems; build_guc_variables(); will_return(superuser, false); /* construct text array */ elems = 2; guc_list = list_make2("invalid_guc=true", "gp_log_format=text"); in = create_guc_array(guc_list, elems); out = GUCArrayReset(in); assert_not_null(out); assert_int_equal(ARR_DIMS(out)[0], 1); d = PointerGetDatum(ARR_DATA_PTR(out)); assert_int_equal(strlen("gp_log_format=text"), VARLEN(d)); assert_memory_equal(VARDATA(d), "gp_log_format=text", VARLEN(d)); list_free(guc_list); pfree(in); pfree(out); }
/* * GUC array: mix of PGC_USERSET, PGC_POSTMASTER, PGC_SUSET * return ArrayType contains non-PGC_USERSET */ void test__GUCArrayReset__mix_guc(void **state) { ArrayType *in; ArrayType *out; Datum d; List *guc_list; int elems; build_guc_variables(); will_return(superuser, false); /* construct text array */ elems = 4; guc_list = list_make4("password_encryption=on", "log_error_verbosity=verbose", "application_name=mixtest", "allow_system_table_mods=dml"); in = create_guc_array(guc_list, elems); out = GUCArrayReset(in); assert_not_null(out); assert_int_equal(ARR_DIMS(out)[0], 1); d = PointerGetDatum(ARR_DATA_PTR(out)); assert_int_equal(strlen("log_error_verbosity=verbose"), VARLEN(d)); assert_memory_equal(VARDATA(d), "log_error_verbosity=verbose", VARLEN(d)); list_free(guc_list); pfree(in); pfree(out); }
END_TEST START_TEST (absolute_multi_step) { char *expression = "$.foo.baz..yobble.thingum"; reset_errno(); parser_context *context = make_parser((uint8_t *)expression, strlen(expression)); assert_not_null(context); assert_noerr(); jsonpath *path = parse(context); assert_parser_success(expression, context, path, ABSOLUTE_PATH, 5); assert_root_step(path); assert_single_name_step(path, 1, "foo"); assert_single_name_step(path, 2, "baz"); assert_recursive_name_step(path, 3, "yobble"); assert_single_name_step(path, 4, "thingum"); assert_no_predicate(path, 1); assert_no_predicate(path, 2); assert_no_predicate(path, 3); assert_no_predicate(path, 4); path_free(path); parser_free(context); }
/** * Inserts a single entry, validates it, removes it, validates again. * Does not touch the session tables. */ static bool simple_bib(void) { struct ipv4_transport_addr addr = addr4[0]; struct bib_entry *bib; bool success = true; if (is_error(pool4_get_any_port(L4PROTO_TCP, &addr.l3, &addr.l4))) return false; bib = bib_create(&addr, &addr6[0], false, L4PROTO_TCP); if (!assert_not_null(bib, "Allocation of test BIB entry")) return false; success &= assert_equals_int(0, bibdb_add(bib), "BIB insertion call"); success &= assert_bib("BIB insertion state", bib, false, true, false); if (!success) return false; success &= assert_equals_int(0, bibdb_remove(bib, false), "BIB removal call"); success &= assert_bib("BIB removal state", bib, false, false, false); if (!success) return false; bib_kfree(bib); return success; }
END_TEST START_TEST (test_load_tagging_from_tag_definition_document_set_tagger_term) { Tagger *tagger = build_tagger(document, item_cache); assert_not_null(tagger->term); assert_equal_s("a-religion", tagger->term); }
END_TEST START_TEST (test_load_tagger_from_tag_definition_document_sets_classifier_taggings_url) { Tagger *tagger = build_tagger(document, item_cache); assert_not_null(tagger->classifier_taggings_url); assert_equal_s("http://localhost:8888/results", tagger->classifier_taggings_url); }
END_TEST START_TEST (test_load_tagger_from_tag_definition_document_sets_training_url) { Tagger *tagger = build_tagger(document, item_cache); assert_not_null(tagger->training_url); assert_equal_s("http://trunk.mindloom.org:80/seangeo/tags/a-religion/training.atom", tagger->training_url); }
END_TEST START_TEST (test_load_tagging_from_tag_definition_document_set_tagger_scheme) { Tagger *tagger = build_tagger(document, item_cache); assert_not_null(tagger->scheme); assert_equal_s("http://trunk.mindloom.org:80/seangeo/tags/", tagger->scheme); }
void testAlarmWithoutInsertingAnythingGetNextOfHead(void) { event_bin_t* head = alarm_queue->head; if(!assert_not_null(head)) return; event_bin_t* after_head = head->next; if(!assert_is_null(after_head)) return; }
} END_TEST START_TEST (precompute_creates_probabilities_for_each_token_in_the_pools) { precompute_tagger(tagger, random_background); assert_not_null(tagger->clues); assert_equal(542, tagger->clues->size); } END_TEST
/** * Inserts a single entry, validates it, removes it, validates again. * Does not touch the session tables. */ bool simple_bib(void) { struct bib_entry *bib; bool success = true; bib = create_bib_entry(0, 0); if (!assert_not_null(bib, "Allocation of test BIB entry")) return false; success &= assert_equals_int(0, bib_add(bib, IPPROTO_TCP), "BIB insertion call"); success &= assert_bib("BIB insertion state", bib, false, true, false); if (!success) /* * Rather have a slight memory leak than corrupted memory. Because of the error, the table * might or might not have a reference to the entry, and if it does, it will try to kfree * it during bib_destroy(). Hence, better not free it here. */ return false; success &= assert_true(bib_remove(bib, IPPROTO_TCP), "BIB removal call"); success &= assert_bib("BIB removal state", bib, false, false, false); if (!success) return false; kfree(bib); return success; }
/** * For every key (from the "keys" array), extracts its corresponding value from "table", and asserts * it equals its corresponding expected value (from the "expected_values" array). * * Assumes "keys" and "expected_values" have the same length. */ static bool assert_table_content(struct test_table *table, struct table_key *keys, struct table_value *expected_values, char *test_name) { int i; bool success = true; for (i = 0; i < 4; i++) { struct table_value *current_val = test_table_get(table, &keys[i]); if (expected_values[i].value == -1) { success &= assert_null(current_val, test_name); } else { bool local = true; local &= assert_not_null(current_val, test_name); if (local) local &= assert_equals_int(expected_values[i].value, current_val->value, test_name); success &= local; } } return success; }
END_TEST START_TEST (scalar_type) { reset_errno(); Node *r = model_document_root(model, 0); assert_noerr(); assert_not_null(r); assert_node_kind(r, MAPPING); reset_errno(); Node *s = mapping_get(mapping(r), (uint8_t *)"two", 3ul); assert_noerr(); assert_not_null(s); assert_node_kind(s, SCALAR); assert_scalar_value((s), "foo2"); }
END_TEST START_TEST (load_from_string) { size_t yaml_size = strlen((char *)YAML); loader_context *loader = make_string_loader(YAML, yaml_size); assert_not_null(loader); document_model *model = load(loader); assert_not_null(model); assert_int_eq(LOADER_SUCCESS, loader_status(loader)); assert_model_state(loader, model); model_free(model); loader_free(loader); }
} END_TEST START_TEST(retrieve_job_via_id) { ClassificationJob *job = ce_add_classification_job(ce, TAG_ID); assert_not_null(job); ClassificationJob *fetched_job = ce_fetch_classification_job(ce, job->id); assert_equal(job, fetched_job); } END_TEST
static LogMessage * parse_geoip_into_log_message(const gchar *input) { LogMessage *msg; msg = parse_geoip_into_log_message_no_check(input); assert_not_null(msg, "expected geoip-parser success and it returned failure, input=%s", input); return msg; }
END_TEST bool check_sequence(Node *each, void *context) { assert_not_null(each); size_t *count = (size_t *)context; (*count)++; return true; }
/* * Test find_option */ void test__find_option(void **state) { build_guc_variables(); struct config_generic *config; config = find_option("unknown_name", LOG); assert_null(config); config = find_option("password_encryption", LOG); assert_not_null(config); config = find_option("gp_resqueue_priority_cpucores_per_segment", LOG); assert_not_null(config); /* supported obsolete guc name */ config = find_option("work_mem", LOG); assert_not_null(config); }
static void assert_error(GError *error, gint code, const gchar *expected_message) { assert_not_null(error, "GError expected to be non-NULL"); assert_gint(error->code, code, "GError error code is as expected"); if (expected_message) assert_string(error->message, expected_message, "GError error message is as expected"); }
static LogMessage * parse_kv_into_log_message(const gchar *kv) { LogMessage *msg; msg = parse_kv_into_log_message_no_check(kv); assert_not_null(msg, "expected kv-parser success and it returned failure, kv=%s", kv); return msg; }