wasmer/lib/runtime-c-api/tests/test-memory.c

35 lines
1002 B
C
Raw Normal View History

2019-02-05 03:46:47 +00:00
#include <stdio.h>
#include "../wasmer.h"
#include <assert.h>
#include <stdint.h>
int main()
{
wasmer_memory_t *memory = NULL;
wasmer_limits_t descriptor;
descriptor.min = 10;
2019-02-09 23:53:03 +00:00
descriptor.max = 15;
2019-02-05 03:46:47 +00:00
wasmer_memory_result_t memory_result = wasmer_memory_new(&memory, descriptor);
printf("Memory result: %d\n", memory_result);
assert(memory_result == WASMER_MEMORY_OK);
uint32_t len = wasmer_memory_length(memory);
printf("Memory pages length: %d\n", len);
assert(len == 10);
2019-02-09 23:53:03 +00:00
wasmer_memory_result_t grow_result = wasmer_memory_grow(memory, 2);
assert(grow_result == WASMER_MEMORY_OK);
uint32_t new_len = wasmer_memory_length(memory);
printf("Memory pages length: %d\n", new_len);
assert(new_len == 12);
// Err, grow beyond max
wasmer_memory_result_t grow_result2 = wasmer_memory_grow(memory, 10);
assert(grow_result2 == WASMER_MEMORY_ERROR);
2019-02-05 03:46:47 +00:00
printf("Destroy memory\n");
wasmer_memory_destroy(memory);
return 0;
}