|
| 1 | +package com.spatialdev.osm.model; |
| 2 | + |
| 3 | + |
| 4 | +import android.test.InstrumentationTestCase; |
| 5 | + |
| 6 | +import org.apache.commons.codec.binary.Hex; |
| 7 | +import org.apache.commons.codec.digest.DigestUtils; |
| 8 | + |
| 9 | +import java.io.InputStream; |
| 10 | +import java.util.List; |
| 11 | + |
| 12 | +public class ChecksumTest extends InstrumentationTestCase { |
| 13 | + |
| 14 | + private OSMWay way; |
| 15 | + private OSMWay way2; |
| 16 | + private OSMNode donutHappy; |
| 17 | + |
| 18 | + public void setUp() throws Exception { |
| 19 | + super.setUp(); |
| 20 | + InputStream in = getInstrumentation().getTargetContext().getResources().getAssets().open("test/osm/checksum_way.osm"); |
| 21 | + OSMDataSet ds = OSMXmlParser.parseFromInputStream(in); |
| 22 | + way = ds.getClosedWays().get(0); |
| 23 | + |
| 24 | + InputStream in2 = getInstrumentation().getTargetContext().getResources().getAssets().open("test/osm/checksum_way2.osm"); |
| 25 | + OSMDataSet ds2 = OSMXmlParser.parseFromInputStream(in2); |
| 26 | + way2 = ds2.getClosedWays().get(0); |
| 27 | + |
| 28 | + InputStream in3 = getInstrumentation().getTargetContext().getResources().getAssets().open("test/osm/donut_happy.osm"); |
| 29 | + OSMDataSet ds3 = OSMXmlParser.parseFromInputStream(in3); |
| 30 | + donutHappy = ds3.getStandaloneNodes().get(0); |
| 31 | + } |
| 32 | + |
| 33 | + public void tearDown() throws Exception { |
| 34 | + super.tearDown(); |
| 35 | + } |
| 36 | + |
| 37 | + public void testSha1OnAString() throws Exception { |
| 38 | + String testStr = "test"; |
| 39 | + String sha1 = new String(Hex.encodeHex(DigestUtils.sha1(testStr))); |
| 40 | + assertEquals("a94a8fe5ccb19ba61c4c0873d391e987982fbbd3", sha1); |
| 41 | + } |
| 42 | + |
| 43 | + public void testWayTagsAsSortedKVString() throws Exception { |
| 44 | + String str = way.tagsAsSortedKVString().toString(); |
| 45 | + assertEquals("buildingcommercialbuilding:conditiongoodbuilding:levels1building:materialconcretenameJava the Hut", str); |
| 46 | + } |
| 47 | + |
| 48 | + public void testWayChecksum() throws Exception { |
| 49 | + String checksum = way.checksum(); |
| 50 | + assertEquals("add90109a0ca34d12d28292ccd05c588d2220f0a", checksum); |
| 51 | + } |
| 52 | + |
| 53 | + public void testWayChecksum2() throws Exception { |
| 54 | + String checksum = way2.checksum(); |
| 55 | + assertEquals("3854296ef0b8fc4810454dd5d8de79dc59f7f007", checksum); |
| 56 | + } |
| 57 | + |
| 58 | + public void testNodesInWayChecksums() throws Exception { |
| 59 | + List<OSMNode> nodes = way.getNodes(); |
| 60 | + for (OSMNode n : nodes) { |
| 61 | + long id = n.getId(); |
| 62 | + if (id == 3969314187L) { |
| 63 | + assertEquals("6f3b2e85e05dbdc496f9250931693f7a3e427807", n.checksum()); |
| 64 | + } else if (id == 3969314188L) { |
| 65 | + assertEquals("e52eb00f4e028a8010e32a9cfca788273f49a675", n.checksum()); |
| 66 | + } else if (id == 3969314189L) { |
| 67 | + assertEquals("3f7514c1b2ca88dfc53fdd7daecc0851bfeba081", n.checksum()); |
| 68 | + } else if (id == 3969314190L) { |
| 69 | + assertEquals("c3010e77a9f5d322bfd0081c607dfc7109b86ba9", n.checksum()); |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + public void testPreWayChecksum() throws Exception { |
| 75 | + String preChecksum = way.preChecksum(); |
| 76 | + assertEquals("buildingcommercialbuilding:conditiongoodbuilding:levels1building:materialconcretenameJava the Hut6f3b2e85e05dbdc496f9250931693f7a3e427807c3010e77a9f5d322bfd0081c607dfc7109b86ba93f7514c1b2ca88dfc53fdd7daecc0851bfeba081e52eb00f4e028a8010e32a9cfca788273f49a6756f3b2e85e05dbdc496f9250931693f7a3e427807", preChecksum); |
| 77 | + } |
| 78 | + |
| 79 | + public void testDonutHappyPreChecksum() throws Exception { |
| 80 | + String preChecksum = donutHappy.preChecksum(); |
| 81 | + assertEquals("addr:citySacramentoaddr:housenumber5049-Daddr:postcode95841addr:stateCAaddr:streetCollege Oak Dr.amenitycafénameDonut Happyshopbakery38.65838277039187-121.3510830389408", preChecksum); |
| 82 | + } |
| 83 | + |
| 84 | + public void testDonutHappyChecksum() throws Exception { |
| 85 | + String checksum = donutHappy.checksum(); |
| 86 | + assertEquals("27b1bf1412ab7f02f0991e37d783f92d83ed1d52", checksum); |
| 87 | + } |
| 88 | + |
| 89 | + public void testAccentEigu() throws Exception { |
| 90 | + String str = "café"; |
| 91 | + String sha1 = new String(Hex.encodeHex(DigestUtils.sha1(str))); |
| 92 | + assertEquals("f424452a9673918c6f09b0cdd35b20be8e6ae7d7", sha1); |
| 93 | + } |
| 94 | +} |
0 commit comments