summaryrefslogtreecommitdiffstats
path: root/qtsharp/src/tests/lookuptest.cs
blob: 9882678f7bd4d960697b660051af0d5f0f0b0418 (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
// Demonstrates that auto-boxing of foreign C++ objects works.
// Set QTCSHARP_DEBUG to true in your environment to see this work.
//
// TODO
// o Turn this into an nunit test.
// o Mono won't let this test call LookupObject because
//   it is marked 'internal', even though they're both
//   in the same namespace. Mono bug?

namespace Qt {

	using Qt;
	using System;

	public class LookupTest : QVBox, IDisposable {
		
		public LookupTest() : base (null)
		{
			QPushButton button = new QPushButton ("Quit", this);
			QPushButton button2 = (QPushButton)QtSupport.LookupObject (button.Ptr); // Lookup a child object that exists in C#

			if (button.GetHashCode () != button2.GetHashCode ())
				Console.WriteLine ("ERROR: Hash codes differ for button and button2!");

			QSize size = button2.SizeHint (); // Wrap a non-C# object. Lookup is called from the C# sizeHint method.
			QSize size2 = (QSize)QtSupport.LookupObject (size.Ptr);

			if (size.GetHashCode () != size2.GetHashCode ())
				Console.WriteLine ("ERROR: Hash codes differ for size and size2!");

			Connect (button, SIGNAL ("clicked()"), QObject.qApp, SLOT ("Quit()"));
		}

		public static void Main (string[] args)
		{
			QApplication a = new QApplication (args);
			LookupTest lt = new LookupTest ();
			a.SetMainWidget (lt);
			lt.Show ();

			LookupTest lt2 = (LookupTest)QtSupport.LookupObject (lt.Ptr); // Lookup a root object that exists in C#

			if (lt.GetHashCode () != lt2.GetHashCode ())
				Console.WriteLine ("ERROR: Hash codes differ for lt and lt2!");

			a.Exec ();
			lt.Dispose ();
		}
	}
}