Clean up version number mishap (4.2.3 reported as 4.2.2)
[SCSI2SD.git] / software / SCSI2SD / test / hidPacketTest.c
1 //      Copyright (C) 2014 Michael McMaster <michael@codesrc.com>
2 //
3 //      This file is part of SCSI2SD.
4 //
5 //      SCSI2SD is free software: you can redistribute it and/or modify
6 //      it under the terms of the GNU General Public License as published by
7 //      the Free Software Foundation, either version 3 of the License, or
8 //      (at your option) any later version.
9 //
10 //      SCSI2SD is distributed in the hope that it will be useful,
11 //      but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //      GNU General Public License for more details.
14 //
15 //      You should have received a copy of the GNU General Public License
16 //      along with SCSI2SD.  If not, see <http://www.gnu.org/licenses/>.
17
18 #include "hidpacket.h"
19
20 #include <assert.h>
21 #include <stdio.h>
22
23 void test(uint8_t* in, size_t inLen)
24 {
25         printf("Testing packet of size %ld\n", inLen);
26
27         hidPacket_send(in, inLen);
28         uint8_t hidBuffer[USBHID_LEN];
29         const uint8_t* toSend = hidPacket_getHIDBytes(hidBuffer);
30         while (toSend)
31         {
32                 printf("Transferring packet\n");
33                 hidPacket_recv(toSend, USBHID_LEN);
34                 toSend = hidPacket_getHIDBytes(hidBuffer);
35         }
36
37         size_t len;
38         const uint8_t* rxPacket = hidPacket_getPacket(&len);
39         printf("Received length = %ld\n", len);
40         assert(len == inLen);
41         assert(rxPacket);
42         assert(memcmp(in, rxPacket, len) == 0);
43         printf("OK\n\n");
44 }
45
46
47 int main()
48 {
49         uint8_t testPacketSmall[] = {1,2,3,4,5,6,7,8,9,0};
50         uint8_t testPacketMed[] =
51         {
52                 1,2,3,4,5,6,7,8,9,0,
53                 1,2,3,4,5,6,7,8,9,0,
54                 1,2,3,4,5,6,7,8,9,0,
55                 1,2,3,4,5,6,7,8,9,0,
56                 1,2,3,4,5,6,7,8,9,0,
57                 1,2,3,4,5,6,7,8,9,0,
58                 1,2,3,4
59         };
60         uint8_t testPacketBig[] =
61         {
62                 1,2,3,4,5,6,7,8,9,0,
63                 1,2,3,4,5,6,7,8,9,0,
64                 1,2,3,4,5,6,7,8,9,0,
65                 1,2,3,4,5,6,7,8,9,0,
66                 1,2,3,4,5,6,7,8,9,0,
67                 1,2,3,4,5,6,7,8,9,0,
68                 1,2,3,4,5,6,7,8,9,0,
69                 1,2,3,4,5,6,7,8,9,0,
70                 1,2,3,4,5,6,7,8,9,0,
71                 1,2,3,4,5,6,7,8,9,0
72         };
73         uint8_t testPacketHuge[] =
74         {
75                 1,2,3,4,5,6,7,8,9,0,
76                 1,2,3,4,5,6,7,8,9,0,
77                 1,2,3,4,5,6,7,8,9,0,
78                 1,2,3,4,5,6,7,8,9,0,
79                 1,2,3,4,5,6,7,8,9,0,
80                 1,2,3,4,5,6,7,8,9,0,
81                 1,2,3,4,5,6,7,8,9,0,
82                 1,2,3,4,5,6,7,8,9,0,
83                 1,2,3,4,5,6,7,8,9,0,
84                 1,2,3,4,5,6,7,8,9,0,
85                 1,2,3,4,5,6,7,8,9,0,
86                 1,2,3,4,5,6,7,8,9,0,
87                 1,2,3,4,5,6,7,8,9,0,
88                 1,2,3,4,5,6,7,8,9,0,
89                 1,2,3,4,5,6,7,8,9,0,
90                 1,2,3,4,5,6,7,8,9,0,
91                 1,2,3,4,5,6,7,8,9,0,
92                 1,2,3,4,5,6,7,8,9,0,
93                 1,2,3,4,5,6,7,8,9,0,
94                 1,2,3,4,5,6,7,8,9,0,
95                 1,2,3,4,5,6,7,8,9,0,
96                 1,2,3,4,5,6,7,8,9,0,
97                 1,2,3,4,5,6,7,8,9,0,
98                 1,2,3,4,5,6,7,8,9,0,
99                 1,2,3,4,5,6,7,8,9,0,
100                 1,2,3,4,5,6
101         };
102
103         test(testPacketSmall, sizeof(testPacketSmall));
104         test(testPacketMed, sizeof(testPacketMed));
105         test(testPacketBig, sizeof(testPacketBig));
106         test(testPacketHuge, sizeof(testPacketHuge));
107         return 0;
108 }