void
TestVariadicMacros_run(TestBatch *batch)
{
    char buf[10];
    chaz_bool_t really_has_var_macs = false;

#if defined(HAS_ISO_VARIADIC_MACROS) || defined(HAS_GNUC_VARIADIC_MACROS)
  #ifdef HAS_VARIADIC_MACROS
    PASS(batch, "#defines agree");
  #else 
    FAIL(batch, 0, "#defines agree");
  #endif
#else
    SKIP_REMAINING(batch, "No variadic macro support");
#endif


#ifdef HAS_ISO_VARIADIC_MACROS
 #define ISO_TEST(buffer, fmt, ...) \
    sprintf(buffer, fmt, __VA_ARGS__)
    really_has_var_macs = true;
    ISO_TEST(buf, "%s", "iso");
    TEST_STR_EQ(batch, buf, "iso", "ISO variadic macros work");
#else
    SKIP(batch, "No ISO variadic macros");
#endif

#ifdef HAS_GNUC_VARIADIC_MACROS
 #define GNU_TEST(buffer, fmt, args...) \
    sprintf(buffer, fmt, ##args )
    really_has_var_macs = true;
    GNU_TEST(buf, "%s", "gnu");
    TEST_STR_EQ(batch, buf, "gnu", "GNUC variadic macros work");
#else
    SKIP(batch, "No GNUC variadic macros");
#endif

    TEST_TRUE(batch, really_has_var_macs, "either ISO or GNUC");
}
static void
S_run_tests(void) {
    char buf[10];
    int really_has_var_macs = false;

#if defined(HAS_ISO_VARIADIC_MACROS) || defined(HAS_GNUC_VARIADIC_MACROS)
  #ifdef HAS_VARIADIC_MACROS
    PASS("#defines agree");
  #else
    FAIL(0, "#defines agree");
  #endif
#else
    SKIP_REMAINING("No variadic macro support");
    return;
#endif


#ifdef HAS_ISO_VARIADIC_MACROS
 #define ISO_TEST(buffer, fmt, ...) \
    sprintf(buffer, fmt, __VA_ARGS__)
    really_has_var_macs = true;
    ISO_TEST(buf, "%s", "iso");
    STR_EQ(buf, "iso", "ISO variadic macros work");
#else
    SKIP("No ISO variadic macros");
#endif

#ifdef HAS_GNUC_VARIADIC_MACROS
 #define GNU_TEST(buffer, fmt, args...) \
    sprintf(buffer, fmt, ##args )
    really_has_var_macs = true;
    GNU_TEST(buf, "%s", "gnu");
    STR_EQ(buf, "gnu", "GNUC variadic macros work");
#else
    SKIP("No GNUC variadic macros");
#endif

    OK(really_has_var_macs, "either ISO or GNUC");
}
Exemple #3
0
static void
S_run_tests(void) {
    FILE *fh;
    off64_t offset;
    int check_val;
    char check_char;
    int fd;

    /* A little over 4 GB, and a little over 2 GB. */
    off64_t gb4_plus = ((off64_t)0x7FFFFFFF << 1) + 100;
    off64_t gb2_plus = (off64_t)0x7FFFFFFF + 200;

    LONG_EQ(sizeof(off64_t), 8, "off64_t type has 8 bytes");

#ifndef HAS_64BIT_STDIO
    SKIP_REMAINING("No stdio large file support");
    return;
#endif
#ifndef STAT_TESTS_ENABLED
    SKIP_REMAINING("Need stat with st_size and st_blocks");
    return;
#else
    /* Check for sparse files. */
    if (!S_check_sparse_files()) {
        SKIP_REMAINING("Can't verify large file support "
                       "without sparse files");
        return;
    }
    if (!S_can_create_big_files()) {
        SKIP_REMAINING("Unsafe to create 5GB sparse files on this system");
        return;
    }

    fh = fopen64("_charm_large_file_test", "w+");
    if (fh == NULL) {
        SKIP_REMAINING("Failed to open file");
        return;
    }

    check_val = fseeko64(fh, gb4_plus, SEEK_SET);
    LONG_EQ(check_val, 0, "fseeko64 above 4 GB");

    offset = ftello64(fh);
    OK((offset == gb4_plus), "ftello64 above 4 GB");

    check_val = fprintf(fh, "X");
    LONG_EQ(check_val, 1, "print above 4 GB");

    check_val = fseeko64(fh, gb2_plus, SEEK_SET);
    LONG_EQ(check_val, 0, "fseeko64 above 2 GB");

    offset = ftello64(fh);
    OK((offset == gb2_plus), "ftello64 above 2 GB");

    check_val = fseeko64(fh, -1, SEEK_END);
    LONG_EQ(check_val, 0, "seek to near end");

    check_char = fgetc(fh);
    LONG_EQ(check_char, 'X', "read value after multiple seeks");

    check_val = fclose(fh);
    LONG_EQ(check_val, 0, "fclose succeeds after all that");

    /* Truncate, just in case the call to remove fails. */
    fh = fopen64("_charm_large_file_test", "w+");
    if (fh != NULL) {
        fclose(fh);
    }
    remove("_charm_large_file_test");

#ifndef HAS_64BIT_LSEEK
    SKIP_REMAINING("No 64-bit lseek");
    return;
#else
    fd = open("_charm_large_file_test",
              O_RDWR | O_CREAT | LARGEFILE_OPEN_FLAG, 0666);
    if (fd == -1) {
        FAIL("open failed");
        SKIP_REMAINING("open failed");
        return;
    }

    offset = lseek64(fd, gb4_plus, SEEK_SET);
    OK(offset == gb4_plus, "lseek64 above 4 GB");

    offset = lseek64(fd, 0, SEEK_CUR);
    OK(offset == gb4_plus, "lseek64 in place above 4 GB");

    check_val = write(fd, "X", 1);
    LONG_EQ(check_val, 1, "write() above 4 GB");

    offset = lseek64(fd, gb2_plus, SEEK_SET);
    OK(offset == gb2_plus, "lseek64 above 2 GB");

    offset = lseek64(fd, 0, SEEK_CUR);
    OK((offset == gb2_plus), "lseek64 in place above 2 GB");

    offset = lseek64(fd, -1, SEEK_END);
    OK(offset == gb4_plus, "seek to near end");

    check_val = read(fd, &check_char, 1);
    LONG_EQ(check_val, 1, "read() after multiple lseek64 calls");
    LONG_EQ(check_char, 'X',
            "read() correct data after multiple lseek64 calls");
#ifdef HAS_64BIT_PREAD
    check_char = 0;
    check_val = pread64(fd, &check_char, 1, gb4_plus);
    LONG_EQ(check_val, 1, "pread64");
    LONG_EQ(check_char, 'X', "pread64() correct data");
#else
    SKIP("no pread64");
    SKIP("no pread64");
#endif

    check_val = close(fd);
    LONG_EQ(check_val, 0, "close succeeds after all that");
#endif

    /* Truncate, just in case the call to remove fails. */
    fh = fopen64("_charm_large_file_test", "w+");
    if (fh != NULL) {
        fclose(fh);
    }
    remove("_charm_large_file_test");
#endif /* STAT_TESTS_ENABLED */
}