Ejemplo n.º 1
0
static int
test_read_from_filename(const char* filename, 
                        const char* test_string, size_t test_string_len,
                        const unsigned int expected_len,
                        const unsigned int expected_len2)
{
  raptor_iostream *iostr=NULL;
  char buffer[READ_BUFFER_SIZE];
  unsigned long count;
  int rc=0;
  const char* const label="read iostream from filename";

#ifdef RAPTOR_DEBUG
  fprintf(stderr, "%s: Testing %s '%s'\n", program, label, filename);
#endif

  iostr=raptor_new_iostream_from_filename(filename);
  if(!iostr) {
    fprintf(stderr, "%s: Failed to create %s '%s'\n", program, label, filename);
    rc=1;
    goto tidy;
  }
  
  count=raptor_iostream_read_bytes(iostr, buffer, 1, test_string_len);
  if(count != expected_len) {
    fprintf(stderr, "%s: %s read %d bytes, expected %d\n", program, label,
            (int)count, (int)expected_len);
    rc=1;
    goto tidy;
  }

  count=raptor_iostream_read_bytes(iostr, buffer, 1, test_string_len);
  if(count != expected_len2) {
    fprintf(stderr, "%s: %s read %d bytes, expected %d\n", program, label,
            (int)count, (int)expected_len2);
    rc=1;
    goto tidy;
  }

  if(!raptor_iostream_read_eof(iostr)) {
    fprintf(stderr, "%s: %s not EOF as expected\n", program, label);
    rc=1;
    goto tidy;
  }

  if(strncmp(buffer, test_string, test_string_len)) {
    fprintf(stderr, "%s: %s returned '%s' expected '%s'\n", program, label,
            buffer, test_string);
    rc=1;
  }

  tidy:
  if(iostr)
    raptor_free_iostream(iostr);

  if(rc)
    fprintf(stderr, "%s: FAILED Testing %s\n", program, label);
    
  return rc;
}
Ejemplo n.º 2
0
static void
rasqal_rowsource_sparql_xml_process(rasqal_rowsource_sparql_xml_context* con)
{
  if(raptor_sequence_size(con->results_sequence) && con->variables_count > 0)
    return;

  /* do some parsing - need some results */
  while(!raptor_iostream_read_eof(con->iostr)) {
    size_t read_len;
    
    read_len = raptor_iostream_read_bytes((char*)con->buffer, 1,
                                          FILE_READ_BUF_SIZE,
                                          con->iostr);
    if(read_len > 0) {
      RASQAL_DEBUG2("processing %d bytes\n", (int)read_len);
      raptor_sax2_parse_chunk(con->sax2, con->buffer, read_len, 0);
      con->locator.byte += read_len;
    }
    
    if(read_len < FILE_READ_BUF_SIZE) {
      /* finished */
      raptor_sax2_parse_chunk(con->sax2, NULL, 0, 1);
      break;
    }
    
    /* end with variables sequence done AND at least one row */
    if(con->variables_count > 0 &&
       raptor_sequence_size(con->results_sequence) > 0)
      break;
  }
  
}
Ejemplo n.º 3
0
static int
test_read_from_sink(raptor_world *world, size_t read_len, size_t expected_len)
{
  raptor_iostream *iostr = NULL;
  char buffer[READ_BUFFER_SIZE];
  unsigned long count;
  int rc = 0;
  const char* const label="read iostream from sink";
  
#if defined(RAPTOR_DEBUG) && RAPTOR_DEBUG > 1
  fprintf(stderr, "%s: Testing %s\n", program, label);
#endif
  expected_len = 0;
  iostr = raptor_new_iostream_from_sink(world);
  if(!iostr) {
    fprintf(stderr, "%s: Failed to create %s\n", program, label);
    rc = 1;
    goto tidy;
  }

  count = raptor_iostream_read_bytes(buffer, 1, read_len, iostr);
  if(count != expected_len) {
    fprintf(stderr, "%s: %s read %d bytes, expected %d\n", program, label,
            (int)count, (int)expected_len);
    rc = 1;
  }

  if(!raptor_iostream_read_eof(iostr)) {
    fprintf(stderr, "%s: %s not EOF as expected\n", program, label);
    rc = 1;
  }

  tidy:
  if(iostr)
    raptor_free_iostream(iostr);

  if(rc)
    fprintf(stderr, "%s: FAILED Testing %s\n", program, label);
    
  return rc;
}