Ejemplo n.º 1
0
extern void test_svgread_fixtures(void)
{
  size_t n = 1024;
  char buf[n];
  const char* files[] = {
    "BrBG_10.svg",
    "eyes.svg",
    "french-flag.svg",
    "gradient-pastel-blue.svg",
    "Gradients_01.svg",
    "lemon-lime.svg",
    "mad-ids.svg",
    "punaisa_01.svg",
    "radial-eclipse.svg",
    "red-green-blue.svg",
    "subtle.svg"
  };
  size_t i, nfile = sizeof(files)/sizeof(char*);

  for (i=0 ; i<nfile ; i++)
    {
      svg_list_t* svglist;

      CU_TEST_FATAL( (svglist = svg_list_new()) != NULL ); 
      CU_TEST_FATAL( fixture(buf, n, "svg", files[i]) < n );
      CU_ASSERT( svg_read(buf, svglist) == 0 );
      CU_ASSERT( svg_list_size(svglist) > 0 );
      svg_list_destroy(svglist);
    }
}
static void test_data(const char * uriStr,
                        lwm2m_media_type_t format,
                        lwm2m_data_t * tlvP,
                        int size,
                        const char * id)
{
    lwm2m_uri_t uri;
    uint8_t * buffer;
    int length;
    
    if (uriStr != NULL)
    {
        lwm2m_stringToUri(uriStr, strlen(uriStr), &uri);
    }

    length = lwm2m_data_serialize((uriStr != NULL) ? &uri : NULL, size, tlvP, &format, &buffer);
    if (length <= 0)
    {
        printf("Serialize lwm2m_data_t %s to %s failed.\n", id, format==LWM2M_CONTENT_JSON?"JSON":"TLV");
        //dump_data_t(stdout, size, tlvP, 0);
        CU_TEST_FATAL(CU_FALSE);
    }
    else
    {
        //printf("\n\nSerialize lwm2m_data_t %s:\n", id);
        //output_buffer(stdout, buffer, length, 0);
        lwm2m_free(buffer);
    }
}
Ejemplo n.º 3
0
extern void test_cptwrite_fixtures(void)
{
  const char* files[] = {
    "blue.cpt",
    "Exxon88.cpt",
    "GMT_gebco.cpt",
    "GMT_haxby.cpt",
    "Onion_Rings.cpt",
    "pakistan.cpt",
    "RdBu_10.cpt",
    "subtle.cpt",
    "test.cpt",
    "tpsfhm.cpt"
  };
  size_t i, nfile = sizeof(files)/sizeof(char*);

  for (i=0 ; i<nfile ; i++)
    {
      char *path = tmpnam(NULL);
      cpt_t* cpt;

      CU_TEST_FATAL( (cpt = load_cpt_fixture(files[i])) != NULL );
      CU_ASSERT( access(path, F_OK) != 0 );
      CU_ASSERT( cpt_write(path, cpt) == 0 );
      CU_ASSERT( access(path, F_OK) == 0 );
  
      unlink(path);
      cpt_destroy(cpt);
    }
}
Ejemplo n.º 4
0
extern void test_povwrite_2stop(void)
{
  pov_t *pov;
  CU_TEST_FATAL( (pov = build_pov()) != NULL);

  char *path;
  CU_TEST_FATAL( (path = tmpnam(NULL)) != NULL );

  CU_ASSERT( access(path, F_OK)   != 0 );
  CU_ASSERT( pov_write(path, pov) == 0 );
  CU_ASSERT( access(path, F_OK)   == 0 );

  unlink(path);

  pov_destroy(pov);
}
Ejemplo n.º 5
0
extern void test_gptwrite_write(void)
{
  gpt_t* gpt;
  CU_TEST_FATAL( (gpt = build_gpt()) != NULL );

  char *path;
  CU_TEST_FATAL( (path = tmpnam(NULL)) != NULL );

  CU_ASSERT( access(path, F_OK)   != 0 );
  CU_ASSERT( gpt_write(path, gpt) == 0 );
  CU_ASSERT( access(path, F_OK)   == 0 );

  unlink(path);

  gpt_destroy(gpt);
}
Ejemplo n.º 6
0
extern void test_sao_create(void)
{
  sao_t *sao;

  CU_TEST_FATAL( (sao = sao_new()) != NULL);

  sao_destroy(sao);
}
Ejemplo n.º 7
0
extern void test_svgread_nofile(void)
{
  svg_list_t* svglist;

  CU_TEST_FATAL( (svglist = svg_list_new()) != NULL ); 
  CU_ASSERT( svg_read("/tmp/no-such-file", svglist) != 0 );
  CU_ASSERT( svg_list_size(svglist) == 0 );
  svg_list_destroy(svglist);
}
Ejemplo n.º 8
0
extern void test_cptwrite_nosuchdir(void)
{
  cpt_t* cpt;

  CU_TEST_FATAL( (cpt = load_cpt_fixture("blue.cpt")) != NULL );
  CU_ASSERT(cpt_write("/no/such/directory/exists", cpt) != 0);

  cpt_destroy(cpt);
}
Ejemplo n.º 9
0
static void test_data_and_compare(const char * uriStr,
                        lwm2m_media_type_t format,
                        lwm2m_data_t * tlvP,
                        int size,
                        const char * id,
                        uint8_t* original_buffer,
                        size_t original_length)
{
    lwm2m_uri_t uri;
    uint8_t * buffer;
    int length;
    
    if (uriStr != NULL)
    {
        lwm2m_stringToUri(uriStr, strlen(uriStr), &uri);
    }

    length = lwm2m_data_serialize((uriStr != NULL) ? &uri : NULL, size, tlvP, &format, &buffer);
    if (length <= 0)
    {
        printf("(Serialize lwm2m_data_t %s to TLV failed.)\t", id);
        //dump_data_t(stdout, size, tlvP, 0);
        CU_TEST_FATAL(CU_FALSE);
        return;
    }

    if (format != LWM2M_CONTENT_JSON)
    {
        CU_ASSERT_EQUAL(original_length, length);

        if ((original_length != (size_t)length) ||
            (memcmp(original_buffer, buffer, length) != 0))
        {
            printf("Comparing buffer after parse/serialize failed for %s:\n", id);
            output_buffer(stdout, buffer, length, 0);
            printf("\ninstead of:\n");
            output_buffer(stdout, original_buffer, original_length, 0);
            CU_TEST_FATAL(CU_FALSE);
        }
    }

    lwm2m_free(buffer);
}
Ejemplo n.º 10
0
extern void test_pov_create(void)
{
  pov_t *pov;

  CU_TEST_FATAL( (pov = pov_new()) != NULL);

  CU_ASSERT( pov->n == 0 );
  CU_ASSERT( pov->stop == NULL );
  CU_ASSERT( pov->name[0] == '\0' );

  pov_destroy(pov);
}
Ejemplo n.º 11
0
extern void test_pov_alloc_stops(void)
{
  pov_t *pov;

  CU_TEST_FATAL( (pov = pov_new()) != NULL);

  CU_ASSERT( pov_stops_alloc(pov, 5) == 0 );
  CU_ASSERT( pov->n == 5 );
  CU_ASSERT( pov->stop != NULL );

  pov_destroy(pov);
}
Ejemplo n.º 12
0
extern void test_pov_set_name_complex(void)
{
  pov_t *pov;
  int changed = 0;

  CU_TEST_FATAL( (pov = pov_new()) != NULL);

  CU_ASSERT( pov_set_name(pov, "bip bip b*p", &changed) == 0 );
  CU_ASSERT( changed == 3 );
  CU_ASSERT( strcmp(pov->name, "bip_bip_b_p") == 0 );

  pov_destroy(pov);
}
Ejemplo n.º 13
0
extern void test_pov_set_name_simple(void)
{
  pov_t *pov;
  int changed = 0;

  CU_TEST_FATAL( (pov = pov_new()) != NULL);

  CU_ASSERT( pov_set_name(pov, "frooble", &changed) == 0 );
  CU_ASSERT( changed == 0 );
  CU_ASSERT( strcmp(pov->name, "frooble") == 0 );

  pov_destroy(pov);
}
Ejemplo n.º 14
0
extern void test_gptwrite_nosuchdir(void)
{
  gpt_t* gpt;
  CU_TEST_FATAL( (gpt = build_gpt()) != NULL );

  const char path[] = "/no/such/directory";

  CU_ASSERT( access(path, F_OK)   != 0 );
  CU_ASSERT( gpt_write(path, gpt) != 0 );
  CU_ASSERT( access(path, F_OK)   != 0 );

  gpt_destroy(gpt);
}
Ejemplo n.º 15
0
extern void test_gpt_simple(void)
{
  gpt_t *gpt;

  CU_TEST_FATAL( (gpt = gpt_new()) != NULL );
  CU_ASSERT( gpt->n == 0 );
  CU_ASSERT( gpt->stop == NULL );
  CU_ASSERT( gpt_stops_alloc(gpt, 5) == 0 );
  CU_ASSERT( gpt->stop != NULL );
  CU_ASSERT( gpt->n == 5 );

  gpt_destroy(gpt);
}
Ejemplo n.º 16
0
extern void test_sao_push(void)
{
  sao_t *sao;

  CU_TEST_FATAL( (sao = sao_new()) != NULL);
  CU_ASSERT( sao_red_push(sao,   0, 0.0) == 0 );
  CU_ASSERT( sao_red_push(sao,   1, 0.0) == 0 );
  CU_ASSERT( sao_green_push(sao, 0, 0.0) == 0 );
  CU_ASSERT( sao_green_push(sao, 1, 0.5) == 0 );
  CU_ASSERT( sao_blue_push(sao,  0, 0.0) == 0 );
  CU_ASSERT( sao_blue_push(sao,  1, 1.0) == 0 );

  sao_destroy(sao);
}
Ejemplo n.º 17
0
extern void test_sao_each(void)
{
  sao_t *sao;

  CU_TEST_FATAL( (sao = build_sao()) != NULL);

  double sum = 0.0;

  CU_ASSERT( sao_eachred(sao, (stop_fn_t*)sum_stop_fn, 
			 (void*)&sum) == 0 );
  CU_ASSERT( sum == 1.0 );

  sao_destroy(sao);
}
Ejemplo n.º 18
0
/**
 * Questa funzione legge e scrive un'agenda effettuando controlli 
 * necessari a verificare che il file sia stato formattato correttamente 
 * e che la conversione sia corretta
 *
 * \param fagenda nome del file agenda
 * \param ftest nome del file in cui verranno scritte le voci covertite
 */
void run_testagenda (char *fagenda, char* ftest) {
    char record[LRECORD+2], pbu[MAXNTEST][LRECORD+1], pb[LRECORD+1];
    evento_t* ev[MAXNTEST];
    FILE *fsa;

    /* prossima posizione libera nell'array di eventi */
    int i=0;
    int l,k;

    /*
     * Apertura del file agenda
     */
    fsa = fopen(fagenda, "r");
    CU_ASSERT_PTR_NOT_NULL_FATAL(fsa); 


    /*
     * Lettura e caricamento eventi nell'array
     */
    while(fgets(record,LRECORD + 2,fsa) != NULL) {
	 CU_ASSERT_EQUAL_FATAL(record[LRECORD], '\n');
	 record[LRECORD]='\0';
	 strncpy(pbu[i],record,LRECORD+1);
	 CU_TEST_FATAL(i < MAXNTEST);
	 ev[i]=convertiRecord(record);
	 CU_ASSERT_NOT_EQUAL_FATAL(ev[i],NULL);
	 i++;
	 
    }
    fclose(fsa);
    printf("lette %d voci\n",i);

    /*
     * Trasformazione voci nel formato stringa
     */
    for ( l=0; l<i; l++ ) {
	int ret;
	/* printf("confron ta la mia %s, che viene da %s,%s,%s, con    la sua %s\n", pb, ev[l]->data, ev[l]->utente, ev[l]->descrizione ,pbu[l]); */
	convertiEvento(ev[l],pb);
	/* printf("confronta la mia %s, che viene da %s con la sua %s\n", pb, ev[l]->data ,pbu[l]); */
	ret=strncmp(pbu[l],pb,LRECORD+1);
	CU_ASSERT_EQUAL_FATAL(ret, 0);
    }

    /*
     * Verifica funzione di matchPattern
     */
    
    for (k=0;pattern[k]!=NULL; k++) {
	int cont = 0;
	for(l=0;l<i;l++) {
	    cont+=matchPattern(pattern[k],ev[l]);
/*	    printf(" pattern %s : %d occurrences \n",pattern[k],cont);*/
	}
	 CU_ASSERT_EQUAL_FATAL(cont, npatternmatch[k]); 
    }

    /*
     * Verifica funzione di matchData
     */
    for (k=0;date[k]!=NULL; k++) {
	int cont = 0;
	for(l=0;l<i;l++) {
	    cont+=matchData(date[k],ev[l]);
	}
	/* printf("cont: %d  nmatch %d\n", cont, nmatch[k]); */
	CU_ASSERT_EQUAL_FATAL(cont, nmatch[k]); 
    }

    /* 
     * Test di creazione di una nuova agenda 
     */

    fsa=fopen(ftest,"w");
    CU_ASSERT_PTR_NOT_NULL_FATAL(fsa); 
    for ( l=0; l<i; l++ ) {
	convertiEvento(ev[l],pb);
        CU_ASSERT_NOT_EQUAL_FATAL(fputs(pb,fsa), EOF);
	fputs("\n",fsa);
    }
    fclose(fsa);
    
}
Ejemplo n.º 19
0
void test1() {
    int i, j, k, p, max = 3000;
    bool flag = false;
    Chromosome_l chr = NULL;
    void **chrs;
    ChrEntity_l ent;
    int chrLen = 0;
    char *message = allocate(sizeof (char) * 10000, __FILE__, __LINE__);
    int rFrom, rTo, rLen, errors = 0;
    FILE *gtfFile = fopen("resources/test.gtf", "r");
    FILE *samFile = fopen("resources/test.sam", "r");
    CU_TEST_FATAL(gtfFile != NULL);
    CU_TEST_FATAL(samFile != NULL);

    printf("\nReading chromosomes from GTF file\n");
    Chromosome_f *chrFactory = NewChromosomeFactory(gtfFile);
    CU_TEST_FATAL(chrFactory != NULL);

    BtreeRecordsToArray(&(chrFactory->chrArray), &(chrFactory->chrArrayLen), chrFactory->chromosomes);
    CU_TEST_FATAL(chrFactory->chrArray != NULL);
    CU_TEST_FATAL(chrFactory->chrArrayLen == 1);
    printf("Chromosomes %d\n", chrFactory->chrArrayLen);

    printf("Parsing sam file\n");
    SAM_f *samFactory = NewSAMFactory();
    CU_TEST_FATAL(samFactory != NULL);
    
    Reads_f *readsFactory = NewReadsFactory(samFactory, chrFactory, stderr);
    CU_TEST_FATAL(readsFactory != NULL);
    readsFactory->processReadFromSAM(readsFactory, samFile, 1);
    printf("Reads %d parsed\n", readsFactory->total);
    CU_TEST_FATAL(readsFactory->total == 12);
    CU_TEST_FATAL(readsFactory->errors == 1);

    chrs = chrFactory->chrArray;
    for (i = 0; i < chrFactory->chrArrayLen; i++) {
        for (j = 0; j < ((Chromosome_l) chrs[i])->genesLen; j++) {
            if (((Chromosome_l) chrs[i])->genesSorted[j].count != 0) {
                for (k = 0; k < ((Chromosome_l) chrs[i])->genesSorted[j].gene->chrEntityLen; k++) {
                    ent = ((Chromosome_l) chrs[i])->genesSorted[j].gene->chrEntity[k];
                    printf("%s\t%s\t%s\t%s\t%d\t%d\t%d\n",
                            ((Chromosome_l) chrs[i])->genesSorted[j].gene->geneId,
                            ((Chromosome_l) chrs[i])->genesSorted[j].gene->transcriptId,
                            ((Chromosome_l) chrs[i])->name,
                            ent->type->type,
                            k + 1,
                            ent->length,
                            ent->count);
                    if (strcmp(((Chromosome_l) chrs[i])->genesSorted[j].gene->geneId, "GEN1") == 0) {                        
                        if (strcmp(((Chromosome_l) chrs[i])->genesSorted[j].gene->transcriptId, "TRANS1") == 0) {
                            CU_TEST_FATAL(((Chromosome_l) chrs[i])->genesSorted[j].gene->length == 2845);
                            CU_TEST_FATAL(((Chromosome_l) chrs[i])->genesSorted[j].gene->chrEntityLen == 7);
                            switch (k) {
                                case 0: // EXON
                                    CU_TEST_FATAL(ent->count == 4);
                                    CU_TEST_FATAL(ent->length == 353);
                                    break;
                                case 1: // INTRON
                                    CU_TEST_FATAL(ent->count == 2);
                                    CU_TEST_FATAL(ent->length == 385);
                                    break;
                                case 2: // EXON
                                    CU_TEST_FATAL(ent->count == 2);
                                    CU_TEST_FATAL(ent->length == 108);
                                    break;
                                case 3: // INTRON
                                    CU_TEST_FATAL(ent->count == 0);
                                    CU_TEST_FATAL(ent->length == 499);
                                    break;
                                case 4: // EXON
                                    CU_TEST_FATAL(ent->count == 3);
                                    CU_TEST_FATAL(ent->length == 1188);
                                    break;
                                case 5: // INTRON
                                    CU_TEST_FATAL(ent->count == 1);
                                    CU_TEST_FATAL(ent->length == 199);
                                    break;
                                case 6: // EXON
                                    CU_TEST_FATAL(ent->count == 2);
                                    CU_TEST_FATAL(ent->length == 110);
                                    break;
                            }
                        }
                        if (strcmp(((Chromosome_l) chrs[i])->genesSorted[j].gene->transcriptId, "TRANS2") == 0) {
                            CU_TEST_FATAL(((Chromosome_l) chrs[i])->genesSorted[j].gene->length == 2106);
                            CU_TEST_FATAL(((Chromosome_l) chrs[i])->genesSorted[j].gene->chrEntityLen == 5);
                            switch (k) {
                                case 0: // EXON
                                    CU_TEST_FATAL(ent->count == 2);
                                    CU_TEST_FATAL(ent->length == 108);
                                    break;
                                case 1: // INTRON
                                    CU_TEST_FATAL(ent->count == 0);
                                    CU_TEST_FATAL(ent->length == 499);
                                    break;
                                case 2: // EXON
                                    CU_TEST_FATAL(ent->count == 3);
                                    CU_TEST_FATAL(ent->length == 1188);
                                    break;
                                case 3: // INTRON
                                    CU_TEST_FATAL(ent->count == 1);
                                    CU_TEST_FATAL(ent->length == 199);
                                    break;
                                case 4: // EXON
                                    CU_TEST_FATAL(ent->count == 2);
                                    CU_TEST_FATAL(ent->length == 110);
                                    break;
                            }
                        }
                        if (strcmp(((Chromosome_l) chrs[i])->genesSorted[j].gene->transcriptId, "TRANS3") == 0) {
                            CU_TEST_FATAL(((Chromosome_l) chrs[i])->genesSorted[j].gene->length == 1796);
                            CU_TEST_FATAL(((Chromosome_l) chrs[i])->genesSorted[j].gene->chrEntityLen == 3);
                            switch (k) {
                                case 0: // EXON
                                    CU_TEST_FATAL(ent->count == 2);
                                    CU_TEST_FATAL(ent->length == 108);
                                    break;
                                case 1: // INTRON
                                    CU_TEST_FATAL(ent->count == 0);
                                    CU_TEST_FATAL(ent->length == 499);
                                    break;
                                case 2: // EXON
                                    CU_TEST_FATAL(ent->count == 3);
                                    CU_TEST_FATAL(ent->length == 1188);
                                    break;
                            }
                        }
                    }
                }
            }
        }
    }

    CU_TEST_FATAL(readsFactory->intergenic == 2);
    printf("Total reads: %10d, intergenic reads: %10d, errors: %5d (testing errors, it should be 1)\n\n", readsFactory->total, readsFactory->intergenic, readsFactory->errors);

    free(message);
    FreeSAMFactory(&samFactory);
    FreeChromosomeFactory(&chrFactory);
    fclose(gtfFile);
    fclose(samFile);
}
static void test_data_and_compare(const char * uriStr,
                        lwm2m_media_type_t format,
                        lwm2m_data_t * tlvP,
                        int size,
                        const char * id,
                        const uint8_t* original_buffer,
                        size_t original_length)
{
    lwm2m_uri_t uri;
    uint8_t * buffer;
    size_t length;
    
    if (uriStr != NULL)
    {
        lwm2m_stringToUri(uriStr, strlen(uriStr), &uri);
    }

    length = lwm2m_data_serialize((uriStr != NULL) ? &uri : NULL, size, tlvP, &format, &buffer);
    if (length <= 0)
    {
        printf("Serialize lwm2m_data_t %s to TLV failed.\n", id);
        //dump_data_t(stdout, size, tlvP, 0);
        CU_TEST_FATAL(CU_FALSE);
        return;
    }

    char* original_compact;
    if (format == LWM2M_CONTENT_JSON) {
        // Remove white spaces from original_buffer if not in a "" context
        // so that the original input string can be compared to the serialized data output,
        // which does not contain additional white spaces.
        original_compact= malloc(original_length);
        char* s = (char*)original_buffer; char* d = original_compact;
        uint8_t in_string_context = 0;
        do
        {
            *d = *s;
            // Toggle "in_string_context" flag if " has been detected and if " is not escaped
            if (*d == '"' && *(d-1) != '\\')
                in_string_context = !in_string_context;
            if(in_string_context || !isspace(*d))
                d++;

        } while(*s++ != 0);
        original_length = strlen(original_compact);
    } else {
        // No JSON format? Just use the original buffer
        original_compact = (char*)original_buffer;
    }

    CU_ASSERT_EQUAL(original_length, length);

    if ((original_length != length) ||
            (memcmp(original_compact, buffer, length) != 0))
    {
        printf("Comparing buffer after parse/serialize failed for %s:\n", id);
        output_buffer(stdout, buffer, length, 0);
        printf("\ninstead of:\n");
        output_buffer(stdout, (uint8_t*)original_compact, original_length, 0);
        CU_TEST_FATAL(CU_FALSE);
    }

    // Free the compact representation of the original buffer
    if (original_compact != (char*)original_buffer)
        free(original_compact);

    lwm2m_free(buffer);
}