lib: metadata: transform fast path precond. checks to BT_ASSERT_PRE()
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 7 Mar 2018 00:25:48 +0000 (19:25 -0500)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 2 May 2019 03:41:50 +0000 (23:41 -0400)
Use BT_ASSERT_PRE() to assert that trace, stream, stream class, event
class, and field type preconditions are satisfied instead of
unconditional run-time checks for typical fast path API functions
(getters).

Update `tests/lib/test_ctf_writer.c` accordingly to remove unit tests
which expect a specific return value when preconditions are not
satisfied.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
lib/ctf-ir/event-class.c
lib/ctf-ir/field-types.c
lib/ctf-ir/stream-class.c
lib/ctf-ir/stream.c
lib/ctf-ir/trace.c
tests/lib/test_ctf_writer.c

index 4152a0b88293cd736e4fe24f2cd46a81df2bbde9..5ff9d0d481c06feea7c9df1ef6ee6dd46509461d 100644 (file)
@@ -46,6 +46,7 @@
 #include <babeltrace/types.h>
 #include <babeltrace/values-internal.h>
 #include <babeltrace/assert-internal.h>
+#include <babeltrace/assert-pre-internal.h>
 #include <inttypes.h>
 #include <stdlib.h>
 
@@ -105,33 +106,15 @@ error:
 
 const char *bt_event_class_get_name(struct bt_event_class *event_class)
 {
-       const char *name = NULL;
-
-       if (!event_class) {
-               BT_LOGW_STR("Invalid parameter: event class is NULL.");
-               goto end;
-       }
-
-       name = event_class->name->str;
-
-end:
-       return name;
+       BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
+       BT_ASSERT(event_class->name);
+       return event_class->name->str;
 }
 
 int64_t bt_event_class_get_id(struct bt_event_class *event_class)
 {
-       int64_t ret = 0;
-
-       if (!event_class) {
-               BT_LOGW_STR("Invalid parameter: event class is NULL.");
-               ret = (int64_t) -1;
-               goto end;
-       }
-
-       ret = event_class->id;
-
-end:
-       return ret;
+       BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
+       return event_class->id;
 }
 
 int bt_event_class_set_id(struct bt_event_class *event_class,
@@ -176,18 +159,8 @@ end:
 enum bt_event_class_log_level bt_event_class_get_log_level(
                struct bt_event_class *event_class)
 {
-       enum bt_event_class_log_level log_level;
-
-       if (!event_class) {
-               BT_LOGW_STR("Invalid parameter: event class is NULL.");
-               log_level = BT_EVENT_CLASS_LOG_LEVEL_UNKNOWN;
-               goto end;
-       }
-
-       log_level = event_class->log_level;
-
-end:
-       return log_level;
+       BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
+       return event_class->log_level;
 }
 
 int bt_event_class_set_log_level(struct bt_event_class *event_class,
@@ -253,16 +226,12 @@ const char *bt_event_class_get_emf_uri(
 {
        const char *emf_uri = NULL;
 
-       if (!event_class) {
-               BT_LOGW_STR("Invalid parameter: event class is NULL.");
-               goto end;
-       }
+       BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
 
        if (event_class->emf_uri->len > 0) {
                emf_uri = event_class->emf_uri->str;
        }
 
-end:
        return emf_uri;
 }
 
@@ -313,25 +282,15 @@ end:
 struct bt_stream_class *bt_event_class_get_stream_class(
                struct bt_event_class *event_class)
 {
-       return event_class ?
-               bt_get(bt_event_class_borrow_stream_class(event_class)) :
-               NULL;
+       BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
+       return bt_get(bt_event_class_borrow_stream_class(event_class));
 }
 
 struct bt_field_type *bt_event_class_get_payload_type(
                struct bt_event_class *event_class)
 {
-       struct bt_field_type *payload = NULL;
-
-       if (!event_class) {
-               BT_LOGW_STR("Invalid parameter: event class is NULL.");
-               goto end;
-       }
-
-       bt_get(event_class->fields);
-       payload = event_class->fields;
-end:
-       return payload;
+       BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
+       return bt_get(event_class->fields);
 }
 
 int bt_event_class_set_payload_type(struct bt_event_class *event_class,
@@ -526,10 +485,7 @@ struct bt_field_type *bt_event_class_get_context_type(
 {
        struct bt_field_type *context_type = NULL;
 
-       if (!event_class) {
-               BT_LOGW_STR("Invalid parameter: event class is NULL.");
-               goto end;
-       }
+       BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
 
        if (!event_class->context) {
                BT_LOGV("Event class has no context field type: "
@@ -539,8 +495,8 @@ struct bt_field_type *bt_event_class_get_context_type(
                goto end;
        }
 
-       bt_get(event_class->context);
-       context_type = event_class->context;
+       context_type = bt_get(event_class->context);
+
 end:
        return context_type;
 }
index a04384d26a9a58d8c6aeccdf89d68277fef96df0..09fa586510d0f8732fae80b6f0233267f723e63f 100644 (file)
 #include <babeltrace/compiler-internal.h>
 #include <babeltrace/endian-internal.h>
 #include <babeltrace/assert-internal.h>
+#include <babeltrace/assert-pre-internal.h>
 #include <float.h>
 #include <inttypes.h>
 #include <stdlib.h>
 
+#define BT_ASSERT_PRE_FT_HAS_ID(_ft, _type_id, _name)                  \
+       BT_ASSERT_PRE((_ft)->id == (_type_id),                          \
+               _name " has the wrong type ID: expected-type-id=%s, "   \
+               "%![ft-]+F", bt_field_type_id_string(_type_id), (_ft))
+
+#define BT_ASSERT_PRE_FT_HOT(_ft, _name)                               \
+       BT_ASSERT_PRE_HOT((_ft), (_name), ": +%!+F", (_ft))
+
 struct range_overlap_query {
        union {
                uint64_t _unsigned;
@@ -847,52 +856,22 @@ struct bt_field_type *bt_field_type_integer_create(unsigned int size)
 
 int bt_field_type_integer_get_size(struct bt_field_type *type)
 {
-       int ret = 0;
        struct bt_field_type_integer *integer;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (type->id != BT_FIELD_TYPE_ID_INTEGER) {
-               BT_LOGW("Invalid parameter: field type is not an integer field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_INTEGER, "Field type");
        integer = container_of(type, struct bt_field_type_integer, parent);
-       ret = (int) integer->size;
-end:
-       return ret;
+       return (int) integer->size;
 }
 
 int bt_ctf_field_type_integer_get_signed(struct bt_field_type *type)
 {
-       int ret = 0;
        struct bt_field_type_integer *integer;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (type->id != BT_FIELD_TYPE_ID_INTEGER) {
-               BT_LOGW("Invalid parameter: field type is not an integer field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_INTEGER, "Field type");
        integer = container_of(type, struct bt_field_type_integer, parent);
-       ret = integer->is_signed;
-end:
-       return ret;
+       return integer->is_signed;
 }
 
 bt_bool bt_field_type_integer_is_signed(
@@ -982,25 +961,12 @@ end:
 enum bt_integer_base bt_field_type_integer_get_base(
                struct bt_field_type *type)
 {
-       enum bt_integer_base ret = BT_INTEGER_BASE_UNKNOWN;
        struct bt_field_type_integer *integer;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               goto end;
-       }
-
-       if (type->id != BT_FIELD_TYPE_ID_INTEGER) {
-               BT_LOGW("Invalid parameter: field type is not an integer field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_INTEGER, "Field type");
        integer = container_of(type, struct bt_field_type_integer, parent);
-       ret = integer->base;
-end:
-       return ret;
+       return integer->base;
 }
 
 int bt_field_type_integer_set_base(struct bt_field_type *type,
@@ -1057,25 +1023,12 @@ end:
 enum bt_string_encoding bt_field_type_integer_get_encoding(
                struct bt_field_type *type)
 {
-       enum bt_string_encoding ret = BT_STRING_ENCODING_UNKNOWN;
        struct bt_field_type_integer *integer;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               goto end;
-       }
-
-       if (type->id != BT_FIELD_TYPE_ID_INTEGER) {
-               BT_LOGW("Invalid parameter: field type is not an integer field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_INTEGER, "Field type");
        integer = container_of(type, struct bt_field_type_integer, parent);
-       ret = integer->encoding;
-end:
-       return ret;
+       return integer->encoding;
 }
 
 int bt_field_type_integer_set_encoding(struct bt_field_type *type,
@@ -1126,18 +1079,11 @@ struct bt_clock_class *bt_field_type_integer_get_mapped_clock_class(
                struct bt_field_type *type)
 {
        struct bt_field_type_integer *integer;
-       struct bt_clock_class *clock_class = NULL;
-
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               goto end;
-       }
 
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_INTEGER, "Field type");
        integer = container_of(type, struct bt_field_type_integer, parent);
-       clock_class = integer->mapped_clock;
-       bt_get(clock_class);
-end:
-       return clock_class;
+       return bt_get(integer->mapped_clock);
 }
 
 BT_HIDDEN
@@ -1236,18 +1182,8 @@ bt_field_type_enumeration_find_mappings_type(
        struct bt_field_type_enumeration *enumeration_type;
        struct bt_field_type_enumeration_mapping_iterator *iter = NULL;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               goto end;
-       }
-
-       if (type->id != BT_FIELD_TYPE_ID_ENUM) {
-               BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_ENUM, "Field type");
        enumeration_type = container_of(type,
                struct bt_field_type_enumeration, parent);
        iter = g_new0(struct bt_field_type_enumeration_mapping_iterator, 1);
@@ -1300,12 +1236,7 @@ int bt_field_type_enumeration_mapping_iterator_next(
        struct bt_field_type *type;
        int i, ret = 0, len;
 
-       if (!iter) {
-               BT_LOGW_STR("Invalid parameter: enumeration field type mapping iterator is NULL.");
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(iter, "Enumeration field type mapping iterator");
        enumeration = iter->enumeration_type;
        type = &enumeration->parent;
        len = enumeration->entries->len;
@@ -1416,25 +1347,13 @@ int bt_field_type_enumeration_mapping_iterator_get_signed(
                const char **mapping_name, int64_t *range_begin,
                int64_t *range_end)
 {
-       int ret = 0;
-
-       if (!iter) {
-               BT_LOGW_STR("Invalid parameter: enumeration field type mapping iterator is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (iter->index == -1) {
-               BT_LOGW_STR("Invalid enumeration field type mapping iterator access: position=-1");
-               ret = -1;
-               goto end;
-       }
-
-       ret = bt_field_type_enumeration_get_mapping_signed(
+       BT_ASSERT_PRE_NON_NULL(iter, "Enumeration field type mapping iterator");
+       BT_ASSERT_PRE(iter->index != -1,
+               "Invalid enumeration field type mapping iterator access: "
+               "addr=%p, position=-1", iter);
+       return bt_field_type_enumeration_get_mapping_signed(
                        &iter->enumeration_type->parent, iter->index,
                        mapping_name, range_begin, range_end);
-end:
-       return ret;
 }
 
 int bt_field_type_enumeration_mapping_iterator_get_unsigned(
@@ -1442,25 +1361,13 @@ int bt_field_type_enumeration_mapping_iterator_get_unsigned(
                const char **mapping_name, uint64_t *range_begin,
                uint64_t *range_end)
 {
-       int ret = 0;
-
-       if (!iter) {
-               BT_LOGW_STR("Invalid parameter: enumeration field type mapping iterator is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (iter->index == -1) {
-               BT_LOGW_STR("Invalid enumeration field type mapping iterator access: position=-1");
-               ret = -1;
-               goto end;
-       }
-
-       ret = bt_field_type_enumeration_get_mapping_unsigned(
+       BT_ASSERT_PRE_NON_NULL(iter, "Enumeration field type mapping iterator");
+       BT_ASSERT_PRE(iter->index != -1,
+               "Invalid enumeration field type mapping iterator access: "
+               "addr=%p, position=-1", iter);
+       return bt_field_type_enumeration_get_mapping_unsigned(
                        &iter->enumeration_type->parent, iter->index,
                        mapping_name, range_begin, range_end);
-end:
-       return ret;
 }
 
 int bt_field_type_enumeration_get_mapping_signed(
@@ -1471,12 +1378,9 @@ int bt_field_type_enumeration_get_mapping_signed(
        int ret = 0;
        struct enumeration_mapping *mapping;
 
-       if (!enum_field_type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(enum_field_type, "Field type");
+       BT_ASSERT_PRE_FT_HAS_ID(enum_field_type,
+               BT_FIELD_TYPE_ID_ENUM, "Field type");
        mapping = get_enumeration_mapping(enum_field_type, index);
        if (!mapping) {
                /* get_enumeration_mapping() reports any error */
@@ -1496,6 +1400,7 @@ int bt_field_type_enumeration_get_mapping_signed(
        if (range_end) {
                *range_end = mapping->range_end._signed;
        }
+
 end:
        return ret;
 }
@@ -1509,12 +1414,9 @@ int bt_field_type_enumeration_get_mapping_unsigned(
        int ret = 0;
        struct enumeration_mapping *mapping;
 
-       if (!enum_field_type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(enum_field_type, "Field type");
+       BT_ASSERT_PRE_FT_HAS_ID(enum_field_type,
+               BT_FIELD_TYPE_ID_ENUM, "Field type");
        mapping = get_enumeration_mapping(enum_field_type, index);
        if (!mapping) {
                /* get_enumeration_mapping() reports any error */
@@ -1534,6 +1436,7 @@ int bt_field_type_enumeration_get_mapping_unsigned(
        if (range_end) {
                *range_end = mapping->range_end._unsigned;
        }
+
 end:
        return ret;
 }
@@ -1584,27 +1487,13 @@ error:
 struct bt_field_type *bt_field_type_enumeration_get_container_type(
                struct bt_field_type *type)
 {
-       struct bt_field_type *container_type = NULL;
        struct bt_field_type_enumeration *enumeration_type;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               goto end;
-       }
-
-       if (type->id != BT_FIELD_TYPE_ID_ENUM) {
-               BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_ENUM, "Field type");
        enumeration_type = container_of(type,
                struct bt_field_type_enumeration, parent);
-       container_type = enumeration_type->container;
-       bt_get(container_type);
-end:
-       return container_type;
+       return bt_get(enumeration_type->container);
 }
 
 int bt_field_type_enumeration_add_mapping_signed(
@@ -1788,28 +1677,13 @@ end:
 int64_t bt_field_type_enumeration_get_mapping_count(
                struct bt_field_type *type)
 {
-       int64_t ret = 0;
        struct bt_field_type_enumeration *enumeration;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               ret = (int64_t) -1;
-               goto end;
-       }
-
-       if (type->id != BT_FIELD_TYPE_ID_ENUM) {
-               BT_LOGW("Invalid parameter: field type is not an enumeration field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               ret = (int64_t) -1;
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_ENUM, "Field type");
        enumeration = container_of(type, struct bt_field_type_enumeration,
                parent);
-       ret = (int64_t) enumeration->entries->len;
-end:
-       return ret;
+       return (int64_t) enumeration->entries->len;
 }
 
 struct bt_field_type *bt_field_type_floating_point_create(void)
@@ -1838,33 +1712,17 @@ end:
 int bt_field_type_floating_point_get_exponent_digits(
                struct bt_field_type *type)
 {
-       int ret = 0;
        struct bt_field_type_floating_point *floating_point;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (type->id != BT_FIELD_TYPE_ID_FLOAT) {
-               BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_FLOAT, "Field type");
        floating_point = container_of(type,
                struct bt_field_type_floating_point, parent);
-       ret = (int) floating_point->exp_dig;
-end:
-       return ret;
+       return (int) floating_point->exp_dig;
 }
 
 int bt_field_type_floating_point_set_exponent_digits(
-               struct bt_field_type *type,
-               unsigned int exponent_digits)
+               struct bt_field_type *type, unsigned int exponent_digits)
 {
        int ret = 0;
        struct bt_field_type_floating_point *floating_point;
@@ -1912,33 +1770,17 @@ end:
 int bt_field_type_floating_point_get_mantissa_digits(
                struct bt_field_type *type)
 {
-       int ret = 0;
        struct bt_field_type_floating_point *floating_point;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (type->id != BT_FIELD_TYPE_ID_FLOAT) {
-               BT_LOGW("Invalid parameter: field type is not a floating point number field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_FLOAT, "Field type");
        floating_point = container_of(type,
                struct bt_field_type_floating_point, parent);
-       ret = (int) floating_point->mant_dig;
-end:
-       return ret;
+       return (int) floating_point->mant_dig;
 }
 
 int bt_field_type_floating_point_set_mantissa_digits(
-               struct bt_field_type *type,
-               unsigned int mantissa_digits)
+               struct bt_field_type *type, unsigned int mantissa_digits)
 {
        int ret = 0;
        struct bt_field_type_floating_point *floating_point;
@@ -2102,28 +1944,13 @@ end:
 int64_t bt_field_type_structure_get_field_count(
                struct bt_field_type *type)
 {
-       int64_t ret = 0;
        struct bt_field_type_structure *structure;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               ret = (int64_t) -1;
-               goto end;
-       }
-
-       if (type->id != BT_FIELD_TYPE_ID_STRUCT) {
-               BT_LOGW("Invalid parameter: field type is not a structure field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               ret = (int64_t) -1;
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_STRUCT, "Field type");
        structure = container_of(type, struct bt_field_type_structure,
                parent);
-       ret = (int64_t) structure->fields->len;
-end:
-       return ret;
+       return (int64_t) structure->fields->len;
 }
 
 int bt_field_type_structure_get_field_by_index(
@@ -2133,48 +1960,32 @@ int bt_field_type_structure_get_field_by_index(
 {
        struct bt_field_type_structure *structure;
        struct structure_field *field;
-       int ret = 0;
-
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (type->id != BT_FIELD_TYPE_ID_STRUCT) {
-               BT_LOGW("Invalid parameter: field type is not a structure field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               ret = -1;
-               goto end;
-       }
 
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_STRUCT, "Field type");
        structure = container_of(type, struct bt_field_type_structure,
                parent);
-       if (index >= structure->fields->len) {
-               BT_LOGW("Invalid parameter: index is out of bounds: "
-                       "addr=%p, index=%" PRIu64 ", count=%u",
-                       type, index, structure->fields->len);
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT_PRE(index < structure->fields->len,
+               "Index is out of bounds: index=%" PRIu64 ", "
+               "count=%u, %![ft-]+F",
+               index, structure->fields->len, type);
        field = g_ptr_array_index(structure->fields, index);
+
        if (field_type) {
                *field_type = field->type;
                bt_get(field->type);
        }
+
        if (field_name) {
                *field_name = g_quark_to_string(field->name);
                BT_ASSERT(*field_name);
        }
-end:
-       return ret;
+
+       return 0;
 }
 
 struct bt_field_type *bt_field_type_structure_get_field_type_by_name(
-               struct bt_field_type *type,
-               const char *name)
+               struct bt_field_type *type, const char *name)
 {
        size_t index;
        GQuark name_quark;
@@ -2182,16 +1993,9 @@ struct bt_field_type *bt_field_type_structure_get_field_type_by_name(
        struct bt_field_type_structure *structure;
        struct bt_field_type *field_type = NULL;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               goto end;
-       }
-
-       if (!name) {
-               BT_LOGW_STR("Invalid parameter: name is NULL.");
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_NON_NULL(name, "Name");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_STRUCT, "Field type");
        name_quark = g_quark_try_string(name);
        if (!name_quark) {
                BT_LOGV("No such structure field type field name: "
@@ -2213,6 +2017,7 @@ struct bt_field_type *bt_field_type_structure_get_field_type_by_name(
        field = structure->fields->pdata[index];
        field_type = field->type;
        bt_get(field_type);
+
 end:
        return field_type;
 }
@@ -2267,18 +2072,8 @@ struct bt_field_type *bt_field_type_variant_get_tag_type(
        struct bt_field_type_variant *variant;
        struct bt_field_type *tag_type = NULL;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               goto end;
-       }
-
-       if (type->id != BT_FIELD_TYPE_ID_VARIANT) {
-               BT_LOGW("Invalid parameter: field type is not a variant field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_VARIANT, "Field type");
        variant = container_of(type, struct bt_field_type_variant, parent);
        if (!variant->tag) {
                BT_LOGV("Variant field type has no tag field type: "
@@ -2288,28 +2083,18 @@ struct bt_field_type *bt_field_type_variant_get_tag_type(
 
        tag_type = &variant->tag->parent;
        bt_get(tag_type);
+
 end:
        return tag_type;
 }
 
-const char *bt_field_type_variant_get_tag_name(
-               struct bt_field_type *type)
+const char *bt_field_type_variant_get_tag_name(struct bt_field_type *type)
 {
        struct bt_field_type_variant *variant;
        const char *tag_name = NULL;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               goto end;
-       }
-
-       if (type->id != BT_FIELD_TYPE_ID_VARIANT) {
-               BT_LOGW("Invalid parameter: field type is not a variant field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_VARIANT, "Field type");
        variant = container_of(type, struct bt_field_type_variant, parent);
        if (variant->tag_name->len == 0) {
                BT_LOGV("Variant field type has no tag field name: "
@@ -2463,16 +2248,9 @@ struct bt_field_type *bt_field_type_variant_get_field_type_by_name(
        struct bt_field_type_variant *variant;
        struct bt_field_type *field_type = NULL;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               goto end;
-       }
-
-       if (!field_name) {
-               BT_LOGW_STR("Invalid parameter: field name is NULL.");
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_NON_NULL(field_name, "Name");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_VARIANT, "Field type");
        name_quark = g_quark_try_string(field_name);
        if (!name_quark) {
                BT_LOGV("No such variant field type field name: "
@@ -2493,6 +2271,7 @@ struct bt_field_type *bt_field_type_variant_get_field_type_by_name(
        field = g_ptr_array_index(variant->fields, index);
        field_type = field->type;
        bt_get(field_type);
+
 end:
        return field_type;
 }
@@ -2506,23 +2285,9 @@ struct bt_field_type *bt_field_type_variant_get_field_type_from_tag(
        struct bt_field_type *field_type = NULL;
        struct bt_field_type_enumeration_mapping_iterator *iter = NULL;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
-               goto end;
-       }
-
-       if (!tag) {
-               BT_LOGW_STR("Invalid parameter: tag field is NULL.");
-               goto end;
-       }
-
-       if (type->id != BT_FIELD_TYPE_ID_VARIANT) {
-               BT_LOGW("Invalid parameter: field type is not a variant field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Variant field type");
+       BT_ASSERT_PRE_NON_NULL(tag, "Tag field type");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_VARIANT, "Field type");
        iter = bt_field_enumeration_get_mappings(tag);
        ret = bt_field_type_enumeration_mapping_iterator_next(iter);
        if (!iter || ret) {
@@ -2548,29 +2313,13 @@ end:
 
 int64_t bt_field_type_variant_get_field_count(struct bt_field_type *type)
 {
-       int64_t ret = 0;
        struct bt_field_type_variant *variant;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               ret = (int64_t) -1;
-               goto end;
-       }
-
-       if (type->id != BT_FIELD_TYPE_ID_VARIANT) {
-               BT_LOGW("Invalid parameter: field type is not a variant field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               ret = (int64_t) -1;
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Variant field type");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_VARIANT, "Field type");
        variant = container_of(type, struct bt_field_type_variant,
                parent);
-       ret = (int64_t) variant->fields->len;
-end:
-       return ret;
-
+       return (int64_t) variant->fields->len;
 }
 
 int bt_field_type_variant_get_field_by_index(struct bt_field_type *type,
@@ -2579,43 +2328,28 @@ int bt_field_type_variant_get_field_by_index(struct bt_field_type *type,
 {
        struct bt_field_type_variant *variant;
        struct structure_field *field;
-       int ret = 0;
-
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (type->id != BT_FIELD_TYPE_ID_VARIANT) {
-               BT_LOGW("Invalid parameter: field type is not a variant field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               ret = -1;
-               goto end;
-       }
 
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_VARIANT, "Field type");
        variant = container_of(type, struct bt_field_type_variant,
                parent);
-       if (index >= variant->fields->len) {
-               BT_LOGW("Invalid parameter: index is out of bounds: "
-                       "addr=%p, index=%" PRIu64 ", count=%u",
-                       type, index, variant->fields->len);
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT_PRE(index < variant->fields->len,
+               "Index is out of bounds: index=%" PRIu64 ", "
+               "count=%u, %![ft-]+F",
+               index, variant->fields->len, type);
        field = g_ptr_array_index(variant->fields, index);
+
        if (field_type) {
                *field_type = field->type;
                bt_get(field->type);
        }
+
        if (field_name) {
                *field_name = g_quark_to_string(field->name);
                BT_ASSERT(*field_name);
        }
-end:
-       return ret;
+
+       return 0;
 }
 
 struct bt_field_type *bt_field_type_array_create(
@@ -2659,26 +2393,12 @@ error:
 struct bt_field_type *bt_field_type_array_get_element_type(
                struct bt_field_type *type)
 {
-       struct bt_field_type *ret = NULL;
        struct bt_field_type_array *array;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               goto end;
-       }
-
-       if (type->id != BT_FIELD_TYPE_ID_ARRAY) {
-               BT_LOGW("Invalid parameter: field type is not an array field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_ARRAY, "Field type");
        array = container_of(type, struct bt_field_type_array, parent);
-       ret = array->element_type;
-       bt_get(ret);
-end:
-       return ret;
+       return bt_get(array->element_type);
 }
 
 BT_HIDDEN
@@ -2725,27 +2445,12 @@ end:
 
 int64_t bt_field_type_array_get_length(struct bt_field_type *type)
 {
-       int64_t ret;
        struct bt_field_type_array *array;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               ret = (int64_t) -1;
-               goto end;
-       }
-
-       if (type->id != BT_FIELD_TYPE_ID_ARRAY) {
-               BT_LOGW("Invalid parameter: field type is not an array field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               ret = (int64_t) -1;
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_ARRAY, "Field type");
        array = container_of(type, struct bt_field_type_array, parent);
-       ret = (int64_t) array->length;
-end:
-       return ret;
+       return (int64_t) array->length;
 }
 
 struct bt_field_type *bt_field_type_sequence_create(
@@ -2790,27 +2495,13 @@ error:
 struct bt_field_type *bt_field_type_sequence_get_element_type(
                struct bt_field_type *type)
 {
-       struct bt_field_type *ret = NULL;
        struct bt_field_type_sequence *sequence;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               goto end;
-       }
-
-       if (type->id != BT_FIELD_TYPE_ID_SEQUENCE) {
-               BT_LOGW("Invalid parameter: field type is not a sequence field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_SEQUENCE, "Field type");
        sequence = container_of(type, struct bt_field_type_sequence,
                parent);
-       ret = sequence->element_type;
-       bt_get(ret);
-end:
-       return ret;
+       return bt_get(sequence->element_type);
 }
 
 BT_HIDDEN
@@ -2857,26 +2548,14 @@ end:
 const char *bt_field_type_sequence_get_length_field_name(
                struct bt_field_type *type)
 {
-       const char *ret = NULL;
        struct bt_field_type_sequence *sequence;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               goto end;
-       }
-
-       if (type->id != BT_FIELD_TYPE_ID_SEQUENCE) {
-               BT_LOGW("Invalid parameter: field type is not a sequence field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_SEQUENCE, "Field type");
        sequence = container_of(type, struct bt_field_type_sequence,
                parent);
-       ret = sequence->length_field_name->str;
-end:
-       return ret;
+       return sequence->length_field_name ?
+               sequence->length_field_name->str : NULL;
 }
 
 struct bt_field_type *bt_field_type_string_create(void)
@@ -2903,25 +2582,12 @@ enum bt_string_encoding bt_field_type_string_get_encoding(
                struct bt_field_type *type)
 {
        struct bt_field_type_string *string;
-       enum bt_string_encoding ret = BT_STRING_ENCODING_UNKNOWN;
-
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               goto end;
-       }
-
-       if (type->id != BT_FIELD_TYPE_ID_STRING) {
-               BT_LOGW("Invalid parameter: field type is not a string field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               goto end;
-       }
 
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_STRING, "Field type");
        string = container_of(type, struct bt_field_type_string,
                parent);
-       ret = string->encoding;
-end:
-       return ret;
+       return string->encoding;
 }
 
 int bt_field_type_string_set_encoding(struct bt_field_type *type,
@@ -2965,11 +2631,7 @@ int bt_field_type_get_alignment(struct bt_field_type *type)
        int ret;
        enum bt_field_type_id type_id;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               ret = -1;
-               goto end;
-       }
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
 
        if (type->frozen) {
                ret = (int) type->alignment;
@@ -3122,10 +2784,7 @@ enum bt_byte_order bt_field_type_get_byte_order(
 {
        enum bt_byte_order ret = BT_BYTE_ORDER_UNKNOWN;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               goto end;
-       }
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
 
        switch (type->id) {
        case BT_FIELD_TYPE_ID_INTEGER:
@@ -3210,11 +2869,7 @@ end:
 enum bt_field_type_id bt_field_type_get_type_id(
                struct bt_field_type *type)
 {
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               return BT_FIELD_TYPE_ID_UNKNOWN;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
        return type->id;
 }
 
@@ -3375,11 +3030,7 @@ struct bt_field_type *bt_field_type_copy(struct bt_field_type *type)
 {
        struct bt_field_type *copy = NULL;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
        copy = type_copy_funcs[type->id](type);
        if (!copy) {
                BT_LOGE_STR("Cannot copy field type.");
@@ -3387,6 +3038,7 @@ struct bt_field_type *bt_field_type_copy(struct bt_field_type *type)
        }
 
        copy->alignment = type->alignment;
+
 end:
        return copy;
 }
@@ -3400,25 +3052,9 @@ int bt_field_type_structure_get_field_name_index(
        GQuark name_quark;
        struct bt_field_type_structure *structure;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (!name) {
-               BT_LOGW_STR("Invalid parameter: field name is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (bt_field_type_get_type_id(type) != BT_FIELD_TYPE_ID_STRUCT) {
-               BT_LOGW("Invalid parameter: field type is not a structure field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               ret = -1;
-               goto end;
-       }
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_NON_NULL(name, "Name");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_STRUCT, "Field type");
 
        name_quark = g_quark_try_string(name);
        if (!name_quark) {
@@ -3454,26 +3090,9 @@ int bt_field_type_variant_get_field_name_index(
        GQuark name_quark;
        struct bt_field_type_variant *variant;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: variant field type is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (!name) {
-               BT_LOGW_STR("Invalid parameter: field name is NULL.");
-               ret = -1;
-               goto end;
-       }
-
-       if (bt_field_type_get_type_id(type) != BT_FIELD_TYPE_ID_VARIANT) {
-               BT_LOGW("Invalid parameter: field type is not a variant field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               ret = -1;
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_NON_NULL(name, "Name");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_VARIANT, "Field type");
        name_quark = g_quark_try_string(name);
        if (!name_quark) {
                BT_LOGV("No such variant field type field name: "
@@ -3501,8 +3120,7 @@ end:
 
 BT_HIDDEN
 int bt_field_type_sequence_set_length_field_path(
-               struct bt_field_type *type,
-               struct bt_field_path *path)
+               struct bt_field_type *type, struct bt_field_path *path)
 {
        int ret = 0;
        struct bt_field_type_sequence *sequence;
@@ -5195,6 +4813,9 @@ int bt_field_type_compare(struct bt_field_type *type_a,
 {
        int ret = 1;
 
+       BT_ASSERT_PRE_NON_NULL(type_a, "Field type A");
+       BT_ASSERT_PRE_NON_NULL(type_b, "Field type B");
+
        if (type_a == type_b) {
                /* Same reference: equal (even if both are NULL) */
                ret = 0;
@@ -5337,49 +4958,23 @@ int bt_field_type_get_field_index(struct bt_field_type *field_type,
 struct bt_field_path *bt_field_type_variant_get_tag_field_path(
                struct bt_field_type *type)
 {
-       struct bt_field_path *field_path = NULL;
        struct bt_field_type_variant *variant;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               goto end;
-       }
-
-       if (!bt_field_type_is_variant(type)) {
-               BT_LOGW("Invalid parameter: field type is not a variant field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_VARIANT, "Field type");
        variant = container_of(type, struct bt_field_type_variant,
                        parent);
-       field_path = bt_get(variant->tag_field_path);
-end:
-       return field_path;
+       return bt_get(variant->tag_field_path);
 }
 
 struct bt_field_path *bt_field_type_sequence_get_length_field_path(
                struct bt_field_type *type)
 {
-       struct bt_field_path *field_path = NULL;
        struct bt_field_type_sequence *sequence;
 
-       if (!type) {
-               BT_LOGW_STR("Invalid parameter: field type is NULL.");
-               goto end;
-       }
-
-       if (!bt_field_type_is_sequence(type)) {
-               BT_LOGW("Invalid parameter: field type is not a sequence field type: "
-                       "addr=%p, ft-id=%s", type,
-                       bt_field_type_id_string(type->id));
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(type, "Field type");
+       BT_ASSERT_PRE_FT_HAS_ID(type, BT_FIELD_TYPE_ID_SEQUENCE, "Field type");
        sequence = container_of(type, struct bt_field_type_sequence,
                        parent);
-       field_path = bt_get(sequence->length_field_path);
-end:
-       return field_path;
+       return bt_get(sequence->length_field_path);
 }
index 3ce610a5f77a80d7a4d3752f381081c3a2c1ed47..9ca8ffb4df7c2c1ef46fbb4876050a785ca2a199 100644 (file)
@@ -49,6 +49,7 @@
 #include <babeltrace/align-internal.h>
 #include <babeltrace/endian-internal.h>
 #include <babeltrace/assert-internal.h>
+#include <babeltrace/assert-pre-internal.h>
 #include <inttypes.h>
 #include <stdint.h>
 #include <stdbool.h>
@@ -133,24 +134,15 @@ error:
 struct bt_trace *bt_stream_class_get_trace(
                struct bt_stream_class *stream_class)
 {
-       return stream_class ?
-               bt_get(bt_stream_class_borrow_trace(stream_class)) :
-               NULL;
+       BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+       return bt_get(bt_stream_class_borrow_trace(stream_class));
 }
 
 const char *bt_stream_class_get_name(
                struct bt_stream_class *stream_class)
 {
-       const char *name = NULL;
-
-       if (!stream_class) {
-               BT_LOGW_STR("Invalid parameter: stream class is NULL.");
-               goto end;
-       }
-
-       name = stream_class->name->len > 0 ? stream_class->name->str : NULL;
-end:
-       return name;
+       BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+       return stream_class->name->len > 0 ? stream_class->name->str : NULL;
 }
 
 int bt_stream_class_set_name(struct bt_stream_class *stream_class,
@@ -259,11 +251,7 @@ int64_t bt_stream_class_get_id(struct bt_stream_class *stream_class)
 {
        int64_t ret;
 
-       if (!stream_class) {
-               BT_LOGW_STR("Invalid parameter: stream class is NULL.");
-               ret = (int64_t) -1;
-               goto end;
-       }
+       BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
 
        if (!stream_class->id_set) {
                BT_LOGV("Stream class's ID is not set: addr=%p, name=\"%s\"",
@@ -274,6 +262,7 @@ int64_t bt_stream_class_get_id(struct bt_stream_class *stream_class)
        }
 
        ret = stream_class->id;
+
 end:
        return ret;
 }
@@ -673,71 +662,31 @@ end:
 struct bt_event_class *bt_stream_class_get_event_class_by_index(
                struct bt_stream_class *stream_class, uint64_t index)
 {
-       struct bt_event_class *event_class = NULL;
-
-       if (!stream_class) {
-               BT_LOGW_STR("Invalid parameter: stream class is NULL.");
-               goto end;
-       }
-
-       if (index >= stream_class->event_classes->len) {
-               BT_LOGW("Invalid parameter: index is out of bounds: "
-                       "addr=%p, name=\"%s\", id=%" PRId64 ", "
-                       "index=%" PRIu64 ", count=%u",
-                       stream_class, bt_stream_class_get_name(stream_class),
-                       bt_stream_class_get_id(stream_class),
-                       index, stream_class->event_classes->len);
-               goto end;
-       }
-
-       event_class = g_ptr_array_index(stream_class->event_classes, index);
-       bt_get(event_class);
-end:
-       return event_class;
+       BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+       BT_ASSERT_PRE(index < stream_class->event_classes->len,
+               "Index is out of bounds: index=%" PRIu64 ", "
+               "count=%u",
+               index, stream_class->event_classes->len);
+       return bt_get(g_ptr_array_index(stream_class->event_classes, index));
 }
 
 struct bt_event_class *bt_stream_class_get_event_class_by_id(
                struct bt_stream_class *stream_class, uint64_t id)
 {
        int64_t id_key = (int64_t) id;
-       struct bt_event_class *event_class = NULL;
 
-       if (!stream_class) {
-               BT_LOGW_STR("Invalid parameter: stream class is NULL.");
-               goto end;
-       }
-
-       if (id_key < 0) {
-               BT_LOGW("Invalid parameter: invalid event class's ID: "
-                       "stream-class-addr=%p, stream-class-name=\"%s\", "
-                       "stream-class-id=%" PRId64 ", event-class-id=%" PRIu64,
-                       stream_class,
-                       bt_stream_class_get_name(stream_class),
-                       bt_stream_class_get_id(stream_class), id);
-               goto end;
-       }
-
-       event_class = g_hash_table_lookup(stream_class->event_classes_ht,
-                       &id_key);
-       bt_get(event_class);
-end:
-       return event_class;
+       BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+       BT_ASSERT_PRE(id_key >= 0,
+               "Invalid event class ID: %" PRIu64, id);
+       return bt_get(g_hash_table_lookup(stream_class->event_classes_ht,
+                       &id_key));
 }
 
 struct bt_field_type *bt_stream_class_get_packet_context_type(
                struct bt_stream_class *stream_class)
 {
-       struct bt_field_type *ret = NULL;
-
-       if (!stream_class) {
-               BT_LOGW_STR("Invalid parameter: stream class is NULL.");
-               goto end;
-       }
-
-       bt_get(stream_class->packet_context_type);
-       ret = stream_class->packet_context_type;
-end:
-       return ret;
+       BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+       return bt_get(stream_class->packet_context_type);
 }
 
 int bt_stream_class_set_packet_context_type(
@@ -796,10 +745,7 @@ struct bt_field_type *bt_stream_class_get_event_header_type(
 {
        struct bt_field_type *ret = NULL;
 
-       if (!stream_class) {
-               BT_LOGW_STR("Invalid parameter: stream class is NULL.");
-               goto end;
-       }
+       BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
 
        if (!stream_class->event_header_type) {
                BT_LOGV("Stream class has no event header field type: "
@@ -809,8 +755,8 @@ struct bt_field_type *bt_stream_class_get_event_header_type(
                goto end;
        }
 
-       bt_get(stream_class->event_header_type);
-       ret = stream_class->event_header_type;
+       ret = bt_get(stream_class->event_header_type);
+
 end:
        return ret;
 }
@@ -869,17 +815,14 @@ struct bt_field_type *bt_stream_class_get_event_context_type(
 {
        struct bt_field_type *ret = NULL;
 
-       if (!stream_class) {
-               BT_LOGW_STR("Invalid parameter: stream class is NULL.");
-               goto end;
-       }
+       BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
 
        if (!stream_class->event_context_type) {
                goto end;
        }
 
-       bt_get(stream_class->event_context_type);
-       ret = stream_class->event_context_type;
+       ret = bt_get(stream_class->event_context_type);
+
 end:
        return ret;
 }
index c5c1f19a0777d48c05a599d89beb89b893bc78b2..4c6bda2653166a2044de3ecce530083472f85efc 100644 (file)
@@ -48,6 +48,7 @@
 #include <babeltrace/compiler-internal.h>
 #include <babeltrace/align-internal.h>
 #include <babeltrace/assert-internal.h>
+#include <babeltrace/assert-pre-internal.h>
 #include <inttypes.h>
 #include <unistd.h>
 
@@ -1210,17 +1211,8 @@ struct bt_stream *bt_stream_create(
 struct bt_stream_class *bt_stream_get_class(
                struct bt_stream *stream)
 {
-       struct bt_stream_class *stream_class = NULL;
-
-       if (!stream) {
-               BT_LOGW_STR("Invalid parameter: stream is NULL.");
-               goto end;
-       }
-
-       stream_class = stream->stream_class;
-       bt_get(stream_class);
-end:
-       return stream_class;
+       BT_ASSERT_PRE_NON_NULL(stream, "Stream");
+       return bt_get(stream->stream_class);
 }
 
 int bt_stream_get_discarded_events_count(
@@ -2075,17 +2067,8 @@ int try_set_structure_field_integer(struct bt_field *structure, char *name,
 
 const char *bt_stream_get_name(struct bt_stream *stream)
 {
-       const char *name = NULL;
-
-       if (!stream) {
-               BT_LOGW_STR("Invalid parameter: stream is NULL.");
-               goto end;
-       }
-
-       name = stream->name ? stream->name->str : NULL;
-
-end:
-       return name;
+       BT_ASSERT_PRE_NON_NULL(stream, "Stream");
+       return stream->name ? stream->name->str : NULL;
 }
 
 int bt_stream_is_writer(struct bt_stream *stream)
@@ -2148,18 +2131,12 @@ int64_t bt_stream_get_id(struct bt_stream *stream)
 {
        int64_t ret;
 
-       if (!stream) {
-               BT_LOGW_STR("Invalid parameter: stream is NULL.");
-               ret = (int64_t) -1;
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(stream, "Stream");
        ret = stream->id;
        if (ret < 0) {
                BT_LOGV("Stream's ID is not set: addr=%p, name=\"%s\"",
                        stream, bt_stream_get_name(stream));
        }
 
-end:
        return ret;
 }
index 1b1e5f82a3bfc0207d9deb89b526a8ca8a138dc7..bc754f5dab762074f98662ad2b34f1d1b8000653 100644 (file)
@@ -51,6 +51,7 @@
 #include <babeltrace/types.h>
 #include <babeltrace/endian-internal.h>
 #include <babeltrace/assert-internal.h>
+#include <babeltrace/assert-pre-internal.h>
 #include <inttypes.h>
 #include <stdint.h>
 #include <string.h>
@@ -158,20 +159,8 @@ error:
 
 const char *bt_trace_get_name(struct bt_trace *trace)
 {
-       const char *name = NULL;
-
-       if (!trace) {
-               BT_LOGW_STR("Invalid parameter: trace is NULL.");
-               goto end;
-       }
-
-       if (!trace->name) {
-               goto end;
-       }
-
-       name = trace->name->str;
-end:
-       return name;
+       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+       return trace->name ? trace->name->str : NULL;
 }
 
 int bt_trace_set_name(struct bt_trace *trace, const char *name)
@@ -214,7 +203,8 @@ end:
 
 const unsigned char *bt_trace_get_uuid(struct bt_trace *trace)
 {
-       return trace && trace->uuid_set ? trace->uuid : NULL;
+       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+       return trace->uuid_set ? trace->uuid : NULL;
 }
 
 int bt_trace_set_uuid(struct bt_trace *trace, const unsigned char *uuid)
@@ -473,18 +463,11 @@ end:
 
 int64_t bt_trace_get_environment_field_count(struct bt_trace *trace)
 {
-       int64_t ret = 0;
-
-       if (!trace) {
-               BT_LOGW_STR("Invalid parameter: trace is NULL.");
-               ret = (int64_t) -1;
-               goto end;
-       }
+       int64_t ret;
 
+       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
        ret = bt_attributes_get_count(trace->environment);
        BT_ASSERT(ret >= 0);
-
-end:
        return ret;
 }
 
@@ -492,55 +475,24 @@ const char *
 bt_trace_get_environment_field_name_by_index(struct bt_trace *trace,
                uint64_t index)
 {
-       const char *ret = NULL;
-
-       if (!trace) {
-               BT_LOGW_STR("Invalid parameter: trace is NULL.");
-               goto end;
-       }
-
-       ret = bt_attributes_get_field_name(trace->environment, index);
-
-end:
-       return ret;
+       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+       return bt_attributes_get_field_name(trace->environment, index);
 }
 
 struct bt_value *bt_trace_get_environment_field_value_by_index(
                struct bt_trace *trace, uint64_t index)
 {
-       struct bt_value *ret = NULL;
-
-       if (!trace) {
-               BT_LOGW_STR("Invalid parameter: trace is NULL.");
-               goto end;
-       }
-
-       ret = bt_attributes_get_field_value(trace->environment, index);
-
-end:
-       return ret;
+       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+       return bt_attributes_get_field_value(trace->environment, index);
 }
 
 struct bt_value *bt_trace_get_environment_field_value_by_name(
                struct bt_trace *trace, const char *name)
 {
-       struct bt_value *ret = NULL;
-
-       if (!trace) {
-               BT_LOGW_STR("Invalid parameter: trace is NULL.");
-               goto end;
-       }
-
-       if (!name) {
-               BT_LOGW_STR("Invalid parameter: name is NULL.");
-               goto end;
-       }
-
-       ret = bt_attributes_get_field_value_by_name(trace->environment,
+       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+       BT_ASSERT_PRE_NON_NULL(name, "Name");
+       return bt_attributes_get_field_value_by_name(trace->environment,
                name);
-
-end:
-       return ret;
 }
 
 int bt_trace_add_clock_class(struct bt_trace *trace,
@@ -603,41 +555,19 @@ end:
 
 int64_t bt_trace_get_clock_class_count(struct bt_trace *trace)
 {
-       int64_t ret = (int64_t) -1;
-
-       if (!trace) {
-               BT_LOGW_STR("Invalid parameter: trace is NULL.");
-               goto end;
-       }
-
-       ret = trace->clocks->len;
-end:
-       return ret;
+       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+       return trace->clocks->len;
 }
 
 struct bt_clock_class *bt_trace_get_clock_class_by_index(
                struct bt_trace *trace, uint64_t index)
 {
-       struct bt_clock_class *clock_class = NULL;
-
-       if (!trace) {
-               BT_LOGW_STR("Invalid parameter: trace is NULL.");
-               goto end;
-       }
-
-       if (index >= trace->clocks->len) {
-               BT_LOGW("Invalid parameter: index is out of bounds: "
-                       "addr=%p, name=\"%s\", "
-                       "index=%" PRIu64 ", count=%u",
-                       trace, bt_trace_get_name(trace),
-                       index, trace->clocks->len);
-               goto end;
-       }
-
-       clock_class = g_ptr_array_index(trace->clocks, index);
-       bt_get(clock_class);
-end:
-       return clock_class;
+       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+       BT_ASSERT_PRE(index < trace->clocks->len,
+               "Index is out of bounds: index=%" PRIu64 ", "
+               "count=%u",
+               index, trace->clocks->len);
+       return bt_get(g_ptr_array_index(trace->clocks, index));
 }
 
 static
@@ -1605,84 +1535,37 @@ end:
 
 int64_t bt_trace_get_stream_count(struct bt_trace *trace)
 {
-       int64_t ret;
-
-       if (!trace) {
-               BT_LOGW_STR("Invalid parameter: trace is NULL.");
-               ret = (int64_t) -1;
-               goto end;
-       }
-
-       ret = (int64_t) trace->streams->len;
-
-end:
-       return ret;
+       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+       return (int64_t) trace->streams->len;
 }
 
 struct bt_stream *bt_trace_get_stream_by_index(
                struct bt_trace *trace,
                uint64_t index)
 {
-       struct bt_stream *stream = NULL;
-
-       if (!trace) {
-               BT_LOGW_STR("Invalid parameter: trace is NULL.");
-               goto end;
-       }
-
-       if (index >= trace->streams->len) {
-               BT_LOGW("Invalid parameter: index is out of bounds: "
-                       "addr=%p, name=\"%s\", "
-                       "index=%" PRIu64 ", count=%u",
-                       trace, bt_trace_get_name(trace),
-                       index, trace->streams->len);
-               goto end;
-       }
-
-       stream = bt_get(g_ptr_array_index(trace->streams, index));
-
-end:
-       return stream;
+       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+       BT_ASSERT_PRE(index < trace->streams->len,
+               "Index is out of bounds: index=%" PRIu64 ", "
+               "count=%u",
+               index, trace->streams->len);
+       return bt_get(g_ptr_array_index(trace->streams, index));
 }
 
 int64_t bt_trace_get_stream_class_count(struct bt_trace *trace)
 {
-       int64_t ret;
-
-       if (!trace) {
-               BT_LOGW_STR("Invalid parameter: trace is NULL.");
-               ret = (int64_t) -1;
-               goto end;
-       }
-
-       ret = (int64_t) trace->stream_classes->len;
-end:
-       return ret;
+       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+       return (int64_t) trace->stream_classes->len;
 }
 
 struct bt_stream_class *bt_trace_get_stream_class_by_index(
                struct bt_trace *trace, uint64_t index)
 {
-       struct bt_stream_class *stream_class = NULL;
-
-       if (!trace) {
-               BT_LOGW_STR("Invalid parameter: trace is NULL.");
-               goto end;
-       }
-
-       if (index >= trace->stream_classes->len) {
-               BT_LOGW("Invalid parameter: index is out of bounds: "
-                       "addr=%p, name=\"%s\", "
-                       "index=%" PRIu64 ", count=%u",
-                       trace, bt_trace_get_name(trace),
-                       index, trace->stream_classes->len);
-               goto end;
-       }
-
-       stream_class = g_ptr_array_index(trace->stream_classes, index);
-       bt_get(stream_class);
-end:
-       return stream_class;
+       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+       BT_ASSERT_PRE(index < trace->stream_classes->len,
+               "Index is out of bounds: index=%" PRIu64 ", "
+               "count=%u",
+               index, trace->stream_classes->len);
+       return bt_get(g_ptr_array_index(trace->stream_classes, index));
 }
 
 struct bt_stream_class *bt_trace_get_stream_class_by_id(
@@ -1692,17 +1575,9 @@ struct bt_stream_class *bt_trace_get_stream_class_by_id(
        struct bt_stream_class *stream_class = NULL;
        int64_t id = (int64_t) id_param;
 
-       if (!trace) {
-               BT_LOGW_STR("Invalid parameter: trace is NULL.");
-               goto end;
-       }
-
-       if (id < 0) {
-               BT_LOGW("Invalid parameter: invalid stream class's ID: "
-                       "trace-addr=%p, trace-name=\"%s\", id=%" PRIu64,
-                       trace, bt_trace_get_name(trace), id_param);
-               goto end;
-       }
+       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+       BT_ASSERT_PRE(id >= 0,
+               "Invalid stream class ID: %" PRIu64, id_param);
 
        for (i = 0; i < trace->stream_classes->len; i++) {
                struct bt_stream_class *stream_class_candidate;
@@ -1728,15 +1603,8 @@ struct bt_clock_class *bt_trace_get_clock_class_by_name(
        size_t i;
        struct bt_clock_class *clock_class = NULL;
 
-       if (!trace) {
-               BT_LOGW_STR("Invalid parameter: trace is NULL.");
-               goto end;
-       }
-
-       if (!name) {
-               BT_LOGW_STR("Invalid parameter: name is NULL.");
-               goto end;
-       }
+       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+       BT_ASSERT_PRE_NON_NULL(name, "Name");
 
        for (i = 0; i < trace->clocks->len; i++) {
                struct bt_clock_class *cur_clk =
@@ -1972,17 +1840,8 @@ end:
 enum bt_byte_order bt_trace_get_native_byte_order(
                struct bt_trace *trace)
 {
-       enum bt_byte_order ret = BT_BYTE_ORDER_UNKNOWN;
-
-       if (!trace) {
-               BT_LOGW_STR("Invalid parameter: trace is NULL.");
-               goto end;
-       }
-
-       ret = trace->native_byte_order;
-
-end:
-       return ret;
+       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+       return trace->native_byte_order;
 }
 
 int bt_trace_set_native_byte_order(struct bt_trace *trace,
@@ -2037,17 +1896,8 @@ end:
 struct bt_field_type *bt_trace_get_packet_header_type(
                struct bt_trace *trace)
 {
-       struct bt_field_type *field_type = NULL;
-
-       if (!trace) {
-               BT_LOGW_STR("Invalid parameter: trace is NULL.");
-               goto end;
-       }
-
-       bt_get(trace->packet_header_type);
-       field_type = trace->packet_header_type;
-end:
-       return field_type;
+       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+       return bt_get(trace->packet_header_type);
 }
 
 int bt_trace_set_packet_header_type(struct bt_trace *trace,
@@ -2259,17 +2109,8 @@ void bt_trace_freeze(struct bt_trace *trace)
 
 bt_bool bt_trace_is_static(struct bt_trace *trace)
 {
-       bt_bool is_static = BT_FALSE;
-
-       if (!trace) {
-               BT_LOGW_STR("Invalid parameter: trace is NULL.");
-               goto end;
-       }
-
-       is_static = trace->is_static;
-
-end:
-       return is_static;
+       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+       return trace->is_static;
 }
 
 int bt_trace_set_is_static(struct bt_trace *trace)
index 68961b1d9cbabfc5b3be340994a9425bb7ccbda5..1653cd6184bfe25600095e324ee2a24a00db952d 100644 (file)
@@ -59,7 +59,7 @@
 #define DEFAULT_CLOCK_TIME 0
 #define DEFAULT_CLOCK_VALUE 0
 
-#define NR_TESTS 552
+#define NR_TESTS 476
 
 struct bt_utsname {
        char sysname[BABELTRACE_HOST_NAME_MAX];
@@ -196,14 +196,11 @@ void append_simple_event(struct bt_stream_class *stream_class,
 
        returned_type = bt_field_type_enumeration_get_container_type(enum_type);
        ok(returned_type == int_64_type, "bt_field_type_enumeration_get_container_type returns the right type");
-       ok(!bt_field_type_enumeration_get_container_type(NULL), "bt_field_type_enumeration_get_container_type handles NULL correctly");
        ok(!bt_field_type_enumeration_create(enum_type),
                "bt_field_enumeration_type_create rejects non-integer container field types");
        bt_put(returned_type);
 
        bt_field_type_set_alignment(float_type, 32);
-       ok(bt_field_type_get_alignment(NULL) < 0,
-               "bt_field_type_get_alignment handles NULL correctly");
        ok(bt_field_type_get_alignment(float_type) == 32,
                "bt_field_type_get_alignment returns a correct value");
 
@@ -212,10 +209,6 @@ void append_simple_event(struct bt_stream_class *stream_class,
        ok(bt_field_type_floating_point_set_mantissa_digits(float_type, 53) == 0,
                "Set a floating point type's mantissa digit count");
 
-       ok(bt_field_type_floating_point_get_exponent_digits(NULL) < 0,
-               "bt_field_type_floating_point_get_exponent_digits handles NULL properly");
-       ok(bt_field_type_floating_point_get_mantissa_digits(NULL) < 0,
-               "bt_field_type_floating_point_get_mantissa_digits handles NULL properly");
        ok(bt_field_type_floating_point_get_exponent_digits(float_type) == 11,
                "bt_field_type_floating_point_get_exponent_digits returns the correct value");
        ok(bt_field_type_floating_point_get_mantissa_digits(float_type) == 53,
@@ -243,9 +236,6 @@ void append_simple_event(struct bt_stream_class *stream_class,
                -54, -55), "bt_field_type_enumeration_add_mapping rejects mapping where end < start");
        bt_ctf_field_type_enumeration_add_mapping(enum_type, "another entry", -42000, -13000);
 
-       iter = bt_field_type_enumeration_find_mappings_by_signed_value(NULL, -42);
-       ok(iter == NULL, "bt_field_type_enumeration_find_mappings_by_signed_value handles a NULL field type correctly");
-
        iter = bt_field_type_enumeration_find_mappings_by_signed_value(enum_type, -4200000);
        ret = bt_field_type_enumeration_mapping_iterator_next(iter);
        ok(iter && ret, "bt_field_type_enumeration_find_mappings_by_signed_value rejects non-mapped values");
@@ -261,9 +251,6 @@ void append_simple_event(struct bt_stream_class *stream_class,
        ok(bt_event_class_add_field(simple_event_class, enum_type,
                "enum_field") == 0, "Add signed enumeration field to event");
 
-       ok(bt_field_type_enumeration_get_mapping_signed(NULL, 0, &ret_char,
-               &ret_range_start_int64_t, &ret_range_end_int64_t) < 0,
-               "bt_field_type_enumeration_get_mapping_signed handles a NULL enumeration correctly");
        ok(bt_field_type_enumeration_get_mapping_signed(enum_type, 0, NULL,
                &ret_range_start_int64_t, &ret_range_end_int64_t) == 0,
                "bt_field_type_enumeration_get_mapping_signed handles a NULL string correctly");
@@ -304,14 +291,9 @@ void append_simple_event(struct bt_stream_class *stream_class,
        ok(bt_event_class_add_field(simple_event_class, enum_type_unsigned,
                "enum_field_unsigned") == 0, "Add unsigned enumeration field to event");
 
-       ok(bt_field_type_enumeration_get_mapping_count(NULL) < 0,
-               "bt_field_type_enumeration_get_mapping_count handles NULL correctly");
        ok(bt_field_type_enumeration_get_mapping_count(enum_type_unsigned) == 6,
                "bt_field_type_enumeration_get_mapping_count returns the correct value");
 
-       ok(bt_field_type_enumeration_get_mapping_unsigned(NULL, 0, &ret_char,
-               &ret_range_start_uint64_t, &ret_range_end_uint64_t) < 0,
-               "bt_field_type_enumeration_get_mapping_unsigned handles a NULL enumeration correctly");
        ok(bt_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned, 0, NULL,
                &ret_range_start_uint64_t, &ret_range_end_uint64_t) == 0,
                "bt_field_type_enumeration_get_mapping_unsigned handles a NULL string correctly");
@@ -342,8 +324,6 @@ void append_simple_event(struct bt_stream_class *stream_class,
        ok(!bt_field_type_structure_add_field(event_context_type, uint_12_type,
                "event_specific_context"),
                "Add event specific context field");
-       ok(bt_event_class_get_context_type(NULL) == NULL,
-               "bt_event_class_get_context_type handles NULL correctly");
 
        ok(bt_event_class_set_context_type(NULL, event_context_type) < 0,
                "bt_event_class_set_context_type handles a NULL event class correctly");
@@ -383,20 +363,12 @@ void append_simple_event(struct bt_stream_class *stream_class,
                        event_payload_type, "enum_field_unsigned");
        assert(ep_enum_field_unsigned_type);
 
-       ok(bt_stream_class_get_event_class_count(NULL) < 0,
-               "bt_stream_class_get_event_class_count handles NULL correctly");
        ok(bt_stream_class_get_event_class_count(stream_class) == 1,
                "bt_stream_class_get_event_class_count returns a correct number of event classes");
-       ok(bt_stream_class_get_event_class_by_index(NULL, 0) == NULL,
-               "bt_stream_class_get_event_class handles NULL correctly");
-       ok(bt_stream_class_get_event_class_by_index(stream_class, 8724) == NULL,
-               "bt_stream_class_get_event_class handles invalid indexes correctly");
        ret_event_class = bt_stream_class_get_event_class_by_index(stream_class, 0);
        ok(ret_event_class == simple_event_class,
                "bt_stream_class_get_event_class returns the correct event class");
        bt_put(ret_event_class);
-       ok(!bt_stream_class_get_event_class_by_id(NULL, 0),
-               "bt_stream_class_get_event_class_by_id handles NULL correctly");
        ok(!bt_stream_class_get_event_class_by_id(stream_class, 2),
                "bt_stream_class_get_event_class_by_id returns NULL when the requested ID doesn't exist");
        ret_event_class =
@@ -601,16 +573,12 @@ void append_complex_event(struct bt_stream_class *stream_class,
        sequence_type = bt_field_type_sequence_create(int_16_type,
                "seq_len");
 
-       ok(bt_field_type_array_get_element_type(NULL) == NULL,
-               "bt_field_type_array_get_element_type handles NULL correctly");
        ret_field_type = bt_field_type_array_get_element_type(
                array_type);
        ok(ret_field_type == int_16_type,
                "bt_field_type_array_get_element_type returns the correct type");
        bt_put(ret_field_type);
 
-       ok(bt_field_type_array_get_length(NULL) < 0,
-               "bt_field_type_array_get_length handles NULL correctly");
        ok(bt_field_type_array_get_length(array_type) == ARRAY_TEST_LENGTH,
                "bt_field_type_array_get_length returns the correct length");
 
@@ -630,9 +598,6 @@ void append_complex_event(struct bt_stream_class *stream_class,
        bt_ctf_field_type_enumeration_add_mapping(enum_variant_type,
                "UINT35_TYPE", 2, 7);
 
-       iter = bt_field_type_enumeration_find_mappings_by_name(NULL, "INT16_TYPE");
-       ok(iter == NULL, "bt_field_type_enumeration_find_mappings_by_name handles a NULL field type correctly");
-
        iter = bt_field_type_enumeration_find_mappings_by_name(enum_variant_type, "INT16_TYPE");
        ok(iter != NULL, "bt_field_type_enumeration_find_mappings_by_name returns a non-NULL iterator");
        ret = bt_field_type_enumeration_mapping_iterator_next(iter);
@@ -641,26 +606,14 @@ void append_complex_event(struct bt_stream_class *stream_class,
                "bt_field_type_enumeration_mapping_iterator_get_unsigned handles mapped values correctly");
        BT_PUT(iter);
 
-       iter = bt_field_type_enumeration_find_mappings_by_name(enum_variant_type, NULL);
-       ret = bt_field_type_enumeration_mapping_iterator_next(iter);
-       ok(iter && ret, "bt_field_type_enumeration_find_mappings_by_name handles a NULL name correctly");
-       BT_PUT(iter);
-
-       iter = bt_field_type_enumeration_find_mappings_by_unsigned_value(NULL, 1);
-       ok(iter == NULL, "bt_field_type_enumeration_find_mappings_by_unsigned_value handles a NULL field type correctly");
-
        iter = bt_field_type_enumeration_find_mappings_by_unsigned_value(enum_variant_type, -42);
        ret = bt_field_type_enumeration_mapping_iterator_next(iter);
        ok(iter && ret, "bt_field_type_enumeration_find_mappings_by_unsigned_value handles invalid values correctly");
-       ok(bt_field_type_enumeration_mapping_iterator_get_unsigned(iter, NULL, NULL, NULL) != 0,
-               "bt_field_type_enumeration_mapping_iterator_get_unsigned handles invalid values correctly");
        BT_PUT(iter);
 
        iter = bt_field_type_enumeration_find_mappings_by_unsigned_value(enum_variant_type, 5);
        ret = bt_field_type_enumeration_mapping_iterator_next(iter);
        ok(iter != NULL && !ret, "bt_field_type_enumeration_find_mappings_by_unsigned_value handles valid values correctly");
-       ok(bt_field_type_enumeration_mapping_iterator_get_unsigned(iter, NULL, NULL, NULL) == 0,
-               "bt_field_type_enumeration_mapping_iterator_get_unsigned handles valid values correctly");
        BT_PUT(iter);
 
        ok(bt_field_type_variant_add_field(variant_type, uint_3_type,
@@ -672,44 +625,28 @@ void append_complex_event(struct bt_stream_class *stream_class,
        ok(!bt_field_type_variant_add_field(variant_type, uint_35_type,
                "UINT35_TYPE"), "Add UINT35_TYPE field to variant");
 
-       ok(bt_field_type_variant_get_tag_type(NULL) == NULL,
-               "bt_field_type_variant_get_tag_type handles NULL correctly");
        ret_field_type = bt_field_type_variant_get_tag_type(variant_type);
        ok(ret_field_type == enum_variant_type,
                "bt_field_type_variant_get_tag_type returns a correct tag type");
        bt_put(ret_field_type);
 
-       ok(bt_field_type_variant_get_tag_name(NULL) == NULL,
-               "bt_field_type_variant_get_tag_name handles NULL correctly");
        ret_string = bt_field_type_variant_get_tag_name(variant_type);
        ok(ret_string ? !strcmp(ret_string, "variant_selector") : 0,
                "bt_field_type_variant_get_tag_name returns the correct variant tag name");
-       ok(bt_field_type_variant_get_field_type_by_name(NULL,
-               "INT16_TYPE") == NULL,
-               "bt_field_type_variant_get_field_type_by_name handles a NULL variant_type correctly");
-       ok(bt_field_type_variant_get_field_type_by_name(variant_type,
-               NULL) == NULL,
-               "bt_field_type_variant_get_field_type_by_name handles a NULL field name correctly");
        ret_field_type = bt_field_type_variant_get_field_type_by_name(
                variant_type, "INT16_TYPE");
        ok(ret_field_type == int_16_type,
                "bt_field_type_variant_get_field_type_by_name returns a correct field type");
        bt_put(ret_field_type);
 
-       ok(bt_field_type_variant_get_field_count(NULL) < 0,
-               "bt_field_type_variant_get_field_count handles NULL correctly");
        ok(bt_field_type_variant_get_field_count(variant_type) == 3,
                "bt_field_type_variant_get_field_count returns the correct count");
 
-       ok(bt_field_type_variant_get_field_by_index(NULL, &ret_string, &ret_field_type, 0) < 0,
-               "bt_field_type_variant_get_field handles a NULL type correctly");
        ok(bt_field_type_variant_get_field_by_index(variant_type, NULL, &ret_field_type, 0) == 0,
                "bt_field_type_variant_get_field handles a NULL field name correctly");
        bt_put(ret_field_type);
        ok(bt_field_type_variant_get_field_by_index(variant_type, &ret_string, NULL, 0) == 0,
                "bt_field_type_variant_get_field handles a NULL field type correctly");
-       ok(bt_field_type_variant_get_field_by_index(variant_type, &ret_string, &ret_field_type, 200) < 0,
-               "bt_field_type_variant_get_field handles an invalid index correctly");
        ok(bt_field_type_variant_get_field_by_index(variant_type, &ret_string, &ret_field_type, 1) == 0,
                "bt_field_type_variant_get_field returns a field");
        ok(!strcmp("INT16_TYPE", ret_string),
@@ -748,15 +685,11 @@ void append_complex_event(struct bt_stream_class *stream_class,
                "complex_structure") == 0,
                "Add composite structure to an event");
 
-       ok(bt_event_class_get_name(NULL) == NULL,
-               "bt_event_class_get_name handles NULL correctly");
        ret_string = bt_event_class_get_name(event_class);
        ok(!strcmp(ret_string, complex_test_event_string),
                "bt_event_class_get_name returns a correct name");
        ok(bt_event_class_get_id(event_class) < 0,
                "bt_event_class_get_id returns a negative value when not set");
-       ok(bt_event_class_get_id(NULL) < 0,
-               "bt_event_class_get_id handles NULL correctly");
        ok(bt_event_class_set_id(NULL, 42) < 0,
                "bt_event_class_set_id handles NULL correctly");
        ok(bt_event_class_set_id(event_class, 42) == 0,
@@ -775,16 +708,12 @@ void append_complex_event(struct bt_stream_class *stream_class,
                "bt_event_class_set_log_level handles an unknown log level correctly");
        ok(!bt_event_class_set_log_level(event_class, BT_EVENT_CLASS_LOG_LEVEL_INFO),
                "bt_event_class_set_log_level succeeds with a valid log level");
-       ok(bt_event_class_get_log_level(NULL) == BT_EVENT_CLASS_LOG_LEVEL_UNKNOWN,
-               "bt_event_class_get_log_level handles a NULL event class correctly");
        ok(bt_event_class_get_log_level(event_class) == BT_EVENT_CLASS_LOG_LEVEL_INFO,
                "bt_event_class_get_log_level returns the expected log level");
        ok(bt_event_class_set_emf_uri(NULL, "http://diamon.org/babeltrace/"),
                "bt_event_class_set_emf_uri handles a NULL event class correctly");
        ok(!bt_event_class_set_emf_uri(event_class, "http://diamon.org/babeltrace/"),
                "bt_event_class_set_emf_uri succeeds with a valid EMF URI");
-       ok(!bt_event_class_get_emf_uri(NULL),
-               "bt_event_class_get_emf_uri handles a NULL event class correctly");
        ok(strcmp(bt_event_class_get_emf_uri(event_class), "http://diamon.org/babeltrace/") == 0,
                "bt_event_class_get_emf_uri returns the expected EMF URI");
        ok(!bt_event_class_set_emf_uri(event_class, NULL),
@@ -798,31 +727,17 @@ void append_complex_event(struct bt_stream_class *stream_class,
        ok(bt_stream_class_add_event_class(stream_class,
                event_class) == 0, "Add an event class to stream class");
 
-       ok(bt_event_class_get_stream_class(NULL) == NULL,
-               "bt_event_class_get_stream_class handles NULL correctly");
        ret_stream_class = bt_event_class_get_stream_class(event_class);
        ok(ret_stream_class == stream_class,
                "bt_event_class_get_stream_class returns the correct stream class");
        bt_put(ret_stream_class);
 
-       ok(bt_event_class_get_payload_type_field_count(NULL) < 0,
-               "bt_event_class_get_field_count handles NULL correctly");
        ok(bt_event_class_get_payload_type_field_count(event_class) == 3,
                "bt_event_class_get_field_count returns a correct value");
 
-       ok(bt_event_class_get_payload_type_field_by_index(NULL, &ret_string,
-               &ret_field_type, 0) < 0,
-               "bt_event_class_get_field handles a NULL event class correctly");
-       ok(bt_event_class_get_payload_type_field_by_index(event_class, NULL,
-               &ret_field_type, 0) == 0,
-               "bt_event_class_get_field handles a NULL field name correctly");
-       bt_put(ret_field_type);
        ok(bt_event_class_get_payload_type_field_by_index(event_class, &ret_string,
                NULL, 0) == 0,
                "bt_event_class_get_field handles a NULL field type correctly");
-       ok(bt_event_class_get_payload_type_field_by_index(event_class, &ret_string,
-               &ret_field_type, 42) < 0,
-               "bt_event_class_get_field handles an invalid index correctly");
        ok(bt_event_class_get_payload_type_field_by_index(event_class, &ret_string,
                &ret_field_type, 0) == 0,
                "bt_event_class_get_field returns a field");
@@ -831,10 +746,6 @@ void append_complex_event(struct bt_stream_class *stream_class,
        bt_put(ret_field_type);
        ok(!strcmp(ret_string, "uint_35"),
                "bt_event_class_get_field returns a correct field name");
-       ok(bt_ctf_event_class_get_field_by_name(NULL, "") == NULL,
-               "bt_event_class_get_field_by_name handles a NULL event class correctly");
-       ok(bt_ctf_event_class_get_field_by_name(event_class, NULL) == NULL,
-               "bt_event_class_get_field_by_name handles a NULL field name correctly");
        ok(bt_ctf_event_class_get_field_by_name(event_class, "truie") == NULL,
                "bt_event_class_get_field_by_name handles an invalid field name correctly");
        ret_field_type = bt_ctf_event_class_get_field_by_name(event_class,
@@ -1564,12 +1475,8 @@ void type_field_tests()
                "Set integer type signedness to signed");
        ok(bt_ctf_field_type_integer_set_signed(uint_12_type, 0) == 0,
                "Set integer type signedness to unsigned");
-       ok(bt_field_type_integer_get_size(NULL) < 0,
-               "bt_field_type_integer_get_size handles NULL correctly");
        ok(bt_field_type_integer_get_size(uint_12_type) == 12,
                "bt_field_type_integer_get_size returns a correct value");
-       ok(bt_ctf_field_type_integer_get_signed(NULL) < 0,
-               "bt_field_type_integer_get_signed handles NULL correctly");
        ok(bt_ctf_field_type_integer_get_signed(uint_12_type) == 0,
                "bt_field_type_integer_get_signed returns a correct value for unsigned types");
 
@@ -1588,20 +1495,11 @@ void type_field_tests()
        ok(bt_field_type_get_byte_order(uint_12_type) ==
                BT_BYTE_ORDER_BIG_ENDIAN,
                "bt_field_type_get_byte_order returns a correct value");
-       ok(bt_field_type_get_byte_order(NULL) ==
-               BT_BYTE_ORDER_UNKNOWN,
-               "bt_field_type_get_byte_order handles NULL correctly");
 
-       ok(bt_field_type_get_type_id(NULL) ==
-               BT_FIELD_TYPE_ID_UNKNOWN,
-               "bt_field_type_get_type_id handles NULL correctly");
        ok(bt_field_type_get_type_id(uint_12_type) ==
                BT_FIELD_TYPE_ID_INTEGER,
                "bt_field_type_get_type_id returns a correct value with an integer type");
 
-       ok(bt_field_type_integer_get_base(NULL) ==
-               BT_INTEGER_BASE_UNKNOWN,
-               "bt_field_type_integer_get_base handles NULL correctly");
        ok(bt_field_type_integer_get_base(uint_12_type) ==
                BT_INTEGER_BASE_HEXADECIMAL,
                "bt_field_type_integer_get_base returns a correct value");
@@ -1615,9 +1513,6 @@ void type_field_tests()
        ok(bt_field_type_integer_set_encoding(uint_12_type,
                BT_STRING_ENCODING_UTF8) == 0,
                "Set integer type encoding to UTF8");
-       ok(bt_field_type_integer_get_encoding(NULL) ==
-               BT_STRING_ENCODING_UNKNOWN,
-               "bt_field_type_integer_get_encoding handles NULL correctly");
        ok(bt_field_type_integer_get_encoding(uint_12_type) ==
                BT_STRING_ENCODING_UTF8,
                "bt_field_type_integer_get_encoding returns a correct value");
@@ -1636,14 +1531,10 @@ void type_field_tests()
                BT_FIELD_TYPE_ID_SEQUENCE,
                "bt_field_type_get_type_id returns a correct value with a sequence type");
 
-       ok(bt_field_type_sequence_get_length_field_name(NULL) == NULL,
-               "bt_field_type_sequence_get_length_field_name handles NULL correctly");
        ret_string = bt_field_type_sequence_get_length_field_name(
                sequence_type);
        ok(!strcmp(ret_string, "seq_len"),
                "bt_field_type_sequence_get_length_field_name returns the correct value");
-       ok(bt_field_type_sequence_get_element_type(NULL) == NULL,
-               "bt_field_type_sequence_get_element_type handles NULL correctly");
        returned_type = bt_field_type_sequence_get_element_type(
                sequence_type);
        ok(returned_type == int_16_type,
@@ -1662,9 +1553,6 @@ void type_field_tests()
                BT_STRING_ENCODING_ASCII) == 0,
                "Set string encoding to ASCII");
 
-       ok(bt_field_type_string_get_encoding(NULL) ==
-               BT_STRING_ENCODING_UNKNOWN,
-               "bt_field_type_string_get_encoding handles NULL correctly");
        ok(bt_field_type_string_get_encoding(string_type) ==
                BT_STRING_ENCODING_ASCII,
                "bt_field_type_string_get_encoding returns the correct value");
@@ -1681,14 +1569,9 @@ void type_field_tests()
                sequence_type, "a_sequence") == 0,
                "Add a sequence type to a structure");
 
-       ok(bt_field_type_structure_get_field_count(NULL) < 0,
-               "bt_field_type_structure_get_field_count handles NULL correctly");
        ok(bt_field_type_structure_get_field_count(structure_seq_type) == 2,
                "bt_field_type_structure_get_field_count returns a correct value");
 
-       ok(bt_ctf_field_type_structure_get_field(NULL,
-               &ret_string, &returned_type, 1) < 0,
-               "bt_field_type_structure_get_field handles a NULL type correctly");
        ok(bt_ctf_field_type_structure_get_field(structure_seq_type,
                NULL, &returned_type, 1) == 0,
                "bt_field_type_structure_get_field handles a NULL name correctly");
@@ -1696,9 +1579,6 @@ void type_field_tests()
        ok(bt_ctf_field_type_structure_get_field(structure_seq_type,
                &ret_string, NULL, 1) == 0,
                "bt_field_type_structure_get_field handles a NULL return type correctly");
-       ok(bt_ctf_field_type_structure_get_field(structure_seq_type,
-               &ret_string, &returned_type, 10) < 0,
-               "bt_field_type_structure_get_field handles an invalid index correctly");
        ok(bt_ctf_field_type_structure_get_field(structure_seq_type,
                &ret_string, &returned_type, 1) == 0,
                "bt_field_type_structure_get_field returns a field");
@@ -1708,10 +1588,6 @@ void type_field_tests()
                "bt_field_type_structure_get_field returns a correct field type");
        bt_put(returned_type);
 
-       ok(bt_field_type_structure_get_field_type_by_name(NULL, "a_sequence") == NULL,
-               "bt_field_type_structure_get_field_type_by_name handles a NULL structure correctly");
-       ok(bt_field_type_structure_get_field_type_by_name(structure_seq_type, NULL) == NULL,
-               "bt_field_type_structure_get_field_type_by_name handles a NULL field name correctly");
        returned_type = bt_field_type_structure_get_field_type_by_name(
                structure_seq_type, "a_sequence");
        ok(returned_type == sequence_type,
@@ -1726,12 +1602,6 @@ void type_field_tests()
                structure_seq_type, "inner_structure") == 0,
                "Add a structure type to a structure");
 
-       ok(bt_field_type_structure_get_field_type_by_name(
-               NULL, "a_sequence") == NULL,
-               "bt_field_type_structure_get_field_type_by_name handles a NULL field correctly");
-       ok(bt_field_type_structure_get_field_type_by_name(
-               structure_seq_type, NULL) == NULL,
-               "bt_field_type_structure_get_field_type_by_name handles a NULL field name correctly");
        returned_type = bt_field_type_structure_get_field_type_by_name(
                structure_seq_type, "a_sequence");
        ok(returned_type == sequence_type,
@@ -1949,8 +1819,6 @@ void test_empty_stream(struct bt_ctf_writer *writer)
        ret = bt_stream_class_set_event_header_type(stream_class, NULL);
        assert(ret == 0);
 
-       ok(bt_stream_class_get_trace(NULL) == NULL,
-               "bt_stream_class_get_trace handles NULL correctly");
        ok(bt_stream_class_get_trace(stream_class) == NULL,
                "bt_stream_class_get_trace returns NULL when stream class is orphaned");
 
@@ -2664,8 +2532,6 @@ void test_trace_uuid(void)
 
        trace = bt_trace_create();
        assert(trace);
-       ok(!bt_trace_get_uuid(NULL),
-               "bt_trace_get_uuid() handles NULL");
        ok(!bt_trace_get_uuid(trace),
                "bt_trace_get_uuid() returns NULL initially");
        ok(bt_trace_set_uuid(NULL, uuid),
@@ -2820,16 +2686,10 @@ int main(int argc, char **argv)
                "bt_trace_set_environment_field_string succeeds");
 
        /* Test bt_trace_get_environment_field_count */
-       ok(bt_trace_get_environment_field_count(NULL) < 0,
-               "bt_trace_get_environment_field_count handles a NULL trace correctly");
        ok(bt_trace_get_environment_field_count(trace) == 5,
                "bt_trace_get_environment_field_count returns a correct number of environment fields");
 
        /* Test bt_trace_get_environment_field_name */
-       ok(bt_trace_get_environment_field_name_by_index(NULL, 0) == NULL,
-               "bt_trace_get_environment_field_name handles a NULL trace correctly");
-       ok(bt_trace_get_environment_field_name_by_index(trace, 5) == NULL,
-               "bt_trace_get_environment_field_name handles an invalid index correctly (too large)");
        ret_string = bt_trace_get_environment_field_name_by_index(trace, 0);
        ok(ret_string && !strcmp(ret_string, "host"),
                "bt_trace_get_environment_field_name returns a correct field name");
@@ -2847,10 +2707,6 @@ int main(int argc, char **argv)
                "bt_trace_get_environment_field_name returns a correct field name");
 
        /* Test bt_trace_get_environment_field_value */
-       ok(bt_trace_get_environment_field_value_by_index(NULL, 0) == NULL,
-               "bt_trace_get_environment_field_value handles a NULL trace correctly");
-       ok(bt_trace_get_environment_field_value_by_index(trace, 5) == NULL,
-               "bt_trace_get_environment_field_value handles an invalid index correctly (too large)");
        obj = bt_trace_get_environment_field_value_by_index(trace, 1);
        ret = bt_value_integer_get(obj, &ret_int64_t);
        ok(!ret && ret_int64_t == 23,
@@ -2863,11 +2719,6 @@ int main(int argc, char **argv)
        BT_PUT(obj);
 
        /* Test bt_trace_get_environment_field_value_by_name */
-       ok(!bt_trace_get_environment_field_value_by_name(NULL,
-               "test_env_str"),
-               "bt_trace_get_environment_field_value_by_name handles a NULL trace correctly");
-       ok(!bt_trace_get_environment_field_value_by_name(trace, NULL),
-               "bt_trace_get_environment_field_value_by_name handles a NULL name correctly");
        ok(!bt_trace_get_environment_field_value_by_name(trace, "oh oh"),
                "bt_trace_get_environment_field_value_by_name returns NULL or an unknown field name");
        obj = bt_trace_get_environment_field_value_by_name(trace,
@@ -2993,8 +2844,6 @@ int main(int argc, char **argv)
        /* Define a stream class */
        stream_class = bt_stream_class_create("test_stream");
 
-       ok(bt_stream_class_get_name(NULL) == NULL,
-               "bt_stream_class_get_name handles NULL correctly");
        ret_string = bt_stream_class_get_name(stream_class);
        ok(ret_string && !strcmp(ret_string, "test_stream"),
                "bt_stream_class_get_name returns a correct stream class name");
@@ -3020,8 +2869,6 @@ int main(int argc, char **argv)
 
        ok(bt_stream_class_get_id(stream_class) < 0,
                "bt_stream_class_get_id returns an error when no id is set");
-       ok(bt_stream_class_get_id(NULL) < 0,
-               "bt_stream_class_get_id handles NULL correctly");
        ok(bt_stream_class_set_id(NULL, 123) < 0,
                "bt_stream_class_set_id handles NULL correctly");
        ok(bt_stream_class_set_id(stream_class, 123) == 0,
@@ -3030,8 +2877,6 @@ int main(int argc, char **argv)
                "bt_stream_class_get_id returns the correct value");
 
        /* Validate default event header fields */
-       ok(bt_stream_class_get_event_header_type(NULL) == NULL,
-               "bt_stream_class_get_event_header_type handles NULL correctly");
        ret_field_type = bt_stream_class_get_event_header_type(
                stream_class);
        ok(ret_field_type,
@@ -3059,8 +2904,6 @@ int main(int argc, char **argv)
        bt_put(ret_field_type);
 
        /* Add a custom trace packet header field */
-       ok(bt_trace_get_packet_header_type(NULL) == NULL,
-               "bt_trace_get_packet_header_type handles NULL correctly");
        packet_header_type = bt_trace_get_packet_header_type(trace);
        ok(packet_header_type,
                "bt_trace_get_packet_header_type returns a packet header");
@@ -3089,9 +2932,6 @@ int main(int argc, char **argv)
        ok(!bt_trace_set_packet_header_type(trace, packet_header_type),
                "Set a trace packet_header_type successfully");
 
-       ok(bt_stream_class_get_packet_context_type(NULL) == NULL,
-               "bt_stream_class_get_packet_context_type handles NULL correctly");
-
        /* Add a custom field to the stream class' packet context */
        packet_context_type = bt_stream_class_get_packet_context_type(stream_class);
        ok(packet_context_type,
@@ -3114,8 +2954,6 @@ int main(int argc, char **argv)
        ok(ret == 0, "Packet context field added successfully");
 
        /* Define a stream event context containing a my_integer field. */
-       ok(bt_stream_class_get_event_context_type(NULL) == NULL,
-               "bt_stream_class_get_event_context_type handles NULL correctly");
        stream_event_context_type = bt_field_type_structure_create();
        bt_field_type_structure_add_field(stream_event_context_type,
                integer_type, "common_event_context");
@@ -3155,25 +2993,13 @@ int main(int argc, char **argv)
         * class to the writer's trace, thus registering the stream
         * class's clock to the trace.
         */
-       ok(bt_trace_get_clock_class_count(NULL) < 0,
-               "bt_trace_get_clock_class_count correctly handles NULL");
        ok(bt_trace_get_clock_class_count(trace) == 1,
                "bt_trace_get_clock_class_count returns the correct number of clocks");
-       ok(!bt_trace_get_clock_class_by_index(NULL, 0),
-               "bt_trace_get_clock_class correctly handles NULL");
-       ok(!bt_trace_get_clock_class_by_index(trace, 1),
-               "bt_trace_get_clock_class correctly handles out of bound accesses");
        ret_clock_class = bt_trace_get_clock_class_by_index(trace, 0);
        ok(strcmp(bt_clock_class_get_name(ret_clock_class),
                bt_ctf_clock_get_name(clock)) == 0,
                "bt_trace_get_clock_class returns the right clock instance");
        bt_put(ret_clock_class);
-       ok(!bt_trace_get_clock_class_by_name(trace, NULL),
-               "bt_trace_get_clock_class_by_name correctly handles NULL (trace)");
-       ok(!bt_trace_get_clock_class_by_name(NULL, clock_name),
-               "bt_trace_get_clock_by_name correctly handles NULL (clock name)");
-       ok(!bt_trace_get_clock_class_by_name(NULL, NULL),
-               "bt_trace_get_clock_by_name correctly handles NULL (both)");
        ret_clock_class = bt_trace_get_clock_class_by_name(trace, clock_name);
        ok(strcmp(bt_clock_class_get_name(ret_clock_class),
                bt_ctf_clock_get_name(clock)) == 0,
@@ -3182,8 +3008,6 @@ int main(int argc, char **argv)
        ok(!bt_trace_get_clock_class_by_name(trace, "random"),
                "bt_trace_get_clock_by_name fails when the requested clock doesn't exist");
 
-       ok(bt_stream_get_class(NULL) == NULL,
-               "bt_stream_get_class correctly handles NULL");
        ret_stream_class = bt_stream_get_class(stream1);
        ok(ret_stream_class,
                "bt_stream_get_class returns a stream class");
This page took 0.052542 seconds and 4 git commands to generate.