forked from troydhanson/uthash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a regression test for troydhanson#241.
- Loading branch information
1 parent
6b54245
commit 0c60fb6
Showing
6 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "utlist.h" | ||
#include <assert.h> | ||
#include <stdlib.h> | ||
|
||
struct item { | ||
int x; | ||
struct item *prev; | ||
struct item *next; | ||
}; | ||
|
||
static int sort_cmp(void *a, void *b) | ||
{ | ||
struct item *item1 = (struct item *)a; | ||
struct item *item2 = (struct item *)b; | ||
return item1->x - item2->x; | ||
} | ||
|
||
void sort_them(struct item **items) | ||
{ | ||
DL_SORT(*items, sort_cmp); | ||
} | ||
|
||
int main() | ||
{ | ||
struct item *list = NULL; | ||
struct item a = { 2, NULL, NULL }; | ||
struct item b = { 1, NULL, NULL }; | ||
sort_them(&list); | ||
assert(list == NULL); | ||
|
||
DL_APPEND(list, &a); | ||
assert(list == &a); | ||
assert(a.prev == &a); | ||
assert(a.next == NULL); | ||
sort_them(&list); | ||
assert(list == &a); | ||
assert(a.prev == &a); | ||
assert(a.next == NULL); | ||
|
||
DL_APPEND(list, &b); | ||
assert(list == &a); | ||
assert(a.prev == &b); | ||
assert(a.next == &b); | ||
assert(b.prev == &a); | ||
assert(b.next == NULL); | ||
sort_them(&list); | ||
assert(list == &b); | ||
assert(b.prev == &a); | ||
assert(b.next == &a); | ||
assert(a.prev == &b); | ||
assert(a.next == NULL); | ||
|
||
return 0; | ||
} |