2019-02-09 19:37:07 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "../wasmer.h"
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
wasmer_table_t *table = NULL;
|
|
|
|
wasmer_limits_t descriptor;
|
|
|
|
descriptor.min = 10;
|
2019-02-19 06:05:08 +00:00
|
|
|
wasmer_limit_option_t max;
|
2019-02-23 06:18:59 +00:00
|
|
|
// max.has_some = false;
|
2019-02-19 06:05:08 +00:00
|
|
|
max.has_some = true;
|
|
|
|
max.some = 15;
|
|
|
|
descriptor.max = max;
|
2019-02-12 01:07:28 +00:00
|
|
|
wasmer_result_t table_result = wasmer_table_new(&table, descriptor);
|
2019-02-09 19:37:07 +00:00
|
|
|
printf("Table result: %d\n", table_result);
|
2019-02-12 01:07:28 +00:00
|
|
|
assert(table_result == WASMER_OK);
|
2019-02-09 19:37:07 +00:00
|
|
|
|
|
|
|
uint32_t len = wasmer_table_length(table);
|
|
|
|
printf("Table length: %d\n", len);
|
2019-02-22 19:16:15 +00:00
|
|
|
assert(len == 10);
|
2019-02-09 19:58:50 +00:00
|
|
|
|
2019-02-23 06:18:59 +00:00
|
|
|
wasmer_result_t grow_result1 = wasmer_table_grow(table, 5);
|
|
|
|
assert(grow_result1 == WASMER_OK);
|
|
|
|
uint32_t len_grow1 = wasmer_table_length(table);
|
|
|
|
printf("Table length: %d\n", len_grow1);
|
|
|
|
assert(len_grow1 == 15);
|
2019-02-09 19:58:50 +00:00
|
|
|
|
2019-02-23 06:18:59 +00:00
|
|
|
// Try to grow beyond max
|
|
|
|
wasmer_result_t grow_result2 = wasmer_table_grow(table, 1);
|
|
|
|
assert(grow_result2 == WASMER_ERROR);
|
|
|
|
uint32_t len_grow2 = wasmer_table_length(table);
|
|
|
|
printf("Table length: %d\n", len_grow2);
|
|
|
|
assert(len_grow2 == 15);
|
2019-02-09 19:37:07 +00:00
|
|
|
|
2019-02-23 06:18:59 +00:00
|
|
|
wasmer_table_t *table_bad = NULL;
|
|
|
|
wasmer_limits_t bad_descriptor;
|
|
|
|
bad_descriptor.min = 15;
|
|
|
|
wasmer_limit_option_t max2;
|
|
|
|
max2.has_some = true;
|
|
|
|
max2.some = 10;
|
|
|
|
bad_descriptor.max = max2;
|
|
|
|
wasmer_result_t table_bad_result = wasmer_table_new(&table_bad, bad_descriptor);
|
|
|
|
printf("Table result: %d\n", table_bad_result);
|
|
|
|
assert(table_bad_result == WASMER_ERROR);
|
2019-02-10 23:57:23 +00:00
|
|
|
|
2019-02-09 19:37:07 +00:00
|
|
|
printf("Destroy table\n");
|
|
|
|
wasmer_table_destroy(table);
|
|
|
|
return 0;
|
|
|
|
}
|