use-slots.scm 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. (module-static #t)
  2. (test-begin "slot-mangling" 15)
  3. (define slot-name 'target-axis-name)
  4. (define tzoffset (slot-ref (make <java.util.Date>) 'timezone-offset))
  5. (define (run-me)
  6. (let ((a :: <Base> (make <A>)))
  7. (test-begin "A through Base")
  8. (test-equal "invoke getTargetAxisName()"
  9. "field value" (invoke a 'getTargetAxisName))
  10. (test-equal "slot-ref with literal" "field value"
  11. (slot-ref a 'target-axis-name))
  12. ;; slot-set! with literal
  13. (slot-set! a 'target-axis-name "still-from-field")
  14. ;; slot-ref with runtime symbol
  15. (test-equal "still-from-field" (slot-ref a slot-name))
  16. ;; slot-set! with runtime symbol
  17. (slot-set! a slot-name 'still-still-from-field)
  18. (test-end))
  19. (let ((a :: <A> (make <A>)))
  20. (test-begin "A as A")
  21. (test-equal "invoke getTargetAxisName()"
  22. "field value" (invoke a 'getTargetAxisName))
  23. (test-equal "slot-ref with literal" "field value"
  24. (slot-ref a 'target-axis-name))
  25. ;; slot-set! with literal
  26. (slot-set! a 'target-axis-name 'still-from-field)
  27. ;; slot-ref with runtime symbol
  28. (test-equal '|still-from-field| (slot-ref a slot-name))
  29. ;; slot-set! with runtime symbol
  30. (slot-set! a slot-name 'still-still-from-field)
  31. (test-end))
  32. (let ((a :: <Base> (make <A2>)))
  33. (test-begin "A2 through Base")
  34. (test-equal "invoke getTargetAxisName()"
  35. "field value" (invoke a 'getTargetAxisName))
  36. (test-equal "slot-ref with literal" "field value"
  37. (slot-ref a 'target-axis-name))
  38. ;; slot-set! with literal
  39. (slot-set! a 'target-axis-name "still-from-field")
  40. ;; slot-ref with runtime symbol
  41. (test-equal "still-from-field" (slot-ref a slot-name))
  42. ;; slot-set! with runtime symbol
  43. (slot-set! a slot-name "still-still-from-field")
  44. (test-end))
  45. (let ((a :: <A2> (make <A2>)))
  46. (test-begin "A2 as A2")
  47. (test-equal "invoke getTargetAxisName()"
  48. "field value" (invoke a 'getTargetAxisName))
  49. (test-equal "slot-ref with literal" "field value"
  50. (slot-ref a 'target-axis-name))
  51. ;; slot-set! with literal
  52. (slot-set! a 'target-axis-name "still-from-field")
  53. ;; slot-ref with runtime symbol
  54. (test-equal "still-from-field" (slot-ref a slot-name))
  55. ;; slot-set! with runtime symbol
  56. (slot-set! a slot-name "still-still-from-field")
  57. (test-end))
  58. ;; We assume getTimeZoneOffset is always a multiple of 30.
  59. (test-equal 0 (modulo tzoffset 30))
  60. (test-equal 15 (modulo (+ 45 tzoffset) 30)))
  61. (run-me)
  62. ;; Based on Savannah bug #39048: Bad method call resolution?
  63. (define (target-axis-name argument)
  64. (format "from top-level with argument ~a" argument))
  65. (let ((simple
  66. (object (Base)
  67. ((setTargetAxisName v::String)
  68. (error "setTargetAxisName called"))
  69. ((getTargetAxisName)
  70. (target-axis-name "from create-simple")))))
  71. (test-equal "from top-level with argument from create-simple"
  72. (invoke simple 'getTargetAxisName)))
  73. (test-end)