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
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
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:')
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
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
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')
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
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
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
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 = {}
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 = {}
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
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
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
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
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