| 1 |
/** |
| 2 |
* This file is part of the Detox package. |
| 3 |
* |
| 4 |
* Copyright (c) Doug Harple <[email protected]> |
| 5 |
* |
| 6 |
* For the full copyright and license information, please view the LICENSE |
| 7 |
* file that was distributed with this source code. |
| 8 |
*/ |
| 9 |
|
| 10 |
#include <stdlib.h> |
| 11 |
#include <stdio.h> |
| 12 |
#include <string.h> |
| 13 |
|
| 14 |
#include "clean_string.h" |
| 15 |
#include "detox_struct.h" |
| 16 |
|
| 17 |
#include "unit_struct.h" |
| 18 |
|
| 19 |
#define DATA_COUNT 11 |
| 20 |
static struct test_filename data[DATA_COUNT] = { |
| 21 |
{ |
| 22 |
.filename = "-#dash_octothorpe-", |
| 23 |
.expected_a = "dash_octothorpe-", |
| 24 |
.expected_b = "dash_octothorpe-", |
| 25 |
}, |
| 26 |
{ |
| 27 |
.filename = "-_dash_underscore-", |
| 28 |
.expected_a = "dash_underscore-", |
| 29 |
.expected_b = "dash_underscore-", |
| 30 |
}, |
| 31 |
{ |
| 32 |
.filename = "ends with octothorpe#", |
| 33 |
.expected_a = "ends with octothorpe#", |
| 34 |
.expected_b = "ends with octothorpe#", |
| 35 |
}, |
| 36 |
{ |
| 37 |
.filename = "#octothorpe", |
| 38 |
.expected_a = "octothorpe", |
| 39 |
.expected_b = "octothorpe", |
| 40 |
}, |
| 41 |
{ |
| 42 |
.filename = "#-octothorpe_dash", |
| 43 |
.expected_a = "octothorpe_dash", |
| 44 |
.expected_b = "octothorpe_dash", |
| 45 |
}, |
| 46 |
{ |
| 47 |
.filename = "_-underscore_dash", |
| 48 |
.expected_a = "underscore_dash", |
| 49 |
.expected_b = "underscore_dash", |
| 50 |
}, |
| 51 |
{ |
| 52 |
.filename = "_underscore", |
| 53 |
.expected_a = "underscore", |
| 54 |
.expected_b = "underscore", |
| 55 |
}, |
| 56 |
{ |
| 57 |
.filename = "___________underscore_______________________.x", |
| 58 |
.expected_a = "underscore_.x", |
| 59 |
.expected_b = "underscore.x", |
| 60 |
}, |
| 61 |
{ |
| 62 |
.filename = "..........how.....does.....this....translate......", |
| 63 |
.expected_a = "..........how.....does.....this....translate......", |
| 64 |
.expected_b = ".how.does.this.translate.", |
| 65 |
}, |
| 66 |
{ |
| 67 |
.filename = "_-_-_-_-_-dotted-_-_-_-_line.....part......two.......", |
| 68 |
.expected_a = "dotted-line.....part......two.......", |
| 69 |
.expected_b = "dotted-line.part.two.", |
| 70 |
}, |
| 71 |
{ |
| 72 |
.filename = "blah-.-de_._da", |
| 73 |
.expected_a = "blah-.-de_._da", |
| 74 |
.expected_b = "blah.de.da", |
| 75 |
}, |
| 76 |
}; |
| 77 |
|
| 78 |
#test test_clean_wipeup |
| 79 |
char *output; |
| 80 |
int i; |
| 81 |
|
| 82 |
// legacy tests |
| 83 |
for (i = 0; i < DATA_COUNT; i++) { |
| 84 |
output = clean_wipeup(data[i].filename, 0); |
| 85 |
ck_assert_str_eq(output, data[i].expected_a); |
| 86 |
} |
| 87 |
|
| 88 |
#test test_clean_wipeup_null |
| 89 |
char *output; |
| 90 |
|
| 91 |
// confirm NULL works |
| 92 |
output = clean_wipeup(NULL, 0); |
| 93 |
ck_assert(output == NULL); |
| 94 |
|
| 95 |
#test test_clean_wipeuprt |
| 96 |
char *output; |
| 97 |
int i; |
| 98 |
|
| 99 |
// legacy tests |
| 100 |
for (i = 0; i < DATA_COUNT; i++) { |
| 101 |
output = clean_wipeup(data[i].filename, 1); |
| 102 |
ck_assert_str_eq(output, data[i].expected_b); |
| 103 |
} |