Skip to content

Commit

Permalink
Create Available PIDs Command tests based on real data
Browse files Browse the repository at this point in the history
  • Loading branch information
eltonvs committed Apr 11, 2019
1 parent bc71432 commit 1238cd5
Showing 1 changed file with 140 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package com.github.eltonvs.obd.command.control

import com.github.eltonvs.obd.command.ObdRawResponse
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import kotlin.test.Test
import kotlin.test.assertEquals


@RunWith(Parameterized::class)
class AvailablePIDsCommand01to20ParameterizedTests(private val rawValue: String, private val expected: IntArray) {
companion object {
@JvmStatic
@Parameterized.Parameters
fun values() = listOf(
// Renault Sandero 2014
arrayOf(
"BE3EB811",
intArrayOf(0x1, 0x3, 0x4, 0x5, 0x6, 0x7, 0xb, 0xc, 0xd, 0xe, 0xf, 0x11, 0x13, 0x14, 0x15, 0x1c, 0x20)
),
// Chevrolet Onix 2015
arrayOf(
"BE3FB813",
intArrayOf(
0x1, 0x3, 0x4, 0x5, 0x6, 0x7, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x13, 0x14, 0x15, 0x1c, 0x1f,
0x20
)
),
// Toyota Corolla 2015
arrayOf(
"BE1FA813",
intArrayOf(0x1, 0x3, 0x4, 0x5, 0x6, 0x7, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x13, 0x15, 0x1c, 0x1f, 0x20)
),
// Fiat Siena 2011
arrayOf(
"BE3EB811",
intArrayOf(0x1, 0x3, 0x4, 0x5, 0x6, 0x7, 0xb, 0xc, 0xd, 0xe, 0xf, 0x11, 0x13, 0x14, 0x15, 0x1c, 0x20)
),
// VW Gol 2014
arrayOf(
"BE3EB813",
intArrayOf(
0x1, 0x3, 0x4, 0x5, 0x6, 0x7, 0xb, 0xc, 0xd, 0xe, 0xf, 0x11, 0x13, 0x14, 0x15, 0x1c, 0x1f, 0x20
)
)
)
}

@Test
fun `test valid available PIDs 01 to 20 responses handler`() {
val rawResponse = ObdRawResponse(value = rawValue, elapsedTime = 0)
val obdResponse = AvailablePIDsCommand(AvailablePIDsCommand.AvailablePIDsRanges.PIDS_01_TO_20).run {
handleResponse(rawResponse)
}
assertEquals(expected.joinToString(",") { "%02X".format(it) }, obdResponse.formattedValue)
}
}


@RunWith(Parameterized::class)
class AvailablePIDsCommand21to40ParameterizedTests(private val rawValue: String, private val expected: IntArray) {
companion object {
@JvmStatic
@Parameterized.Parameters
fun values() = listOf(
// Renault Sandero 2014
arrayOf("80018001", intArrayOf(0x21, 0x30, 0x31, 0x40)),
// Chevrolet Onix 2015
arrayOf("8007A011", intArrayOf(0x21, 0x2e, 0x2f, 0x30, 0x31, 0x33, 0x3c, 0x40)),
// Toyota Corolla 2015
arrayOf("9005B015", intArrayOf(0x21, 0x24, 0x2e, 0x30, 0x31, 0x33, 0x34, 0x3c, 0x3e, 0x40)),
// Fiat Siena 2011
arrayOf("80000000", intArrayOf(0x21)),
// VW Gol 2014
arrayOf("8007A011", intArrayOf(0x21, 0x2e, 0x2f, 0x30, 0x31, 0x33, 0x3c, 0x40))
)
}

@Test
fun `test valid available PIDs 21 to 40 responses handler`() {
val rawResponse = ObdRawResponse(value = rawValue, elapsedTime = 0)
val obdResponse = AvailablePIDsCommand(AvailablePIDsCommand.AvailablePIDsRanges.PIDS_21_TO_40).run {
handleResponse(rawResponse)
}
assertEquals(expected.joinToString(",") { "%02X".format(it) }, obdResponse.formattedValue)
}
}


@RunWith(Parameterized::class)
class AvailablePIDsCommand41to60ParameterizedTests(private val rawValue: String, private val expected: IntArray) {
companion object {
@JvmStatic
@Parameterized.Parameters
fun values() = listOf(
// Renault Sandero 2014
arrayOf("80000000", intArrayOf(0x41)),
// Chevrolet Onix 2015
arrayOf("FED0C000", intArrayOf(0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x49, 0x4a, 0x4c, 0x51, 0x52)),
// Toyota Corolla 2015
arrayOf("7ADC8001", intArrayOf(0x42, 0x43, 0x44, 0x45, 0x47, 0x49, 0x4a, 0x4c, 0x4d, 0x4e, 0x51, 0x60)),
// VW Gol 2014
arrayOf(
"FED14400",
intArrayOf(0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x49, 0x4a, 0x4c, 0x50, 0x52, 0x56)
)
)
}

@Test
fun `test valid available PIDs 41 to 60 responses handler`() {
val rawResponse = ObdRawResponse(value = rawValue, elapsedTime = 0)
val obdResponse = AvailablePIDsCommand(AvailablePIDsCommand.AvailablePIDsRanges.PIDS_41_TO_60).run {
handleResponse(rawResponse)
}
assertEquals(expected.joinToString(",") { "%02X".format(it) }, obdResponse.formattedValue)
}
}


@RunWith(Parameterized::class)
class AvailablePIDsCommand61to80ParameterizedTests(private val rawValue: String, private val expected: IntArray) {
companion object {
@JvmStatic
@Parameterized.Parameters
fun values() = listOf(
// Toyota Corolla 2015
arrayOf("08000000", intArrayOf(0x65))
)
}

@Test
fun `test valid available PIDs 61 to 80 responses handler`() {
val rawResponse = ObdRawResponse(value = rawValue, elapsedTime = 0)
val obdResponse = AvailablePIDsCommand(AvailablePIDsCommand.AvailablePIDsRanges.PIDS_61_TO_80).run {
handleResponse(rawResponse)
}
assertEquals(expected.joinToString(",") { "%02X".format(it) }, obdResponse.formattedValue)
}
}

0 comments on commit 1238cd5

Please sign in to comment.