Skip to content
Snippets Groups Projects
Commit e36d13d7 authored by Matthew Hall's avatar Matthew Hall
Browse files

Add test to check decompression works

parent 31690371
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" renderorder="right-down" width="100" height="100" tilewidth="32" tileheight="32" backgroundcolor="#ff00ff" nextobjectid="5">
<tileset firstgid="1" name="tilesheet" tilewidth="32" tileheight="32">
<image source="tilesheet.png" width="448" height="192"/>
<tile id="1">
<properties>
<property name="a tile property" value="123"/>
</properties>
</tile>
</tileset>
<layer name="Tile Layer 1" width="100" height="100">
<properties>
<property name="prop1" value="12"/>
<property name="prop2" value="some text"/>
</properties>
<data encoding="base64" compression="gzip">
H4sIAAAAAAAAA+3XMQrDMAwFUF0hJwglc9L7364NjUG4dulQu8t7IMiQSR8heYuIrapbpxhvuWq/6njWvVNymaNkUs/JqZURc5wZLOm7rpKLGRlvjVfP107t8T47jJH7vTcqZ3KETEYrfa/7XO/6vEtkMk7u87kbcq9LJjV5jFPfUOWube30CFnM0Lpr6/dGyaE3M/zep1zy210e47Tu2FYuW3gTzvDtLrAz5ujt7d5/zPUpG3n837fzw3zyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgewAvf+EvQJwAAA==
</data>
</layer>
<objectgroup name="Object group">
<object id="1" x="14" y="9" width="285" height="135"/>
<object id="2" x="329" y="217" width="102" height="109">
<ellipse/>
</object>
<object id="3" x="314" y="376">
<polyline points="0,0 -111,-63 -203,27 -205,-130 -78,-150 -6,-6"/>
</object>
<object id="4" x="479" y="84">
<polygon points="0,0 139,128 -55,64 -37,-49 159,47 138,126"/>
</object>
</objectgroup>
</map>
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" renderorder="right-down" width="100" height="100" tilewidth="32" tileheight="32" backgroundcolor="#ff00ff" nextobjectid="5">
<tileset firstgid="1" name="tilesheet" tilewidth="32" tileheight="32">
<image source="tilesheet.png" width="448" height="192"/>
<tile id="1">
<properties>
<property name="a tile property" value="123"/>
</properties>
</tile>
</tileset>
<layer name="Tile Layer 1" width="100" height="100">
<properties>
<property name="prop1" value="12"/>
<property name="prop2" value="some text"/>
</properties>
<data encoding="base64" compression="zlib">
eJzt1zEKwzAMBVBdIScIJXPS+9+uDY1BuHbpULvLeyDIkEkfIXmLiK2qW6cYb7lqv+p41r1TcpmjZFLPyamVEXOcGSzpu66SixkZb41Xz9dO7fE+O4yR+703KmdyhExGK32v+1zv+rxLZDJO7vO5G3KvSyY1eYxT31Dlrm3t9AhZzNC6a+v3RsmhNzP83qdc8ttdHuO07thWLlt4E87w7S6wM+bo7e3ef8z1KRt5/N+388N88gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIHsArPIXTA==
</data>
</layer>
<objectgroup name="Object group">
<object id="1" x="14" y="9" width="285" height="135"/>
<object id="2" x="329" y="217" width="102" height="109">
<ellipse/>
</object>
<object id="3" x="314" y="376">
<polyline points="0,0 -111,-63 -203,27 -205,-130 -78,-150 -6,-6"/>
</object>
<object id="4" x="479" y="84">
<polygon points="0,0 139,128 -55,64 -37,-49 159,47 138,126"/>
</object>
</objectgroup>
</map>
This diff is collapsed.
......@@ -15,6 +15,7 @@ use serialize::base64::{FromBase64, FromBase64Error};
use flate2::read::{ZlibDecoder, GzDecoder};
use std::num::from_str_radix;
#[derive(Debug)]
enum ParseTileError {
ColourError,
OrientationError,
......@@ -76,7 +77,7 @@ macro_rules! parse_tag {
}
}
#[derive(Debug)]
#[derive(Debug, PartialEq, Eq)]
pub struct Colour {
pub red: u8,
pub green: u8,
......@@ -150,7 +151,7 @@ fn parse_properties<B: Buffer>(parser: &mut EventReader<B>) -> Result<Properties
}
/// All Tiled files will be parsed i32o this. Holds all the layers and tilesets
#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub struct Map {
pub version: String,
pub orientation: Orientation,
......@@ -221,7 +222,7 @@ impl Map {
}
}
#[derive(Debug)]
#[derive(Debug, PartialEq, Eq)]
pub enum Orientation {
Orthogonal,
Isometric,
......@@ -242,7 +243,7 @@ impl FromStr for Orientation {
}
/// A tileset, usually the tilesheet image.
#[derive(Debug)]
#[derive(Debug, PartialEq, Eq)]
pub struct Tileset {
/// The GID of the first tile stored
pub first_gid: u32,
......@@ -283,7 +284,7 @@ impl Tileset {
}
}
#[derive(Debug)]
#[derive(Debug, PartialEq, Eq)]
pub struct Image {
/// The filepath of the image
pub source: String,
......@@ -307,7 +308,7 @@ impl Image {
}
}
#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub struct Layer {
pub name: String,
pub opacity: f32,
......@@ -342,7 +343,7 @@ impl Layer {
}
}
#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub struct ObjectGroup {
pub name: String,
pub opacity: f32,
......@@ -373,7 +374,7 @@ impl ObjectGroup {
}
}
#[derive(Debug)]
#[derive(Debug, PartialEq, Eq)]
pub enum Object {
Rect { x: i32, y: i32, width: u32, height: u32, visible: bool},
Ellipse { x: i32, y: i32, width: u32, height: u32, visible: bool},
......
extern crate tiled;
use std::old_io::{File, BufferedReader};
use tiled::{Map, TiledError, parse};
fn read_from_file(p: &Path) -> Result<Map, TiledError> {
let file = File::open(p).unwrap();
let reader = BufferedReader::new(file);
return parse(reader);
}
#[test]
fn test_gzip_and_zlib_encoded_and_raw_are_the_same() {
let z = read_from_file(&Path::new("assets/tiled_base64_zlib.tmx")).unwrap();
let g = read_from_file(&Path::new("assets/tiled_base64_gzip.tmx")).unwrap();
let r = read_from_file(&Path::new("assets/tiled_base64.tmx")).unwrap();
assert_eq!(z, g);
assert_eq!(z, r);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment