Example #1
0
/**
  Testuje wstawianie do drzewa.
  @param state Środowisko testowe.
  */
static void trie_insert_word_test(void** state)
{
    Trie *trie = trie_new();

    size_t n_words = 4;
    wchar_t *words[] = {L"wątły", L"wątły", L"wątlejszy", L"łódka"};

    for (size_t i = 0; i < n_words; i++)
    {
        if (i == 1) assert_false(trie_insert_word(trie, words[i]));
        else assert_true(trie_insert_word(trie, words[i]));
    }

    for (size_t i = 0; i < n_words; i++) assert_true(trie_has_word(trie, words[i]));

    trie_done(trie);
}
void test__rb_tree_iterator_before__false(void** state)
{
    _rb_tree_t* pt_rb_tree = _create_rb_tree("int");
    _rb_tree_iterator_t it_first;
    _rb_tree_iterator_t it_second;
    int elem = 100;

    _rb_tree_init(pt_rb_tree, NULL);
    _rb_tree_insert_unique(pt_rb_tree, &elem);
    elem = 2;
    _rb_tree_insert_unique(pt_rb_tree, &elem);
    it_first = _rb_tree_end(pt_rb_tree);
    it_second = _rb_tree_begin(pt_rb_tree);
    assert_false(_rb_tree_iterator_before(it_first, it_second));

    _rb_tree_destroy(pt_rb_tree);
}
Example #3
0
static void
empty(void **state) {
	t_array	array;
	size_t	put;

	assert_true(D_ARRAY(init)(&array, 0, 0, sizeof(int)));
	put = 0;
	while (put < 10) {
		assert_true(D_ARRAY(push_back)(&array, &put));
		put++;
	}
	assert_false(D_ARRAY(empty)(&array));
	D_ARRAY(clear)(&array);
	assert_true(D_ARRAY(empty)(&array));
	D_ARRAY(destroy)(&array);
	(void)state;
}
Example #4
0
static void
cm_file_local_io(void **state)
{
	int ret;
	char *path = NULL;
	struct elasto_fh *fh;
	struct cm_unity_state *cm_us = cm_unity_state_get();
	uint8_t buf[1024];

	ret = asprintf(&path, "%s/io_test", cm_us->local_tmpdir);
	assert_false(ret < 0);

	ret = elasto_fopen(&cm_us->local_auth,
			   path,
			   ELASTO_FOPEN_CREATE,
			   NULL, &fh);
	assert_int_equal(ret, ELASTO_FOPEN_RET_CREATED);

	cm_file_local_buf_fill(buf, ARRAY_SIZE(buf), 0);
	ret = elasto_fwrite(fh, 0, ARRAY_SIZE(buf), buf);
	assert_false(ret < 0);

	/* leave a 1k hole between first and second write */
	cm_file_local_buf_fill(buf, ARRAY_SIZE(buf), ARRAY_SIZE(buf));
	ret = elasto_fwrite(fh, ARRAY_SIZE(buf) * 2, ARRAY_SIZE(buf), buf);
	assert_false(ret < 0);

	memset(buf, 0, ARRAY_SIZE(buf));
	/* check first, hole zeros, then last chunk */
	ret = elasto_fread(fh, 0, ARRAY_SIZE(buf), buf);
	assert_false(ret < 0);

	cm_file_local_buf_check(buf, ARRAY_SIZE(buf), 0);

	ret = elasto_fread(fh, ARRAY_SIZE(buf), ARRAY_SIZE(buf), buf);
	assert_false(ret < 0);

	cm_file_local_buf_check_zero(buf, ARRAY_SIZE(buf));

	ret = elasto_fread(fh, ARRAY_SIZE(buf) * 2, ARRAY_SIZE(buf), buf);
	assert_false(ret < 0);

	cm_file_local_buf_check(buf, ARRAY_SIZE(buf), ARRAY_SIZE(buf));

	ret = elasto_funlink_close(fh);
	assert_false(ret < 0);
	free(path);
}
Example #5
0
static void torture_auth_kbdint_nonblocking(void **state) {
    struct torture_state *s = *state;
    ssh_session session = s->ssh.session;
    int rc;

    rc = ssh_options_set(session, SSH_OPTIONS_USER, TORTURE_SSH_USER_BOB);
    assert_int_equal(rc, SSH_OK);

    rc = ssh_connect(session);
    assert_int_equal(rc, SSH_OK);

    ssh_set_blocking(session,0);
    do {
      rc = ssh_userauth_none(session, NULL);
    } while (rc == SSH_AUTH_AGAIN);

    /* This request should return a SSH_REQUEST_DENIED error */
    if (rc == SSH_ERROR) {
        assert_true(ssh_get_error_code(session) == SSH_REQUEST_DENIED);
    }
    rc = ssh_userauth_list(session, NULL);
    assert_true(rc & SSH_AUTH_METHOD_INTERACTIVE);

    do {
        rc = ssh_userauth_kbdint(session, NULL, NULL);
    } while (rc == SSH_AUTH_AGAIN);
    assert_int_equal(rc, SSH_AUTH_INFO);
    assert_int_equal(ssh_userauth_kbdint_getnprompts(session), 1);
    do {
        rc = ssh_userauth_kbdint_setanswer(session, 0, TORTURE_SSH_USER_BOB_PASSWORD);
    } while (rc == SSH_AUTH_AGAIN);
    assert_false(rc < 0);

    do {
        rc = ssh_userauth_kbdint(session, NULL, NULL);
    } while (rc == SSH_AUTH_AGAIN);
    /* Sometimes, SSH server send an empty query at the end of exchange */
    if(rc == SSH_AUTH_INFO) {
        assert_int_equal(ssh_userauth_kbdint_getnprompts(session), 0);
        do {
            rc = ssh_userauth_kbdint(session, NULL, NULL);
        } while (rc == SSH_AUTH_AGAIN);
    }
    assert_int_equal(rc, SSH_AUTH_SUCCESS);
}
Example #6
0
void test_zero_length( void ** state )
{
#if defined(PSO_UNIT_TESTS)
   int errcode;
   bool ok;

   ok = psonTopFolderEditObject( pTopFolder,
                                 "Test1/Test2",
                                 0,
                                 PSO_FAST_MAP,
                                 &folderItem,
                                 &context );
   assert_false( ok );
   errcode = psocGetLastError( &context.errorHandler );
   assert_true( errcode == PSO_INVALID_OBJECT_NAME );
#endif
   return;
}
Example #7
0
void test_wrong_type( void ** state )
{
#if defined(PSO_UNIT_TESTS)
   int errcode;
   bool ok;

   ok = psonTopFolderEditObject( pTopFolder,
                                 "Test1/Test2",
                                 strlen("Test1/Test2"),
                                 PSO_FOLDER,
                                 &folderItem,
                                 &context );
   assert_false( ok );
   errcode = psocGetLastError( &context.errorHandler );
   assert_true( errcode == PSO_WRONG_OBJECT_TYPE );
#endif
   return;
}
Example #8
0
void test_wrong_length( void ** state )
{
#if defined(PSO_UNIT_TESTS)
   int errcode;
   bool ok;

   ok = psonTopFolderEditObject( pTopFolder,
                                 "Test1/Test2",
                                 PSO_MAX_FULL_NAME_LENGTH+1,
                                 PSO_FAST_MAP,
                                 &folderItem,
                                 &context );
   assert_false( ok );
   errcode = psocGetLastError( &context.errorHandler );
   assert_true( errcode == PSO_OBJECT_NAME_TOO_LONG );
#endif
   return;
}
Example #9
0
void test_exodus_file_query(void** state)
{
  size_t real_size;
  float version;
  int num_mpi_processes;
  real_array_t* times = real_array_new();
  bool result = exodus_file_query("test.exo", &real_size, &version,
                                  &num_mpi_processes, times);
  assert_false(result); // has 2D elements!

  result = exodus_file_query("test-nfaced.exo", &real_size, &version,
                             &num_mpi_processes, times);
  assert_true(result);
  assert_true(real_size == sizeof(float));
  assert_true(version >= 6.09);
  assert_true(times->size == 0);
  real_array_free(times);
}
Example #10
0
static void
prevent_stack_overflow(void)
{
	assert_int_equal(0, add_user_keys(L"j", L"j", NORMAL_MODE, 0));
	assert_false(IS_KEYS_RET_CODE(execute_keys(L"j")));

	assert_int_equal(0, add_user_keys(L"q", L"q", NORMAL_MODE, 0));
	assert_int_equal(KEYS_UNKNOWN, execute_keys(L"q"));

	set_def_handler(NORMAL_MODE, handler);

	assert_int_equal(0, add_user_keys(L"t", L"toto", NORMAL_MODE, 0));
	assert_int_equal(0, execute_keys(L"t"));

	assert_int_equal(4, counter);

	set_def_handler(NORMAL_MODE, NULL);
}
Example #11
0
static void
test_aux_data_copy_separates_the_copies(void)
{
  LogTransportAuxData *aux = construct_aux_with_some_data();
  LogTransportAuxData aux_copy;
  gchar *orig, *copy;
  
  log_transport_aux_data_copy(&aux_copy, aux);
  log_transport_aux_data_add_nv_pair(aux, "super", "lativus");
  
  orig = _concat_nvpairs(aux);
  copy = _concat_nvpairs(&aux_copy);
  assert_false(strcmp(orig, copy) == 0, "copy incorrectly copied aux->nvpairs as change to one of them affected the other, orig=%s, copy=%s", orig, copy);
  g_free(orig);
  g_free(copy);
  log_transport_aux_data_destroy(&aux_copy);
  free_aux(aux);
}
Example #12
0
static void test_util_bundle_qualified_name(void)
{
    Bundle *b = xcalloc(1, sizeof(struct Bundle_));
    assert_false(BundleQualifiedName(b));

    b->name = "bar";

    char *fqname = BundleQualifiedName(b);
    assert_string_equal("default:bar", fqname);
    free(fqname);

    b->ns = "foo";
    fqname = BundleQualifiedName(b);
    assert_string_equal("foo:bar", fqname);
    free(fqname);

    free(b);
}
Example #13
0
static void test_list_select_last_matching_not_found(void)
{
    EvalContext *ctx = EvalContextNew();
    Item *list = NULL, *match = NULL, *prev = NULL;
    bool result;

    AppendItem(&list, "abc", NULL);
    AppendItem(&list, "def", NULL);
    AppendItem(&list, "ghi", NULL);
    AppendItem(&list, "abc", NULL);

    result = SelectLastItemMatching(ctx, "xyz", list, NULL, &match, &prev);
    assert_false(result);
    assert_int_equal(match, CF_UNDEFINED_ITEM);
    assert_int_equal(prev, CF_UNDEFINED_ITEM);
    DeleteItemList(list);
    EvalContextDestroy(ctx);
}
Example #14
0
static void test_array_mm(void **state)
{
	array_t(int) arr;
	array_init(arr);

	/* Reserve using fake memory allocator. */
	assert_false(array_reserve_mm(arr, 5, fake_reserve, NULL) >= 0);

	/* Reserve capacity and fill. */
	assert_true(array_reserve_mm(arr, 100, test_reserve, &global_mm) >= 0);
	for (unsigned i = 0; i < 100; ++i) {
		int ret = array_push(arr, i);
		assert_true(ret >= 0);
	}

	array_clear_mm(arr, mm_free, &global_mm);

}
Example #15
0
static void
test_log_proto_text_server_invalid_encoding(void)
{
  LogProtoServer *proto;
  gboolean success;

  log_proto_server_options_set_encoding(&proto_server_options, "never-ever-is-going-to-be-such-an-encoding");
  proto = construct_test_proto(
            log_transport_mock_stream_new(
              "", -1,
              LTM_EOF));

  start_grabbing_messages();
  success = log_proto_server_validate_options(proto);
  assert_grabbed_messages_contain("Unknown character set name specified; encoding='never-ever-is-going-to-be-such-an-encoding'", "message about unknown charset missing");
  assert_false(success, "validate_options() returned success but it should have failed");
  log_proto_server_free(proto);
}
Example #16
0
/** 
  test funkcji alphabet_init().
  Sprawdzenie czy w alfabecie znajdują się jedynie litery ze slownika.
  */
static void alphabet_init_test(void** state) {
	struct dictionary *dict = *state;
	struct letter_list *l = malloc(sizeof(letter_list));
	l->letter = '#';
	l->next = NULL;
	alphabet_init(dict->root, l);
	for (int i = 0; i < wcslen(first); i++)
		assert_true(is_char_in_list(l, first[i]));
	for (int i = 0; i < wcslen(second); i++)
		assert_true(is_char_in_list(l, second[i]));
	for (int i = 0; i < wcslen(third); i++)
		assert_true(is_char_in_list(l, third[i]));
	for (int i = 0; i < wcslen(fourth); i++)
		assert_true(is_char_in_list(l, fourth[i]));
	for (int i = 0; i < wcslen(fifth); i++)
		assert_true(is_char_in_list(l, fifth[i]));
	assert_false(is_char_in_list(l, 'k'));
}
Example #17
0
static void test_parse_bad_numbers(void **state)
{
    {
        const char *data = "[01]";
        assert_false(JsonParse(&data));
    }

    {
        const char *data = "[01.1]";
        assert_false(JsonParse(&data));
    }

    {
        const char *data = "[1.]";
        assert_false(JsonParse(&data));
    }

    {
        const char *data = "[e10]";
        assert_false(JsonParse(&data));
    }

    {
        const char *data = "[-e10]";
        assert_false(JsonParse(&data));
    }

    {
        const char *data = "[+2]";
        assert_false(JsonParse(&data));
    }

    {
        const char *data = "[1e]";
        assert_false(JsonParse(&data));
    }

    {
        const char *data = "[e10]";
        assert_false(JsonParse(&data));
    }
}
void
test__supported_filter_type(void **state)
{
	Oid oids[] =
	{
		INT2OID,
		INT4OID,
		INT8OID,
		FLOAT4OID,
		FLOAT8OID,
		NUMERICOID,
		TEXTOID,
		VARCHAROID,
		BPCHAROID,
		CHAROID,
		BYTEAOID,
		BOOLOID,
        DATEOID,
		CIRCLEOID /* unsupported type */
	};

	int array_size = sizeof(oids) / sizeof(oids[0]);
	bool result = false;
	int i = 0;

	/* supported types */
	for (; i < array_size-1; ++i)
	{
		result = supported_filter_type(oids[i]);
		assert_true(result);
	}
	/* unsupported type */
	result = supported_filter_type(oids[i]);
	assert_false(result);

	/* go over pxf_supported_types array */
	int nargs = sizeof(pxf_supported_types) / sizeof(Oid);
	assert_int_equal(nargs, (array_size-1));
	for (i = 0; i < nargs; ++i)
	{
		assert_true(supported_filter_type(pxf_supported_types[i]));
	}

}
/*
 * The object is not in the current local domain so it should NOT have
 * DB_FLAG_INTERNAL_UNIQUE_VALUE set
 */
static void test_objectSID_not_in_domain(void **state)
{
	struct ldbtest_ctx *test_ctx =
		talloc_get_type_abort(*state, struct ldbtest_ctx);
	struct ldb_context *ldb			= test_ctx->ldb;
	struct ldb_message *msg			= ldb_msg_new(test_ctx);
	struct ldb_message_element *el		= NULL;
	struct ldb_request *request		= NULL;
	struct ldb_request *original_request	= NULL;
	int rc;

	msg->dn = ldb_dn_new(msg, ldb, "dc=test");
	add_sid(msg, FOREIGN_SID);

	rc = ldb_build_add_req(
		&request,
		test_ctx->ldb,
		test_ctx,
		msg,
		NULL,
		NULL,
		ldb_op_default_callback,
		NULL);

	assert_int_equal(rc, LDB_SUCCESS);
	assert_non_null(request);
	original_request = request;

	rc = unique_object_sids_add(test_ctx->module, request);
	assert_int_equal(rc, LDB_SUCCESS);

	/*
	 * Check that the original request was passed to the next module
	 * and not a copy
	 */
	assert_ptr_equal(last_request, original_request);

	/*
	 * Check that the flag was not set on the objectSID element
	 */
	el = ldb_msg_find_element(msg, "objectSID");
	assert_non_null(el);
	assert_false(el->flags & LDB_FLAG_INTERNAL_FORCE_UNIQUE_INDEX);
}
Example #20
0
void
test_persist_state_in_use_handle_is_loaded(void)
{
    PersistState *state;
    guint8 version;
    gsize size;
    PersistEntryHandle handle;

    unlink("test_in_use.persist");
    write_test_file_for_test_in_use_handle(TRUE);

    state = create_persist_state_for_test("test_in_use.persist");

    handle = persist_state_lookup_entry(state, "alma", &size, &version);

    assert_false(handle == 0, "lookup failed when looking for simple entry with in_use = TRUE!");

    cancel_and_destroy_persist_state(state);
}
Example #21
0
void test_pass( void ** state )
{
#if defined(PSO_UNIT_TESTS)
   enum psoErrors errcode;
   
   errcode = psonHashTxInsert( pHash,
                               bucket,
                               (unsigned char*)key,
                               strlen(key),
                               data1,
                               strlen(data1),
                               &pNewItem,
                               &context );
   assert_true( errcode == PSO_OK );
   assert_false( pNewItem == NULL );
   
#endif
   return;
}
Example #22
0
void
stardate_assert(const gchar *msg_str, const int precision, const gchar *expected)
{

  LogMessage *logmsg = log_msg_new(msg_str, strlen(msg_str), NULL, &parse_options);

  char *template_command;
  int ret_val;
  if (precision == -1)
    ret_val = asprintf(&template_command, "$(stardate $UNIXTIME)");
  else
    ret_val = asprintf(&template_command, "$(stardate --digits %d $UNIXTIME)", precision);

  assert_false(ret_val == -1, "Memory allocation failed in asprintf.");
  assert_template_format_msg(template_command, expected, logmsg);
  free(template_command);

  log_msg_unref(logmsg);
}
} END_TEST

START_TEST(test_engine_starting_and_stopping) {
  ItemCache *item_cache;
  item_cache_create(&item_cache, "/tmp/valid-copy", &item_cache_options);
  item_cache_load(item_cache);
  tagger_cache = create_tagger_cache(item_cache, NULL);

  ClassificationEngine *engine = create_classification_engine(item_cache, tagger_cache, &opts);
  assert_not_null(engine);
  int start_code = ce_start(engine);
  assert_equal(1, start_code);
  assert_true(ce_is_running(engine));
  assert_equal(0, ce_num_jobs_in_system(engine));
  int stop_code = ce_stop(engine);
  assert_equal(1, stop_code);
  assert_false(ce_is_running(engine));
  free_classification_engine(engine);
} END_TEST
Example #24
0
static void
test_secure_channel_listen_start_setsockopt_bind_failed() {
  setup();

  int listen_fd = 1;

  listener_info.listen_fd = -1;

  expect_value( mock_socket, domain, PF_INET );
  expect_value( mock_socket, type, SOCK_STREAM );
  expect_value( mock_socket, protocol, 0 );
  will_return( mock_socket, listen_fd );

  expect_value_count( mock_setsockopt, sockfd, listen_fd, 1 );
  expect_value_count( mock_setsockopt, level, SOL_SOCKET, 1 );
  expect_value_count( mock_setsockopt, optname, SO_REUSEADDR, 1 );
  expect_not_value_count( mock_setsockopt, optval, NULL, 1 );
  expect_value_count( mock_setsockopt, optlen, sizeof( int ), 1 );
  will_return_count( mock_setsockopt, -1, 1 );

  expect_value_count( mock_setsockopt, sockfd, listen_fd, 1 );
  expect_value_count( mock_setsockopt, level, IPPROTO_TCP, 1 );
  expect_value_count( mock_setsockopt, optname, TCP_NODELAY, 1 );
  expect_not_value_count( mock_setsockopt, optval, NULL, 1 );
  expect_value_count( mock_setsockopt, optlen, sizeof( int ), 1 );
  will_return_count( mock_setsockopt, -1, 1 );

  expect_value( mock_bind, sockfd, listen_fd );
  expect_not_value( mock_bind, addr_in, NULL );
  expect_value( mock_bind, addrlen, sizeof( struct sockaddr_in ) );
  expect_value( mock_bind, sin_family32, AF_INET );
  expect_value( mock_bind, sin_port32, ( uint32_t ) htons( OFP_TCP_PORT ) );
  expect_value( mock_bind, addr_in->sin_addr.s_addr, htonl( INADDR_ANY ) );
  will_return( mock_bind, -1 );

  expect_value( mock_close, fd, listen_fd );
  will_return_void( mock_close );

  assert_false( secure_channel_listen_start( &listener_info ) );
  assert_true( listener_info.listen_fd == -1 );

  teardown();
}
Example #25
0
static void test_isEqualRefCount(void)
{
    int data2 = 0xbad00bad;
    RefCount *refCount1 = NULL;
    RefCount *refCount2 = NULL;

    // initialize refcount1
    RefCountNew(&refCount1);
    assert_int_equal(0, refCount1->user_count);
    assert_true(refCount1->last == NULL);
    assert_true(refCount1->users == NULL);

    // initialize refcount2 as a copy of refcount1
    refCount2 = refCount1;

    // isEqual should return true
    assert_true(RefCountIsEqual(refCount1, refCount2));

    /* Initialize refcount2 on its own */
    RefCountNew(&refCount2);
    assert_int_equal(0, refCount2->user_count);
    assert_true(refCount2->last == NULL);
    assert_true(refCount2->users == NULL);

    // isEqual should return false
    assert_false(RefCountIsEqual(refCount1, refCount2));

    // Add one to refcount1
    RefCountAttach(refCount1, &data2);

    // isEqual should return false
    assert_false(RefCountIsEqual(refCount1, refCount2));

    // Add the same to refcount2
    RefCountAttach(refCount2, &data2);

    // isEqual should return false
    assert_false(RefCountIsEqual(refCount1, refCount2));

    // Try one NULL
    assert_false(RefCountIsEqual(refCount1, NULL));
    assert_false(RefCountIsEqual(NULL, refCount2));

    // Both NULL
    assert_false(RefCountIsEqual(NULL, NULL));

    // Destroy both refcounts
    RefCountDestroy(&refCount1);
    RefCountDestroy(&refCount2);
}
Example #26
0
void remove_text_multi_value_does_nothing_when_doesnt_exist(void **state)
{
    form_init_module();

    DataForm *form = _new_form();
    g_hash_table_insert(form->tag_to_var, strdup("tag1"), strdup("var1"));

    FormField *field1 = _new_field();
    field1->var = strdup("var1");
    field1->type_t = FIELD_LIST_MULTI;
    field1->values = g_slist_append(field1->values, strdup("value1"));
    field1->values = g_slist_append(field1->values, strdup("value2"));
    field1->values = g_slist_append(field1->values, strdup("value3"));
    field1->values = g_slist_append(field1->values, strdup("value4"));
    form->fields = g_slist_append(form->fields, field1);

    gboolean res = form_remove_text_multi_value(form, "tag1", 5);

    int length = -1;
    int value_count = 0;
    GSList *curr_field = form->fields;
    while (curr_field != NULL) {
        FormField *field = curr_field->data;
        if (g_strcmp0(field->var, "var1") == 0) {
            length = g_slist_length(field->values);
            GSList *curr_value = field->values;
            while (curr_value != NULL) {
                if (g_strcmp0(curr_value->data, "value5") == 0) {
                    value_count++;
                }
                curr_value = g_slist_next(curr_value);
            }
        }
        curr_field = g_slist_next(curr_field);
    }

    assert_false(res);
    assert_int_equal(length, 4);
    assert_int_equal(value_count, 0);

    form_destroy(form);
}
Example #27
0
/*
 * Tests circular buffer - stores integers in it.
 */
static void
circular_buffer_test1(void **state)
{
    sr_cbuff_t *buffer = NULL;
    int rc = 0, i = 0;
    int tmp = 0;

    rc = sr_cbuff_init(2, sizeof(int), &buffer);
    assert_int_equal(rc, SR_ERR_OK);

    for (i = 1; i <= 50; i++) {
        rc = sr_cbuff_enqueue(buffer, &i);
        assert_int_equal(rc, SR_ERR_OK);

        if (4 == i) {
            sr_cbuff_dequeue(buffer, &tmp);
            assert_int_equal(tmp, 1);
            sr_cbuff_dequeue(buffer, &tmp);
            assert_int_equal(tmp, 2);
        }
        if (10 == i) {
            sr_cbuff_dequeue(buffer, &tmp);
            assert_int_equal(tmp, 3);
            sr_cbuff_dequeue(buffer, &tmp);
            assert_int_equal(tmp, 4);
            sr_cbuff_dequeue(buffer, &tmp);
            assert_int_equal(tmp, 5);
            sr_cbuff_dequeue(buffer, &tmp);
            assert_int_equal(tmp, 6);
        }
    }

    for (i = 7; i <= 50; i++) {
        sr_cbuff_dequeue(buffer, &tmp);
        assert_int_equal(tmp, i);
    }

    /* buffer should be empty now */
    assert_false(sr_cbuff_dequeue(buffer, &tmp));

    sr_cbuff_cleanup(buffer);
}
Example #28
0
static void test_pop_empty_and_push_null(void)
{
    ThreadedQueue *queue = ThreadedQueueNew(1, NULL);
    // |^|

    assert(ThreadedQueueIsEmpty(queue));

    void *i_am_null = NULL; bool ret = ThreadedQueuePop(queue, &i_am_null, 0);
    // |^|
    assert(i_am_null == NULL);
    assert_false(ret);
    ThreadedQueuePush(queue, i_am_null);
    // |v|
    ret = ThreadedQueuePop(queue, &i_am_null, 0);
    assert(i_am_null == NULL);
    assert_true(ret);
    // |^|

    ThreadedQueueDestroy(queue);
}
Example #29
0
void
test_persist_state_not_in_use_handle_is_loaded_in_dump_mode(void)
{
    PersistState *state;
    guint8 version;
    gsize size;
    PersistEntryHandle handle;

    unlink("test_in_use.persist");
    write_test_file_for_test_in_use_handle(FALSE);

    state = persist_state_new("test_in_use.persist");
    persist_state_start_dump(state);

    handle = persist_state_lookup_entry(state, "alma", &size, &version);

    assert_false(handle == 0, "lookup failed in dump mode when looking for simple entry with in_use = FALSE!");

    cancel_and_destroy_persist_state(state);
}
Example #30
0
void add_unique_value_does_nothing_when_exists(void **state)
{
    form_init_module();

    DataForm *form = _new_form();
    g_hash_table_insert(form->tag_to_var, strdup("tag1"), strdup("var1"));
    g_hash_table_insert(form->tag_to_var, strdup("tag2"), strdup("var2"));

    FormField *field1 = _new_field();
    field1->var = strdup("var1");
    field1->type_t = FIELD_JID_MULTI;
    field1->values = g_slist_append(field1->values, strdup("*****@*****.**"));
    form->fields = g_slist_append(form->fields, field1);

    FormField *field2 = _new_field();
    field2->var = strdup("var2");
    field2->type_t = FIELD_LIST_SINGLE;
    field2->values = g_slist_append(field2->values, strdup("value2"));
    form->fields = g_slist_append(form->fields, field2);

    gboolean ret = form_add_unique_value(form, "tag1", "*****@*****.**");

    int length = 0;
    char *value = NULL;
    GSList *curr_field = form->fields;
    while (curr_field != NULL) {
        FormField *field = curr_field->data;
        if (g_strcmp0(field->var, "var1") == 0) {
            length = g_slist_length(field->values);
            value = field->values->data;
            break;
        }
        curr_field = g_slist_next(curr_field);
    }

    assert_false(ret);
    assert_int_equal(length, 1);
    assert_string_equal(value, "*****@*****.**");

    form_destroy(form);
}