#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>
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,
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,
{
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;
}
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,
{
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: "
goto end;
}
- bt_get(event_class->context);
- context_type = event_class->context;
+ context_type = bt_get(event_class->context);
+
end:
return context_type;
}
#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;
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(
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,
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,
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
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);
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;
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(
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(
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 */
if (range_end) {
*range_end = mapping->range_end._signed;
}
+
end:
return ret;
}
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 */
if (range_end) {
*range_end = mapping->range_end._unsigned;
}
+
end:
return ret;
}
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(
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)
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;
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;
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(
{
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;
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: "
field = structure->fields->pdata[index];
field_type = field->type;
bt_get(field_type);
+
end:
return field_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: "
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: "
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: "
field = g_ptr_array_index(variant->fields, index);
field_type = field->type;
bt_get(field_type);
+
end:
return field_type;
}
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) {
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,
{
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(
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
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(
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
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)
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,
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;
{
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:
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;
}
{
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.");
}
copy->alignment = type->alignment;
+
end:
return copy;
}
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) {
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: "
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;
{
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;
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);
}
#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>
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,
{
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\"",
}
ret = stream_class->id;
+
end:
return ret;
}
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(
{
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: "
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;
}
{
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;
}
#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>
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(
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)
{
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;
}
#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>
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)
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)
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;
}
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,
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
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(
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;
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 =
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,
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,
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)
#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];
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");
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,
-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");
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");
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");
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");
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 =
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");
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);
"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,
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),
"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,
"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),
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");
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,
"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");
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");
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");
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,
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");
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");
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");
"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,
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,
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");
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),
"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");
"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,
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,
/* 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");
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,
"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,
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");
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,
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");
* 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,
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");