tests/libpakfire/main \
tests/libpakfire/arch \
tests/libpakfire/archive \
+ tests/libpakfire/buffer \
tests/libpakfire/build \
tests/libpakfire/cgroup \
tests/libpakfire/config \
tests_libpakfire_archive_LDADD = \
$(TESTSUITE_LDADD)
+tests_libpakfire_buffer_SOURCES = \
+ tests/libpakfire/buffer.c
+
+tests_libpakfire_buffer_CPPFLAGS = \
+ $(TESTSUITE_CPPFLAGS)
+
+tests_libpakfire_buffer_CFLAGS = \
+ $(TESTSUITE_CFLAGS)
+
+tests_libpakfire_buffer_LDFLAGS = \
+ $(TESTSUITE_LDFLAGS)
+
+tests_libpakfire_buffer_LDADD = \
+ $(TESTSUITE_LDADD)
+
dist_tests_libpakfire_build_SOURCES = \
tests/libpakfire/build.c
--- /dev/null
+/*#############################################################################
+# #
+# Pakfire - The IPFire package management system #
+# Copyright (C) 2025 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/buffer.h>
+
+#include "../testsuite.h"
+
+static int test_allocate(const struct test* t) {
+ struct pakfire_buffer buffer = {};
+ int r = EXIT_FAILURE;
+
+ // The buffer should be empty, and not full
+ ASSERT_TRUE(pakfire_buffer_is_empty(&buffer));
+ ASSERT_FALSE(pakfire_buffer_is_full(&buffer));
+
+ // Push something into the buffer
+ ASSERT_SUCCESS(pakfire_buffer_push(&buffer, "ABC", strlen("ABC")));
+
+ // Now the buffer should not be empty any more
+ ASSERT_FALSE(pakfire_buffer_is_empty(&buffer));
+ ASSERT_FALSE(pakfire_buffer_is_full(&buffer));
+ ASSERT(pakfire_buffer_length(&buffer) == 3);
+
+ // Now pop a few bytes...
+ ASSERT_SUCCESS(pakfire_buffer_pop(&buffer, 3));
+
+ // The buffer should be empty again
+ ASSERT_TRUE(pakfire_buffer_is_empty(&buffer));
+ ASSERT_FALSE(pakfire_buffer_is_full(&buffer));
+
+ // Everything passed
+ r = EXIT_SUCCESS;
+
+FAIL:
+ pakfire_buffer_free(&buffer);
+
+ return r;
+}
+
+static int test_find_line(const struct test* t) {
+ struct pakfire_buffer buffer = {};
+ int r = EXIT_FAILURE;
+
+ const char* input = "ABC\nDEFG\nHIJKL\n";
+
+ // Push something into the buffer
+ ASSERT_SUCCESS(pakfire_buffer_push(&buffer, input, strlen(input)));
+
+ // Try find the first line
+ ASSERT_EQUALS(pakfire_buffer_find_line(&buffer), 4);
+
+ // Remove the first line
+ ASSERT_SUCCESS(pakfire_buffer_pop(&buffer, 4));
+
+ // Try find the second line
+ ASSERT_EQUALS(pakfire_buffer_find_line(&buffer), 5);
+
+ // Remove the second line
+ ASSERT_SUCCESS(pakfire_buffer_pop(&buffer, 5));
+
+ // Everything passed
+ r = EXIT_SUCCESS;
+
+FAIL:
+ pakfire_buffer_free(&buffer);
+
+ return r;
+}
+
+int main(int argc, const char* argv[]) {
+ testsuite_add_test(test_allocate, 0);
+ testsuite_add_test(test_find_line, 0);
+
+ return testsuite_run(argc, argv);
+}