matlab.unittest.constraints.IsSameHandleAs class

Package: matlab.unittest.constraints
Superclasses: matlab.unittest.constraints.BooleanConstraint

Constraint specifying handle instance same as another

Construction

IsSameHandle(h) provides a constraint specifying a handle instance or group of instances is same as another.

The constraint is satisfied only if each element of the actual value is the same instance as each corresponding element of h.

Input Arguments

h

handle object or array of handle objects. The actual value array passed to the qualification must be the same size as h.

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects.

Examples

collapse all

In a file in your working folder, create the following handle class for interactive testing.

classdef ExampleHandle < handle
end

At the command prompt, create a test case for interactive testing.

import matlab.unittest.TestCase
import matlab.unittest.constraints.IsSameHandleAs

testCase = TestCase.forInteractiveUse;

Instantiate two handles.

h1 = ExampleHandle;
h2 = ExampleHandle;

Verify that the handle, h1, is the same as h1.

testCase.verifyThat(h1, IsSameHandleAs(h1))
Interactive verification passed.

Test that h1 is the same handle instance as h2.

testCase.verifyThat(h1, IsSameHandleAs(h2))
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
IsSameHandleAs failed.
--> Values do not refer to the same handle.

Actual Value:
      ExampleHandle with no properties.
Expected Handle Object:
      ExampleHandle with no properties.

Test that two arrays of handles are the same instances.

expArr = [h1 h2 h1];
actArr = [h1 h2 h1];

testCase.verifyThat(expArr, IsSameHandleAs(actArr))
Interactive verification passed.

The arrays satisfy the constraint even though the elements within a particular array are not the same instance as each other.

Verify that the constraint is not satisfied if it expects a single handle and the actual value is an array of the same instances.

testCase.verifyThat([h1 h1], IsSameHandleAs(h1))
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
IsSameHandleAs failed.
--> Sizes do not match.
    	Actual Value Size           : [1  2]
    	Expected Handle Object Size : [1  1]

Actual Value:
      1x2 ExampleHandle array with no properties.
Expected Handle Object:
      ExampleHandle with no properties.

Similarly, the constraint is not satisfied a single handle instance if it expects an array of handles.

testCase.verifyThat(h2, IsSameHandleAs([h2 h2]))
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
IsSameHandleAs failed.
--> Sizes do not match.
    	Actual Value Size           : [1  1]
    	Expected Handle Object Size : [1  2]

Actual Value:
      ExampleHandle with no properties.
Expected Handle Object:
      1x2 ExampleHandle array with no properties.

See Also

| |