Implement recordset iterators
JerryScript-DCO-1.0-Signed-off-by: Evgeny Gavrin e.gavrin@samsung.com JerryScript-DCO-1.0-Signed-off-by: Andrey Shitov a.shitov@samsung.com
This commit is contained in:
@@ -41,6 +41,9 @@ extern "C"
|
||||
// Maximum number of elements in a type-one record
|
||||
#define test_max_type_one_record_elements 64
|
||||
|
||||
// Element size in a type-one record
|
||||
#define test_element_size_type_one_record (sizeof (uint16_t))
|
||||
|
||||
class test_rcs_record_type_one_t : public rcs_record_t
|
||||
{
|
||||
public:
|
||||
@@ -80,7 +83,7 @@ private:
|
||||
static const uint32_t prev_field_width = rcs_cpointer_t::bit_field_width;
|
||||
|
||||
static const size_t header_size = 2 * RCS_DYN_STORAGE_LENGTH_UNIT;
|
||||
static const size_t element_size = sizeof (uint16_t);
|
||||
static const size_t element_size = test_element_size_type_one_record;
|
||||
};
|
||||
|
||||
class test_rcs_record_type_two_t : public rcs_record_t
|
||||
@@ -232,6 +235,7 @@ main (int __attr_unused___ argc,
|
||||
{
|
||||
test_rcs_record_type_one_t *type_one_records[test_sub_iters];
|
||||
uint32_t type_one_record_element_counts[test_sub_iters];
|
||||
uint16_t type_one_record_elements[test_sub_iters][test_max_type_one_record_elements];
|
||||
int type_one_records_number = 0;
|
||||
|
||||
test_rcs_record_type_two_t *type_two_records[test_sub_iters];
|
||||
@@ -249,6 +253,27 @@ main (int __attr_unused___ argc,
|
||||
|
||||
JERRY_ASSERT (type_one_records[type_one_records_number] != NULL);
|
||||
|
||||
rcs_record_iterator_t it (&storage, type_one_records[type_one_records_number]);
|
||||
it.skip<uint32_t> (); // skip header
|
||||
it.skip<uint32_t> (); // skip header
|
||||
for (uint32_t i = 0; i < type_one_record_element_counts[type_one_records_number]; it.skip<uint16_t>(), i++)
|
||||
{
|
||||
uint16_t val = (uint16_t)rand ();
|
||||
type_one_record_elements[type_one_records_number][i] = val;
|
||||
it.write (val);
|
||||
}
|
||||
|
||||
JERRY_ASSERT (type_one_records[type_one_records_number] != NULL);
|
||||
|
||||
it.reset ();
|
||||
it.skip<uint32_t> (); // skip header
|
||||
it.skip<uint32_t> (); // skip header
|
||||
for (uint32_t i = 0; i < type_one_record_element_counts[type_one_records_number]; it.skip<uint16_t>(), i++)
|
||||
{
|
||||
uint16_t val = type_one_record_elements[type_one_records_number][i];
|
||||
JERRY_ASSERT (val == it.read<uint16_t> ());
|
||||
}
|
||||
|
||||
type_one_records_number++;
|
||||
}
|
||||
else
|
||||
@@ -265,6 +290,26 @@ main (int __attr_unused___ argc,
|
||||
|
||||
while (type_one_records_number + type_two_records_number != 0)
|
||||
{
|
||||
// Read test
|
||||
for (int index_to_free = 0; index_to_free < type_one_records_number; index_to_free++)
|
||||
{
|
||||
JERRY_ASSERT (type_one_records_number > 0);
|
||||
|
||||
JERRY_ASSERT (index_to_free >= 0 && index_to_free < type_one_records_number);
|
||||
|
||||
rcs_record_iterator_t it (&storage, type_one_records[index_to_free]);
|
||||
it.skip<uint32_t> (); // skip header
|
||||
it.skip<uint32_t> (); // skip header
|
||||
for (uint32_t i = 0; i < type_one_record_element_counts[index_to_free]; it.skip<uint16_t>(), i++)
|
||||
{
|
||||
uint16_t val = type_one_record_elements[index_to_free][i];
|
||||
JERRY_ASSERT (it.read <uint16_t> () == val);
|
||||
}
|
||||
|
||||
JERRY_ASSERT (JERRY_ALIGNUP (type_one_record_element_counts[index_to_free]*2 + 8, RCS_DYN_STORAGE_ALIGNMENT) ==
|
||||
type_one_records[index_to_free]->get_size ());
|
||||
}
|
||||
|
||||
bool free_type_one;
|
||||
|
||||
if (type_one_records_number == 0)
|
||||
@@ -291,6 +336,16 @@ main (int __attr_unused___ argc,
|
||||
|
||||
JERRY_ASSERT (index_to_free >= 0 && index_to_free < type_one_records_number);
|
||||
|
||||
rcs_record_iterator_t it (&storage, type_one_records[index_to_free]);
|
||||
it.skip<uint32_t> (); // skip header
|
||||
it.skip<uint32_t> (); // skip header
|
||||
for (uint32_t i = 0; i < type_one_record_element_counts[index_to_free]; it.skip<uint16_t>(), i++)
|
||||
{
|
||||
uint16_t val = type_one_record_elements[index_to_free][i];
|
||||
JERRY_ASSERT (it.read <uint16_t> () == val);
|
||||
}
|
||||
|
||||
// free the record
|
||||
storage.free_record_type_one (type_one_records[index_to_free]);
|
||||
|
||||
type_one_records_number--;
|
||||
@@ -298,6 +353,8 @@ main (int __attr_unused___ argc,
|
||||
{
|
||||
type_one_records[index_to_free] = type_one_records[index_to_free + 1];
|
||||
type_one_record_element_counts[index_to_free] = type_one_record_element_counts[index_to_free + 1];
|
||||
memcpy (type_one_record_elements[index_to_free], type_one_record_elements[index_to_free + 1],
|
||||
test_max_type_one_record_elements * test_element_size_type_one_record);
|
||||
|
||||
index_to_free++;
|
||||
}
|
||||
@@ -328,3 +385,9 @@ main (int __attr_unused___ argc,
|
||||
|
||||
return 0;
|
||||
} /* main */
|
||||
|
||||
template test_rcs_record_type_one_t *
|
||||
rcs_recordset_t::alloc_record<test_rcs_record_type_one_t> (rcs_record_t::type_t, uint32_t);
|
||||
|
||||
template test_rcs_record_type_two_t *
|
||||
rcs_recordset_t::alloc_record<test_rcs_record_type_two_t> (rcs_record_t::type_t);
|
||||
|
||||
Reference in New Issue
Block a user