add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
/* EINA - EFL data type library
|
|
|
|
* Copyright (C) 2012 ProFUSION embedded systems
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library;
|
|
|
|
* if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <inttypes.h>
|
2014-10-23 05:34:14 -07:00
|
|
|
#include <float.h>
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
|
2016-02-04 05:44:58 -08:00
|
|
|
#include <Eina.h>
|
|
|
|
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
#include "eina_suite.h"
|
|
|
|
|
2013-11-12 03:12:54 -08:00
|
|
|
#define FP_ERR (1)
|
|
|
|
#define CHECK_FP(a, b) ((a - b) <= FP_ERR)
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_simple)
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
{
|
|
|
|
Eina_Value *value;
|
|
|
|
char c;
|
|
|
|
short s;
|
|
|
|
int i;
|
|
|
|
long l;
|
|
|
|
int64_t i64;
|
|
|
|
unsigned char uc;
|
|
|
|
unsigned short us;
|
|
|
|
unsigned int ui;
|
|
|
|
unsigned long ul;
|
|
|
|
uint64_t u64;
|
|
|
|
float f;
|
|
|
|
double d;
|
|
|
|
|
|
|
|
|
|
|
|
value = eina_value_new(EINA_VALUE_TYPE_CHAR);
|
|
|
|
fail_unless(value != NULL);
|
|
|
|
fail_unless(eina_value_set(value, 'x'));
|
|
|
|
fail_unless(eina_value_get(value, &c));
|
|
|
|
fail_unless(c == 'x');
|
2019-01-02 18:40:02 -08:00
|
|
|
fail_unless(eina_value_char_get(value, &c));
|
|
|
|
fail_if(eina_value_double_get(value, &d));
|
|
|
|
fail_unless(c == 'x');
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_SHORT));
|
|
|
|
fail_unless(eina_value_set(value, 300));
|
|
|
|
fail_unless(eina_value_get(value, &s));
|
|
|
|
fail_unless(s == 300);
|
2019-01-02 18:40:02 -08:00
|
|
|
fail_unless(eina_value_short_get(value, &s));
|
|
|
|
fail_if(eina_value_char_get(value, &c));
|
|
|
|
fail_unless(s == 300);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_INT));
|
|
|
|
fail_unless(eina_value_set(value, -12345));
|
|
|
|
fail_unless(eina_value_get(value, &i));
|
|
|
|
fail_unless(i == -12345);
|
2019-01-02 18:40:02 -08:00
|
|
|
fail_unless(eina_value_int_get(value, &i));
|
|
|
|
fail_if(eina_value_short_get(value, &s));
|
|
|
|
fail_unless(i == -12345);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_LONG));
|
|
|
|
fail_unless(eina_value_set(value, 0xb33f));
|
|
|
|
fail_unless(eina_value_get(value, &l));
|
|
|
|
fail_unless(l == 0xb33f);
|
2019-01-02 18:40:02 -08:00
|
|
|
fail_unless(eina_value_long_get(value, &l));
|
|
|
|
fail_if(eina_value_int_get(value, &i));
|
|
|
|
fail_unless(l == 0xb33f);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_INT64));
|
|
|
|
fail_unless(eina_value_set(value, 0x0011223344556677));
|
|
|
|
fail_unless(eina_value_get(value, &i64));
|
|
|
|
fail_unless(i64 == 0x0011223344556677);
|
2019-01-02 18:40:02 -08:00
|
|
|
fail_unless(eina_value_int64_get(value, &i64));
|
|
|
|
fail_if(eina_value_long_get(value, &l));
|
|
|
|
fail_unless(i64 == 0x0011223344556677);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
/* unsigned: */
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_UCHAR));
|
|
|
|
fail_unless(eina_value_set(value, 200));
|
|
|
|
fail_unless(eina_value_get(value, &uc));
|
|
|
|
fail_unless(uc == 200);
|
2019-01-02 18:40:02 -08:00
|
|
|
fail_unless(eina_value_uchar_get(value, &uc));
|
|
|
|
fail_if(eina_value_int64_get(value, &i64));
|
|
|
|
fail_unless(uc == 200);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_USHORT));
|
|
|
|
fail_unless(eina_value_set(value, 65535));
|
|
|
|
fail_unless(eina_value_get(value, &us));
|
|
|
|
fail_unless(us == 65535);
|
2019-01-02 18:40:02 -08:00
|
|
|
fail_unless(eina_value_ushort_get(value, &us));
|
|
|
|
fail_if(eina_value_uchar_get(value, &uc));
|
|
|
|
fail_unless(us == 65535);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_UINT));
|
|
|
|
fail_unless(eina_value_set(value, 4000000000U));
|
|
|
|
fail_unless(eina_value_get(value, &ui));
|
|
|
|
fail_unless(ui == 4000000000U);
|
2019-01-02 18:40:02 -08:00
|
|
|
fail_unless(eina_value_uint_get(value, &ui));
|
|
|
|
fail_if(eina_value_ushort_get(value, &us));
|
|
|
|
fail_unless(ui == 4000000000U);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_ULONG));
|
2012-05-17 02:59:46 -07:00
|
|
|
fail_unless(eina_value_set(value, 3000000001UL));
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
fail_unless(eina_value_get(value, &ul));
|
2012-05-17 02:59:46 -07:00
|
|
|
fail_unless(ul == 3000000001UL);
|
2019-01-02 18:40:02 -08:00
|
|
|
fail_unless(eina_value_ulong_get(value, &ul));
|
|
|
|
fail_if(eina_value_uint_get(value, &ui));
|
|
|
|
fail_unless(ul == 3000000001UL);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_UINT64));
|
|
|
|
fail_unless(eina_value_set(value, 0x1122334455667788));
|
|
|
|
fail_unless(eina_value_get(value, &u64));
|
|
|
|
fail_unless(u64 == 0x1122334455667788);
|
2019-01-02 18:40:02 -08:00
|
|
|
fail_unless(eina_value_uint64_get(value, &u64));
|
|
|
|
fail_if(eina_value_ulong_get(value, &ul));
|
|
|
|
fail_unless(u64 == 0x1122334455667788);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
/* floating point */
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_FLOAT));
|
|
|
|
fail_unless(eina_value_set(value, 0.1234));
|
|
|
|
fail_unless(eina_value_get(value, &f));
|
|
|
|
fail_unless(CHECK_FP(0.1234, f));
|
2019-01-02 18:40:02 -08:00
|
|
|
fail_unless(eina_value_float_get(value, &f));
|
|
|
|
fail_if(eina_value_uint64_get(value, &u64));
|
|
|
|
fail_unless(CHECK_FP(0.1234, f));
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_DOUBLE));
|
|
|
|
fail_unless(eina_value_set(value, 34567.8));
|
|
|
|
fail_unless(eina_value_get(value, &d));
|
|
|
|
fail_unless(CHECK_FP(34567.8, d));
|
2019-01-02 18:40:02 -08:00
|
|
|
fail_unless(eina_value_double_get(value, &d));
|
|
|
|
fail_if(eina_value_float_get(value, &f));
|
|
|
|
fail_unless(CHECK_FP(34567.8, d));
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
eina_value_free(value);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_compare)
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
{
|
|
|
|
Eina_Value *a, *b;
|
|
|
|
|
|
|
|
|
|
|
|
a = eina_value_new(EINA_VALUE_TYPE_CHAR);
|
|
|
|
fail_unless(a != NULL);
|
|
|
|
b = eina_value_new(EINA_VALUE_TYPE_CHAR);
|
|
|
|
fail_unless(b != NULL);
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(a, 123));
|
|
|
|
fail_unless(eina_value_set(b, 123));
|
|
|
|
fail_unless(eina_value_compare(a, b) == 0);
|
|
|
|
fail_unless(eina_value_set(a, -10));
|
|
|
|
fail_unless(eina_value_set(b, 123));
|
|
|
|
fail_unless(eina_value_compare(a, b) < 0);
|
|
|
|
fail_unless(eina_value_set(a, 123));
|
|
|
|
fail_unless(eina_value_set(b, 10));
|
|
|
|
fail_unless(eina_value_compare(a, b) > 0);
|
|
|
|
eina_value_flush(a);
|
|
|
|
eina_value_flush(b);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(a, EINA_VALUE_TYPE_SHORT));
|
|
|
|
fail_unless(eina_value_setup(b, EINA_VALUE_TYPE_SHORT));
|
|
|
|
fail_unless(eina_value_set(a, 1230));
|
|
|
|
fail_unless(eina_value_set(b, 1230));
|
|
|
|
fail_unless(eina_value_compare(a, b) == 0);
|
|
|
|
fail_unless(eina_value_set(a, -100));
|
|
|
|
fail_unless(eina_value_set(b, 1230));
|
|
|
|
fail_unless(eina_value_compare(a, b) < 0);
|
|
|
|
fail_unless(eina_value_set(a, 1230));
|
|
|
|
fail_unless(eina_value_set(b, -100));
|
|
|
|
fail_unless(eina_value_compare(a, b) > 0);
|
|
|
|
eina_value_flush(a);
|
|
|
|
eina_value_flush(b);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(a, EINA_VALUE_TYPE_INT));
|
|
|
|
fail_unless(eina_value_setup(b, EINA_VALUE_TYPE_INT));
|
|
|
|
fail_unless(eina_value_set(a, 300000));
|
|
|
|
fail_unless(eina_value_set(b, 300000));
|
|
|
|
fail_unless(eina_value_compare(a, b) == 0);
|
|
|
|
fail_unless(eina_value_set(a, -100));
|
|
|
|
fail_unless(eina_value_set(b, 300000));
|
|
|
|
fail_unless(eina_value_compare(a, b) < 0);
|
|
|
|
fail_unless(eina_value_set(a, 300000));
|
|
|
|
fail_unless(eina_value_set(b, -100));
|
|
|
|
fail_unless(eina_value_compare(a, b) > 0);
|
|
|
|
eina_value_flush(a);
|
|
|
|
eina_value_flush(b);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(a, EINA_VALUE_TYPE_LONG));
|
|
|
|
fail_unless(eina_value_setup(b, EINA_VALUE_TYPE_LONG));
|
|
|
|
fail_unless(eina_value_set(a, 300000L));
|
|
|
|
fail_unless(eina_value_set(b, 300000L));
|
|
|
|
fail_unless(eina_value_compare(a, b) == 0);
|
|
|
|
fail_unless(eina_value_set(a, -100L));
|
|
|
|
fail_unless(eina_value_set(b, 300000L));
|
|
|
|
fail_unless(eina_value_compare(a, b) < 0);
|
|
|
|
fail_unless(eina_value_set(a, 300000L));
|
|
|
|
fail_unless(eina_value_set(b, -100L));
|
|
|
|
fail_unless(eina_value_compare(a, b) > 0);
|
|
|
|
eina_value_flush(a);
|
|
|
|
eina_value_flush(b);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(a, EINA_VALUE_TYPE_INT64));
|
|
|
|
fail_unless(eina_value_setup(b, EINA_VALUE_TYPE_INT64));
|
|
|
|
fail_unless(eina_value_set(a, (int64_t)800000));
|
|
|
|
fail_unless(eina_value_set(b, (int64_t)800000));
|
|
|
|
fail_unless(eina_value_compare(a, b) == 0);
|
|
|
|
fail_unless(eina_value_set(a, (int64_t)-100));
|
|
|
|
fail_unless(eina_value_set(b, (int64_t)8000000));
|
|
|
|
fail_unless(eina_value_compare(a, b) < 0);
|
|
|
|
fail_unless(eina_value_set(a, (int64_t)8000000));
|
|
|
|
fail_unless(eina_value_set(b, (int64_t)-100));
|
|
|
|
fail_unless(eina_value_compare(a, b) > 0);
|
|
|
|
eina_value_flush(a);
|
|
|
|
eina_value_flush(b);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(a, EINA_VALUE_TYPE_UCHAR));
|
|
|
|
fail_unless(eina_value_setup(b, EINA_VALUE_TYPE_UCHAR));
|
|
|
|
fail_unless(eina_value_set(a, 123));
|
|
|
|
fail_unless(eina_value_set(b, 123));
|
|
|
|
fail_unless(eina_value_compare(a, b) == 0);
|
|
|
|
fail_unless(eina_value_set(a, 10));
|
|
|
|
fail_unless(eina_value_set(b, 123));
|
|
|
|
fail_unless(eina_value_compare(a, b) < 0);
|
|
|
|
fail_unless(eina_value_set(a, 123));
|
|
|
|
fail_unless(eina_value_set(b, 10));
|
|
|
|
fail_unless(eina_value_compare(a, b) > 0);
|
|
|
|
eina_value_flush(a);
|
|
|
|
eina_value_flush(b);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(a, EINA_VALUE_TYPE_USHORT));
|
|
|
|
fail_unless(eina_value_setup(b, EINA_VALUE_TYPE_USHORT));
|
|
|
|
fail_unless(eina_value_set(a, 1230));
|
|
|
|
fail_unless(eina_value_set(b, 1230));
|
|
|
|
fail_unless(eina_value_compare(a, b) == 0);
|
|
|
|
fail_unless(eina_value_set(a, 100));
|
|
|
|
fail_unless(eina_value_set(b, 1230));
|
|
|
|
fail_unless(eina_value_compare(a, b) < 0);
|
|
|
|
fail_unless(eina_value_set(a, 1230));
|
|
|
|
fail_unless(eina_value_set(b, 100));
|
|
|
|
fail_unless(eina_value_compare(a, b) > 0);
|
|
|
|
eina_value_flush(a);
|
|
|
|
eina_value_flush(b);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(a, EINA_VALUE_TYPE_UINT));
|
|
|
|
fail_unless(eina_value_setup(b, EINA_VALUE_TYPE_UINT));
|
|
|
|
fail_unless(eina_value_set(a, 300000));
|
|
|
|
fail_unless(eina_value_set(b, 300000));
|
|
|
|
fail_unless(eina_value_compare(a, b) == 0);
|
|
|
|
fail_unless(eina_value_set(a, 100));
|
|
|
|
fail_unless(eina_value_set(b, 300000));
|
|
|
|
fail_unless(eina_value_compare(a, b) < 0);
|
|
|
|
fail_unless(eina_value_set(a, 300000));
|
|
|
|
fail_unless(eina_value_set(b, 100));
|
|
|
|
fail_unless(eina_value_compare(a, b) > 0);
|
|
|
|
eina_value_flush(a);
|
|
|
|
eina_value_flush(b);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(a, EINA_VALUE_TYPE_ULONG));
|
|
|
|
fail_unless(eina_value_setup(b, EINA_VALUE_TYPE_ULONG));
|
|
|
|
fail_unless(eina_value_set(a, 300000UL));
|
|
|
|
fail_unless(eina_value_set(b, 300000UL));
|
|
|
|
fail_unless(eina_value_compare(a, b) == 0);
|
|
|
|
fail_unless(eina_value_set(a, 100UL));
|
|
|
|
fail_unless(eina_value_set(b, 300000UL));
|
|
|
|
fail_unless(eina_value_compare(a, b) < 0);
|
|
|
|
fail_unless(eina_value_set(a, 300000UL));
|
|
|
|
fail_unless(eina_value_set(b, 100UL));
|
|
|
|
fail_unless(eina_value_compare(a, b) > 0);
|
|
|
|
eina_value_flush(a);
|
|
|
|
eina_value_flush(b);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(a, EINA_VALUE_TYPE_UINT64));
|
|
|
|
fail_unless(eina_value_setup(b, EINA_VALUE_TYPE_UINT64));
|
|
|
|
fail_unless(eina_value_set(a, (uint64_t)8000000));
|
|
|
|
fail_unless(eina_value_set(b, (uint64_t)8000000));
|
|
|
|
fail_unless(eina_value_compare(a, b) == 0);
|
|
|
|
fail_unless(eina_value_set(a, (uint64_t)100));
|
|
|
|
fail_unless(eina_value_set(b, (uint64_t)8000000));
|
|
|
|
fail_unless(eina_value_compare(a, b) < 0);
|
|
|
|
fail_unless(eina_value_set(a, (uint64_t)8000000));
|
|
|
|
fail_unless(eina_value_set(b, (uint64_t)100));
|
|
|
|
fail_unless(eina_value_compare(a, b) > 0);
|
|
|
|
eina_value_flush(a);
|
|
|
|
eina_value_flush(b);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(a, EINA_VALUE_TYPE_STRING));
|
|
|
|
fail_unless(eina_value_setup(b, EINA_VALUE_TYPE_STRING));
|
|
|
|
fail_unless(eina_value_set(a, "aaa"));
|
|
|
|
fail_unless(eina_value_set(b, "aaa"));
|
|
|
|
fail_unless(eina_value_compare(a, b) == 0);
|
|
|
|
fail_unless(eina_value_set(a, "abc"));
|
|
|
|
fail_unless(eina_value_set(b, "acd"));
|
|
|
|
fail_unless(eina_value_compare(a, b) < 0);
|
|
|
|
fail_unless(eina_value_set(a, "acd"));
|
|
|
|
fail_unless(eina_value_set(b, "abc"));
|
|
|
|
fail_unless(eina_value_compare(a, b) > 0);
|
|
|
|
eina_value_flush(a);
|
|
|
|
eina_value_flush(b);
|
|
|
|
|
|
|
|
fail_unless(eina_value_array_setup(a, EINA_VALUE_TYPE_CHAR, 0));
|
|
|
|
fail_unless(eina_value_array_setup(b, EINA_VALUE_TYPE_CHAR, 0));
|
|
|
|
fail_unless(eina_value_compare(a, b) == 0);
|
|
|
|
|
|
|
|
fail_unless(eina_value_array_append(a, 1));
|
|
|
|
fail_unless(eina_value_array_append(a, 2));
|
|
|
|
fail_unless(eina_value_array_append(a, 3));
|
|
|
|
|
|
|
|
fail_unless(eina_value_array_append(b, 1));
|
|
|
|
fail_unless(eina_value_array_append(b, 2));
|
|
|
|
fail_unless(eina_value_array_append(b, 3));
|
|
|
|
|
|
|
|
fail_unless(eina_value_compare(a, b) == 0);
|
|
|
|
|
|
|
|
fail_unless(eina_value_array_set(a, 0, 0));
|
|
|
|
fail_unless(eina_value_compare(a, b) < 0);
|
|
|
|
|
|
|
|
fail_unless(eina_value_array_set(a, 0, 10));
|
|
|
|
fail_unless(eina_value_compare(a, b) > 0);
|
|
|
|
|
|
|
|
fail_unless(eina_value_array_set(a, 0, 1));
|
|
|
|
|
|
|
|
fail_unless(eina_value_array_set(b, 0, 0));
|
|
|
|
fail_unless(eina_value_compare(a, b) > 0);
|
|
|
|
|
|
|
|
fail_unless(eina_value_array_set(b, 0, 10));
|
|
|
|
fail_unless(eina_value_compare(a, b) < 0);
|
|
|
|
|
|
|
|
fail_unless(eina_value_array_set(b, 0, 1));
|
|
|
|
fail_unless(eina_value_compare(a, b) == 0);
|
|
|
|
|
|
|
|
/* bigger arrays are greater */
|
|
|
|
fail_unless(eina_value_array_append(b, 0));
|
|
|
|
fail_unless(eina_value_compare(a, b) < 0);
|
|
|
|
|
|
|
|
fail_unless(eina_value_array_append(a, 0));
|
|
|
|
fail_unless(eina_value_array_append(a, 0));
|
|
|
|
fail_unless(eina_value_compare(a, b) > 0);
|
|
|
|
|
|
|
|
/* bigger arrays are greater, unless an element says otherwise */
|
|
|
|
fail_unless(eina_value_array_set(b, 0, 10));
|
|
|
|
fail_unless(eina_value_compare(a, b) < 0);
|
|
|
|
|
2012-01-11 13:52:32 -08:00
|
|
|
eina_value_flush(a);
|
|
|
|
eina_value_flush(b);
|
|
|
|
|
|
|
|
fail_unless(eina_value_list_setup(a, EINA_VALUE_TYPE_CHAR));
|
|
|
|
fail_unless(eina_value_list_setup(b, EINA_VALUE_TYPE_CHAR));
|
|
|
|
fail_unless(eina_value_compare(a, b) == 0);
|
|
|
|
|
|
|
|
fail_unless(eina_value_list_append(a, 1));
|
|
|
|
fail_unless(eina_value_list_append(a, 2));
|
|
|
|
fail_unless(eina_value_list_append(a, 3));
|
|
|
|
|
|
|
|
fail_unless(eina_value_list_append(b, 1));
|
|
|
|
fail_unless(eina_value_list_append(b, 2));
|
|
|
|
fail_unless(eina_value_list_append(b, 3));
|
|
|
|
|
|
|
|
fail_unless(eina_value_compare(a, b) == 0);
|
|
|
|
|
|
|
|
fail_unless(eina_value_list_set(a, 0, 0));
|
|
|
|
fail_unless(eina_value_compare(a, b) < 0);
|
|
|
|
|
|
|
|
fail_unless(eina_value_list_set(a, 0, 10));
|
|
|
|
fail_unless(eina_value_compare(a, b) > 0);
|
|
|
|
|
|
|
|
fail_unless(eina_value_list_set(a, 0, 1));
|
|
|
|
|
|
|
|
fail_unless(eina_value_list_set(b, 0, 0));
|
|
|
|
fail_unless(eina_value_compare(a, b) > 0);
|
|
|
|
|
|
|
|
fail_unless(eina_value_list_set(b, 0, 10));
|
|
|
|
fail_unless(eina_value_compare(a, b) < 0);
|
|
|
|
|
|
|
|
fail_unless(eina_value_list_set(b, 0, 1));
|
|
|
|
fail_unless(eina_value_compare(a, b) == 0);
|
|
|
|
|
|
|
|
/* bigger lists are greater */
|
|
|
|
fail_unless(eina_value_list_append(b, 0));
|
|
|
|
fail_unless(eina_value_compare(a, b) < 0);
|
|
|
|
|
|
|
|
fail_unless(eina_value_list_append(a, 0));
|
|
|
|
fail_unless(eina_value_list_append(a, 0));
|
|
|
|
fail_unless(eina_value_compare(a, b) > 0);
|
|
|
|
|
|
|
|
/* bigger lists are greater, unless an element says otherwise */
|
|
|
|
fail_unless(eina_value_list_set(b, 0, 10));
|
|
|
|
fail_unless(eina_value_compare(a, b) < 0);
|
|
|
|
|
2012-01-11 15:54:35 -08:00
|
|
|
eina_value_flush(a);
|
|
|
|
eina_value_flush(b);
|
|
|
|
|
|
|
|
fail_unless(eina_value_hash_setup(a, EINA_VALUE_TYPE_CHAR, 0));
|
|
|
|
fail_unless(eina_value_hash_setup(b, EINA_VALUE_TYPE_CHAR, 0));
|
|
|
|
fail_unless(eina_value_compare(a, b) == 0);
|
|
|
|
|
|
|
|
fail_unless(eina_value_hash_set(a, "abc", 1));
|
|
|
|
fail_unless(eina_value_hash_set(a, "xyz", 2));
|
|
|
|
fail_unless(eina_value_hash_set(a, "hello", 3));
|
|
|
|
|
|
|
|
fail_unless(eina_value_hash_set(b, "abc", 1));
|
|
|
|
fail_unless(eina_value_hash_set(b, "xyz", 2));
|
|
|
|
fail_unless(eina_value_hash_set(b, "hello", 3));
|
|
|
|
|
|
|
|
fail_unless(eina_value_compare(a, b) == 0);
|
|
|
|
|
|
|
|
fail_unless(eina_value_hash_set(a, "abc", 0));
|
|
|
|
fail_unless(eina_value_compare(a, b) < 0);
|
|
|
|
|
|
|
|
fail_unless(eina_value_hash_set(a, "abc", 10));
|
|
|
|
fail_unless(eina_value_compare(a, b) > 0);
|
|
|
|
|
|
|
|
fail_unless(eina_value_hash_set(a, "abc", 1));
|
|
|
|
|
|
|
|
fail_unless(eina_value_hash_set(b, "abc", 0));
|
|
|
|
fail_unless(eina_value_compare(a, b) > 0);
|
|
|
|
|
|
|
|
fail_unless(eina_value_hash_set(b, "abc", 10));
|
|
|
|
fail_unless(eina_value_compare(a, b) < 0);
|
|
|
|
|
|
|
|
fail_unless(eina_value_hash_set(b, "abc", 1));
|
|
|
|
fail_unless(eina_value_compare(a, b) == 0);
|
|
|
|
|
|
|
|
/* bigger hashs are greater */
|
|
|
|
fail_unless(eina_value_hash_set(b,"newkey", 0));
|
|
|
|
fail_unless(eina_value_compare(a, b) < 0);
|
|
|
|
|
|
|
|
fail_unless(eina_value_hash_set(a, "newkey", 0));
|
|
|
|
fail_unless(eina_value_hash_set(a, "onemorenewkey", 0));
|
|
|
|
fail_unless(eina_value_compare(a, b) > 0);
|
|
|
|
|
|
|
|
/* bigger hashs are greater, unless an element says otherwise */
|
|
|
|
fail_unless(eina_value_hash_set(b, "abc", 10));
|
|
|
|
fail_unless(eina_value_compare(a, b) < 0);
|
|
|
|
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
eina_value_free(a);
|
|
|
|
eina_value_free(b);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_string)
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
{
|
|
|
|
Eina_Value *value;
|
|
|
|
const char *s;
|
|
|
|
|
|
|
|
|
|
|
|
value = eina_value_new(EINA_VALUE_TYPE_STRING);
|
|
|
|
fail_unless(value != NULL);
|
|
|
|
fail_unless(eina_value_set(value, "hello world!"));
|
|
|
|
fail_unless(eina_value_get(value, &s));
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(s, "hello world!");
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
|
|
|
|
fail_unless(eina_value_set(value, "eina-value"));
|
|
|
|
fail_unless(eina_value_get(value, &s));
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(s, "eina-value");
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
|
|
|
|
eina_value_flush(value);
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_STRING));
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(value, "profusion"));
|
|
|
|
fail_unless(eina_value_get(value, &s));
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(s, "profusion");
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
|
|
|
|
eina_value_free(value);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_pvariant)
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
{
|
|
|
|
Eina_Value *value;
|
|
|
|
char c, in_c;
|
|
|
|
short s, in_s;
|
|
|
|
int i, in_i;
|
|
|
|
long l, in_l;
|
|
|
|
int64_t i64, in_i64;
|
|
|
|
unsigned char uc, in_uc;
|
|
|
|
unsigned short us, in_us;
|
|
|
|
unsigned int ui, in_ui;
|
|
|
|
unsigned long ul, in_ul;
|
|
|
|
uint64_t u64, in_u64;
|
|
|
|
float f, in_f;
|
|
|
|
double d, in_d;
|
|
|
|
const char *str, *in_str;
|
|
|
|
|
|
|
|
|
|
|
|
value = eina_value_new(EINA_VALUE_TYPE_CHAR);
|
|
|
|
fail_unless(value != NULL);
|
|
|
|
in_c = 'x';
|
|
|
|
fail_unless(eina_value_pset(value, &in_c));
|
|
|
|
fail_unless(eina_value_pget(value, &c));
|
|
|
|
fail_unless(c == 'x');
|
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_SHORT));
|
|
|
|
in_s = 300;
|
|
|
|
fail_unless(eina_value_pset(value, &in_s));
|
|
|
|
fail_unless(eina_value_pget(value, &s));
|
|
|
|
fail_unless(s == 300);
|
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_INT));
|
|
|
|
in_i = -12345;
|
|
|
|
fail_unless(eina_value_pset(value, &in_i));
|
|
|
|
fail_unless(eina_value_pget(value, &i));
|
|
|
|
fail_unless(i == -12345);
|
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_LONG));
|
|
|
|
in_l = 0xb33f;
|
|
|
|
fail_unless(eina_value_pset(value, &in_l));
|
|
|
|
fail_unless(eina_value_pget(value, &l));
|
|
|
|
fail_unless(l == 0xb33f);
|
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_INT64));
|
|
|
|
in_i64 = 0x0011223344556677;
|
|
|
|
fail_unless(eina_value_pset(value, &in_i64));
|
|
|
|
fail_unless(eina_value_pget(value, &i64));
|
|
|
|
fail_unless(i64 == 0x0011223344556677);
|
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
/* unsigned: */
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_UCHAR));
|
|
|
|
in_uc = 200;
|
|
|
|
fail_unless(eina_value_pset(value, &in_uc));
|
|
|
|
fail_unless(eina_value_pget(value, &uc));
|
|
|
|
fail_unless(uc == 200);
|
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_USHORT));
|
|
|
|
in_us = 65535;
|
|
|
|
fail_unless(eina_value_pset(value, &in_us));
|
|
|
|
fail_unless(eina_value_pget(value, &us));
|
|
|
|
fail_unless(us == 65535);
|
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_UINT));
|
|
|
|
in_ui = 4000000000U;
|
|
|
|
fail_unless(eina_value_pset(value, &in_ui));
|
|
|
|
fail_unless(eina_value_pget(value, &ui));
|
|
|
|
fail_unless(ui == 4000000000U);
|
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_ULONG));
|
2012-05-17 02:59:46 -07:00
|
|
|
in_ul = 3000000001UL;
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
fail_unless(eina_value_pset(value, &in_ul));
|
|
|
|
fail_unless(eina_value_pget(value, &ul));
|
2012-05-17 02:59:46 -07:00
|
|
|
fail_unless(ul == 3000000001UL);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_UINT64));
|
|
|
|
in_u64 = 0x1122334455667788;
|
|
|
|
fail_unless(eina_value_pset(value, &in_u64));
|
|
|
|
fail_unless(eina_value_pget(value, &u64));
|
|
|
|
fail_unless(u64 == 0x1122334455667788);
|
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
/* floating point */
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_FLOAT));
|
|
|
|
in_f = 0.1234;
|
|
|
|
fail_unless(eina_value_pset(value, &in_f));
|
|
|
|
fail_unless(eina_value_pget(value, &f));
|
|
|
|
fail_unless(CHECK_FP(0.1234, f));
|
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_DOUBLE));
|
|
|
|
in_d = 34567.8;
|
|
|
|
fail_unless(eina_value_pset(value, &in_d));
|
|
|
|
fail_unless(eina_value_pget(value, &d));
|
|
|
|
fail_unless(CHECK_FP(34567.8, d));
|
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_STRING));
|
|
|
|
in_str = "hello world!";
|
|
|
|
fail_unless(eina_value_pset(value, &in_str));
|
|
|
|
fail_unless(eina_value_pget(value, &str));
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(str, "hello world!");
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
|
|
|
|
in_str = "eina-value";
|
|
|
|
fail_unless(eina_value_pset(value, &in_str));
|
|
|
|
fail_unless(eina_value_pget(value, &str));
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(str, "eina-value");
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
|
|
|
|
eina_value_flush(value);
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_STRING));
|
|
|
|
|
|
|
|
in_str = "profusion";
|
|
|
|
fail_unless(eina_value_pset(value, &in_str));
|
|
|
|
fail_unless(eina_value_pget(value, &str));
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(str, "profusion");
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
|
|
|
|
eina_value_free(value);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_to_string)
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
{
|
|
|
|
Eina_Value *value;
|
|
|
|
char c, in_c;
|
|
|
|
short s, in_s;
|
|
|
|
int i, in_i;
|
|
|
|
long l, in_l;
|
|
|
|
int64_t i64, in_i64;
|
|
|
|
unsigned char uc, in_uc;
|
|
|
|
unsigned short us, in_us;
|
|
|
|
unsigned int ui, in_ui;
|
|
|
|
unsigned long ul, in_ul;
|
|
|
|
uint64_t u64, in_u64;
|
|
|
|
float f, in_f;
|
|
|
|
double d, in_d;
|
|
|
|
const char *str, *in_str;
|
|
|
|
char *out;
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
|
|
|
|
value = eina_value_new(EINA_VALUE_TYPE_CHAR);
|
|
|
|
fail_unless(value != NULL);
|
|
|
|
in_c = 'x';
|
|
|
|
fail_unless(eina_value_pset(value, &in_c));
|
|
|
|
fail_unless(eina_value_pget(value, &c));
|
|
|
|
fail_unless(c == 'x');
|
|
|
|
snprintf(buf, sizeof(buf), "%hhd", in_c);
|
|
|
|
out = eina_value_to_string(value);
|
|
|
|
fail_unless(out != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(buf, out);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
free(out);
|
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_SHORT));
|
|
|
|
in_s = 300;
|
|
|
|
fail_unless(eina_value_pset(value, &in_s));
|
|
|
|
fail_unless(eina_value_pget(value, &s));
|
|
|
|
fail_unless(s == 300);
|
|
|
|
snprintf(buf, sizeof(buf), "%hd", in_s);
|
|
|
|
out = eina_value_to_string(value);
|
|
|
|
fail_unless(out != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(buf, out);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
free(out);
|
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_INT));
|
|
|
|
in_i = -12345;
|
|
|
|
fail_unless(eina_value_pset(value, &in_i));
|
|
|
|
fail_unless(eina_value_pget(value, &i));
|
|
|
|
fail_unless(i == -12345);
|
|
|
|
snprintf(buf, sizeof(buf), "%d", in_i);
|
|
|
|
out = eina_value_to_string(value);
|
|
|
|
fail_unless(out != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(buf, out);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
free(out);
|
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_LONG));
|
|
|
|
in_l = 0xb33f;
|
|
|
|
fail_unless(eina_value_pset(value, &in_l));
|
|
|
|
fail_unless(eina_value_pget(value, &l));
|
|
|
|
fail_unless(l == 0xb33f);
|
|
|
|
snprintf(buf, sizeof(buf), "%ld", in_l);
|
|
|
|
out = eina_value_to_string(value);
|
|
|
|
fail_unless(out != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(buf, out);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
free(out);
|
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_INT64));
|
|
|
|
in_i64 = 0x0011223344556677;
|
|
|
|
fail_unless(eina_value_pset(value, &in_i64));
|
|
|
|
fail_unless(eina_value_pget(value, &i64));
|
|
|
|
fail_unless(i64 == 0x0011223344556677);
|
|
|
|
snprintf(buf, sizeof(buf), "%"PRId64, in_i64);
|
|
|
|
out = eina_value_to_string(value);
|
|
|
|
fail_unless(out != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(buf, out);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
free(out);
|
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
/* unsigned: */
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_UCHAR));
|
|
|
|
in_uc = 200;
|
|
|
|
fail_unless(eina_value_pset(value, &in_uc));
|
|
|
|
fail_unless(eina_value_pget(value, &uc));
|
|
|
|
fail_unless(uc == 200);
|
|
|
|
snprintf(buf, sizeof(buf), "%hhu", in_uc);
|
|
|
|
out = eina_value_to_string(value);
|
|
|
|
fail_unless(out != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(buf, out);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
free(out);
|
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_USHORT));
|
|
|
|
in_us = 65535;
|
|
|
|
fail_unless(eina_value_pset(value, &in_us));
|
|
|
|
fail_unless(eina_value_pget(value, &us));
|
|
|
|
fail_unless(us == 65535);
|
|
|
|
snprintf(buf, sizeof(buf), "%hu", in_us);
|
|
|
|
out = eina_value_to_string(value);
|
|
|
|
fail_unless(out != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(buf, out);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
free(out);
|
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_UINT));
|
|
|
|
in_ui = 4000000000U;
|
|
|
|
fail_unless(eina_value_pset(value, &in_ui));
|
|
|
|
fail_unless(eina_value_pget(value, &ui));
|
|
|
|
fail_unless(ui == 4000000000U);
|
|
|
|
snprintf(buf, sizeof(buf), "%u", in_ui);
|
|
|
|
out = eina_value_to_string(value);
|
|
|
|
fail_unless(out != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(buf, out);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
free(out);
|
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_ULONG));
|
2012-05-17 02:59:46 -07:00
|
|
|
in_ul = 3000000001UL;
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
fail_unless(eina_value_pset(value, &in_ul));
|
|
|
|
fail_unless(eina_value_pget(value, &ul));
|
2012-05-17 02:59:46 -07:00
|
|
|
fail_unless(ul == 3000000001UL);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
snprintf(buf, sizeof(buf), "%lu", in_ul);
|
|
|
|
out = eina_value_to_string(value);
|
|
|
|
fail_unless(out != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(buf, out);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
free(out);
|
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_UINT64));
|
|
|
|
in_u64 = 0x1122334455667788;
|
|
|
|
fail_unless(eina_value_pset(value, &in_u64));
|
|
|
|
fail_unless(eina_value_pget(value, &u64));
|
|
|
|
fail_unless(u64 == 0x1122334455667788);
|
|
|
|
snprintf(buf, sizeof(buf), "%"PRIu64, in_u64);
|
|
|
|
out = eina_value_to_string(value);
|
|
|
|
fail_unless(out != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(buf, out);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
free(out);
|
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
/* floating point */
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_FLOAT));
|
|
|
|
in_f = 0.1234;
|
|
|
|
fail_unless(eina_value_pset(value, &in_f));
|
|
|
|
fail_unless(eina_value_pget(value, &f));
|
|
|
|
fail_unless(CHECK_FP(0.1234, f));
|
|
|
|
snprintf(buf, sizeof(buf), "%g", in_f);
|
|
|
|
out = eina_value_to_string(value);
|
|
|
|
fail_unless(out != NULL);
|
|
|
|
fail_unless(strncmp(buf, out, 6) == 0); /* stupid float... */
|
|
|
|
free(out);
|
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_DOUBLE));
|
|
|
|
in_d = 34567.8;
|
|
|
|
fail_unless(eina_value_pset(value, &in_d));
|
|
|
|
fail_unless(eina_value_pget(value, &d));
|
|
|
|
fail_unless(CHECK_FP(34567.8, d));
|
|
|
|
snprintf(buf, sizeof(buf), "%g", in_d);
|
|
|
|
out = eina_value_to_string(value);
|
|
|
|
fail_unless(out != NULL);
|
|
|
|
fail_unless(strncmp(buf, out, 7) == 0); /* stupid double... */
|
|
|
|
free(out);
|
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_STRING));
|
|
|
|
in_str = "hello world!";
|
|
|
|
fail_unless(eina_value_pset(value, &in_str));
|
|
|
|
fail_unless(eina_value_pget(value, &str));
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(str, "hello world!");
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
out = eina_value_to_string(value);
|
|
|
|
fail_unless(out != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(in_str, out);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
free(out);
|
|
|
|
|
|
|
|
in_str = "eina-value";
|
|
|
|
fail_unless(eina_value_pset(value, &in_str));
|
|
|
|
fail_unless(eina_value_pget(value, &str));
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(str, "eina-value");
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
out = eina_value_to_string(value);
|
|
|
|
fail_unless(out != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(in_str, out);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
free(out);
|
|
|
|
|
|
|
|
eina_value_flush(value);
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_STRING));
|
|
|
|
|
|
|
|
in_str = "profusion";
|
|
|
|
fail_unless(eina_value_pset(value, &in_str));
|
|
|
|
fail_unless(eina_value_pget(value, &str));
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(str, "profusion");
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
out = eina_value_to_string(value);
|
|
|
|
fail_unless(out != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(in_str, out);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
free(out);
|
|
|
|
|
|
|
|
eina_value_free(value);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_to_binbuf)
|
2017-09-13 17:26:26 -07:00
|
|
|
{
|
|
|
|
Eina_Value *value;
|
|
|
|
char c, in_c;
|
|
|
|
const char *str, *in_str;
|
|
|
|
Eina_Binbuf *bin;
|
|
|
|
const char *out;
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
|
|
|
|
value = eina_value_new(EINA_VALUE_TYPE_CHAR);
|
|
|
|
fail_unless(value != NULL);
|
|
|
|
in_c = 'x';
|
|
|
|
fail_unless(eina_value_pset(value, &in_c));
|
|
|
|
fail_unless(eina_value_pget(value, &c));
|
|
|
|
fail_unless(c == 'x');
|
|
|
|
snprintf(buf, sizeof(buf), "%c", in_c);
|
|
|
|
bin = eina_value_to_binbuf(value);
|
|
|
|
out = (char *) eina_binbuf_string_get(bin);
|
|
|
|
fail_unless(out != NULL);
|
|
|
|
ck_assert_str_eq(buf, out);
|
|
|
|
eina_binbuf_free(bin);
|
|
|
|
eina_value_flush(value);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_STRING));
|
|
|
|
in_str = "hello world!";
|
|
|
|
fail_unless(eina_value_pset(value, &in_str));
|
|
|
|
fail_unless(eina_value_pget(value, &str));
|
|
|
|
ck_assert_str_eq(str, "hello world!");
|
|
|
|
bin = eina_value_to_binbuf(value);
|
|
|
|
out = (char *) eina_binbuf_string_get(bin);
|
|
|
|
fail_unless(out != NULL);
|
|
|
|
ck_assert_str_eq(in_str, out);
|
|
|
|
eina_binbuf_free(bin);
|
|
|
|
|
|
|
|
in_str = "eina-value";
|
|
|
|
fail_unless(eina_value_pset(value, &in_str));
|
|
|
|
fail_unless(eina_value_pget(value, &str));
|
|
|
|
ck_assert_str_eq(str, "eina-value");
|
|
|
|
bin = eina_value_to_binbuf(value);
|
|
|
|
out = (char *) eina_binbuf_string_get(bin);
|
|
|
|
fail_unless(out != NULL);
|
|
|
|
ck_assert_str_eq(in_str, out);
|
|
|
|
eina_binbuf_free(bin);
|
|
|
|
|
|
|
|
eina_value_flush(value);
|
|
|
|
fail_unless(eina_value_setup(value, EINA_VALUE_TYPE_STRING));
|
|
|
|
|
|
|
|
in_str = "profusion";
|
|
|
|
fail_unless(eina_value_pset(value, &in_str));
|
|
|
|
fail_unless(eina_value_pget(value, &str));
|
|
|
|
ck_assert_str_eq(str, "profusion");
|
|
|
|
bin = eina_value_to_binbuf(value);
|
|
|
|
out = (char *) eina_binbuf_string_get(bin);
|
|
|
|
fail_unless(out != NULL);
|
|
|
|
ck_assert_str_eq(in_str, out);
|
|
|
|
eina_binbuf_free(bin);
|
|
|
|
|
|
|
|
eina_value_free(value);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2017-09-13 17:26:26 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_convert_char)
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
{
|
|
|
|
Eina_Value *value, conv;
|
|
|
|
char c;
|
|
|
|
short s;
|
|
|
|
int i;
|
|
|
|
long l;
|
|
|
|
int64_t i64;
|
|
|
|
unsigned char uc;
|
|
|
|
unsigned short us;
|
|
|
|
unsigned int ui;
|
|
|
|
unsigned long ul;
|
|
|
|
uint64_t u64;
|
|
|
|
float f;
|
|
|
|
double d;
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
|
|
|
|
value = eina_value_new(EINA_VALUE_TYPE_CHAR);
|
|
|
|
fail_unless(value != NULL);
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(value, 123));
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &uc));
|
|
|
|
fail_unless(uc == 123);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &us));
|
|
|
|
fail_unless(us == 123);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &ui));
|
|
|
|
fail_unless(ui == 123);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &ul));
|
|
|
|
fail_unless(ul == 123);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &u64));
|
|
|
|
fail_unless(u64 == 123);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &c));
|
|
|
|
fail_unless(c == 123);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_SHORT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &s));
|
|
|
|
fail_unless(s == 123);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &i));
|
|
|
|
fail_unless(i == 123);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_LONG));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &l));
|
|
|
|
fail_unless(l == 123);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT64));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &i64));
|
|
|
|
fail_unless(i64 == 123);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &f));
|
|
|
|
fail_unless(CHECK_FP(f, 123));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_DOUBLE));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &d));
|
|
|
|
fail_unless(CHECK_FP(d, 123));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_STRING));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &str));
|
|
|
|
fail_unless(str != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(str, "123");
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
/* negative tests */
|
|
|
|
fail_unless(eina_value_set(value, -123));
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
eina_value_free(value);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_convert_uchar)
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
{
|
|
|
|
Eina_Value *value, conv;
|
|
|
|
char c;
|
|
|
|
short s;
|
|
|
|
int i;
|
|
|
|
long l;
|
|
|
|
int64_t i64;
|
|
|
|
unsigned char uc;
|
|
|
|
unsigned short us;
|
|
|
|
unsigned int ui;
|
|
|
|
unsigned long ul;
|
|
|
|
uint64_t u64;
|
|
|
|
float f;
|
|
|
|
double d;
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
|
|
|
|
value = eina_value_new(EINA_VALUE_TYPE_UCHAR);
|
|
|
|
fail_unless(value != NULL);
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(value, 31));
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &uc));
|
|
|
|
fail_unless(uc == 31);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &us));
|
|
|
|
fail_unless(us == 31);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &ui));
|
|
|
|
fail_unless(ui == 31);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &ul));
|
|
|
|
fail_unless(ul == 31);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &u64));
|
|
|
|
fail_unless(u64 == 31);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &c));
|
|
|
|
fail_unless(c == 31);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_SHORT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &s));
|
|
|
|
fail_unless(s == 31);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &i));
|
|
|
|
fail_unless(i == 31);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_LONG));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &l));
|
|
|
|
fail_unless(l == 31);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT64));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &i64));
|
|
|
|
fail_unless(i64 == 31);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &f));
|
|
|
|
fail_unless(CHECK_FP(f, 31));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_DOUBLE));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &d));
|
|
|
|
fail_unless(CHECK_FP(d, 31));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_STRING));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &str));
|
|
|
|
fail_unless(str != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(str, "31");
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
/* negative tests */
|
|
|
|
fail_unless(eina_value_set(value, 200));
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
eina_value_free(value);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2016-02-04 05:44:58 -08:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_convert_short)
|
2013-07-16 23:20:08 -07:00
|
|
|
{
|
|
|
|
Eina_Value *value, conv;
|
|
|
|
short s;
|
|
|
|
int i;
|
|
|
|
long l;
|
|
|
|
int64_t i64;
|
|
|
|
unsigned short us;
|
|
|
|
unsigned int ui;
|
|
|
|
unsigned long ul;
|
|
|
|
uint64_t u64;
|
|
|
|
float f;
|
|
|
|
double d;
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
|
|
|
|
value = eina_value_new(EINA_VALUE_TYPE_SHORT);
|
|
|
|
fail_unless(value != NULL);
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(value, 12345));
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &us));
|
|
|
|
fail_unless(us == 12345);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &ui));
|
|
|
|
fail_unless(ui == 12345);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &ul));
|
|
|
|
fail_unless(ul == 12345);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &u64));
|
|
|
|
fail_unless(u64 == 12345);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_SHORT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &s));
|
|
|
|
fail_unless(s == 12345);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &i));
|
|
|
|
fail_unless(i == 12345);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_LONG));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &l));
|
|
|
|
fail_unless(l == 12345);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT64));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &i64));
|
|
|
|
fail_unless(i64 == 12345);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &f));
|
|
|
|
fail_unless(CHECK_FP(f, 12345));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_DOUBLE));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &d));
|
|
|
|
fail_unless(CHECK_FP(d, 12345));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_STRING));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &str));
|
|
|
|
fail_unless(str != NULL);
|
|
|
|
ck_assert_str_eq(str, "12345");
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
/* negative tests */
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
|
|
|
|
// value too big
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
|
|
|
|
// value too big
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
// check negative value
|
|
|
|
fail_unless(eina_value_set(value, -12345));
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
|
|
|
|
// value should be positive
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
|
|
|
|
// value should be positive
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
|
|
|
|
// value should be positive
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
|
|
|
|
// value should be positive
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
|
|
|
|
// value should be positive
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
eina_value_free(value);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2013-07-16 23:20:08 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_convert_ushort)
|
2013-07-16 23:20:08 -07:00
|
|
|
{
|
|
|
|
Eina_Value *value, conv;
|
|
|
|
int i;
|
|
|
|
long l;
|
|
|
|
int64_t i64;
|
|
|
|
unsigned short us;
|
|
|
|
unsigned int ui;
|
|
|
|
unsigned long ul;
|
|
|
|
uint64_t u64;
|
|
|
|
float f;
|
|
|
|
double d;
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
|
|
|
|
value = eina_value_new(EINA_VALUE_TYPE_USHORT);
|
|
|
|
fail_unless(value != NULL);
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(value, 54321));
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &us));
|
|
|
|
fail_unless(us == 54321);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &ui));
|
|
|
|
fail_unless(ui == 54321);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &ul));
|
|
|
|
fail_unless(ul == 54321);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &u64));
|
|
|
|
fail_unless(u64 == 54321);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &i));
|
|
|
|
fail_unless(i == 54321);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_LONG));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &l));
|
|
|
|
fail_unless(l == 54321);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT64));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &i64));
|
|
|
|
fail_unless(i64 == 54321);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &f));
|
|
|
|
fail_unless(CHECK_FP(f, 54321));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_DOUBLE));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &d));
|
|
|
|
fail_unless(CHECK_FP(d, 54321));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_STRING));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &str));
|
|
|
|
fail_unless(str != NULL);
|
|
|
|
ck_assert_str_eq(str, "54321");
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
/* negative tests */
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
|
|
|
|
// value too big
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
|
|
|
|
// value too big
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_SHORT));
|
|
|
|
// value too big
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
eina_value_free(value);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2013-07-16 23:20:08 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_convert_int)
|
2013-07-16 23:20:08 -07:00
|
|
|
{
|
|
|
|
Eina_Value *value, conv;
|
|
|
|
int i;
|
|
|
|
long l;
|
|
|
|
int64_t i64;
|
|
|
|
unsigned int ui;
|
|
|
|
unsigned long ul;
|
|
|
|
uint64_t u64;
|
|
|
|
float f;
|
|
|
|
double d;
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
|
|
|
|
value = eina_value_new(EINA_VALUE_TYPE_INT);
|
|
|
|
fail_unless(value != NULL);
|
|
|
|
|
|
|
|
const int max_positive_signed_4_bytes = 0x7FFFFFFF;
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(value, max_positive_signed_4_bytes));
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &ui));
|
|
|
|
fail_unless(ui == (unsigned int)max_positive_signed_4_bytes);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &ul));
|
|
|
|
fail_unless(ul == (unsigned long)max_positive_signed_4_bytes);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &u64));
|
|
|
|
fail_unless(u64 == (uint64_t)max_positive_signed_4_bytes);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &i));
|
|
|
|
fail_unless(i == max_positive_signed_4_bytes);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_LONG));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &l));
|
|
|
|
fail_unless(l == max_positive_signed_4_bytes);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT64));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &i64));
|
|
|
|
fail_unless(i64 == max_positive_signed_4_bytes);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &f));
|
|
|
|
fail_unless(CHECK_FP(f, max_positive_signed_4_bytes));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_DOUBLE));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &d));
|
|
|
|
fail_unless(CHECK_FP(d, max_positive_signed_4_bytes));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_STRING));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &str));
|
|
|
|
fail_unless(str != NULL);
|
|
|
|
ck_assert_str_eq(str, "2147483647"); // "2147483647" == 0x7FFFFFFF
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
/* negative tests */
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
|
|
|
|
// value too big
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_SHORT));
|
|
|
|
// value too big
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
|
|
|
|
// value too big
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
|
|
|
|
// value too big
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
// check negative value
|
|
|
|
fail_unless(eina_value_set(value, -1234567890));
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
|
|
|
|
// value should be positive
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
|
|
|
|
// value should be positive
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
|
|
|
|
// value should be positive
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
|
|
|
|
// value should be positive
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
|
|
|
|
// value should be positive
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
eina_value_free(value);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2013-07-16 23:20:08 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_convert_uint)
|
2013-07-16 23:20:08 -07:00
|
|
|
{
|
|
|
|
Eina_Value *value, conv;
|
|
|
|
unsigned int ui;
|
|
|
|
unsigned long ul;
|
|
|
|
uint64_t u64;
|
|
|
|
float f;
|
|
|
|
double d;
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
|
|
|
|
value = eina_value_new(EINA_VALUE_TYPE_UINT);
|
|
|
|
fail_unless(value != NULL);
|
|
|
|
|
|
|
|
const unsigned int max_positive_unsigned_4_bytes = 0xFFFFFFFF;
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(value, max_positive_unsigned_4_bytes));
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &ui));
|
|
|
|
fail_unless(ui == max_positive_unsigned_4_bytes);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &ul));
|
|
|
|
fail_unless(ul == max_positive_unsigned_4_bytes);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &u64));
|
|
|
|
fail_unless(u64 == max_positive_unsigned_4_bytes);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &f));
|
|
|
|
fail_unless(CHECK_FP(f, max_positive_unsigned_4_bytes));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_DOUBLE));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &d));
|
|
|
|
fail_unless(CHECK_FP(d, max_positive_unsigned_4_bytes));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_STRING));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &str));
|
|
|
|
fail_unless(str != NULL);
|
|
|
|
ck_assert_str_eq(str, "4294967295"); // 4294967295 == 0xFFFFFFFF
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
/* negative tests */
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
|
|
|
|
// value too big
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_SHORT));
|
|
|
|
// value too big
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT));
|
|
|
|
// value too big
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
|
|
|
|
// value too big
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
|
|
|
|
// value too big
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
eina_value_free(value);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_convert_long)
|
2013-03-24 20:55:42 -07:00
|
|
|
{
|
|
|
|
Eina_Value *value, conv;
|
|
|
|
char c;
|
|
|
|
short s;
|
|
|
|
int i;
|
|
|
|
long l;
|
|
|
|
int64_t i64;
|
|
|
|
unsigned char uc;
|
|
|
|
unsigned short us;
|
|
|
|
unsigned int ui;
|
|
|
|
unsigned long ul;
|
|
|
|
uint64_t u64;
|
|
|
|
float f;
|
|
|
|
double d;
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
|
|
|
|
value = eina_value_new(EINA_VALUE_TYPE_LONG);
|
|
|
|
fail_unless(value != NULL);
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(value, 32l));
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &uc));
|
|
|
|
fail_unless(uc == 32);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &us));
|
|
|
|
fail_unless(us == 32);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &ui));
|
|
|
|
fail_unless(ui == 32);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &ul));
|
|
|
|
fail_unless(ul == 32ul);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &u64));
|
|
|
|
fail_unless(u64 == 32ull);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &c));
|
|
|
|
fail_unless(c == 32);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_SHORT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &s));
|
|
|
|
fail_unless(s == 32);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &i));
|
|
|
|
fail_unless(i == 32);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_LONG));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &l));
|
|
|
|
fail_unless(l == 32l);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT64));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &i64));
|
|
|
|
fail_unless(i64 == 32ll);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &f));
|
|
|
|
fail_unless(CHECK_FP(f, 32));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_DOUBLE));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &d));
|
|
|
|
fail_unless(CHECK_FP(d, 32));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_STRING));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &str));
|
|
|
|
fail_unless(str != NULL);
|
|
|
|
ck_assert_str_eq(str, "32");
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
/* negative tests */
|
|
|
|
fail_unless(eina_value_set(value, 128l));
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(value, 256l));
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(value, 32768l));
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_SHORT));
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(value, 65536l));
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(value, -32l));
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
eina_value_free(value);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2013-03-24 20:55:42 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_convert_ulong)
|
2013-03-24 20:55:42 -07:00
|
|
|
{
|
|
|
|
Eina_Value *value, conv;
|
|
|
|
char c;
|
|
|
|
short s;
|
|
|
|
int i;
|
|
|
|
long l;
|
|
|
|
int64_t i64;
|
|
|
|
unsigned char uc;
|
|
|
|
unsigned short us;
|
|
|
|
unsigned int ui;
|
|
|
|
unsigned long ul;
|
|
|
|
uint64_t u64;
|
|
|
|
float f;
|
|
|
|
double d;
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
|
|
|
|
value = eina_value_new(EINA_VALUE_TYPE_ULONG);
|
|
|
|
fail_unless(value != NULL);
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(value, 42ul));
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &uc));
|
|
|
|
fail_unless(uc == 42);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &us));
|
|
|
|
fail_unless(us == 42);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &ui));
|
|
|
|
fail_unless(ui == 42);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &ul));
|
|
|
|
fail_unless(ul == 42ul);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &u64));
|
|
|
|
fail_unless(u64 == 42ull);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &c));
|
|
|
|
fail_unless(c == 42);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_SHORT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &s));
|
|
|
|
fail_unless(s == 42);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &i));
|
|
|
|
fail_unless(i == 42);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_LONG));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &l));
|
|
|
|
fail_unless(l == 42l);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT64));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &i64));
|
|
|
|
fail_unless(i64 == 42ll);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &f));
|
|
|
|
fail_unless(CHECK_FP(f, 42));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_DOUBLE));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &d));
|
|
|
|
fail_unless(CHECK_FP(d, 42));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_STRING));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &str));
|
|
|
|
fail_unless(str != NULL);
|
|
|
|
ck_assert_str_eq(str, "42");
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
/* negative tests */
|
|
|
|
fail_unless(eina_value_set(value, 128ul));
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(value, 256ul));
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(value, 32768ul));
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_SHORT));
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(value, 65536ul));
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
eina_value_free(value);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_convert_float)
|
2014-10-23 05:34:14 -07:00
|
|
|
{
|
|
|
|
Eina_Value *value, conv;
|
|
|
|
char c;
|
|
|
|
short s;
|
|
|
|
int i;
|
|
|
|
long l;
|
|
|
|
int64_t i64;
|
|
|
|
unsigned char uc;
|
|
|
|
unsigned short us;
|
|
|
|
unsigned int ui;
|
|
|
|
unsigned long ul;
|
|
|
|
uint64_t u64;
|
|
|
|
float f;
|
|
|
|
double d;
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
float max_float_value = FLT_MAX;
|
|
|
|
float min_float_value = FLT_MIN;
|
2016-02-04 05:44:58 -08:00
|
|
|
|
2014-10-23 05:34:14 -07:00
|
|
|
|
|
|
|
value = eina_value_new(EINA_VALUE_TYPE_FLOAT);
|
|
|
|
fail_unless(value != NULL);
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(value, 42.354645));
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &uc));
|
|
|
|
fail_unless(uc == 42);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &us));
|
|
|
|
fail_unless(us == 42);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &ui));
|
|
|
|
fail_unless(ui == 42);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_ULONG));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &ul));
|
|
|
|
fail_unless(ul == 42ul);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UINT64));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &u64));
|
|
|
|
fail_unless(ul == 42ull);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &c));
|
|
|
|
fail_unless(c == 42);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_SHORT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &s));
|
|
|
|
fail_unless(s == 42);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &i));
|
|
|
|
fail_unless(i == 42);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_LONG));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &l));
|
|
|
|
fail_unless(l == 42l);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_INT64));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &i64));
|
|
|
|
fail_unless(i64 == 42ll);
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &f));
|
|
|
|
fail_unless(CHECK_FP(f, max_float_value));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_DOUBLE));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &d));
|
|
|
|
fail_unless(CHECK_FP(d, max_float_value));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_STRING));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &str));
|
|
|
|
fail_unless(str != NULL);
|
|
|
|
ck_assert_str_eq(str, "42.354645");
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(value, max_float_value));
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &f));
|
|
|
|
fail_unless(CHECK_FP(f, max_float_value));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_DOUBLE));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &d));
|
|
|
|
fail_unless(CHECK_FP(d, max_float_value));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(value, min_float_value));
|
2016-02-04 05:44:58 -08:00
|
|
|
|
2014-10-23 05:34:14 -07:00
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &f));
|
|
|
|
fail_unless(CHECK_FP(f, min_float_value));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_DOUBLE));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &d));
|
|
|
|
fail_unless(CHECK_FP(d, min_float_value));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(value, -max_float_value));
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_FLOAT));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &f));
|
|
|
|
fail_unless(CHECK_FP(f, -max_float_value));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_DOUBLE));
|
|
|
|
fail_unless(eina_value_convert(value, &conv));
|
|
|
|
fail_unless(eina_value_get(&conv, &d));
|
|
|
|
fail_unless(CHECK_FP(d, -max_float_value));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
/* negative tests */
|
|
|
|
fail_unless(eina_value_set(value, -max_float_value));
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_CHAR));
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(value, -max_float_value));
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_UCHAR));
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(value, -max_float_value));
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_SHORT));
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(value, -max_float_value));
|
|
|
|
fail_unless(eina_value_setup(&conv, EINA_VALUE_TYPE_USHORT));
|
|
|
|
fail_if(eina_value_convert(value, &conv));
|
|
|
|
eina_value_flush(&conv);
|
|
|
|
|
|
|
|
eina_value_free(value);
|
2016-02-04 05:44:58 -08:00
|
|
|
|
2014-10-23 05:34:14 -07:00
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2014-10-23 05:34:14 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_array)
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
{
|
2012-01-11 13:55:48 -08:00
|
|
|
Eina_Value *value, other;
|
2012-01-12 09:07:07 -08:00
|
|
|
Eina_Value_Array desc;
|
|
|
|
Eina_Inarray *inarray;
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
char c;
|
|
|
|
char buf[1024];
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
|
|
|
|
value = eina_value_array_new(EINA_VALUE_TYPE_CHAR, 0);
|
|
|
|
fail_unless(value != NULL);
|
|
|
|
|
|
|
|
fail_unless(eina_value_array_append(value, 'k'));
|
|
|
|
fail_unless(eina_value_array_append(value, '-'));
|
|
|
|
fail_unless(eina_value_array_append(value, 's'));
|
|
|
|
|
|
|
|
fail_unless(eina_value_array_get(value, 0, &c));
|
|
|
|
fail_unless(c == 'k');
|
|
|
|
fail_unless(eina_value_array_get(value, 1, &c));
|
|
|
|
fail_unless(c == '-');
|
|
|
|
fail_unless(eina_value_array_get(value, 2, &c));
|
|
|
|
fail_unless(c == 's');
|
|
|
|
|
|
|
|
fail_unless(eina_value_array_insert(value, 0, '!'));
|
|
|
|
fail_unless(eina_value_array_get(value, 0, &c));
|
|
|
|
fail_unless(c == '!');
|
|
|
|
fail_unless(eina_value_array_get(value, 1, &c));
|
|
|
|
fail_unless(c == 'k');
|
|
|
|
fail_unless(eina_value_array_get(value, 2, &c));
|
|
|
|
fail_unless(c == '-');
|
|
|
|
fail_unless(eina_value_array_get(value, 3, &c));
|
|
|
|
fail_unless(c == 's');
|
|
|
|
|
|
|
|
fail_unless(eina_value_array_set(value, 0, '*'));
|
|
|
|
fail_unless(eina_value_array_get(value, 0, &c));
|
|
|
|
fail_unless(c == '*');
|
|
|
|
fail_unless(eina_value_array_get(value, 1, &c));
|
|
|
|
fail_unless(c == 'k');
|
|
|
|
fail_unless(eina_value_array_get(value, 2, &c));
|
|
|
|
fail_unless(c == '-');
|
|
|
|
fail_unless(eina_value_array_get(value, 3, &c));
|
|
|
|
fail_unless(c == 's');
|
|
|
|
|
2013-03-21 06:21:10 -07:00
|
|
|
snprintf(buf, sizeof(buf), "[%d, %d, %d, %d]",
|
|
|
|
(int) '*', (int) 'k', (int) '-', (int) 's');
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
|
|
|
|
str = eina_value_to_string(value);
|
|
|
|
fail_unless(str != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(str, buf);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
free(str);
|
|
|
|
|
|
|
|
eina_value_flush(value);
|
|
|
|
fail_unless(eina_value_array_setup(value, EINA_VALUE_TYPE_STRINGSHARE, 2));
|
|
|
|
|
|
|
|
fail_unless(eina_value_array_append(value, "Enlightenment.org"));
|
|
|
|
fail_unless(eina_value_array_append(value, "X11"));
|
|
|
|
fail_unless(eina_value_array_append(value, "Pants"));
|
|
|
|
fail_unless(eina_value_array_append(value, "on!!!"));
|
|
|
|
fail_unless(eina_value_array_append(value, "k-s"));
|
|
|
|
|
|
|
|
str = eina_value_to_string(value);
|
|
|
|
fail_unless(str != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(str, "[Enlightenment.org, X11, Pants, on!!!, k-s]");
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
free(str);
|
|
|
|
|
2012-01-11 13:55:48 -08:00
|
|
|
eina_value_flush(value);
|
|
|
|
fail_unless(eina_value_array_setup(value, EINA_VALUE_TYPE_CHAR, 0));
|
|
|
|
fail_unless(eina_value_setup(&other, EINA_VALUE_TYPE_CHAR));
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(&other, 100));
|
|
|
|
fail_unless(eina_value_get(&other, &c));
|
|
|
|
fail_unless(c == 100);
|
|
|
|
|
|
|
|
fail_unless(eina_value_convert(&other, value));
|
|
|
|
str = eina_value_to_string(value);
|
|
|
|
fail_unless(str != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(str, "[100]");
|
2012-01-11 13:55:48 -08:00
|
|
|
free(str);
|
|
|
|
|
|
|
|
fail_unless(eina_value_array_set(value, 0, 33));
|
|
|
|
fail_unless(eina_value_convert(value, &other));
|
|
|
|
fail_unless(eina_value_get(&other, &c));
|
|
|
|
fail_unless(c == 33);
|
|
|
|
|
2012-01-12 09:07:07 -08:00
|
|
|
inarray = eina_inarray_new(sizeof(char), 0);
|
|
|
|
fail_unless(inarray != NULL);
|
|
|
|
c = 11;
|
2012-04-20 01:30:59 -07:00
|
|
|
fail_unless(eina_inarray_push(inarray, &c) >= 0);
|
2012-01-12 09:07:07 -08:00
|
|
|
c = 21;
|
2012-04-20 01:30:59 -07:00
|
|
|
fail_unless(eina_inarray_push(inarray, &c) >= 0);
|
2012-01-12 09:07:07 -08:00
|
|
|
c = 31;
|
2012-04-20 01:30:59 -07:00
|
|
|
fail_unless(eina_inarray_push(inarray, &c) >= 0);
|
2012-01-12 09:07:07 -08:00
|
|
|
desc.subtype = EINA_VALUE_TYPE_CHAR;
|
|
|
|
desc.step = 0;
|
2012-02-10 16:34:25 -08:00
|
|
|
desc.array = inarray;
|
2012-01-12 09:07:07 -08:00
|
|
|
fail_unless(eina_value_set(value, desc)); /* manually configure */
|
2012-02-10 16:34:25 -08:00
|
|
|
eina_inarray_free(inarray);
|
|
|
|
|
2012-01-12 09:07:07 -08:00
|
|
|
fail_unless(eina_value_array_get(value, 0, &c));
|
|
|
|
fail_unless(c == 11);
|
|
|
|
fail_unless(eina_value_array_get(value, 1, &c));
|
|
|
|
fail_unless(c == 21);
|
|
|
|
fail_unless(eina_value_array_get(value, 2, &c));
|
|
|
|
fail_unless(c == 31);
|
|
|
|
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
eina_value_free(value);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_list)
|
2012-01-11 13:52:32 -08:00
|
|
|
{
|
|
|
|
Eina_Value *value, other;
|
2012-01-12 09:15:49 -08:00
|
|
|
Eina_Value_List desc;
|
2012-01-11 13:52:32 -08:00
|
|
|
char c;
|
|
|
|
char buf[1024];
|
|
|
|
char *str;
|
2012-01-12 09:15:49 -08:00
|
|
|
const char *s;
|
2012-01-11 13:52:32 -08:00
|
|
|
|
|
|
|
|
|
|
|
value = eina_value_list_new(EINA_VALUE_TYPE_CHAR);
|
|
|
|
fail_unless(value != NULL);
|
|
|
|
|
|
|
|
fail_unless(eina_value_list_append(value, 'k'));
|
|
|
|
fail_unless(eina_value_list_append(value, '-'));
|
|
|
|
fail_unless(eina_value_list_append(value, 's'));
|
|
|
|
|
|
|
|
fail_unless(eina_value_list_get(value, 0, &c));
|
|
|
|
fail_unless(c == 'k');
|
|
|
|
fail_unless(eina_value_list_get(value, 1, &c));
|
|
|
|
fail_unless(c == '-');
|
|
|
|
fail_unless(eina_value_list_get(value, 2, &c));
|
|
|
|
fail_unless(c == 's');
|
|
|
|
|
|
|
|
fail_unless(eina_value_list_insert(value, 0, '!'));
|
|
|
|
fail_unless(eina_value_list_get(value, 0, &c));
|
|
|
|
fail_unless(c == '!');
|
|
|
|
fail_unless(eina_value_list_get(value, 1, &c));
|
|
|
|
fail_unless(c == 'k');
|
|
|
|
fail_unless(eina_value_list_get(value, 2, &c));
|
|
|
|
fail_unless(c == '-');
|
|
|
|
fail_unless(eina_value_list_get(value, 3, &c));
|
|
|
|
fail_unless(c == 's');
|
|
|
|
|
|
|
|
fail_unless(eina_value_list_set(value, 0, '*'));
|
|
|
|
fail_unless(eina_value_list_get(value, 0, &c));
|
|
|
|
fail_unless(c == '*');
|
|
|
|
fail_unless(eina_value_list_get(value, 1, &c));
|
|
|
|
fail_unless(c == 'k');
|
|
|
|
fail_unless(eina_value_list_get(value, 2, &c));
|
|
|
|
fail_unless(c == '-');
|
|
|
|
fail_unless(eina_value_list_get(value, 3, &c));
|
|
|
|
fail_unless(c == 's');
|
|
|
|
|
2013-03-21 06:21:10 -07:00
|
|
|
snprintf(buf, sizeof(buf), "[%d, %d, %d, %d]",
|
|
|
|
(int) '*', (int) 'k', (int) '-', (int) 's');
|
2012-01-11 13:52:32 -08:00
|
|
|
|
|
|
|
str = eina_value_to_string(value);
|
|
|
|
fail_unless(str != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(str, buf);
|
2012-01-11 13:52:32 -08:00
|
|
|
free(str);
|
|
|
|
|
|
|
|
eina_value_flush(value);
|
|
|
|
fail_unless(eina_value_list_setup(value, EINA_VALUE_TYPE_STRINGSHARE));
|
|
|
|
|
|
|
|
fail_unless(eina_value_list_append(value, "Enlightenment.org"));
|
|
|
|
fail_unless(eina_value_list_append(value, "X11"));
|
|
|
|
fail_unless(eina_value_list_append(value, "Pants"));
|
|
|
|
fail_unless(eina_value_list_append(value, "on!!!"));
|
|
|
|
fail_unless(eina_value_list_append(value, "k-s"));
|
|
|
|
|
|
|
|
str = eina_value_to_string(value);
|
|
|
|
fail_unless(str != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(str, "[Enlightenment.org, X11, Pants, on!!!, k-s]");
|
2012-01-11 13:52:32 -08:00
|
|
|
free(str);
|
|
|
|
|
|
|
|
eina_value_flush(value);
|
|
|
|
fail_unless(eina_value_list_setup(value, EINA_VALUE_TYPE_CHAR));
|
|
|
|
fail_unless(eina_value_setup(&other, EINA_VALUE_TYPE_CHAR));
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(&other, 100));
|
|
|
|
fail_unless(eina_value_get(&other, &c));
|
|
|
|
fail_unless(c == 100);
|
|
|
|
|
|
|
|
fail_unless(eina_value_convert(&other, value));
|
|
|
|
str = eina_value_to_string(value);
|
|
|
|
fail_unless(str != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(str, "[100]");
|
2012-01-11 13:52:32 -08:00
|
|
|
free(str);
|
|
|
|
|
|
|
|
fail_unless(eina_value_list_set(value, 0, 33));
|
|
|
|
fail_unless(eina_value_convert(value, &other));
|
|
|
|
fail_unless(eina_value_get(&other, &c));
|
|
|
|
fail_unless(c == 33);
|
|
|
|
|
2012-01-12 09:15:49 -08:00
|
|
|
desc.subtype = EINA_VALUE_TYPE_STRING;
|
|
|
|
desc.list = NULL;
|
2012-02-10 16:34:25 -08:00
|
|
|
desc.list = eina_list_append(desc.list, "hello");
|
|
|
|
desc.list = eina_list_append(desc.list, "world");
|
|
|
|
desc.list = eina_list_append(desc.list, "eina");
|
2012-01-12 09:15:49 -08:00
|
|
|
fail_unless(eina_list_count(desc.list) == 3);
|
|
|
|
fail_unless(eina_value_set(value, desc));
|
2012-02-10 16:34:25 -08:00
|
|
|
eina_list_free(desc.list);
|
|
|
|
|
2012-01-12 09:15:49 -08:00
|
|
|
fail_unless(eina_value_list_get(value, 0, &s));
|
|
|
|
fail_unless(s != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(s, "hello");
|
2012-01-12 09:15:49 -08:00
|
|
|
fail_unless(eina_value_list_get(value, 1, &s));
|
|
|
|
fail_unless(s != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(s, "world");
|
2012-01-12 09:15:49 -08:00
|
|
|
fail_unless(eina_value_list_get(value, 2, &s));
|
|
|
|
fail_unless(s != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(s, "eina");
|
2012-01-12 09:15:49 -08:00
|
|
|
|
2012-01-11 13:52:32 -08:00
|
|
|
eina_value_free(value);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2012-01-11 13:52:32 -08:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_hash)
|
2012-01-11 15:54:35 -08:00
|
|
|
{
|
|
|
|
Eina_Value *value, other;
|
2012-01-12 09:27:53 -08:00
|
|
|
Eina_Value_Hash desc;
|
2012-01-11 15:54:35 -08:00
|
|
|
char c;
|
|
|
|
char buf[1024];
|
2012-01-12 09:27:53 -08:00
|
|
|
char **ptr;
|
2012-01-11 15:54:35 -08:00
|
|
|
char *str;
|
2012-01-12 09:27:53 -08:00
|
|
|
const char *s;
|
2012-01-11 15:54:35 -08:00
|
|
|
|
|
|
|
|
|
|
|
value = eina_value_hash_new(EINA_VALUE_TYPE_CHAR, 0);
|
|
|
|
fail_unless(value != NULL);
|
|
|
|
|
|
|
|
fail_unless(eina_value_hash_set(value, "first", 'k'));
|
|
|
|
fail_unless(eina_value_hash_set(value, "second", '-'));
|
|
|
|
fail_unless(eina_value_hash_set(value, "third", 's'));
|
|
|
|
|
|
|
|
fail_unless(eina_value_hash_get(value, "first", &c));
|
|
|
|
fail_unless(c == 'k');
|
|
|
|
fail_unless(eina_value_hash_get(value, "second", &c));
|
|
|
|
fail_unless(c == '-');
|
|
|
|
fail_unless(eina_value_hash_get(value, "third", &c));
|
|
|
|
fail_unless(c == 's');
|
|
|
|
|
|
|
|
fail_unless(eina_value_hash_set(value, "first", '!'));
|
|
|
|
fail_unless(eina_value_hash_get(value, "first", &c));
|
|
|
|
fail_unless(c == '!');
|
|
|
|
fail_unless(eina_value_hash_get(value, "second", &c));
|
|
|
|
fail_unless(c == '-');
|
|
|
|
fail_unless(eina_value_hash_get(value, "third", &c));
|
|
|
|
fail_unless(c == 's');
|
|
|
|
|
|
|
|
str = eina_value_to_string(value);
|
|
|
|
fail_unless(str != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
|
2013-03-21 06:21:10 -07:00
|
|
|
snprintf(buf, sizeof(buf), "first: %d", (int) '!');
|
2013-01-17 11:44:13 -08:00
|
|
|
fail_unless(strstr(str, buf) != NULL, "Couldn't find '%s' in '%s'", buf, str);
|
|
|
|
|
2013-03-21 06:21:10 -07:00
|
|
|
snprintf(buf, sizeof(buf), "second: %d", (int) '-');
|
2013-01-17 11:44:13 -08:00
|
|
|
fail_unless(strstr(str, buf) != NULL, "Couldn't find '%s' in '%s'", buf, str);
|
|
|
|
|
2013-03-21 06:21:10 -07:00
|
|
|
snprintf(buf, sizeof(buf), "third: %d", (int) 's');
|
2013-01-17 11:44:13 -08:00
|
|
|
fail_unless(strstr(str, buf) != NULL, "Couldn't find '%s' in '%s'", buf, str);
|
|
|
|
|
2012-01-11 15:54:35 -08:00
|
|
|
free(str);
|
|
|
|
|
|
|
|
eina_value_flush(value);
|
|
|
|
fail_unless(eina_value_hash_setup(value, EINA_VALUE_TYPE_STRINGSHARE, 0));
|
|
|
|
|
|
|
|
fail_unless(eina_value_hash_set(value, "a", "Enlightenment.org"));
|
|
|
|
fail_unless(eina_value_hash_set(value, "b", "X11"));
|
|
|
|
fail_unless(eina_value_hash_set(value, "c", "Pants"));
|
|
|
|
fail_unless(eina_value_hash_set(value, "d", "on!!!"));
|
|
|
|
fail_unless(eina_value_hash_set(value, "e", "k-s"));
|
|
|
|
|
|
|
|
str = eina_value_to_string(value);
|
|
|
|
fail_unless(str != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
|
|
|
|
eina_strlcpy(buf, "a: Enlightenment.org", sizeof(buf));
|
|
|
|
fail_unless(strstr(str, buf) != NULL, "Couldn't find '%s' in '%s'", buf, str);
|
|
|
|
|
|
|
|
eina_strlcpy(buf, "b: X11", sizeof(buf));
|
|
|
|
fail_unless(strstr(str, buf) != NULL, "Couldn't find '%s' in '%s'", buf, str);
|
|
|
|
|
|
|
|
eina_strlcpy(buf, "c: Pants", sizeof(buf));
|
|
|
|
fail_unless(strstr(str, buf) != NULL, "Couldn't find '%s' in '%s'", buf, str);
|
|
|
|
|
|
|
|
eina_strlcpy(buf, "d: on!!!", sizeof(buf));
|
|
|
|
fail_unless(strstr(str, buf) != NULL, "Couldn't find '%s' in '%s'", buf, str);
|
|
|
|
|
|
|
|
eina_strlcpy(buf, "e: k-s", sizeof(buf));
|
|
|
|
fail_unless(strstr(str, buf) != NULL, "Couldn't find '%s' in '%s'", buf, str);
|
|
|
|
|
2012-01-11 15:54:35 -08:00
|
|
|
free(str);
|
|
|
|
|
|
|
|
eina_value_flush(value);
|
|
|
|
fail_unless(eina_value_hash_setup(value, EINA_VALUE_TYPE_CHAR, 0));
|
|
|
|
fail_unless(eina_value_setup(&other, EINA_VALUE_TYPE_CHAR));
|
|
|
|
|
|
|
|
fail_unless(eina_value_set(&other, 100));
|
|
|
|
fail_unless(eina_value_get(&other, &c));
|
|
|
|
fail_unless(c == 100);
|
|
|
|
|
|
|
|
fail_unless(eina_value_hash_set(value, "first", 33));
|
|
|
|
fail_unless(eina_value_convert(value, &other));
|
|
|
|
fail_unless(eina_value_get(&other, &c));
|
|
|
|
fail_unless(c == 33);
|
|
|
|
|
2012-01-12 09:27:53 -08:00
|
|
|
desc.subtype = EINA_VALUE_TYPE_STRING;
|
|
|
|
desc.buckets_power_size = 0;
|
|
|
|
desc.hash = eina_hash_string_small_new(NULL);
|
|
|
|
fail_unless(desc.hash != NULL);
|
|
|
|
/* watch out hash pointer is to a size of subtype->value_size! */
|
|
|
|
ptr = malloc(sizeof(char *));
|
2012-02-10 16:34:25 -08:00
|
|
|
*ptr = "there";
|
2012-01-12 09:27:53 -08:00
|
|
|
fail_unless(eina_hash_add(desc.hash, "hi", ptr));
|
|
|
|
ptr = malloc(sizeof(char *));
|
2012-02-10 16:34:25 -08:00
|
|
|
*ptr = "y";
|
2012-01-12 09:27:53 -08:00
|
|
|
fail_unless(eina_hash_add(desc.hash, "x", ptr));
|
|
|
|
fail_unless(eina_value_set(value, desc));
|
|
|
|
|
2012-02-10 16:34:25 -08:00
|
|
|
free(eina_hash_find(desc.hash, "hi"));
|
|
|
|
free(eina_hash_find(desc.hash, "x"));
|
|
|
|
eina_hash_free(desc.hash);
|
|
|
|
|
2012-01-12 09:27:53 -08:00
|
|
|
fail_unless(eina_value_hash_get(value, "hi", &s));
|
|
|
|
fail_unless(s != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(s, "there");
|
2012-01-12 09:27:53 -08:00
|
|
|
|
|
|
|
fail_unless(eina_value_hash_get(value, "x", &s));
|
|
|
|
fail_unless(s != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(s, "y");
|
2012-01-12 09:27:53 -08:00
|
|
|
|
2012-01-11 15:54:35 -08:00
|
|
|
eina_value_free(value);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2012-01-11 15:54:35 -08:00
|
|
|
|
2012-01-11 17:31:21 -08:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_timeval)
|
2012-01-11 17:31:21 -08:00
|
|
|
{
|
|
|
|
Eina_Value *value, other;
|
|
|
|
struct timeval itv, otv;
|
2015-01-30 01:49:57 -08:00
|
|
|
time_t t;
|
2012-01-11 17:31:21 -08:00
|
|
|
char c;
|
|
|
|
char *str;
|
2013-01-17 12:36:52 -08:00
|
|
|
char buf[64];
|
2012-01-11 17:31:21 -08:00
|
|
|
|
|
|
|
|
|
|
|
value = eina_value_new(EINA_VALUE_TYPE_TIMEVAL);
|
|
|
|
fail_unless(value != NULL);
|
|
|
|
|
|
|
|
itv.tv_sec = 1;
|
|
|
|
itv.tv_usec = 123;
|
|
|
|
fail_unless(eina_value_set(value, itv));
|
|
|
|
fail_unless(eina_value_get(value, &otv));
|
2014-12-11 02:21:50 -08:00
|
|
|
fail_unless(itv.tv_sec == otv.tv_sec);
|
|
|
|
fail_unless(itv.tv_usec == otv.tv_usec);
|
2012-01-11 17:31:21 -08:00
|
|
|
|
|
|
|
itv.tv_sec = 3;
|
|
|
|
itv.tv_usec = -1;
|
|
|
|
fail_unless(eina_value_set(value, itv));
|
|
|
|
fail_unless(eina_value_get(value, &otv));
|
|
|
|
itv.tv_sec = 2;
|
|
|
|
itv.tv_usec = 999999;
|
2014-12-11 02:21:50 -08:00
|
|
|
fail_unless(itv.tv_sec == otv.tv_sec);
|
|
|
|
fail_unless(itv.tv_usec == otv.tv_usec);
|
2012-01-11 17:31:21 -08:00
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&other, EINA_VALUE_TYPE_CHAR));
|
|
|
|
fail_unless(eina_value_convert(value, &other));
|
|
|
|
fail_unless(eina_value_get(&other, &c));
|
|
|
|
fail_unless(c == 2);
|
|
|
|
eina_value_flush(&other);
|
|
|
|
|
|
|
|
itv.tv_sec = 12345;
|
|
|
|
itv.tv_usec = 6789;
|
|
|
|
fail_unless(eina_value_set(value, itv));
|
|
|
|
str = eina_value_to_string(value);
|
|
|
|
fail_unless(str != NULL);
|
2013-01-17 12:36:52 -08:00
|
|
|
|
2015-01-30 01:49:57 -08:00
|
|
|
t = itv.tv_sec;
|
|
|
|
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", localtime(&(t)));
|
2013-01-17 12:36:52 -08:00
|
|
|
ck_assert_str_eq(str, buf);
|
2012-01-11 17:31:21 -08:00
|
|
|
free(str);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&other, EINA_VALUE_TYPE_TIMEVAL));
|
|
|
|
fail_unless(eina_value_set(&other, itv));
|
|
|
|
fail_unless(eina_value_compare(value, &other) == 0);
|
|
|
|
|
|
|
|
itv.tv_sec++;
|
|
|
|
fail_unless(eina_value_set(&other, itv));
|
|
|
|
fail_unless(eina_value_compare(value, &other) < 0);
|
|
|
|
|
|
|
|
itv.tv_sec -= 2;
|
|
|
|
fail_unless(eina_value_set(&other, itv));
|
|
|
|
fail_unless(eina_value_compare(value, &other) > 0);
|
|
|
|
|
|
|
|
itv.tv_sec++;
|
|
|
|
fail_unless(eina_value_set(&other, itv));
|
|
|
|
fail_unless(eina_value_compare(value, &other) == 0);
|
|
|
|
|
|
|
|
itv.tv_usec++;
|
|
|
|
fail_unless(eina_value_set(&other, itv));
|
|
|
|
fail_unless(eina_value_compare(value, &other) < 0);
|
|
|
|
|
|
|
|
itv.tv_usec -= 2;
|
|
|
|
fail_unless(eina_value_set(&other, itv));
|
|
|
|
fail_unless(eina_value_compare(value, &other) > 0);
|
|
|
|
|
|
|
|
itv.tv_usec++;
|
|
|
|
fail_unless(eina_value_set(&other, itv));
|
|
|
|
fail_unless(eina_value_compare(value, &other) == 0);
|
|
|
|
|
2012-01-11 19:00:03 -08:00
|
|
|
eina_value_flush(&other);
|
|
|
|
|
|
|
|
|
|
|
|
eina_value_free(value);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2012-01-11 19:00:03 -08:00
|
|
|
|
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_blob)
|
2012-01-11 19:00:03 -08:00
|
|
|
{
|
|
|
|
Eina_Value *value, other;
|
|
|
|
Eina_Value_Blob in, out;
|
|
|
|
unsigned char blob[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
|
|
|
int i = 0x11223344;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
|
|
|
|
value = eina_value_new(EINA_VALUE_TYPE_BLOB);
|
|
|
|
fail_unless(value != NULL);
|
|
|
|
|
|
|
|
in.ops = NULL;
|
|
|
|
in.memory = blob;
|
|
|
|
in.size = sizeof(blob);
|
|
|
|
fail_unless(eina_value_set(value, in));
|
|
|
|
fail_unless(eina_value_get(value, &out));
|
|
|
|
fail_unless(out.memory == blob);
|
|
|
|
fail_unless(out.size == sizeof(blob));
|
2016-04-19 00:33:33 -07:00
|
|
|
fail_unless(memcmp(in.memory, out.memory, in.size) == 0);
|
2012-01-11 19:00:03 -08:00
|
|
|
|
|
|
|
str = eina_value_to_string(value);
|
|
|
|
fail_unless(str != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(str, "BLOB(10, [01 02 03 04 05 06 07 08 09 0a])");
|
2012-01-11 19:00:03 -08:00
|
|
|
free(str);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&other, EINA_VALUE_TYPE_INT));
|
|
|
|
fail_unless(eina_value_set(&other, i));
|
|
|
|
fail_unless(eina_value_convert(&other, value));
|
|
|
|
fail_unless(eina_value_get(value, &out));
|
|
|
|
|
|
|
|
fail_unless(out.memory != NULL);
|
|
|
|
fail_unless(out.size == sizeof(int));
|
|
|
|
fail_unless(memcmp(&i, out.memory, sizeof(int)) == 0);
|
2012-01-11 17:31:21 -08:00
|
|
|
|
|
|
|
eina_value_flush(&other);
|
|
|
|
|
2012-01-12 11:39:16 -08:00
|
|
|
fail_unless(eina_value_setup(&other, EINA_VALUE_TYPE_STRING));
|
|
|
|
fail_unless(eina_value_set(&other, "hi there!"));
|
|
|
|
fail_unless(eina_value_convert(&other, value));
|
|
|
|
fail_unless(eina_value_get(value, &out));
|
|
|
|
fail_unless(out.memory != NULL);
|
|
|
|
fail_unless(out.size == sizeof("hi there!"));
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(out.memory, "hi there!");
|
2012-01-12 11:39:16 -08:00
|
|
|
|
|
|
|
str = eina_value_to_string(value);
|
|
|
|
fail_unless(str != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(str, "BLOB(10, [68 69 20 74 68 65 72 65 21 00])");
|
2012-01-12 11:39:16 -08:00
|
|
|
free(str);
|
|
|
|
|
|
|
|
eina_value_flush(&other);
|
|
|
|
|
|
|
|
fail_unless(eina_value_array_setup(&other, EINA_VALUE_TYPE_CHAR, 0));
|
|
|
|
fail_unless(eina_value_array_append(&other, 0xa));
|
|
|
|
fail_unless(eina_value_array_append(&other, 0xb));
|
|
|
|
fail_unless(eina_value_array_append(&other, 0xc));
|
|
|
|
fail_unless(eina_value_convert(&other, value));
|
|
|
|
fail_unless(eina_value_get(value, &out));
|
|
|
|
fail_unless(out.memory != NULL);
|
|
|
|
fail_unless(out.size == 3);
|
|
|
|
|
|
|
|
str = eina_value_to_string(value);
|
|
|
|
fail_unless(str != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(str, "BLOB(3, [0a 0b 0c])");
|
2012-01-12 11:39:16 -08:00
|
|
|
free(str);
|
|
|
|
|
|
|
|
eina_value_flush(&other);
|
|
|
|
|
|
|
|
fail_unless(eina_value_setup(&other, EINA_VALUE_TYPE_BLOB));
|
|
|
|
fail_unless(eina_value_set(&other, in));
|
|
|
|
fail_unless(eina_value_convert(value, &other));
|
|
|
|
fail_unless(eina_value_get(&other, &out));
|
|
|
|
fail_unless(out.memory != NULL);
|
|
|
|
fail_unless(out.size == 3);
|
|
|
|
|
|
|
|
str = eina_value_to_string(&other);
|
|
|
|
fail_unless(str != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(str, "BLOB(3, [0a 0b 0c])");
|
2012-01-12 11:39:16 -08:00
|
|
|
free(str);
|
|
|
|
|
|
|
|
eina_value_flush(&other);
|
2012-01-11 17:31:21 -08:00
|
|
|
|
|
|
|
eina_value_free(value);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2012-01-11 17:31:21 -08:00
|
|
|
|
2012-01-12 14:58:31 -08:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_struct)
|
2012-01-12 14:58:31 -08:00
|
|
|
{
|
|
|
|
struct mybigst {
|
|
|
|
int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, x;
|
|
|
|
};
|
|
|
|
const Eina_Value_Struct_Member mybigst_members[] = {
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, a),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, b),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, c),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, d),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, e),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, f),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, g),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, h),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, i),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, j),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, k),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, l),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, m),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, n),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, o),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, p),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, q),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, r),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, s),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, t),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, u),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, v),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct mybigst, x),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER_SENTINEL
|
|
|
|
};
|
|
|
|
const Eina_Value_Struct_Desc mybigst_desc = {
|
|
|
|
EINA_VALUE_STRUCT_DESC_VERSION,
|
|
|
|
EINA_VALUE_STRUCT_OPERATIONS_BINSEARCH,
|
|
|
|
mybigst_members, 23, sizeof(struct mybigst)
|
|
|
|
};
|
|
|
|
struct myst {
|
|
|
|
int i;
|
|
|
|
char c;
|
|
|
|
};
|
|
|
|
const Eina_Value_Struct_Member myst_members[] = {
|
|
|
|
{"i", EINA_VALUE_TYPE_INT, 0},
|
|
|
|
{"c", EINA_VALUE_TYPE_CHAR, 4},
|
|
|
|
{NULL, NULL, 0}
|
|
|
|
};
|
|
|
|
const Eina_Value_Struct_Desc myst_desc = {
|
|
|
|
EINA_VALUE_STRUCT_DESC_VERSION,
|
|
|
|
NULL, myst_members, 2, sizeof(struct myst)
|
|
|
|
};
|
|
|
|
Eina_Value *value, other;
|
|
|
|
int i;
|
|
|
|
char c;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
|
|
|
|
value = eina_value_struct_new(&myst_desc);
|
|
|
|
fail_unless(value != NULL);
|
|
|
|
|
|
|
|
fail_unless(eina_value_struct_set(value, "i", 5678));
|
|
|
|
fail_unless(eina_value_struct_set(value, "c", 0xf));
|
|
|
|
|
|
|
|
fail_unless(eina_value_struct_get(value, "i", &i));
|
|
|
|
fail_unless(i == 5678);
|
|
|
|
fail_unless(eina_value_struct_get(value, "c", &c));
|
|
|
|
fail_unless(c == 0xf);
|
|
|
|
|
2012-01-25 08:58:57 -08:00
|
|
|
fail_unless(eina_value_struct_member_value_get
|
|
|
|
(value, myst_members + 0, &other));
|
|
|
|
fail_unless(other.type == EINA_VALUE_TYPE_INT);
|
|
|
|
fail_unless(eina_value_get(&other, &i));
|
|
|
|
fail_unless(i == 5678);
|
|
|
|
eina_value_flush(&other);
|
|
|
|
|
|
|
|
fail_unless(eina_value_struct_member_value_get
|
|
|
|
(value, myst_members + 1, &other));
|
|
|
|
fail_unless(other.type == EINA_VALUE_TYPE_CHAR);
|
|
|
|
fail_unless(eina_value_get(&other, &c));
|
|
|
|
fail_unless(c = 0xf);
|
|
|
|
eina_value_flush(&other);
|
|
|
|
|
2012-01-12 14:58:31 -08:00
|
|
|
str = eina_value_to_string(value);
|
|
|
|
fail_unless(str != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(str, "{i: 5678, c: 15}");
|
2012-01-12 14:58:31 -08:00
|
|
|
free(str);
|
|
|
|
|
|
|
|
fail_if(eina_value_struct_get(value, "x", 1234));
|
|
|
|
|
|
|
|
i = 0x11223344;
|
|
|
|
fail_unless(eina_value_struct_pset(value, "i", &i));
|
|
|
|
i = -1;
|
|
|
|
fail_unless(eina_value_struct_pget(value, "i", &i));
|
|
|
|
fail_unless(i == 0x11223344);
|
|
|
|
|
|
|
|
fail_unless(eina_value_copy(value, &other));
|
|
|
|
str = eina_value_to_string(&other);
|
|
|
|
fail_unless(str != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(str, "{i: 287454020, c: 15}");
|
2012-01-12 14:58:31 -08:00
|
|
|
free(str);
|
|
|
|
|
|
|
|
eina_value_flush(&other);
|
|
|
|
|
|
|
|
fail_unless(eina_value_struct_setup(&other, &mybigst_desc));
|
|
|
|
fail_unless(eina_value_struct_set(&other, "a", 1) );
|
|
|
|
fail_unless(eina_value_struct_set(&other, "b", 2));
|
|
|
|
fail_unless(eina_value_struct_set(&other, "c", 3));
|
|
|
|
fail_unless(eina_value_struct_set(&other, "d", 4));
|
|
|
|
fail_unless(eina_value_struct_set(&other, "e", 5));
|
|
|
|
fail_unless(eina_value_struct_set(&other, "f", 6));
|
|
|
|
fail_unless(eina_value_struct_set(&other, "g", 7));
|
|
|
|
fail_unless(eina_value_struct_set(&other, "h", 8));
|
|
|
|
fail_unless(eina_value_struct_set(&other, "i", 9));
|
|
|
|
fail_unless(eina_value_struct_set(&other, "j", 10));
|
|
|
|
fail_unless(eina_value_struct_set(&other, "k", 12));
|
|
|
|
fail_unless(eina_value_struct_set(&other, "l", 13));
|
|
|
|
fail_unless(eina_value_struct_set(&other, "m", 14));
|
|
|
|
fail_unless(eina_value_struct_set(&other, "n", 15));
|
|
|
|
fail_unless(eina_value_struct_set(&other, "o", 16));
|
|
|
|
fail_unless(eina_value_struct_set(&other, "p", 17));
|
|
|
|
fail_unless(eina_value_struct_set(&other, "q", 18));
|
|
|
|
fail_unless(eina_value_struct_set(&other, "r", 19));
|
|
|
|
fail_unless(eina_value_struct_set(&other, "s", 20));
|
|
|
|
fail_unless(eina_value_struct_set(&other, "t", 21));
|
|
|
|
fail_unless(eina_value_struct_set(&other, "u", 22));
|
|
|
|
fail_unless(eina_value_struct_set(&other, "v", 23));
|
|
|
|
fail_unless(eina_value_struct_set(&other, "x", 24));
|
|
|
|
|
|
|
|
fail_unless(eina_value_struct_get(&other, "a", &i));
|
|
|
|
fail_unless(i == 1);
|
|
|
|
fail_unless(eina_value_struct_get(&other, "b", &i));
|
|
|
|
fail_unless(i == 2);
|
|
|
|
fail_unless(eina_value_struct_get(&other, "c", &i));
|
|
|
|
fail_unless(i == 3);
|
|
|
|
fail_unless(eina_value_struct_get(&other, "d", &i));
|
|
|
|
fail_unless(i == 4);
|
|
|
|
fail_unless(eina_value_struct_get(&other, "e", &i));
|
|
|
|
fail_unless(i == 5);
|
|
|
|
fail_unless(eina_value_struct_get(&other, "f", &i));
|
|
|
|
fail_unless(i == 6);
|
|
|
|
fail_unless(eina_value_struct_get(&other, "g", &i));
|
|
|
|
fail_unless(i == 7);
|
|
|
|
fail_unless(eina_value_struct_get(&other, "h", &i));
|
|
|
|
fail_unless(i == 8);
|
|
|
|
fail_unless(eina_value_struct_get(&other, "i", &i));
|
|
|
|
fail_unless(i == 9);
|
|
|
|
fail_unless(eina_value_struct_get(&other, "j", &i));
|
|
|
|
fail_unless(i == 10);
|
|
|
|
fail_unless(eina_value_struct_get(&other, "k", &i));
|
|
|
|
fail_unless(i == 12);
|
|
|
|
fail_unless(eina_value_struct_get(&other, "l", &i));
|
|
|
|
fail_unless(i == 13);
|
|
|
|
fail_unless(eina_value_struct_get(&other, "m", &i));
|
|
|
|
fail_unless(i == 14);
|
|
|
|
fail_unless(eina_value_struct_get(&other, "n", &i));
|
|
|
|
fail_unless(i == 15);
|
|
|
|
fail_unless(eina_value_struct_get(&other, "o", &i));
|
|
|
|
fail_unless(i == 16);
|
|
|
|
fail_unless(eina_value_struct_get(&other, "p", &i));
|
|
|
|
fail_unless(i == 17);
|
|
|
|
fail_unless(eina_value_struct_get(&other, "q", &i));
|
|
|
|
fail_unless(i == 18);
|
|
|
|
fail_unless(eina_value_struct_get(&other, "r", &i));
|
|
|
|
fail_unless(i == 19);
|
|
|
|
fail_unless(eina_value_struct_get(&other, "s", &i));
|
|
|
|
fail_unless(i == 20);
|
|
|
|
fail_unless(eina_value_struct_get(&other, "t", &i));
|
|
|
|
fail_unless(i == 21);
|
|
|
|
fail_unless(eina_value_struct_get(&other, "u", &i));
|
|
|
|
fail_unless(i == 22);
|
|
|
|
fail_unless(eina_value_struct_get(&other, "v", &i));
|
|
|
|
fail_unless(i == 23);
|
|
|
|
fail_unless(eina_value_struct_get(&other, "x", &i));
|
|
|
|
fail_unless(i == 24);
|
|
|
|
|
|
|
|
str = eina_value_to_string(&other);
|
|
|
|
fail_unless(str != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(str, "{a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10, k: 12, l: 13, m: 14, n: 15, o: 16, p: 17, q: 18, r: 19, s: 20, t: 21, u: 22, v: 23, x: 24}");
|
2012-01-12 14:58:31 -08:00
|
|
|
free(str);
|
|
|
|
|
2012-02-10 12:39:27 -08:00
|
|
|
eina_value_flush(&other);
|
2012-01-12 14:58:31 -08:00
|
|
|
eina_value_free(value);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2012-01-12 14:58:31 -08:00
|
|
|
|
2012-01-12 15:31:42 -08:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_array_of_struct)
|
2012-01-12 15:31:42 -08:00
|
|
|
{
|
|
|
|
struct myst {
|
|
|
|
int a, b, c;
|
|
|
|
const char *s;
|
|
|
|
};
|
|
|
|
const Eina_Value_Struct_Member myst_members[] = {
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct myst, a),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct myst, b),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT, struct myst, c),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_STRING, struct myst, s),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER_SENTINEL
|
|
|
|
};
|
|
|
|
const Eina_Value_Struct_Desc myst_desc = {
|
|
|
|
EINA_VALUE_STRUCT_DESC_VERSION,
|
|
|
|
EINA_VALUE_STRUCT_OPERATIONS_BINSEARCH,
|
|
|
|
myst_members, 4, sizeof(struct myst)
|
|
|
|
};
|
2012-03-01 09:15:54 -08:00
|
|
|
Eina_Value *value, array_item;
|
2012-01-12 15:31:42 -08:00
|
|
|
char *str;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
|
|
value = eina_value_array_new(EINA_VALUE_TYPE_STRUCT, 0);
|
|
|
|
fail_unless(value != NULL);
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
Eina_Value_Struct desc;
|
2012-02-10 16:34:25 -08:00
|
|
|
struct myst st;
|
2012-01-12 15:31:42 -08:00
|
|
|
char buf[64];
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "item%02d", i);
|
2012-02-10 16:34:25 -08:00
|
|
|
st.a = i;
|
|
|
|
st.b = i * 10;
|
|
|
|
st.c = i * 100;
|
|
|
|
st.s = buf;
|
2012-01-12 15:31:42 -08:00
|
|
|
|
|
|
|
desc.desc = &myst_desc;
|
2012-02-10 16:34:25 -08:00
|
|
|
desc.memory = &st;
|
2012-01-12 15:31:42 -08:00
|
|
|
fail_unless(eina_value_array_append(value, desc));
|
|
|
|
}
|
|
|
|
|
|
|
|
str = eina_value_to_string(value);
|
|
|
|
fail_unless(str != NULL);
|
2013-01-17 11:44:13 -08:00
|
|
|
ck_assert_str_eq(str, "["
|
2012-01-12 15:31:42 -08:00
|
|
|
"{a: 0, b: 0, c: 0, s: item00}, "
|
|
|
|
"{a: 1, b: 10, c: 100, s: item01}, "
|
|
|
|
"{a: 2, b: 20, c: 200, s: item02}, "
|
|
|
|
"{a: 3, b: 30, c: 300, s: item03}, "
|
|
|
|
"{a: 4, b: 40, c: 400, s: item04}, "
|
|
|
|
"{a: 5, b: 50, c: 500, s: item05}, "
|
|
|
|
"{a: 6, b: 60, c: 600, s: item06}, "
|
|
|
|
"{a: 7, b: 70, c: 700, s: item07}, "
|
|
|
|
"{a: 8, b: 80, c: 800, s: item08}, "
|
|
|
|
"{a: 9, b: 90, c: 900, s: item09}"
|
2013-01-17 11:44:13 -08:00
|
|
|
"]");
|
2012-01-12 15:31:42 -08:00
|
|
|
free(str);
|
|
|
|
|
2012-03-01 09:15:54 -08:00
|
|
|
eina_value_array_value_get(value, 2, &array_item);
|
|
|
|
eina_value_struct_get(&array_item, "a", &i);
|
|
|
|
ck_assert_int_eq(i, 2);
|
|
|
|
eina_value_struct_get(&array_item, "b", &i);
|
|
|
|
ck_assert_int_eq(i, 20);
|
|
|
|
eina_value_struct_get(&array_item, "c", &i);
|
|
|
|
ck_assert_int_eq(i, 200);
|
|
|
|
eina_value_struct_get(&array_item, "s", &str);
|
|
|
|
ck_assert_str_eq(str, "item02");
|
|
|
|
eina_value_flush(&array_item);
|
|
|
|
|
2012-01-12 15:31:42 -08:00
|
|
|
eina_value_free(value);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2012-01-12 15:31:42 -08:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_optional_int)
|
2015-07-08 20:57:38 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
/* Eina_Value *value = eina_value_new(EINA_VALUE_TYPE_OPTIONAL); */
|
|
|
|
/* Eina_Bool is_empty; */
|
|
|
|
/* ck_assert(eina_value_optional_empty_is(value, &is_empty)); */
|
|
|
|
/* ck_assert(is_empty); */
|
|
|
|
|
|
|
|
/* // sets expectation */
|
|
|
|
/* int expected_value = -12345; */
|
|
|
|
/* ck_assert(eina_value_optional_pset(value, EINA_VALUE_TYPE_INT, &expected_value)); */
|
|
|
|
/* ck_assert(eina_value_optional_empty_is(value, &is_empty)); */
|
|
|
|
/* ck_assert(!is_empty); */
|
|
|
|
|
|
|
|
/* // gets the actual value */
|
|
|
|
/* int actual_value; */
|
|
|
|
/* ck_assert(eina_value_optional_pget(value, &actual_value)); */
|
|
|
|
/* ck_assert_int_eq(expected_value, actual_value); */
|
|
|
|
|
|
|
|
/* // resets the optional */
|
|
|
|
/* ck_assert(eina_value_optional_reset(value)); */
|
|
|
|
/* ck_assert(eina_value_optional_empty_is(value, &is_empty)); */
|
|
|
|
/* ck_assert(is_empty); */
|
|
|
|
|
|
|
|
/* // Sets expectation again after reset */
|
|
|
|
/* expected_value = -54321; */
|
|
|
|
/* ck_assert(eina_value_optional_pset(value, EINA_VALUE_TYPE_INT, &expected_value)); */
|
|
|
|
/* ck_assert(eina_value_optional_empty_is(value, &is_empty)); */
|
|
|
|
/* ck_assert(!is_empty); */
|
2016-02-04 05:44:58 -08:00
|
|
|
|
2015-07-08 20:57:38 -07:00
|
|
|
/* // gets the actual value */
|
|
|
|
/* ck_assert(eina_value_optional_pget(value, &actual_value)); */
|
|
|
|
/* ck_assert_int_eq(expected_value, actual_value); */
|
|
|
|
|
|
|
|
/* eina_value_free(value); */
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2015-07-08 20:57:38 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_optional_string)
|
2015-07-08 20:57:38 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
Eina_Value *value = eina_value_new(EINA_VALUE_TYPE_OPTIONAL);
|
|
|
|
Eina_Bool is_empty;
|
|
|
|
ck_assert(eina_value_optional_empty_is(value, &is_empty));
|
|
|
|
ck_assert(is_empty);
|
|
|
|
ck_assert(EINA_VALUE_TYPE_OPTIONAL);
|
|
|
|
|
|
|
|
// sets expectation
|
|
|
|
const char *expected_value = "Hello world!";
|
|
|
|
ck_assert(eina_value_optional_pset(value, EINA_VALUE_TYPE_STRING, &expected_value));
|
|
|
|
ck_assert(eina_value_optional_empty_is(value, &is_empty));
|
|
|
|
ck_assert(!is_empty);
|
|
|
|
|
|
|
|
// gets the actual value
|
|
|
|
const char *actual_value;
|
|
|
|
ck_assert(eina_value_optional_pget(value, &actual_value));
|
|
|
|
ck_assert_str_eq(expected_value, actual_value);
|
|
|
|
|
|
|
|
// resets the optional
|
|
|
|
ck_assert(eina_value_optional_reset(value));
|
|
|
|
ck_assert(eina_value_optional_empty_is(value, &is_empty));
|
|
|
|
ck_assert(is_empty);
|
|
|
|
|
|
|
|
// Sets expectation again after reset
|
|
|
|
expected_value = "!dlrow olleH";
|
|
|
|
ck_assert(eina_value_optional_pset(value, EINA_VALUE_TYPE_STRING, &expected_value));
|
|
|
|
ck_assert(eina_value_optional_empty_is(value, &is_empty));
|
|
|
|
ck_assert(!is_empty);
|
|
|
|
|
|
|
|
// gets the actual value
|
|
|
|
ck_assert(eina_value_optional_pget(value, &actual_value));
|
|
|
|
ck_assert_str_eq(expected_value, actual_value);
|
|
|
|
|
|
|
|
eina_value_free(value);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2015-07-08 20:57:38 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_optional_struct_members)
|
2015-07-08 20:57:38 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
struct s {
|
|
|
|
int64_t a;
|
|
|
|
Eina_Value_Optional text;
|
|
|
|
int64_t b;
|
|
|
|
};
|
|
|
|
const Eina_Value_Struct_Member members[] = {
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT64, struct s, a),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_OPTIONAL, struct s, text),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT64, struct s, b),
|
|
|
|
EINA_VALUE_STRUCT_MEMBER_SENTINEL
|
|
|
|
};
|
|
|
|
const Eina_Value_Struct_Desc desc = {
|
|
|
|
EINA_VALUE_STRUCT_DESC_VERSION,
|
|
|
|
NULL, members, 3, sizeof(struct s)
|
|
|
|
};
|
|
|
|
|
|
|
|
Eina_Value *value = eina_value_struct_new(&desc);
|
|
|
|
ck_assert_ptr_ne(NULL, value);
|
|
|
|
|
|
|
|
int64_t expected_a = 0x1234567887654321ll;
|
|
|
|
fail_unless(eina_value_struct_set(value, "a", expected_a));
|
|
|
|
int64_t actual_a;
|
|
|
|
fail_unless(eina_value_struct_get(value, "a", &actual_a));
|
|
|
|
ck_assert_int_eq(expected_a, actual_a);
|
|
|
|
|
|
|
|
int64_t expected_b = 0xEEDCBA9889ABCDEFll;
|
|
|
|
fail_unless(eina_value_struct_set(value, "b", expected_b));
|
|
|
|
int64_t actual_b;
|
|
|
|
fail_unless(eina_value_struct_get(value, "b", &actual_b));
|
|
|
|
ck_assert_int_eq(expected_b, actual_b);
|
|
|
|
|
|
|
|
Eina_Value expected_value;
|
|
|
|
fail_unless(eina_value_setup(&expected_value, EINA_VALUE_TYPE_OPTIONAL));
|
|
|
|
const char* str = "Hello world!";
|
|
|
|
fail_unless(eina_value_optional_pset(&expected_value, EINA_VALUE_TYPE_STRING, &str));
|
|
|
|
fail_unless(eina_value_struct_value_set(value, "text", &expected_value));
|
|
|
|
|
|
|
|
Eina_Value actual_value;
|
|
|
|
fail_unless(eina_value_struct_value_get(value, "text", &actual_value));
|
|
|
|
fail_unless(eina_value_compare(&expected_value, &actual_value) == 0);
|
|
|
|
|
|
|
|
// tests if the value have been overriden
|
|
|
|
fail_unless(eina_value_struct_get(value, "a", &actual_a));
|
|
|
|
ck_assert_int_eq(expected_a, actual_a);
|
|
|
|
fail_unless(eina_value_struct_get(value, "b", &actual_b));
|
|
|
|
ck_assert_int_eq(expected_b, actual_b);
|
|
|
|
|
|
|
|
eina_value_flush(&actual_value);
|
|
|
|
eina_value_flush(&expected_value);
|
2016-02-04 05:44:58 -08:00
|
|
|
|
2015-07-08 20:57:38 -07:00
|
|
|
eina_value_free(value);
|
|
|
|
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2015-07-08 20:57:38 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_value)
|
2017-08-17 10:36:47 -07:00
|
|
|
{
|
|
|
|
Eina_Value composed, v;
|
|
|
|
const int ivalue = 3500;
|
|
|
|
int i;
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
|
|
|
|
fail_if(!eina_value_setup(&composed, EINA_VALUE_TYPE_VALUE));
|
|
|
|
fail_if(!eina_value_setup(&v, EINA_VALUE_TYPE_INT));
|
|
|
|
fail_if(!eina_value_set(&v, ivalue));
|
|
|
|
fail_if(!eina_value_set(&composed, v));
|
|
|
|
|
|
|
|
fail_if(!eina_value_get(&composed, &v));
|
|
|
|
fail_if(!eina_value_get(&v, &i));
|
|
|
|
fail_if(i != ivalue);
|
|
|
|
|
|
|
|
eina_value_flush(&v);
|
|
|
|
fail_if(!eina_value_setup(&v, EINA_VALUE_TYPE_STRING));
|
|
|
|
fail_if(!eina_value_convert(&composed, &v));
|
|
|
|
fail_if(!eina_value_get(&v, &str));
|
|
|
|
ck_assert_str_eq(str, "3500");
|
|
|
|
|
|
|
|
eina_value_flush(&v);
|
|
|
|
fail_if(!eina_value_copy(&composed, &v));
|
|
|
|
fail_if(eina_value_compare(&composed, &v));
|
|
|
|
|
|
|
|
eina_value_flush(&v);
|
|
|
|
eina_value_flush(&composed);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2017-08-17 10:36:47 -07:00
|
|
|
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_START_TEST(eina_value_test_value_string)
|
2017-08-17 10:36:47 -07:00
|
|
|
{
|
|
|
|
Eina_Value composed, v, str_v;
|
|
|
|
const char *msg = "A string", *str;
|
|
|
|
|
|
|
|
|
|
|
|
fail_if(!eina_value_setup(&composed, EINA_VALUE_TYPE_VALUE));
|
|
|
|
fail_if(!eina_value_setup(&v, EINA_VALUE_TYPE_STRING));
|
|
|
|
fail_if(!eina_value_set(&v, msg));
|
|
|
|
fail_if(!eina_value_set(&composed, v));
|
|
|
|
|
|
|
|
eina_value_flush(&v);
|
|
|
|
fail_if(!eina_value_copy(&composed, &v));
|
|
|
|
fail_if(eina_value_compare(&composed, &v));
|
|
|
|
|
|
|
|
fail_if(!eina_value_get(&composed, &str_v));
|
|
|
|
fail_if(!eina_value_get(&str_v, &str));
|
|
|
|
ck_assert_str_eq(str, msg);
|
|
|
|
eina_value_flush(&str_v);
|
|
|
|
|
|
|
|
str = NULL;
|
|
|
|
fail_if(!eina_value_get(&v, &str_v));
|
|
|
|
fail_if(!eina_value_get(&str_v, &str));
|
|
|
|
ck_assert_str_eq(str, msg);
|
|
|
|
|
|
|
|
eina_value_flush(&str_v);
|
|
|
|
eina_value_flush(&composed);
|
|
|
|
eina_value_flush(&v);
|
|
|
|
}
|
2018-03-26 11:19:28 -07:00
|
|
|
EFL_END_TEST
|
2017-08-17 10:36:47 -07:00
|
|
|
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
void
|
|
|
|
eina_test_value(TCase *tc)
|
|
|
|
{
|
|
|
|
tcase_add_test(tc, eina_value_test_simple);
|
|
|
|
tcase_add_test(tc, eina_value_test_string);
|
|
|
|
tcase_add_test(tc, eina_value_test_pvariant);
|
|
|
|
tcase_add_test(tc, eina_value_test_compare);
|
|
|
|
tcase_add_test(tc, eina_value_test_to_string);
|
2017-09-13 17:26:26 -07:00
|
|
|
tcase_add_test(tc, eina_value_test_to_binbuf);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
tcase_add_test(tc, eina_value_test_convert_char);
|
|
|
|
tcase_add_test(tc, eina_value_test_convert_uchar);
|
2013-07-16 23:20:08 -07:00
|
|
|
tcase_add_test(tc, eina_value_test_convert_short);
|
|
|
|
tcase_add_test(tc, eina_value_test_convert_ushort);
|
|
|
|
tcase_add_test(tc, eina_value_test_convert_int);
|
|
|
|
tcase_add_test(tc, eina_value_test_convert_uint);
|
2013-03-24 20:55:42 -07:00
|
|
|
tcase_add_test(tc, eina_value_test_convert_long);
|
|
|
|
tcase_add_test(tc, eina_value_test_convert_ulong);
|
2014-10-23 05:34:14 -07:00
|
|
|
tcase_add_test(tc, eina_value_test_convert_float);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
// TODO: other converters...
|
|
|
|
tcase_add_test(tc, eina_value_test_array);
|
2012-01-11 13:52:32 -08:00
|
|
|
tcase_add_test(tc, eina_value_test_list);
|
2012-01-11 15:54:35 -08:00
|
|
|
tcase_add_test(tc, eina_value_test_hash);
|
2012-01-11 17:31:21 -08:00
|
|
|
tcase_add_test(tc, eina_value_test_timeval);
|
2012-01-11 19:00:03 -08:00
|
|
|
tcase_add_test(tc, eina_value_test_blob);
|
2012-01-12 14:58:31 -08:00
|
|
|
tcase_add_test(tc, eina_value_test_struct);
|
2012-01-12 15:31:42 -08:00
|
|
|
tcase_add_test(tc, eina_value_test_array_of_struct);
|
2015-07-08 20:57:38 -07:00
|
|
|
tcase_add_test(tc, eina_value_test_optional_int);
|
|
|
|
tcase_add_test(tc, eina_value_test_optional_string);
|
|
|
|
tcase_add_test(tc, eina_value_test_optional_struct_members);
|
2017-08-17 10:36:47 -07:00
|
|
|
tcase_add_test(tc, eina_value_test_value);
|
|
|
|
tcase_add_test(tc, eina_value_test_value_string);
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
}
|