X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Forder%2Ftest%2Frun-fancy.c;fp=ccan%2Forder%2Ftest%2Frun-fancy.c;h=be5ff3f2d53d8a303247dee7a087d3be8d2c6861;hb=9a082140b9331ade729893e2d1e352e90dc6cba5;hp=0000000000000000000000000000000000000000;hpb=28681e0a15c453e86528ca488415e2220cbe0f0a;p=ccan diff --git a/ccan/order/test/run-fancy.c b/ccan/order/test/run-fancy.c new file mode 100644 index 00000000..be5ff3f2 --- /dev/null +++ b/ccan/order/test/run-fancy.c @@ -0,0 +1,68 @@ +#include +#include +#include + +#include + +#include + +#include "fancy_cmp.h" + +int main(int argc, char *argv[]) +{ + struct item item1 = { + .value = 0, + .str = "aaa", + }; + struct item item2 = { + .value = 0, + .str = "abb", + }; + struct item item3 = { + .value = 0x1000, + .str = "baa", + }; + struct cmp_info ctx1 = { + .xcode = 0, + .offset = 0, + }; + struct cmp_info ctx2 = { + .xcode = 0x1000, + .offset = 1, + }; + total_order(order1, struct item, struct cmp_info *) = { + fancy_cmp, &ctx1, + }; + total_order(order2, struct item, struct cmp_info *) = { + fancy_cmp, &ctx2, + }; + + plan_tests(18); + + ok1(total_order_cmp(order1, &item1, &item1) == 0); + ok1(total_order_cmp(order1, &item2, &item2) == 0); + ok1(total_order_cmp(order1, &item3, &item3) == 0); + + ok1(total_order_cmp(order1, &item1, &item2) == -1); + ok1(total_order_cmp(order1, &item2, &item3) == -1); + ok1(total_order_cmp(order1, &item1, &item3) == -1); + + ok1(total_order_cmp(order1, &item2, &item1) == 1); + ok1(total_order_cmp(order1, &item3, &item2) == 1); + ok1(total_order_cmp(order1, &item3, &item1) == 1); + + + ok1(total_order_cmp(order2, &item1, &item1) == 0); + ok1(total_order_cmp(order2, &item2, &item2) == 0); + ok1(total_order_cmp(order2, &item3, &item3) == 0); + + ok1(total_order_cmp(order2, &item1, &item2) == 1); + ok1(total_order_cmp(order2, &item2, &item3) == 1); + ok1(total_order_cmp(order2, &item1, &item3) == 1); + + ok1(total_order_cmp(order2, &item2, &item1) == -1); + ok1(total_order_cmp(order2, &item3, &item2) == -1); + ok1(total_order_cmp(order2, &item3, &item1) == -1); + + exit(0); +}