aboutsummaryrefslogtreecommitdiff
path: root/Examples/test-suite/csharp/csharp_director_typemaps_runme.cs
blob: 6143332db6524ff6e6f53979767bcb85f8dd2c49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

using System;
using System.Reflection;
using csharp_director_typemapsNamespace;

public class csharp_director_typemaps_runme {

  class CSharpDirectorTypemaps_InStreamDerived : InStream
  {
    private int constant;
    public CSharpDirectorTypemaps_InStreamDerived(int constant) { this.constant = constant; }
    public override int Read(global::System.IntPtr buf, int len, out int readLen) {
      readLen = (buf == global::System.IntPtr.Zero) ? -len - constant : len + constant;
      return readLen;
    }
    public override int Write(global::System.IntPtr buf, int len, out int writeLen) {
      writeLen = (buf == global::System.IntPtr.Zero) ? -len - constant : len + constant;
      return writeLen;
    }
  }
  public static void Main() {
    int outLen = -1;
    int k = 100;
    int j = 23;
    InStream instream = new CSharpDirectorTypemaps_InStreamDerived(k);

    {
      int ret = csharp_director_typemaps.callRead(instream, InStream.getCPtr(instream).Handle, j, out outLen);
      Assert(outLen, j + k);
      Assert(ret, j + k);
    }
    {
      int ret = csharp_director_typemaps.callRead(instream, global::System.IntPtr.Zero, j, out outLen);
      Assert(outLen, -j - k);
      Assert(ret, -j - k);
    }

    {
      int ret = csharp_director_typemaps.callWrite(instream, InStream.getCPtr(instream).Handle, j, out outLen);
      Assert(outLen, j + k);
      Assert(ret, j + k);
    }
    {
      int ret = csharp_director_typemaps.callWrite(instream, global::System.IntPtr.Zero, j, out outLen);
      Assert(outLen, -j - k);
      Assert(ret, -j - k);
    }
  }
  private static void Assert(int i1, int i2) {
    if (i1 != i2)
      throw new Exception("assertion failure. " + i1 + " != " + i2);
  }
}