Skip to content

Commit

Permalink
Fix indent in test/stress.c
Browse files Browse the repository at this point in the history
There exists some indent problem in test/stress.c.
Fix the indent problem and unify indent using 4 spaces.
  • Loading branch information
Billy4195 authored and kcwu committed Jun 13, 2017
1 parent 4b047bf commit 85a681d
Showing 1 changed file with 127 additions and 128 deletions.
255 changes: 127 additions & 128 deletions test/stress.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int read_from_fd()
unsigned char c;
int len = read(input_fd, &c, 1);
if (len <= 0)
return EOF;
return EOF;
return c;
}

Expand Down Expand Up @@ -92,170 +92,169 @@ int main(int argc, char *argv[])
TestKeyEntry *key_entry;

for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-init") == 0)
flag_random_init = 1;
else if (strcmp(argv[i], "-extra") == 0)
flag_random_extra = 1;
else if (strcmp(argv[i], "-verbose") == 0) {
flag_verbose = 1;
if (strcmp(argv[i], "-init") == 0)
flag_random_init = 1;
else if (strcmp(argv[i], "-extra") == 0)
flag_random_extra = 1;
else if (strcmp(argv[i], "-verbose") == 0) {
flag_verbose = 1;
logger = verbose_logger;
} else if (strcmp(argv[i], "-loop") == 0 && argv[i + 1])
flag_loop = atoi(argv[++i]);
else if (strcmp(argv[i], "-stdin") == 0) {
flag_loop = atoi(argv[++i]);
else if (strcmp(argv[i], "-stdin") == 0) {
input_fd = 0;
get_input = &read_from_fd;
get_input = &read_from_fd;
} else if (strcmp(argv[i], "-file") == 0 && argv[i + 1]) {
input_fd = open(argv[i + 1], O_RDONLY);
if (input_fd < 0) {
fprintf(stderr, "failed to open '%s'\n", argv[i + 1]);
exit(1);
}
get_input = &read_from_fd;
get_input = &read_from_fd;
i++;
} else {
printf("Usage: %s [-init] [-extra] [-loop N] [-stdin]\n", argv[0]);
printf("\t-init Random initial configuration\n");
printf("\t-extra Random change all configurations during input.\n");
printf("\t This is usually unexpected.\n");
printf("\t-stdin Get random input from stdin\n");
printf("\t-loop N How many iterations to test (default infinite=-1)\n");
printf("Usage: %s [-init] [-extra] [-loop N] [-stdin]\n", argv[0]);
printf("\t-init Random initial configuration\n");
printf("\t-extra Random change all configurations during input.\n");
printf("\t This is usually unexpected.\n");
printf("\t-stdin Get random input from stdin\n");
printf("\t-loop N How many iterations to test (default infinite=-1)\n");
printf("\t-verbose Verbose\n");
exit(1);
}
exit(1);
}
}

/* Initialize for testing */
for (key_entry = chewing_test_special_keys; key_entry->key; key_entry++)
num_special_key++;
num_special_key++;

/* Initialize libchewing */
chewing_sys_path = getenv("CHEWING_PATH");
if (!chewing_sys_path)
chewing_sys_path = CHEWING_DATA_PREFIX;
chewing_sys_path = CHEWING_DATA_PREFIX;

/* for the sake of testing, we should not change existing hash data */
userphrase_path = get_test_userphrase_path();

for (i = 0; i != flag_loop; i++) {
ChewingContext *ctx;
clean_userphrase();
ctx = chewing_new2(chewing_sys_path, userphrase_path, logger, NULL);
ChewingContext *ctx;
clean_userphrase();
ctx = chewing_new2(chewing_sys_path, userphrase_path, logger, NULL);

/* typical configuration */
chewing_set_KBType(ctx, chewing_KBStr2Num("KB_DEFAULT"));
chewing_set_candPerPage(ctx, 9);
chewing_set_maxChiSymbolLen(ctx, 16);
chewing_set_addPhraseDirection(ctx, 1);
chewing_set_selKey(ctx, selKey_define, 10);
chewing_set_spaceAsSelection(ctx, 1);
/* typical configuration */
chewing_set_KBType(ctx, chewing_KBStr2Num("KB_DEFAULT"));
chewing_set_candPerPage(ctx, 9);
chewing_set_maxChiSymbolLen(ctx, 16);
chewing_set_addPhraseDirection(ctx, 1);
chewing_set_selKey(ctx, selKey_define, 10);
chewing_set_spaceAsSelection(ctx, 1);

if (flag_random_init) {
chewing_set_KBType(ctx, get_input());
chewing_set_candPerPage(ctx, get_input());
chewing_set_maxChiSymbolLen(ctx, get_input());
chewing_set_addPhraseDirection(ctx, get_input());
chewing_set_selKey(ctx, selKey_define, get_input() % 11);
chewing_set_spaceAsSelection(ctx, get_input());
chewing_set_escCleanAllBuf(ctx, get_input());
chewing_set_autoShiftCur(ctx, get_input());
chewing_set_easySymbolInput(ctx, get_input());
chewing_set_phraseChoiceRearward(ctx, get_input());
}
if (flag_random_init) {
chewing_set_KBType(ctx, get_input());
chewing_set_candPerPage(ctx, get_input());
chewing_set_maxChiSymbolLen(ctx, get_input());
chewing_set_addPhraseDirection(ctx, get_input());
chewing_set_selKey(ctx, selKey_define, get_input() % 11);
chewing_set_spaceAsSelection(ctx, get_input());
chewing_set_escCleanAllBuf(ctx, get_input());
chewing_set_autoShiftCur(ctx, get_input());
chewing_set_easySymbolInput(ctx, get_input());
chewing_set_phraseChoiceRearward(ctx, get_input());
}

while (1) {
/* Random value: [0, max_key) for keys, [max_key, 0xff] for
* configurations. Use a fixed range here because I don't want the
* meaning of input changed a lot frequently if we add more keys in
* the future. */
const int max_key = 192; /* arbitrary number */
int v = get_input();
if (v == EOF)
break;
assert(max_key >= (num_special_key + num_normal_key));
if (v >= max_key) {
const int typical = 2;
int handled = 1;
v = v - max_key;
if (flag_random_extra || v < typical) {
switch (v) {
/* typical configurations may be changed during input */
case 0:
chewing_set_ChiEngMode(ctx, get_input());
break;
case 1:
chewing_set_ShapeMode(ctx, get_input());
break;

/* usually not changed during input */
case 2:
chewing_set_KBType(ctx, get_input());
break;
case 3:
chewing_set_candPerPage(ctx, get_input());
break;
case 4:
chewing_set_maxChiSymbolLen(ctx, get_input());
break;
case 5:
chewing_set_addPhraseDirection(ctx, get_input());
break;
case 6:
chewing_set_selKey(ctx, selKey_define, get_input() % 11);
break;
case 7:
chewing_set_spaceAsSelection(ctx, get_input());
break;
case 8:
chewing_set_escCleanAllBuf(ctx, get_input());
break;
case 9:
chewing_set_autoShiftCur(ctx, get_input());
break;
case 10:
chewing_set_easySymbolInput(ctx, get_input());
break;
case 11:
chewing_set_phraseChoiceRearward(ctx, get_input());
break;
default:
handled = 0;
break;
}
} else {
handled = 0;
}
if (!handled)
break;
} else {
if (0 <= v && v < num_special_key) {
int key = chewing_test_special_keys[v].key;
if (flag_verbose) {
while (1) {
/* Random value: [0, max_key) for keys, [max_key, 0xff] for
* configurations. Use a fixed range here because I don't want the
* meaning of input changed a lot frequently if we add more keys in
* the future. */
const int max_key = 192; /* arbitrary number */
int v = get_input();
if (v == EOF)
break;
assert(max_key >= (num_special_key + num_normal_key));
if (v >= max_key) {
const int typical = 2;
int handled = 1;
v = v - max_key;
if (flag_random_extra || v < typical) {
switch (v) {
/* typical configurations may be changed during input */
case 0:
chewing_set_ChiEngMode(ctx, get_input());
break;
case 1:
chewing_set_ShapeMode(ctx, get_input());
break;
/* usually not changed during input */
case 2:
chewing_set_KBType(ctx, get_input());
break;
case 3:
chewing_set_candPerPage(ctx, get_input());
break;
case 4:
chewing_set_maxChiSymbolLen(ctx, get_input());
break;
case 5:
chewing_set_addPhraseDirection(ctx, get_input());
break;
case 6:
chewing_set_selKey(ctx, selKey_define, get_input() % 11);
break;
case 7:
chewing_set_spaceAsSelection(ctx, get_input());
break;
case 8:
chewing_set_escCleanAllBuf(ctx, get_input());
break;
case 9:
chewing_set_autoShiftCur(ctx, get_input());
break;
case 10:
chewing_set_easySymbolInput(ctx, get_input());
break;
case 11:
chewing_set_phraseChoiceRearward(ctx, get_input());
break;
default:
handled = 0;
break;
}
} else {
handled = 0;
}
if (!handled)
break;
} else {
if (0 <= v && v < num_special_key) {
int key = chewing_test_special_keys[v].key;
if (flag_verbose) {
printf("\r\n------------------------------\r\n");
printf("keystroke: %s\r\n", chewing_test_special_keys[v].str);
fflush(stdout);
}
type_single_keystroke(ctx, key);
fflush(stdout);
}
type_single_keystroke(ctx, key);
} else if (num_special_key <= v && v < num_special_key + num_normal_key) {
int key = normal_keys[v - num_special_key];
if (flag_verbose) {
int key = normal_keys[v - num_special_key];
if (flag_verbose) {
printf("\r\n------------------------------\r\n");
printf("keystroke: [%c]\r\n", key);
fflush(stdout);
}
type_single_keystroke(ctx, key);
} else {
break;
}
}
commit_string(ctx);
}
fflush(stdout);
}
type_single_keystroke(ctx, key);
} else {
break;
}
}
commit_string(ctx);
}
if (flag_verbose)
printf("\r\n");
chewing_delete(ctx);
chewing_delete(ctx);

#if !defined(_WIN32) && !defined(_WIN64) && !defined(_WIN32_WCE)
if (getenv("AFL_PERSISTENT"))
raise(SIGSTOP);
if (getenv("AFL_PERSISTENT"))
raise(SIGSTOP);
#endif
}
clean_userphrase();
Expand Down

0 comments on commit 85a681d

Please sign in to comment.