Search code examples
contextmenueclipse-rcptt

How can i verify that a specific context menu path doesn't exist, using RCPTT?


I wish to test that there is a specific choice inside the context menu - based on my selection - and no other choices.

As an example: I wish to verify that if I select one item in my tree, the context menu shall contain "Compare with/Something Else" (this already works) AND that this is the only option, or at least that there is no selection "Compare with/Each other" since I only selected 1 item and not 2.

For checking if something exists I already use this assertion/verification, which works - but for my aproach of "non-existence" it is too detailled, as there will be no property enablement:

get-menu -path "someCascadeMenuItem/someSelectableLeafItem" | get-property enablement | equals true | verify-true

If I try above code (including verify-false or equals false) of a path that doesn't exist, I receive a relatively expected "null" or a failing test which could not find the given menu (since it does not exist).

So, I don't wish to verify the property of the LeafItem - but only its non-existence.

As I didn't find how to get into the asserion mode on the CascadeMenuItem, I guessed for potential properties, like childCount, itemCount, getItems().length, getChildren().length and getData().toString() - used like this example:

get-menu -path "someCascadeMenuItem" | get-property childCount| equals 1 | assert-true

Generally speaking it would be great to know how to check for non-existence, as it might be needed for the root path of the menu eventually.


Solution

  • I finally figured how to check for non-existence. Since it returns an error, if my menu path doesn't exist, I can use:

    verify-error { get-menu -path "someCascadeMenuItem/someSelectableLeafItem" }
    

    This also works on the top level and likely on anything, that is expected to not exist.

    Where I found it: https://archive.eclipse.org/rcptt/release/1.5.4/doc/ecl/