jss-tests.lisp 2.29 KB
Newer Older
1 2
(in-package :cl-user)

3
(prove:plan 6)
4

5 6 7 8 9 10 11 12 13 14 15 16
(prove:is
 (read-from-string "#\"{bar}.{foo}\"")
 '(get-java-field bar foo t))
(prove:is
 (read-from-string "#\"q.bar.{foo}\"")
 '(get-java-field (load-time-value (find-java-class "q.bar")) foo t))
(prove:is
 (read-from-string "#\"{bar}.foo\"")
 '(get-java-field bar "foo" t))
(prove:is-error
 (read-from-string "#\".bar.foo\"")
 'simple-error)
17
;;; http://abcl.org/trac/ticket/205
18 19 20
(prove:is
 (with-constant-signature ((substring "substring"))
   (substring "01234" 2)) "234")
21
;;; http://abcl.org/trac/ticket/229 - note: version of test for this ticket was broken in tests.lisp
22 23 24
(prove:is (#"toString"
           (find "size" (#"getMethods" (find-java-class "java.util.Collections$UnmodifiableMap"))
                 :test 'string-equal :key #"getName"))
25 26
    (#"toString" (java::jmethod "java.util.Collections$UnmodifiableMap" "size" )))

27
;; test that optimized jss is much faster than unoptimized
28 29 30 31 32 33 34 35 36 37 38 39 40
(let ()
  (defun optimized-jss (count)
    (loop repeat count do (#"compile" 'regex.Pattern ".*")))
  (let ((jss::*inhibit-jss-optimization* t))
    (defun unoptimized-jss (count)
      (loop repeat count do (#"compile" 'regex.Pattern ".*"))))
  (defun just-loop (count)
    (loop repeat count))
  (let ((jss::*inhibit-jss-optimization* nil))
    (compile 'just-loop)
    (compile 'optimized-jss))
  (let ((jss::*inhibit-jss-optimization* t))
    (compile 'unoptimized-jss))
41

42 43 44 45
  (defmacro timeit (&body body)
    `(let ((start (#"currentTimeMillis" 'system)))
       ,@body
       (- (#"currentTimeMillis" 'system) start)))
46

47 48
  (prove:plan 1)
  (prove:is-type (let ((just-loop (timeit (just-loop 10000))))
49
	   (+ 0.0 
50 51
	      (/ (-  (timeit (optimized-jss 10000)) just-loop)
			(-  (timeit (unoptimized-jss 10000)) just-loop))))
52 53
                 '(float 0 0.1)
                 "Testing JSS compiler optimization…"))
54

55
(prove:plan 2)
56
(let* ((jss::*inhibit-jss-optimization* nil)
57 58 59
       (optimized-jss
        (macroexpand (precompiler::precompile-form
                                    '(#"compile" 'regex.Pattern ".*") t))))
60
  (let* ((jss::*inhibit-jss-optimization* t)
61 62 63 64
         (unoptimized-jss
          (macroexpand (precompiler::precompile-form '(#"compile" 'regex.Pattern ".*") t))))
    (prove:is (car optimized-jss) 'java:jstatic)
    (prove:is (caar unoptimized-jss) 'lambda)))
65

66
(prove:finalize)
67