#### /trunk/Examples/test-suite/d/member_pointer_runme.1.d

#
D | 43 lines | 30 code | 9 blank | 4 comment | 2 complexity | b36816cd16b868da7bc4f49fe1897c13 MD5 | raw file
``` 1module member_pointer_runme;
2
3import Float = tango.text.convert.Float;
4import member_pointer.member_pointer;
5import member_pointer.Square;
6import member_pointer.SWIGTYPE_m_Shape__f_void__double;
7
8void main() {
9  auto s = new Square(10);
10
11  // Do some calculations
12  auto area_pt = areapt();
13  auto perim_pt = perimeterpt();
14  check("Square area ", 100.0, do_op(s, area_pt));
15  check("Square perim", 40.0, do_op(s, perim_pt));
16
17  SWIGTYPE_m_Shape__f_void__double memberPtr = null;
18  memberPtr = areavar;
19  memberPtr = perimetervar;
20
21  // Try the variables
22  check("Square area ", 100.0, do_op(s, areavar));
23  check("Square perim", 40.0, do_op(s, perimetervar));
24
25  // Modify one of the variables
26  areavar = perim_pt;
27  check("Square perimeter", 40.0, do_op(s,areavar));
28
29  // Try the constants
30  memberPtr = AREAPT;
31  memberPtr = PERIMPT;
32  memberPtr = NULLPT;
33
34  check("Square area", 100.0, do_op(s, AREAPT));
35  check("Square perim", 40.0, do_op(s, PERIMPT));
36}
37
38void check(char[] what, double expected, double actual) {
39  if (expected != actual) {
40    throw new Exception("Failed: " ~ what ~ ": expected "
41      ~ Float.toString(expected) ~ ", but got " ~ Float.toString(actual));
42  }
43}
```