var SandboxedModule = require("sandboxed-module"),
  errorGpx = ['<?xml version="1.0" encoding="UTF-8" standalone="no" ?>',
    '<gpx xmlns="http://www.topografix.com/GPX/1/1"',
    'xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3" ',
    'xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" ',
    'creator="Oregon 400t" version="1.01" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ',
    'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd ',
    'http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd ',
    'http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd">',
    '<metadata>',
    '<link href="http://www.garmin.com">',
    '<text>Garmin International</text>',
    '</link>',
    '<time>2009-10-17T22:58:43Z</time>',
    '</metadata>',
    '<trk>',
    '<name>Example GPX Document</name>',
    '<trkseg>',
    '<trkpt lat="47.644548" lon="-122.326897">',
    '<ele>4.46</ele>',
    '<time>2009-10-17T18:37:26Z</time>',
    '</trkpt>',
    '<trkpt lat="47.644548" lon="-122.326897">',
    '<ele>4.94</ele>',
    '<time>2009-10-17T18:37:31Z</time>',
    '</trkpt>',
    '<trkpt lat="47.644548" lon="-122.326897">',
    '<ele>6.87</ele>',
    '<time>2009-10-17T18:37:34Z</time>',
    '</trkpt>',
    '</trkseg>',
    '</trk>',
    '</gpx>'
  ].join("\n");

module.exports = {
  setUp: function(callback) {

    //mock the file system
    this.fsMock = {};
    this.gpxParse = SandboxedModule.require("../", {
      "requires": {
        "fs": this.fsMock
      }

    });

    callback();
  },

  tearDown: function(callback) {
    // clean up
    callback();
  },

  "Should error returned when invalid gpx version": function(test) {
    this.gpxParse.parseGpx(errorGpx, function(error, result) {
      test.notEqual(error, null);
      test.equal(error.message, "version not supported");
      test.done();
    });
  },
  
  "Should error gracefully with malformed gpx" : function(test) {
    this.gpxParse.parseGpx("<gpx > <<", function(error, result) {
      test.notEqual(error, null);
      test.done();
    });
  }
};