PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/go/director_classic_runme.go

#
Go | 135 lines | 98 code | 29 blank | 8 comment | 10 complexity | 00dc505eaf3a8efa2490e7fd8b94900f MD5 | raw file
  1package main
  2
  3import "fmt"
  4import . "./director_classic"
  5
  6type TargetLangPerson struct{} // From Person
  7func (p *TargetLangPerson) Id() string {
  8	return "TargetLangPerson"
  9}
 10
 11type TargetLangChild struct{} // Form Child
 12func (p *TargetLangChild) Id() string {
 13	return "TargetLangChild"
 14}
 15
 16type TargetLangGrandChild struct{} // From Grandchild
 17func (p *TargetLangGrandChild) Id() string {
 18	return "TargetLangGrandChild"
 19}
 20
 21// Semis - don't override id() in target language
 22
 23type TargetLangSemiPerson struct{} // From Person
 24
 25type TargetLangSemiChild struct{} // From Child
 26
 27type TargetLangSemiGrandChild struct{} // From GrandChild
 28
 29// Orphans - don't override id() in C++
 30
 31type TargetLangOrphanPerson struct{} // From OrphanPerson
 32func (p *TargetLangOrphanPerson) Id() string {
 33	return "TargetLangOrphanPerson"
 34}
 35
 36type TargetLangOrphanChild struct{} // From OrphanChild
 37func (p *TargetLangOrphanChild) Id() string {
 38	return "TargetLangOrphanChild"
 39}
 40
 41func check(person Person, expected string) {
 42	debug := false
 43
 44	// Normal target language polymorphic call
 45	ret := person.Id()
 46	if debug {
 47		fmt.Println(ret)
 48	}
 49	if ret != expected {
 50		panic("Failed. Received: " + ret + " Expected: " + expected)
 51	}
 52
 53	// Polymorphic call from C++
 54	caller := NewCaller()
 55	caller.SetCallback(person)
 56	ret = caller.Call()
 57	if debug {
 58		fmt.Println(ret)
 59	}
 60	if ret != expected {
 61		panic("Failed. Received: " + ret + " Expected: " + expected)
 62	}
 63
 64	// Polymorphic call of object created in target language and
 65	// passed to C++ and back again
 66	baseclass := caller.BaseClass()
 67	ret = baseclass.Id()
 68	if debug {
 69		fmt.Println(ret)
 70	}
 71	if ret != expected {
 72		panic("Failed. Received: " + ret + " Expected: " + expected)
 73	}
 74
 75	caller.ResetCallback()
 76	if debug {
 77		fmt.Println("----------------------------------------")
 78	}
 79}
 80
 81func main() {
 82	person := NewPerson()
 83	check(person, "Person")
 84	DeletePerson(person)
 85
 86	person = NewChild()
 87	check(person, "Child")
 88	DeletePerson(person)
 89
 90	person = NewGrandChild()
 91	check(person, "GrandChild")
 92	DeletePerson(person)
 93
 94	person = NewDirectorPerson(&TargetLangPerson{})
 95	check(person, "TargetLangPerson")
 96	DeleteDirectorPerson(person)
 97
 98	person = NewDirectorChild(&TargetLangChild{})
 99	check(person, "TargetLangChild")
100	DeleteDirectorChild(person.(Child))
101
102	person = NewDirectorGrandChild(&TargetLangGrandChild{})
103	check(person, "TargetLangGrandChild")
104	DeleteDirectorGrandChild(person.(GrandChild))
105
106	// Semis - don't override id() in target language
107	person = NewDirectorPerson(&TargetLangSemiPerson{})
108	check(person, "Person")
109	DeleteDirectorPerson(person)
110
111	person = NewDirectorChild(&TargetLangSemiChild{})
112	check(person, "Child")
113	DeleteDirectorChild(person.(Child))
114
115	person = NewDirectorGrandChild(&TargetLangSemiGrandChild{})
116	check(person, "GrandChild")
117	DeleteDirectorGrandChild(person.(GrandChild))
118
119	// Orphans - don't override id() in C++
120	person = NewOrphanPerson()
121	check(person, "Person")
122	DeleteOrphanPerson(person.(OrphanPerson))
123
124	person = NewOrphanChild()
125	check(person, "Child")
126	DeleteOrphanChild(person.(OrphanChild))
127
128	person = NewDirectorOrphanPerson(&TargetLangOrphanPerson{})
129	check(person, "TargetLangOrphanPerson")
130	DeleteDirectorOrphanPerson(person.(OrphanPerson))
131
132	person = NewDirectorOrphanChild(&TargetLangOrphanChild{})
133	check(person, "TargetLangOrphanChild")
134	DeleteDirectorOrphanChild(person.(OrphanChild))
135}