PageRenderTime 34ms CodeModel.GetById 1ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. package main
  2. import "fmt"
  3. import . "./director_classic"
  4. type TargetLangPerson struct{} // From Person
  5. func (p *TargetLangPerson) Id() string {
  6. return "TargetLangPerson"
  7. }
  8. type TargetLangChild struct{} // Form Child
  9. func (p *TargetLangChild) Id() string {
  10. return "TargetLangChild"
  11. }
  12. type TargetLangGrandChild struct{} // From Grandchild
  13. func (p *TargetLangGrandChild) Id() string {
  14. return "TargetLangGrandChild"
  15. }
  16. // Semis - don't override id() in target language
  17. type TargetLangSemiPerson struct{} // From Person
  18. type TargetLangSemiChild struct{} // From Child
  19. type TargetLangSemiGrandChild struct{} // From GrandChild
  20. // Orphans - don't override id() in C++
  21. type TargetLangOrphanPerson struct{} // From OrphanPerson
  22. func (p *TargetLangOrphanPerson) Id() string {
  23. return "TargetLangOrphanPerson"
  24. }
  25. type TargetLangOrphanChild struct{} // From OrphanChild
  26. func (p *TargetLangOrphanChild) Id() string {
  27. return "TargetLangOrphanChild"
  28. }
  29. func check(person Person, expected string) {
  30. debug := false
  31. // Normal target language polymorphic call
  32. ret := person.Id()
  33. if debug {
  34. fmt.Println(ret)
  35. }
  36. if ret != expected {
  37. panic("Failed. Received: " + ret + " Expected: " + expected)
  38. }
  39. // Polymorphic call from C++
  40. caller := NewCaller()
  41. caller.SetCallback(person)
  42. ret = caller.Call()
  43. if debug {
  44. fmt.Println(ret)
  45. }
  46. if ret != expected {
  47. panic("Failed. Received: " + ret + " Expected: " + expected)
  48. }
  49. // Polymorphic call of object created in target language and
  50. // passed to C++ and back again
  51. baseclass := caller.BaseClass()
  52. ret = baseclass.Id()
  53. if debug {
  54. fmt.Println(ret)
  55. }
  56. if ret != expected {
  57. panic("Failed. Received: " + ret + " Expected: " + expected)
  58. }
  59. caller.ResetCallback()
  60. if debug {
  61. fmt.Println("----------------------------------------")
  62. }
  63. }
  64. func main() {
  65. person := NewPerson()
  66. check(person, "Person")
  67. DeletePerson(person)
  68. person = NewChild()
  69. check(person, "Child")
  70. DeletePerson(person)
  71. person = NewGrandChild()
  72. check(person, "GrandChild")
  73. DeletePerson(person)
  74. person = NewDirectorPerson(&TargetLangPerson{})
  75. check(person, "TargetLangPerson")
  76. DeleteDirectorPerson(person)
  77. person = NewDirectorChild(&TargetLangChild{})
  78. check(person, "TargetLangChild")
  79. DeleteDirectorChild(person.(Child))
  80. person = NewDirectorGrandChild(&TargetLangGrandChild{})
  81. check(person, "TargetLangGrandChild")
  82. DeleteDirectorGrandChild(person.(GrandChild))
  83. // Semis - don't override id() in target language
  84. person = NewDirectorPerson(&TargetLangSemiPerson{})
  85. check(person, "Person")
  86. DeleteDirectorPerson(person)
  87. person = NewDirectorChild(&TargetLangSemiChild{})
  88. check(person, "Child")
  89. DeleteDirectorChild(person.(Child))
  90. person = NewDirectorGrandChild(&TargetLangSemiGrandChild{})
  91. check(person, "GrandChild")
  92. DeleteDirectorGrandChild(person.(GrandChild))
  93. // Orphans - don't override id() in C++
  94. person = NewOrphanPerson()
  95. check(person, "Person")
  96. DeleteOrphanPerson(person.(OrphanPerson))
  97. person = NewOrphanChild()
  98. check(person, "Child")
  99. DeleteOrphanChild(person.(OrphanChild))
  100. person = NewDirectorOrphanPerson(&TargetLangOrphanPerson{})
  101. check(person, "TargetLangOrphanPerson")
  102. DeleteDirectorOrphanPerson(person.(OrphanPerson))
  103. person = NewDirectorOrphanChild(&TargetLangOrphanChild{})
  104. check(person, "TargetLangOrphanChild")
  105. DeleteDirectorOrphanChild(person.(OrphanChild))
  106. }