Skip to content

Commit 3d0e910

Browse files
committed
Add end-to-end tests
1 parent 353ce8c commit 3d0e910

File tree

8 files changed

+58
-0
lines changed

8 files changed

+58
-0
lines changed

tests/samples/Enum.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "Enum.h"
2+
3+
enum days get_WEDNESDAY() { return WEDNESDAY; }
4+
5+
char *check_BIG_NEG_A(enum bigNegativeValues big_neg_a) {
6+
if (big_neg_a == BIG_NEG_A) {
7+
return "OK";
8+
}
9+
return "FAIL";
10+
}

tests/samples/Enum.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ enum { // anonymous enum
2121
enum negativeValues { NEG_A = -1, NEG_B = -2 };
2222

2323
enum bigNegativeValues { BIG_NEG_A = -10000000000, BIG_NEG_B = -1 };
24+
25+
enum days get_WEDNESDAY();
26+
27+
char *check_BIG_NEG_A(enum bigNegativeValues big_neg_a);

tests/samples/Enum.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ object Enum {
1010
type enum_bigValues = native.CUnsignedLong
1111
type enum_negativeValues = native.CInt
1212
type enum_bigNegativeValues = native.CLong
13+
def get_WEDNESDAY(): enum_days = native.extern
14+
def check_BIG_NEG_A(big_neg_a: enum_bigNegativeValues): native.CString = native.extern
1315
}
1416

1517
import Enum._

tests/samples/Struct.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "Struct.h"
2+
#include <stdlib.h>
3+
4+
point_s getPoint() {
5+
point_s point = malloc(sizeof(struct point));
6+
point->x = 10;
7+
point->y = 20;
8+
return point;
9+
}

tests/samples/Struct.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ struct point {
44
};
55

66
typedef struct point *point_s;
7+
8+
point_s getPoint();

tests/samples/Struct.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import scala.scalanative.native._
88
object Struct {
99
type point_s = native.Ptr[struct_point]
1010
type struct_point = native.CStruct2[native.CInt, native.CInt]
11+
def getPoint(): native.Ptr[struct_point] = native.extern
1112
}
1213

1314
import Struct._
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.scalanative.bindgen.samples
2+
3+
import utest._
4+
import scalanative.native._
5+
6+
object EnumTests extends TestSuite {
7+
val tests = Tests {
8+
'get_WEDNESDAY - {
9+
assert(Enum.get_WEDNESDAY() == EnumEnums.enum_days_WEDNESDAY)
10+
}
11+
12+
'check_BIG_NEG_A - {
13+
assert(Enum.check_BIG_NEG_A(EnumEnums.enum_bigNegativeValues_BIG_NEG_A) == c"OK")
14+
}
15+
}
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.scalanative.bindgen.samples
2+
3+
import utest._
4+
import org.scalanative.bindgen.samples.StructHelpers._
5+
6+
object StructTests extends TestSuite {
7+
val tests = Tests {
8+
'getPoint - {
9+
val point = Struct.getPoint()
10+
assert(point.x == 10)
11+
assert(point.y == 20)
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)