forked from racket/plot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix initialization of 2d-plot-area% when drawing overlays (racket#49)
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
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |