typedef struct {
bluetooth::Uuid app_uuid128;
- tGATT_CBACK app_cb;
- tGATT_IF gatt_if; /* one based */
- bool in_use;
- uint8_t listening; /* if adv for all has been enabled */
- bool eatt_support;
+ tGATT_CBACK app_cb{};
+ tGATT_IF gatt_if{0}; /* one based */
+ bool in_use{false};
+ uint8_t listening{0}; /* if adv for all has been enabled */
+ bool eatt_support{false};
} tGATT_REG;
struct tGATT_CLCB;
* MUST be provided.
*/
typedef struct {
- tGATT_CONN_CBACK* p_conn_cb;
- tGATT_CMPL_CBACK* p_cmpl_cb;
- tGATT_DISC_RES_CB* p_disc_res_cb;
- tGATT_DISC_CMPL_CB* p_disc_cmpl_cb;
- tGATT_REQ_CBACK* p_req_cb;
- tGATT_ENC_CMPL_CB* p_enc_cmpl_cb;
- tGATT_CONGESTION_CBACK* p_congestion_cb;
- tGATT_PHY_UPDATE_CB* p_phy_update_cb;
- tGATT_CONN_UPDATE_CB* p_conn_update_cb;
+ tGATT_CONN_CBACK* p_conn_cb{nullptr};
+ tGATT_CMPL_CBACK* p_cmpl_cb{nullptr};
+ tGATT_DISC_RES_CB* p_disc_res_cb{nullptr};
+ tGATT_DISC_CMPL_CB* p_disc_cmpl_cb{nullptr};
+ tGATT_REQ_CBACK* p_req_cb{nullptr};
+ tGATT_ENC_CMPL_CB* p_enc_cmpl_cb{nullptr};
+ tGATT_CONGESTION_CBACK* p_congestion_cb{nullptr};
+ tGATT_PHY_UPDATE_CB* p_phy_update_cb{nullptr};
+ tGATT_CONN_UPDATE_CB* p_conn_update_cb{nullptr};
} tGATT_CBACK;
/***************** Start Handle Management Definitions *********************/
*/
#include <gtest/gtest.h>
+#include <string.h>
+
#include <cstdint>
#include <map>
+#include <memory>
#include <string>
#include "common/message_loop_thread.h"
+#include "stack/gatt/gatt_int.h"
std::map<std::string, int> mock_function_count_map;
class StackGattTest : public ::testing::Test {};
-TEST_F(StackGattTest, nop) {}
+// Actual size of structure without compiler padding
+size_t actual_sizeof_tGATT_REG() {
+ return sizeof(bluetooth::Uuid) + sizeof(tGATT_CBACK) + sizeof(tGATT_IF) +
+ sizeof(bool) + sizeof(uint8_t) + sizeof(bool);
+}
+
+TEST_F(StackGattTest, lifecycle_tGATT_REG) {
+ {
+ std::unique_ptr<tGATT_REG> reg0 = std::make_unique<tGATT_REG>();
+ std::unique_ptr<tGATT_REG> reg1 = std::make_unique<tGATT_REG>();
+ memset(reg0.get(), 0xff, sizeof(tGATT_REG));
+ memset(reg1.get(), 0xff, sizeof(tGATT_REG));
+ ASSERT_EQ(0, memcmp(reg0.get(), reg1.get(), sizeof(tGATT_REG)));
+ }
+
+ {
+ std::unique_ptr<tGATT_REG> reg0 = std::make_unique<tGATT_REG>();
+ memset(reg0.get(), 0xff, sizeof(tGATT_REG));
+
+ tGATT_REG reg1;
+ memset(®1, 0xff, sizeof(tGATT_REG));
+
+ // Clear the structures
+ memset(reg0.get(), 0, sizeof(tGATT_REG));
+ reg1 = {};
+ ASSERT_EQ(0, memcmp(reg0.get(), ®1, actual_sizeof_tGATT_REG()));
+ }
+
+ {
+ tGATT_REG* reg0 = new tGATT_REG();
+ tGATT_REG* reg1 = new tGATT_REG();
+ memset(reg0, 0, sizeof(tGATT_REG));
+ *reg1 = {};
+ reg0->in_use = true;
+ ASSERT_NE(0, memcmp(reg0, reg1, sizeof(tGATT_REG)));
+ delete reg1;
+ delete reg0;
+ }
+}