Main Content

Simulink.data.adapters.AdapterDataTester

Test custom external file adapter

    Description

    A Simulink.data.adapters.AdapterDataTester object provides functions for testing a custom external file adapter derived from the Simulink.data.adapters.BaseMatlabFileAdapter base class.

    Creation

    Description

    example

    adapterTester = Simulink.data.adapters.AdapterDataTester(adapterObj,source,section) creates a Simulink.data.adapters object that can test an instance of an adapter derived from the Simulink.data.adapters.BaseMatlabFileAdapter base class. With this adapter tester you can test the getData method for your custom file adapter.

    Input Arguments

    expand all

    Custom file adapter, specified as an object of a class that derives from the Simulink.data.adapters.BaseMatlabFileAdapter base class.

    Example: myCustomFileAdapter

    External source file, specified as a character array.

    Example: 'Tires.xls'

    Section of the external file source, specified as a character array or string.

    Example: 'tireManufacturer'

    Properties

    expand all

    This property is read-only.

    Workspace variables, specified as a containers.Map object. Simulink® populates the map object when you call the object function readFromSource. The keys to the map object are the workspace variable names..

    Object Functions

    clearClear variables from file adapter tester object
    readFromSourceTest custom file adapter by reading from source

    Examples

    collapse all

    Create a Simulink.data.adapters.AdapterDataTester object to test the getData method of an XML file adapter derived from a Simulink.data.adapters.BaseMatlabFileAdapter base class. For an example of an XML file adapter, see .

    The getData method reads data from an XML file test.xml in the following format.

    <customerData>
    <x>10</x>
    <y>15</y>
    </customerData>

    Create an instance of your file adapter.

    adapterInstance = myXMLAdapter;
    

    Create an instance of the file adapter tester object using the test file specified above.

    adapterTester = Simulink.data.adapters.AdapterDataTester(adapterInstance, 'test.xml','XML Adapter');

    Use adapterTester to read the data from your XML file. Then, check the data in the WorkspaceVariables property.

    readFromSource(adapterTester);
    variables = adapterTester.WorkspaceVariables
    
    variables = 
      Map with properties:
        Count: 2
        KeyType: char
        ValueType: double
    

    Check the data in the WorkspaceVariables map object.

    variables.keys
    
    ans = 
      1x2 cell array
        {"x"}  {"y"}

    Finally, clear the workspace variables.

    clear(adapterTester);

    After clearing the variables, you can make changes to your XML file and use the same adapter to read the file again.

    readFromSource(adapterTester);
    

    Version History

    Introduced in R2022b