Пример #1
0
int test_thread_full(void* data) {
    (void) data;
    int status = 1;
    /* create dummy post */
    Post *post = new_post("title", "name", "text", 0, 0, 0);
    Thread *thread = new_thread(NULL, 1, 0);
    add_post_to_thread(thread, post);
    add_post_to_thread(thread, post);
    assert(thread->nreplies == 1);
    free_thread(thread);
    free_post(post);
    return status;
}
Пример #2
0
/* same as with post, since you've created the thread with
 * new_thread() (you have, right?), the thread contains
 * buffers of variables size that must be freed. */
void read_thread_bin_noalloc(Thread *thread, int filed)
{
    short i = 0;
    /* free replies buffers */
    if (thread->max_replies != 0) {
        free(thread->replies);
    }
    /* read stuff */
    read(filed, &(thread->flags), sizeof(thread->flags));
    read(filed, &(thread->max_replies), sizeof(thread->max_replies));
    /* allocate buffer for replies */
    thread->replies = malloc(sizeof(Post*) * thread->max_replies);
    /* read other options */
    read(filed, &(thread->nreplies), sizeof(thread->nreplies));
    /* set queue values */
    if (thread->flags & THREAD_CYCLIC) {
        thread->first_post = 0;
        thread->last_post = thread->nreplies - 1;
    } else {
        thread->first_post = thread->last_post = 0;
    }
    for (i = 0; i < thread->nreplies; ++i) {
        add_post_to_thread(thread, read_post_bin(filed));
    }
    /* set DELPOSTS flag */
    thread->flags |= THREAD_DELPOSTS;
}
Пример #3
0
int test_add_post(void *data)
{
    (void) data;
    int status = 1;
    /* create posts */
    Post *op = new_post("nameOP", "titleOP", "textOP", 0, -1, 0);
    Post *reply = new_post("name", "title", "text", 1, 0, 0);
    Thread *thread = new_thread(op, 150, 0);
    add_post_to_thread(thread, reply);
    assert(thread->nreplies == 1);
    assert(thread->first_post == 0);
    assert(thread->last_post == 0);
    free_thread(thread);
    free_post(op);
    free_post(reply);
    return status;
}