From a1ae7f5080ca99c38c87ba3e4102beac16b75eb3 Mon Sep 17 00:00:00 2001
From: "benjamin.franksen" <benjamin.franksen@helmholtz-berlin.de>
Date: Mon, 1 Jul 2013 00:09:15 +0000
Subject: [PATCH] added validation test for access to variables of foreign
 types

---
 test/validate/Makefile        |  1 +
 test/validate/foreignTypes.st | 74 +++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+)
 create mode 100644 test/validate/foreignTypes.st

diff --git a/test/validate/Makefile b/test/validate/Makefile
index 13fb92ef..2616ce03 100644
--- a/test/validate/Makefile
+++ b/test/validate/Makefile
@@ -43,6 +43,7 @@ REGRESSION_TESTS_WITHOUT_DB += array
 REGRESSION_TESTS_WITHOUT_DB += assign
 REGRESSION_TESTS_WITHOUT_DB += change
 REGRESSION_TESTS_WITHOUT_DB += commaOperator
+REGRESSION_TESTS_WITHOUT_DB += foreignTypes
 REGRESSION_TESTS_WITHOUT_DB += local
 REGRESSION_TESTS_WITHOUT_DB += opttVar
 REGRESSION_TESTS_WITHOUT_DB += pvSync
diff --git a/test/validate/foreignTypes.st b/test/validate/foreignTypes.st
new file mode 100644
index 00000000..807dfc99
--- /dev/null
+++ b/test/validate/foreignTypes.st
@@ -0,0 +1,74 @@
+program foreignTypesTest
+
+%%#include "../testSupport.h"
+
+/* option +r; */
+
+%%struct struct_t { int i; struct { double d; } s; };
+%%union union_t { int i; struct struct_t *p; };
+%%enum enum_t { zero, one, two };
+%%typedef short typedef_t;
+
+foreign zero, one, two;
+
+struct struct_t s = {1, {0.1}};
+union union_t u = {13};
+enum enum_t e = one;
+typename typedef_t t = 42;
+
+entry {
+    seq_test_init(24);
+}
+
+ss simple {
+    state simple {
+        when () {
+            struct struct_t *ps = &s;
+            union union_t *pu = &u;
+            enum enum_t *pe = &e;
+            typename typedef_t *pt = &t;
+
+            testOk1(s.i == 1);
+            testOk1(s.s.d == 0.1);
+            testOk1(u.i == 13);
+            u.p = ps;
+            testOk1(u.p == ps);
+            testOk1(u.p->i == 1);
+            testOk1(u.p->s.d == 0.1);
+            u.i = 13; /* restore */
+            testOk1(e == one);
+            testOk1(t == 42);
+
+            testOk1(ps->i == 1);
+            testOk1(ps->s.d == 0.1);
+            testOk1(pu->i == 13);
+            pu->p = ps;
+            testOk1(pu->p == ps);
+            testOk1(pu->p->i == 1);
+            testOk1(pu->p->s.d == 0.1);
+            pu->i = 13; /* restore */
+            testOk1(*pe == one);
+            testOk1(*pt == 42);
+
+            ps->i++;
+            ps->s.d /= 3.0;
+            pu->i--;
+            *pe = two;
+            *pt %= 10;
+
+            testOk1(ps->i == 2);
+            testOk1(ps->s.d == 0.1/3.0);
+            testOk1(pu->i == 12);
+            pu->p = ps;
+            testOk1(pu->p == ps);
+            testOk1(pu->p->i == 2);
+            testOk1(pu->p->s.d == 0.1/3.0);
+            testOk1(*pe == two);
+            testOk1(*pt == 2);
+        } exit
+    }
+}
+
+exit {
+    seq_test_done();
+}
-- 
GitLab