fireworks: Partial revert of r2452, remote several trials of EfcOverAVC
[ffado.git] / libffado / tests / test-devicestringparser.cpp
blobebdb0c7a09e5c9d78ea6dd28a0ce81c4a232ba0e
1 /*
2 * Copyright (C) 2005-2008 by Pieter Palmers
4 * This file is part of FFADO
5 * FFADO = Free Firewire (pro-)audio drivers for linux
7 * FFADO is based upon FreeBoB.
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) version 3 of the License.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
28 #include <argp.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
33 #include "debugmodule/debugmodule.h"
35 #include "src/DeviceStringParser.h"
37 DECLARE_GLOBAL_DEBUG_MODULE;
39 // Program documentation.
40 static char doc[] = "FFADO -- Watchdog test\n\n";
42 // A description of the arguments we accept.
43 static char args_doc[] = "";
46 struct arguments
48 short verbose;
51 // The options we understand.
52 static struct argp_option options[] = {
53 {"verbose", 'v', "n", 0, "Verbose level" },
54 { 0 }
57 //-------------------------------------------------------------
59 // Parse a single option.
60 static error_t
61 parse_opt( int key, char* arg, struct argp_state* state )
63 // Get the input argument from `argp_parse', which we
64 // know is a pointer to our arguments structure.
65 struct arguments* arguments = ( struct arguments* ) state->input;
66 char* tail;
68 errno = 0;
69 switch (key) {
70 case 'v':
71 if (arg) {
72 arguments->verbose = strtoll( arg, &tail, 0 );
73 if ( errno ) {
74 fprintf( stderr, "Could not parse 'verbose' argument\n" );
75 return ARGP_ERR_UNKNOWN;
77 } else {
78 if ( errno ) {
79 fprintf( stderr, "Could not parse 'verbose' argument\n" );
80 return ARGP_ERR_UNKNOWN;
83 break;
84 default:
85 return ARGP_ERR_UNKNOWN;
87 return 0;
90 // Our argp parser.
91 static struct argp argp = { options, parse_opt, args_doc, doc };
93 int main(int argc, char *argv[])
96 struct arguments arguments;
98 // Default values.
99 arguments.verbose = DEBUG_LEVEL_VERY_VERBOSE;
101 // Parse our arguments; every option seen by `parse_opt' will
102 // be reflected in `arguments'.
103 if ( argp_parse ( &argp, argc, argv, 0, 0, &arguments ) ) {
104 fprintf( stderr, "Could not parse command line\n" );
105 exit(1);
108 setDebugLevel(arguments.verbose);
110 DeviceStringParser p = DeviceStringParser();
111 p.setVerboseLevel(arguments.verbose);
113 p.parseString("hw:0;hw:1");
114 p.parseString("hw:0;hw:1;");
115 p.parseString("hw:0,0;hw:1,1;");
116 p.parseString("hw:1,1;hw:1,0");
117 p.parseString("guid:0x123456789");
118 p.show();
120 return EXIT_SUCCESS;