-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(c-api) Add test case for
wat2wasm
.
- Loading branch information
Showing
2 changed files
with
64 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <inttypes.h> | ||
|
||
#include "wasmer_wasm.h" | ||
|
||
#define own | ||
|
||
int main(int argc, const char* argv[]) { | ||
// Initialize. | ||
printf("Initializing...\n"); | ||
wasm_engine_t* engine = wasm_engine_new(); | ||
wasm_store_t* store = wasm_store_new(engine); | ||
|
||
// Getting Wasm. | ||
printf("Compiling WAT to Wasm...\n"); | ||
|
||
wasm_byte_vec_t wat = { | ||
.data = "(module)", | ||
.size = 8, | ||
}; | ||
wasm_byte_vec_t *wasm = wat2wasm(&wat); | ||
|
||
if (!wasm) { | ||
printf("> Error compiler WAT to Wasm!\n"); | ||
return 1; | ||
} | ||
|
||
if (wasm->size != 8) { | ||
printf("The Wasm size is incorrect!\n"); | ||
return 1; | ||
} | ||
|
||
if (!(wasm->data[0] == 0 && | ||
wasm->data[1] == 'a' && | ||
wasm->data[2] == 's' && | ||
wasm->data[3] == 'm' && | ||
wasm->data[4] == 1 && | ||
wasm->data[5] == 0 && | ||
wasm->data[6] == 0 && | ||
wasm->data[7] == 0)) { | ||
printf("The Wasm data is incorrect!\n"); | ||
return 1; | ||
} | ||
|
||
wasm_byte_vec_delete(wasm); | ||
|
||
// All done. | ||
printf("Done.\n"); | ||
return 0; | ||
} |