From 8a54baf73d681a1874c4f68908951a2c146269cf Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Tue, 28 Aug 2018 18:27:13 -0400 Subject: [PATCH] Test reuse of union bindings --- tests/samples/CustomNames.scala | 1 + tests/samples/ReuseBindings.h | 2 ++ tests/samples/ReuseBindings.json | 1 + tests/samples/ReuseBindings.scala | 8 ++++++-- tests/samples/include/CustomNames.h | 5 +++++ 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/samples/CustomNames.scala b/tests/samples/CustomNames.scala index a6cfd8f..b61c3f7 100644 --- a/tests/samples/CustomNames.scala +++ b/tests/samples/CustomNames.scala @@ -14,5 +14,6 @@ object CustomNames { type EnumWithTypedef = enum_enumWithTypedef type page = native.CStruct2[native.CString, native.Ptr[Byte]] type book = native.CStruct1[native.Ptr[page]] + type weight = native.CArray[Byte, native.Nat._4] type MY_INT = native.CInt } diff --git a/tests/samples/ReuseBindings.h b/tests/samples/ReuseBindings.h index 2f6689b..40855aa 100644 --- a/tests/samples/ReuseBindings.h +++ b/tests/samples/ReuseBindings.h @@ -11,9 +11,11 @@ typedef struct bigStruct aliasForBigStruct; struct usesImportedEnum { enum pointIndex index; + union weight weight; }; void readBook(struct book *book); +void getWeight(union weight *weight); myInt getMyInt(); enumWithTypedef getEnum(); \ No newline at end of file diff --git a/tests/samples/ReuseBindings.json b/tests/samples/ReuseBindings.json index 70701dd..7c1cc8a 100644 --- a/tests/samples/ReuseBindings.json +++ b/tests/samples/ReuseBindings.json @@ -5,6 +5,7 @@ "names": { "struct book": "book", "struct page": "page", + "union weight": "weight", "myInt": "MY_INT", "enumWithTypedef": "EnumWithTypedef" } diff --git a/tests/samples/ReuseBindings.scala b/tests/samples/ReuseBindings.scala index 5f11efd..91553cd 100644 --- a/tests/samples/ReuseBindings.scala +++ b/tests/samples/ReuseBindings.scala @@ -7,11 +7,12 @@ import scala.scalanative.native._ @native.extern object ReuseBindings { type aliasForBigStruct = org.scalanative.bindgen.samples.Struct.struct_bigStruct - type struct_usesImportedEnum = native.CStruct1[org.scalanative.bindgen.samples.Struct.enum_pointIndex] + type struct_usesImportedEnum = native.CStruct2[org.scalanative.bindgen.samples.Struct.enum_pointIndex, org.scalanative.bindgen.samples.CustomNames.weight] def useStruct(p0: native.Ptr[org.scalanative.bindgen.samples.Struct.struct_point]): Unit = native.extern def returnTypedef_point_s(): native.Ptr[org.scalanative.bindgen.samples.Struct.struct_point] = native.extern def returnTypedef_point(): native.Ptr[org.scalanative.bindgen.samples.Struct.point] = native.extern def readBook(book: native.Ptr[org.scalanative.bindgen.samples.CustomNames.book]): Unit = native.extern + def getWeight(weight: native.Ptr[org.scalanative.bindgen.samples.CustomNames.weight]): Unit = native.extern def getMyInt(): org.scalanative.bindgen.samples.CustomNames.MY_INT = native.extern def getEnum(): org.scalanative.bindgen.samples.CustomNames.EnumWithTypedef = native.extern @@ -19,15 +20,18 @@ object ReuseBindings { implicit class struct_usesImportedEnum_ops(val p: native.Ptr[struct_usesImportedEnum]) extends AnyVal { def index: org.scalanative.bindgen.samples.Struct.enum_pointIndex = !p._1 def index_=(value: org.scalanative.bindgen.samples.Struct.enum_pointIndex): Unit = !p._1 = value + def weight: native.Ptr[org.scalanative.bindgen.samples.CustomNames.weight] = p._2 + def weight_=(value: native.Ptr[org.scalanative.bindgen.samples.CustomNames.weight]): Unit = !p._2 = !value } } object struct_usesImportedEnum { import implicits._ def apply()(implicit z: native.Zone): native.Ptr[struct_usesImportedEnum] = native.alloc[struct_usesImportedEnum] - def apply(index: org.scalanative.bindgen.samples.Struct.enum_pointIndex)(implicit z: native.Zone): native.Ptr[struct_usesImportedEnum] = { + def apply(index: org.scalanative.bindgen.samples.Struct.enum_pointIndex, weight: native.Ptr[org.scalanative.bindgen.samples.CustomNames.weight])(implicit z: native.Zone): native.Ptr[struct_usesImportedEnum] = { val ptr = native.alloc[struct_usesImportedEnum] ptr.index = index + ptr.weight = weight ptr } } diff --git a/tests/samples/include/CustomNames.h b/tests/samples/include/CustomNames.h index 676984a..91dc66e 100644 --- a/tests/samples/include/CustomNames.h +++ b/tests/samples/include/CustomNames.h @@ -7,5 +7,10 @@ struct book { struct page *firstPage; }; +union weight { + int kilos; + float grams; +}; + typedef int myInt; typedef enum { CONST } enumWithTypedef;