Ejemplo n.º 1
0
fdata readpseudofile(const char *path, off_t extra)
{
	fdata mydata;
	size_t fsize = count_file_bytes(path);
	FILE *fpi = dofopen(path, "r");
	mydata.from = docalloc(fsize + extra, 1, "readpseudofile()");
	dofread(path, mydata.from, fsize, fpi);
	mydata.to = mydata.from + (fsize + extra);
	dofclose(fpi);
	return mydata;
} // readpseudofile()
Ejemplo n.º 2
0
/* MAIN */
int
main( int argc, char **argv )
{
    size_t  results[] = {4255, 142803, 46838, 0}, i = 0,
            output = 0;
    const size_t b = 5;
    const char *count_bytes_files[] = {
            "/data/orig_breaks.txt", "/data/spawner_output.txt",
            "/data/zh_romance_of_three_kingdoms.txt", ""},
            *source_dir = getenv("SOURCE");
    char    buffer[BUFSIZ], tinybuffer[b], *locale = "root", *encoding = "UTF-8";
    OChar   obuffer[BUFSIZ], otinybuffer[b];
    struct  stat sts;
    time_t  now;
    FILE    *f;
    init_oly(argv[0], TEST_PKGDATADIR, encoding, locale);
    if (source_dir == NULL)
    {
        fprintf(stderr, "requires SOURCE environment variable, supplied by runtest. Exiting...\n");
        exit(EXIT_FAILURE);
    }
    plan(16);
    diag("----- Testing oly_timestamp function. -----");
    time(&now);
    is_double(((double)( now*1000)), oly_timestamp(), 1000.0, "Two times should be close enough.");

    diag("----- Testing count_file_bytes function. -----");
    for (i = 0; (results[i] != 0); i++) {
        strcpy(buffer, source_dir);
        strcat(buffer, count_bytes_files[i]);
        if (stat(buffer, &sts) == -1 && errno == ENOENT)
        {
            printf ("The file %s doesn't exist...\n", buffer);
        }
        f = fopen(buffer, "r");
        assert( count_file_bytes( f, &output ) == OLY_OKAY ) ;
        is_int(results[i], output, "File: %s", count_bytes_files[i]);
        fclose(f);
    }
    
    diag("----- Testing get_default_locale and get_default_encoding function. -----");
    is_unicode_string( u"root", 
            get_default_locale(), "For this test, default locale should be root.");
    is_unicode_string( u"UTF-8", 
            get_default_encoding(), "For this test, default encoding should be UTF-8.");
    
    diag("----- Testing char_default_locale and char_default_encoding function. -----");
    is_string( "root", 
            char_default_locale(), "For this test, default locale should be root.");
    is_string( "UTF-8", 
            char_default_encoding(), "For this test, default encoding should be UTF-8.");
    
    diag("----- ostr_to_cstr and cstr_to_ostr -----");
    is_unicode_string( u"Lorum ipsum etc...", 
            cstr_to_ostr( obuffer, BUFSIZ, "Lorum ipsum etc..."), 
            "Char to ochar with space, BUFSIZ = %i", BUFSIZ);
    is_unicode_string( u"Loru", 
            cstr_to_ostr( otinybuffer, b, "Lorum ipsum etc..." ), 
            "Char to ochar with tiny buffer of %i characters.", (int)b );
    is_unicode_string( u"", 
            cstr_to_ostr( otinybuffer, b, "" ), 
            "Char to ochar With empty string" );
    is_unicode_string( u"", 
            cstr_to_ostr( otinybuffer, b, NULL ), 
            "Char to ochar from null" );
    is_string( "Back the other way!", 
            ostr_to_cstr( buffer, BUFSIZ, u"Back the other way!" ), 
            "OChar to char, BUFSIZ = %i", BUFSIZ );
    is_string( "five", 
            ostr_to_cstr( tinybuffer, b, u"five characters is all that fits." ), 
            "OChar to char, buffer of %i OChars", (int)b );
    is_string( "", 
            ostr_to_cstr( tinybuffer, b, NULL ), 
            "Char to ochar a NULL from string." );
    is_string( "", 
            ostr_to_cstr( tinybuffer, b, u"" ), 
            "Char to ochar with an empty string." );


    exit(EXIT_SUCCESS);
}