~ubuntu-branches/ubuntu/oneiric/swig1.3/oneiric

« back to all changes in this revision

Viewing changes to Examples/test-suite/csharp/csharp_prepost_runme.cs

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-12-06 10:27:08 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20071206102708-t37t62i45n595w0e
Tags: 1.3.33-2ubuntu1
* Merge with Debian; remaining changes:
  - Drop support for pike.
  - Use python2.5 instead of python2.4.
  - Clean Runtime/ as well.
  - Force a few environment variables.
* debian/Rules (clean): Remove Lib/ocaml/swigp4.ml.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
using System;
 
3
using System.Reflection;
 
4
using csharp_prepostNamespace;
 
5
 
 
6
public class csharp_prepost_runme {
 
7
 
 
8
  public static void Main() {
 
9
    {
 
10
      double[] v;
 
11
      csharp_prepost.globalfunction(out v);
 
12
      Assert(v.Length, 3);
 
13
      Assert(v[0], 0.0);
 
14
      Assert(v[1], 1.1);
 
15
      Assert(v[2], 2.2);
 
16
    }
 
17
    {
 
18
      double[] v;
 
19
      new PrePostTest(out v);
 
20
      Assert(v.Length, 2);
 
21
      Assert(v[0], 3.3);
 
22
      Assert(v[1], 4.4);
 
23
    }
 
24
    {
 
25
      double[] v;
 
26
      PrePostTest p = new PrePostTest();
 
27
      p.method(out v);
 
28
      Assert(v.Length, 2);
 
29
      Assert(v[0], 5.5);
 
30
      Assert(v[1], 6.6);
 
31
    }
 
32
    {
 
33
      double[] v;
 
34
      PrePostTest.staticmethod(out v);
 
35
      Assert(v.Length, 2);
 
36
      Assert(v[0], 7.7);
 
37
      Assert(v[1], 8.8);
 
38
    }
 
39
 
 
40
    // Check attributes are generated for the constructor helper function
 
41
    {
 
42
      CsinAttributes c = new CsinAttributes(5);
 
43
      Assert(c.getVal(), 500);
 
44
 
 
45
      Type type = typeof(CsinAttributes);
 
46
      {
 
47
        MethodInfo member = (MethodInfo)type.GetMember("SwigConstructCsinAttributes", BindingFlags.NonPublic | BindingFlags.Static)[0];
 
48
        if (Attribute.GetCustomAttribute(member, typeof(CustomIntPtrAttribute)) == null)
 
49
          throw new Exception("No CustomIntPtr attribute for " + member.Name);
 
50
        ParameterInfo parameter = member.GetParameters()[0]; // expecting one parameter
 
51
        if (parameter.Name != "val")
 
52
          throw new Exception("Incorrect parameter name");
 
53
        Attribute attribute = Attribute.GetCustomAttributes(parameter)[0];
 
54
        if (attribute.GetType() != typeof(CustomIntAttribute))
 
55
          throw new Exception("Expecting CustomInt attribute");
 
56
      }
 
57
    }
 
58
  }
 
59
  private static void Assert(double d1, double d2) {
 
60
    if (d1 != d2)
 
61
      throw new Exception("assertion failure. " + d1 + " != " + d2);
 
62
  }
 
63
}
 
64
 
 
65
// Custom attribute classes
 
66
[AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
 
67
public class CustomIntAttribute : Attribute {}
 
68
 
 
69
[AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
 
70
public class CustomIntPtrAttribute : Attribute {}