def match_fields(exp_fields, fields):
    """
    Check field names and values match the expected ones.
        - exp_fields:
            A list of dictionaries with field name/value pairs.
        - fields:
            SPARKL event fields as returned by the listener.
            [
                {'attr': {'name':'n', 'value':3}},
                {'attr': {'name': 'div', 'value':2}}]
    """
    # Reformat event fields to contain only name and value. If value is not
    # given (in case of FLAG fields), value is None.
    fields = [{field['attr']['name']: field['attr']['value']}
              if 'value' in field['attr']
              else {field['attr']['name']: None}
              for field in fields]

    return exp_fields == fields