diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 2a4591524..4b10527db 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -602,6 +602,7 @@ C_TEST_CASES += \ memberin_extend_c \ name \ nested \ + nested_extend_c \ nested_structs \ newobject2 \ overload_extend \ diff --git a/Examples/test-suite/java/nested_extend_c_runme.java b/Examples/test-suite/java/nested_extend_c_runme.java new file mode 100644 index 000000000..9da093a09 --- /dev/null +++ b/Examples/test-suite/java/nested_extend_c_runme.java @@ -0,0 +1,38 @@ +import nested_extend_c.*; + +public class nested_extend_c_runme { + + static { + try { + System.loadLibrary("nested_extend_c"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) throws Throwable + { + { + hiA hi = new hiA(); + if (hi.hi_extend() != 'h') + throw new RuntimeException("test failed"); + } + { + lowA low = new lowA(); + if (low.low_extend() != 99) + throw new RuntimeException("test failed"); + } + + { + hiB hi = new hiB(); + if (hi.hi_extend() != 'h') + throw new RuntimeException("test failed"); + } + { + lowB low = new lowB(); + if (low.low_extend() != 99) + throw new RuntimeException("test failed"); + } + } +} diff --git a/Examples/test-suite/nested_extend_c.i b/Examples/test-suite/nested_extend_c.i new file mode 100644 index 000000000..3641cf78f --- /dev/null +++ b/Examples/test-suite/nested_extend_c.i @@ -0,0 +1,74 @@ +%module nested_extend_c + +%extend hiA { + hiA() { + union hiA *self = (union hiA *)malloc(sizeof(union hiA)); + self->c = 'h'; + return self; + } + char hi_extend() { + return $self->c; + } +} +%extend lowA { + lowA() { + struct lowA *self = (struct lowA *)malloc(sizeof(struct lowA)); + self->name = 0; + self->num = 99; + return self; + } + int low_extend() { + return $self->num; + } +} + +%extend hiB { + hiB() { + union hiB *self = (union hiB *)malloc(sizeof(union hiB)); + self->c = 'h'; + return self; + } + char hi_extend() { + return $self->c; + } +} +%extend lowB { + lowB() { + struct lowB *self = (struct lowB *)malloc(sizeof(struct lowB)); + self->name = 0; + self->num = 99; + return self; + } + int low_extend() { + return $self->num; + } +} + +%inline %{ +typedef struct NestedA { + int a; + union hiA { + char c; + int d; + } hiA_instance; + + struct lowA { + char *name; + int num; + } lowA_instance; +} NestedA; + +typedef struct { + int a; + union hiB { + char c; + int d; + } hiB_instance; + + struct lowB { + char *name; + int num; + } lowB_instance; +} NestedB; +%} +