-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeshtest3.c
36 lines (34 loc) · 1.08 KB
/
meshtest3.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include"meshlib.h"
#define CHECK(cond) if (!(cond)) { \
fprintf(stderr, "Check failed in %s line %d\n", __FILE__, __LINE__); exit(1); } \
else fprintf(stderr, "Check passed in %s line %d\n", __FILE__, __LINE__)
int main(void) {
int res;
double val;
res = meshlib_init(".");
CHECK(res == 0);
res = mesh_func_init("demo3.lua");
CHECK(res == 0);
res = mesh_func_call("f1", "d", &val, 10.0);
CHECK(res == 0 && val == 10.0);
res = mesh_func_call("f2", "d", &val, 10.0);
CHECK(res != 0);
res = mesh_func_call("f2", "id", &val, 3, 10.5);
CHECK(res == 0 && val == 31.5);
res = mesh_func_call("f3", "i_d", &val, -2, 2.0);
CHECK(res == 0 && val == 4);
/* Subtyping test */
res = mesh_func_call("ity", "d", &val, 1.5);
CHECK(res == 0 && val == 0);
res = mesh_func_call("ity", "i", &val, 2);
CHECK(res == 0 && val == 1);
/* String parameters */
res = mesh_func_call("f4", "cd", &val, "foo", 5.0);
CHECK(res == 0 && val == 12.42);
meshlib_close();
fprintf(stderr, "All tests passed.\n");
return 0;
}