## Have no mzXML files anymore
## test_mzXML <- function() {
##     file <- system.file("threonine", "threonine_i2_e35_pH_tree.mzXML", package = "msdata")
##     mzxml <- openMSfile(file, backend="pwiz")
##     checkTrue(class(mzxml)=="mzRpwiz")

##     show(mzxml)
##     length(mzxml)
##     runInfo(mzxml)
##     instrumentInfo(mzxml)
##     checkTrue(is.list(peaks(mzxml)))
##     checkTrue(is.matrix(peaks(mzxml,1)))
##     pks <- peaks(mzxml, 2:3)
##     checkTrue(length(pks) == 2)
##     checkEquals(colnames(pks[[1L]]), c("mz", "intensity"))
##     peaksCount(mzxml)
##     hdr <- header(mzxml)
##     checkTrue(any(colnames(hdr) == "spectrumId"))
##     checkTrue(all(hdr$centroided))
##     checkTrue(any(colnames(hdr) == "scanWindowLowerLimit"))
##     checkTrue(any(colnames(hdr) == "scanWindowUpperLimit"))
##     checkTrue(all(!is.na(hdr$scanWindowLowerLimit)))
##     checkTrue(all(!is.na(hdr$scanWindowUpperLimit)))
##     checkTrue(any(colnames(hdr) == "electronBeamEnergy"))
##     checkTrue(all(is.na(hdr$electronBeamEnergy)))
##     hdr <- header(mzxml,1)
##     checkTrue(is.list(hdr))
##     hdr <- header(mzxml, 2:3)
##     checkTrue(is.data.frame(hdr))
##     checkTrue(nrow(hdr) == 2)
##     fileName(mzxml)
##     close(mzxml)
## }

test_mzML <- function() {
    file <- MsDataHub::PestMix1_DDA.mzML()
    mzml <- openMSfile(file, backend="pwiz")
    checkTrue(class(mzml)=="mzRpwiz")
    show(mzml)
    length(mzml)
    runInfo(mzml)
    instrumentInfo(mzml)
    pks <- peaks(mzml)
    pks <- peaks(mzml,1)
    pks <- peaks(mzml,2:3)
    checkEquals(colnames(pks[[1L]]), c("mz", "intensity"))
    peaksCount(mzml)
    hdr <- header(mzml)
    checkTrue(any(colnames(hdr) == "spectrumId"))
    checkTrue(all(hdr$centroided))
    checkTrue(any(colnames(hdr) == "scanWindowLowerLimit"))
    checkTrue(any(colnames(hdr) == "scanWindowUpperLimit"))
    checkTrue(all(!is.na(hdr$scanWindowLowerLimit)))
    checkTrue(all(!is.na(hdr$scanWindowUpperLimit)))
    hdr <- header(mzml,1)
    checkTrue(is.list(hdr))
    hdr <- header(mzml, 2:3)
    checkTrue(is.data.frame(hdr))
    checkTrue(nrow(hdr) == 2)

    checkTrue(ncol(header(mzml))>4)
    checkTrue(length(header(mzml,1))>4)
    checkTrue(ncol(header(mzml,2:3))>4)

    ## Check polarity reporting
    checkTrue(all(header(mzml)$polarity==1))

    fileName(mzml)
    close(mzml)

    file <- MsDataHub::TMT_Erwinia_1uLSike_Top10HCD_isol2_45stepped_60min_01.20141210.mzML.gz()
    mzml <- openMSfile(file, backend="pwiz")
    checkTrue(class(mzml)=="mzRpwiz")
    hdr <- header(mzml)
    checkTrue(!hdr$centroided[2])
    checkTrue(hdr$centroided[235])
    close(mzml)
}

test_get3Dmap <- function() {
    ms <- openMSfile(MsDataHub::PestMix1_DDA.mzML())
    td <- get3Dmap(ms, scans = 1:100, lowMz = 100, highMz = 1000, resMz = 1)
    checkTrue(any(td > 0))
    close(ms)
}
