Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C1D93932CE for ; Wed, 5 Aug 2026 15:03:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785942223; cv=none; b=gc5Keuns5OXTmOSOKkaMXOqrn8Kyn10G2vfr0TRsz6s1qZE0IV6wbM8EWDhvjZMhgQpaDHLUTaWEVcmH5K1bjJTazz+sJdgTFwiVzC20nSSmmXOcuIvh3K/0dIS55HSVyOwQsRPs9KXG4b4m7ET/Zc0/0K4y8CvDTGV+e8lUkwQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785942223; c=relaxed/simple; bh=7INxH/baR5ofel/+BOedCj4IunxX/8gbvlc+BSgKm8Q=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=foXY2lFKACiDA9Q0a2CInbiplQYiwrc/RmVQT0T41xHdXmcUk3vTja3GqhS9gq/D118Xi8QL9rYnkx0Hwl+lqWNmLWkPvlBtXY77WgQlknsL0n8II5Z/g1DoEalCJEUyGPx62s/F9b/YDv9f967QLzy/qHn1YQCnUg6s26lZE/4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hadess.net; spf=pass smtp.mailfrom=hadess.net; arc=none smtp.client-ip=217.70.183.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hadess.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hadess.net Received: by mail.gandi.net (Postfix) with ESMTPSA id DF7A03EC1C for ; Wed, 5 Aug 2026 15:03:35 +0000 (UTC) From: Bastien Nocera To: linux-bluetooth@vger.kernel.org Subject: [BlueZ, v2] unit: Add test for sdp_xml_parse_record() Date: Wed, 5 Aug 2026 17:02:44 +0200 Message-ID: <20260805150327.2669078-1-hadess@hadess.net> X-Mailer: git-send-email 2.55.0 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Sasl: hadess@hadess.net X-GND-Score: 49 X-GND-Cause: dmFkZTFUzDbTVM1Dq7uTKIBc/uxZRuBdZr6mj4L+snIa58H+LXv8w2eJYyYU3ZiTFKpfYodFYohth19PK/9tGPX6lL5ccvGbqcRi6NpsgtD+OiL23hsaop4eu1PHTZi2FaKmHv0MdjlnVB7CT1EUVumYZRjrBxiY2SGKrtbzrEmf9jQHdL+XeiqUrNOiOl4sh7/eycWChKSUxOcdfaiiH8g2KNAwUKKDaa0y7srupQOwGSjfdPqNk4QxGImwQJL2kqpkoQoV+rOjy0m6h4lf+78Yx31QBTH4ndSIIJzrZ9m0zMKxQxjLHtFiRWZV+8hii4YjkZOzxfveb15S+akDnHUr4beWH6bDCxbg71v+fCbjrdT0M2NSkgIDtOJkmOWmdTt0Nffgdx2PdXxccacZJsCFLRe8o/DaSS3DyvGXK+SVXmvcOxOK1yNOY6BUiizKQEBAze6nLzQBDuu3QcV1ZunOuoHeGGGxKHngx6IpoaPh4r3ZR6YXwJlpyPh+qkeHL+jMDOdcGv3L42fQYXf8h+/5a3LxjOy/wZwYPIa9RUhlyEelqtaJuD/p7cG19JW7FRE0JH4GwwmzcnNkai+T8vnNJfHgH17tk0cHpqSp0APvoMr/6FApgUstlCrMdxL7iw34T7Qqn+FZywSgWl9rIrRj0MMkmwDO1yAgms8FESK8422WTQ X-GND-State: clean This adds 2 example XML files from other repositories, under a fair use license exception. --- Changes since v1: - Added an "expected result" field, so expected failures can also pass tests. Makefile.am | 10 ++ unit/sdp-xml/Bluetooth_HID-sdp_record.xml | 123 ++++++++++++++++++++++ unit/sdp-xml/qt-SerialPortSDPRecord.xml | 57 ++++++++++ unit/test-sdp-xml.c | 81 ++++++++++++++ 4 files changed, 271 insertions(+) create mode 100644 unit/sdp-xml/Bluetooth_HID-sdp_record.xml create mode 100644 unit/sdp-xml/qt-SerialPortSDPRecord.xml create mode 100644 unit/test-sdp-xml.c diff --git a/Makefile.am b/Makefile.am index 19c468d3a504..1c62ee66bdce 100644 --- a/Makefile.am +++ b/Makefile.am @@ -637,6 +637,16 @@ unit_test_sdp_SOURCES = unit/test-sdp.c \ unit_test_sdp_LDADD = lib/libbluetooth-internal.la \ src/libshared-glib.la $(GLIB_LIBS) +unit_tests += unit/test-sdp-xml + +unit_test_sdp_xml_SOURCES = unit/test-sdp-xml.c \ + src/sdp-xml.c src/sdp-xml.h \ + src/log.h src/log.c +unit_test_sdp_xml_LDADD = lib/libbluetooth-internal.la \ + src/libshared-glib.la $(GLIB_LIBS) +unit_test_sdp_xml_CFLAGS = $(AM_CFLAGS) $(GLIB_CFLAGS) -DTOP_SRCDIR=\""$(srcdir)"\" +unit_test_sdp_xml_CPPFLAGS = -I$(srcdir)/lib + unit_tests += unit/test-avdtp unit_test_avdtp_SOURCES = unit/test-avdtp.c \ diff --git a/unit/sdp-xml/Bluetooth_HID-sdp_record.xml b/unit/sdp-xml/Bluetooth_HID-sdp_record.xml new file mode 100644 index 000000000000..687b0b15b520 --- /dev/null +++ b/unit/sdp-xml/Bluetooth_HID-sdp_record.xml @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/unit/sdp-xml/qt-SerialPortSDPRecord.xml b/unit/sdp-xml/qt-SerialPortSDPRecord.xml new file mode 100644 index 000000000000..1f62ccf11a41 --- /dev/null +++ b/unit/sdp-xml/qt-SerialPortSDPRecord.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/unit/test-sdp-xml.c b/unit/test-sdp-xml.c new file mode 100644 index 000000000000..aef22b280498 --- /dev/null +++ b/unit/test-sdp-xml.c @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2026 Intel Corporation. All rights reserved. + * + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include "bluetooth/sdp.h" +#include "bluetooth/sdp_lib.h" + +#include "src/shared/util.h" +#include "src/shared/tester.h" +#include "src/log.h" +#include "src/sdp-xml.h" + +struct test_data { + GString *s; + char *filename; + gboolean expected_result; +}; + +static void parse_xml(gconstpointer data, gsize len, gboolean expected_result) +{ + sdp_record_t *rec = NULL; + gboolean ret; + + rec = sdp_xml_parse_record(data, len); + ret = rec ? TRUE : FALSE; + if (ret == expected_result) + tester_test_passed(); + else + tester_test_failed(); + if (rec) + sdp_record_free(rec); +} + +static void parse_xml_for_filename(gconstpointer data) +{ + struct test_data *t = (struct test_data *) data; + char *path = NULL; + GError *error = NULL; + char *contents = NULL; + gsize len; + + path = g_build_filename(TOP_SRCDIR, "unit", "sdp-xml", t->filename, NULL); + if (!g_file_get_contents(path, &contents, &len, &error)) { + g_warning("Can't load file '%s': %s", path, error->message); + g_free(path); + g_error_free(error); + tester_test_failed(); + } + parse_xml(contents, len, t->expected_result); + g_free(contents); + g_free(path); +} + +#define DEFINE_TEST(fname, res) \ + data.expected_result = res; \ + data.filename = fname; \ + tester_add("/" fname, &data, NULL, parse_xml_for_filename, NULL); + +int main(int argc, char *argv[]) +{ + struct test_data data; + + tester_init(&argc, &argv); + + DEFINE_TEST("Bluetooth_HID-sdp_record.xml", TRUE); + DEFINE_TEST("qt-SerialPortSDPRecord.xml", TRUE); + + return tester_run(); +} -- 2.55.0