Hash :
3286c408
Author :
Date :
2011-10-28T14:51:13
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
#include "clay_libgit2.h"
#include "vector.h"
/* initial size of 1 would cause writing past array bounds */
void test_core_vector__0(void)
{
git_vector x;
int i;
git_vector_init(&x, 1, NULL);
for (i = 0; i < 10; ++i) {
git_vector_insert(&x, (void*) 0xabc);
}
git_vector_free(&x);
}
/* don't read past array bounds on remove() */
void test_core_vector__1(void)
{
git_vector x;
// make initial capacity exact for our insertions.
git_vector_init(&x, 3, NULL);
git_vector_insert(&x, (void*) 0xabc);
git_vector_insert(&x, (void*) 0xdef);
git_vector_insert(&x, (void*) 0x123);
git_vector_remove(&x, 0); // used to read past array bounds.
git_vector_free(&x);
}
static int test_cmp(const void *a, const void *b)
{
return *(const int *)a - *(const int *)b;
}
/* remove duplicates */
void test_core_vector__2(void)
{
git_vector x;
int *ptrs[2];
ptrs[0] = git__malloc(sizeof(int));
ptrs[1] = git__malloc(sizeof(int));
*ptrs[0] = 2;
*ptrs[1] = 1;
cl_git_pass(git_vector_init(&x, 5, test_cmp));
cl_git_pass(git_vector_insert(&x, ptrs[0]));
cl_git_pass(git_vector_insert(&x, ptrs[1]));
cl_git_pass(git_vector_insert(&x, ptrs[1]));
cl_git_pass(git_vector_insert(&x, ptrs[0]));
cl_git_pass(git_vector_insert(&x, ptrs[1]));
cl_assert(x.length == 5);
git_vector_uniq(&x);
cl_assert(x.length == 2);
git_vector_free(&x);
git__free(ptrs[0]);
git__free(ptrs[1]);
}