PageRenderTime 26ms CodeModel.GetById 19ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/csharp/member_pointer_runme.cs

#
C# | 47 lines | 27 code | 14 blank | 6 comment | 2 complexity | edd46f4de1db421fdd19e25ae7da53e4 MD5 | raw file
 1using System;
 2using member_pointerNamespace;
 3
 4public class runme {
 5  public static SWIGTYPE_m_Shape__f_void__double memberPtr = null;
 6  static void Main() {
 7    // Get the pointers
 8
 9    SWIGTYPE_m_Shape__f_void__double area_pt = member_pointer.areapt();
10    SWIGTYPE_m_Shape__f_void__double perim_pt = member_pointer.perimeterpt();
11
12    // Create some objects
13
14    Square s = new Square(10);
15
16    // Do some calculations
17
18    check( "Square area ", 100.0, member_pointer.do_op(s,area_pt) );
19    check( "Square perim", 40.0, member_pointer.do_op(s,perim_pt) );
20
21    memberPtr = member_pointer.areavar;
22    memberPtr = member_pointer.perimetervar;
23
24    // Try the variables
25    check( "Square area ", 100.0, member_pointer.do_op(s,member_pointer.areavar) );
26    check( "Square perim", 40.0, member_pointer.do_op(s,member_pointer.perimetervar) );
27
28    // Modify one of the variables
29    member_pointer.areavar = perim_pt;
30
31    check( "Square perimeter", 40.0, member_pointer.do_op(s,member_pointer.areavar) );
32
33    // Try the constants
34
35    memberPtr = member_pointer.AREAPT;
36    memberPtr = member_pointer.PERIMPT;
37    memberPtr = member_pointer.NULLPT;
38
39    check( "Square area ", 100.0, member_pointer.do_op(s,member_pointer.AREAPT) );
40    check( "Square perim", 40.0, member_pointer.do_op(s,member_pointer.PERIMPT) );
41
42  }
43  private static void check(string what, double expected, double actual) {
44    if (expected != actual)
45      throw new ApplicationException("Failed: " + what + " Expected: " + expected + " Actual: " + actual);
46  }
47}