| 20 | #define DATA_BYTE 'a' |
| 21 | |
| 22 | static int |
| 23 | test_rte_strsplit(void) |
| 24 | { |
| 25 | int i; |
| 26 | do { |
| 27 | /* ======================================================= |
| 28 | * split a mac address correct number of splits requested |
| 29 | * =======================================================*/ |
| 30 | char test_string[] = "54:65:76:87:98:90"; |
| 31 | char *splits[6]; |
| 32 | |
| 33 | LOG("Source string: '%s', to split on ':'\n", test_string); |
| 34 | if (rte_strsplit(test_string, sizeof(test_string), |
| 35 | splits, 6, ':') != 6) { |
| 36 | LOG("Error splitting mac address\n"); |
| 37 | return -1; |
| 38 | } |
| 39 | for (i = 0; i < 6; i++) |
| 40 | LOG("Token %d = %s\n", i + 1, splits[i]); |
| 41 | } while (0); |
| 42 | |
| 43 | |
| 44 | do { |
| 45 | /* ======================================================= |
| 46 | * split on spaces smaller number of splits requested |
| 47 | * =======================================================*/ |
| 48 | char test_string[] = "54 65 76 87 98 90"; |
| 49 | char *splits[6]; |
| 50 | |
| 51 | LOG("Source string: '%s', to split on ' '\n", test_string); |
| 52 | if (rte_strsplit(test_string, sizeof(test_string), |
| 53 | splits, 3, ' ') != 3) { |
| 54 | LOG("Error splitting mac address for max 2 splits\n"); |
| 55 | return -1; |
| 56 | } |
| 57 | for (i = 0; i < 3; i++) |
| 58 | LOG("Token %d = %s\n", i + 1, splits[i]); |
| 59 | } while (0); |
| 60 | |
| 61 | do { |
| 62 | /* ======================================================= |
| 63 | * split on commas - more splits than commas requested |
| 64 | * =======================================================*/ |
| 65 | char test_string[] = "a,b,c,d"; |
| 66 | char *splits[6]; |
| 67 | |
| 68 | LOG("Source string: '%s', to split on ','\n", test_string); |
| 69 | if (rte_strsplit(test_string, sizeof(test_string), |
| 70 | splits, 6, ',') != 4) { |
| 71 | LOG("Error splitting %s on ','\n", test_string); |
| 72 | return -1; |
| 73 | } |
| 74 | for (i = 0; i < 4; i++) |
| 75 | LOG("Token %d = %s\n", i + 1, splits[i]); |
| 76 | } while(0); |
| 77 | |
| 78 | do { |
| 79 | /* ======================================================= |
no test coverage detected