update tests
This commit is contained in:
parent
6a7d90145c
commit
ceec0d8521
2
refuse.c
2
refuse.c
@ -1,6 +1,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include "refuse.h"
|
#include "refuse.h"
|
||||||
|
|
||||||
static inline refhdr_t* _refuse_header(void* ptr)
|
static inline refhdr_t* _refuse_header(void* ptr)
|
||||||
@ -45,6 +46,7 @@ void refuse_reconcile(refuse_t* refuse)
|
|||||||
if(hdr->retainCount == 0) {
|
if(hdr->retainCount == 0) {
|
||||||
// Iterate children, delete children
|
// Iterate children, delete children
|
||||||
free(hdr);
|
free(hdr);
|
||||||
|
hdr = NULL;
|
||||||
}
|
}
|
||||||
hdr = refdeque_pop_front(refuse->dec);
|
hdr = refdeque_pop_front(refuse->dec);
|
||||||
}
|
}
|
||||||
|
12
tests.c
12
tests.c
@ -71,12 +71,14 @@ START_TEST(test_refuse_retain_3)
|
|||||||
refuse_t refuse = {0};
|
refuse_t refuse = {0};
|
||||||
refuse_init(&refuse);
|
refuse_init(&refuse);
|
||||||
struct mock* t = refuse_alloc(&refuse, sizeof(struct mock));
|
struct mock* t = refuse_alloc(&refuse, sizeof(struct mock));
|
||||||
refuse_set_dirty(&refuse, t);
|
|
||||||
refuse_retain(&refuse, t);
|
|
||||||
refhdr_t* hdr = (refhdr_t*)((char*)t - sizeof(refhdr_t));
|
refhdr_t* hdr = (refhdr_t*)((char*)t - sizeof(refhdr_t));
|
||||||
ck_assert_int_eq(hdr->retainCount, 0);
|
refuse_retain(&refuse, t);
|
||||||
refuse_reconcile(&refuse);
|
refuse_reconcile(&refuse);
|
||||||
ck_assert_int_eq(hdr->retainCount, 0);
|
refuse_set_dirty(&refuse, t);
|
||||||
|
ck_assert_int_eq(hdr->dirty, 1);
|
||||||
|
ck_assert_int_eq(hdr->retainCount, 1);
|
||||||
|
refuse_reconcile(&refuse);
|
||||||
|
ck_assert_int_eq(hdr->retainCount, 1);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
@ -92,6 +94,8 @@ START_TEST(test_refuse_release_1)
|
|||||||
refuse_release(&refuse, t);
|
refuse_release(&refuse, t);
|
||||||
ck_assert_int_eq(hdr->retainCount, 1);
|
ck_assert_int_eq(hdr->retainCount, 1);
|
||||||
refuse_reconcile(&refuse);
|
refuse_reconcile(&refuse);
|
||||||
|
// This is not safe, as the memory has been deallocated, but we're
|
||||||
|
// in a controlled environment.
|
||||||
ck_assert_int_eq(hdr->retainCount, 0);
|
ck_assert_int_eq(hdr->retainCount, 0);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
Loading…
Reference in New Issue
Block a user