<pre style='margin:0'>
Christopher Nielsen (mascguy) pushed a commit to branch master
in repository macports-legacy-support.
</pre>
<p><a href="https://github.com/macports/macports-legacy-support/commit/a2cd30549f437341996dc1e5e84bd9a1cd136c70">https://github.com/macports/macports-legacy-support/commit/a2cd30549f437341996dc1e5e84bd9a1cd136c70</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit a2cd30549f437341996dc1e5e84bd9a1cd136c70
</span>Author: Fred Wright <fw@fwright.net>
AuthorDate: Sat Jul 20 15:40:03 2024 -0700
<span style='display:block; white-space:pre;color:#404040;'> Add tests for some queue operations.
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> This adds a long-missing test for STAILQ_FOREACH, as well as a test
</span><span style='display:block; white-space:pre;color:#404040;'> for the newly added SLIST_REMOVE_AFTER (which also tests
</span><span style='display:block; white-space:pre;color:#404040;'> SLIST_HEAD_INITIALIZER).
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> Re: https://trac.macports.org/ticket/69890
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> TESTED:
</span><span style='display:block; white-space:pre;color:#404040;'> Detects missing STAILQ_FOREACH in 10.4 SDK (without old fix).
</span><span style='display:block; white-space:pre;color:#404040;'> Detects missing SLIST_HEAD_INITIALIZER in 10.4 SDK (without new fix).
</span><span style='display:block; white-space:pre;color:#404040;'> Detects missing SLIST_REMOVE_AFTER in 10.4-10.6 SDKs (without new
</span><span style='display:block; white-space:pre;color:#404040;'> fix).
</span><span style='display:block; white-space:pre;color:#404040;'> With fixes, passes with all applicable SDKs on all platforms.
</span>---
test/test_queues.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 131 insertions(+)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/test/test_queues.c b/test/test_queues.c
</span>new file mode 100644
<span style='display:block; white-space:pre;color:#808080;'>index 0000000..a0ae0af
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>--- /dev/null
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/test/test_queues.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -0,0 +1,131 @@
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+/*
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * Copyright (c) 2024 Frederick H. G. Wright II <fw@fwright.net>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * Permission to use, copy, modify, and distribute this software for any
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * purpose with or without fee is hereby granted, provided that the above
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * copyright notice and this permission notice appear in all copies.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+/*
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * This provides tests for some functions from sys/queue.h., currently:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * STAILQ_FOREACH
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * SLIST_REMOVE_AFTER
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <assert.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <stddef.h> /* For NULL */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <sys/queue.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+/* Tests for SLIST_REMOVE_AFTER */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#ifndef SLIST_REMOVE_AFTER
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#error SLIST_REMOVE_AFTER is undefined
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#endif
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#ifndef SLIST_HEAD_INITIALIZER
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#error SLIST_HEAD_INITIALIZER is undefined
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#endif
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+typedef struct slist_entry_s {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int value;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ SLIST_ENTRY(slist_entry_s) next;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+} slist_entry_t;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+typedef SLIST_HEAD(slist_head_s, slist_entry_s) slist_head_t;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+static slist_head_t slist_head = SLIST_HEAD_INITIALIZER(slist_head);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+/* Some sample entries */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+static slist_entry_t slist_entries[] = {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ {.value = 1},
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ {.value = 2},
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ {.value = 3},
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+};
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#define SLIST_NUM (sizeof(slist_entries) / sizeof(slist_entries[0]))
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+static void
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+test_slist(void)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+{
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ slist_entry_t *ep, *tp;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ /* Fill the queue with the sample entries (reversed) */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ for (ep = &slist_entries[0]; ep < &slist_entries[SLIST_NUM]; ++ep) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ SLIST_INSERT_HEAD(&slist_head, ep, next);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ /* Get and check the first entry */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ ep = &slist_entries[SLIST_NUM - 1];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ tp = SLIST_FIRST(&slist_head);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ assert(tp->value == ep->value);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ /* Remove the following entry, then check the one after */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ SLIST_REMOVE_AFTER(tp, next);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ ep = &slist_entries[SLIST_NUM - 1 - 2];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ tp = SLIST_NEXT(tp, next);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ assert(tp->value == ep->value);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+/* Tests for STAILQ_FOREACH */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#ifndef STAILQ_FOREACH
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#error STAILQ_FOREACH is undefined
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#endif
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+typedef struct stailq_entry_s {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int value;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ STAILQ_ENTRY(stailq_entry_s) next;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+} stailq_entry_t;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+typedef STAILQ_HEAD(stailq_head_s, stailq_entry_s) stailq_head_t;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+static stailq_head_t stailq_head = STAILQ_HEAD_INITIALIZER(stailq_head);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+/* Some sample entries */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+static stailq_entry_t stailq_entries[] = {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ {.value = 1},
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ {.value = 2},
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ {.value = 3},
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+};
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#define STAILQ_NUM (sizeof(stailq_entries) / sizeof(stailq_entries[0]))
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+static void
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+test_stailq(void)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+{
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ stailq_entry_t *ep, *tp;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ /* Fill the queue with the sample entries */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ for (ep = &stailq_entries[0]; ep < &stailq_entries[STAILQ_NUM]; ++ep) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ STAILQ_INSERT_TAIL(&stailq_head, ep, next);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ /* See if STAILQ_FOREACH returns expected sequence */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ ep = &stailq_entries[0];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ STAILQ_FOREACH(tp, &stailq_head, next) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ assert(tp->value == ep++->value);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ /* Check expected end */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ assert(ep == &stailq_entries[STAILQ_NUM]);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+int
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+main(int argc, char *argv[])
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+{
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ (void) argc; (void) argv;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ test_slist();
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ test_stailq();
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span></pre><pre style='margin:0'>
</pre>