from bt2.trace_collection_message_iterator import *
from bt2.value import *
from bt2.value import _Value
+from bt2.value import _IntegerValue
class Error(Exception):
typedef enum bt_value_type {
/// Null value object.
- BT_VALUE_TYPE_NULL = 0,
+ BT_VALUE_TYPE_NULL = 0,
/// Boolean value object (holds #BT_TRUE or #BT_FALSE).
- BT_VALUE_TYPE_BOOL = 1,
+ BT_VALUE_TYPE_BOOL = 1,
- /// Integer value object (holds a signed 64-bit integer raw value).
- BT_VALUE_TYPE_INTEGER = 2,
+ /// Unsigned integer value object (holds an unsigned 64-bit integer raw value).
+ BT_VALUE_TYPE_UNSIGNED_INTEGER = 2,
+
+ /// Signed integer value object (holds a signed 64-bit integer raw value).
+ BT_VALUE_TYPE_SIGNED_INTEGER = 3,
/// Floating point number value object (holds a \c double raw value).
- BT_VALUE_TYPE_REAL = 3,
+ BT_VALUE_TYPE_REAL = 4,
/// String value object.
- BT_VALUE_TYPE_STRING = 4,
+ BT_VALUE_TYPE_STRING = 5,
/// Array value object.
- BT_VALUE_TYPE_ARRAY = 5,
+ BT_VALUE_TYPE_ARRAY = 6,
/// Map value object.
- BT_VALUE_TYPE_MAP = 6,
+ BT_VALUE_TYPE_MAP = 7,
} bt_value_type;
extern bt_value_type bt_value_get_type(const bt_value *object);
-bt_bool bt_value_is_null(const bt_value *object);
-
-bt_bool bt_value_is_bool(const bt_value *object);
-
-bt_bool bt_value_is_integer(const bt_value *object);
-
-bt_bool bt_value_is_real(const bt_value *object);
-
-bt_bool bt_value_is_string(const bt_value *object);
-
-bt_bool bt_value_is_array(const bt_value *object);
-
-bt_bool bt_value_is_map(const bt_value *object);
-
extern bt_value_status bt_value_copy(const bt_value *object,
- bt_value **OUT);
+ bt_value **copy);
extern bt_bool bt_value_compare(const bt_value *object_a,
const bt_value *object_b);
extern bt_bool bt_value_bool_get(const bt_value *bool_obj);
-extern int64_t bt_value_integer_get(const bt_value *integer_obj);
+extern uint64_t bt_value_unsigned_integer_get(const bt_value *integer_obj);
+
+extern int64_t bt_value_signed_integer_get(const bt_value *integer_obj);
extern double bt_value_real_get(const bt_value *real_obj);
extern uint64_t bt_value_array_get_size(const bt_value *array_obj);
-bt_bool bt_value_array_is_empty(const bt_value *array_obj);
-
extern const bt_value *bt_value_array_borrow_element_by_index_const(
const bt_value *array_obj, uint64_t index);
extern uint64_t bt_value_map_get_size(const bt_value *map_obj);
-bt_bool bt_value_map_is_empty(const bt_value *map_obj);
-
extern const bt_value *bt_value_map_borrow_entry_value_const(
const bt_value *map_obj, const char *key);
extern void bt_value_bool_set(bt_value *bool_obj, bt_bool val);
-extern bt_value *bt_value_integer_create(void);
+extern bt_value *bt_value_unsigned_integer_create(void);
+
+extern bt_value *bt_value_unsigned_integer_create_init(uint64_t val);
-extern bt_value *bt_value_integer_create_init(
- int64_t val);
+extern void bt_value_unsigned_integer_set(bt_value *integer_obj, uint64_t val);
-extern void bt_value_integer_set(bt_value *integer_obj, int64_t val);
+extern bt_value *bt_value_signed_integer_create(void);
+
+extern bt_value *bt_value_signed_integer_create_init(int64_t val);
+
+extern void bt_value_signed_integer_set(bt_value *integer_obj, int64_t val);
extern bt_value *bt_value_real_create(void);
extern bt_value_status bt_value_array_append_bool_element(
bt_value *array_obj, bt_bool val);
-extern bt_value_status bt_value_array_append_integer_element(
+extern bt_value_status bt_value_array_append_unsigned_integer_element(
+ bt_value *array_obj, uint64_t val);
+
+extern bt_value_status bt_value_array_append_signed_integer_element(
bt_value *array_obj, int64_t val);
extern bt_value_status bt_value_array_append_real_element(
extern bt_value_status bt_value_map_insert_bool_entry(
bt_value *map_obj, const char *key, bt_bool val);
-extern bt_value_status bt_value_map_insert_integer_entry(
+extern bt_value_status bt_value_map_insert_unsigned_integer_entry(
+ bt_value *map_obj, const char *key, uint64_t val);
+
+extern bt_value_status bt_value_map_insert_signed_integer_entry(
bt_value *map_obj, const char *key, int64_t val);
extern bt_value_status bt_value_map_insert_real_entry(
return BoolValue(value)
if isinstance(value, int):
- return IntegerValue(value)
+ return SignedIntegerValue(value)
if isinstance(value, float):
return RealValue(value)
value = property(fset=_set_value)
-class IntegerValue(_IntegralValue):
- _NAME = 'Integer'
-
+class _IntegerValue(_IntegralValue):
def __init__(self, value=None):
if value is None:
- ptr = native_bt.value_integer_create()
+ ptr = self._create_default_value()
else:
- ptr = native_bt.value_integer_create_init(self._value_to_int(value))
+ ptr = self._create_value(self._value_to_int(value))
self._check_create_status(ptr)
super().__init__(ptr)
raise TypeError('expecting a number object')
value = int(value)
- utils._check_int64(value)
+ self._check_int_range(value)
return value
@property
def _value(self):
- return native_bt.value_integer_get(self._ptr)
+ return self._get_value(self._ptr)
- def _set_value(self, value):
- native_bt.value_integer_set(self._ptr, self._value_to_int(value))
+ def _prop_set_value(self, value):
+ self._set_value(self._ptr, self._value_to_int(value))
- value = property(fset=_set_value)
+ value = property(fset=_prop_set_value)
+
+
+class UnsignedIntegerValue(_IntegerValue):
+ _check_int_range = staticmethod(utils._check_uint64)
+ _create_default_value = native_bt.value_unsigned_integer_create
+ _create_value = native_bt.value_unsigned_integer_create_init
+ _set_value = native_bt.value_unsigned_integer_set
+ _get_value = native_bt.value_unsigned_integer_get
+
+
+class SignedIntegerValue(_IntegerValue):
+ _check_int_range = staticmethod(utils._check_int64)
+ _create_default_value = native_bt.value_signed_integer_create
+ _create_value = native_bt.value_signed_integer_create_init
+ _set_value = native_bt.value_signed_integer_set
+ _get_value = native_bt.value_signed_integer_get
class RealValue(_RealValue):
_TYPE_TO_OBJ = {
native_bt.VALUE_TYPE_BOOL: BoolValue,
- native_bt.VALUE_TYPE_INTEGER: IntegerValue,
+ native_bt.VALUE_TYPE_UNSIGNED_INTEGER: UnsignedIntegerValue,
+ native_bt.VALUE_TYPE_SIGNED_INTEGER: SignedIntegerValue,
native_bt.VALUE_TYPE_REAL: RealValue,
native_bt.VALUE_TYPE_STRING: StringValue,
native_bt.VALUE_TYPE_ARRAY: ArrayValue,
g_string_append_printf(state->ini_error, "^\n\n");
}
+/* Parse the next token as an unsigned integer. */
+static
+bt_value *ini_parse_uint(struct ini_parsing_state *state)
+{
+ bt_value *value = NULL;
+ GTokenType token_type = g_scanner_get_next_token(state->scanner);
+
+ if (token_type != G_TOKEN_INT) {
+ ini_append_error_expecting(state, state->scanner,
+ "integer value");
+ goto end;
+ }
+
+ value = bt_value_unsigned_integer_create_init(
+ state->scanner->value.v_int64);
+
+end:
+ return value;
+}
+
/* Parse the next token as a number and return its negation. */
static
bt_value *ini_parse_neg_number(struct ini_parsing_state *state)
"Integer value -%" PRIu64 " is outside the range of a 64-bit signed integer\n",
int_val);
} else {
- value = bt_value_integer_create_init(-((int64_t) int_val));
+ value = bt_value_signed_integer_create_init(
+ -((int64_t) int_val));
}
break;
if (state->scanner->value.v_char == '-') {
/* Negative number */
value = ini_parse_neg_number(state);
+ } else if (state->scanner->value.v_char == '+') {
+ /* Unsigned integer */
+ value = ini_parse_uint(state);
} else if (state->scanner->value.v_char == '[') {
/* Array */
value = ini_parse_array(state);
break;
case G_TOKEN_INT:
{
- /* Positive integer */
+ /* Positive, signed integer */
uint64_t int_val = state->scanner->value.v_int64;
if (int_val > INT64_MAX) {
"Integer value %" PRIu64 " is outside the range of a 64-bit signed integer\n",
int_val);
} else {
- value = bt_value_integer_create_init((int64_t)int_val);
+ value = bt_value_signed_integer_create_init(
+ (int64_t) int_val);
}
break;
}
fprintf(fp, "* `true`, `TRUE`, `yes`, `YES`: true boolean value (no backticks).\n");
fprintf(fp, "* `false`, `FALSE`, `no`, `NO`: false boolean value (no backticks).\n");
fprintf(fp, "* Binary (`0b` prefix), octal (`0` prefix), decimal, or hexadecimal\n");
- fprintf(fp, " (`0x` prefix) signed 64-bit integer.\n");
+ fprintf(fp, " (`0x` prefix) unsigned (with `+` prefix) or signed 64-bit integer.\n");
fprintf(fp, "* Double precision floating point number (scientific notation is accepted).\n");
fprintf(fp, "* Unquoted string with no special characters, and not matching any of\n");
fprintf(fp, " the null and boolean value symbols above.\n");
fprintf(fp, "Example:\n");
fprintf(fp, "\n");
fprintf(fp, " many=null, fresh=yes, condition=false, squirrel=-782329,\n");
- fprintf(fp, " observe=3.14, simple=beef, needs-quotes=\"some string\",\n");
+ fprintf(fp, " play=+23, observe=3.14, simple=beef, needs-quotes=\"some string\",\n");
fprintf(fp, " escape.chars-are:allowed=\"this is a \\\" double quote\",\n");
fprintf(fp, " things=[1, \"2\", 3]\n");
fprintf(fp, "\n");
{
bt_bool bool_val;
int64_t int_val;
+ uint64_t uint_val;
double dbl_val;
const char *str_val;
int size;
bt_common_color_fg_cyan(), bool_val ? "yes" : "no",
bt_common_color_reset());
break;
- case BT_VALUE_TYPE_INTEGER:
- int_val = bt_value_integer_get(value);
+ case BT_VALUE_TYPE_UNSIGNED_INTEGER:
+ uint_val = bt_value_unsigned_integer_get(value);
+ fprintf(fp, "%s%s%" PRIu64 "%s\n", bt_common_color_bold(),
+ bt_common_color_fg_red(), uint_val,
+ bt_common_color_reset());
+ break;
+ case BT_VALUE_TYPE_SIGNED_INTEGER:
+ int_val = bt_value_signed_integer_get(value);
fprintf(fp, "%s%s%" PRId64 "%s\n", bt_common_color_bold(),
bt_common_color_fg_red(), int_val,
bt_common_color_reset());
BT_LOGE_STR("Unexpected empty array \"timer-us\" entry.");
goto error;
}
- timer_us = bt_value_integer_get(v);
+ timer_us = bt_value_signed_integer_get(v);
fprintf(out_stream, " (timer = %" PRIu64 ", ", timer_us);
v = bt_value_map_borrow_entry_value_const(map, "stream-count");
if (!v) {
BT_LOGE_STR("Unexpected empty array \"stream-count\" entry.");
goto error;
}
- streams = bt_value_integer_get(v);
+ streams = bt_value_signed_integer_get(v);
fprintf(out_stream, "%" PRIu64 " stream(s), ", streams);
v = bt_value_map_borrow_entry_value_const(map, "client-count");
if (!v) {
BT_LOGE_STR("Unexpected empty array \"client-count\" entry.");
goto error;
}
- clients = bt_value_integer_get(v);
+ clients = bt_value_signed_integer_get(v);
fprintf(out_stream, "%" PRIu64 " client(s) connected)\n", clients);
}
goto error;
}
- begin = bt_value_integer_get(intersection_begin);
- end = bt_value_integer_get(intersection_end);
+ begin = bt_value_signed_integer_get(intersection_begin);
+ end = bt_value_signed_integer_get(intersection_end);
if (begin < 0 || end < 0 || end < begin) {
BT_LOGW("Invalid trace stream intersection values: "
* `false`, `FALSE`, `no`, `NO`: false boolean value.
* Binary (`0b` prefix), octal (`0` prefix), decimal, or hexadecimal
- (`0x` prefix) signed 64-bit integer.
+ (`0x` prefix) unsigned (with `+` prefix) or signed 64-bit integer.
* Double precision floating point number (scientific notation is
accepted).
----
babeltrace ... --params='many=null, fresh=yes, condition=false,
- squirrel=-782329, observe=3.14,
+ squirrel=-782329, play=+23, observe=3.14,
simple=beef, needs-quotes="some string",
escape.chars-are:allowed="a \" quote",
things=[1, "2", 3]'
return "BT_VALUE_TYPE_NULL";
case BT_VALUE_TYPE_BOOL:
return "BT_VALUE_TYPE_BOOL";
- case BT_VALUE_TYPE_INTEGER:
- return "BT_VALUE_TYPE_INTEGER";
+ case BT_VALUE_TYPE_UNSIGNED_INTEGER:
+ return "BT_VALUE_TYPE_UNSIGNED_INTEGER";
+ case BT_VALUE_TYPE_SIGNED_INTEGER:
+ return "BT_VALUE_TYPE_SIGNED_INTEGER";
case BT_VALUE_TYPE_REAL:
return "BT_VALUE_TYPE_REAL";
case BT_VALUE_TYPE_STRING:
typedef enum bt_value_type {
/// Null value object.
- BT_VALUE_TYPE_NULL = 0,
+ BT_VALUE_TYPE_NULL = 0,
/// Boolean value object (holds #BT_TRUE or #BT_FALSE).
- BT_VALUE_TYPE_BOOL = 1,
+ BT_VALUE_TYPE_BOOL = 1,
- /// Integer value object (holds a signed 64-bit integer raw value).
- BT_VALUE_TYPE_INTEGER = 2,
+ /// Unsigned integer value object (holds an unsigned 64-bit integer raw value).
+ BT_VALUE_TYPE_UNSIGNED_INTEGER = 2,
+
+ /// Signed integer value object (holds a signed 64-bit integer raw value).
+ BT_VALUE_TYPE_SIGNED_INTEGER = 3,
/// Floating point number value object (holds a \c double raw value).
- BT_VALUE_TYPE_REAL = 3,
+ BT_VALUE_TYPE_REAL = 4,
/// String value object.
- BT_VALUE_TYPE_STRING = 4,
+ BT_VALUE_TYPE_STRING = 5,
/// Array value object.
- BT_VALUE_TYPE_ARRAY = 5,
+ BT_VALUE_TYPE_ARRAY = 6,
/// Map value object.
- BT_VALUE_TYPE_MAP = 6,
+ BT_VALUE_TYPE_MAP = 7,
} bt_value_type;
extern bt_value_type bt_value_get_type(const bt_value *object);
}
static inline
-bt_bool bt_value_is_integer(const bt_value *object)
+bt_bool bt_value_is_unsigned_integer(const bt_value *object)
+{
+ return bt_value_get_type(object) == BT_VALUE_TYPE_UNSIGNED_INTEGER;
+}
+
+static inline
+bt_bool bt_value_is_signed_integer(const bt_value *object)
{
- return bt_value_get_type(object) == BT_VALUE_TYPE_INTEGER;
+ return bt_value_get_type(object) == BT_VALUE_TYPE_SIGNED_INTEGER;
}
static inline
extern bt_bool bt_value_bool_get(const bt_value *bool_obj);
-extern int64_t bt_value_integer_get(const bt_value *integer_obj);
+extern uint64_t bt_value_unsigned_integer_get(const bt_value *integer_obj);
+
+extern int64_t bt_value_signed_integer_get(const bt_value *integer_obj);
extern double bt_value_real_get(const bt_value *real_obj);
struct bt_value_integer {
struct bt_value base;
- int64_t value;
+ union {
+ uint64_t i;
+ int64_t u;
+ } value;
};
struct bt_value_real {
extern void bt_value_bool_set(bt_value *bool_obj, bt_bool val);
-extern bt_value *bt_value_integer_create(void);
+extern bt_value *bt_value_unsigned_integer_create(void);
-extern bt_value *bt_value_integer_create_init(
- int64_t val);
+extern bt_value *bt_value_unsigned_integer_create_init(uint64_t val);
-extern void bt_value_integer_set(bt_value *integer_obj, int64_t val);
+extern void bt_value_unsigned_integer_set(bt_value *integer_obj, uint64_t val);
+
+extern bt_value *bt_value_signed_integer_create(void);
+
+extern bt_value *bt_value_signed_integer_create_init(int64_t val);
+
+extern void bt_value_signed_integer_set(bt_value *integer_obj, int64_t val);
extern bt_value *bt_value_real_create(void);
extern bt_value_status bt_value_array_append_bool_element(
bt_value *array_obj, bt_bool val);
-extern bt_value_status bt_value_array_append_integer_element(
+extern bt_value_status bt_value_array_append_unsigned_integer_element(
+ bt_value *array_obj, uint64_t val);
+
+extern bt_value_status bt_value_array_append_signed_integer_element(
bt_value *array_obj, int64_t val);
extern bt_value_status bt_value_array_append_real_element(
extern bt_value_status bt_value_map_insert_bool_entry(
bt_value *map_obj, const char *key, bt_bool val);
-extern bt_value_status bt_value_map_insert_integer_entry(
+extern bt_value_status bt_value_map_insert_unsigned_integer_entry(
+ bt_value *map_obj, const char *key, uint64_t val);
+
+extern bt_value_status bt_value_map_insert_signed_integer_entry(
bt_value *map_obj, const char *key, int64_t val);
extern bt_value_status bt_value_map_insert_real_entry(
BUF_APPEND(", %svalue=%d", PRFIELD(val));
break;
}
- case BT_VALUE_TYPE_INTEGER:
+ case BT_VALUE_TYPE_UNSIGNED_INTEGER:
{
- int64_t val = bt_value_integer_get(value);
-
- BUF_APPEND(", %svalue=%" PRId64, PRFIELD(val));
+ BUF_APPEND(", %svalue=%" PRIu64,
+ PRFIELD(bt_value_unsigned_integer_get(value)));
+ break;
+ }
+ case BT_VALUE_TYPE_SIGNED_INTEGER:
+ {
+ BUF_APPEND(", %svalue=%" PRId64,
+ PRFIELD(bt_value_signed_integer_get(value)));
break;
}
case BT_VALUE_TYPE_REAL:
struct bt_value *value_obj;
BT_ASSERT_PRE_NON_NULL(tc, "Trace class");
BT_ASSERT_PRE_NON_NULL(name, "Name");
- value_obj = bt_value_integer_create_init(value);
+ value_obj = bt_value_signed_integer_create_init(value);
if (!value_obj) {
BT_LOGE_STR("Cannot create an integer value object.");
ret = BT_TRACE_CLASS_STATUS_NOMEM;
static
void (* const destroy_funcs[])(struct bt_value *) = {
- [BT_VALUE_TYPE_NULL] = NULL,
- [BT_VALUE_TYPE_BOOL] = NULL,
- [BT_VALUE_TYPE_INTEGER] = NULL,
- [BT_VALUE_TYPE_REAL] = NULL,
- [BT_VALUE_TYPE_STRING] = bt_value_string_destroy,
- [BT_VALUE_TYPE_ARRAY] = bt_value_array_destroy,
- [BT_VALUE_TYPE_MAP] = bt_value_map_destroy,
+ [BT_VALUE_TYPE_NULL] = NULL,
+ [BT_VALUE_TYPE_BOOL] = NULL,
+ [BT_VALUE_TYPE_UNSIGNED_INTEGER] = NULL,
+ [BT_VALUE_TYPE_SIGNED_INTEGER] = NULL,
+ [BT_VALUE_TYPE_REAL] = NULL,
+ [BT_VALUE_TYPE_STRING] = bt_value_string_destroy,
+ [BT_VALUE_TYPE_ARRAY] = bt_value_array_destroy,
+ [BT_VALUE_TYPE_MAP] = bt_value_map_destroy,
};
static
BT_VALUE_TO_BOOL(bool_obj)->value);
}
+static inline
+struct bt_value *bt_value_integer_create_init(enum bt_value_type type,
+ uint64_t uval);
+
static
struct bt_value *bt_value_integer_copy(
const struct bt_value *integer_obj)
{
- return bt_value_integer_create_init(
- BT_VALUE_TO_INTEGER(integer_obj)->value);
+ return bt_value_integer_create_init(integer_obj->type,
+ BT_VALUE_TO_INTEGER(integer_obj)->value.u);
}
static
static
struct bt_value *(* const copy_funcs[])(const struct bt_value *) = {
- [BT_VALUE_TYPE_NULL] = bt_value_null_copy,
- [BT_VALUE_TYPE_BOOL] = bt_value_bool_copy,
- [BT_VALUE_TYPE_INTEGER] = bt_value_integer_copy,
- [BT_VALUE_TYPE_REAL] = bt_value_real_copy,
- [BT_VALUE_TYPE_STRING] = bt_value_string_copy,
- [BT_VALUE_TYPE_ARRAY] = bt_value_array_copy,
- [BT_VALUE_TYPE_MAP] = bt_value_map_copy,
+ [BT_VALUE_TYPE_NULL] = bt_value_null_copy,
+ [BT_VALUE_TYPE_BOOL] = bt_value_bool_copy,
+ [BT_VALUE_TYPE_UNSIGNED_INTEGER] = bt_value_integer_copy,
+ [BT_VALUE_TYPE_SIGNED_INTEGER] = bt_value_integer_copy,
+ [BT_VALUE_TYPE_REAL] = bt_value_real_copy,
+ [BT_VALUE_TYPE_STRING] = bt_value_string_copy,
+ [BT_VALUE_TYPE_ARRAY] = bt_value_array_copy,
+ [BT_VALUE_TYPE_MAP] = bt_value_map_copy,
};
static
bt_bool bt_value_integer_compare(const struct bt_value *object_a,
const struct bt_value *object_b)
{
- if (BT_VALUE_TO_INTEGER(object_a)->value !=
- BT_VALUE_TO_INTEGER(object_b)->value) {
- BT_LOGV("Integer value objects are different: "
- "int-a-val=%" PRId64 ", int-b-val=%" PRId64,
- BT_VALUE_TO_INTEGER(object_a)->value,
- BT_VALUE_TO_INTEGER(object_b)->value);
+ if (BT_VALUE_TO_INTEGER(object_a)->value.u !=
+ BT_VALUE_TO_INTEGER(object_b)->value.u) {
+ if (object_a->type == BT_VALUE_TYPE_UNSIGNED_INTEGER) {
+ BT_LOGV("Unsigned integer value objects are different: "
+ "int-a-val=%" PRIu64 ", int-b-val=%" PRIu64,
+ BT_VALUE_TO_INTEGER(object_a)->value.u,
+ BT_VALUE_TO_INTEGER(object_b)->value.u);
+ } else {
+ BT_LOGV("Signed integer value objects are different: "
+ "int-a-val=%" PRId64 ", int-b-val=%" PRId64,
+ BT_VALUE_TO_INTEGER(object_a)->value.i,
+ BT_VALUE_TO_INTEGER(object_b)->value.i);
+ }
+
return BT_FALSE;
}
static
bt_bool (* const compare_funcs[])(const struct bt_value *,
const struct bt_value *) = {
- [BT_VALUE_TYPE_NULL] = bt_value_null_compare,
- [BT_VALUE_TYPE_BOOL] = bt_value_bool_compare,
- [BT_VALUE_TYPE_INTEGER] = bt_value_integer_compare,
- [BT_VALUE_TYPE_REAL] = bt_value_real_compare,
- [BT_VALUE_TYPE_STRING] = bt_value_string_compare,
- [BT_VALUE_TYPE_ARRAY] = bt_value_array_compare,
- [BT_VALUE_TYPE_MAP] = bt_value_map_compare,
+ [BT_VALUE_TYPE_NULL] = bt_value_null_compare,
+ [BT_VALUE_TYPE_BOOL] = bt_value_bool_compare,
+ [BT_VALUE_TYPE_UNSIGNED_INTEGER] = bt_value_integer_compare,
+ [BT_VALUE_TYPE_SIGNED_INTEGER] = bt_value_integer_compare,
+ [BT_VALUE_TYPE_REAL] = bt_value_real_compare,
+ [BT_VALUE_TYPE_STRING] = bt_value_string_compare,
+ [BT_VALUE_TYPE_ARRAY] = bt_value_array_compare,
+ [BT_VALUE_TYPE_MAP] = bt_value_map_compare,
};
static
static
void (* const freeze_funcs[])(struct bt_value *) = {
- [BT_VALUE_TYPE_NULL] = bt_value_null_freeze,
- [BT_VALUE_TYPE_BOOL] = bt_value_generic_freeze,
- [BT_VALUE_TYPE_INTEGER] = bt_value_generic_freeze,
- [BT_VALUE_TYPE_REAL] = bt_value_generic_freeze,
- [BT_VALUE_TYPE_STRING] = bt_value_generic_freeze,
- [BT_VALUE_TYPE_ARRAY] = bt_value_array_freeze,
- [BT_VALUE_TYPE_MAP] = bt_value_map_freeze,
+ [BT_VALUE_TYPE_NULL] = bt_value_null_freeze,
+ [BT_VALUE_TYPE_BOOL] = bt_value_generic_freeze,
+ [BT_VALUE_TYPE_UNSIGNED_INTEGER] = bt_value_generic_freeze,
+ [BT_VALUE_TYPE_SIGNED_INTEGER] = bt_value_generic_freeze,
+ [BT_VALUE_TYPE_REAL] = bt_value_generic_freeze,
+ [BT_VALUE_TYPE_STRING] = bt_value_generic_freeze,
+ [BT_VALUE_TYPE_ARRAY] = bt_value_array_freeze,
+ [BT_VALUE_TYPE_MAP] = bt_value_map_freeze,
};
static
return bt_value_bool_create_init(BT_FALSE);
}
-struct bt_value *bt_value_integer_create_init(int64_t val)
+static inline
+struct bt_value *bt_value_integer_create_init(enum bt_value_type type,
+ uint64_t uval)
{
struct bt_value_integer *integer_obj;
- BT_LOGD("Creating integer value object: val=%" PRId64, val);
+ BT_ASSERT(type == BT_VALUE_TYPE_UNSIGNED_INTEGER ||
+ type == BT_VALUE_TYPE_SIGNED_INTEGER);
+
+ if (type == BT_VALUE_TYPE_UNSIGNED_INTEGER) {
+ BT_LOGD("Creating unsigned integer value object: val=%" PRIu64,
+ uval);
+ } else {
+ BT_LOGD("Creating signed integer value object: val=%" PRId64,
+ (int64_t) uval);
+ }
+
integer_obj = g_new0(struct bt_value_integer, 1);
if (!integer_obj) {
BT_LOGE_STR("Failed to allocate one integer value object.");
goto end;
}
- integer_obj->base = bt_value_create_base(BT_VALUE_TYPE_INTEGER);
- integer_obj->value = val;
- BT_LOGD("Created integer value object: addr=%p",
+ integer_obj->base = bt_value_create_base(type);
+ integer_obj->value.u = uval;
+ BT_LOGD("Created %ssigned integer value object: addr=%p",
+ type == BT_VALUE_TYPE_UNSIGNED_INTEGER ? "un" : "",
integer_obj);
end:
return (void *) integer_obj;
}
-struct bt_value *bt_value_integer_create(void)
+struct bt_value *bt_value_unsigned_integer_create_init(uint64_t val)
+{
+ return bt_value_integer_create_init(BT_VALUE_TYPE_UNSIGNED_INTEGER,
+ val);
+}
+
+struct bt_value *bt_value_unsigned_integer_create(void)
+{
+ return bt_value_unsigned_integer_create_init(0);
+}
+
+struct bt_value *bt_value_signed_integer_create_init(int64_t val)
+{
+ return bt_value_integer_create_init(BT_VALUE_TYPE_SIGNED_INTEGER,
+ (uint64_t) val);
+}
+
+struct bt_value *bt_value_signed_integer_create(void)
{
- return bt_value_integer_create_init(0);
+ return bt_value_signed_integer_create_init(0);
}
struct bt_value *bt_value_real_create_init(double val)
bool_obj, val);
}
-int64_t bt_value_integer_get(const struct bt_value *integer_obj)
+uint64_t bt_value_unsigned_integer_get(const struct bt_value *integer_obj)
+{
+ BT_ASSERT_PRE_NON_NULL(integer_obj, "Value object");
+ BT_ASSERT_PRE_VALUE_IS_TYPE(integer_obj,
+ BT_VALUE_TYPE_UNSIGNED_INTEGER);
+ return BT_VALUE_TO_INTEGER(integer_obj)->value.u;
+}
+
+int64_t bt_value_signed_integer_get(const struct bt_value *integer_obj)
{
BT_ASSERT_PRE_NON_NULL(integer_obj, "Value object");
- BT_ASSERT_PRE_VALUE_IS_TYPE(integer_obj, BT_VALUE_TYPE_INTEGER);
- return BT_VALUE_TO_INTEGER(integer_obj)->value;
+ BT_ASSERT_PRE_VALUE_IS_TYPE(integer_obj,
+ BT_VALUE_TYPE_SIGNED_INTEGER);
+ return BT_VALUE_TO_INTEGER(integer_obj)->value.i;
}
+static inline
void bt_value_integer_set(struct bt_value *integer_obj,
- int64_t val)
+ enum bt_value_type expected_type, uint64_t uval)
{
BT_ASSERT_PRE_NON_NULL(integer_obj, "Value object");
- BT_ASSERT_PRE_VALUE_IS_TYPE(integer_obj, BT_VALUE_TYPE_INTEGER);
+ BT_ASSERT_PRE_VALUE_IS_TYPE(integer_obj, expected_type);
BT_ASSERT_PRE_VALUE_HOT(integer_obj, "Value object");
- BT_VALUE_TO_INTEGER(integer_obj)->value = val;
- BT_LOGV("Set integer value's raw value: value-addr=%p, value=%" PRId64,
- integer_obj, val);
+ BT_VALUE_TO_INTEGER(integer_obj)->value.u = uval;
+}
+
+void bt_value_unsigned_integer_set(struct bt_value *integer_obj,
+ uint64_t val)
+{
+ bt_value_integer_set(integer_obj, BT_VALUE_TYPE_UNSIGNED_INTEGER, val);
+ BT_LOGV("Set unsigned integer value's raw value: "
+ "value-addr=%p, value=%" PRIu64, integer_obj, val);
+}
+
+void bt_value_signed_integer_set(struct bt_value *integer_obj,
+ int64_t val)
+{
+ bt_value_integer_set(integer_obj, BT_VALUE_TYPE_SIGNED_INTEGER,
+ (uint64_t) val);
+ BT_LOGV("Set signed integer value's raw value: "
+ "value-addr=%p, value=%" PRId64, integer_obj, val);
}
double bt_value_real_get(const struct bt_value *real_obj)
return ret;
}
-enum bt_value_status bt_value_array_append_integer_element(
+enum bt_value_status bt_value_array_append_unsigned_integer_element(
+ struct bt_value *array_obj, uint64_t val)
+{
+ enum bt_value_status ret;
+ struct bt_value *integer_obj = NULL;
+
+ integer_obj = bt_value_unsigned_integer_create_init(val);
+ ret = bt_value_array_append_element(array_obj,
+ (void *) integer_obj);
+ bt_object_put_ref(integer_obj);
+ return ret;
+}
+
+enum bt_value_status bt_value_array_append_signed_integer_element(
struct bt_value *array_obj, int64_t val)
{
enum bt_value_status ret;
struct bt_value *integer_obj = NULL;
- integer_obj = bt_value_integer_create_init(val);
+ integer_obj = bt_value_signed_integer_create_init(val);
ret = bt_value_array_append_element(array_obj,
(void *) integer_obj);
bt_object_put_ref(integer_obj);
return ret;
}
-enum bt_value_status bt_value_map_insert_integer_entry(
+enum bt_value_status bt_value_map_insert_unsigned_integer_entry(
+ struct bt_value *map_obj, const char *key, uint64_t val)
+{
+ enum bt_value_status ret;
+ struct bt_value *integer_obj = NULL;
+
+ integer_obj = bt_value_unsigned_integer_create_init(val);
+ ret = bt_value_map_insert_entry(map_obj, key,
+ (void *) integer_obj);
+ bt_object_put_ref(integer_obj);
+ return ret;
+}
+
+enum bt_value_status bt_value_map_insert_signed_integer_entry(
struct bt_value *map_obj, const char *key, int64_t val)
{
enum bt_value_status ret;
struct bt_value *integer_obj = NULL;
- integer_obj = bt_value_integer_create_init(val);
+ integer_obj = bt_value_signed_integer_create_init(val);
ret = bt_value_map_insert_entry(map_obj, key,
(void *) integer_obj);
bt_object_put_ref(integer_obj);
int ret;
v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "tracer_buffering_id");
- if (!v || !bt_value_is_integer(v)) {
+ if (!v || !bt_value_is_signed_integer(v)) {
BT_LOGD_STR("Couldn't get environment value: name=\"tracer_buffering_id\"");
goto error;
}
- g_string_append_printf(path, G_DIR_SEPARATOR_S "%" PRId64, bt_value_integer_get(v));
+ g_string_append_printf(path, G_DIR_SEPARATOR_S "%" PRId64,
+ bt_value_signed_integer_get(v));
v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "isa_length");
- if (!v || !bt_value_is_integer(v)) {
+ if (!v || !bt_value_is_signed_integer(v)) {
BT_LOGD_STR("Couldn't get environment value: name=\"isa_length\"");
goto error;
}
- g_string_append_printf(path, G_DIR_SEPARATOR_S "%" PRIu64 "-bit", bt_value_integer_get(v));
+ g_string_append_printf(path, G_DIR_SEPARATOR_S "%" PRIu64 "-bit",
+ bt_value_signed_integer_get(v));
ret = 0;
goto end;
g_string_append_printf(path, G_DIR_SEPARATOR_S "%s", bt_value_string_get(v));
v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "vpid");
- if (!v || !bt_value_is_integer(v)) {
+ if (!v || !bt_value_is_signed_integer(v)) {
BT_LOGD_STR("Couldn't get environment value: name=\"vpid\"");
goto error;
}
- g_string_append_printf(path, "-%" PRId64, bt_value_integer_get(v));
+ g_string_append_printf(path, "-%" PRId64, bt_value_signed_integer_get(v));
v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "vpid_datetime");
if (!v || !bt_value_is_string(v)) {
}
v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "tracer_major");
- if (!v || !bt_value_is_integer(v)) {
+ if (!v || !bt_value_is_signed_integer(v)) {
BT_LOGD_STR("Couldn't get environment value: name=\"tracer_major\"");
goto error;
}
- tracer_major = bt_value_integer_get(v);
+ tracer_major = bt_value_signed_integer_get(v);
v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "tracer_minor");
- if (!v || !bt_value_is_integer(v)) {
+ if (!v || !bt_value_is_signed_integer(v)) {
BT_LOGD_STR("Couldn't get environment value: name=\"tracer_minor\"");
goto error;
}
- tracer_minor = bt_value_integer_get(v);
+ tracer_minor = bt_value_signed_integer_get(v);
if (!(tracer_major >= 3 || (tracer_major == 2 && tracer_minor >= 11))) {
BT_LOGD("Unsupported LTTng version for automatic trace path: major=%" PRId64 ", minor=%" PRId64,
g_string_append_printf(tsdl, "%s = ", name);
switch (bt_value_get_type(val)) {
- case BT_VALUE_TYPE_INTEGER:
+ case BT_VALUE_TYPE_SIGNED_INTEGER:
g_string_append_printf(tsdl, "%" PRId64,
- bt_value_integer_get(val));
+ bt_value_signed_integer_get(val));
break;
case BT_VALUE_TYPE_STRING:
append_quoted_string(&ctx, bt_value_string_get(val));
}
switch (bt_value_get_type(val)) {
- case BT_VALUE_TYPE_INTEGER:
+ case BT_VALUE_TYPE_SIGNED_INTEGER:
case BT_VALUE_TYPE_STRING:
break;
default:
value = bt_value_map_borrow_entry_value_const(params,
"clock-class-offset-s");
if (value) {
- if (!bt_value_is_integer(value)) {
+ if (!bt_value_is_signed_integer(value)) {
BT_LOGE("clock-class-offset-s must be an integer");
goto error;
}
ctf_fs->metadata_config.clock_class_offset_s =
- bt_value_integer_get(value);
+ bt_value_signed_integer_get(value);
}
/* clock-class-offset-ns parameter */
value = bt_value_map_borrow_entry_value_const(params,
"clock-class-offset-ns");
if (value) {
- if (!bt_value_is_integer(value)) {
+ if (!bt_value_is_signed_integer(value)) {
BT_LOGE("clock-class-offset-ns must be an integer");
goto error;
}
ctf_fs->metadata_config.clock_class_offset_ns =
- bt_value_integer_get(value);
+ bt_value_signed_integer_get(value);
}
goto end;
}
- status = bt_value_map_insert_integer_entry(range_map, "begin",
+ status = bt_value_map_insert_signed_integer_entry(range_map, "begin",
range->begin_ns);
if (status != BT_VALUE_STATUS_OK) {
ret = -1;
goto end;
}
- status = bt_value_map_insert_integer_entry(range_map, "end",
+ status = bt_value_map_insert_signed_integer_entry(range_map, "end",
range->end_ns);
if (status != BT_VALUE_STATUS_OK) {
ret = -1;
bt_value_status status;
if (ds_file_group->stream_id != UINT64_C(-1)) {
- status = bt_value_map_insert_integer_entry(info, "id",
- (int64_t) ds_file_group->stream_id);
+ status = bt_value_map_insert_unsigned_integer_entry(info, "id",
+ ds_file_group->stream_id);
if (status != BT_VALUE_STATUS_OK) {
ret = -1;
goto end;
}
}
- status = bt_value_map_insert_integer_entry(info, "class-id",
- (int64_t) ds_file_group->sc->id);
+ status = bt_value_map_insert_unsigned_integer_entry(info, "class-id",
+ ds_file_group->sc->id);
if (status != BT_VALUE_STATUS_OK) {
ret = -1;
goto end;
ret = -1;
goto end;
}
- val = bt_value_integer_get(btval);
+ val = bt_value_signed_integer_get(btval);
/* sum */
val += streams;
- bt_value_integer_set(btval, val);
+ bt_value_signed_integer_set(btval, val);
btval = bt_value_map_borrow_entry_value(map, "client-count");
if (!btval) {
ret = -1;
goto end;
}
- val = bt_value_integer_get(btval);
+ val = bt_value_signed_integer_get(btval);
/* max */
val = max_t(int64_t, clients, val);
- bt_value_integer_set(btval, val);
+ bt_value_signed_integer_set(btval, val);
}
if (found) {
{
uint32_t live_timer = be32toh(session->live_timer);
- ret_status = bt_value_map_insert_integer_entry(map, "timer-us",
- live_timer);
+ ret_status = bt_value_map_insert_signed_integer_entry(
+ map, "timer-us", live_timer);
if (ret_status != BT_VALUE_STATUS_OK) {
BT_LOGE_STR("Error inserting \"timer-us\" entry.");
ret = -1;
{
uint32_t streams = be32toh(session->streams);
- ret_status = bt_value_map_insert_integer_entry(map, "stream-count",
- streams);
+ ret_status = bt_value_map_insert_signed_integer_entry(map,
+ "stream-count", streams);
if (ret_status != BT_VALUE_STATUS_OK) {
BT_LOGE_STR("Error inserting \"stream-count\" entry.");
ret = -1;
{
uint32_t clients = be32toh(session->clients);
- ret_status = bt_value_map_insert_integer_entry(map, "client-count",
- clients);
+ ret_status = bt_value_map_insert_signed_integer_entry(map,
+ "client-count", clients);
if (ret_status != BT_VALUE_STATUS_OK) {
BT_LOGE_STR("Error inserting \"client-count\" entry.");
ret = -1;
BT_ASSERT(value_name);
BT_ASSERT(value);
- if (bt_value_is_integer(value)) {
+ if (bt_value_is_signed_integer(value)) {
trace_class_status =
bt_trace_class_set_environment_entry_integer(
out_trace_class, value_name,
- bt_value_integer_get(value));
+ bt_value_signed_integer_get(
+ value));
} else if (bt_value_is_string(value)) {
trace_class_status =
bt_trace_class_set_environment_entry_string(
} else if (dom_print) {
g_string_append(pretty->string, ":");
}
- value = bt_value_integer_get(vpid_value);
+ value = bt_value_signed_integer_get(vpid_value);
g_string_append_printf(pretty->string,
"(%" PRId64 ")", value);
dom_print = 1;
AM_CPPFLAGS += -I$(top_srcdir)/plugins
noinst_LTLIBRARIES = libbabeltrace-plugin-counter-cc.la
-libbabeltrace_plugin_counter_cc_la_SOURCES = counter.c counter.h
+libbabeltrace_plugin_counter_cc_la_SOURCES = \
+ counter.c \
+ counter.h \
+ logging.c \
+ logging.h
* SOFTWARE.
*/
+#define BT_LOG_TAG "PLUGIN-UTILS-COUNTER-FLT"
+#include "logging.h"
+
#include <babeltrace/babeltrace.h>
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/common-internal.h>
counter->last_printed_total = -1ULL;
counter->step = 10000;
step = bt_value_map_borrow_entry_value_const(params, "step");
- if (step && bt_value_is_integer(step)) {
- int64_t val;
-
- val = bt_value_integer_get(step);
- if (val >= 0) {
- counter->step = (uint64_t) val;
+ if (step) {
+ if (!bt_value_is_unsigned_integer(step)) {
+ BT_LOGE("`step` parameter: expecting an unsigned integer value: "
+ "type=%s", bt_common_value_type_string(
+ bt_value_get_type(step)));
+ goto error;
}
+
+ counter->step = bt_value_unsigned_integer_get(step);
}
hide_zero = bt_value_map_borrow_entry_value_const(params, "hide-zero");
- if (hide_zero && bt_value_is_bool(hide_zero)) {
- bt_bool val;
+ if (hide_zero) {
+ if (!bt_value_is_bool(hide_zero)) {
+ BT_LOGE("`hide-zero` parameter: expecting a boolean value: "
+ "type=%s", bt_common_value_type_string(
+ bt_value_get_type(hide_zero)));
+ goto error;
+ }
- val = bt_value_bool_get(hide_zero);
- counter->hide_zero = (bool) val;
+ counter->hide_zero = (bool) bt_value_bool_get(hide_zero);
}
bt_self_component_set_data(
error:
destroy_private_counter_data(counter);
+ ret = BT_SELF_COMPONENT_STATUS_ERROR;
end:
return ret;
--- /dev/null
+/*
+ * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#define BT_LOG_OUTPUT_LEVEL bt_plugin_utils_counter_log_level
+#include <babeltrace/logging-internal.h>
+
+BT_LOG_INIT_LOG_LEVEL(bt_plugin_utils_counter_log_level,
+ "BABELTRACE_FLT_UTILS_COUNTER_LOG_LEVEL");
--- /dev/null
+#ifndef PLUGINS_UTILS_MUXER_LOGGING_H
+#define PLUGINS_UTILS_MUXER_LOGGING_H
+
+/*
+ * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#define BT_LOG_OUTPUT_LEVEL bt_plugin_utils_muxer_log_level
+#include <babeltrace/logging-internal.h>
+
+BT_LOG_LEVEL_EXTERN_SYMBOL(bt_plugin_utils_muxer_log_level);
+
+#endif /* PLUGINS_UTILS_MUXER_LOGGING_H */
const char *arg;
char tmp_arg[64];
- if (bt_value_is_integer(param)) {
- int64_t value = bt_value_integer_get(param);
+ if (bt_value_is_signed_integer(param)) {
+ int64_t value = bt_value_signed_integer_get(param);
/*
* Just convert it to a temporary string to handle
# the current value of `int_value_obj`, so after this the value
# of the object is 5. This does not compare to 5.3, which is
# why we also use the `int()` type here.
- if type(self._def) is bt2.IntegerValue:
+ if isinstance(self._def, bt2._IntegerValue):
rv = int(rv)
self.assertEqual(r, rv)
)
-def _inject_numeric_testing_methods(cls):
+def _inject_numeric_testing_methods(cls, has_neg=True):
def test_binop_name(suffix):
return 'test_binop_{}_{}'.format(name, suffix)
# inject testing methods for each binary operation
for name, binop in _BINOPS:
-
setattr(cls, test_binop_name('invalid_unknown'), partialmethod(_TestNumericValue._test_binop_invalid_unknown, op=binop))
setattr(cls, test_binop_name('invalid_none'), partialmethod(_TestNumericValue._test_binop_invalid_none, op=binop))
setattr(cls, test_binop_name('type_true'), partialmethod(_TestNumericValue._test_binop_type_true, op=binop))
setattr(cls, test_binop_name('lhs_value_same_true'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_true, op=binop))
setattr(cls, test_binop_name('lhs_value_same_pos_int'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_pos_int, op=binop))
setattr(cls, test_binop_name('lhs_value_same_pos_vint'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_pos_vint, op=binop))
- setattr(cls, test_binop_name('type_neg_int'), partialmethod(_TestNumericValue._test_binop_type_neg_int, op=binop))
- setattr(cls, test_binop_name('type_neg_vint'), partialmethod(_TestNumericValue._test_binop_type_neg_vint, op=binop))
- setattr(cls, test_binop_name('value_neg_int'), partialmethod(_TestNumericValue._test_binop_value_neg_int, op=binop))
- setattr(cls, test_binop_name('value_neg_vint'), partialmethod(_TestNumericValue._test_binop_value_neg_vint, op=binop))
- setattr(cls, test_binop_name('lhs_addr_same_neg_int'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_neg_int, op=binop))
- setattr(cls, test_binop_name('lhs_addr_same_neg_vint'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_neg_vint, op=binop))
- setattr(cls, test_binop_name('lhs_value_same_neg_int'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_neg_int, op=binop))
- setattr(cls, test_binop_name('lhs_value_same_neg_vint'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_neg_vint, op=binop))
+
+ if has_neg:
+ setattr(cls, test_binop_name('type_neg_int'), partialmethod(_TestNumericValue._test_binop_type_neg_int, op=binop))
+ setattr(cls, test_binop_name('type_neg_vint'), partialmethod(_TestNumericValue._test_binop_type_neg_vint, op=binop))
+ setattr(cls, test_binop_name('value_neg_int'), partialmethod(_TestNumericValue._test_binop_value_neg_int, op=binop))
+ setattr(cls, test_binop_name('value_neg_vint'), partialmethod(_TestNumericValue._test_binop_value_neg_vint, op=binop))
+ setattr(cls, test_binop_name('lhs_addr_same_neg_int'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_neg_int, op=binop))
+ setattr(cls, test_binop_name('lhs_addr_same_neg_vint'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_neg_vint, op=binop))
+ setattr(cls, test_binop_name('lhs_value_same_neg_int'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_neg_int, op=binop))
+ setattr(cls, test_binop_name('lhs_value_same_neg_vint'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_neg_vint, op=binop))
+
setattr(cls, test_binop_name('type_false'), partialmethod(_TestNumericValue._test_binop_type_false, op=binop))
setattr(cls, test_binop_name('type_zero_int'), partialmethod(_TestNumericValue._test_binop_type_zero_int, op=binop))
setattr(cls, test_binop_name('type_zero_vint'), partialmethod(_TestNumericValue._test_binop_type_zero_vint, op=binop))
setattr(cls, test_binop_name('lhs_value_same_false'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_false, op=binop))
setattr(cls, test_binop_name('lhs_value_same_zero_int'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_zero_int, op=binop))
setattr(cls, test_binop_name('lhs_value_same_zero_vint'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_zero_vint, op=binop))
+
+ if has_neg:
+ setattr(cls, test_binop_name('type_neg_float'), partialmethod(_TestNumericValue._test_binop_type_neg_float, op=binop))
+ setattr(cls, test_binop_name('type_neg_vfloat'), partialmethod(_TestNumericValue._test_binop_type_neg_vfloat, op=binop))
+ setattr(cls, test_binop_name('value_neg_float'), partialmethod(_TestNumericValue._test_binop_value_neg_float, op=binop))
+ setattr(cls, test_binop_name('value_neg_vfloat'), partialmethod(_TestNumericValue._test_binop_value_neg_vfloat, op=binop))
+ setattr(cls, test_binop_name('lhs_addr_same_neg_float'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_neg_float, op=binop))
+ setattr(cls, test_binop_name('lhs_addr_same_neg_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_neg_vfloat, op=binop))
+ setattr(cls, test_binop_name('lhs_value_same_neg_float'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_neg_float, op=binop))
+ setattr(cls, test_binop_name('lhs_value_same_neg_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_neg_vfloat, op=binop))
+
setattr(cls, test_binop_name('type_pos_float'), partialmethod(_TestNumericValue._test_binop_type_pos_float, op=binop))
- setattr(cls, test_binop_name('type_neg_float'), partialmethod(_TestNumericValue._test_binop_type_neg_float, op=binop))
setattr(cls, test_binop_name('type_pos_vfloat'), partialmethod(_TestNumericValue._test_binop_type_pos_vfloat, op=binop))
- setattr(cls, test_binop_name('type_neg_vfloat'), partialmethod(_TestNumericValue._test_binop_type_neg_vfloat, op=binop))
setattr(cls, test_binop_name('value_pos_float'), partialmethod(_TestNumericValue._test_binop_value_pos_float, op=binop))
- setattr(cls, test_binop_name('value_neg_float'), partialmethod(_TestNumericValue._test_binop_value_neg_float, op=binop))
setattr(cls, test_binop_name('value_pos_vfloat'), partialmethod(_TestNumericValue._test_binop_value_pos_vfloat, op=binop))
- setattr(cls, test_binop_name('value_neg_vfloat'), partialmethod(_TestNumericValue._test_binop_value_neg_vfloat, op=binop))
setattr(cls, test_binop_name('lhs_addr_same_pos_float'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_pos_float, op=binop))
- setattr(cls, test_binop_name('lhs_addr_same_neg_float'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_neg_float, op=binop))
setattr(cls, test_binop_name('lhs_addr_same_pos_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_pos_vfloat, op=binop))
- setattr(cls, test_binop_name('lhs_addr_same_neg_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_neg_vfloat, op=binop))
setattr(cls, test_binop_name('lhs_value_same_pos_float'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_pos_float, op=binop))
- setattr(cls, test_binop_name('lhs_value_same_neg_float'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_neg_float, op=binop))
setattr(cls, test_binop_name('lhs_value_same_pos_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_pos_vfloat, op=binop))
- setattr(cls, test_binop_name('lhs_value_same_neg_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_neg_vfloat, op=binop))
setattr(cls, test_binop_name('type_zero_float'), partialmethod(_TestNumericValue._test_binop_type_zero_float, op=binop))
setattr(cls, test_binop_name('type_zero_vfloat'), partialmethod(_TestNumericValue._test_binop_type_zero_vfloat, op=binop))
setattr(cls, test_binop_name('value_zero_float'), partialmethod(_TestNumericValue._test_binop_value_zero_float, op=binop))
setattr(cls, test_ibinop_name('type_pos_vint'), partialmethod(_TestNumericValue._test_ibinop_type_pos_vint, op=ibinop))
setattr(cls, test_ibinop_name('value_pos_int'), partialmethod(_TestNumericValue._test_ibinop_value_pos_int, op=ibinop))
setattr(cls, test_ibinop_name('value_pos_vint'), partialmethod(_TestNumericValue._test_ibinop_value_pos_vint, op=ibinop))
- setattr(cls, test_ibinop_name('type_neg_int'), partialmethod(_TestNumericValue._test_ibinop_type_neg_int, op=ibinop))
- setattr(cls, test_ibinop_name('type_neg_vint'), partialmethod(_TestNumericValue._test_ibinop_type_neg_vint, op=ibinop))
- setattr(cls, test_ibinop_name('value_neg_int'), partialmethod(_TestNumericValue._test_ibinop_value_neg_int, op=ibinop))
- setattr(cls, test_ibinop_name('value_neg_vint'), partialmethod(_TestNumericValue._test_ibinop_value_neg_vint, op=ibinop))
+
+ if has_neg:
+ setattr(cls, test_ibinop_name('type_neg_int'), partialmethod(_TestNumericValue._test_ibinop_type_neg_int, op=ibinop))
+ setattr(cls, test_ibinop_name('type_neg_vint'), partialmethod(_TestNumericValue._test_ibinop_type_neg_vint, op=ibinop))
+ setattr(cls, test_ibinop_name('value_neg_int'), partialmethod(_TestNumericValue._test_ibinop_value_neg_int, op=ibinop))
+ setattr(cls, test_ibinop_name('value_neg_vint'), partialmethod(_TestNumericValue._test_ibinop_value_neg_vint, op=ibinop))
+
setattr(cls, test_ibinop_name('type_false'), partialmethod(_TestNumericValue._test_ibinop_type_false, op=ibinop))
setattr(cls, test_ibinop_name('value_false'), partialmethod(_TestNumericValue._test_ibinop_value_false, op=ibinop))
setattr(cls, test_ibinop_name('type_zero_int'), partialmethod(_TestNumericValue._test_ibinop_type_zero_int, op=ibinop))
setattr(cls, test_ibinop_name('value_zero_int'), partialmethod(_TestNumericValue._test_ibinop_value_zero_int, op=ibinop))
setattr(cls, test_ibinop_name('value_zero_vint'), partialmethod(_TestNumericValue._test_ibinop_value_zero_vint, op=ibinop))
setattr(cls, test_ibinop_name('type_pos_float'), partialmethod(_TestNumericValue._test_ibinop_type_pos_float, op=ibinop))
- setattr(cls, test_ibinop_name('type_neg_float'), partialmethod(_TestNumericValue._test_ibinop_type_neg_float, op=ibinop))
+
+ if has_neg:
+ setattr(cls, test_ibinop_name('type_neg_float'), partialmethod(_TestNumericValue._test_ibinop_type_neg_float, op=ibinop))
+ setattr(cls, test_ibinop_name('type_neg_vfloat'), partialmethod(_TestNumericValue._test_ibinop_type_neg_vfloat, op=ibinop))
+ setattr(cls, test_ibinop_name('value_neg_float'), partialmethod(_TestNumericValue._test_ibinop_value_neg_float, op=ibinop))
+ setattr(cls, test_ibinop_name('value_neg_vfloat'), partialmethod(_TestNumericValue._test_ibinop_value_neg_vfloat, op=ibinop))
+
setattr(cls, test_ibinop_name('type_pos_vfloat'), partialmethod(_TestNumericValue._test_ibinop_type_pos_vfloat, op=ibinop))
- setattr(cls, test_ibinop_name('type_neg_vfloat'), partialmethod(_TestNumericValue._test_ibinop_type_neg_vfloat, op=ibinop))
setattr(cls, test_ibinop_name('value_pos_float'), partialmethod(_TestNumericValue._test_ibinop_value_pos_float, op=ibinop))
- setattr(cls, test_ibinop_name('value_neg_float'), partialmethod(_TestNumericValue._test_ibinop_value_neg_float, op=ibinop))
setattr(cls, test_ibinop_name('value_pos_vfloat'), partialmethod(_TestNumericValue._test_ibinop_value_pos_vfloat, op=ibinop))
- setattr(cls, test_ibinop_name('value_neg_vfloat'), partialmethod(_TestNumericValue._test_ibinop_value_neg_vfloat, op=ibinop))
setattr(cls, test_ibinop_name('type_zero_float'), partialmethod(_TestNumericValue._test_ibinop_type_zero_float, op=ibinop))
setattr(cls, test_ibinop_name('type_zero_vfloat'), partialmethod(_TestNumericValue._test_ibinop_type_zero_vfloat, op=ibinop))
setattr(cls, test_ibinop_name('value_zero_float'), partialmethod(_TestNumericValue._test_ibinop_value_zero_float, op=ibinop))
def test_create_int_pos(self):
raw = 23
v = bt2.create_value(raw)
- self.assertIsInstance(v, bt2.IntegerValue)
+ self.assertIsInstance(v, bt2.SignedIntegerValue)
self.assertEqual(v, raw)
def test_create_int_neg(self):
raw = -23
v = bt2.create_value(raw)
- self.assertIsInstance(v, bt2.IntegerValue)
+ self.assertIsInstance(v, bt2.SignedIntegerValue)
self.assertEqual(v, raw)
def test_create_float_pos(self):
self.assertNotEqual(self._t, False)
-class IntegerValueTestCase(_TestNumericValue, unittest.TestCase):
+class _TestIntegerValue(_TestNumericValue):
def setUp(self):
self._pv = 23
- self._nv = -52
- self._ip = bt2.IntegerValue(self._pv)
- self._in = bt2.IntegerValue(self._nv)
+ self._ip = self._CLS(self._pv)
self._def = self._ip
self._def_value = self._pv
- self._def_new_value = -101
+ self._def_new_value = 101
def tearDown(self):
del self._ip
- del self._in
del self._def
del self._def_value
return self.assertRaisesRegex(ValueError, r"expecting an unsigned 64-bit integral value")
def test_create_default(self):
- i = bt2.IntegerValue()
+ i = self._CLS()
self.assertEqual(i, 0)
def test_create_pos(self):
def test_create_neg(self):
self.assertEqual(self._in, self._nv)
- def test_create_pos_too_big(self):
- with self._assert_expecting_int64():
- i = bt2.IntegerValue(2 ** 63)
-
- def test_create_neg_too_big(self):
- with self._assert_expecting_int64():
- i = bt2.IntegerValue(-(2 ** 63) - 1)
-
def test_create_from_vint(self):
- i = bt2.IntegerValue(self._ip)
+ i = self._CLS(self._ip)
self.assertEqual(i, self._pv)
def test_create_from_false(self):
- i = bt2.IntegerValue(False)
+ i = self._CLS(False)
self.assertFalse(i)
def test_create_from_true(self):
- i = bt2.IntegerValue(True)
+ i = self._CLS(True)
self.assertTrue(i)
def test_create_from_float(self):
- i = bt2.IntegerValue(99.6)
+ i = self._CLS(99.6)
self.assertEqual(i, 99)
def test_create_from_vfloat(self):
f = bt2.create_value(17.5)
- i = bt2.IntegerValue(f)
+ i = self._CLS(f)
self.assertEqual(i, 17)
def test_create_from_unknown(self):
pass
with self._assert_expecting_int():
- i = bt2.IntegerValue(A())
+ i = self._CLS(A())
def test_create_from_varray(self):
with self._assert_expecting_int():
- i = bt2.IntegerValue(bt2.ArrayValue())
+ i = self._CLS(bt2.ArrayValue())
def test_assign_true(self):
raw = True
self._def.value = raw
self.assertEqual(self._def, raw)
- def test_assign_neg_int(self):
- raw = -13
- self._def.value = raw
- self.assertEqual(self._def, raw)
-
def test_assign_vint(self):
raw = 999
self._def.value = bt2.create_value(raw)
self.assertEqual(self._def, int(raw))
-_inject_numeric_testing_methods(IntegerValueTestCase)
+class SignedIntegerValueTestCase(_TestIntegerValue, unittest.TestCase):
+ _CLS = bt2.SignedIntegerValue
+
+ def setUp(self):
+ super().setUp()
+ self._nv = -52
+ self._in = self._CLS(self._nv)
+ self._def_new_value = -101
+
+ def tearDown(self):
+ super().tearDown()
+ del self._in
+
+ def test_create_neg(self):
+ self.assertEqual(self._in, self._nv)
+
+ def test_create_pos_too_big(self):
+ with self._assert_expecting_int64():
+ i = self._CLS(2 ** 63)
+
+ def test_create_neg_too_big(self):
+ with self._assert_expecting_int64():
+ i = self._CLS(-(2 ** 63) - 1)
+
+ def test_assign_neg_int(self):
+ raw = -13
+ self._def.value = raw
+ self.assertEqual(self._def, raw)
+
+
+_inject_numeric_testing_methods(SignedIntegerValueTestCase)
+
+
+class UnsignedIntegerValueTestCase(_TestIntegerValue, unittest.TestCase):
+ _CLS = bt2.UnsignedIntegerValue
+
+ def test_create_pos_too_big(self):
+ with self._assert_expecting_uint64():
+ i = self._CLS(2 ** 64)
+
+ def test_create_neg(self):
+ with self._assert_expecting_uint64():
+ i = self._CLS(-1)
+
+
+_inject_numeric_testing_methods(UnsignedIntegerValueTestCase, False)
class RealValueTestCase(_TestNumericValue, unittest.TestCase):
#include <string.h>
#include "tap/tap.h"
-#define NR_TESTS 147
+#define NR_TESTS 166
static
void test_null(void)
}
static
-void test_integer(void)
+void test_unsigned_integer(void)
{
- int64_t value;
+ uint64_t value;
bt_value *obj;
- obj = bt_value_integer_create();
- ok(obj && bt_value_is_integer(obj),
- "bt_value_integer_create() returns an integer value object");
+ obj = bt_value_unsigned_integer_create();
+ ok(obj && bt_value_is_unsigned_integer(obj),
+ "bt_value_unsigned_integer_create() returns an unsigned integer value object");
value = 1961;
- value = bt_value_integer_get(obj);
- ok(value == 0, "default integer value object value is 0");
+ value = bt_value_unsigned_integer_get(obj);
+ ok(value == 0, "default unsigned integer value object value is 0");
- bt_value_integer_set(obj, -98765);
- value = bt_value_integer_get(obj);
- ok(value == -98765, "bt_private_integer_bool_set() works");
+ bt_value_unsigned_integer_set(obj, 98765);
+ value = bt_value_unsigned_integer_get(obj);
+ ok(value == 98765, "bt_value_unsigned_integer_bool_set() works");
BT_VALUE_PUT_REF_AND_RESET(obj);
- pass("putting an existing integer value object does not cause a crash")
+ pass("putting an existing unsigned integer value object does not cause a crash")
- obj = bt_value_integer_create_init(321456987);
- ok(obj && bt_value_is_integer(obj),
- "bt_value_integer_create_init() returns an integer value object");
- value = bt_value_integer_get(obj);
+ obj = bt_value_unsigned_integer_create_init(321456987);
+ ok(obj && bt_value_is_unsigned_integer(obj),
+ "bt_value_unsigned_integer_create_init() returns an unsigned integer value object");
+ value = bt_value_unsigned_integer_get(obj);
ok(value == 321456987,
- "bt_value_integer_create_init() sets the appropriate initial value");
+ "bt_value_unsigned_integer_create_init() sets the appropriate initial value");
+
+ BT_VALUE_PUT_REF_AND_RESET(obj);
+}
+
+static
+void test_signed_integer(void)
+{
+ int64_t value;
+ bt_value *obj;
+
+ obj = bt_value_signed_integer_create();
+ ok(obj && bt_value_is_signed_integer(obj),
+ "bt_value_signed_integer_create() returns a signed integer value object");
+
+ value = 1961;
+ value = bt_value_signed_integer_get(obj);
+ ok(value == 0, "default signed integer value object value is 0");
+
+ bt_value_signed_integer_set(obj, 98765);
+ value = bt_value_signed_integer_get(obj);
+ ok(value == 98765, "bt_value_signed_integer_bool_set() works");
+
+ BT_VALUE_PUT_REF_AND_RESET(obj);
+ pass("putting an existing signed integer value object does not cause a crash")
+
+ obj = bt_value_signed_integer_create_init(-321456987);
+ ok(obj && bt_value_is_signed_integer(obj),
+ "bt_value_signed_integer_create_init() returns a signed integer value object");
+ value = bt_value_signed_integer_get(obj);
+ ok(value == -321456987,
+ "bt_value_signed_integer_create_init() sets the appropriate initial value");
BT_VALUE_PUT_REF_AND_RESET(obj);
}
ok(bt_value_array_is_empty(array_obj),
"initial array value object size is 0");
- obj = bt_value_integer_create_init(345);
+ obj = bt_value_unsigned_integer_create_init(345);
ret = bt_value_array_append_element(array_obj, obj);
BT_VALUE_PUT_REF_AND_RESET(obj);
+ obj = bt_value_signed_integer_create_init(-507);
+ ret |= bt_value_array_append_element(array_obj, obj);
+ BT_VALUE_PUT_REF_AND_RESET(obj);
obj = bt_value_real_create_init(-17.45);
ret |= bt_value_array_append_element(array_obj, obj);
BT_VALUE_PUT_REF_AND_RESET(obj);
ret |= bt_value_array_append_element(array_obj,
bt_value_null);
ok(!ret, "bt_value_array_append_element() succeeds");
- ok(bt_value_array_get_size(array_obj) == 4,
+ ok(bt_value_array_get_size(array_obj) == 5,
"appending an element to an array value object increment its size");
obj = bt_value_array_borrow_element_by_index(array_obj, 0);
- ok(obj && bt_value_is_integer(obj),
- "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (integer)");
- int_value = bt_value_integer_get(obj);
+ ok(obj && bt_value_is_unsigned_integer(obj),
+ "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (unsigned integer)");
+ int_value = bt_value_unsigned_integer_get(obj);
ok(int_value == 345,
- "bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (integer)");
+ "bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (unsigned integer)");
obj = bt_value_array_borrow_element_by_index(array_obj, 1);
+ ok(obj && bt_value_is_signed_integer(obj),
+ "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (signed integer)");
+ int_value = bt_value_signed_integer_get(obj);
+ ok(int_value == -507,
+ "bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (signed integer)");
+ obj = bt_value_array_borrow_element_by_index(array_obj, 2);
ok(obj && bt_value_is_real(obj),
"bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (real number)");
real_value = bt_value_real_get(obj);
ok(real_value == -17.45,
"bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (real number)");
- obj = bt_value_array_borrow_element_by_index(array_obj, 2);
+ obj = bt_value_array_borrow_element_by_index(array_obj, 3);
ok(obj && bt_value_is_bool(obj),
"bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (boolean)");
bool_value = bt_value_bool_get(obj);
ok(bool_value,
"bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (boolean)");
- obj = bt_value_array_borrow_element_by_index(array_obj, 3);
+ obj = bt_value_array_borrow_element_by_index(array_obj, 4);
ok(obj == bt_value_null,
"bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (null)");
- obj = bt_value_integer_create_init(1001);
+ obj = bt_value_signed_integer_create_init(1001);
BT_ASSERT(obj);
ok(!bt_value_array_set_element_by_index(array_obj, 2, obj),
"bt_value_array_set_element_by_index() succeeds");
BT_VALUE_PUT_REF_AND_RESET(obj);
obj = bt_value_array_borrow_element_by_index(array_obj, 2);
- ok(obj && bt_value_is_integer(obj),
+ ok(obj && bt_value_is_signed_integer(obj),
"bt_value_array_set_element_by_index() inserts an value object with the appropriate type");
- int_value = bt_value_integer_get(obj);
+ int_value = bt_value_signed_integer_get(obj);
BT_ASSERT(!ret);
ok(int_value == 1001,
"bt_value_array_set_element_by_index() inserts an value object with the appropriate value");
ret = bt_value_array_append_bool_element(array_obj,
BT_FALSE);
ok(!ret, "bt_value_array_append_bool_element() succeeds");
- ret = bt_value_array_append_integer_element(array_obj,
+ ret = bt_value_array_append_unsigned_integer_element(array_obj,
98765);
- ok(!ret, "bt_value_array_append_integer_element() succeeds");
+ ok(!ret, "bt_value_array_append_unsigned_integer_element() succeeds");
+ ret = bt_value_array_append_signed_integer_element(array_obj,
+ -10101);
+ ok(!ret, "bt_value_array_append_signed_integer_element() succeeds");
ret = bt_value_array_append_real_element(array_obj,
2.49578);
ok(!ret, "bt_value_array_append_real_element() succeeds");
ret = bt_value_array_append_empty_map_element(array_obj);
ok(!ret, "bt_value_array_append_empty_map_element() succeeds");
- ok(bt_value_array_get_size(array_obj) == 10,
+ ok(bt_value_array_get_size(array_obj) == 12,
"the bt_value_array_append_element_*() functions increment the array value object's size");
ok(!bt_value_array_is_empty(array_obj),
"map value object is not empty");
- obj = bt_value_array_borrow_element_by_index(array_obj, 4);
+ obj = bt_value_array_borrow_element_by_index(array_obj, 5);
ok(obj && bt_value_is_bool(obj),
"bt_value_array_append_bool_element() appends a boolean value object");
bool_value = bt_value_bool_get(obj);
ok(!bool_value,
"bt_value_array_append_bool_element() appends the appropriate value");
- obj = bt_value_array_borrow_element_by_index(array_obj, 5);
- ok(obj && bt_value_is_integer(obj),
- "bt_value_array_append_integer_element() appends an integer value object");
- int_value = bt_value_integer_get(obj);
- ok(int_value == 98765,
- "bt_value_array_append_integer_element() appends the appropriate value");
obj = bt_value_array_borrow_element_by_index(array_obj, 6);
+ ok(obj && bt_value_is_unsigned_integer(obj),
+ "bt_value_array_append_unsigned_integer_element() appends an unsigned integer value object");
+ int_value = bt_value_unsigned_integer_get(obj);
+ ok(int_value == 98765,
+ "bt_value_array_append_unsigned_integer_element() appends the appropriate value");
+ obj = bt_value_array_borrow_element_by_index(array_obj, 7);
+ ok(obj && bt_value_is_signed_integer(obj),
+ "bt_value_array_append_signed_integer_element() appends a signed integer value object");
+ int_value = bt_value_signed_integer_get(obj);
+ ok(int_value == -10101,
+ "bt_value_array_append_signed_integer_element() appends the appropriate value");
+ obj = bt_value_array_borrow_element_by_index(array_obj, 8);
ok(obj && bt_value_is_real(obj),
"bt_value_array_append_real_element() appends a real number value object");
real_value = bt_value_real_get(obj);
ok(real_value == 2.49578,
"bt_value_array_append_real_element() appends the appropriate value");
- obj = bt_value_array_borrow_element_by_index(array_obj, 7);
+ obj = bt_value_array_borrow_element_by_index(array_obj, 9);
ok(obj && bt_value_is_string(obj),
"bt_value_array_append_string_element() appends a string value object");
string_value = bt_value_string_get(obj);
ok(!ret && string_value && !strcmp(string_value, "bt_value"),
"bt_value_array_append_string_element() appends the appropriate value");
- obj = bt_value_array_borrow_element_by_index(array_obj, 8);
+ obj = bt_value_array_borrow_element_by_index(array_obj, 10);
ok(obj && bt_value_is_array(obj),
"bt_value_array_append_empty_array_element() appends an array value object");
ok(bt_value_array_is_empty(obj),
"bt_value_array_append_empty_array_element() an empty array value object");
- obj = bt_value_array_borrow_element_by_index(array_obj, 9);
+ obj = bt_value_array_borrow_element_by_index(array_obj, 11);
ok(obj && bt_value_is_map(obj),
"bt_value_array_append_empty_map_element() appends a map value object");
ok(bt_value_map_is_empty(obj),
struct map_foreach_checklist {
bt_bool bool1;
+ bt_bool uint;
bt_bool int1;
bt_bool real1;
bt_bool null1;
fail("test_map_foreach_cb_check(): \"bt_bool\" value object has the wrong value");
}
}
+ } else if (!strcmp(key, "uint")) {
+ if (checklist->uint) {
+ fail("test_map_foreach_cb_check(): duplicate key \"uint\"");
+ } else {
+ uint64_t val = 0;
+
+ val = bt_value_unsigned_integer_get(object);
+
+ if (val == 19457) {
+ pass("test_map_foreach_cb_check(): \"uint\" value object has the right value");
+ checklist->uint = BT_TRUE;
+ } else {
+ fail("test_map_foreach_cb_check(): \"uint\" value object has the wrong value");
+ }
+ }
} else if (!strcmp(key, "int")) {
if (checklist->int1) {
fail("test_map_foreach_cb_check(): duplicate key \"int\"");
} else {
int64_t val = 0;
- val = bt_value_integer_get(object);
+ val = bt_value_signed_integer_get(object);
- if (val == 19457) {
+ if (val == -12345) {
pass("test_map_foreach_cb_check(): \"int\" value object has the right value");
checklist->int1 = BT_TRUE;
} else {
} else {
int64_t val = 0;
- val = bt_value_integer_get(object);
+ val = bt_value_signed_integer_get(object);
if (val == 98765) {
pass("test_map_foreach_cb_check(): \"int2\" value object has the right value");
ok(bt_value_map_get_size(map_obj) == 0,
"initial map value object size is 0");
- obj = bt_value_integer_create_init(19457);
- ret = bt_value_map_insert_entry(map_obj, "int", obj);
+ obj = bt_value_unsigned_integer_create_init(19457);
+ ret = bt_value_map_insert_entry(map_obj, "uint", obj);
+ BT_VALUE_PUT_REF_AND_RESET(obj);
+ obj = bt_value_signed_integer_create_init(-12345);
+ ret |= bt_value_map_insert_entry(map_obj, "int", obj);
BT_VALUE_PUT_REF_AND_RESET(obj);
obj = bt_value_real_create_init(5.444);
ret |= bt_value_map_insert_entry(map_obj, "real", obj);
ret |= bt_value_map_insert_entry(map_obj, "null",
bt_value_null);
ok(!ret, "bt_value_map_insert_entry() succeeds");
- ok(bt_value_map_get_size(map_obj) == 4,
+ ok(bt_value_map_get_size(map_obj) == 5,
"inserting an element into a map value object increment its size");
obj = bt_value_bool_create_init(BT_TRUE);
real_value = bt_value_real_get(obj);
ok(real_value == 5.444,
"bt_value_map_borrow_entry_value() returns an value object with the appropriate value (real)");
- obj = bt_value_map_borrow_entry_value(map_obj, "int");
- ok(obj && bt_value_is_integer(obj),
- "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (integer)");
- int_value = bt_value_integer_get(obj);
+ obj = bt_value_map_borrow_entry_value(map_obj, "uint");
+ ok(obj && bt_value_is_unsigned_integer(obj),
+ "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (unsigned integer)");
+ int_value = bt_value_unsigned_integer_get(obj);
ok(int_value == 19457,
- "bt_value_map_borrow_entry_value() returns an value object with the appropriate value (integer)");
+ "bt_value_map_borrow_entry_value() returns an value object with the appropriate value (unsigned integer)");
+ obj = bt_value_map_borrow_entry_value(map_obj, "int");
+ ok(obj && bt_value_is_signed_integer(obj),
+ "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (signed integer)");
+ int_value = bt_value_signed_integer_get(obj);
+ ok(int_value == -12345,
+ "bt_value_map_borrow_entry_value() returns an value object with the appropriate value (signed integer)");
obj = bt_value_map_borrow_entry_value(map_obj, "null");
ok(obj && bt_value_is_null(obj),
"bt_value_map_borrow_entry_value() returns an value object with the appropriate type (null)");
ret = bt_value_map_insert_bool_entry(map_obj, "bool2",
BT_TRUE);
ok(!ret, "bt_value_map_insert_bool_entry() succeeds");
- ret = bt_value_map_insert_integer_entry(map_obj, "int2",
+ ret = bt_value_map_insert_signed_integer_entry(map_obj, "int2",
98765);
- ok(!ret, "bt_value_map_insert_integer_entry() succeeds");
+ ok(!ret, "bt_value_map_insert_signed_integer_entry() succeeds");
ret = bt_value_map_insert_real_entry(map_obj, "real2",
-49.0001);
ok(!ret, "bt_value_map_insert_real_entry() succeeds");
ret = bt_value_map_insert_empty_map_entry(map_obj, "map2");
ok(!ret, "bt_value_map_insert_empty_map_entry() succeeds");
- ok(bt_value_map_get_size(map_obj) == 10,
+ ok(bt_value_map_get_size(map_obj) == 11,
"the bt_value_map_insert*() functions increment the map value object's size");
ok(!bt_value_map_has_entry(map_obj, "hello"),
"map value object does not have key \"hello\"");
ok(bt_value_map_has_entry(map_obj, "bt_bool"),
"map value object has key \"bt_bool\"");
+ ok(bt_value_map_has_entry(map_obj, "uint"),
+ "map value object has key \"uint\"");
ok(bt_value_map_has_entry(map_obj, "int"),
"map value object has key \"int\"");
ok(bt_value_map_has_entry(map_obj, "real"),
&checklist);
ok(ret == BT_VALUE_STATUS_OK,
"bt_value_map_foreach_entry() succeeds with test_map_foreach_cb_check()");
- ok(checklist.bool1 && checklist.int1 && checklist.real1 &&
- checklist.null1 && checklist.bool2 && checklist.int2 &&
- checklist.real2 && checklist.string2 &&
+ ok(checklist.bool1 && checklist.uint && checklist.int1 &&
+ checklist.real1 && checklist.null1 && checklist.bool2 &&
+ checklist.int2 && checklist.real2 && checklist.string2 &&
checklist.array2 && checklist.map2,
"bt_value_map_foreach_entry() iterates over all the map value object's elements");
{
test_null();
test_bool();
- test_integer();
+ test_unsigned_integer();
+ test_signed_integer();
test_real();
test_string();
test_array();
}
static
-void test_compare_integer(void)
+void test_compare_unsigned_integer(void)
{
bt_value *int1 =
- bt_value_integer_create_init(10);
+ bt_value_unsigned_integer_create_init(10);
bt_value *int2 =
- bt_value_integer_create_init(-23);
+ bt_value_unsigned_integer_create_init(23);
bt_value *int3 =
- bt_value_integer_create_init(10);
+ bt_value_unsigned_integer_create_init(10);
BT_ASSERT(int1 && int2 && int3);
ok(!bt_value_compare(bt_value_null,
int1),
- "cannot compare null value object and integer value object");
- ok(!bt_value_compare(int1,
- int2),
- "integer value objects are not equivalent (10 and -23)");
- ok(bt_value_compare(int1,
- int3),
- "integer value objects are equivalent (10 and 10)");
+ "cannot compare null value object and unsigned integer value object");
+ ok(!bt_value_compare(int1, int2),
+ "unsigned integer value objects are not equivalent (10 and 23)");
+ ok(bt_value_compare(int1, int3),
+ "unsigned integer value objects are equivalent (10 and 10)");
+
+ BT_VALUE_PUT_REF_AND_RESET(int1);
+ BT_VALUE_PUT_REF_AND_RESET(int2);
+ BT_VALUE_PUT_REF_AND_RESET(int3);
+}
+
+void test_compare_signed_integer(void)
+{
+ bt_value *int1 =
+ bt_value_signed_integer_create_init(10);
+ bt_value *int2 =
+ bt_value_signed_integer_create_init(-23);
+ bt_value *int3 =
+ bt_value_signed_integer_create_init(10);
+
+ BT_ASSERT(int1 && int2 && int3);
+ ok(!bt_value_compare(bt_value_null,
+ int1),
+ "cannot compare null value object and signed integer value object");
+ ok(!bt_value_compare(int1, int2),
+ "signed integer value objects are not equivalent (10 and -23)");
+ ok(bt_value_compare(int1, int3),
+ "signed integer value objects are equivalent (10 and 10)");
BT_VALUE_PUT_REF_AND_RESET(int1);
BT_VALUE_PUT_REF_AND_RESET(int2);
BT_ASSERT(array1 && array2 && array3);
- ok(bt_value_compare(array1,
- array2),
+ ok(bt_value_compare(array1, array2),
"empty array value objects are equivalent");
- status = bt_value_array_append_integer_element(array1, 23);
+ status = bt_value_array_append_signed_integer_element(array1, 23);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
status = bt_value_array_append_real_element(array1, 14.2);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
status = bt_value_array_append_real_element(array2, 14.2);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
- status = bt_value_array_append_integer_element(array2, 23);
+ status = bt_value_array_append_signed_integer_element(array2, 23);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
status = bt_value_array_append_bool_element(array2, BT_FALSE);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
- status = bt_value_array_append_integer_element(array3, 23);
+ status = bt_value_array_append_signed_integer_element(array3, 23);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
status = bt_value_array_append_real_element(array3, 14.2);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
"empty map value objects are equivalent");
- status = bt_value_map_insert_integer_entry(map1, "one", 23);
+ status = bt_value_map_insert_signed_integer_entry(map1, "one", 23);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
status = bt_value_map_insert_real_entry(map1, "two", 14.2);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
status = bt_value_map_insert_real_entry(map2, "one", 14.2);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
- status = bt_value_map_insert_integer_entry(map2, "two", 23);
+ status = bt_value_map_insert_signed_integer_entry(map2, "two", 23);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
status = bt_value_map_insert_bool_entry(map2, "three",
BT_FALSE);
status = bt_value_map_insert_bool_entry(map3, "three",
BT_FALSE);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
- status = bt_value_map_insert_integer_entry(map3, "one", 23);
+ status = bt_value_map_insert_signed_integer_entry(map3, "one", 23);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
status = bt_value_map_insert_real_entry(map3, "two", 14.2);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
{
test_compare_null();
test_compare_bool();
- test_compare_integer();
+ test_compare_unsigned_integer();
+ test_compare_signed_integer();
test_compare_real();
test_compare_string();
test_compare_array();
{
/*
* Here's the deal here. If we make sure that each value object
- * of our deep copy has a different address than its source,
- * and that bt_value_compare() returns BT_TRUE for the top-level
- * value object, taking into account that we test the correctness of
- * bt_value_compare() elsewhere, then the deep copy is a
- * success.
+ * of our deep copy has a different address than its source, and
+ * that bt_value_compare() returns BT_TRUE for the top-level
+ * value object, taking into account that we test the
+ * correctness of bt_value_compare() elsewhere, then the deep
+ * copy is a success.
*/
bt_value *null_copy_obj;
bt_value *bool_obj, *bool_copy_obj;
- bt_value *integer_obj, *integer_copy_obj;
+ bt_value *unsigned_integer_obj, *unsigned_integer_copy_obj;
+ bt_value *signed_integer_obj, *signed_integer_copy_obj;
bt_value *real_obj, *real_copy_obj;
bt_value *string_obj, *string_copy_obj;
bt_value *array_obj, *array_copy_obj;
bt_value_status status;
bool_obj = bt_value_bool_create_init(BT_TRUE);
- integer_obj = bt_value_integer_create_init(23);
+ unsigned_integer_obj = bt_value_unsigned_integer_create_init(23);
+ signed_integer_obj = bt_value_signed_integer_create_init(-47);
real_obj = bt_value_real_create_init(-3.1416);
string_obj = bt_value_string_create_init("test");
array_obj = bt_value_array_create();
map_obj = bt_value_map_create();
- BT_ASSERT(bool_obj && integer_obj && real_obj && string_obj &&
- array_obj && map_obj);
+ BT_ASSERT(bool_obj && unsigned_integer_obj && signed_integer_obj &&
+ real_obj && string_obj && array_obj && map_obj);
- status = bt_value_array_append_element(array_obj,
- bool_obj);
+ status = bt_value_array_append_element(array_obj, bool_obj);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
- status = bt_value_array_append_element(array_obj,
- integer_obj);
+ status = bt_value_array_append_element(array_obj, unsigned_integer_obj);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
- status = bt_value_array_append_element(array_obj,
- real_obj);
+ status = bt_value_array_append_element(array_obj, signed_integer_obj);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
- status = bt_value_array_append_element(array_obj,
- bt_value_null);
+ status = bt_value_array_append_element(array_obj, real_obj);
+ BT_ASSERT(status == BT_VALUE_STATUS_OK);
+ status = bt_value_array_append_element(array_obj, bt_value_null);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
- status = bt_value_map_insert_entry(map_obj, "array",
- array_obj);
+ status = bt_value_map_insert_entry(map_obj, "array", array_obj);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
- status = bt_value_map_insert_entry(map_obj, "string",
- string_obj);
+ status = bt_value_map_insert_entry(map_obj, "string", string_obj);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
status = bt_value_copy(map_obj, &map_copy_obj);
bool_copy_obj = bt_value_array_borrow_element_by_index(
array_copy_obj, 0);
ok(bool_copy_obj != bool_obj,
- "bt_value_copy() returns a different pointer (bt_bool)");
- integer_copy_obj = bt_value_array_borrow_element_by_index(
+ "bt_value_copy() returns a different pointer (bool)");
+ unsigned_integer_copy_obj = bt_value_array_borrow_element_by_index(
array_copy_obj, 1);
- ok(integer_copy_obj != integer_obj,
- "bt_value_copy() returns a different pointer (integer)");
- real_copy_obj = bt_value_array_borrow_element_by_index(
+ ok(unsigned_integer_copy_obj != unsigned_integer_obj,
+ "bt_value_copy() returns a different pointer (unsigned integer)");
+ signed_integer_copy_obj = bt_value_array_borrow_element_by_index(
array_copy_obj, 2);
+ ok(signed_integer_copy_obj != signed_integer_obj,
+ "bt_value_copy() returns a different pointer (signed integer)");
+ real_copy_obj = bt_value_array_borrow_element_by_index(
+ array_copy_obj, 3);
ok(real_copy_obj != real_obj,
"bt_value_copy() returns a different pointer (real)");
null_copy_obj = bt_value_array_borrow_element_by_index(
- array_copy_obj, 3);
+ array_copy_obj, 4);
ok(null_copy_obj == bt_value_null,
"bt_value_copy() returns the same pointer (null)");
- ok(bt_value_compare(map_obj,
- map_copy_obj),
+ ok(bt_value_compare(map_obj, map_copy_obj),
"source and destination value objects have the same content");
BT_VALUE_PUT_REF_AND_RESET(map_copy_obj);
BT_VALUE_PUT_REF_AND_RESET(bool_obj);
- BT_VALUE_PUT_REF_AND_RESET(integer_obj);
+ BT_VALUE_PUT_REF_AND_RESET(unsigned_integer_obj);
+ BT_VALUE_PUT_REF_AND_RESET(signed_integer_obj);
BT_VALUE_PUT_REF_AND_RESET(real_obj);
BT_VALUE_PUT_REF_AND_RESET(string_obj);
BT_VALUE_PUT_REF_AND_RESET(array_obj);
status = bt_value_map_insert_bool_entry(base_map, "edit",
BT_FALSE);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
- status = bt_value_map_insert_integer_entry(base_map,
+ status = bt_value_map_insert_signed_integer_entry(base_map,
"selection", 17);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
- status = bt_value_map_insert_integer_entry(base_map, "find",
+ status = bt_value_map_insert_signed_integer_entry(base_map, "find",
-34);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
status = bt_value_map_insert_bool_entry(extension_map, "edit",
BT_TRUE);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
- status = bt_value_map_insert_integer_entry(extension_map,
+ status = bt_value_map_insert_signed_integer_entry(extension_map,
"find", 101);
BT_ASSERT(status == BT_VALUE_STATUS_OK);
status = bt_value_map_insert_real_entry(extension_map,
plugin, "filter");
ok(filter_comp_class,
"bt_plugin_borrow_filter_component_class_by_name_const() finds a filter component class");
- params = bt_value_integer_create_init(23);
+ params = bt_value_signed_integer_create_init(23);
BT_ASSERT(params);
ret = bt_query_executor_query(query_exec,
bt_component_class_filter_as_component_class_const(filter_comp_class),