int main (int argc, char *argv[])
{
#ifndef OMIT_ICONV	/* only if ICONV is supported */
    void * converter;
    char *test_str1;
    int err;

    asprintf(&test_str1, "Hello World");
    gaiaConvertCharset(&test_str1, "ASCII", "UTF-8");
    if (strcmp(test_str1, "Hello World") != 0) {
	fprintf(stderr, "bad ASCII to UTF-8 conversion: %s\n", test_str1);
	free(test_str1);
	return -1;
    }
    free(test_str1);

#if 0
    /* TODO: this will cause a buffer overflow */
    asprintf(&test_str1, "Hello World");
    gaiaConvertCharset(&test_str1, "ASCII", "UTF-16LE");
    if (memcmp(test_str1, "H\0e\0l\0l\0o\0 \0W\0o\0r\0l\0d\0\0\0", 24) != 0) {
	fprintf(stderr, "bad ASCII to UTF-16LE conversion\n");
	free(test_str1);
	return -2;
    }
    free(test_str1);
#endif

    converter = gaiaCreateUTF8Converter ("CP1252");
    if (! converter) {
	fprintf(stderr, "null UTF8 converter\n");
	return -3;
    }
    
    test_str1 = gaiaConvertToUTF8(converter, "Hello world", strlen("Hello world"), &err);
    if (memcmp("Hello world", test_str1, strlen("Hello world") + 1) != 0) {
	fprintf(stderr, "bad conversion to UTF8: %s\n", test_str1);
	free(test_str1);
	return -4;
    }
    free(test_str1);
    
    gaiaFreeUTF8Converter (converter);
    converter = NULL;
    /* test null converter */
    gaiaFreeUTF8Converter (converter);
    
    test_str1 = gaiaConvertToUTF8(converter, "Hello world", strlen("Hello world"), &err);
    if ((test_str1 != NULL) || (err != 1)) {
	fprintf(stderr, "unexpected null converter result: %s, %i\n", test_str1, err);
	return -5;
    }

    /* there is no sane way to test this automatically */
    printf("Local codeset: %s\n", gaiaGetLocaleCharset() );
#endif	/* end ICONV conditional */

    return 0;
}
Example #2
0
GAIAGEO_DECLARE void
gaiaTextReaderDestroy (gaiaTextReaderPtr reader)
{
/* destroying the main TXT-Reader */
    int col;
    struct vrttxt_row_block *blk;
    struct vrttxt_row_block *blkN;
    if (reader)
      {
	  blk = reader->first;
	  while (blk)
	    {
		/* destroying the row offset Blocks */
		blkN = blk->next;
		vrttxt_block_destroy (blk);
		blk = blkN;
	    }
	  /* freeing the input buffers */
	  if (reader->line_buffer)
	      free (reader->line_buffer);
	  if (reader->field_buffer)
	      free (reader->field_buffer);
	  /* freeing the row offsets array */
	  if (reader->rows)
	      free (reader->rows);
	  /* closing the input file */
	  fclose (reader->text_file);
	  for (col = 0; col < VRTTXT_FIELDS_MAX; col++)
	    {
		/* destroying column headers */
		if (reader->columns[col].name != NULL)
		    free (reader->columns[col].name);
	    }
	  gaiaFreeUTF8Converter (reader->toUtf8);
	  free (reader);
      }
}