package com.doverfuelingsolutions.issp

import androidx.lifecycle.lifecycleScope
import com.doverfuelingsolutions.issp.driver.lib.PrintManager
import com.doverfuelingsolutions.issp.utils.thread.ThreadUtil
import com.wayne.www.waynelib.fdc.FdcClient
import com.wayne.www.waynelib.fdc.OnFdcServiceResponseReceivedListener
import com.wayne.www.waynelib.fdc.message.DeviceClass
import com.wayne.www.waynelib.fdc.message.ServiceResponse
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import org.junit.Test

import org.junit.Assert.*
import java.math.BigDecimal
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
class ExampleUnitTest {
    @Test
    fun addition_isCorrect() {
        val baseStr = "<img id=\\\"einvoice\\\" src=\\\"data:image/jpg;base64,[encoded data, 6416 characters]\\\"></img>"
        val strsign = "data:image/jpg;base64,"
        var str = ""
        val index1 = baseStr.indexOf(strsign)
        if (index1 > -1) {
            val index2 = baseStr.indexOf("</img>",index1)
            str = baseStr.slice((index1+strsign.length) until index2)
        }

        println(str)


    }

    suspend fun fun1() = suspendCoroutine<String>{
        Thread.sleep(3000)
        it.resume("执行完毕")
    }

    @Test
    fun fun2() {
        val list = arrayListOf<Int>(1,2,3,4,5)
        println(list)
        list.add(0,0)
        println(list)
    }

    @Test
    fun test_thread(){
//        val thread = Thread()
//
//        println(thread.isDaemon)
//        println(thread.priority)
//        println(thread.threadGroup)

        for (i in 1 .. 100) {
            ThreadUtil.io{

            }
        }
    }

    @Test
    fun test1(){
        val arrayListOf = arrayListOf<DeviceClass>()
        for (index in 1 .. 5) {
            val deviceClass = DeviceClass()
            deviceClass.pumpNo = index
            deviceClass.transactionSeqNo = "123"
            deviceClass.releaseTokenAttribute = "123"
            deviceClass.endTimeStamp = "123456"
            deviceClass.amount = BigDecimal("0.01")
            arrayListOf.add(deviceClass)
        }

        val order1 = arrayListOf.find {
            it.pumpNo == 1 &&
                    it.transactionSeqNo == "123" &&
                    (it.releaseTokenAttribute == "123" || it.releaseTokenElement == "123") }
        val deviceClass1 = DeviceClass()
        deviceClass1.pumpNo = 1
        deviceClass1.transactionSeqNo = "123"
        deviceClass1.releaseTokenAttribute = "123"
        deviceClass1.amount = order1?.amount
        deviceClass1.endTimeStamp = order1?.endTimeStamp


        val order2 = arrayListOf.find {
            it.pumpNo == 10 &&
                    it.transactionSeqNo == "123" &&
                    (it.releaseTokenAttribute == "123" || it.releaseTokenElement == "123") }
        val deviceClass2 = DeviceClass()
        deviceClass2.pumpNo = 1
        deviceClass2.transactionSeqNo = "123"
        deviceClass2.releaseTokenAttribute = "123"
        deviceClass2.amount = order2?.amount
        deviceClass2.endTimeStamp = order2?.endTimeStamp

        println("${deviceClass1.pumpNo} ${deviceClass1.transactionSeqNo} ${deviceClass1.releaseTokenAttribute}" +
                "${deviceClass1.amount} ${deviceClass1.endTimeStamp}")

        println("${deviceClass2.pumpNo} ${deviceClass2.transactionSeqNo} ${deviceClass2.releaseTokenAttribute}" +
                "${deviceClass2.amount} ${deviceClass2.endTimeStamp}")
    }
}