-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tag names with definition type, add tests for recursive structs (#39)
- Loading branch information
Showing
9 changed files
with
129 additions
and
162 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
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
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
23 changes: 23 additions & 0 deletions
23
bindgen/src/test/resources/scala-native/recursive_structs.h
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,23 @@ | ||
typedef struct Recursive_Struct2 Recursive_Struct2; | ||
|
||
typedef void (*hello_func)(struct Recursive_Struct2 *); | ||
|
||
typedef struct Recursive_Struct2 { | ||
struct Recrusive_Struct1 *hello2; | ||
char *str; | ||
} Recursive_Struct2; | ||
|
||
typedef struct Recursive_Struct3 { | ||
hello_func handler; | ||
int two; | ||
} Recursive_Struct3; | ||
|
||
typedef struct Recrusive_Struct1 { | ||
Recursive_Struct3 *hello; | ||
double d; | ||
} Recrusive_Struct1; | ||
|
||
typedef struct Recrusive_Simple { | ||
struct Recrusive_Simple *hello; | ||
double d; | ||
} Recrusive_Simple; |
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,42 @@ | ||
package bindgen | ||
|
||
import org.junit.Assert.* | ||
import org.junit.Test | ||
|
||
import scala.scalanative.unsafe.* | ||
import scala.scalanative.unsigned.* | ||
|
||
class TestRecursiveStructs: | ||
import lib_test_recursive_structs.types.* | ||
@Test def test_simple_recursive(): Unit = | ||
zone { | ||
val nested3 = Recrusive_Simple(null, 333.33) | ||
val nested2 = Recrusive_Simple(nested3, 222.22) | ||
val nested1 = Recrusive_Simple(nested2, 111.11) | ||
val nested0 = Recrusive_Simple(nested1, 0.0) | ||
|
||
assertEquals(111.11, (!(!nested0).hello).d, 0.01d) | ||
assertEquals(222.22, (!(!nested1).hello).d, 0.01d) | ||
assertEquals(333.33, (!(!nested2).hello).d, 0.01d) | ||
assertEquals(null, (!nested3).hello) | ||
|
||
(!(!nested0).hello).hello = nested3 | ||
assertEquals( | ||
nested3.unary_!.d, | ||
nested0.unary_!.hello.unary_!.hello.unary_!.d, | ||
0.01d | ||
) | ||
} | ||
|
||
@Test def test_mutually_recursive(): Unit = | ||
zone { | ||
val struct1 = Recrusive_Struct1(null, 1.0) | ||
val struct2 = Recursive_Struct2(struct1, c"hello") | ||
val struct3 = Recursive_Struct3(hello_func(null), 25) | ||
(!struct1).hello = struct3 | ||
|
||
assertEquals(1.0, struct1.unary_!.d, 0.01d) | ||
assertEquals('h', struct2.unary_!.str(0)) | ||
|
||
} | ||
end TestRecursiveStructs |
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
Oops, something went wrong.