Example #1
0
def req6_a(cli):
    """Test requirement FR6-A: Parameter for C header file."""
    header = os.path.join(os.path.dirname(__file__), 'cpp.h')
    include = os.path.join(os.path.dirname(__file__), 'include.h')
    assert os.path.isfile(include)
    headers, _ = csjark.parse_args([header, '-v', '-d', '-f', include])
    assert len(headers) == 2
Example #2
0
def create_protocols(headers, yml, args=None, cleanup=True):
    """Create protocols for black-box-testing."""
    # Store default options to be able to restore them later
    config.Options.platforms = set()
    o = config.Options
    defaults = (o.verbose, o.debug, o.strict, o.use_cpp,
                o.output_dir, o.output_file, o.platforms, o.delegator)

    # Parse command line arguments
    if args is None:
        args = []
    cli_args = ['-f'] + headers + ['-c', yml] + args
    headers, configs = csjark.parse_args(cli_args)

    # Parse config files
    for filename in configs:
        config.parse_file(filename)
    config.Options.prepare_for_parsing()

    # Create protocols
    csjark.parse_headers(headers)

    # Sort the protocols on name
    structs = {}
    for key, proto in cparser.StructVisitor.all_protocols.items():
        structs[proto.name] = proto.generate()

    if cleanup:
        perform_cleanup(defaults)
        return structs
    else:
        return structs, defaults
Example #3
0
def cli_no_file(cli):
    """Test that providing no header or config prints usage message."""
    with contexts.capture_output() as (out, err):
        with contexts.raises(SystemExit) as error:
            headers, configs = csjark.parse_args(['-v', '-d'])
    assert str(error) == '2'
    assert out[0].startswith('usage:')
Example #4
0
def cli_headerfile2(cli):
    """Test the default commandline interface flags"""
    header = os.path.join(os.path.dirname(__file__), 'cpp.h')
    include = os.path.join(os.path.dirname(__file__), 'include.h')
    assert os.path.isfile(include)
    headers, _ = csjark.parse_args([header, '-v', '-d', '-f', include])
    assert len(headers) == 2
Example #5
0
def cli_headerfile2(cli):
    """Test the default commandline interface flags"""
    header = os.path.join(os.path.dirname(__file__), 'cpp.h')
    include = os.path.join(os.path.dirname(__file__), 'include.h')
    assert os.path.isfile(include)
    headers, _ = csjark.parse_args([header, '-v', '-d', '-f', include])
    assert len(headers) == 2
Example #6
0
def cli_only_config(cli):
    """Test that one can provide only a yaml file."""
    config = os.path.join(os.path.dirname(__file__), 'sprint2.yml')
    assert os.path.isfile(config)
    headers, configs = csjark.parse_args([config])
    assert len(headers) == 0
    assert len(configs) == 1
Example #7
0
def cli_only_config(cli):
    """Test that one can provide only a yaml file."""
    config = os.path.join(os.path.dirname(__file__), 'sprint2.yml')
    assert os.path.isfile(config)
    headers, configs = csjark.parse_args([config])
    assert len(headers) == 0
    assert len(configs) == 1
Example #8
0
def cli_no_file(cli):
    """Test that providing no header or config prints usage message."""
    with contexts.capture_output() as (out, err):
        with contexts.raises(SystemExit) as error:
            headers, configs = csjark.parse_args(['-v', '-d'])
    assert str(error) == '2'
    assert out[0].startswith('usage:')
Example #9
0
def req6_a(cli):
    """Test requirement FR6-A: Parameter for C header file."""
    header = os.path.join(os.path.dirname(__file__), 'cpp.h')
    include = os.path.join(os.path.dirname(__file__), 'include.h')
    assert os.path.isfile(include)
    headers, _ = csjark.parse_args([header, '-v', '-d', '-f', include])
    assert len(headers) == 2
Example #10
0
def cli_file_dont_existing(cli):
    """Test if a file is missing"""
    config = os.path.join(os.path.dirname(__file__), 'sprint2.yml')
    with contexts.capture_output() as (out, err):
        with contexts.raises(SystemExit) as error:
            headers, configs = csjark.parse_args(['404.h', config])
    assert str(error) == '2'
    assert out[0].startswith('Unknown file(s): 404.h')
Example #11
0
def cli_file_dont_existing(cli):
    """Test if a file is missing"""
    config = os.path.join(os.path.dirname(__file__), 'sprint2.yml')
    with contexts.capture_output() as (out, err):
        with contexts.raises(SystemExit) as error:
            headers, configs = csjark.parse_args(['404.h', config])
    assert str(error) == '2'
    assert out[0].startswith('Unknown file(s): 404.h')
Example #12
0
def req6_b(cli):
    """Test requirement FR6-B: Parameter for configuration file."""
    header = os.path.join(os.path.dirname(__file__), 'cpp.h')
    include = os.path.join(os.path.dirname(__file__), 'include.h')
    config = os.path.join(os.path.dirname(__file__), 'sprint2.yml')
    assert os.path.isfile(config)
    headers, configs = csjark.parse_args(
            [header, '--verbose', '-d', '-f', include, '--config', config])
    assert len(headers) == 2
Example #13
0
def cli_headerfile_and_configfile(cli):
    """Test the default commandline interface flags"""
    header = os.path.join(os.path.dirname(__file__), 'cpp.h')
    include = os.path.join(os.path.dirname(__file__), 'include.h')
    config = os.path.join(os.path.dirname(__file__), 'sprint2.yml')
    assert os.path.isfile(config)
    headers, configs = csjark.parse_args(
            [header, '--verbose', '-d', '-f', include, '--config', config])
    assert len(headers) == 2
Example #14
0
def req6_b(cli):
    """Test requirement FR6-B: Parameter for configuration file."""
    header = os.path.join(os.path.dirname(__file__), 'cpp.h')
    include = os.path.join(os.path.dirname(__file__), 'include.h')
    config = os.path.join(os.path.dirname(__file__), 'sprint2.yml')
    assert os.path.isfile(config)
    headers, configs = csjark.parse_args(
        [header, '--verbose', '-d', '-f', include, '--config', config])
    assert len(headers) == 2
Example #15
0
def cli_headerfile_and_configfile(cli):
    """Test the default commandline interface flags"""
    header = os.path.join(os.path.dirname(__file__), 'cpp.h')
    include = os.path.join(os.path.dirname(__file__), 'include.h')
    config = os.path.join(os.path.dirname(__file__), 'sprint2.yml')
    assert os.path.isfile(config)
    headers, configs = csjark.parse_args(
        [header, '--verbose', '-d', '-f', include, '--config', config])
    assert len(headers) == 2
Example #16
0
def cli_output_file(cli):
    """Test that one can provide an output file argument."""
    assert cli.output_file is None
    assert cli.output_dir is None
    header = os.path.join(os.path.dirname(__file__), 'cpp.h')
    config = os.path.join(os.path.dirname(__file__), 'sprint3.yml')
    out_file = os.path.join(os.path.dirname(__file__), 'out_file.lua')
    headers, configs = csjark.parse_args([header, config, '-o', out_file])
    assert cli.output_file == out_file
    assert cli.output_dir is None
Example #17
0
def cli_output_file(cli):
    """Test that one can provide an output file argument."""
    assert cli.output_file is None
    assert cli.output_dir is None
    header = os.path.join(os.path.dirname(__file__), 'cpp.h')
    config = os.path.join(os.path.dirname(__file__), 'sprint3.yml')
    out_file = os.path.join(os.path.dirname(__file__), 'out_file.lua')
    headers, configs = csjark.parse_args([header, config, '-o', out_file])
    assert cli.output_file == out_file
    assert cli.output_dir is None
Example #18
0
def parse_headers(cli):
    """Test the parse header function in csjark module."""
    headers = [os.path.join(os.path.dirname(__file__), i)
                for i in ('sprint2.h', 'sprint3.h', 'cpp.h')]
    tmp, configs = csjark.parse_args([headers[0], '-v', '-d'])
    failed = csjark.parse_headers(headers)
    assert failed == 0
    # Cleanup
    cparser.StructVisitor.all_protocols = {}
    dissector.Protocol.protocols = {}
Example #19
0
def parse_headers(cli):
    """Test the parse header function in csjark module."""
    headers = [
        os.path.join(os.path.dirname(__file__), i)
        for i in ('sprint2.h', 'sprint3.h', 'cpp.h')
    ]
    tmp, configs = csjark.parse_args([headers[0], '-v', '-d'])
    failed = csjark.parse_headers(headers)
    assert failed == 0
    # Cleanup
    cparser.StructVisitor.all_protocols = {}
    dissector.Protocol.protocols = {}
Example #20
0
def cli_headerfile_and_configfile_from_folder(cli):
    """Test the support for batch processing"""
    test_folder = os.path.dirname(__file__)
    headers, configs = csjark.parse_args([test_folder])
    assert len(headers) > 0 # Requires that test folder has header files
Example #21
0
def cli_flag_debug(cli):
    """Test the default commandline interface flags"""
    assert cli.debug == False
    header = os.path.join(os.path.dirname(__file__), 'cpp.h')
    csjark.parse_args(['--debug', header])
    assert cli.debug == True
Example #22
0
def cli_headerfile_and_configfile_from_folder(cli):
    """Test the support for batch processing"""
    test_folder = os.path.dirname(__file__)
    headers, configs = csjark.parse_args([test_folder])
    assert len(headers) > 0  # Requires that test folder has header files
Example #23
0
def cli_headerfile1(cli):
    """Test the default commandline interface flags"""
    header = os.path.join(os.path.dirname(__file__), 'cpp.h')
    assert os.path.isfile(header)
    headers, configs = csjark.parse_args([header, '--verbose', '--debug'])
    assert len(headers) == 1
Example #24
0
def cli_headerfile1(cli):
    """Test the default commandline interface flags"""
    header = os.path.join(os.path.dirname(__file__), 'cpp.h')
    assert os.path.isfile(header)
    headers, configs = csjark.parse_args([header, '--verbose', '--debug'])
    assert len(headers) == 1
Example #25
0
def req6_c(cli):
    """Test requirement FR6-C: Parameters for batch processing."""
    test_folder = os.path.dirname(__file__)
    headers, configs = csjark.parse_args([test_folder])
    assert len(headers) > 0  # Requires that test folder has header files
Example #26
0
def req6_c(cli):
    """Test requirement FR6-C: Parameters for batch processing."""
    test_folder = os.path.dirname(__file__)
    headers, configs = csjark.parse_args([test_folder])
    assert len(headers) > 0 # Requires that test folder has header files
Example #27
0
def cli_flag_nocpp(cli):
    """Test the default commandline interface flags"""
    assert cli.use_cpp == True
    header = os.path.join(os.path.dirname(__file__), 'cpp.h')
    csjark.parse_args(['--nocpp', header])
    assert cli.use_cpp == False