diff --git a/plug-ins/script-fu/test/meson.build b/plug-ins/script-fu/test/meson.build index ed500f08c8fc6209c92ac60c6ac247b312eb297e..67e71f7ec0f78016a1b7b9610371d93ff7e20f88 100644 --- a/plug-ins/script-fu/test/meson.build +++ b/plug-ins/script-fu/test/meson.build @@ -20,23 +20,36 @@ if not stable 'tests' / 'PDB' / 'layer' / 'layer-new.scm', 'tests' / 'PDB' / 'layer' / 'layer-ops.scm', 'tests' / 'PDB' / 'layer' / 'layer-mask.scm', + 'tests' / 'PDB' / 'text-layer' / 'text-layer-new.scm', + 'tests' / 'PDB' / 'item' / 'item.scm', + 'tests' / 'PDB' / 'item' / 'item-position.scm', + 'tests' / 'PDB' / 'item' / 'item-layer-group.scm', + 'tests' / 'PDB' / 'channel' / 'channel-new.scm', 'tests' / 'PDB' / 'channel' / 'channel-attributes.scm', 'tests' / 'PDB' / 'channel' / 'channel-ops.scm', - 'tests' / 'PDB' / 'vectors-new.scm', + + 'tests' / 'PDB' / 'vectors' / 'vectors-new.scm', + 'tests' / 'PDB' / 'vectors' / 'vectors-stroke.scm', + 'tests' / 'PDB' / 'selection' / 'selection.scm', 'tests' / 'PDB' / 'selection' / 'selection-from.scm', + 'tests' / 'PDB' / 'selection' / 'selection-by.scm', + 'tests' / 'PDB' / 'resource' / 'resource.scm', 'tests' / 'PDB' / 'resource' / 'resource-ops.scm', 'tests' / 'PDB' / 'resource' / 'brush.scm', 'tests' / 'PDB' / 'resource' / 'palette.scm', 'tests' / 'PDB' / 'context' / 'context-get-set.scm', 'tests' / 'PDB' / 'context' / 'context-resource.scm', - # TODO context push pop list-paint-methods + 'tests' / 'PDB' / 'edit' / 'buffer.scm', 'tests' / 'PDB' / 'edit' / 'edit.scm', + 'tests' / 'PDB' / 'edit' / 'edit-multi-layer.scm', + + 'tests' / 'PDB' / 'gimp' / 'gimp.scm', 'tests' / 'PDB' / 'misc.scm', 'tests' / 'PDB' / 'enums.scm', 'tests' / 'PDB' / 'refresh.scm', diff --git a/plug-ins/script-fu/test/tests/PDB/channel/channel-new.scm b/plug-ins/script-fu/test/tests/PDB/channel/channel-new.scm index 37fd68f500944cdd961c075865582f898fa33c82..1b9dc02ebf412216b319b91c68dfd31d7f34affe 100644 --- a/plug-ins/script-fu/test/tests/PDB/channel/channel-new.scm +++ b/plug-ins/script-fu/test/tests/PDB/channel/channel-new.scm @@ -31,11 +31,10 @@ ; attributes -; color -; FIXME: this passes but should test return red ??? +; color attribute is as given during creation (assert `(equal? (car (gimp-channel-get-color ,testChannel)) - '(0 0 0))) + '(255 0 0))) ; red (assert `(string=? (car (gimp-channel-get-name ,testChannel)) "Test Channel")) diff --git a/plug-ins/script-fu/test/tests/PDB/context/context-get-set.scm b/plug-ins/script-fu/test/tests/PDB/context/context-get-set.scm index 04a04710d4e1d193fe5c7eeb326b30cd30d30633..239c89c5cd5b6f05631297482cff4603485c75e3 100644 --- a/plug-ins/script-fu/test/tests/PDB/context/context-get-set.scm +++ b/plug-ins/script-fu/test/tests/PDB/context/context-get-set.scm @@ -1,7 +1,7 @@ ; test getters and setters of GimpContext ; (sic its not an object or class) - +; TODO context push pop list-paint-methods ; set-line-dash-pattern diff --git a/plug-ins/script-fu/test/tests/PDB/context/context-resource.scm b/plug-ins/script-fu/test/tests/PDB/context/context-resource.scm index a090cb9717faa3ab25578d17cccca85c221f7eb9..e7a3a7e2c095fe52fd4fafc661fb611e80446180 100644 --- a/plug-ins/script-fu/test/tests/PDB/context/context-resource.scm +++ b/plug-ins/script-fu/test/tests/PDB/context/context-resource.scm @@ -2,8 +2,8 @@ -; function to test methods on Resource -; for a valid Resource ID +; function to test methods on Resource for a valid Resource ID. +; Tests methods: get-name, id-is-valid, get-identifiers, is-editable. (define (test-resource-methods resource) ; a resource is an int ID in ScriptFu @@ -44,7 +44,7 @@ ; test context-get-resource returns active resource of given className -; Setup. Not assert. +; This is setup, not asserted. (define testBrush (car (gimp-context-get-resource "GimpBrush"))) (define testFont (car (gimp-context-get-resource "GimpFont"))) @@ -66,6 +66,7 @@ ; test more specific context methods return same result ; as the general context-get-resource +; ID's are numeric ; test equality of numeric IDs (assert `(= (car(gimp-context-get-brush)) ,testBrush)) @@ -93,15 +94,8 @@ ; test errors -; invalid type name +; context-get-resource requires a valid type name (assert-error `(gimp-context-get-resource "InvalidTypeName") "Procedure execution of gimp-context-get-resource failed") -; invalid numeric ID -; -1 is out of range -(assert-error `(gimp-resource-get-name -1) - "Invalid value for argument 0") -; 12345678 is in range but invalid -(assert-error `(gimp-resource-get-name 12345678) - "Invalid value for argument 0") diff --git a/plug-ins/script-fu/test/tests/PDB/edit/edit-multi-layer.scm b/plug-ins/script-fu/test/tests/PDB/edit/edit-multi-layer.scm new file mode 100644 index 0000000000000000000000000000000000000000..a12d60f8001fe62d52b0ffe3be4a3899a250ef3c --- /dev/null +++ b/plug-ins/script-fu/test/tests/PDB/edit/edit-multi-layer.scm @@ -0,0 +1,144 @@ +; Test methods of Edit module of the PDB +; When the image has multi-layers +; Multi-layer editing is new to GIMP v3 + +; tested elsewhere +; paste when: +; - clip is not empty +; - clip has one layers +; - no selection + + + +; setup +; Load test image that already has drawable +(define testImage (testing:load-test-image "wilber.png")) + +; Add a layer +(define testLayer2 + (car (gimp-layer-new + testImage + 21 + 22 + RGB-IMAGE + "LayerNew" + 50.0 + LAYER-MODE-NORMAL))) +; Insert new layer +(assert `(gimp-image-insert-layer + ,testImage + ,testLayer2 + 0 0)) ; parent, position within parent + +; get all the root layers +; testImage has two layers at root. +(define testLayers (cadr (gimp-image-get-layers testImage))) +;testLayers is-a vector + +; capture a ref to the first layer +(define testLayer (vector-ref testLayers 0)) + +; check the image has two layers +(assert `(= (car (gimp-image-get-layers ,testImage)) + 2)) + +; check our local list of layers is length 2 +(assert `(= (vector-length ,testLayers) + 2)) + + + + +; tests + +; copy when no selection + +; copy returns true when no selection and copies entire drawables + +; FIXME this should fail? the passed length does not match the length of list +; copy first of two +(assert-PDB-true `(gimp-edit-copy 1 ,testLayers)) +; copy both of two +(assert-PDB-true `(gimp-edit-copy 2 ,testLayers)) + + +; paste when: +; - clip is not empty +; - clip has two layers +; - no selection +; returns the pasted layers, a vector of length two +(assert `(= (car (gimp-edit-paste + ,testLayer + TRUE)) ; paste-into + 2)) + +; paste is NOT floating +; the passed layer is moot: new layers are created. + +; the image now has four layers +(assert `(= (car (gimp-image-get-layers ,testImage)) + 4)) + +; the new layers were pasted centered at (0,0) +; the new layers are partially off the canvas + +; The image i.e. canvas is NOT larger now +(assert `(= (car (gimp-image-get-width ,testImage)) + 256)) +; !!! Note that some layers, when selected, +; might not be visible, since the scrollbars are on the current canvas +; not the size of the bounding box of all the layers. + +; But resizing gives a larger size +;;(assert `(gimp-image-resize-to-layers ,testImage)) +;;(assert `(= (car (gimp-image-get-width ,testImage)) +;; 373)) + + + + +; test pasting into a layer whose origin is off the canvas +; don't resize and then paste into the new layer that is off canvas. +; the clip still has two layers + +; get reference to one of the new layers +; it is top of stack, the first element in the vector of layers +(define testOffCanvasLayer (vector-ref (cadr (gimp-image-get-layers testImage)) + 0)) + +(assert `(= (car (gimp-edit-paste + ,testOffCanvasLayer + TRUE)) ; paste-into + 2)) +; The image now has six layers, extending to the upper left. +(assert `(gimp-image-resize-to-layers ,testImage)) +(assert `(= (car (gimp-image-get-width ,testImage)) + 490)) + + +; copy-visible when image has many layers +; only puts one layer on clip +(assert-PDB-true `(gimp-edit-copy-visible ,testImage)) + +; TODO this tested elsewhere +; paste when: +; - clip is not empty +; - clip has one layers +; - no selection +; returns the pasted layers, a vector of length one +(assert `(= (car (gimp-edit-paste + ,testLayer + TRUE)) ; paste-into + 1)) + + +; TODO test when the selection is not empty + + +; TODO test paste-into FALSE + +; TODO test pasting into empty image. + + +; for debugging individual test file: +;(gimp-display-new testImage) diff --git a/plug-ins/script-fu/test/tests/PDB/edit/edit.scm b/plug-ins/script-fu/test/tests/PDB/edit/edit.scm index 01879fe465d33bd229f2b326f282f8c744b8833c..cffd0ee4a03d4597c474556056d53de11148c7ed 100644 --- a/plug-ins/script-fu/test/tests/PDB/edit/edit.scm +++ b/plug-ins/script-fu/test/tests/PDB/edit/edit.scm @@ -1,5 +1,13 @@ ; Test methods of Edit module of the PDB +; This tests some of the general cases. +; See elsewhere for other cases e.g. edit-multi-layer.scm + +; TODO the "Paste In Place" methods are not in the PDB? + +; TODO the "Paste As" distinctions between Layer and Floating Sel +; are not in the PDB + ; setup @@ -9,7 +17,7 @@ ; get all the root layers ; testImage has exactly one root layer. (define testLayers (cadr (gimp-image-get-layers testImage))) -;testLayers is-a list +;testLayers is-a vector (define testLayer (vector-ref testLayers 0)) @@ -39,27 +47,86 @@ ; copy -; copy returns true when no selection and copies entire drawables +; copy when: +; - no selection +; - image has one drawable +; - one drawable is passed +; returns true and clip has one drawable (assert-PDB-true `(gimp-edit-copy 1 ,testLayers)) +; paste when clipboard is not empty returns a vector of length one +(assert `(= (car (gimp-edit-paste + ,testLayer + TRUE)) ; paste-into + 1)) +; get reference to pasted layer +(define testPastedLayer (vector-ref (cadr (gimp-image-get-layers testImage)) + 0)) + +; !!! this is not what happens in the GUI, the pasted layer is NOT floating +; The pasted layer is floating +(assert-PDB-true `(gimp-layer-is-floating-sel ,testPastedLayer)) + + + -; copy returns false when is a selection -; but it doesn't intersect any chosen layers -; When one layer is offset from another and bounds of layer -; do not intersect bounds of selection. -; TODO ; copy-visible takes only an image +; it puts one drawable on clip (assert-PDB-true `(gimp-edit-copy-visible ,testImage)) + ; paste when clipboard is not empty returns a vector of length one -(assert `(= (car (gimp-edit-paste - ,testLayer - TRUE)) ; paste-into +(assert `(= (car (gimp-edit-paste ,testLayer TRUE)) ; paste-into 1)) + +; The first pasted floating layer was anchored (merged into) first layer +; The ID of the floating sel is now invalid +(assert-PDB-false `(gimp-item-id-is-valid ,testPastedLayer)) +; Can't do this, it throws CRITICAL +;(assert-error `(gimp-layer-is-floating-sel ,testPastedLayer) +; "Procedure") + +; There are now two layers +(assert `(= (car (gimp-image-get-layers ,testImage)) + 2)) +(define testPastedLayer2 (vector-ref (cadr (gimp-image-get-layers testImage)) + 0)) +; the new layer is now floating. +(assert-PDB-true `(gimp-layer-is-floating-sel ,testPastedLayer2)) + + + + + +; paste specifying no destination layer is an error. +; You cannot paste into an empty image because you must pass a destination layer. +; !!! This is different from the GUI +(assert-error `(gimp-edit-paste -1 TRUE) + "Invalid value for argument 0") + + + ; TODO test paste-into FALSE +; TODO test cut + +; TODO test cross image paste, of different modes + + +; copy returns false when is a selection +; but it doesn't intersect any chosen layers +; When one layer is offset from another and bounds of layer +; do not intersect bounds of selection. +; TODO + + + + + + + ; for debugging individual test file: -;(gimp-display-new testImage) +(gimp-display-new testImage) diff --git a/plug-ins/script-fu/test/tests/PDB/gimp/gimp.scm b/plug-ins/script-fu/test/tests/PDB/gimp/gimp.scm new file mode 100644 index 0000000000000000000000000000000000000000..c65ec611a875f6b648059b91ac84cc4b4fe463c3 --- /dev/null +++ b/plug-ins/script-fu/test/tests/PDB/gimp/gimp.scm @@ -0,0 +1,64 @@ +; Tests of gimp module of the PDB +; These are not associated with an object class + + +; The serialized color configuration is a string +(assert '(string? (car (gimp-get-color-configuration)))) + +; The default comment on images is a string +(assert '(string? (car (gimp-get-default-comment)))) + +; The default unit is an integer enum for mm +(assert '(= (car (gimp-get-default-unit)) + UNIT-MM)) + +; The list of open images is a vector of integer ID +; At test time, we don't know how many +(assert '(number? (car (gimp-get-images)))) +(assert '(vector? (cadr (gimp-get-images)))) + +; The list of modules to not be loaded is a list of strings +; Not double wrapped in a list, usually ("") +(assert '(list? (gimp-get-module-load-inhibit))) + +; the monitor resolution is two doubles e.g. (57.0 57.0) +; TODO in what units, pixels/in? +(assert '(real? (car (gimp-get-monitor-resolution)))) + +; the PID is an integer +; FIXME should be renamed get-pid? +(assert '(number? (car (gimp-getpid)))) + + + + +; global parasites +; They persist from session to session + +; the list of global parasites is a list +(assert '(list? (gimp-get-parasite-list))) + +; error to get by name not of a global parasite +(assert-error '(gimp-get-parasite "never in the list") + "Procedure execution of") + +; Can create a named parasite on global namespace. +; See elsewhere, a Parasite is a list. +(assert '(gimp-attach-parasite (list "foo" 1 "zed"))) +; effective +(assert `(equal? (car (gimp-get-parasite "foo")) + '("foo" 1 "zed"))) + +; Can reattach, regardless whether same name already attached. +(assert '(gimp-attach-parasite (list "foo" 2 "bar"))) +; effective +(assert `(equal? (car (gimp-get-parasite "foo")) + '("foo" 2 "bar"))) + +; detaching by name destroys a parasite +(assert `(gimp-detach-parasite "foo")) +; effective, name no longer valid +(assert-error '(gimp-get-parasite "foo") + "Procedure execution of") + + diff --git a/plug-ins/script-fu/test/tests/PDB/image/image-new.scm b/plug-ins/script-fu/test/tests/PDB/image/image-new.scm index 4a6d4483e786315ca9e0e400baef864b117b277c..63cca25e87dd47bd2f85d96b026c4ed9af2add93 100644 --- a/plug-ins/script-fu/test/tests/PDB/image/image-new.scm +++ b/plug-ins/script-fu/test/tests/PDB/image/image-new.scm @@ -13,18 +13,15 @@ -; FUTURE method is_valid on new image yields #t + ; method is_valid on new image yields 1 i.e. true -(assert `(= - (car (gimp-image-id-is-valid ,testImage)) - 1)) +(assert-PDB-true `(gimp-image-id-is-valid ,testImage)) + ; Ensure attributes of new image are correct ; method is_dirty on new image is true -(assert `(= - (car (gimp-image-is-dirty ,testImage)) - 1)) +(assert-PDB-true `(gimp-image-is-dirty ,testImage)) ; method get_width on new image yields same width given when created (assert `(= @@ -47,7 +44,19 @@ ,testImage)) -; new image has no components +; new image has few components + +; !!!! +; New image has one drawable, the selection mask. +; Note there is no gimp-image-get-drawables +; FIXME: this is susceptible to test order: +; subsequent images will have different ID for selection mask. +(assert-PDB-true `(gimp-item-id-is-valid 1)) +; Item 1 is the Selection Mask. +(assert `(string=? (car (gimp-item-get-name 1)) + "Selection Mask")) + + ; new image has zero layers (assert `(= (car (gimp-image-get-layers ,testImage)) diff --git a/plug-ins/script-fu/test/tests/PDB/image/image-ops.scm b/plug-ins/script-fu/test/tests/PDB/image/image-ops.scm index 68bd9272776d0e0377d7c74ac6b8d96d54cc115e..75bfc901b65ad38861d81ee9f2a3b12c704587b3 100644 --- a/plug-ins/script-fu/test/tests/PDB/image/image-ops.scm +++ b/plug-ins/script-fu/test/tests/PDB/image/image-ops.scm @@ -18,9 +18,10 @@ " for argument 'flip-type' (#2, type GimpOrientationType). This value is out of range.")) ; rotate -(assert `(gimp-image-rotate ,testImage ROTATE-90)) -(assert `(gimp-image-rotate ,testImage ROTATE-180)) -(assert `(gimp-image-rotate ,testImage ROTATE-270)) +; v2 ROTATE-90 => v3 ROTATE-DEGREES90 +(assert `(gimp-image-rotate ,testImage ROTATE-DEGREES90)) +(assert `(gimp-image-rotate ,testImage ROTATE-DEGREES180)) +(assert `(gimp-image-rotate ,testImage ROTATE-DEGREES270)) ; scale ; up diff --git a/plug-ins/script-fu/test/tests/PDB/item/item-layer-group.scm b/plug-ins/script-fu/test/tests/PDB/item/item-layer-group.scm new file mode 100644 index 0000000000000000000000000000000000000000..554d0e1fced34b51ae4208bf1a167c8b252ee700 --- /dev/null +++ b/plug-ins/script-fu/test/tests/PDB/item/item-layer-group.scm @@ -0,0 +1,94 @@ +; test Item methods for creating and positioning in layer groups + + + +; setup +(define testImage (testing:load-test-image "wilber.png")) +(define testLayer (vector-ref (cadr (gimp-image-get-layers testImage )) + 0)) + +; group-new not throw +; This is setup, not an assert, because we need to capture the group's ID +; Note the ID is wrapped in list: (3) +(define testGroup (car (gimp-layer-group-new testImage))) + + + + +; tests + +; new group is not in the image until inserted +(assert `(= (car (gimp-image-get-layers ,testImage)) + 1)) + +; group can be inserted in image +; Note group is zero (NULL) +(assert `(gimp-image-insert-layer + ,testImage + ,testGroup + 0 ; parent + 0 )) ; position within parent + +; TODO Error to insert layer into invalid parent + +; Effective: newly created item is-a group +(assert-PDB-true `(gimp-item-is-group ,testGroup)) + +; Newly created group has no children +; vector length is zero +(assert `(= (car (gimp-item-get-children ,testGroup)) + 0)) + +; Newly created group is at the top i.e. position 0 of the root level +(assert `(= (car (gimp-image-get-item-position ,testImage ,testGroup)) + 0)) + + + +; Add children +; Note add child is "reorder" + +; Layer is initially not in the new group +; -1 is ScriptFu NULL +(assert `(= (car (gimp-item-get-parent ,testLayer)) + -1)) + +; Add child does not throw +(assert `(gimp-image-reorder-item ,testImage ,testLayer ,testGroup 0)) + +; Add child is effective, group now has children +(assert `(= (car (gimp-item-get-children ,testGroup)) + 1)) + +; Add child is effective, now child's parent is the group +(assert `(= (car (gimp-item-get-parent ,testLayer)) + ,testGroup)) + +; !!! The added child is still at position 0 of it's level +; It's level is the group, not the root +(assert `(= (car (gimp-image-get-item-position ,testImage ,testLayer)) + 0)) + +; TODO reparenting has no effect on which layer is selected + + + + +; stack order group + +; A group can be raised and lowered. +; The group is already at both top and bottom of root level, +; so this is not a rigorous test. +(assert `(gimp-image-lower-item-to-bottom ,testImage ,testGroup)) + +; Raising a child does not take it out of it's group, +; the raising is within its level +(assert `(gimp-image-raise-item-to-top ,testImage ,testLayer)) +(assert `(= (car (gimp-item-get-parent ,testLayer)) + ,testGroup)) + + +; TODO gimp-image-merge-layer-group +; merge-layer-group means the item is not a group any longer +; the new layer is at the same position in the root level as the group was + diff --git a/plug-ins/script-fu/test/tests/PDB/item/item-position.scm b/plug-ins/script-fu/test/tests/PDB/item/item-position.scm new file mode 100644 index 0000000000000000000000000000000000000000..1eaff79037e46e94c0cd1c8e3e20a616fd521c4c --- /dev/null +++ b/plug-ins/script-fu/test/tests/PDB/item/item-position.scm @@ -0,0 +1,48 @@ +; test Item methods for positioning in stack + +; This tests that all calls minimally work. +; TODO test stack semantics i.e. algebra of stacking operations. + +; All the calls named for layer, channel, vectors are deprecated +; in favor of these more generic "item" calls + + + +; setup +(define testImage (testing:load-test-image "wilber.png")) +(define testLayer (vector-ref (cadr (gimp-image-get-layers testImage )) + 0)) + + + + +; position of single layer is index zero +(assert `(= (car (gimp-image-get-item-position ,testImage ,testLayer)) + 0)) + + +; Single layer is both at top and at bottom of stack and cannot be raised or lowered +(assert-error `(gimp-image-raise-item ,testImage ,testLayer) + "Procedure execution of gimp-image-raise-item failed: Layer cannot be raised higher. ") + +(assert-error `(gimp-image-lower-item ,testImage ,testLayer) + "Procedure execution of gimp-image-lower-item failed: Layer cannot be lowered more. ") + + + +; Can raise to top and bottom without throwing error, but no effect +(assert `(gimp-image-raise-item-to-top ,testImage ,testLayer)) + +(assert `(gimp-image-lower-item-to-bottom ,testImage ,testLayer)) + + +; FIXME API naming inconsistent: should image-reorder-item => image-item-reorder + +; Cannot reorder an item to make parent itself +(assert-error `(gimp-image-reorder-item ,testImage ,testLayer ,testLayer 0) + "Procedure execution of gimp-image-reorder-item failed on invalid input arguments:" ) +; " Item 'Background' (2) cannot be used because it is not a group item" + + + + diff --git a/plug-ins/script-fu/test/tests/PDB/pdb.scm b/plug-ins/script-fu/test/tests/PDB/pdb.scm index ecb00f5f849c0e8e6d50ca1ae83bdd4dea021f5e..96f037c38717dd1d6630ef44c8fb2c0c97a5cffc 100644 --- a/plug-ins/script-fu/test/tests/PDB/pdb.scm +++ b/plug-ins/script-fu/test/tests/PDB/pdb.scm @@ -28,9 +28,11 @@ (testing:load-test "text-layer-new.scm") (testing:load-test "vectors-new.scm") +(testing:load-test "vectors-stroke.scm") (testing:load-test "selection.scm") (testing:load-test "selection-from.scm") +(testing:load-test "selection-by.scm") (testing:load-test "channel-new.scm") (testing:load-test "channel-attributes.scm") @@ -42,7 +44,8 @@ ; Testing Drawable and Item uses extant instances; ; must be after instances of subclasses are created. (testing:load-test "item.scm") -; todo item ordering operations +(testing:load-test "item-position.scm") +(testing:load-test "item-layer-group.scm") ; TODO drawable @@ -58,9 +61,13 @@ ; clipboards ; Order important: edit.scm requires empty clipboard + (testing:load-test "edit.scm") +(testing:load-test "edit-multi-layer.scm") (testing:load-test "buffer.scm") +; gimp module, gimp-get methods +(testing:load-test "gimp.scm") ; TODO undo ; TODO progress @@ -70,7 +77,7 @@ ; parasite ; pdb the object -; gimp the class, gimp-get, gimp-parasite +; gimp-parasite (testing:load-test "misc.scm") diff --git a/plug-ins/script-fu/test/tests/PDB/resource/palette.scm b/plug-ins/script-fu/test/tests/PDB/resource/palette.scm index dd48f78b6251ca0b8e12e0f5f18f420e88f8d510..91da7c8e02a11458c3e2403863177432dec841c7 100644 --- a/plug-ins/script-fu/test/tests/PDB/resource/palette.scm +++ b/plug-ins/script-fu/test/tests/PDB/resource/palette.scm @@ -123,10 +123,9 @@ (assert `(= (car (gimp-palette-add-entry ,testNewPalette "fooEntryName" "red")) 0)) -; was effective on color -; FIXME returns ((0 0 0)) which is not "red" +; was effective: color is as given when entry created (assert `(equal? (car (gimp-palette-entry-get-color ,testNewPalette 0)) - (list 0 0 0))) + (list 255 0 0))) ; red ; was effective on name (assert `(equal? (car (gimp-palette-entry-get-name ,testNewPalette 0)) diff --git a/plug-ins/script-fu/test/tests/PDB/resource/resource.scm b/plug-ins/script-fu/test/tests/PDB/resource/resource.scm index f1b338d6fd6b5d8952f84a3d63e192e3ffcb0e3a..5e1a3f96d68437293951df2980a4f448ca734bd2 100644 --- a/plug-ins/script-fu/test/tests/PDB/resource/resource.scm +++ b/plug-ins/script-fu/test/tests/PDB/resource/resource.scm @@ -14,6 +14,23 @@ + +; invalid numeric ID +; ScriptFu detects these errors, before GIMP can check for out of range. + +; A negative ID is invalid. +; If ScriptFu did not detect, GIMP would yield: "Invalid value for argument 0" +(assert-error `(gimp-resource-get-name -1) + "runtime: invalid resource ID") + +; 12345678 is in range but invalid (presume not exist resource with such a large ID) +(assert-error `(gimp-resource-get-name 12345678) + "runtime: invalid resource ID") + + + + + ; an ID of wrong subclass of resource throws an error. ; !!! Also check stderr for CRITICAL ; 1 is not a valid font ID but it IS the ID of say a brush diff --git a/plug-ins/script-fu/test/tests/PDB/selection/selection-by.scm b/plug-ins/script-fu/test/tests/PDB/selection/selection-by.scm new file mode 100644 index 0000000000000000000000000000000000000000..f8fb98305fa55404bb0b1b031c52ce5d7bf7d563 --- /dev/null +++ b/plug-ins/script-fu/test/tests/PDB/selection/selection-by.scm @@ -0,0 +1,81 @@ +; test PDB methods that change selection by another object +; such as a color or a channel + +; Function to reset the selection +; (define testResetSelection ) + + + +; setup +(define testImage (testing:load-test-image "wilber.png")) +(define testLayer (vector-ref (cadr (gimp-image-get-layers testImage )) + 0)) +; a layer mask from alpha +(define testLayerMask (car (gimp-layer-create-mask + testLayer + ADD-MASK-ALPHA))) +(gimp-layer-add-mask testLayer testLayerMask) + + + +; new image has no initial selection +(assert-PDB-true `(gimp-selection-is-empty ,testImage)) + + + +; test selection by given color + +(assert `(gimp-image-select-color ,testImage CHANNEL-OP-ADD ,testLayer "black")) +; effective: test image has some black pixels, now selection is not empty +(assert-PDB-false `(gimp-selection-is-empty ,testImage)) + + + +; test selection by picking coords + +; !!! This is not the same as the menu item Select>By Color +; That menu item selects all pixels of a picked color. +; The PDB procedure selects a contiguous area (not disconnected pixels) +; and is more affected by settings in the context particularly sample-transparent. +; This test fails if you pick a coord that is transparent, +; since sample-transparent defaults to false? + +; Reset to no selection +(assert `(gimp-selection-none ,testImage)) +(assert-PDB-true `(gimp-selection-is-empty ,testImage)) +(assert `(= (car (gimp-selection-value ,testImage 125 125)) + 0)) + +; gimp-image-select-contiguous-color does not throw +(assert `(gimp-image-select-contiguous-color ,testImage CHANNEL-OP-ADD ,testLayer 125 125)) +; effective, now selection is not empty +(assert-PDB-false `(gimp-selection-is-empty ,testImage)) +; effective, the selection value at the picked coords is "totally selected" +(assert `(= (car (gimp-selection-value ,testImage 125 125)) + 255)) + + + +; selection from item + +; selection from the layer itself: selects same as layer's alpha +(assert `(gimp-selection-none ,testImage)) +(assert `(gimp-image-select-item ,testImage CHANNEL-OP-ADD ,testLayer)) +; effective: selection is not empty +(assert-PDB-false `(gimp-selection-is-empty ,testImage)) + +; selection from layer mask + +(gimp-selection-none testImage) +; layer mask to selection succeeds +(assert `(gimp-image-select-item ,testImage CHANNEL-OP-ADD ,testLayerMask)) +; effective: selection is not empty +(assert-PDB-false `(gimp-selection-is-empty ,testImage)) + +; TODO selection from +; channel, vectors +; TODO selection from layer group? fails? + + +; for debugging individual test file: +; (gimp-display-new testImage) diff --git a/plug-ins/script-fu/test/tests/PDB/text-layer/text-layer-new.scm b/plug-ins/script-fu/test/tests/PDB/text-layer/text-layer-new.scm index 6fb740ec19753306fe30d5f75e6502711aca7df9..162c47a405ec68735bd199215c159a39ecfb8fbc 100644 --- a/plug-ins/script-fu/test/tests/PDB/text-layer/text-layer-new.scm +++ b/plug-ins/script-fu/test/tests/PDB/text-layer/text-layer-new.scm @@ -143,5 +143,4 @@ ; for debugging: display -(assert `(= (car (gimp-display-new ,testImage)) - 1)) \ No newline at end of file +;(gimp-display-new ,testImage) diff --git a/plug-ins/script-fu/test/tests/PDB/vectors-new.scm b/plug-ins/script-fu/test/tests/PDB/vectors/vectors-new.scm similarity index 100% rename from plug-ins/script-fu/test/tests/PDB/vectors-new.scm rename to plug-ins/script-fu/test/tests/PDB/vectors/vectors-new.scm diff --git a/plug-ins/script-fu/test/tests/PDB/vectors/vectors-stroke.scm b/plug-ins/script-fu/test/tests/PDB/vectors/vectors-stroke.scm new file mode 100644 index 0000000000000000000000000000000000000000..3b1aab25141a7e2595233693ff941f4a1c6a5a0d --- /dev/null +++ b/plug-ins/script-fu/test/tests/PDB/vectors/vectors-stroke.scm @@ -0,0 +1,169 @@ +; Test stroke methods of vector class of the PDB + +; in the console, this typically works to debug: +; i.e. these are the typical IDs +; (gimp-image-get-vectors 1) => (1 #(3)) +; (gimp-vectors-get-strokes 3) => (1 #(2)) +; (gimp-vectors-stroke-get-points 3 2) => (0 6 #(200.0 200.0 200.0 200.0 200.0 200.0) 0) + +; setup + +(define testImage (testing:load-test-image "wilber.png")) +(define testLayer (vector-ref (cadr (gimp-image-get-layers testImage )) + 0)) + +(define testPath (car (gimp-vectors-new + testImage + "Test Path"))) +(gimp-image-insert-vectors + testImage + testPath + 0 0) + + +; tests + + +; A stroke has two endpoints. +; Each endpoint as three control points: HAH (sometimes said CAC) +; Where H is a handle, A is an anchor. +; Each control point is a coordinate i.e. pair of floats. +; The count of elements in the array is minimum of 12 +; Two endpoints * three control points per endpoint * 2 floats per control point +(assert `(gimp-vectors-stroke-new-from-points + ,testPath + VECTORS-STROKE-TYPE-BEZIER + 12 ; count control points, 2*2 + (vector 1 2 3 4 5 6 7 8 9 10 11 12) + FALSE)) ; not closed + +; path now has one stroke +(assert `(= (car (gimp-vectors-get-strokes ,testPath)) + 1)) + + + +; capture stroke ID +(define testStroke (vector-ref (cadr (gimp-vectors-get-strokes testPath)) 0)) + +; stroke has correct count of control points +(assert `(gimp-vectors-stroke-get-points + ,testPath + ,testStroke)) +; returns (type count (x y ...) isClosed) + + + +; operations on stroke + +; A Bézier path can be either open or closed. +; An open path has two separate end points. +; A closed path has end points coincide. +; Each Bézier point can have up to two handles, +; the length and direction of which determine the curve of the segments. +; Their end points are called handle points. + +; Closing a path does NOT add a new stroke after the given stroke, +; that connects the end of the given stroke +; to the beginning of the first stroke in the path. +; Instead, closing a stroke changes the coords of the end point +; to coincide with the coords of the start point of the stroke. + +; close a path does not throw +(assert `(gimp-vectors-stroke-close ,testPath ,testStroke)) +; effective: path still has one stroke +(assert `(= (car (gimp-vectors-get-strokes ,testPath)) + 1)) +; effective: the flag on the stroke says it is closed +; the flag is the fourth element of the returned list. +(assert `(= (cadddr (gimp-vectors-stroke-get-points ,testPath ,testStroke)) + 1)) +; effective: the coords coincide +; TODO + +; transformations +(displayln "stroke transformations") + +(assert `(gimp-vectors-stroke-flip ,testPath ,testStroke + ORIENTATION-HORIZONTAL + 0)) ; axis + +(assert `(gimp-vectors-stroke-flip-free ,testPath ,testStroke + 0 0 ; x1,y1 of axis + 100 100 ; x2,y2 of axis + )) + +(assert `(gimp-vectors-stroke-reverse ,testPath ,testStroke)) + +(assert `(gimp-vectors-stroke-rotate ,testPath ,testStroke + 0 0 ; center x,y + 45)) ; angle + +(assert `(gimp-vectors-stroke-scale ,testPath ,testStroke + 10 10)) ; x, y factors + +(assert `(gimp-vectors-stroke-translate ,testPath ,testStroke + 10 10)) ; x, y offsets + + + +; stroke attributes + +(assert `(gimp-vectors-stroke-get-length ,testPath ,testStroke + 0 ;precision + )) + +(assert `(gimp-vectors-stroke-get-point-at-dist ,testPath ,testStroke + 0 ; along + 0 ; precision + )) + +(displayln "stroke interpolate") +; TODO check isClosed +; !!! yields vector 24k length +; This does NOT add a stroke, only yields data +(assert `(gimp-vectors-stroke-interpolate ,testPath ,testStroke + 0 ; precision + )) + + + +; add strokes +(displayln "add stroke") + +; add a stroke to path by moveto does not throw +; TODO does this start at the end of the path? +(assert `(gimp-vectors-bezier-stroke-new-moveto ,testPath + 200 200 ; x, y of moveto point + )) +; effective: path now has two stroke +(assert `(= (car (gimp-vectors-get-strokes ,testPath)) + 2)) + +; FIXME: this crashes app when the stroke is closed +;(assert `(gimp-vectors-bezier-stroke-lineto ,testPath ,testStroke +; 256 256 ; x,y of lineto point +; )) + +; todo cubicto, conicto + +; todo lineto when no previous moveto??? + +(assert `(gimp-vectors-bezier-stroke-new-ellipse ,testPath + 200 200 ; x, y of center + 20 20 ; radius in x, y direction + 200 ; angle of x axis in radians + )) +; effective: path now has three stroke +(assert `(= (car (gimp-vectors-get-strokes ,testPath)) + 3)) + + + +; remove stroke + +(assert `(gimp-vectors-remove-stroke ,testPath ,testStroke)) +; effective: path now has two stroke +(assert `(= (car (gimp-vectors-get-strokes ,testPath)) + 2)) +