Skip to content

Commit

Permalink
Fix initialization of 2d-plot-area% when drawing overlays (racket#49)
Browse files Browse the repository at this point in the history
The 2d-plot-area% for the overlays is only created if there are any overlays
present and no unit tests were exercising that code path, so a unit test was
also added to ensure that this plot area is not forgotten about.
  • Loading branch information
alex-hhh committed Sep 25, 2020
1 parent d7da090 commit cbc0620
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plot-gui-lib/plot/private/gui/snip2d.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
(define overlay-area
(make-object 2d-plot-area%
overlay-plot-bounds
'() '() '() '()
'() '() '() '() '()
dc
dc-x-min dc-y-min
(- dc-x-max dc-x-min) (- dc-y-max dc-y-min)))
Expand Down
44 changes: 44 additions & 0 deletions plot-test/plot/tests/PRs/snip-overlay-renderers.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#lang racket
(require plot racket/gui/base racket/draw rackunit)

;; Refactoring done as part of #49 changed the number of init fields for the
;; 2d-plot-area%, but didn't update the overlay-renderer plot area. This unit
;; test exists to ensure that the overlay plot area is created at least once
;; during the testing process, and any initialization problems are caught
;; early.

(define snip-overlay-renderers
(test-suite
"snip-overlay-renderers"
(test-case "snip-overlay-renderers"

;; Scaffolding, construct a pasteboard to hold our plot snip
(define tl (new frame% [label "hello"] [width 800] [height 600]))
(define pb [new pasteboard%])
(define editor (new editor-canvas% [parent tl] [editor pb]))

;; Construct the plot snip and add it to the pasteboard so it has an
;; administrator.
(define snip (plot-snip (function sin -3 3)))
(send pb insert snip)

;; Show the frame -- this is not strictly needed, but will ensure that
;; all widgets have their proper dimensions set and mouse events will be
;; "interpreted" according to correct snip positions.
(send tl show #t)

;; Construct a dummy DC on which to draw the snip
(define dc (new record-dc% [width 800] [height 600]))

(after
(check-not-exn
(lambda ()
;; The 2d-plot-area% for the overlay area is created on-demand when
;; overlay renderers are present
(send snip set-overlay-renderers (list (function cos -3 3)))
(send snip draw dc 0 0 0 0 10 10 0 0 'no-caret)))
(send tl show #f)))))

(module+ test
(require rackunit/text-ui)
(run-tests snip-overlay-renderers))

0 comments on commit cbc0620

Please sign in to comment.