before refactoring
This commit is contained in:
parent
68cf83f408
commit
d2c728dc90
@ -40,42 +40,8 @@
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.8.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib:1.7.10" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-common:1.7.10" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jetbrains:annotations:13.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: io.kotest:kotest-runner-junit5-jvm:5.4.2" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: io.kotest:kotest-framework-api-jvm:5.4.2" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.jetbrains.kotlinx:kotlinx-coroutines-test-jvm:1.6.4" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: io.kotest:kotest-common-jvm:5.4.2" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: io.kotest:kotest-framework-engine-jvm:5.4.2" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: io.github.classgraph:classgraph:4.8.149" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: com.github.ajalt:mordant:1.2.1" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: com.github.ajalt:colormath:1.2.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.jetbrains.kotlinx:kotlinx-coroutines-debug:1.6.4" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: net.java.dev.jna:jna:5.9.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: net.java.dev.jna:jna-platform:5.9.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy:1.10.9" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy-agent:1.10.9" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: io.kotest:kotest-framework-discovery-jvm:5.4.2" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: io.kotest:kotest-extensions-jvm:5.4.2" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: commons-io:commons-io:2.11.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: io.mockk:mockk:1.12.5" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: io.mockk:mockk-common:1.12.5" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: io.mockk:mockk-dsl:1.12.5" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: io.mockk:mockk-dsl-jvm:1.12.5" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: io.mockk:mockk-agent-jvm:1.12.5" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: io.mockk:mockk-agent-api:1.12.5" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: io.mockk:mockk-agent-common:1.12.5" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:3.2" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: io.kotest:kotest-framework-concurrency-jvm:5.4.2" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-suite-api:1.7.2" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-launcher:1.7.2" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.jetbrains.kotlin:kotlin-reflect:1.6.21" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: io.kotest:kotest-assertions-core-jvm:5.4.2" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: io.kotest:kotest-assertions-shared-jvm:5.4.2" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: io.github.java-diff-utils:java-diff-utils:4.12" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-common:1.6.21" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.6.4" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: io.kotest:kotest-assertions-api-jvm:5.4.2" level="project" />
|
||||
</component>
|
||||
</module>
|
8
src/main/kotlin/me/bvn13/sdk/android/gpx/GpxConstant.kt
Normal file
8
src/main/kotlin/me/bvn13/sdk/android/gpx/GpxConstant.kt
Normal file
@ -0,0 +1,8 @@
|
||||
package me.bvn13.sdk.android.gpx
|
||||
|
||||
class GpxConstant {
|
||||
companion object {
|
||||
const val HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||
const val VERSION = "1.1"
|
||||
}
|
||||
}
|
183
src/main/kotlin/me/bvn13/sdk/android/gpx/GpxReader.kt
Normal file
183
src/main/kotlin/me/bvn13/sdk/android/gpx/GpxReader.kt
Normal file
@ -0,0 +1,183 @@
|
||||
package me.bvn13.sdk.android.gpx
|
||||
|
||||
import java.io.InputStream
|
||||
|
||||
fun GpxType.Companion.read(dis: InputStream) = GpxReader().read(dis)
|
||||
|
||||
fun ByteArray.asString() = String(this)
|
||||
|
||||
class GpxReader {
|
||||
fun read(dis: InputStream): GpxType {
|
||||
val container = readNotSpace(dis, Container.empty())
|
||||
return when (container.byte!!.toInt()) {
|
||||
'<'.code -> readBeginning(dis, container)
|
||||
else -> throw IllegalArgumentException("Not a GPX/XML?")
|
||||
}
|
||||
}
|
||||
|
||||
private fun readBeginning(dis: InputStream, buffer: Container): GpxType {
|
||||
val container = readByte(dis, buffer)
|
||||
return when (container.byte!!.toInt()) {
|
||||
'?'.code -> readSignature(dis, container)
|
||||
'<'.code -> readGpx(dis, container)
|
||||
else -> throw IllegalArgumentException("Wrong symbol at ${container.position} from the very beginning")
|
||||
}
|
||||
}
|
||||
|
||||
private fun readSignature(dis: InputStream, buffer: Container): GpxType {
|
||||
val container = readUntil(dis, buffer, '\n')
|
||||
if ("${GpxConstant.HEADER}\n" != container.buffer.asString()) {
|
||||
throw IllegalArgumentException("Wrong xml signature!")
|
||||
}
|
||||
return readBeginning(dis, Container.empty(container.position))
|
||||
}
|
||||
|
||||
private fun readGpx(dis: InputStream, buffer: Container): GpxType {
|
||||
val container = readUntil(dis, buffer, setOf(' ', '\n'))
|
||||
val tagName = container.buffer.asString().substring(1, container.buffer.size - 1).lowercase()
|
||||
if ("gpx" != tagName) {
|
||||
throw IllegalArgumentException("There must be GPX tag in given InputStream")
|
||||
}
|
||||
val xmlObject = XmlObject(tagName)
|
||||
val attributesContainer = readAttributes(dis, container)
|
||||
xmlObject.attributes = attributesContainer.attributes
|
||||
val nestedContainer = readNestedObjects(dis, attributesContainer)
|
||||
val finishingContainer = readFinishingTag(dis, nestedContainer, tagName)
|
||||
return GpxType(
|
||||
|
||||
MetadataType("test")
|
||||
)
|
||||
}
|
||||
|
||||
private fun readObject(dis: InputStream, buffer: Container, checker: (Container) -> Unit): Container {
|
||||
val container = readUntil(dis, buffer, setOf(' ', '\n'))
|
||||
val tagName = container.buffer.asString().substring(1, container.buffer.size - 1).lowercase()
|
||||
checker.invoke(container)
|
||||
if ("gpx" != tagName) {
|
||||
throw IllegalArgumentException("There must be GPX tag in given InputStream")
|
||||
}
|
||||
val xmlObject = XmlObject(tagName)
|
||||
val attributesContainer = readAttributes(dis, container)
|
||||
xmlObject.attributes = attributesContainer.attributes
|
||||
val nestedContainer = readNestedObjects(dis, attributesContainer)
|
||||
val finishingContainer = readFinishingTag(dis, nestedContainer, tagName)
|
||||
}
|
||||
|
||||
private fun readNestedObjects(dis: InputStream, buffer: Container): Container {
|
||||
|
||||
}
|
||||
|
||||
private fun readFinishingTag(dis: InputStream, buffer: Container, tagName: String): Container =
|
||||
readExactly(dis, Container.empty(buffer.position), "</${tagName}>")
|
||||
|
||||
private fun readAttributes(dis: InputStream, buffer: Container): Container {
|
||||
if (buffer.byte!!.toInt() == '>'.code) {
|
||||
return Container.empty(buffer.position)
|
||||
}
|
||||
val attributes = HashMap<String, String>()
|
||||
var attributeContainer: Container = Container.empty(buffer.position)
|
||||
do {
|
||||
attributeContainer = readAttribute(dis, attributeContainer)
|
||||
attributes.putAll(attributeContainer.attributes)
|
||||
} while (attributeContainer.attributes.isNotEmpty() && attributeContainer.byte!!.toInt() != '>'.code)
|
||||
val result = Container.emptyWithAttributes(attributeContainer.position, attributes)
|
||||
return result
|
||||
}
|
||||
|
||||
private fun readAttribute(dis: InputStream, buffer: Container): Container {
|
||||
val nameContainer = readUntil(dis, buffer, setOf(' ', '\n', '=', '\t'))
|
||||
val nameAsString = nameContainer.buffer.asString()
|
||||
val name = nameAsString.substring(0, nameAsString.length - 1)
|
||||
val equalsContainer = readUntil(dis, Container.empty(nameContainer.position), '"')
|
||||
val valueContainer = readUntil(dis, Container.empty(equalsContainer.position), '"')
|
||||
val valueAsString = valueContainer.buffer.asString()
|
||||
val value = valueAsString.substring(0, valueAsString.length - 1)
|
||||
val result = Container.empty(valueContainer.position)
|
||||
val closingContainer = readSkipping(dis, result, setOf(' ', '\n', '\t'))
|
||||
val nextBlockContainer = Container.of(closingContainer.byte!!, closingContainer.position)
|
||||
nextBlockContainer.attributes = mapOf(name to value)
|
||||
return nextBlockContainer
|
||||
}
|
||||
|
||||
private fun readUntil(dis: InputStream, buffer: Container, ch: Char): Container {
|
||||
var container = buffer
|
||||
do {
|
||||
container = readByte(dis, container)
|
||||
} while (container.byte!!.toInt() != ch.code)
|
||||
return container
|
||||
}
|
||||
|
||||
private fun readUntil(dis: InputStream, buffer: Container, chs: Set<Char>): Container {
|
||||
val chars = chs.map { c -> c.code }
|
||||
var container = buffer
|
||||
do {
|
||||
container = readByte(dis, container)
|
||||
} while (!chars.contains(container.byte!!.toInt()))
|
||||
return container
|
||||
}
|
||||
|
||||
private fun readSkipping(dis: InputStream, buffer: Container, chs: Set<Char>): Container {
|
||||
val chars = chs.map { c -> c.code }
|
||||
var container = buffer
|
||||
do {
|
||||
container = readByte(dis, container)
|
||||
} while (chars.contains(container.byte!!.toInt()))
|
||||
return container
|
||||
}
|
||||
|
||||
private fun readExactly(dis: InputStream, buffer: Container, charSequence: CharSequence): Container {
|
||||
var container = buffer
|
||||
charSequence.forEach {
|
||||
container = readByte(dis, container)
|
||||
if (container.byte!!.toInt() != it.code) {
|
||||
throw IllegalArgumentException("Expected closing tag $charSequence at position ${buffer.position}")
|
||||
}
|
||||
}
|
||||
return container
|
||||
}
|
||||
|
||||
private fun readNotSpace(dis: InputStream, buffer: Container): Container {
|
||||
val container = readByte(dis, buffer)
|
||||
if (container.byte!!.toInt() == ' '.code
|
||||
|| container.byte.toInt() == '\n'.code
|
||||
) {
|
||||
return readByte(dis, container)
|
||||
} else {
|
||||
return container
|
||||
}
|
||||
}
|
||||
|
||||
private fun readByte(dis: InputStream, container: Container): Container {
|
||||
val ba = ByteArray(1);
|
||||
if (-1 == dis.read(ba, 0, 1)) {
|
||||
throw InterruptedException("EOF")
|
||||
} else if (ba.size != 1) {
|
||||
throw InterruptedException("Reading 1 byte returns ${ba.size} bytes")
|
||||
}
|
||||
return Container(container.position + 1, ba[0], container.buffer.plus(ba))
|
||||
}
|
||||
|
||||
class Container(val position: Long = 0, val byte: Byte?, val buffer: ByteArray) {
|
||||
var objects: List<XmlObject>? = null
|
||||
var attributes: Map<String, String> = HashMap()
|
||||
|
||||
companion object {
|
||||
fun empty(): Container = empty(0)
|
||||
fun empty(position: Long) = Container(position, null, ByteArray(0))
|
||||
fun emptyWithAttributes(position: Long, attributes: Map<String, String>): Container {
|
||||
val container = Container.empty(position)
|
||||
container.attributes = attributes
|
||||
return container
|
||||
}
|
||||
fun of(b: Byte, position: Long) = Container(position, b, ByteArray(1) {_ -> b})
|
||||
}
|
||||
|
||||
override fun toString(): String = this.buffer.asString()
|
||||
}
|
||||
|
||||
class XmlObject(val type: String) {
|
||||
var attributes: Map<String, String> = HashMap()
|
||||
var nested: List<XmlObject>? = null
|
||||
}
|
||||
|
||||
}
|
@ -77,6 +77,8 @@ limitations under the License.
|
||||
|
||||
package me.bvn13.sdk.android.gpx
|
||||
|
||||
import me.bvn13.sdk.android.gpx.GpxConstant.Companion.VERSION
|
||||
|
||||
/**
|
||||
* GPX documents contain a metadata header, followed by waypoints, routes, and tracks. You can add your own elements to the extensions section of the GPX document.
|
||||
*
|
||||
@ -100,5 +102,11 @@ class GpxType(
|
||||
val trk: List<TrkType>? = null,
|
||||
val extensions: ExtensionType? = null
|
||||
) {
|
||||
val version: String = "1.1"
|
||||
val version: String = VERSION
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
// TODO implement it
|
||||
return super.equals(other)
|
||||
}
|
||||
companion object { }
|
||||
}
|
||||
|
@ -77,8 +77,8 @@ limitations under the License.
|
||||
|
||||
package me.bvn13.sdk.android.gpx
|
||||
|
||||
import me.bvn13.sdk.android.gpx.GpxConstant.Companion.HEADER
|
||||
import me.bvn13.sdk.android.gpx.GpxWriter.Companion.DTF
|
||||
import me.bvn13.sdk.android.gpx.GpxWriter.Companion.HEADER
|
||||
import me.bvn13.sdk.android.gpx.GpxWriter.Companion.SCHEMA_LOCATION
|
||||
import me.bvn13.sdk.android.gpx.GpxWriter.Companion.XMLNS
|
||||
import me.bvn13.sdk.android.gpx.GpxWriter.Companion.XMLNS_XSI
|
||||
@ -262,7 +262,6 @@ private fun String.removeEmptyStrings() = this.lineSequence().map {
|
||||
|
||||
class GpxWriter {
|
||||
companion object {
|
||||
const val HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||
const val XMLNS = "http://www.topografix.com/GPX/1/1"
|
||||
const val XMLNS_XSI = "http://www.w3.org/2001/XMLSchema-instance"
|
||||
const val SCHEMA_LOCATION = "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
|
||||
|
412
src/test/kotlin/me/bvn13/sdk/android/gpx/GpxReaderTest.kt
Normal file
412
src/test/kotlin/me/bvn13/sdk/android/gpx/GpxReaderTest.kt
Normal file
@ -0,0 +1,412 @@
|
||||
package me.bvn13.sdk.android.gpx
|
||||
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.time.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class GpxReaderTest {
|
||||
|
||||
@DisplayName("test GPX Reader")
|
||||
@Test
|
||||
fun testReader() {
|
||||
val clock = Clock.fixed(
|
||||
LocalDateTime.of(2022, 9, 24, 15, 4, 0, 0).toInstant(ZoneOffset.ofHours(3)), ZoneId.of("Europe/Moscow")
|
||||
)
|
||||
|
||||
val gpxType = GpxType(
|
||||
MetadataType("test name", description = "test description", authorName = "bvn13"),
|
||||
wpt = listOf(
|
||||
WptType(
|
||||
lat = 14.64736838389662,
|
||||
lon = 7.93212890625,
|
||||
ele = 10.toDouble(),
|
||||
time = OffsetDateTime.now(clock),
|
||||
magvar = 3.toDouble(),
|
||||
geoidheight = 45.toDouble(),
|
||||
name = "test point 1",
|
||||
cmt = "comment 1",
|
||||
desc = "description of point 1",
|
||||
link = listOf(
|
||||
LinkType(
|
||||
href = "http://link-to.site.href",
|
||||
text = "text",
|
||||
type = "hyperlink"
|
||||
),
|
||||
LinkType(
|
||||
href = "http://link2-to.site.href",
|
||||
text = "text2",
|
||||
type = "hyperlink2"
|
||||
)
|
||||
),
|
||||
src = "source 1",
|
||||
sym = "sym 1",
|
||||
type = "type 1",
|
||||
fix = FixType.DGPS,
|
||||
sat = 1,
|
||||
hdop = 55.toDouble(),
|
||||
vdop = 66.toDouble(),
|
||||
pdop = 77.toDouble(),
|
||||
ageofgpsdata = 44,
|
||||
dgpsid = 88,
|
||||
extensions = listOf(
|
||||
ExtensionType(
|
||||
"extension1",
|
||||
parameters = mapOf(Pair("first", "second"), Pair("third", "fours"))
|
||||
),
|
||||
ExtensionType(
|
||||
"extension2",
|
||||
parameters = mapOf(Pair("aa", "bb"), Pair("cc", "dd"))
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
rte = listOf(
|
||||
RteType(
|
||||
name = "rte name",
|
||||
cmt = "cmt",
|
||||
desc = "desc",
|
||||
src = "src",
|
||||
link = listOf(
|
||||
LinkType(
|
||||
href = "https://new.link.rte",
|
||||
text = "new text rte",
|
||||
type = "hyperlink"
|
||||
)
|
||||
),
|
||||
number = 1234,
|
||||
type = "route",
|
||||
extensions = listOf(
|
||||
ExtensionType(
|
||||
"ext-1",
|
||||
value = "value1"
|
||||
)
|
||||
),
|
||||
rtept = listOf(
|
||||
WptType(
|
||||
lat = 14.64736838389662,
|
||||
lon = 7.93212890625,
|
||||
ele = 10.toDouble(),
|
||||
time = OffsetDateTime.now(clock),
|
||||
magvar = 3.toDouble(),
|
||||
geoidheight = 45.toDouble(),
|
||||
name = "test point 1",
|
||||
cmt = "comment 1",
|
||||
desc = "description of point 1",
|
||||
link = listOf(
|
||||
LinkType(
|
||||
href = "http://link-to.site.href",
|
||||
text = "text",
|
||||
type = "hyperlink"
|
||||
),
|
||||
LinkType(
|
||||
href = "http://link2-to.site.href",
|
||||
text = "text2",
|
||||
type = "hyperlink2"
|
||||
)
|
||||
),
|
||||
src = "source 1",
|
||||
sym = "sym 1",
|
||||
type = "type 1",
|
||||
fix = FixType.DGPS,
|
||||
sat = 1,
|
||||
hdop = 55.toDouble(),
|
||||
vdop = 66.toDouble(),
|
||||
pdop = 77.toDouble(),
|
||||
ageofgpsdata = 44,
|
||||
dgpsid = 88,
|
||||
extensions = listOf(
|
||||
ExtensionType(
|
||||
"extension1",
|
||||
parameters = mapOf(Pair("first", "second"), Pair("third", "fours"))
|
||||
),
|
||||
ExtensionType(
|
||||
"extension2",
|
||||
parameters = mapOf(Pair("aa", "bb"), Pair("cc", "dd"))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
trk = listOf(
|
||||
TrkType(
|
||||
name = "track 1",
|
||||
cmt = "comment track 1",
|
||||
desc = "desc track 1",
|
||||
src = "src track 1",
|
||||
number = 1234,
|
||||
type = "type 1",
|
||||
trkseg = listOf(
|
||||
TrksegType(
|
||||
listOf(
|
||||
WptType(
|
||||
lat = 14.64736838389662,
|
||||
lon = 7.93212890625,
|
||||
ele = 10.toDouble(),
|
||||
time = OffsetDateTime.now(clock),
|
||||
magvar = 3.toDouble(),
|
||||
geoidheight = 45.toDouble(),
|
||||
name = "test point 1",
|
||||
cmt = "comment 1",
|
||||
desc = "description of point 1",
|
||||
link = listOf(
|
||||
LinkType(
|
||||
href = "http://link-to.site.href",
|
||||
text = "text",
|
||||
type = "hyperlink"
|
||||
),
|
||||
LinkType(
|
||||
href = "http://link2-to.site.href",
|
||||
text = "text2",
|
||||
type = "hyperlink2"
|
||||
)
|
||||
),
|
||||
src = "source 1",
|
||||
sym = "sym 1",
|
||||
type = "type 1",
|
||||
fix = FixType.DGPS,
|
||||
sat = 1,
|
||||
hdop = 55.toDouble(),
|
||||
vdop = 66.toDouble(),
|
||||
pdop = 77.toDouble(),
|
||||
ageofgpsdata = 44,
|
||||
dgpsid = 88,
|
||||
extensions = listOf(
|
||||
ExtensionType(
|
||||
"extension1",
|
||||
parameters = mapOf(Pair("first", "second"), Pair("third", "fours"))
|
||||
),
|
||||
ExtensionType(
|
||||
"extension2",
|
||||
parameters = mapOf(Pair("aa", "bb"), Pair("cc", "dd"))
|
||||
)
|
||||
)
|
||||
),
|
||||
WptType(
|
||||
lat = 14.64736838389662,
|
||||
lon = 7.93212890625,
|
||||
ele = 10.toDouble(),
|
||||
time = OffsetDateTime.now(clock),
|
||||
magvar = 3.toDouble(),
|
||||
geoidheight = 45.toDouble(),
|
||||
name = "test point 1",
|
||||
cmt = "comment 1",
|
||||
desc = "description of point 1",
|
||||
link = listOf(
|
||||
LinkType(
|
||||
href = "http://link-to.site.href",
|
||||
text = "text",
|
||||
type = "hyperlink"
|
||||
),
|
||||
LinkType(
|
||||
href = "http://link2-to.site.href",
|
||||
text = "text2",
|
||||
type = "hyperlink2"
|
||||
)
|
||||
),
|
||||
src = "source 1",
|
||||
sym = "sym 1",
|
||||
type = "type 1",
|
||||
fix = FixType.DGPS,
|
||||
sat = 1,
|
||||
hdop = 55.toDouble(),
|
||||
vdop = 66.toDouble(),
|
||||
pdop = 77.toDouble(),
|
||||
ageofgpsdata = 44,
|
||||
dgpsid = 88,
|
||||
extensions = listOf(
|
||||
ExtensionType(
|
||||
"extension1",
|
||||
parameters = mapOf(Pair("first", "second"), Pair("third", "fours"))
|
||||
),
|
||||
ExtensionType(
|
||||
"extension2",
|
||||
parameters = mapOf(Pair("aa", "bb"), Pair("cc", "dd"))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
val gpxString = """
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gpx
|
||||
xmlns="http://www.topografix.com/GPX/1/1"
|
||||
version="1.1"
|
||||
creator="me.bvn13.sdk.android.gpx"
|
||||
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">
|
||||
<time>2022-09-24T15:04:00+03:00</time>
|
||||
<metadata>
|
||||
<name>test name</name>
|
||||
<desc>test description</desc>
|
||||
<author>
|
||||
<name>bvn13</name>
|
||||
</author>
|
||||
</metadata>
|
||||
<wpt lat="14.64736838389662" lon="7.93212890625">
|
||||
<ele>10.0</ele>
|
||||
<time>2022-09-24T15:04:00+03:00</time>
|
||||
<magvar>3.0</magvar>
|
||||
<geoidheight>45.0</geoidheight>
|
||||
<name>test point 1</name>
|
||||
<cmt>comment 1</cmt>
|
||||
<desc>description of point 1</desc>
|
||||
<src>source 1</src>
|
||||
<link href="http://link-to.site.href">
|
||||
<text>text</text>
|
||||
<type>hyperlink</type>
|
||||
</link>
|
||||
<link href="http://link2-to.site.href">
|
||||
<text>text2</text>
|
||||
<type>hyperlink2</type>
|
||||
</link>
|
||||
<sym>sym 1</sym>
|
||||
<type>type 1</type>
|
||||
<fix>dgps</fix>
|
||||
<sat>1</sat>
|
||||
<hdop>55.0</hdop>
|
||||
<vdop>66.0</vdop>
|
||||
<pdop>77.0</pdop>
|
||||
<ageofgpsdata>44</ageofgpsdata>
|
||||
<dgpsid>88</dgpsid>
|
||||
<extensions>
|
||||
<extension1 first="second" third="fours"></extension1>
|
||||
<extension2 aa="bb" cc="dd"></extension2>
|
||||
</extensions>
|
||||
</wpt>
|
||||
<rte>
|
||||
<name>rte name</name>
|
||||
<cmt>cmt</cmt>
|
||||
<desc>desc</desc>
|
||||
<src>src</src>
|
||||
<link href="https://new.link.rte">
|
||||
<text>new text rte</text>
|
||||
<type>hyperlink</type>
|
||||
</link>
|
||||
<number>1234</number>
|
||||
<type>route</type>
|
||||
<extensions>
|
||||
<ext-1>value1</ext-1>
|
||||
</extensions>
|
||||
<wpt lat="14.64736838389662" lon="7.93212890625">
|
||||
<ele>10.0</ele>
|
||||
<time>2022-09-24T15:04:00+03:00</time>
|
||||
<magvar>3.0</magvar>
|
||||
<geoidheight>45.0</geoidheight>
|
||||
<name>test point 1</name>
|
||||
<cmt>comment 1</cmt>
|
||||
<desc>description of point 1</desc>
|
||||
<src>source 1</src>
|
||||
<link href="http://link-to.site.href">
|
||||
<text>text</text>
|
||||
<type>hyperlink</type>
|
||||
</link>
|
||||
<link href="http://link2-to.site.href">
|
||||
<text>text2</text>
|
||||
<type>hyperlink2</type>
|
||||
</link>
|
||||
<sym>sym 1</sym>
|
||||
<type>type 1</type>
|
||||
<fix>dgps</fix>
|
||||
<sat>1</sat>
|
||||
<hdop>55.0</hdop>
|
||||
<vdop>66.0</vdop>
|
||||
<pdop>77.0</pdop>
|
||||
<ageofgpsdata>44</ageofgpsdata>
|
||||
<dgpsid>88</dgpsid>
|
||||
<extensions>
|
||||
<extension1 first="second" third="fours"></extension1>
|
||||
<extension2 aa="bb" cc="dd"></extension2>
|
||||
</extensions>
|
||||
</wpt>
|
||||
</rte>
|
||||
<trk>
|
||||
<name>track 1</name>
|
||||
<cmt>comment track 1</cmt>
|
||||
<desc>desc track 1</desc>
|
||||
<src>src track 1</src>
|
||||
<number>1234</number>
|
||||
<type>type 1</type>
|
||||
<trkseg>
|
||||
<trkpt lat="14.64736838389662" lon="7.93212890625">
|
||||
<ele>10.0</ele>
|
||||
<time>2022-09-24T15:04:00+03:00</time>
|
||||
<magvar>3.0</magvar>
|
||||
<geoidheight>45.0</geoidheight>
|
||||
<name>test point 1</name>
|
||||
<cmt>comment 1</cmt>
|
||||
<desc>description of point 1</desc>
|
||||
<src>source 1</src>
|
||||
<link href="http://link-to.site.href">
|
||||
<text>text</text>
|
||||
<type>hyperlink</type>
|
||||
</link>
|
||||
<link href="http://link2-to.site.href">
|
||||
<text>text2</text>
|
||||
<type>hyperlink2</type>
|
||||
</link>
|
||||
<sym>sym 1</sym>
|
||||
<type>type 1</type>
|
||||
<fix>dgps</fix>
|
||||
<sat>1</sat>
|
||||
<hdop>55.0</hdop>
|
||||
<vdop>66.0</vdop>
|
||||
<pdop>77.0</pdop>
|
||||
<ageofgpsdata>44</ageofgpsdata>
|
||||
<dgpsid>88</dgpsid>
|
||||
<extensions>
|
||||
<extension1 first="second" third="fours"></extension1>
|
||||
<extension2 aa="bb" cc="dd"></extension2>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
<trkpt lat="14.64736838389662" lon="7.93212890625">
|
||||
<ele>10.0</ele>
|
||||
<time>2022-09-24T15:04:00+03:00</time>
|
||||
<magvar>3.0</magvar>
|
||||
<geoidheight>45.0</geoidheight>
|
||||
<name>test point 1</name>
|
||||
<cmt>comment 1</cmt>
|
||||
<desc>description of point 1</desc>
|
||||
<src>source 1</src>
|
||||
<link href="http://link-to.site.href">
|
||||
<text>text</text>
|
||||
<type>hyperlink</type>
|
||||
</link>
|
||||
<link href="http://link2-to.site.href">
|
||||
<text>text2</text>
|
||||
<type>hyperlink2</type>
|
||||
</link>
|
||||
<sym>sym 1</sym>
|
||||
<type>type 1</type>
|
||||
<fix>dgps</fix>
|
||||
<sat>1</sat>
|
||||
<hdop>55.0</hdop>
|
||||
<vdop>66.0</vdop>
|
||||
<pdop>77.0</pdop>
|
||||
<ageofgpsdata>44</ageofgpsdata>
|
||||
<dgpsid>88</dgpsid>
|
||||
<extensions>
|
||||
<extension1 first="second" third="fours"></extension1>
|
||||
<extension2 aa="bb" cc="dd"></extension2>
|
||||
</extensions>
|
||||
</trkpt>
|
||||
</trkseg>
|
||||
</trk>
|
||||
</gpx>
|
||||
""".trim()
|
||||
.lineSequence()
|
||||
.map {
|
||||
it.trim()
|
||||
}
|
||||
.joinToString("\n")
|
||||
|
||||
val gpx = GpxType.read(gpxString.byteInputStream())
|
||||
assertEquals(gpxType, gpx)
|
||||
}
|
||||
}
|
@ -146,7 +146,7 @@ class GpxWriterTest {
|
||||
|
||||
@DisplayName("test maximum")
|
||||
@Test
|
||||
fun maximumTest() {
|
||||
fun testMaximum() {
|
||||
val clock = Clock.fixed(
|
||||
LocalDateTime.of(2022, 9, 24, 15, 4, 0, 0).toInstant(ZoneOffset.ofHours(3)), ZoneId.of("Europe/Moscow")
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user