Exemple #1
0
static void test_destroyer(void)
{
    BufferList *list = NULL;
    list = BufferListNew();
    assert_true(list != NULL);

    char *element0 = strdup("this is a test string");
    Buffer *buffer0 = BufferNewFrom(element0, strlen(element0));
    char *element1 = strdup("another test string");
    Buffer *buffer1 = BufferNewFrom(element1, strlen(element1));
    char *element2 = strdup("yet another test string");
    Buffer *buffer2 = BufferNewFrom(element2, strlen(element2));
    char *element3 = strdup("and one more test string");
    Buffer *buffer3 = BufferNewFrom(element3, strlen(element3));

    // We add element0 to the list.
    assert_int_equal(BufferListPrepend(list, buffer0), 0);
    // We add element1 to the list.
    assert_int_equal(BufferListPrepend(list, buffer1), 0);
    // We add element2 to the list.
    assert_int_equal(BufferListPrepend(list, buffer2), 0);
    // We add element3 to the list.
    assert_int_equal(BufferListPrepend(list, buffer3), 0);

    // Now we try to destroy the list.
    assert_int_equal(BufferListDestroy(&list), 0);
    free (element0);
    free (element1);
    free (element2);
    free (element3);
}
Exemple #2
0
static void test_copyList(void)
{
    BufferList *list1 = NULL;
    BufferList *list2 = NULL;
    BufferList *list3 = NULL;
    BufferList *list4 = NULL;
    char *element0 = strdup("this is a test string");
    Buffer *buffer0 = BufferNewFrom(element0, strlen(element0));
    char *element1 = strdup("another test string");
    Buffer *buffer1 = BufferNewFrom(element1, strlen(element1));
    char *element2 = strdup("yet another test string");
    Buffer *buffer2 = BufferNewFrom(element2, strlen(element2));

    list1 = BufferListNew();
    assert_true(list1 != NULL);
    assert_int_equal(0, BufferListPrepend(list1, buffer0));
    assert_int_equal(1, BufferListCount(list1));
    /*
     * Copy the list1 to list2 and prepend one more element
     */
    assert_int_equal(0, BufferListCopy(list1, &list2));
    assert_int_equal(1, BufferListCount(list2));
    assert_int_equal(0, BufferListPrepend(list2, buffer1));
    /*
     * The two lists have detached now.
     */
    assert_int_equal(1, BufferListCount(list1));
    assert_int_equal(2, BufferListCount(list2));
    /*
     * Add one more element to list1 and then attach list3 and list4.
     * Finally detach list4 by removing one element.
     */
    assert_int_equal(0, BufferListPrepend(list1, buffer2));
    assert_int_equal(0, BufferListCopy(list1, &list3));
    assert_int_equal(0, BufferListCopy(list1, &list4));
    assert_int_equal(2, BufferListCount(list1));
    assert_int_equal(2, BufferListCount(list3));
    assert_int_equal(2, BufferListCount(list4));
    assert_int_equal(0, BufferListRemove(list4, buffer0));
    assert_int_equal(2, BufferListCount(list1));
    assert_int_equal(2, BufferListCount(list3));
    assert_int_equal(1, BufferListCount(list4));

    BufferListDestroy(&list1);
    BufferListDestroy(&list2);
    BufferListDestroy(&list3);
    BufferListDestroy(&list4);
    free (element0);
    free (element1);
    free (element2);
}
Exemple #3
0
int IsIPV6Address(char *name)
{
    if (!name)
    {
        return false;
    }
    Buffer *buffer = BufferNewFrom(name, strlen(name));
    if (!buffer)
    {
        return false;
    }
    IPAddress *ip_address = NULL;
    bool is_ip = false;
    is_ip = IPAddressIsIPAddress(buffer, &ip_address);
    if (!is_ip)
    {
        BufferDestroy(buffer);
        return false;
    }
    if (IPAddressType(ip_address) != IP_ADDRESS_TYPE_IPV6)
    {
        BufferDestroy(buffer);
        IPAddressDestroy(&ip_address);
        return false;
    }
    BufferDestroy(buffer);
    IPAddressDestroy(&ip_address);
    return true;
}
Exemple #4
0
static bool RlistItemIPLess(void *lhs, void *rhs, ARG_UNUSED void *ctx)
{
    const char *left_item = RlistScalarValue((Rlist*)lhs);
    const char *right_item = RlistScalarValue((Rlist*)rhs);

    Buffer *left_buffer = BufferNewFrom(left_item, strlen(left_item));
    Buffer *right_buffer = BufferNewFrom(right_item, strlen(right_item));

    IPAddress *left = IPAddressNew(left_buffer);
    IPAddress *right = IPAddressNew(right_buffer);

    bool matched_left = left != NULL;
    bool matched_right = right != NULL;

    BufferDestroy(&left_buffer);
    BufferDestroy(&right_buffer);

    if (matched_left && matched_right)
    {
        int less = IPAddressCompareLess(left, right);
        IPAddressDestroy(&left);
        IPAddressDestroy(&right);
        return less;
    }

    IPAddressDestroy(&left);
    IPAddressDestroy(&right);

    if (matched_left)
    {
        return false;
    }

    if (matched_right)
    {
        return true;
    }

    // neither item matched
    return RlistItemLess(lhs, rhs, ctx);
}
Exemple #5
0
static void test_appendToList(void)
{
    BufferList *list = NULL;
    list = BufferListNew();
    assert_true(list != NULL);

    char *element0 = strdup("this is a test string");
    Buffer *buffer0 = BufferNewFrom(element0, strlen(element0));
    char *element1 = strdup("another test string");
    Buffer *buffer1 = BufferNewFrom(element1, strlen(element1));

    // We add element0 to the list.
    assert_int_equal(BufferListAppend(list, buffer0), 0);
    assert_int_equal(BufferListCount(list), 1);

    // We add element1 to the list.
    assert_int_equal(BufferListAppend(list, buffer1), 0);
    assert_int_equal(BufferListCount(list), 2);

    assert_int_equal(BufferListDestroy(&list), 0);
    free (element0);
    free (element1);
}
Exemple #6
0
static void test_createBufferFrom(void)
{
    char *data = xstrdup("this is some data");
    unsigned int dataLength = strlen(data);
    Buffer *buffer = BufferNewFrom(data, dataLength);
    assert_true(buffer != NULL);
    assert_true(buffer->buffer != NULL);
    assert_string_equal(data, buffer->buffer);
    assert_int_equal(buffer->mode, BUFFER_BEHAVIOR_CSTRING);
    assert_int_equal(buffer->capacity, DEFAULT_BUFFER_SIZE);
    assert_int_equal(buffer->used, dataLength);
    assert_int_equal(buffer->beginning, 0);
    assert_int_equal(buffer->end, 0);
    assert_true(buffer->ref_count != NULL);
    assert_int_equal(buffer->ref_count->user_count, 1);
    assert_int_equal(0, BufferDestroy(&buffer));
    free (data);
}
Exemple #7
0
Buffer *BufferCopy(const Buffer *source)
{
    assert(source);
    return BufferNewFrom(source->buffer, source->used);
}
Exemple #8
0
// If return_names is not set, only the captured data is returned (so
// for N captures you can expect N elements in the Sequence).
Seq *StringMatchCapturesWithPrecompiledRegex(const pcre *pattern, const char *str, const bool return_names)
{
    int captures;
    int res = pcre_fullinfo(pattern, NULL, PCRE_INFO_CAPTURECOUNT, &captures);
    if (res != 0)
    {
        return NULL;
    }

    // Get the table of named captures.
    unsigned char *name_table = NULL; // Doesn't have to be freed as per docs.
    int namecount = 0;
    int name_entry_size = 0;
    unsigned char *tabptr;

    pcre_fullinfo(pattern, NULL, PCRE_INFO_NAMECOUNT, &namecount);

    const bool have_named_captures = (namecount > 0 && return_names);

    if (have_named_captures)
    {
        pcre_fullinfo(pattern, NULL, PCRE_INFO_NAMETABLE, &name_table);
        pcre_fullinfo(pattern, NULL, PCRE_INFO_NAMEENTRYSIZE, &name_entry_size);
    }

    int *ovector = xmalloc(sizeof(int) * (captures + 1) * 3);

    int result = pcre_exec(pattern, NULL, str, strlen(str),
                           0, 0, ovector, (captures + 1) * 3);

    if (result <= 0)
    {
        free(ovector);
        return NULL;
    }

    Seq *ret = SeqNew(captures + 1, BufferDestroy);
    for (int i = 0; i <= captures; ++i)
    {
        Buffer *capture = NULL;

        if (have_named_captures)
        {
            // The overhead of doing a nested name scan is negligible.
            tabptr = name_table;
            for (int namepos = 0; namepos < namecount; namepos++)
            {
                int n = (tabptr[0] << 8) | tabptr[1];
                if (n == i) // We found the position
                {
                    capture = BufferNewFrom(tabptr + 2, name_entry_size - 3);
                    break;
                }
                tabptr += name_entry_size;
            }
        }

        if (return_names)
        {
            if (NULL == capture)
            {
                capture = BufferNew();
                BufferAppendF(capture, "%zd", i);
            }

            SeqAppend(ret, capture);
        }

        Buffer *data = BufferNewFrom(str + ovector[2*i],
                                     ovector[2*i + 1] - ovector[2 * i]);
        Log(LOG_LEVEL_DEBUG, "StringMatchCaptures: return_names = %d, have_named_captures = %d, offset %d, name '%s', data '%s'", return_names, have_named_captures, i, capture == NULL ? "no_name" : BufferData(capture), BufferData(data));
        SeqAppend(ret, data);
    }

    free(ovector);
    return ret;
}
Exemple #9
0
static void test_creation_destruction(void)
{
    char right_version[] = "1.2.3";
    char wrong_version[] = "a.0.1";
    char right_unix_version[] = "1.2.3-4";
    char wrong_unix_version_0[] = "3-5.1-1";
    char wrong_unix_version_1[] = "3.5-1-1";
    char wrong_unix_version_2[] = "3.5.1.1";
    char right_windows_version[] = "1.2.3.4-5";
    char wrong_windows_version_0[] = "3-5.1.0-1";
    char wrong_windows_version_1[] = "3.5-1.0-1";
    char wrong_windows_version_2[] = "3.5.1-0-1";
    char wrong_windows_version_3[] = "3.5.1.0.1";
    char large_version_0[] = "256.1.2.3-4";
    char large_version_1[] = "1.256.3-4";
    char large_version_2[] = "1.2.256.3-4";
    char large_version_3[] = "1.2.3.256-4";

    Version *version = NULL;
    version = VersionNew();
    assert_true (version != NULL);
    assert_int_equal(version->major, 0);
    assert_int_equal(version->minor, 0);
    assert_int_equal(version->patch, 0);
    assert_int_equal(version->extra, 0);
    assert_int_equal(version->build, 0);
    VersionDestroy(&version);
    assert_true (version == NULL);

    version = VersionNewFromCharP(right_version, strlen(right_version));
    assert_true(version != NULL);
    assert_int_equal(version->major, 1);
    assert_int_equal(version->minor, 2);
    assert_int_equal(version->patch, 3);
    assert_int_equal(version->extra, 0);
    assert_int_equal(version->build, 0);
    VersionDestroy(&version);
    assert_true (version == NULL);

    version = VersionNewFromCharP(right_unix_version, strlen(right_unix_version));
    assert_true(version != NULL);
    assert_int_equal(version->major, 1);
    assert_int_equal(version->minor, 2);
    assert_int_equal(version->patch, 3);
    assert_int_equal(version->extra, 0);
    assert_int_equal(version->build, 4);
    VersionDestroy(&version);
    assert_true (version == NULL);

    version = VersionNewFromCharP(right_windows_version, strlen(right_windows_version));
    assert_true(version != NULL);
    assert_int_equal(version->major, 1);
    assert_int_equal(version->minor, 2);
    assert_int_equal(version->patch, 3);
    assert_int_equal(version->extra, 4);
    assert_int_equal(version->build, 5);
    VersionDestroy(&version);
    assert_true (version == NULL);

    version = VersionNewFromCharP(wrong_version, strlen(wrong_version));
    assert_true(version == NULL);
    version = VersionNewFromCharP(wrong_unix_version_0, strlen(wrong_unix_version_0));
    assert_true(version == NULL);
    version = VersionNewFromCharP(wrong_unix_version_1, strlen(wrong_unix_version_1));
    assert_true(version == NULL);
    version = VersionNewFromCharP(wrong_unix_version_2, strlen(wrong_unix_version_2));
    assert_true(version == NULL);
    version = VersionNewFromCharP(wrong_windows_version_0, strlen(wrong_windows_version_0));
    assert_true(version == NULL);
    version = VersionNewFromCharP(wrong_windows_version_1, strlen(wrong_windows_version_1));
    assert_true(version == NULL);
    version = VersionNewFromCharP(wrong_windows_version_2, strlen(wrong_windows_version_2));
    assert_true(version == NULL);
    version = VersionNewFromCharP(wrong_windows_version_3, strlen(wrong_windows_version_3));
    assert_true(version == NULL);
    version = VersionNewFromCharP(large_version_0, strlen(large_version_0));
    assert_true(version == NULL);
    version = VersionNewFromCharP(large_version_1, strlen(large_version_1));
    assert_true(version == NULL);
    version = VersionNewFromCharP(large_version_2, strlen(large_version_2));
    assert_true(version == NULL);
    version = VersionNewFromCharP(large_version_3, strlen(large_version_3));
    assert_true(version == NULL);

    /* Creation from a buffer uses the same path as the creation from a char p, we just test the two main cases */
    Buffer *buffer = NULL;
    buffer = BufferNewFrom(right_version, strlen(right_version));
    assert_true (buffer != NULL);
    version = VersionNewFrom(buffer);
    assert_true(version != NULL);
    assert_int_equal(version->major, 1);
    assert_int_equal(version->minor, 2);
    assert_int_equal(version->patch, 3);
    assert_int_equal(version->extra, 0);
    assert_int_equal(version->build, 0);
    VersionDestroy(&version);
    assert_true (version == NULL);
    BufferDestroy(&buffer);
    assert_true(buffer == NULL);

    buffer = BufferNewFrom(wrong_version, strlen(wrong_version));
    assert_true (buffer != NULL);
    version = VersionNewFrom(buffer);
    assert_true(version == NULL);
    BufferDestroy(&buffer);
    assert_true(buffer == NULL);
}
Exemple #10
0
static void test_removeFromList(void)
{
    BufferList *list = NULL;
    list = BufferListNew();
    assert_true(list != NULL);

    char *element0 = strdup("this is a test string");
    Buffer *buffer0 = BufferNewFrom(element0, strlen(element0));
    char *element1 = strdup("another test string");
    Buffer *buffer1 = BufferNewFrom(element1, strlen(element1));
    char *element2 = strdup("yet another test string");
    Buffer *buffer2 = BufferNewFrom(element2, strlen(element2));
    char *element3 = strdup("and one more test string");
    Buffer *buffer3 = BufferNewFrom(element3, strlen(element3));
    char *element4 = strdup("non existing element");
    Buffer *buffer4 = BufferNewFrom(element4, strlen(element4));

    // We add element0 to the list.
    assert_int_equal(BufferListPrepend(list, buffer0), 0);
    assert_int_equal(BufferListCount(list), 1);

    // We add element1 to the list.
    assert_int_equal(BufferListPrepend(list, buffer1), 0);
    assert_int_equal(BufferListCount(list), 2);

    // We add element2 to the list.
    assert_int_equal(BufferListPrepend(list, buffer2), 0);
    assert_int_equal(BufferListCount(list), 3);

    // We add element3 to the list.
    assert_int_equal(BufferListPrepend(list, buffer3), 0);
    assert_int_equal(BufferListCount(list), 4);

    // We remove the non existing element
    assert_int_equal(BufferListRemove(list, buffer4), -1);
    assert_int_equal(BufferListCount(list), 4);

    // Remove element1 which is in the middle of the list
    assert_int_equal(BufferListRemove(list, buffer1), 0);
    assert_int_equal(BufferListCount(list), 3);

    // Remove element3 which is at the beginning of the list
    assert_int_equal(BufferListRemove(list, buffer3), 0);
    assert_int_equal(BufferListCount(list), 2);

    // Remove element0 which is at the end of the list
    assert_int_equal(BufferListRemove(list, buffer0), 0);
    assert_int_equal(BufferListCount(list), 1);

    // Remove element2 which is the only element on the list
    assert_int_equal(BufferListRemove(list, buffer2), 0);
    assert_int_equal(BufferListCount(list), 0);

    // Now we destroy the list.
    assert_int_equal(BufferListDestroy(&list), 0);
    BufferDestroy(&buffer4);
    free (element0);
    free (element1);
    free (element2);
    free (element3);
    free (element4);
}
Exemple #11
0
static void test_mutableIterator(void)
{
    BufferList *list = NULL;
    list = BufferListNew();
    assert_true(list != NULL);

    BufferListMutableIterator *emptyListIterator = NULL;
    emptyListIterator = BufferListMutableIteratorGet(list);
    assert_true(emptyListIterator == NULL);
    char *element0 = strdup("this is a test string");
    Buffer *buffer0 = BufferNewFrom(element0, strlen(element0));
    char *element1 = strdup("another test string");
    Buffer *buffer1 = BufferNewFrom(element1, strlen(element1));
    char *element2 = strdup("yet another test string");
    Buffer *buffer2 = BufferNewFrom(element2, strlen(element2));
    char *element3 = strdup("and one more test string");
    Buffer *buffer3 = BufferNewFrom(element3, strlen(element3));
    char *element4 = strdup("prepended by iterator");
    Buffer *buffer4 = BufferNewFrom(element4, strlen(element4));
    char *element5 = strdup("appended by iterator");
    Buffer *buffer5 = BufferNewFrom(element5, strlen(element5));
    char *element6 = strdup("appended by iterator, second");
    Buffer *buffer6 = BufferNewFrom(element6, strlen(element6));
    char *element7 = strdup("prepended by iterator, second");
    Buffer *buffer7 = BufferNewFrom(element7, strlen(element7));

    // We add element0 to the list.
    assert_int_equal(BufferListAppend(list, buffer0), 0);
    // We add element1 to the list.
    assert_int_equal(BufferListAppend(list, buffer1), 0);
    // We add element2 to the list.
    assert_int_equal(BufferListAppend(list, buffer2), 0);
    // We add element3 to the list.
    assert_int_equal(BufferListAppend(list, buffer3), 0);

    // We use a light iterator to check that is valid
    BufferListIterator *lightIterator = NULL;
    lightIterator = BufferListIteratorGet(list);
    BufferListMutableIterator *iterator = NULL;
    BufferListMutableIterator *secondIterator = NULL;
    iterator = BufferListMutableIteratorGet(list);
    assert_true(iterator != NULL);
    secondIterator = BufferListMutableIteratorGet(list);
    assert_true(secondIterator == NULL);
    // Loop through the list until we get to the last element and then back
    while (BufferListMutableIteratorHasNext(iterator))
    {
        assert_int_equal(0, BufferListMutableIteratorNext(iterator));
    }
    assert_int_equal(-1, BufferListMutableIteratorNext(iterator));
    // and back
    while (BufferListMutableIteratorHasPrevious(iterator))
    {
        assert_int_equal(0, BufferListMutableIteratorPrevious(iterator));
    }
    assert_int_equal(-1, BufferListMutableIteratorPrevious(iterator));
    // Jump to the last element
    assert_int_equal(0, BufferListMutableIteratorLast(iterator));
    // and back to the first element
    assert_int_equal(0, BufferListMutableIteratorFirst(iterator));
    // Prepend one element at the beginning of the list
    assert_int_equal(0, BufferListMutableIteratorPrepend(iterator, buffer4));
    assert_int_equal(5, BufferListCount(list));
    // It should be possible to go back one element now.
    assert_int_equal(0, BufferListMutableIteratorPrevious(iterator));
    // Append one element after the first element
    assert_int_equal(0, BufferListMutableIteratorAppend(iterator, buffer5));
    assert_int_equal(6, BufferListCount(list));
    // Loop through the list until we get to the last element and then back
    while (BufferListMutableIteratorHasNext(iterator))
    {
        assert_int_equal(0, BufferListMutableIteratorNext(iterator));
    }
    assert_int_equal(-1, BufferListMutableIteratorNext(iterator));
    // and back
    while (BufferListMutableIteratorHasPrevious(iterator))
    {
        assert_int_equal(0, BufferListMutableIteratorPrevious(iterator));
    }
    assert_int_equal(-1, BufferListMutableIteratorPrevious(iterator));
    // Jump to the last element
    assert_int_equal(0, BufferListMutableIteratorLast(iterator));
    // and back to the first element
    assert_int_equal(0, BufferListMutableIteratorFirst(iterator));
    // And back to the last element
    assert_int_equal(0, BufferListMutableIteratorLast(iterator));
    // Append one element after the last element
    assert_int_equal(0, BufferListMutableIteratorAppend(iterator, buffer6));
    assert_int_equal(7, BufferListCount(list));
    assert_int_equal(0, BufferListMutableIteratorNext(iterator));
    // Prepend one element before the last element
    assert_int_equal(0, BufferListMutableIteratorPrepend(iterator, buffer7));
    assert_int_equal(8, BufferListCount(list));
    // Go back one element and remove the element
    assert_int_equal(0, BufferListMutableIteratorPrevious(iterator));
    // Remove the current element
    assert_int_equal(0, BufferListMutableIteratorRemove(iterator));
    // Check that the list agrees
    assert_int_equal(7, BufferListCount(list));
    // Remove the last element, we should go back to element3
    assert_int_equal(0, BufferListMutableIteratorRemove(iterator));
    // Check that the list agrees
    assert_int_equal(6, BufferListCount(list));
    // Jump to the first element of the list
    assert_int_equal(0, BufferListMutableIteratorFirst(iterator));
    // Remove the first element, we should end up in element5
    assert_int_equal(0, BufferListMutableIteratorRemove(iterator));
    // Check that the list agrees
    assert_int_equal(5, BufferListCount(list));
    // Now remove element3, the last element of the list using the Remove function
    assert_int_equal(0, BufferListRemove(list, buffer3));
    assert_int_equal(4, BufferListCount(list));
    // Jump to the last element of the list
    assert_int_equal(0, BufferListMutableIteratorLast(iterator));
    // Move the iterator to the previous element, element1, and delete it. The iterator should move to element2.
    assert_int_equal(0, BufferListMutableIteratorPrevious(iterator));
    assert_int_equal(0, BufferListRemove(list, buffer1));
    assert_int_equal(3, BufferListCount(list));
    // Remove the last element of the list, the iterator should move to element0
    assert_int_equal(0, BufferListRemove(list, buffer2));
    assert_int_equal(2, BufferListCount(list));
    // Jump to the first element
    assert_int_equal(0, BufferListMutableIteratorFirst(iterator));
    // Remove the first element, that should move the iterator to element0
    assert_int_equal(0, BufferListRemove(list, buffer5));
    assert_int_equal(1, BufferListCount(list));
    // Finally try to remove the only element using the iterator, it should fail.
    assert_int_equal(-1, BufferListMutableIteratorRemove(iterator));
    // Remove the final element using the list and check that the iterator is invalid
    assert_int_equal(0, BufferListRemove(list, buffer0));
    // Destroy the iterators and the list
    assert_int_equal(0, BufferListMutableIteratorRelease(&iterator));
    assert_int_equal(0, BufferListIteratorDestroy(&lightIterator));
    assert_int_equal(0, BufferListDestroy(&list));
    free (element0);
    free (element1);
    free (element2);
    free (element3);
    free (element4);
    free (element5);
    free (element6);
    free (element7);
}
Exemple #12
0
static void test_iterator(void)
{
    BufferList *list = NULL;
    list = BufferListNew();
    assert_true(list != NULL);

    BufferListIterator *emptyListIterator = NULL;
    emptyListIterator = BufferListIteratorGet(list);
    assert_true(emptyListIterator == NULL);
    char *element0 = strdup("this is a test string");
    Buffer *buffer0 = BufferNewFrom(element0, strlen(element0));
    char *element1 = strdup("another test string");
    Buffer *buffer1 = BufferNewFrom(element1, strlen(element1));
    char *element2 = strdup("yet another test string");
    Buffer *buffer2 = BufferNewFrom(element2, strlen(element2));
    char *element3 = strdup("and one more test string");
    Buffer *buffer3 = BufferNewFrom(element3, strlen(element3));

    // We add elements to the list.
    assert_int_equal(BufferListPrepend(list, buffer0), 0);
    assert_int_equal(BufferListPrepend(list, buffer1), 0);
    assert_int_equal(BufferListPrepend(list, buffer2), 0);
    assert_int_equal(BufferListPrepend(list, buffer3), 0);

    BufferListIterator *iterator0 = NULL;
    iterator0 = BufferListIteratorGet(list);
    // Check the iterator
    assert_true(iterator0 != NULL);

    // Remove element1 which is in the middle of the list, this will invalidate the iterator
    assert_int_equal(BufferListRemove(list, buffer1), 0);
    // Check that the iterator is not valid by trying to advance it
    assert_int_equal(BufferListIteratorNext(iterator0), -1);
    // Destroy the iterator
    assert_int_equal(BufferListIteratorDestroy(&iterator0), 0);
    assert_int_equal(iterator0, NULL);

    // Create a new iterator and move it
    BufferListIterator *iterator1 = NULL;
    iterator1 = BufferListIteratorGet(list);
    // Check the iterator
    assert_int_not_equal(iterator1, NULL);
    Buffer *value = NULL;
    value = BufferListIteratorData(iterator1);
    assert_int_equal(BufferCompare(value, buffer3), 0);

    // Advance it
    assert_int_equal(BufferListIteratorNext(iterator1), 0);
    // Check the value, it should be equal to element2
    value = BufferListIteratorData(iterator1);
    assert_int_equal(BufferCompare(value, buffer2), 0);

    // Advance it, now we are at the last element
    assert_int_equal(BufferListIteratorNext(iterator1), 0);
    // Check the value, it should be equal to element0
    value = BufferListIteratorData(iterator1);
    assert_int_equal(BufferCompare(value, buffer0), 0);

    // Advance it, should fail and the iterator should stay where it was
    assert_int_equal(BufferListIteratorNext(iterator1), -1);
    // Check the value, it should be equal to element0
    value = BufferListIteratorData(iterator1);
    assert_int_equal(BufferCompare(value, buffer0), 0);

    // Go back
    assert_int_equal(BufferListIteratorPrevious(iterator1), 0);
    // Check the value, it should be equal to element2
    value = BufferListIteratorData(iterator1);
    assert_int_equal(BufferCompare(value, buffer2), 0);

    // Go back, now we are at the beginning of the list
    assert_int_equal(BufferListIteratorPrevious(iterator1), 0);
    // Check the value, it should be equal to element3
    value = BufferListIteratorData(iterator1);
    assert_int_equal(BufferCompare(value, buffer3), 0);

    // Go back, should fail and the iterator should stay where it was
    assert_int_equal(BufferListIteratorPrevious(iterator1), -1);
    // Check the value, it should be equal to element3
    value = BufferListIteratorData(iterator1);
    assert_int_equal(BufferCompare(value, buffer3), 0);

    // Jump to the last element
    assert_int_equal(BufferListIteratorLast(iterator1), 0);
    // Check the value, it should be equal to element0
    value = BufferListIteratorData(iterator1);
    assert_int_equal(BufferCompare(value, buffer0), 0);

    // Go back
    assert_true(BufferListIteratorHasPrevious(iterator1));
    assert_int_equal(BufferListIteratorPrevious(iterator1), 0);
    // Check the value, it should be equal to element2
    value = BufferListIteratorData(iterator1);
    assert_int_equal(BufferCompare(value, buffer2), 0);

    // Jump to the first element
    assert_int_equal(BufferListIteratorFirst(iterator1), 0);
    // Check the value, it should be equal to element3
    value = BufferListIteratorData(iterator1);
    assert_int_equal(BufferCompare(value, buffer3), 0);

    // Advance it
    assert_true(BufferListIteratorHasNext(iterator1));
    assert_int_equal(BufferListIteratorNext(iterator1), 0);
    // Check the value, it should be equal to element2
    value = BufferListIteratorData(iterator1);
    assert_int_equal(BufferCompare(value, buffer2), 0);

    // Remove the elements
    assert_int_equal(BufferListRemove(list, buffer3), 0);
    assert_int_equal(BufferListRemove(list, buffer0), 0);
    assert_int_equal(BufferListRemove(list, buffer2), 0);

    // Now we destroy the list.
    assert_int_equal(BufferListDestroy(&list), 0);
    assert_int_equal(BufferListIteratorDestroy(&iterator1), 0);
    free (element0);
    free (element1);
    free (element2);
    free (element3);
}