1 | (in-package :cl-user) |
---|
2 | |
---|
3 | (prove:plan 8) |
---|
4 | |
---|
5 | (prove:is |
---|
6 | (read-from-string "#\"{bar}.{foo}\"") |
---|
7 | '(jss:get-java-field bar foo t)) |
---|
8 | (prove:is |
---|
9 | (read-from-string "#\"q.bar.{foo}\"") |
---|
10 | '(jss:get-java-field (load-time-value (jss:find-java-class "q.bar")) foo t)) |
---|
11 | (prove:is |
---|
12 | (read-from-string "#\"{bar}.foo\"") |
---|
13 | '(jss:get-java-field bar "foo" t)) |
---|
14 | (prove:is-error |
---|
15 | (read-from-string "#\".bar.foo\"") |
---|
16 | 'simple-error) |
---|
17 | ;;; http://abcl.org/trac/ticket/205 |
---|
18 | (prove:is |
---|
19 | (jss:with-constant-signature ((substring "substring")) |
---|
20 | (substring "01234" 2)) "234") |
---|
21 | ;;; http://abcl.org/trac/ticket/229 - note: version of test for this ticket was broken in tests.lisp |
---|
22 | (prove:is (#"toString" |
---|
23 | (find "size" (#"getMethods" (jss:find-java-class "java.util.Collections$UnmodifiableMap")) |
---|
24 | :test 'string-equal :key #"getName")) |
---|
25 | (#"toString" (java::jmethod "java.util.Collections$UnmodifiableMap" "size" ))) |
---|
26 | |
---|
27 | (prove:is |
---|
28 | (jss::with-class-lookup-disambiguated (lang.object) (jss:find-java-class 'object)) |
---|
29 | (jss:find-java-class 'java.lang.object)) |
---|
30 | |
---|
31 | ;; Object is ambiguous in default java |
---|
32 | (prove:is-error |
---|
33 | (jss:find-java-class 'object) |
---|
34 | 'simple-error) |
---|
35 | |
---|
36 | ;; test that optimized jss is much faster than unoptimized |
---|
37 | (let () |
---|
38 | (defun optimized-jss (count) |
---|
39 | (loop repeat count do (#"compile" 'regex.Pattern ".*"))) |
---|
40 | (let ((jss::*inhibit-jss-optimization* t)) |
---|
41 | (defun unoptimized-jss (count) |
---|
42 | (loop repeat count do (#"compile" 'regex.Pattern ".*")))) |
---|
43 | (defun just-loop (count) |
---|
44 | (loop repeat count)) |
---|
45 | (let ((jss::*inhibit-jss-optimization* nil)) |
---|
46 | (compile 'just-loop) |
---|
47 | (compile 'optimized-jss)) |
---|
48 | (let ((jss::*inhibit-jss-optimization* t)) |
---|
49 | (compile 'unoptimized-jss)) |
---|
50 | |
---|
51 | (defmacro timeit (&body body) |
---|
52 | `(let ((start (#"currentTimeMillis" 'system))) |
---|
53 | ,@body |
---|
54 | (- (#"currentTimeMillis" 'system) start))) |
---|
55 | |
---|
56 | (prove:plan 1) |
---|
57 | (prove:is-type (let ((just-loop (timeit (just-loop 10000)))) |
---|
58 | (+ 0.0 |
---|
59 | (/ (- (timeit (optimized-jss 10000)) just-loop) |
---|
60 | (- (timeit (unoptimized-jss 10000)) just-loop)))) |
---|
61 | '(float 0 0.1) |
---|
62 | "Testing JSS compiler optimizationâŠ")) |
---|
63 | |
---|
64 | (prove:plan 2) |
---|
65 | (let* ((jss::*inhibit-jss-optimization* nil) |
---|
66 | (optimized-jss |
---|
67 | (macroexpand (precompiler::precompile-form |
---|
68 | '(#"compile" 'regex.Pattern ".*") t)))) |
---|
69 | (let* ((jss::*inhibit-jss-optimization* t) |
---|
70 | (unoptimized-jss |
---|
71 | (macroexpand (precompiler::precompile-form '(#"compile" 'regex.Pattern ".*") t)))) |
---|
72 | (prove:is (car optimized-jss) 'java:jstatic) |
---|
73 | (prove:is (caar unoptimized-jss) 'lambda))) |
---|
74 | |
---|
75 | (prove:finalize) |
---|
76 | |
---|