3 #include "testing/testing.h"
16 #define TESTFAIL(test) \
22 if (listbase->
first) {
34 }
while ((
void)(
prev = link), (link = link->next));
41 }
while ((
void)(
prev = link), (link = link->prev));
55 static int char_switch(
char *
string,
char ch_src,
char ch_dst)
58 while (*
string != 0) {
59 if (*
string == ch_src) {
68 TEST(listbase, FindLinkOrIndex)
107 TEST(listbase, FindLinkFromStringOrPointer)
115 const char *
const link1_name =
"Link1";
116 const char *
const link2_name =
"Link2";
117 const void *
const link1_ptr =
nullptr;
118 const void *
const link2_ptr = link2_name;
120 const size_t name_offset = offsetof(
struct TestLink, name);
121 const size_t ptr_offset = offsetof(
struct TestLink,
ptr);
124 struct TestLink *link1 = (
struct TestLink *)
MEM_callocN(
sizeof(TestLink),
"link1");
125 BLI_strncpy(link1->name, link1_name,
sizeof(link1->name));
126 link1->ptr = link1_ptr;
127 struct TestLink *link2 = (
struct TestLink *)
MEM_callocN(
sizeof(TestLink),
"link2");
128 BLI_strncpy(link2->name, link2_name,
sizeof(link2->name));
129 link2->ptr = link2_ptr;
195 int i = strcmp(*(
const char **)
a, *(
const char **)
b);
196 return (i > 0) ? 1 : (i < 0) ? -1 : 0;
203 int i = strcmp((
const char *)link_a->
data, (
const char *)link_b->
data);
204 return (i > 0) ? 1 : (i < 0) ? -1 : 0;
224 for (i = 0; i < arr_num; i++) {
225 if (strcmp(arr[i], (
char *)link_step->
data) != 0) {
228 link_step = link_step->
next;
243 while (link_step && link_step->
next) {
244 if (strcmp((
const char *)link_step->
data, (
const char *)link_step->
next->
data) == 0) {
245 if ((link_step < link_step->
next) != forward) {
249 link_step = link_step->
next;
256 const int words_len =
sizeof(
words10k) - 1;
268 words_arr = (
char **)
MEM_mallocN(
sizeof(*words_arr) * words_num, __func__);
270 words_linkdata_arr = (
LinkData *)
MEM_mallocN(
sizeof(*words_linkdata_arr) * words_num, __func__);
274 for (i = 0; i < words_num; i++) {
275 words_arr[i] = w_step;
276 w_step += strlen(w_step) + 1;
299 for (i = 0; i < words_num; i++) {
300 LinkData *link = &words_linkdata_arr[i];
303 w_step += strlen(w_step) + 1;
Generic array manipulation API.
#define BLI_array_reverse(arr, arr_len)
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
void void * BLI_listbase_string_or_index_find(const struct ListBase *listbase, const char *string, size_t string_offset, int index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
void * BLI_rfindlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void * BLI_findlinkfrom(struct Link *start, int number) ATTR_WARN_UNUSED_RESULT
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
void void BLI_listbase_sort(struct ListBase *listbase, int(*cmp)(const void *, const void *)) ATTR_NONNULL(1
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void void void void void void BLI_listbase_reverse(struct ListBase *lb) ATTR_NONNULL(1)
ListBase BLI_listbase_from_link(struct Link *some_link)
void * BLI_findstring(const struct ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void * BLI_rfindstring(const struct ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void * BLI_rfindptr(const struct ListBase *listbase, const void *ptr, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void * BLI_findptr(const struct ListBase *listbase, const void *ptr, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
static int testsort_listbase_str_cmp(const void *a, const void *b)
static int testsort_array_str_cmp(const void *a, const void *b)
static bool listbase_is_valid(const ListBase *listbase)
static bool testsort_listbase_array_str_cmp(ListBase *lb, char **arr, int arr_num)
static int testsort_array_str_cmp_reverse(const void *a, const void *b)
TEST(listbase, FindLinkOrIndex)
static int char_switch(char *string, char ch_src, char ch_dst)
static int testsort_listbase_str_cmp_reverse(const void *a, const void *b)
static bool testsort_listbase_sort_is_stable(ListBase *lb, bool forward)
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Read Guarded memory(de)allocation.
void(* MEM_freeN)(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
void *(* MEM_mallocN)(size_t len, const char *str)
SymEdge< T > * prev(const SymEdge< T > *se)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)