From c8bf38e5fb717d40635a2a89b22ed71b0de4266b Mon Sep 17 00:00:00 2001
From: Toni Uhlig <matzeton@googlemail.com>
Date: Tue, 1 Dec 2020 13:33:34 +0100
Subject: Squashed 'dependencies/uthash/' content from commit 8e67ced

git-subtree-dir: dependencies/uthash
git-subtree-split: 8e67ced1d1c5bd8141c542a22630e6de78aa6b90
---
 tests/test70.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)
 create mode 100644 tests/test70.c

(limited to 'tests/test70.c')

diff --git a/tests/test70.c b/tests/test70.c
new file mode 100644
index 000000000..abddea1c8
--- /dev/null
+++ b/tests/test70.c
@@ -0,0 +1,87 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include "utlist.h"
+
+typedef struct el {
+    int id;
+    struct el *next, *prev;
+} el;
+
+int main()
+{
+    int i;
+    el els[20], *e, *tmp;
+    el *headA = NULL;
+    el *headB = NULL;
+    for(i=0; i<20; i++) {
+        els[i].id=(int)'a'+i;
+    }
+
+    /* test LL macros */
+    printf("LL replace elem\n");
+    LL_APPEND(headA,&els[0]);
+    LL_APPEND(headA,&els[1]);
+    LL_APPEND(headA,&els[2]);
+    LL_APPEND(headA,&els[3]);
+    LL_FOREACH(headA,e) {
+        printf("%c ", e->id);
+    }
+    printf("\n");
+
+    /* replace head elem */
+    LL_REPLACE_ELEM(headA, &els[0], &els[4]);
+    LL_FOREACH(headA,e) {
+        printf("%c ", e->id);
+    }
+    printf("\n");
+    LL_REPLACE_ELEM(headA, &els[4], &els[5]);
+    LL_FOREACH(headA,e) {
+        printf("%c ", e->id);
+    }
+    printf("\n");
+
+    /* replace last elem */
+    LL_REPLACE_ELEM(headA, &els[3], &els[6]);
+    LL_FOREACH(headA,e) {
+        printf("%c ", e->id);
+    }
+    printf("\n");
+    LL_REPLACE_ELEM(headA, &els[6], &els[7]);
+    LL_FOREACH(headA,e) {
+        printf("%c ", e->id);
+    }
+    printf("\n");
+
+    /* replace middle elem */
+    LL_REPLACE_ELEM(headA, &els[1], &els[8]);
+    LL_REPLACE_ELEM(headA, &els[2], &els[9]);
+    LL_FOREACH(headA,e) {
+        printf("%c ", e->id);
+    }
+    printf("\n");
+
+    /* replace all just to be sure the list is intact... */
+    i = 10;
+    LL_FOREACH_SAFE(headA, e, tmp) {
+        LL_REPLACE_ELEM(headA, e, &els[i]);
+        i++;
+    }
+    LL_FOREACH(headA,e) {
+        printf("%c ", e->id);
+    }
+    printf("\n");
+
+    /* single elem */
+    LL_APPEND(headB, &els[18]);
+    LL_FOREACH(headB,e) {
+        printf("%c ", e->id);
+    }
+    printf("\n");
+    LL_REPLACE_ELEM(headB, &els[18], &els[19]);
+    LL_FOREACH(headB,e) {
+        printf("%c ", e->id);
+    }
+    printf("\n");
+
+    return 0;
+}
-- 
cgit v1.2.3