PageRenderTime 36ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Go | 90 lines | 72 code | 12 blank | 6 comment | 36 complexity | 4eaf8c703aac678f6024a66a8577071e MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. package main
  2. import "./li_attribute"
  3. func main() {
  4. aa := li_attribute.NewA(1, 2, 3)
  5. if aa.GetA() != 1 {
  6. panic(0)
  7. }
  8. aa.SetA(3)
  9. if aa.GetA() != 3 {
  10. panic(aa.GetA())
  11. }
  12. if aa.GetB() != 2 {
  13. panic(aa.GetB())
  14. }
  15. aa.SetB(5)
  16. if aa.GetB() != 5 {
  17. panic(0)
  18. }
  19. if aa.GetD() != aa.GetB() {
  20. panic(0)
  21. }
  22. if aa.GetC() != 3 {
  23. panic(0)
  24. }
  25. pi := li_attribute.NewParam_i(7)
  26. if pi.GetValue() != 7 {
  27. panic(0)
  28. }
  29. pi.SetValue(3)
  30. if pi.GetValue() != 3 {
  31. panic(0)
  32. }
  33. b := li_attribute.NewB(aa)
  34. if b.GetA().GetC() != 3 {
  35. panic(0)
  36. }
  37. // class/struct attribute with get/set methods using
  38. // return/pass by reference
  39. myFoo := li_attribute.NewMyFoo()
  40. myFoo.SetX(8)
  41. myClass := li_attribute.NewMyClass()
  42. myClass.SetFoo(myFoo)
  43. if myClass.GetFoo().GetX() != 8 {
  44. panic(0)
  45. }
  46. // class/struct attribute with get/set methods using
  47. // return/pass by value
  48. myClassVal := li_attribute.NewMyClassVal()
  49. if myClassVal.GetReadWriteFoo().GetX() != -1 {
  50. panic(0)
  51. }
  52. if myClassVal.GetReadOnlyFoo().GetX() != -1 {
  53. panic(0)
  54. }
  55. myClassVal.SetReadWriteFoo(myFoo)
  56. if myClassVal.GetReadWriteFoo().GetX() != 8 {
  57. panic(0)
  58. }
  59. if myClassVal.GetReadOnlyFoo().GetX() != 8 {
  60. panic(0)
  61. }
  62. // string attribute with get/set methods using return/pass by
  63. // value
  64. myStringyClass := li_attribute.NewMyStringyClass("initial string")
  65. if myStringyClass.GetReadWriteString() != "initial string" {
  66. panic(0)
  67. }
  68. if myStringyClass.GetReadOnlyString() != "initial string" {
  69. panic(0)
  70. }
  71. myStringyClass.SetReadWriteString("changed string")
  72. if myStringyClass.GetReadWriteString() != "changed string" {
  73. panic(0)
  74. }
  75. if myStringyClass.GetReadOnlyString() != "changed string" {
  76. panic(0)
  77. }
  78. }