File: usb-device-parse.c

package info (click to toggle)
gammu 1.42.0-11
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,340 kB
  • sloc: ansic: 107,388; pascal: 7,209; cpp: 3,976; php: 1,622; python: 1,559; sh: 1,208; sql: 601; perl: 240; makefile: 162; asm: 31; cs: 4
file content (66 lines) | stat: -rw-r--r-- 1,813 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <gammu.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "common.h"

#ifdef WIN32
# define NUL "NUL"
#else
# define NUL "/dev/null"
#endif

GSM_Error GSM_USB_ParseDevice(GSM_StateMachine *s, int *vendor, int *product, int *bus, int *deviceid, char **serial);

int vendor = -1, product = -1, bus = -1, deviceid = -1;
char *serial;
GSM_StateMachine *s;
GSM_Debug_Info *debug_info;
GSM_Config *cfg;

void single_check(const char *string, int vendor_match, int product_match, int bus_match, int deviceid_match, const char *serial_match)
{
	cfg->Device = strdup(string);
	GSM_USB_ParseDevice(s,  &vendor, &product, &bus, &deviceid, &serial);
	test_result(vendor == vendor_match);
	test_result(product == product_match);
	test_result(bus == bus_match);
	test_result(deviceid == deviceid_match);
	test_result((serial == NULL && serial_match == NULL) || strcmp(serial, serial_match) == 0);
	free(cfg->Device);
	cfg->Device = NULL;
}

int main(int argc UNUSED, char **argv UNUSED)
{
	debug_info = GSM_GetGlobalDebug();
	GSM_SetDebugFileDescriptor(stderr, FALSE, debug_info);
	GSM_SetDebugLevel("textall", debug_info);

	s = GSM_AllocStateMachine();
	test_result(s != NULL);

	cfg = GSM_GetConfig(s, -1);

	debug_info = GSM_GetDebug(s);
	GSM_SetDebugGlobal(TRUE, debug_info);

	single_check("0x1234:0x5678", 0x1234, 0x5678, -1, -1, NULL);
	single_check("1234:5678", 1234, 5678, -1, -1, NULL);
	single_check("0x1234:-1", 0x1234, -1, -1, -1, NULL);
	single_check("1.10", -1, -1, 1, 10, NULL);
	single_check("10", -1, -1, -1, 10, NULL);
	single_check("serial:123456", -1, -1, -1, -1, "123456");
	single_check("serial : 123456", -1, -1, -1, -1, "123456");

	/* Free state machine */
	GSM_FreeStateMachine(s);

	return 0;
}

/* Editor configuration
 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72:
 */