Main Content

readFromSource

Test custom file adapter by reading from source

Since R2022b

    Description

    readFromSource(testerObj) tests the getData method of a custom external file adapter derived from the Simulink.data.adapters.BaseMatlabFileAdapter base class. When you create the Simulink.data.adapters.AdapterDataTester object, testerObj, you open a connection to a test file by using an instance of a custom file adapter. The object function reads data from that test file.

    example

    Examples

    collapse all

    Use 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 Create External File Adapter for Loading Variables into Simulink.SimulationInput Object.

    The getData method reads data from an XML file test.xml with 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);

    Input Arguments

    collapse all

    File adapter tester, specified as a Simulink.data.adapters.AdapterDataTester object.

    Version History

    Introduced in R2022b