ScriptFu: tests: add tests of layer groups and item parent and position

Changes only test scripts.
This commit is contained in:
lloyd konneker 2024-11-19 08:39:21 -05:00
parent da5dc1e303
commit c65cf25805
5 changed files with 446 additions and 32 deletions

View File

@ -34,6 +34,8 @@ test_scripts = [
'tests' / 'PDB' / 'item' / 'item.scm',
'tests' / 'PDB' / 'item' / 'item-position.scm',
'tests' / 'PDB' / 'item' / 'item-layer-group.scm',
'tests' / 'PDB' / 'item' / 'item-layer-group-2.scm',
'tests' / 'PDB' / 'drawable' / 'drawable.scm',
'tests' / 'PDB' / 'drawable' / 'drawable-attributes.scm',

View File

@ -0,0 +1,252 @@
; test Item methods for creating and positioning in GroupLayer
; This is part 2: more tests of more arcane cases
; The test script uses v3 binding of return values
(script-fu-use-v3)
; setup
(define testImage (testing:load-test-image-basic-v3 "gimp-logo.png"))
(displayln testImage)
(define testLayer (vector-ref (gimp-image-get-layers testImage )
0))
; gimp-logo.png has only one layer
; another layer for reorder tests
(define testLayer2 (gimp-layer-new
testImage
21
22
RGB-IMAGE
"LayerNew"
50.0
LAYER-MODE-NORMAL))
; group-new not throw
; This is setup, not an assert, because we need to capture the group's ID
; Note the ID is not wrapped in list
(define testGroup (gimp-group-layer-new testImage))
(define testGroup2 (gimp-group-layer-new testImage))
; tests
(test! "nested GroupLayer")
; group can be inserted in image
; Note parent is zero (NULL)
(assert `(gimp-image-insert-layer
,testImage
,testGroup
0 ; parent
0 )) ; position within parent
; insertion effective: image now has two root layers, a layer and empty group
(assert `(= (vector-length (gimp-image-get-layers ,testImage))
2))
; Groups can be nested
(assert `(gimp-image-insert-layer
,testImage
,testGroup2
,testGroup ; parent
0 )) ; position within parent
; insertion effective: image still has only two root layers, a layer and a group
(assert `(= (vector-length (gimp-image-get-layers ,testImage))
2))
(test! "move item between two groups")
; Initial condition:
; testLayer
; testGroup
; testGroup2
; testLayer is at the top
(assert `(= (gimp-item-get-parent ,testLayer) -1))
; move testLayer to next level
(assert `(gimp-image-reorder-item ,testImage ,testLayer ,testGroup 0))
; reorder effective: image has one root layer, a group
(assert `(= (vector-length (gimp-image-get-layers ,testImage))
1))
; effective: testLayer is parented to testGroup
(assert `(= (gimp-item-get-parent ,testLayer) ,testGroup))
; Condition:
; testGroup
; testLayer
; testGroup2
; move to a deeper group
(assert `(gimp-image-reorder-item ,testImage ,testLayer ,testGroup2 0))
; effective: testLayer is parented to testGroup2
(assert `(= (gimp-item-get-parent ,testLayer) ,testGroup2))
(test! "Error to create cycles in layer graph")
; Now group2 is in group. Error to move group into group2, i.e. parent into child
(assert-error `(gimp-image-reorder-item
,testImage
,testGroup ; moved item
,testGroup2 ; parent
0)
"Procedure execution of gimp-image-reorder-item failed on invalid input arguments:")
; suffix of err msg:
; Item 'Layer Group' (4) must not be an ancestor of 'Layer Group #1' (5)
(test! "Text layers can be reordered")
(define testFont (gimp-context-get-font))
(define testTextLayer
(gimp-text-font
testImage
-1 ; drawable. -1 means NULL means create new text layer
0 0 ; coords
"bar" ; text
1 ; border size
1 ; antialias true
31 ; fontsize
testFont ))
; text layer is already in image
; Condition:
; testTextLayer
; testGroup
; testLayer
; testGroup2
(assert `(= (vector-length (gimp-image-get-layers ,testImage))
2))
(assert `(= (gimp-image-get-item-position ,testImage ,testTextLayer)
0))
; move TextLayer to a deeper group
(assert `(gimp-image-reorder-item ,testImage ,testTextLayer ,testGroup2 0))
; effective: TextLayer parent is testGroup2
(assert `(= (gimp-item-get-parent ,testTextLayer) ,testGroup2))
; Channels and Paths are in a separate item tree
; No support for groups of Channels or Paths
(test! "Channels as Item with parent and position")
; Channels are Items but reorder-item only works with subclass Layer
; There is no such thing as a ChannelGroup
; I.E. only layers can be reordered
(define testChannel (gimp-channel-new
testImage ; image
"Test Channel" ; name
23 24 ; width, height
50.0 ; opacity
"red" )) ; compositing color
; Can insert into image
(assert `(gimp-image-insert-channel
,testImage
,testChannel
0 ; parent, moot since channel groups not supported
0)) ; position in stack
; A channel has a position in its parent
(assert `(= (gimp-image-get-item-position ,testImage ,testChannel)
0))
; A channel parent is always top level.
; The parent of a channel is not a layer.
(assert `(= (gimp-item-get-parent ,testChannel) -1))
(test! "Channels cannot be reordered into the layer tree")
; Error to parent a channel into the layer tree, into a group layer
(assert-error `(gimp-image-reorder-item
,testImage
,testChannel ; moved item
,testGroup2 ; parent
0)
"Procedure execution of gimp-image-reorder-item failed on invalid input arguments:")
; suffix of err message
; Items 'Test Channel' (6) and 'Layer Group #1' (5) cannot be used because they are not part of the same item tree
(test! "Path layers as items with parent and position.")
(define testPath (gimp-path-new
testImage
"Test Path"))
; a new Path is not in the image
(assert `(= (vector-length (gimp-image-get-paths ,testImage))
0))
; !!! Even before inserted in image, path has parent but not position!!!
; Path has parent
(assert `(= (gimp-item-get-parent ,testPath)
-1))
; Error to get position of Path not inserted in image
(assert-error `(gimp-image-get-item-position ,testImage ,testPath)
"Procedure execution of gimp-image-get-item-position failed on invalid input arguments:")
; suffix of err msg
; Item 'Test Path' (8) cannot be used because it has not been added to an image
(assert `(gimp-image-insert-path
,testImage
,testPath
0 0)) ; parent=0 position=0
; A Path's parent is always top level.
; The parent of a Path is not a layer.
(assert `(= (gimp-item-get-parent ,testPath)
-1))
; A Path has a position in its parent, after Path was inserted
(assert `(= (gimp-image-get-item-position ,testImage ,testPath)
0))
(test! "Path layers cannot be reordered into layer tree")
; Error to parent a Path into the layer tree, into a group layer
(assert-error `(gimp-image-reorder-item
,testImage
,testPath ; moved item
,testGroup2 ; parent
0)
"Procedure execution of gimp-image-reorder-item failed on invalid input arguments:")
; suffix of err msg
; Items 'Test Path' (8) and 'Layer Group #1' (5) cannot be used because they are not part of the same item tree
(script-fu-use-v2)

View File

@ -1,17 +1,26 @@
; test Item methods for creating and positioning in GroupLayer
; The test script uses v3 binding of return values
(script-fu-use-v3)
; setup
(define testImage (testing:load-test-image "gimp-logo.png"))
(define testImage (testing:load-test-image-basic-v3 "gimp-logo.png"))
(displayln testImage)
(define testLayer (vector-ref (car (gimp-image-get-layers testImage ))
(define testLayer (vector-ref (gimp-image-get-layers testImage )
0))
; gimp-logo.png has only one layer
; !!! Note that load-test-image is not script-fu-v3 compatible, already unpacks
(script-fu-use-v3)
; The rest of the test script is v3, no need for car to unpack single values
; another layer for reorder tests
(define testLayer2 (gimp-layer-new
testImage
21
22
RGB-IMAGE
"LayerNew"
50.0
LAYER-MODE-NORMAL))
; group-new not throw
@ -20,14 +29,42 @@
(define testGroup (gimp-group-layer-new testImage))
; tests
; new group is not in the image until inserted
; length of list of layers is one, the background
(test! "new GroupLayer")
; group-layer-new was called above, not tested explicitly
; Name of the new group is a fabricated name
(assert `(string=? (gimp-item-get-name ,testGroup)
"Layer Group"))
; new group is not in the image until inserted.
; length of list of layers is one, the background.
(assert `(= (vector-length (gimp-image-get-layers ,testImage))
1))
(test! "insert GroupLayer")
; Effective: new item is-a group
(assert `(gimp-item-id-is-group-layer ,testGroup))
; New group has no children
; vector length is zero
(assert `(= (vector-length (gimp-item-get-children ,testGroup))
0))
; New group has no position until added to image
(assert-error `(gimp-image-get-item-position ,testImage ,testGroup)
"Procedure execution of gimp-image-get-item-position failed on invalid input arguments:")
; Full text:
; Procedure execution of gimp-image-get-item-position failed on invalid input arguments:
; Item 'Layer Group' (3) cannot be used because it has not been added to an image
(test! "insert GroupLayer into image")
; group can be inserted in image
; Note group is zero (NULL)
(assert `(gimp-image-insert-layer
@ -36,35 +73,63 @@
0 ; parent
0 )) ; position within parent
; insertion effective: image now has two layers
; insertion effective: image now has two layers, a layer and empty group
(assert `(= (vector-length (gimp-image-get-layers ,testImage))
2))
; TODO Error to insert layer into invalid parent
; Effective: newly created item is-a group
(assert `(gimp-item-id-is-group-layer ,testGroup))
; Newly created group has no children
; vector length is zero
(assert `(= (vector-length (gimp-item-get-children ,testGroup))
0))
; Newly created group is at the top i.e. position 0 of the root level
; New group, when added to image, is at the top i.e. position 0 of the root level
(assert `(= (gimp-image-get-item-position ,testImage ,testGroup)
0))
; Error to insert twice in the same position as already is
(assert-error `(gimp-image-insert-layer
,testImage
,testGroup
0 ; parent
0 ) ; position within parent
"Procedure execution of gimp-image-insert-layer failed on invalid input arguments: ")
; "Item 'LayerGroup' (3) has already been added to an image"
(test! "Add children to GroupLayer")
; Note add child is "reorder"
; Error to insert layer into invalid parent
; FIXME: we don't test this because:
; thereafter GIMP erroneously thinks the item has been added to some image.
; GIMP could be fixed so that even after this error, the item can be inserted
; into a valid parent i.e. 0
;(assert-error `(gimp-image-insert-layer
; ,testImage
; ,testGroup
; 666 ; parent
; 0 ) ; position within parent
; "Procedure execution of gimp-image-insert-layer failed on invalid input arguments: ")
; Layer is initially not in the new group
; !!! image-reorder-item has many purposes:
; 1) move child into group (from another level)
; 2) reorder i.e. move child within group
(test! "Add child to GroupLayer")
; Note testLayer already is in the image, but in the top (root) group
; Layer is initially at root, not in the new group
; -1 is ScriptFu NULL
(assert `(= (gimp-item-get-parent ,testLayer)
-1))
; Add child does not throw
; error to move layer item into self, i.e. an item not a group
(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
; Not an error to move item into a group at a position larger than size of group
; The group layer is now empty.
(assert `(gimp-image-reorder-item ,testImage ,testLayer ,testGroup 666))
(assert `(= (gimp-image-get-item-position ,testImage ,testLayer)
0))
; Not an error to move item into its current group at its current position
(assert `(gimp-image-reorder-item ,testImage ,testLayer ,testGroup 0))
; Add child is effective, group now has children
@ -85,7 +150,87 @@
; stack order group
(test! "Remove child from GroupLayer")
(assert `(gimp-image-reorder-item
,testImage
,testLayer
-1 ; parent 0 or -1 means remove
0))
; effective: group has no items
(assert `(= (vector-length (gimp-item-get-children ,testGroup))
0))
; effective: now child's parent is NULL i.e. -1 i.e. the top level
(assert `(= (gimp-item-get-parent ,testLayer)
-1))
; restore test conditions, add child back to group
(assert `(gimp-image-reorder-item ,testImage ,testLayer ,testGroup 0))
(test! "order within a group")
; initial conditions:
; testLayer2 not in the image
; image
; testGroup
; testLayer
(assert `(= (vector-length (gimp-item-get-children ,testGroup))
1))
; insert testLayer2 in the image
(assert `(gimp-image-insert-layer
,testImage
,testLayer2
-1 ; parent is top level
0 )) ; position within parent
; The image now has two layers
; !!! This only returns the root layers
(assert `(= (vector-length (gimp-image-get-layers ,testImage))
2))
; TODO Add testLayer2 to the image, and simultaneously to the group
; gimp-image-insert-layer
; Not an error to reorder into existing parent, position
(assert `(gimp-image-reorder-item ,testImage ,testLayer2
-1 ; root, layer is already at root
0)) ; position, layer is already at position 0
; move testLayer2 from top level into group
(assert `(gimp-image-reorder-item ,testImage ,testLayer2 ,testGroup 0))
; effective: image now has only one root layer, the group
(assert `(= (vector-length (gimp-image-get-layers ,testImage))
1))
; effective: group now has two items
(assert `(= (vector-length (gimp-item-get-children ,testGroup))
2))
; effective: testLayer moved down, is now at position 1 within group
(assert `(= (gimp-image-get-item-position ,testImage ,testLayer)
1))
; Reorder within group, testLayer to position top
(assert `(gimp-image-reorder-item ,testImage ,testLayer ,testGroup 0))
; effective: testLayer is now at position 0 within group
(assert `(= (gimp-image-get-item-position ,testImage ,testLayer)
0))
; effective: testLayer2 is now at position 1 within group
(assert `(= (gimp-image-get-item-position ,testImage ,testLayer2)
1))
(test! "stack order of a group")
; A group can be raised and lowered.
; The group is already at both top and bottom of root level,
@ -93,22 +238,37 @@
(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
; the raising is within its level.
(assert `(gimp-image-raise-item-to-top ,testImage ,testLayer))
(assert `(= (gimp-item-get-parent ,testLayer)
,testGroup))
(test! "merge GroupLayer")
; Deprecated: image-merge-layer-group
; gimp-group-layer-merge converts item from group to normal layer
; FIXME (script-fu:397): LibGimpConfig-WARNING **: 18:02:38.773: gimp_config_class_init:
; not supported: GimpParamGroupLayer (group-layer | GimpGroupLayer)
(assert `(gimp-group-layer-merge ,testGroup))
; group layer ID is now not a group
(assert `(not (gimp-item-id-is-group-layer ,testGroup)))
; the new layer is at the same position in the root level as the group was
; TODO we didn't capture the new layer ID
; the ID of the group layer is now invalid
(assert `(not (gimp-item-id-is-valid ,testGroup)))
; The image now has one layer, the merged group.
; It formerly had one group with two layers.
(assert `(= (vector-length (gimp-image-get-layers ,testImage))
1))
(define mergedLayer (vector-ref (gimp-image-get-layers testImage) 0))
; the merged layer is not a group layer anymore
(assert `(not (gimp-item-id-is-group-layer ,mergedLayer)))
; !!! But the name sort of suggests it is
(assert `(string=? (gimp-item-get-name ,mergedLayer)
"Layer Group"))

View File

@ -54,6 +54,7 @@
(testing:load-test "item.scm")
(testing:load-test "item-position.scm")
(testing:load-test "item-layer-group.scm")
(testing:load-test "item-layer-group-2.scm")
(testing:load-test "drawable.scm")
(testing:load-test "drawable-attributes.scm")

View File

@ -131,7 +131,6 @@
; error to insert layer created by gimp-text-font
; TODO make the error message matching by prefix only
(assert-error `(gimp-image-insert-layer
,testImage
,testTextLayer2