diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index 7923c8b..385f61a 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
#include "src/shared/att.h"
#include "src/shared/gatt-helpers.h"
#include "src/shared/gatt-client.h"
+#include "src/shared/queue.h"
+#include "src/shared/gatt-db.h"
+#include "src/shared/gatt-server.h"
struct test_pdu {
bool valid;
struct context {
GMainLoop *main_loop;
struct bt_gatt_client *client;
+ struct bt_gatt_server *server;
struct bt_att *att;
+ struct gatt_db *db;
guint source;
guint process;
int fd;
#define define_test_client(name, function, bt_services, test_step, args...)\
define_test(name, function, CLIENT, NULL, bt_services, test_step, args)
+#define define_test_server(name, function, bt_services, test_step, args...)\
+ define_test(name, function, SERVER, NULL, bt_services, test_step, args)
+
#define SERVICE_DATA_1_PDU \
raw_pdu(0x02, 0x00, 0x02), \
raw_pdu(0x03, 0x00, 0x02), \
raw_pdu(0x04, 0x08, 0x00, 0x08, 0x00), \
raw_pdu(0x05, 0x01, 0x08, 0x00, 0x01, 0x29)
+#define SERVER_MTU_EXCHANGE_PDU raw_pdu(0x02, 0x17, 0x00)
+
static bt_uuid_t uuid_16 = {
.type = BT_UUID16,
.value.u16 = 0x1800
static void context_process(struct context *context)
{
+ /* Quit the context if we processed the last PDU */
if (!context->data->pdu_list[context->pdu_offset].valid) {
context_quit(context);
return;
bt_gatt_exchange_mtu(context->att, mtu, NULL, NULL, NULL);
break;
+ case SERVER:
+ context->db = gatt_db_new();
+ g_assert(context->db);
+
+ context->server = bt_gatt_server_new(context->db, att, mtu);
+ g_assert(context->server);
+
+ if (g_test_verbose())
+ bt_gatt_server_set_debug(context->server, print_debug,
+ "bt_gatt_server:", NULL);
+ bt_att_unref(att);
+ break;
case CLIENT:
context->client = bt_gatt_client_new(att, mtu);
g_assert(context->client);
g_source_remove(context->source);
bt_gatt_client_unref(context->client);
+ bt_gatt_server_unref(context->server);
+ gatt_db_destroy(context->db);
if (context->att)
bt_att_unref(context->att);
execute_context(context);
}
+static void test_server(gconstpointer data)
+{
+ struct context *context = create_context(512, data);
+ ssize_t len;
+ const struct test_pdu pdu = SERVER_MTU_EXCHANGE_PDU;
+
+ len = write(context->fd, pdu.data, pdu.size);
+
+ if (g_test_verbose())
+ util_hexdump('<', pdu.data, len, test_debug, "GATT: ");
+
+ g_assert_cmpint(len, ==, pdu.size);
+
+ execute_context(context);
+}
+
static void test_search_primary(gconstpointer data)
{
struct context *context = create_context(512, data);
*/
define_test_client("/TP/GAC/CL/BV-01-C", test_client, NULL, NULL,
- raw_pdu(0x02, 0x00, 0x02));
+ raw_pdu(0x02, 0x00, 0x02));
+
+ define_test_server("/TP/GAC/SR/BV-01-C", test_server, NULL, NULL,
+ raw_pdu(0x03, 0x00, 0x02));
/*
* Discovery