diff mbox series

[BlueZ,5/5] test-eir: Run tests using bt_ad

Message ID 20230712193854.1862996-5-luiz.dentz@gmail.com
State New
Headers show
Series [BlueZ,1/5] shared/ad: Use util_iov_push_* helpers to generate data | expand

Commit Message

Luiz Augusto von Dentz July 12, 2023, 7:38 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This enables the same tests done with eir_data using bt_ad.
---
 unit/test-eir.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
diff mbox series

Patch

diff --git a/unit/test-eir.c b/unit/test-eir.c
index e05a37d01306..49ce65f24bc9 100644
--- a/unit/test-eir.c
+++ b/unit/test-eir.c
@@ -21,6 +21,7 @@ 
 #include "lib/sdp.h"
 #include "src/shared/tester.h"
 #include "src/shared/util.h"
+#include "src/shared/ad.h"
 #include "src/eir.h"
 
 struct test_data {
@@ -539,6 +540,54 @@  static void print_debug(const char *str, void *user_data)
 	tester_debug("%s%s", prefix, str);
 }
 
+static void test_ad(const struct test_data *test, struct eir_data *eir)
+{
+	struct bt_ad *ad;
+	GSList *list;
+
+	ad = bt_ad_new_with_data(test->eir_size, test->eir_data);
+	g_assert(ad);
+
+	g_assert_cmpint(bt_ad_get_flags(ad), ==, test->flags);
+	g_assert_cmpstr(bt_ad_get_name(ad), ==, test->name);
+	g_assert_cmpint(bt_ad_get_tx_power(ad), ==, test->tx_power);
+
+	if (test->uuid) {
+		int i;
+
+		for (i = 0; test->uuid[i]; i++) {
+			bt_uuid_t uuid;
+
+			bt_string_to_uuid(&uuid, test->uuid[i]);
+			g_assert(bt_ad_has_service_uuid(ad, &uuid));
+		}
+	}
+
+	for (list = eir->msd_list; list; list = list->next) {
+		struct eir_msd *msd = list->data;
+		struct bt_ad_manufacturer_data adm;
+
+		adm.manufacturer_id = msd->company;
+		adm.data = msd->data;
+		adm.len = msd->data_len;
+
+		g_assert(bt_ad_has_manufacturer_data(ad, &adm));
+	}
+
+	for (list = eir->sd_list; list; list = list->next) {
+		struct eir_sd *sd = list->data;
+		struct bt_ad_service_data ads;
+
+		bt_string_to_uuid(&ads.uuid, sd->uuid);
+		ads.data = sd->data;
+		ads.len = sd->data_len;
+
+		g_assert(bt_ad_has_service_data(ad, &ads));
+	}
+
+	bt_ad_unref(ad);
+}
+
 static void test_parsing(gconstpointer data)
 {
 	const struct test_data *test = data;
@@ -599,6 +648,8 @@  static void test_parsing(gconstpointer data)
 							"Service Data:");
 	}
 
+	test_ad(data, &eir);
+
 	eir_data_free(&eir);
 
 	tester_test_passed();