示例#1
0
/* Setup/teardown for this suite */
static int
init_suite(void)
{
	char *xmlstr = file_to_str(xmlfile);
	schema = pc_schema_from_xml(xmlstr);
	pcfree(xmlstr);
	if ( !schema ) return 1;

	xmlstr = file_to_str(simplexmlfile);
	simpleschema = pc_schema_from_xml(xmlstr);
	pcfree(xmlstr);
	if ( !simpleschema ) return 1;

	xmlstr = file_to_str(simplexmlfile_nointensity);
	simpleschema_nointensity = pc_schema_from_xml(xmlstr);
	pcfree(xmlstr);
	if ( !simpleschema_nointensity ) return 1;

	xmlstr = file_to_str(lasxmlfile);
	lasschema = pc_schema_from_xml(xmlstr);
	pcfree(xmlstr);
	if ( !lasschema ) return 1;

	xmlstr = file_to_str(simplelazxmlfile);
	simplelazschema = pc_schema_from_xml(xmlstr);
	pcfree(xmlstr);
	if ( !simplelazschema ) return 1;

	return 0;
}
示例#2
0
/* Setup/teardown for this suite */
static int
init_suite(void)
{
	char *xmlstr;

	xmlstr = file_to_str(xmlfile);
	schema = pc_schema_from_xml(xmlstr);
	pcfree(xmlstr);
	if ( !schema ) return 1;

	xmlstr = file_to_str(xmlfile_xy);
	schema_xy = pc_schema_from_xml(xmlstr);
	pcfree(xmlstr);
	if ( !schema_xy ) return 1;

	xmlstr = file_to_str(xmlfile_xyz);
	schema_xyz = pc_schema_from_xml(xmlstr);
	pcfree(xmlstr);
	if ( !schema_xyz ) return 1;

	xmlstr = file_to_str(xmlfile_xym);
	schema_xym = pc_schema_from_xml(xmlstr);
	pcfree(xmlstr);
	if ( !schema_xym ) return 1;

	xmlstr = file_to_str(xmlfile_xyzm);
	schema_xyzm = pc_schema_from_xml(xmlstr);
	pcfree(xmlstr);
	if ( !schema_xyzm ) return 1;
	return 0;
}
示例#3
0
/* Setup/teardown for this suite */
static int
init_suite(void)
{
	char *xmlstr = file_to_str(simplexmlfile);
	simpleschema = pc_schema_from_xml(xmlstr);
	pcfree(xmlstr);
	if ( !simpleschema ) return 1;

	xmlstr = file_to_str(multipledimxmlfile);
	multipledimschema = pc_schema_from_xml(xmlstr);
	pcfree(xmlstr);
	if ( !multipledimschema ) return 1;

	return 0;
}
示例#4
0
/* Setup/teardown for this suite */
static int
init_suite(void)
{
	char *xmlstr = file_to_str(xmlfile);
	int rv = pc_schema_from_xml(xmlstr, &schema);
	pcfree(xmlstr);
	return rv == PC_FAILURE ? -1 : 0;
}
示例#5
0
static void
test_schema_clone(void)
{
    int i;
    PCSCHEMA *myschema;
    PCSCHEMA *clone = pc_schema_clone(schema);
    hashtable *hash, *chash;
    char *xmlstr;
    CU_ASSERT_EQUAL(clone->pcid, schema->pcid);
    CU_ASSERT_EQUAL(clone->ndims, schema->ndims);
    CU_ASSERT_EQUAL(clone->size, schema->size);
    CU_ASSERT_EQUAL(clone->srid, schema->srid);
    CU_ASSERT_EQUAL(clone->x_position, schema->x_position);
    CU_ASSERT_EQUAL(clone->y_position, schema->y_position);
    CU_ASSERT_EQUAL(clone->compression, schema->compression);
    CU_ASSERT(clone->dims != schema->dims); /* deep clone */
    CU_ASSERT(clone->namehash != schema->namehash); /* deep clone */
    hash = schema->namehash;
    chash = clone->namehash;
    CU_ASSERT_EQUAL(chash->tablelength, hash->tablelength);
    CU_ASSERT_EQUAL(chash->entrycount, hash->entrycount);
    CU_ASSERT_EQUAL(chash->loadlimit, hash->loadlimit);
    CU_ASSERT_EQUAL(chash->primeindex, hash->primeindex);
    CU_ASSERT_EQUAL(chash->hashfn, hash->hashfn);
    CU_ASSERT_EQUAL(chash->eqfn, hash->eqfn);
    CU_ASSERT(chash->table != hash->table); /* deep clone */
    for (i=0; i<schema->ndims; ++i) {
      PCDIMENSION *dim = schema->dims[i];
      PCDIMENSION *cdim = clone->dims[i];
      CU_ASSERT(dim != cdim); /* deep clone */
      CU_ASSERT_STRING_EQUAL(cdim->name, dim->name);
      CU_ASSERT_STRING_EQUAL(cdim->description, dim->description);
      CU_ASSERT_EQUAL(cdim->position, dim->position);
      CU_ASSERT_EQUAL(cdim->size, dim->size);
      CU_ASSERT_EQUAL(cdim->byteoffset, dim->byteoffset);
      CU_ASSERT_EQUAL(cdim->interpretation, dim->interpretation);
      CU_ASSERT_EQUAL(cdim->scale, dim->scale);
      CU_ASSERT_EQUAL(cdim->offset, dim->offset);
      CU_ASSERT_EQUAL(cdim->active, dim->active);
      /* hash table is correctly setup */
      CU_ASSERT_EQUAL(cdim, hashtable_search(clone->namehash, dim->name) );
    }

    pc_schema_free(clone);

    /* See https://github.com/pgpointcloud/pointcloud/issues/66 */
	  xmlstr = "<pc:PointCloudSchema xmlns:pc='x'><pc:dimension><pc:position>1</pc:position></pc:dimension></pc:PointCloudSchema>";
    i = pc_schema_from_xml(xmlstr, &myschema);
	  CU_ASSERT_EQUAL(i, PC_SUCCESS);
    clone = pc_schema_clone(myschema);
    CU_ASSERT_EQUAL(clone->ndims, myschema->ndims);
    CU_ASSERT_EQUAL(clone->dims[0]->name, NULL);
    CU_ASSERT_EQUAL(clone->dims[0]->description, NULL);
    pc_schema_free(myschema);
    pc_schema_free(clone);
}
示例#6
0
/* Setup/teardown for this suite */
static int
init_suite(void)
{
	char *xmlstr = file_to_str(xmlfile);
	int rv = pc_schema_from_xml(xmlstr, &schema);
	pcfree(xmlstr);
	if ( rv == PC_FAILURE ) return 1;

	xmlstr = file_to_str(simplexmlfile);
	rv = pc_schema_from_xml(xmlstr, &simpleschema);
	pcfree(xmlstr);
	if ( rv == PC_FAILURE ) return 1;

	xmlstr = file_to_str(lasxmlfile);
	rv = pc_schema_from_xml(xmlstr, &lasschema);
	pcfree(xmlstr);
	if ( rv == PC_FAILURE ) return 1;

	return 0;
}
示例#7
0
static void
test_schema_compression_lazperf(void)
{
	PCSCHEMA *myschema = NULL;
	char *myxmlfile = "data/simple-schema-laz.xml";
	char *xmlstr = file_to_str(myxmlfile);
	myschema = pc_schema_from_xml(xmlstr);

	CU_ASSERT_PTR_NOT_NULL(myschema);
	int compression = myschema->compression;
	CU_ASSERT_EQUAL(compression, PC_LAZPERF);

	pc_schema_free(myschema);
	pcfree(xmlstr);
}
示例#8
0
static void
test_schema_from_xml()
{
    static PCSCHEMA *myschema = NULL;
	char *xmlstr = file_to_str(xmlfile);
	int rv = pc_schema_from_xml(xmlstr, &myschema);
	pcfree(xmlstr);

	// char *schemastr = pc_schema_to_json(schema);
	// printf("ndims %d\n", schema->ndims);
	// printf("name0 %s\n", schema->dims[0]->name);
	// printf("%s\n", schemastr);

	CU_ASSERT(myschema != NULL);
    pc_schema_free(myschema);
}
示例#9
0
static void
test_schema_is_valid()
{
	static PCSCHEMA *myschema = NULL;
	char *xmlstr;
	int rv;

	// See https://github.com/pgpointcloud/pointcloud/issues/28
	xmlstr = "<pc:PointCloudSchema xmlns:pc='x'><pc:dimension>1</pc:dimension></pc:PointCloudSchema>";
	rv = pc_schema_from_xml(xmlstr, &myschema);
	CU_ASSERT_EQUAL(rv, PC_SUCCESS);

  cu_error_msg_reset();
  rv = pc_schema_is_valid(myschema);
	CU_ASSERT_EQUAL(rv, PC_FAILURE);

  pc_schema_free(myschema);
}
示例#10
0
Datum pcschema_is_valid(PG_FUNCTION_ARGS)
{
	bool valid;
	text *xml = PG_GETARG_TEXT_P(0);
	char *xmlstr = text_to_cstring(xml);
	PCSCHEMA *schema;
	int err = pc_schema_from_xml(xmlstr, &schema);
	pfree(xmlstr);

	if ( ! err )
	{
		PG_RETURN_BOOL(FALSE);
	}

	valid = pc_schema_is_valid(schema);
	pc_schema_free(schema);
	PG_RETURN_BOOL(valid);
}
示例#11
0
PCSCHEMA *
pc_schema_from_pcid_uncached(uint32 pcid)
{
	char sql[256];
	char *xml, *xml_spi, *srid_spi;
	int err, srid;
	size_t size;
	PCSCHEMA *schema;

	if (SPI_OK_CONNECT != SPI_connect ())
	{
		SPI_finish();
		elog(ERROR, "pc_schema_from_pcid: could not connect to SPI manager");
		return NULL;
	}

	sprintf(sql, "select %s, %s from %s where pcid = %d", 
	              POINTCLOUD_FORMATS_XML, POINTCLOUD_FORMATS_SRID, POINTCLOUD_FORMATS, pcid);
	err = SPI_exec(sql, 1);

	if ( err < 0 )
	{
		SPI_finish();
		elog(ERROR, "pc_schema_from_pcid: error (%d) executing query: %s", err, sql);
		return NULL;
	} 

	/* No entry in POINTCLOUD_FORMATS */
	if (SPI_processed <= 0)
	{
		SPI_finish();
		elog(ERROR, "no entry in \"%s\" for pcid = %d", POINTCLOUD_FORMATS, pcid);
		return NULL;
	}

	/* Result  */
	xml_spi = SPI_getvalue(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1);
	srid_spi = SPI_getvalue(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 2);	

	/* NULL result */
	if ( ! ( xml_spi && srid_spi ) )
	{
		SPI_finish();
		elog(ERROR, "unable to read row from \"%s\" for pcid = %d", POINTCLOUD_FORMATS, pcid);
		return NULL;
	}

	/* Copy result to upper executor context */
	size = strlen(xml_spi) + 1;
	xml = SPI_palloc(size);
	memcpy(xml, xml_spi, size);

	/* Parse the SRID string into the function stack */
	srid = atoi(srid_spi);

	/* Disconnect from SPI, losing all our SPI-allocated memory now... */
	SPI_finish();

	/* Build the schema object */
	err = pc_schema_from_xml(xml, &schema);
	
	if ( ! err )
	{
        ereport(ERROR,
            (errcode(ERRCODE_NOT_AN_XML_DOCUMENT),
             errmsg("unable to parse XML for pcid = %d in \"%s\"", pcid, POINTCLOUD_FORMATS)));
	}
	
	schema->pcid = pcid;
	schema->srid = srid;
	
	return schema;
}