示例#1
0
int main(int argc, char* argv[]) {
    fprintf(stderr, "KwPbar for C test suite\n");
    fprintf(stderr, "\nTesting printing...\n");
    int t1 = pbar(0, 2);  // 0
    int t2 = pbar(1, 2);  // 0
    int t3 = pbar(2, 2);  // 0
    fprintf(stderr, "\ndone.\n");
    fprintf(stderr, "\nTesting erasing...\n");
    int t4 = pbar(2, 3);  // 0
    erase_pbar();
    fprintf(stderr, "done.\n");
    fprintf(stderr, "\nTesting expected failures...\n");
    int t5 = pbar(1, 0);  // 1
    int t6 = pbar(2, 1);  // 2
    int t7 = pbar(-2, 1); // 2
    fprintf(stderr, "done.\n");
    int score = t1 + t2 + t3 + t4 + t5 + t6 + t7;
    int expected = 5;
    if (score == expected) {
        fprintf(stderr, "\nPASS (error score %d/%d)\n", score, expected);
    } else {
        fprintf(stderr, "\nFAIL (error score %d/%d)\n", score, expected);
    }
    return (expected - score);
}
示例#2
0
int main(int argc, char* argv[]) {
    int i = 0;
    char time_arg = 1;
    char expected_argc = 2;
    char stay_mode = 0;
    strcpy(PROGNAME, argv[0]);
    if (argc == 1 ||
        strcmp(argv[1], "-h") == 0 ||
        strcmp(argv[1], "--help") == 0) {
        usage(1);
        return 2;
    } else if (strcmp(argv[1], "-v") == 0 ||
               strcmp(argv[1], "--version") == 0) {
        fprintf(stderr, "%s %s\n", argv[0], VERSION);
        return 2;
    }

    if (strcmp(argv[1], "-s") == 0 ||
        strcmp(argv[1], "--stay") == 0) {
        stay_mode = 1;
        time_arg = 2;
        expected_argc = 3;
    }

    if (argc != expected_argc) {
        usage(1);
        return 2;
    }

    // we do use timespec, but we manage them ourselves
    // (we do not pass tmsec to nanosleep or the like)
    struct timespec tmsec = input_to_timespec(argv[time_arg]);
    struct nruns nr = timespec_to_nruns(tmsec);
#if defined(DEBUG) || defined(DRYMODE)
    fprintf(stderr, "abuser wants %s\n", print_timespec(tmsec));
    fprintf(stderr, "nruns: %lld runs, %s, final %s\n", nr.runs,
            print_timespec(nr.runlength), print_timespec(nr.final));
#endif

#ifndef DRYMODE
    int errno;
    errno = pbar(0, 1);
    if (errno != 0) return errno;
    for (i = 0; i < nr.runs; i++) {
        nanosleep(&nr.runlength, &nr.runlength);
        errno = pbar(i, nr.runs + 1);
        if (errno != 0) return errno;
    }
    nanosleep(&nr.final, &nr.final);
    errno = pbar(1, 1);
    if (errno != 0) return errno;
    if (stay_mode) {
        // stay mode, progressbar stays on the screen
        printf("\n");
    } else {
        // progressbar disappears at the end
        erase_pbar();
    }
#endif

    return 0;
}