📄 waddatatests.java
字号:
wad = new WadData(malformedMapMeta); } catch(WadDataFormatException wdfe) { result.assertTrue(this, WadDataFormatException.BAD_RESOURCE_ERROR, wdfe.failCode(), "malformed map meta error code check"); result.assertTrue(this, "maps/greatmap.meta", wdfe.badEntryLocation(), "malformed map meta entry location check"); return; } catch(Exception e) { result.errorCaught(this, e); result.print("^^ in malformedMapMeta: " + e.toString()); return; } result.fail(this, "a malformed map meta didn't throw an exception"); } private void malformedPlaceSet(TestResult result) { WadData wad = null; try { wad = new WadData(malformedPlaceSet); } catch(WadDataFormatException wdfe) { result.assertTrue(this, WadDataFormatException.BAD_RESOURCE_ERROR, wdfe.failCode(), "malformed place set error code check"); result.assertTrue(this, "places/rad.txt", wdfe.badEntryLocation(), "malformed place set entry location check"); return; } catch(Exception e) { result.errorCaught(this, e); result.print("^^ in malformedPlaceSetMeta: " + e.toString()); return; } result.fail(this, "a malformed place set meta didn't throw an exception"); } // this is now a succeed test. the correct behaviour is now for WadData to give // back an empty JDBMMapper when there is no apcache rather than throwing an exception // in this way, with the new JDBMMapper additions to do hierarchical lookup of Beacons // we can always load the wad cache and if it has the Beacons, great, if not then don't worry // about it. private void loadApsWhenNoneExist(TestResult result) { WadData wad = null; File tempFile = null; JDBMMapper mapper = null; try { wad = new WadData(noAPCache); } catch(Exception e) { result.errorCaught(this, e); result.print("^^ in loadApsWhenNoneExist 1: " + e.toString()); return; } try { tempFile = File.createTempFile("mapper", "db"); tempFile.deleteOnExit(); mapper = wad.loadAPCacheIntoMapper(tempFile.getAbsolutePath()); } catch(Exception e) { result.errorCaught(this, e); result.print("^^ in loadApsWhenNoneExist 2: " + e.toString()); return; } result.assertTrue(this, true, mapper == null, "load missing ap cache size check"); } private void malformedDefaults(TestResult result) { WadData wad = null; try { wad = new WadData(malformedDefaults); } catch (WadDataFormatException wdfe) { result.assertTrue(this, WadDataFormatException.BAD_RESOURCE_ERROR, wdfe.failCode(), "malformed defaults error code check"); result.assertTrue(this, "defaults.txt", wdfe.badEntryLocation(), "malformed defaults entry location check"); } catch (Exception e) { result.errorCaught(this, e); result.print("^^ in malformedDefaults: " + e.toString()); } } // tests things that should succeed private void succeedTests(TestResult result) { // none of these guys should throw exceptions try { loadAPCacheAsPlaces(result); checkPlaces(result); checkMap(result); checkDefaults(result); checkDir(result); check2Origins(result); checkSave(result); // This is no longer an error, the behaviour is now to give // simply an empty JDBMMapper back in this case loadApsWhenNoneExist(result); } catch (Exception e) { result.errorCaught(this, e); } } private void checkSave(TestResult result) throws IOException, WadDataFormatException { File temp = null; try { WadData wad = new WadData(twoOrigins); temp = File.createTempFile("test", "mapwad"); //System.out.println("save wad file is " + temp.getAbsolutePath()); wad.saveWad(new FileOutputStream(temp)); wad = new WadData(temp.getAbsolutePath()); // ap cache saving isn't implemented yet -fats //_loadAPCacheAsPlaces(result, wad); _checkPlaces(result, wad); _checkMap(result, wad); _checkDefaults(result, wad); wad = null; } finally { if(temp != null) temp.delete(); } } private void loadAPCacheAsPlaces(TestResult result) throws IOException, WadDataFormatException { WadData wad = new WadData(apsMapsAndPlaces); _loadAPCacheAsPlaces(result, wad); } private void _loadAPCacheAsPlaces(TestResult result, WadData wad) throws IOException, WadDataFormatException { Hashtable apPlaces = wad.loadAPCacheAsPlaces( new ImageData(testDataDir + "apicon.gif")); // the keys are the mac addresses PlaceBacking ht = (PlaceBacking)apPlaces.get("02:04:23:ab:57:80"); result.assertTrue(this, true, ht != null, "load ap cache as places place 1 existance check"); result.assertTrueDouble(this, 47.658121282353, ht.lat, "load ap cache as places place 1 lat check"); result.assertTrueDouble(this, -122.30429284705, ht.lon, "load ap cache as places place 1 lon check"); result.assertTrue(this, "HealthTrends", ht.name, "load ap cache as places place 1 name check"); PlaceBacking uw = (PlaceBacking)apPlaces.get("00:0d:29:1a:f5:c2"); result.assertTrue(this, true, uw != null, "load ap cache as places place 2 existance check"); result.assertTrueDouble(this, 47.659275515384, uw.lat, "load ap cache as places place 2 lat check"); result.assertTrueDouble(this, -122.3082921923, uw.lon, "load ap cache as places place 2 lon check"); result.assertTrue(this, "University of Washington", uw.name, "load ap cache as places place 2 name check"); } private void checkPlaces(TestResult result) throws IOException, WadDataFormatException { WadData wad = new WadData(apsMapsAndPlaces); _checkPlaces(result, wad); } private void _checkPlaces(TestResult result, WadData wad) { // without loss of generality, i'll just check the facts for my // house, since there's nothing special about it as a place // over any other as far as the wad is concerned PlaceBacking myHouse = wad.getPlace("radplaces", "James's House"); result.assertTrue(this, true, myHouse != null, "check places house existance check"); result.assertTrueDouble(this, 47.19829, myHouse.lat, "check places house lat check"); result.assertTrueDouble(this, -122.8132, myHouse.lon, "check places house lon check"); result.assertTrue(this, "at least its still standing", myHouse.text, "check places house text check"); result.assertTrue(this, 20 * 20, myHouse.getImageResource().width * myHouse.getImageResource().height, "check places house image size check"); } private void checkMap(TestResult result) throws IOException, WadDataFormatException { WadData wad = new WadData(noPlaceIndex); _checkMap(result, wad); } private void _checkMap(TestResult result, WadData wad) { BitmapMapBacking map = (BitmapMapBacking)wad.getMap("greatmap"); result.assertTrue(this, true, map != null, "check map existance check"); result.assertTrueDouble(this, 47.6551847973423, map.getOriginLat(), "check map lat check"); result.assertTrueDouble(this, -122.318433676012, map.getOriginLon(), "check map lon check"); result.assertTrueDouble(this, 100998.13932293755577592136948456, map.getPixelsPerLat(), "check map pixels per lat check"); result.assertTrueDouble(this, 68250.274852131006688294884574341, map.getPixelsPerLon(), "check map pixels per lon check"); result.assertTrue(this, 730 * 998, map.getImageResource().width * map.getImageResource().height, "check map image size check"); } private void checkDefaults(TestResult result) throws IOException, WadDataFormatException { WadData wad = new WadData(withDefaults); _checkDefaults(result, wad); } private void _checkDefaults(TestResult result, WadData wad) { BitmapMapBacking map = (BitmapMapBacking) wad.getDefaultMap(); result.assertTrue(this, true, map != null, "checkDefaults default map existance check"); // checkHashtablechecks whether or not the map backing was // loaded correctly, so there is no need to do that here Hashtable placeSets = wad.getDefaultPlaceSets(); result.assertTrue(this, true, placeSets != null, "checkDefaults place set existance check"); result.assertTrue(this, true, placeSets.containsKey("radplaces"), "checkDefaults place set place existance check"); } private void checkDir(TestResult result) throws IOException, WadDataFormatException { WadData wad = new WadData(fromDirectory); _loadAPCacheAsPlaces(result, wad); _checkPlaces(result, wad); _checkMap(result, wad); _checkDefaults(result, wad); } private void check2Origins(TestResult result) throws IOException, WadDataFormatException { WadData wad = new WadData(twoOrigins); _loadAPCacheAsPlaces(result, wad); _checkPlaces(result, wad); _checkMap(result, wad); _checkDefaults(result, wad); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -