tests/libpakfire/httpclient \
tests/libpakfire/jail \
tests/libpakfire/key \
+ tests/libpakfire/log_buffer \
tests/libpakfire/makefile \
tests/libpakfire/os \
tests/libpakfire/package \
tests_libpakfire_key_LDADD = \
$(TESTSUITE_LDADD)
+tests_libpakfire_log_buffer_SOURCES = \
+ tests/libpakfire/log_buffer.c
+
+tests_libpakfire_log_buffer_CPPFLAGS = \
+ $(TESTSUITE_CPPFLAGS)
+
+tests_libpakfire_log_buffer_CFLAGS = \
+ $(TESTSUITE_CFLAGS)
+
+tests_libpakfire_log_buffer_LDFLAGS = \
+ $(TESTSUITE_LDFLAGS)
+
+tests_libpakfire_log_buffer_LDADD = \
+ $(TESTSUITE_LDADD)
+
dist_tests_libpakfire_makefile_SOURCES = \
tests/libpakfire/makefile.c
--- /dev/null
+/*#############################################################################
+# #
+# Pakfire - The IPFire package management system #
+# Copyright (C) 2024 Pakfire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#include <pakfire/log_buffer.h>
+
+#include "../testsuite.h"
+
+static int test_simple(const struct test* t) {
+ struct pakfire_log_buffer* buffer = NULL;
+ char* line = NULL;
+ size_t length = 0;
+ int priority = 0;
+ int r = EXIT_FAILURE;
+
+ ASSERT_SUCCESS(pakfire_log_buffer_create(&buffer, t->ctx, 0));
+
+ // Enqueue three strings
+ ASSERT_SUCCESS(pakfire_log_buffer_enqueue(buffer, LOG_DEBUG, "A", -1));
+ ASSERT_SUCCESS(pakfire_log_buffer_enqueue(buffer, LOG_DEBUG, "BB", -1));
+ ASSERT_SUCCESS(pakfire_log_buffer_enqueue(buffer, LOG_DEBUG, "CCC", -1));
+
+ // Dequeue the first string
+ ASSERT_SUCCESS(pakfire_log_buffer_dequeue(buffer, &priority, &line, &length));
+
+ ASSERT_EQUALS(priority, LOG_DEBUG);
+ ASSERT_STRING_EQUALS(line, "A");
+ ASSERT_EQUALS(length, 1);
+ free(line);
+
+ // Dequeue the second string
+ ASSERT_SUCCESS(pakfire_log_buffer_dequeue(buffer, &priority, &line, &length));
+
+ ASSERT_EQUALS(priority, LOG_DEBUG);
+ ASSERT_STRING_EQUALS(line, "BB");
+ ASSERT_EQUALS(length, 2);
+ free(line);
+
+ // Dequeue the third string
+ ASSERT_SUCCESS(pakfire_log_buffer_dequeue(buffer, &priority, &line, &length));
+
+ ASSERT_EQUALS(priority, LOG_DEBUG);
+ ASSERT_STRING_EQUALS(line, "CCC");
+ ASSERT_EQUALS(length, 3);
+ free(line);
+
+ // Dequeue more than we put in
+ ASSERT_SUCCESS(pakfire_log_buffer_dequeue(buffer, &priority, &line, &length));
+
+ ASSERT_EQUALS(priority, -1);
+ ASSERT_EQUALS(line, NULL);
+ ASSERT_EQUALS(length, -1);
+
+ // Everything passed
+ r = EXIT_SUCCESS;
+
+FAIL:
+ if (buffer)
+ pakfire_log_buffer_unref(buffer);
+
+ return r;
+}
+
+int main(int argc, const char* argv[]) {
+ testsuite_add_test(test_simple, 0);
+
+ return testsuite_run(argc, argv);
+}