File: vtkObjectModifiedEvtTest.cs

package info (click to toggle)
activiz.net 1%3A1.0~git20111214-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,280 kB
  • ctags: 5,957
  • sloc: cs: 28,767; python: 915; cpp: 130; makefile: 35; sh: 11
file content (77 lines) | stat: -rw-r--r-- 2,214 bytes parent folder | download | duplicates (2)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Class name is always file base name with "Class" appended:
//
/// <summary>
/// VTK test class
/// </summary>
public class vtkObjectModifiedEvtTestClass
{
  private static int ObjectModifiedCallCount;

  /// <summary>
  /// Handler for any vtkObject event:
  /// </summary>
  public static void ObjectModified(Kitware.VTK.vtkObject sender, Kitware.VTK.vtkObjectEventArgs e)
  {
    ++ObjectModifiedCallCount;

    System.Console.Error.WriteLine("//----------------------------------------------------------------------------");
    System.Console.Error.WriteLine("ObjectModified");

    System.Console.Error.WriteLine("sender:");
    System.Console.Error.WriteLine(sender.ToString());

    System.Console.Error.WriteLine("e.Caller:");
    System.Console.Error.WriteLine(e.Caller.ToString());

    System.Console.Error.WriteLine("e.EventId:");
    System.Console.Error.WriteLine(e.EventId.ToString());

    System.Console.Error.WriteLine("e.CallData:");
    System.Console.Error.WriteLine(e.CallData.ToString());

    System.Console.Error.WriteLine("");
  }

  // Static void method with same signature as "Main" is always
  // file base name:
  //
  /// <summary>
  /// VTK test Main method
  /// </summary>
  public static void vtkObjectModifiedEvtTest(string[] args)
  {
    ObjectModifiedCallCount = 0;

    // Create an object to send an event:
    //
    Kitware.VTK.vtkActor2D sender = new Kitware.VTK.vtkActor2D();

    // Connect a new handler for the Modified event:
    //
    Kitware.VTK.vtkObject.vtkObjectEventHandler handler =
      new Kitware.VTK.vtkObject.vtkObjectEventHandler(ObjectModified);

    sender.ModifiedEvt += handler;

    // Trigger the event:
    //
    sender.Modified();

    // Toggle Debug, trigger event again, then turn off Debug before objects are destroyed...
    //
    sender.SetDebug((byte)((0 == sender.GetDebug()) ? 1 : 0));
    sender.Modified();
    sender.DebugOff();

    // Disconnect them:
    //
    sender.ModifiedEvt -= handler;

    if (2 != ObjectModifiedCallCount)
    {
      throw new System.Exception(System.String.Format(
        "error: ObjectModified was called {0} times. Expected exactly 2 calls.",
        ObjectModifiedCallCount));
    }
  }
}