Esempio n. 1
0
GhtErr
ght_node_free(GhtNode *node)
{
	int i;
	const int deep = 1;
	assert(node != NULL);

	if ( node->attributes )
		GHT_TRY(ght_attribute_free(node->attributes));

	if ( node->children )
		GHT_TRY(ght_nodelist_free_deep(node->children));

	if ( node->hash )
		GHT_TRY(ght_hash_free(node->hash));

	ght_free(node);
	return GHT_OK;
}
Esempio n. 2
0
static void
test_geohash_inout()
{
    /* ght_hash_from_coordinate(const GhtCoordinate *coord,
                                unsigned int resolution,
                                GhtHash **rhash) */

    /* ght_area_from_hash(const GhtHash *hash, GhtArea *area) */

    GhtHash *hash;
    GhtCoordinate coord;
    GhtErr err;
    GhtArea area;

    coord.x = 1.0;
    coord.y = 1.0;
    err = ght_hash_from_coordinate(&coord, 20, &hash);
    CU_ASSERT_EQUAL(err, GHT_OK);
    CU_ASSERT_STRING_EQUAL(hash, "s00twy01mtw037ms06g7");
    err = ght_area_from_hash(hash, &area);
    CU_ASSERT_EQUAL(err, GHT_OK);
    CU_ASSERT_DOUBLE_EQUAL(coord.x, (area.x.min + area.x.max)/2.0, 0.0000000001);
    CU_ASSERT_DOUBLE_EQUAL(coord.y, (area.y.min + area.y.max)/2.0, 0.0000000001);
    ght_hash_free(hash);

    coord.x = 0.0;
    coord.y = 0.0;
    err = ght_hash_from_coordinate(&coord, 20, &hash);
    CU_ASSERT_EQUAL(err, GHT_OK);
    CU_ASSERT_STRING_EQUAL(hash, "s0000000000000000000");
    err = ght_area_from_hash(hash, &area);
    CU_ASSERT_EQUAL(err, GHT_OK);
    CU_ASSERT_DOUBLE_EQUAL(coord.x, (area.x.min + area.x.max)/2.0, 0.0000000001);
    CU_ASSERT_DOUBLE_EQUAL(coord.y, (area.y.min + area.y.max)/2.0, 0.0000000001);
    ght_hash_free(hash);

    coord.x = 90.0;
    coord.y = 0.0;
    err = ght_hash_from_coordinate(&coord, 20, &hash);
    CU_ASSERT_EQUAL(err, GHT_OK);
    CU_ASSERT_STRING_EQUAL(hash, "w0000000000000000000");
    err = ght_area_from_hash(hash, &area);
    CU_ASSERT_EQUAL(err, GHT_OK);
    CU_ASSERT_DOUBLE_EQUAL(coord.x, (area.x.min + area.x.max)/2.0, 0.0000000001);
    CU_ASSERT_DOUBLE_EQUAL(coord.y, (area.y.min + area.y.max)/2.0, 0.0000000001);
    ght_hash_free(hash);

    coord.x = 90.0;
    coord.y = 45.0;
    err = ght_hash_from_coordinate(&coord, 20, &hash);
    CU_ASSERT_EQUAL(err, GHT_OK);
    CU_ASSERT_STRING_EQUAL(hash, "y0000000000000000000");
    err = ght_area_from_hash(hash, &area);
    CU_ASSERT_EQUAL(err, GHT_OK);
    CU_ASSERT_DOUBLE_EQUAL(coord.x, (area.x.min + area.x.max)/2.0, 0.0000000001);
    CU_ASSERT_DOUBLE_EQUAL(coord.y, (area.y.min + area.y.max)/2.0, 0.0000000001);
    ght_hash_free(hash);

    coord.x = 180.0;
    coord.y = 45.0;
    err = ght_hash_from_coordinate(&coord, 20, &hash);
    CU_ASSERT_EQUAL(err, GHT_OK);
    CU_ASSERT_STRING_EQUAL(hash, "zbpbpbpbpbpbpbpbpbpb");
    err = ght_area_from_hash(hash, &area);
    CU_ASSERT_EQUAL(err, GHT_OK);
    CU_ASSERT_DOUBLE_EQUAL(coord.x, (area.x.min + area.x.max)/2.0, 0.0000000001);
    CU_ASSERT_DOUBLE_EQUAL(coord.y, (area.y.min + area.y.max)/2.0, 0.0000000001);
    ght_hash_free(hash);

    coord.x = -180.0;
    coord.y = 45.0;
    err = ght_hash_from_coordinate(&coord, 20, &hash);
    CU_ASSERT_EQUAL(err, GHT_OK);
    CU_ASSERT_STRING_EQUAL(hash, "b0000000000000000000");
    err = ght_area_from_hash(hash, &area);
    CU_ASSERT_EQUAL(err, GHT_OK);
    CU_ASSERT_DOUBLE_EQUAL(coord.x, (area.x.min + area.x.max)/2.0, 0.0000000001);
    CU_ASSERT_DOUBLE_EQUAL(coord.y, (area.y.min + area.y.max)/2.0, 0.0000000001);
    ght_hash_free(hash);

    coord.x = 179.9999;
    coord.y = 45.0;
    err = ght_hash_from_coordinate(&coord, 9, &hash);
    CU_ASSERT_EQUAL(err, GHT_OK);
    CU_ASSERT_STRING_EQUAL(hash, "zbpbpbpbj");
    err = ght_area_from_hash(hash, &area);
    // printf("\n%s\n", hash);
    CU_ASSERT_EQUAL(err, GHT_OK);
    CU_ASSERT_DOUBLE_EQUAL(coord.x, (area.x.min + area.x.max)/2.0, 0.0001);
    CU_ASSERT_DOUBLE_EQUAL(coord.y, (area.y.min + area.y.max)/2.0, 0.0001);
    ght_hash_free(hash);
}