1 /* -*- c -*- */ 2 /* 3 * Copyright 2007 - 2011 Dominic Spill, Michael Ossmann 4 * 5 * This file is part of libbtbb 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2, or (at your option) 10 * any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with libbtbb; see the file COPYING. If not, write to 19 * the Free Software Foundation, Inc., 51 Franklin Street, 20 * Boston, MA 02110-1301, USA. 21 */ 22 23 #ifdef HAVE_CONFIG_H 24 #include "config.h" 25 #endif 26 27 #include "../bluetooth_packet.h" 28 #include <stdio.h> 29 30 int test_unfec23() { 31 char *optr; 32 int i, j, ret, err; 33 ret = 0; 34 35 printf("Testing unfec23\n"); 36 printf("---------------\n"); 37 38 char input[20][15] = { 39 /* No errors */ 40 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0}, 41 {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1}, 42 {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0}, 43 {0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0}, 44 {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1}, 45 {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1}, 46 {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0}, 47 {0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1}, 48 {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1}, 49 {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1}, 50 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0, 1, 0, 0, 0, 0, 0}, 81 {0, 0, 0, 0, 0, 1, 0, 0, 0, 0}, 82 {0, 0, 0, 0, 0, 0, 1, 0, 0, 0}, 83 {0, 0, 0, 0, 0, 0, 0, 1, 0, 0}, 84 {0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, 85 {0, 0, 0, 0, 0, 0, 0, 0, 0, 1} 86 }; 87 88 for(i = 0; i < 20; i++) { 89 if (optr = unfec23(input[i], 1)) { 90 err = 0; 91 for(j = 0; j < 10; j++) { 92 if (optr[j] != output[i][j]) { 93 err = 1; 94 break; 95 } 96 } 97 if (err == 1) { 98 printf("E"); 99 ret++; 100 } 101 else 102 printf("."); 103 } else { 104 printf("F"); 105 ret++; 106 } 107 } 108 109 if (ret > 0) 110 printf("%d errors\n", ret); 111 printf("\n--------------------\n"); 112 printf("Done testing unfec23\n"); 113 return ret; 114 } 115 116 int main(int argc, char** argv) { 117 int ret = 0; 118 119 ret += test_unfec23(); 120 121 exit(ret); 122 } 123