made a public and private header and merged the c code back into one
[webos-internals:precomd.git] / test / test_novacom.c
1 #include "fct.h"
2 #include <novacom.h>
3 #include <novacom_private.h>
4
5 #include <stdio.h>
6 #include <unistd.h>
7 #include <string.h>
8
9
10 FCT_BGN()
11 {
12  /* A simple test case. No setup/teardown. */
13  FCT_SUITE_BGN(integration)
14  {
15         FCT_TEST_BGN(test_is_novacom_interface)
16         {
17                 struct usb_interface_descriptor novacom_descriptor = {0, 0, 0, 0, 0, NOVACOM_USB_CLASS, NOVACOM_USB_SUBCLASS, NOVACOM_USB_PROTOCOL};
18                 struct usb_interface_descriptor non_novacom_descriptor = {0, 0, 0, 0, 0, 0, NOVACOM_USB_SUBCLASS, NOVACOM_USB_PROTOCOL};
19
20                 fct_chk(is_interface_novacom(&novacom_descriptor));
21                 fct_chk(!is_interface_novacom(&non_novacom_descriptor));
22         }
23         FCT_TEST_END();
24
25         FCT_TEST_BGN(test_open_pre_ping_and_close)
26         {
27                 /* The USB device with other relavent information */
28                         novacom_device_t *dev = (novacom_device_t *)malloc( sizeof(novacom_device_t)+USB_BUFLEN ) ;
29
30                         /* Check to see if we're root before we really get into this thing */
31                         fct_chk(geteuid() == 0);
32
33                         /* Initialize novacom communications */
34                         int novacom_init_val = novacom_init( dev );
35                         printf("init value: %i\n", novacom_init_val);
36                         fct_chk(novacom_init_val >= 0);
37
38                         /* Iterate through a NOP loop */
39                         int i;
40                         int novacom_packet_read_return;
41                         for(i = 0 ; i  < 1 ; i++ ) {
42                                 printf( "Iteration: %i\n", i ) ;
43                                 novacom_packet_read_return = novacom_packet_read( dev, USB_BUFLEN, USB_TIMEOUT );
44                                 fct_chk(novacom_packet_read_return >= 0);
45                                 novacom_packet_read_return = error_check( novacom_packet_read( dev, USB_BUFLEN, USB_TIMEOUT ), 0, "Timeout or error reading USB!\n" ) ;
46                                 if( novacom_packet_read_return > 0 ) {
47                                         printf( "Read %i bytes - success!\n", novacom_packet_read_return ) ;
48                                         novacom_packet_process( dev, novacom_packet_read_return ) ;
49                                 }
50                         }
51         }
52         FCT_TEST_END();
53
54  /* Every test suite must be closed. */
55  }
56  FCT_SUITE_END();
57
58 /* Every FCT scope has an end. */
59 }
60 FCT_END();