Newer
Older
adjustgpx-gui / src / test / java / osm / jp / gpx / ElementMapTRKSEGTest.java
  1. package osm.jp.gpx;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.text.ParseException;
  6. import java.util.Date;
  7.  
  8. import javax.xml.parsers.ParserConfigurationException;
  9.  
  10. import org.junit.Test;
  11. import org.junit.experimental.theories.DataPoints;
  12. import org.junit.experimental.theories.Theories;
  13. import org.junit.experimental.theories.Theory;
  14. import org.junit.runner.RunWith;
  15. import org.xml.sax.SAXException;
  16. import static org.junit.Assert.*;
  17. import static org.hamcrest.CoreMatchers.*;
  18.  
  19. public class ElementMapTRKSEGTest {
  20.  
  21. @RunWith(Theories.class)
  22. public static class 各種GPXファイルを食わせる {
  23. static class Fixture {
  24. String gpxSourcePath; // GPXファイル(オリジナル)
  25. int segCount; // GPXファイルに含まれるTRKSEGノードの数
  26.  
  27. public Fixture(String gpxSourcePath, int segCount) {
  28. this.gpxSourcePath = gpxSourcePath;
  29. this.segCount = segCount;
  30. }
  31.  
  32. @Override
  33. public String toString() {
  34. String msg = "テストパターン : \n";
  35. msg += "\tgpxSourcePath = "+ gpxSourcePath +"\n";
  36. msg += "\tsegCount = "+ segCount;
  37. return msg;
  38. }
  39. }
  40.  
  41. @DataPoints
  42. public static Fixture[] datas = {
  43. new Fixture("target/test-classes/gpx/20170517.gpx", 1),
  44. new Fixture("target/test-classes/gpx/20170518.gpx", 1),
  45. new Fixture("target/test-classes/gpx/2019-09-07 16.17.12 Day.gpx", 1),
  46. new Fixture("target/test-classes/gpx/2019-12-29 06.50.19 Day.gpx", 1),
  47. new Fixture("target/test-classes/gpx/2020-02-29 13.35.58 Day.gpx", 1),
  48. //new Fixture("target/test-classes/gpx/muiltiTRK.GarminColorado.gpx.xml", 3),
  49. //new Fixture("target/test-classes/gpx/muiltiTRKSEG.GarminColorado.gpx.xml", 3),
  50. //new Fixture("target/test-classes/gpx/muiltiTRKSEG.noNameSpace.gpx.xml", 3),
  51. //new Fixture("target/test-classes/gpx/multiTRKSEG.eTrex_20J.gpx.xml", 3),
  52. //new Fixture("target/test-classes/gpx/multiTRKSEGreverse.eTrex_20J.gpx.xml", 3),
  53. };
  54.  
  55. @Theory
  56. public void TRKSEGを読み込む(Fixture dataset) {
  57. try {
  58. System.out.println("GPX file: "+ dataset.gpxSourcePath);
  59. GpxFile gpx = new GpxFile(new AppParameters(AppParameters.FILE_PATH), new File(dataset.gpxSourcePath));
  60. gpx.parse();
  61. assertThat(gpx.gpx.trkseg.size(), is(dataset.segCount));
  62. for (Date key : gpx.gpx.trkseg.keySet()) {
  63. assertThat(key, is(notNullValue()));
  64. }
  65. }
  66. catch (IOException | ParseException | ParserConfigurationException | SAXException e) {
  67. fail();
  68. }
  69. }
  70. @Test
  71. public void test整形されていないGPX() {
  72. String gpxSourcePath = "target/test-classes/gpx/2020-02-29 13.35.58 Day.gpx";
  73. try {
  74. System.out.println("GPX file: "+ gpxSourcePath);
  75. GpxFile gpx = new GpxFile(new AppParameters(AppParameters.FILE_PATH), new File(gpxSourcePath));
  76. gpx.parse();
  77. ElementMapTRKSEG seg = gpx.gpx.trkseg;
  78. assertTrue(seg.size() == 1);
  79. for (Date key : seg.keySet()) {
  80. assertThat(key, notNullValue());
  81. }
  82. }
  83. catch (IOException e) {
  84. fail();
  85. }
  86. catch (ParseException e) {
  87. fail();
  88. }
  89. catch (ParserConfigurationException e) {
  90. fail();
  91. }
  92. catch (SAXException e) {
  93. // 整形されていないXML
  94. }
  95. }
  96. }
  97. }