#    rpmquery.at: test rpmquery
#
#    Copyright (C) 2007  Ralf Corsépius <corsepiu@fedoraproject.org>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

AT_BANNER([RPM queries])

# ------------------------------
AT_SETUP([rpm --qf -p *.i386.rpm])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  -q --qf "%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n" \
  -p /data/RPMS/hello-1.0-1.i386.rpm
],
[0],
[hello-1.0-1.i386
],
[ignore])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([rpm --qf -p *.src.rpm])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  -q --qf "%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n" \
  -p /data/SRPMS/hello-1.0-1.src.rpm
],
[0],
[hello-1.0-1.x86_64
],
[ignore])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([rpm -qp <glob>])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  -qp "/data/RPMS/hello-2.0-1.{i686,x86_64}.rpm"
],
[0],
[hello-2.0-1.i686
hello-2.0-1.x86_64
],
[])
RPMTEST_CLEANUP

AT_SETUP([rpm -qp <glob fallback>])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT

cp "${RPMTEST}/data/RPMS/hello-1.0-1.i386.rpm" \
   "${RPMTEST}/tmp/fallback-[[123]].0-1.i386.rpm"

runroot rpm \
  -qp "/tmp/fallback-[[123]].0-1.i386.rpm"
],
[0],
[hello-1.0-1.i386
],
[])
RPMTEST_CLEANUP

AT_SETUP([rpm -qp <notfound>])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  -qp /data/RPMS/hello-not-there-1.0-1.x86_64.rpm \
      /data/RPMS/hello-not-there-2.0-1.x86_64.rpm \
      /data/RPMS/hello-not-there-3.0-1.x86_64.rpm
],
[3],
[],
[error: open of /data/RPMS/hello-not-there-1.0-1.x86_64.rpm failed: No such file or directory
error: open of /data/RPMS/hello-not-there-2.0-1.x86_64.rpm failed: No such file or directory
error: open of /data/RPMS/hello-not-there-3.0-1.x86_64.rpm failed: No such file or directory
])
RPMTEST_CLEANUP

AT_SETUP([rpm -qp <glob notfound>])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  -qp "/data/RPMS/hello-not-there-*.x86_64.rpm" \
      /data/RPMS/hello-not-there-1.0-1.x86_64.rpm \
      /data/RPMS/hello-not-there-2.0-1.x86_64.rpm
],
[3],
[],
[error: open of /data/RPMS/hello-not-there-*.x86_64.rpm failed: No such file or directory
error: open of /data/RPMS/hello-not-there-1.0-1.x86_64.rpm failed: No such file or directory
error: open of /data/RPMS/hello-not-there-2.0-1.x86_64.rpm failed: No such file or directory
])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([rpm -ql -p *.src.rpm])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  -ql \
  -p /data/SRPMS/hello-1.0-1.src.rpm
],
[0],
[hello-1.0.tar.gz
hello.spec
],
[ignore])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([rpm -ql multiple *.rpm])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  -ql \
  /data/SRPMS/hello-1.0-1.src.rpm /data/RPMS/hello-1.0-1.i386.rpm
],
[0],
[hello-1.0.tar.gz
hello.spec
/usr/local/bin/hello
/usr/share/doc/hello-1.0
/usr/share/doc/hello-1.0/FAQ
],
[ignore])
RPMTEST_CLEANUP

AT_SETUP([rpm -qp --dump])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  -qp --dump \
  /data/RPMS/hello-2.0-1.x86_64.rpm
],
[0],
[/usr/bin/hello 7120 1489670606 c89fa87aeb1143969c0b6be9334b21d932f77f74e8f60120b5de316406369cf0 0100751 root root 0 0 0 X
/usr/share/doc/hello-2.0 4096 1489670606 0000000000000000000000000000000000000000000000000000000000000000 040755 root root 0 0 0 X
/usr/share/doc/hello-2.0/COPYING 48 908894882 fac3b28492ecdc16da172a6f1a432ceed356ca4d9248157b2a962b395e37b3b0 0100644 root root 0 1 0 X
/usr/share/doc/hello-2.0/FAQ 36 908895030 678b87e217a415f05e43460e2c7b668245b412e2b4f18a75aa7399d9774ed0b4 0100644 root root 0 1 0 X
/usr/share/doc/hello-2.0/README 39 908884468 d63fdc6c986106f57230f217d36b2395d83ecf491d2b7187af714dc8db9629e9 0100644 root root 0 1 0 X
],
[])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([rpmspec -q])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpmspec \
  -q --qf "%{name}" /data/SPECS/hello.spec
],
[0],
[hello],
[])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([rpm -ql -p *.i386.rpm])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  -ql \
  -p /data/RPMS/hello-1.0-1.i386.rpm
],
[0],
[/usr/local/bin/hello
/usr/share/doc/hello-1.0
/usr/share/doc/hello-1.0/FAQ
],
[ignore])
RPMTEST_CLEANUP

# ------------------------------
# Test query on manifest
AT_SETUP([rpm -qp <manifest>])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
cat << EOF > ${RPMTEST}/query.mft
/data/RPMS/hello-1.0-1.i386.rpm
/data/RPMS/hello-1.0-1.ppc64.rpm
/data/RPMS/foo-1.0-1.noarch.rpm
EOF
runroot rpm -qp --qf "%{nvr}\n" /query.mft
],
[0],
[hello-1.0-1
hello-1.0-1
foo-1.0-1
],
[])
RPMTEST_CLEANUP

# ------------------------------
# Try to check "scripts"
# * Gets rpmpopt-$(VERSION) involved
AT_SETUP([rpm -q --scripts -p *.i386.rpm])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  -q --scripts \
  -p /data/RPMS/hello-1.0-1.i386.rpm
],
[0],
[preinstall program: /bin/sh
postinstall program: /bin/sh
preuninstall program: /bin/sh
postuninstall program: /bin/sh
],
[ignore])
RPMTEST_CLEANUP


# ------------------------------
# install a package into a local rpmdb
# * Shall only work with relocation
# * Use --ignorearch because we don't know the arch
AT_SETUP([rpm -q on installed package])
AT_KEYWORDS([rpmdb install query])

RPMTEST_CHECK([
RPMDB_INIT

runroot rpm \
  --noscripts --nodeps --ignorearch --relocate=/usr=/check \
  -i /data/RPMS/hello-1.0-1.ppc64.rpm
],
[0])

# check common NVRA combinations
RPMTEST_CHECK([
runroot rpm \
  -q hello hello-1.0 hello-1.0-1 \
     hello.ppc64 hello-1.0.ppc64 hello-1.0-1.ppc64 
],
[0],
[hello-1.0-1.ppc64
hello-1.0-1.ppc64
hello-1.0-1.ppc64
hello-1.0-1.ppc64
hello-1.0-1.ppc64
hello-1.0-1.ppc64
],
[ignore])


RPMTEST_CHECK([
runroot rpm \
  -ql hello
],
[0],
[/check/local/bin/hello
/check/share/doc/hello-1.0
/check/share/doc/hello-1.0/FAQ
],
[ignore])

RPMTEST_CLEANUP

# ------------------------------
# query a package by a file
AT_SETUP([rpm -qf])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  --nodeps \
  --ignorearch \
  -i /data/RPMS/hello-1.0-1.i386.rpm
runroot rpm \
  -qf /usr/local/bin/hello
],
[0],
[hello-1.0-1.i386
],
[])
RPMTEST_CLEANUP

AT_SETUP([rpm -qf on non-installed file])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  --nodeps \
  --excludedocs \
  --ignorearch \
  -i /data/RPMS/hello-1.0-1.i386.rpm
runroot rpm \
  -qf /usr/share/doc/hello-1.0/FAQ
],
[1],
[],
[error: file /usr/share/doc/hello-1.0/FAQ: No such file or directory
])
RPMTEST_CLEANUP

AT_SETUP([rpm -q --path on non-installed file])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  --nodeps \
  --excludedocs \
  --ignorearch \
  -i /data/RPMS/hello-1.0-1.i386.rpm
runroot rpm \
  -q --path /usr/share/doc/hello-1.0/FAQ
],
[0],
[hello-1.0-1.i386
],
[])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([integer array query])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  --queryformat="[[%{filemodes}\n]]" \
  -qp /data/RPMS/hello-1.0-1.i386.rpm
],
[0],
[33257
16877
33188
],
[])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([formatted filesbypkg query])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  --queryformat="[[%-10{=NAME} %{FILENAMES}\n]]" \
  -qp /data/RPMS/hello-1.0-1.i386.rpm
],
[0],
[hello      /usr/local/bin/hello
hello      /usr/share/doc/hello-1.0
hello      /usr/share/doc/hello-1.0/FAQ
],
[])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([hex formatted integer array extension query])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  --queryformat="[[%5{longfilesizes:hex}\n]]" \
  -qp /data/RPMS/hello-1.0-1.i386.rpm
],
[0],
[  b40
 1000
   24
],
[])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([base64 extension query])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  --queryformat="%{pkgid:base64}" \
  -qp /data/RPMS/foo-1.0-1.noarch.rpm
],
[0],
[qt8W635v5FKy1pILrW+0uw==
],
[])
RPMTEST_CLEANUP

AT_SETUP([pgpsig extension query])
AT_KEYWORDS([query signature])
AT_SKIP_IF([test x$PGP = xdummy])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
    --queryformat="%{rsaheader:pgpsig}" \
    -qp /data/RPMS/hello-2.0-1.x86_64-signed.rpm
],
[0],
[RSA/SHA256, Thu Apr  6 13:02:33 2017, Key ID 4344591e1964c5fc],
[warning: /data/RPMS/hello-2.0-1.x86_64-signed.rpm: Header V4 RSA/SHA256 Signature, key ID 1964c5fc: NOKEY
])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([integer array perms format query])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  --queryformat="[[%{filemodes:perms}\n]]" \
  -qp /data/RPMS/hello-1.0-1.i386.rpm
],
[0],
[-rwxr-x--x
drwxr-xr-x
-rw-r--r--
],
[])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([string array query])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  --queryformat="[[%{basenames} ]]" \
  -qp /data/RPMS/hello-1.0-1.i386.rpm
],
[0],
[hello hello-1.0 FAQ ],
[])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([empty string array query])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  --queryformat="[[%{basenames}]]" \
  -qp /data/RPMS/foo-1.0-1.noarch.rpm
],
[0],
[],
[])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([empty string array extension array format])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  --queryformat="[[%{filenames}]]" \
  -qp /data/RPMS/foo-1.0-1.noarch.rpm
],
[0],
[],
[])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([empty string array extension query])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  --queryformat="%{filenames}" \
  -qp /data/RPMS/foo-1.0-1.noarch.rpm
],
[0],
[(none)],
[])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([different sizes arrays query 1])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  --queryformat="[[%{basenames} %{changelogname}]\n]" \
  -qp /data/RPMS/hello-1.0-1.i386.rpm
],
[0],
[],
[error: incorrect format: array iterator used with different sized arrays
])
RPMTEST_CLEANUP

# ------------------------------
# This is succeeds because there happens to be exactly one changelog entry
# so the size matches with name.
AT_SETUP([different sizes arrays query 2])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  --queryformat="[[%{name} %{changelogtime}]\n]" \
  -qp /data/RPMS/hello-1.0-1.i386.rpm
],
[0],
[hello 908877600
],
[])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([different sizes arrays query 3])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  --queryformat="[[%{name} %{basenames}]\n]" \
  -qp /data/RPMS/hello-1.0-1.i386.rpm
],
[0],
[],
[error: incorrect format: array iterator used with different sized arrays
])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([different sizes arrays query 4])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  --queryformat="[[%{=name} %{basenames}\n]]" \
  -qp /data/RPMS/hello-1.0-1.i386.rpm
],
[0],
[hello hello
hello hello-1.0
hello FAQ
],
[])

RPMTEST_CLEANUP
# ------------------------------
AT_SETUP([non-existent string tag])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  --queryformat="%{vendor}" \
  -qp /data/RPMS/foo-1.0-1.noarch.rpm
],
[0],
[(none)],
[])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([non-existent integer tag query])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  --queryformat="%{installcolor}" \
  -qp /data/RPMS/foo-1.0-1.noarch.rpm
],
[0],
[(none)],
[])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([conditional queryformat])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  --queryformat="%|name?{%{name}}:{no}| %|installtime?{%{installtime}}:{(not installed)}|" \
  -qp /data/RPMS/foo-1.0-1.noarch.rpm
],
[0],
[foo (not installed)],
[])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([invalid tag query])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  --queryformat="%{notag}" \
  -qp /data/RPMS/foo-1.0-1.noarch.rpm
],
[0],
[],
[error: incorrect format: unknown tag: "notag"
])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([invalid data for format query])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  --queryformat="%{name:depflags}" \
  -qp /data/RPMS/foo-1.0-1.noarch.rpm
],
[0],
[(not a number)],
[])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([invalid format width query])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  --queryformat="%ss{size}" \
  -qp /data/RPMS/foo-1.0-1.noarch.rpm
],
[0],
[],
[error: incorrect format: invalid field width
])
RPMTEST_CLEANUP

AT_SETUP([xml format])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm -qp --xml  /data/RPMS/hello-2.0-1.x86_64.rpm
],
[0],
[<rpmHeader>
  <rpmTag name="Headeri18ntable">
	<string>C</string>
  </rpmTag>
  <rpmTag name="Sigsize">
	<integer>5411</integer>
  </rpmTag>
  <rpmTag name="Sigmd5">
	<base64>E3yh2LNcygKhhUujAcVDLg==
</base64>
  </rpmTag>
  <rpmTag name="Sha1header">
	<string>5cd9874c510b67b44483f9e382a1649ef7743bac</string>
  </rpmTag>
  <rpmTag name="Sha256header">
	<string>ef920781af3bf072ae9888eec3de1c589143101dff9cc0b561468d395fb766d9</string>
  </rpmTag>
  <rpmTag name="Name">
	<string>hello</string>
  </rpmTag>
  <rpmTag name="Version">
	<string>2.0</string>
  </rpmTag>
  <rpmTag name="Release">
	<string>1</string>
  </rpmTag>
  <rpmTag name="Summary">
	<string>hello -- hello, world rpm</string>
  </rpmTag>
  <rpmTag name="Description">
	<string>Simple rpm demonstration.</string>
  </rpmTag>
  <rpmTag name="Buildtime">
	<integer>1227355200</integer>
  </rpmTag>
  <rpmTag name="Buildhost">
	<string>localhost</string>
  </rpmTag>
  <rpmTag name="Size">
	<integer>7243</integer>
  </rpmTag>
  <rpmTag name="License">
	<string>GPL</string>
  </rpmTag>
  <rpmTag name="Group">
	<string>Testing</string>
  </rpmTag>
  <rpmTag name="Os">
	<string>linux</string>
  </rpmTag>
  <rpmTag name="Arch">
	<string>x86_64</string>
  </rpmTag>
  <rpmTag name="Filesizes">
	<integer>7120</integer>
	<integer>4096</integer>
	<integer>48</integer>
	<integer>36</integer>
	<integer>39</integer>
  </rpmTag>
  <rpmTag name="Filemodes">
	<integer>33257</integer>
	<integer>16877</integer>
	<integer>33188</integer>
	<integer>33188</integer>
	<integer>33188</integer>
  </rpmTag>
  <rpmTag name="Filerdevs">
	<integer>0</integer>
	<integer>0</integer>
	<integer>0</integer>
	<integer>0</integer>
	<integer>0</integer>
  </rpmTag>
  <rpmTag name="Filemtimes">
	<integer>1489670606</integer>
	<integer>1489670606</integer>
	<integer>908894882</integer>
	<integer>908895030</integer>
	<integer>908884468</integer>
  </rpmTag>
  <rpmTag name="Filedigests">
	<string>c89fa87aeb1143969c0b6be9334b21d932f77f74e8f60120b5de316406369cf0</string>
	<string/>
	<string>fac3b28492ecdc16da172a6f1a432ceed356ca4d9248157b2a962b395e37b3b0</string>
	<string>678b87e217a415f05e43460e2c7b668245b412e2b4f18a75aa7399d9774ed0b4</string>
	<string>d63fdc6c986106f57230f217d36b2395d83ecf491d2b7187af714dc8db9629e9</string>
  </rpmTag>
  <rpmTag name="Filelinktos">
	<string/>
	<string/>
	<string/>
	<string/>
	<string/>
  </rpmTag>
  <rpmTag name="Fileflags">
	<integer>0</integer>
	<integer>0</integer>
	<integer>2</integer>
	<integer>2</integer>
	<integer>2</integer>
  </rpmTag>
  <rpmTag name="Fileusername">
	<string>root</string>
	<string>root</string>
	<string>root</string>
	<string>root</string>
	<string>root</string>
  </rpmTag>
  <rpmTag name="Filegroupname">
	<string>root</string>
	<string>root</string>
	<string>root</string>
	<string>root</string>
	<string>root</string>
  </rpmTag>
  <rpmTag name="Sourcerpm">
	<string>hello-2.0-1.src.rpm</string>
  </rpmTag>
  <rpmTag name="Fileverifyflags">
	<integer>4294967295</integer>
	<integer>0</integer>
	<integer>4294967295</integer>
	<integer>4294967295</integer>
	<integer>4294967295</integer>
  </rpmTag>
  <rpmTag name="Archivesize">
	<integer>8060</integer>
  </rpmTag>
  <rpmTag name="Providename">
	<string>hello</string>
	<string>hello(x86-64)</string>
  </rpmTag>
  <rpmTag name="Requireflags">
	<integer>16384</integer>
	<integer>16384</integer>
	<integer>16777226</integer>
	<integer>16777226</integer>
	<integer>16777226</integer>
	<integer>16384</integer>
  </rpmTag>
  <rpmTag name="Requirename">
	<string>libc.so.6()(64bit)</string>
	<string>libc.so.6(GLIBC_2.2.5)(64bit)</string>
	<string>rpmlib(CompressedFileNames)</string>
	<string>rpmlib(FileDigests)</string>
	<string>rpmlib(PayloadFilesHavePrefix)</string>
	<string>rtld(GNU_HASH)</string>
  </rpmTag>
  <rpmTag name="Requireversion">
	<string/>
	<string/>
	<string>3.0.4-1</string>
	<string>4.6.0-1</string>
	<string>4.0-1</string>
	<string/>
  </rpmTag>
  <rpmTag name="Rpmversion">
	<string>4.13.90</string>
  </rpmTag>
  <rpmTag name="Changelogtime">
	<integer>1227355200</integer>
	<integer>908884800</integer>
  </rpmTag>
  <rpmTag name="Changelogname">
	<string>Panu Matilainen &lt;pmatilai@redhat.com&gt;</string>
	<string>Jeff Johnson &lt;jbj@redhat.com&gt;</string>
  </rpmTag>
  <rpmTag name="Changelogtext">
	<string>- updated version</string>
	<string>- create.</string>
  </rpmTag>
  <rpmTag name="Filedevices">
	<integer>1</integer>
	<integer>1</integer>
	<integer>1</integer>
	<integer>1</integer>
	<integer>1</integer>
  </rpmTag>
  <rpmTag name="Fileinodes">
	<integer>1</integer>
	<integer>2</integer>
	<integer>3</integer>
	<integer>4</integer>
	<integer>5</integer>
  </rpmTag>
  <rpmTag name="Filelangs">
	<string/>
	<string/>
	<string/>
	<string/>
	<string/>
  </rpmTag>
  <rpmTag name="Prefixes">
	<string>/usr</string>
  </rpmTag>
  <rpmTag name="Provideflags">
	<integer>8</integer>
	<integer>8</integer>
  </rpmTag>
  <rpmTag name="Provideversion">
	<string>2.0-1</string>
	<string>2.0-1</string>
  </rpmTag>
  <rpmTag name="Dirindexes">
	<integer>0</integer>
	<integer>1</integer>
	<integer>2</integer>
	<integer>2</integer>
	<integer>2</integer>
  </rpmTag>
  <rpmTag name="Basenames">
	<string>hello</string>
	<string>hello-2.0</string>
	<string>COPYING</string>
	<string>FAQ</string>
	<string>README</string>
  </rpmTag>
  <rpmTag name="Dirnames">
	<string>/usr/bin/</string>
	<string>/usr/share/doc/</string>
	<string>/usr/share/doc/hello-2.0/</string>
  </rpmTag>
  <rpmTag name="Optflags">
	<string>-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic</string>
  </rpmTag>
  <rpmTag name="Payloadformat">
	<string>cpio</string>
  </rpmTag>
  <rpmTag name="Payloadcompressor">
	<string>gzip</string>
  </rpmTag>
  <rpmTag name="Payloadflags">
	<string>9</string>
  </rpmTag>
  <rpmTag name="Platform">
	<string>x86_64-redhat-linux-gnu</string>
  </rpmTag>
  <rpmTag name="Filecolors">
	<integer>2</integer>
	<integer>0</integer>
	<integer>0</integer>
	<integer>0</integer>
	<integer>0</integer>
  </rpmTag>
  <rpmTag name="Fileclass">
	<integer>0</integer>
	<integer>1</integer>
	<integer>2</integer>
	<integer>2</integer>
	<integer>2</integer>
  </rpmTag>
  <rpmTag name="Classdict">
	<string>ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[[sha1]]=775fdcb927e4300adbe83cfacec3cfeb1f63fe17, stripped</string>
	<string>directory</string>
	<string>ASCII text</string>
  </rpmTag>
  <rpmTag name="Filedependsx">
	<integer>0</integer>
	<integer>0</integer>
	<integer>0</integer>
	<integer>0</integer>
	<integer>0</integer>
  </rpmTag>
  <rpmTag name="Filedependsn">
	<integer>3</integer>
	<integer>0</integer>
	<integer>0</integer>
	<integer>0</integer>
	<integer>0</integer>
  </rpmTag>
  <rpmTag name="Dependsdict">
	<integer>1375731713</integer>
	<integer>1375731712</integer>
	<integer>1375731717</integer>
  </rpmTag>
  <rpmTag name="Filedigestalgo">
	<integer>8</integer>
  </rpmTag>
  <rpmTag name="Encoding">
	<string>utf-8</string>
  </rpmTag>
  <rpmTag name="Payloaddigest">
	<string>84a7338287bf19715c4eed0243f5cdb447eeb0ade37b2af718d4060aefca2f7c</string>
  </rpmTag>
  <rpmTag name="Payloaddigestalgo">
	<integer>8</integer>
  </rpmTag>
</rpmHeader>
],
[])
RPMTEST_CLEANUP

AT_SETUP([json format 1])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm -qp --json  /data/RPMS/hello-2.0-1.x86_64.rpm
],
[0],
[[{
    "Headeri18ntable": 	"C",
    "Sigsize": 	5411,
    "Sigmd5": 	"E3yh2LNcygKhhUujAcVDLg==",
    "Sha1header": 	"5cd9874c510b67b44483f9e382a1649ef7743bac",
    "Sha256header": 	"ef920781af3bf072ae9888eec3de1c589143101dff9cc0b561468d395fb766d9",
    "Name": 	"hello",
    "Version": 	"2.0",
    "Release": 	"1",
    "Summary": 	"hello -- hello, world rpm",
    "Description": 	"Simple rpm demonstration.",
    "Buildtime": 	1227355200,
    "Buildhost": 	"localhost",
    "Size": 	7243,
    "License": 	"GPL",
    "Group": 	"Testing",
    "Os": 	"linux",
    "Arch": 	"x86_64",
    "Filesizes": [
	7120,
	4096,
	48,
	36,
	39
    ],
    "Filemodes": [
	33257,
	16877,
	33188,
	33188,
	33188
    ],
    "Filerdevs": [
	0,
	0,
	0,
	0,
	0
    ],
    "Filemtimes": [
	1489670606,
	1489670606,
	908894882,
	908895030,
	908884468
    ],
    "Filedigests": [
	"c89fa87aeb1143969c0b6be9334b21d932f77f74e8f60120b5de316406369cf0",
	"",
	"fac3b28492ecdc16da172a6f1a432ceed356ca4d9248157b2a962b395e37b3b0",
	"678b87e217a415f05e43460e2c7b668245b412e2b4f18a75aa7399d9774ed0b4",
	"d63fdc6c986106f57230f217d36b2395d83ecf491d2b7187af714dc8db9629e9"
    ],
    "Filelinktos": [
	"",
	"",
	"",
	"",
	""
    ],
    "Fileflags": [
	0,
	0,
	2,
	2,
	2
    ],
    "Fileusername": [
	"root",
	"root",
	"root",
	"root",
	"root"
    ],
    "Filegroupname": [
	"root",
	"root",
	"root",
	"root",
	"root"
    ],
    "Sourcerpm": 	"hello-2.0-1.src.rpm",
    "Fileverifyflags": [
	4294967295,
	0,
	4294967295,
	4294967295,
	4294967295
    ],
    "Archivesize": 	8060,
    "Providename": [
	"hello",
	"hello(x86-64)"
    ],
    "Requireflags": [
	16384,
	16384,
	16777226,
	16777226,
	16777226,
	16384
    ],
    "Requirename": [
	"libc.so.6()(64bit)",
	"libc.so.6(GLIBC_2.2.5)(64bit)",
	"rpmlib(CompressedFileNames)",
	"rpmlib(FileDigests)",
	"rpmlib(PayloadFilesHavePrefix)",
	"rtld(GNU_HASH)"
    ],
    "Requireversion": [
	"",
	"",
	"3.0.4-1",
	"4.6.0-1",
	"4.0-1",
	""
    ],
    "Rpmversion": 	"4.13.90",
    "Changelogtime": [
	1227355200,
	908884800
    ],
    "Changelogname": [
	"Panu Matilainen <pmatilai@redhat.com>",
	"Jeff Johnson <jbj@redhat.com>"
    ],
    "Changelogtext": [
	"- updated version",
	"- create."
    ],
    "Filedevices": [
	1,
	1,
	1,
	1,
	1
    ],
    "Fileinodes": [
	1,
	2,
	3,
	4,
	5
    ],
    "Filelangs": [
	"",
	"",
	"",
	"",
	""
    ],
    "Prefixes": 	"/usr",
    "Provideflags": [
	8,
	8
    ],
    "Provideversion": [
	"2.0-1",
	"2.0-1"
    ],
    "Dirindexes": [
	0,
	1,
	2,
	2,
	2
    ],
    "Basenames": [
	"hello",
	"hello-2.0",
	"COPYING",
	"FAQ",
	"README"
    ],
    "Dirnames": [
	"/usr/bin/",
	"/usr/share/doc/",
	"/usr/share/doc/hello-2.0/"
    ],
    "Optflags": 	"-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic",
    "Payloadformat": 	"cpio",
    "Payloadcompressor": 	"gzip",
    "Payloadflags": 	"9",
    "Platform": 	"x86_64-redhat-linux-gnu",
    "Filecolors": [
	2,
	0,
	0,
	0,
	0
    ],
    "Fileclass": [
	0,
	1,
	2,
	2,
	2
    ],
    "Classdict": [
	"ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=775fdcb927e4300adbe83cfacec3cfeb1f63fe17, stripped",
	"directory",
	"ASCII text"
    ],
    "Filedependsx": [
	0,
	0,
	0,
	0,
	0
    ],
    "Filedependsn": [
	3,
	0,
	0,
	0,
	0
    ],
    "Dependsdict": [
	1375731713,
	1375731712,
	1375731717
    ],
    "Filedigestalgo": 	8,
    "Encoding": 	"utf-8",
    "Payloaddigest": 	"84a7338287bf19715c4eed0243f5cdb447eeb0ade37b2af718d4060aefca2f7c",
    "Payloaddigestalgo": 	8
}
]],
[])
RPMTEST_CLEANUP

AT_SETUP([json format 2])
AT_KEYWORDS([query])
RPMDB_INIT
runroot rpmbuild --quiet -bb /data/SPECS/weirdnames.spec

RPMTEST_CHECK([
runroot rpm -q --json /build/RPMS/noarch/weirdnames-1.0-1.noarch.rpm
],
[0],
[stdout],
[])

RPMPY_CHECK([
import json
s = open('stdout').read()
print(len(json.loads(s)))
],
[58
],
[])
RPMTEST_CLEANUP


AT_SETUP([query file attribute filtering])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpmbuild -bb --quiet \
  /data/SPECS/vattrtest.spec

pkg="/build/RPMS/noarch/vattrtest-1.0-1.noarch.rpm"
cmd="rpm -qpl"
for filter in --noconfig --noghost --noartifact -A -c -d -L; do
    echo ${filter}
    runroot ${cmd} ${filter} ${pkg}
done
],
[0],
[--noconfig
/opt/vattrtest
/opt/vattrtest/a
/opt/vattrtest/d
/opt/vattrtest/g
/opt/vattrtest/l
/opt/vattrtest/m
/opt/vattrtest/r
--noghost
/opt/vattrtest
/opt/vattrtest/a
/opt/vattrtest/c
/opt/vattrtest/cn
/opt/vattrtest/d
/opt/vattrtest/l
/opt/vattrtest/m
/opt/vattrtest/r
--noartifact
/opt/vattrtest
/opt/vattrtest/c
/opt/vattrtest/cn
/opt/vattrtest/d
/opt/vattrtest/g
/opt/vattrtest/l
/opt/vattrtest/m
/opt/vattrtest/r
-A
/opt/vattrtest/a
-c
/opt/vattrtest/c
/opt/vattrtest/cn
-d
/opt/vattrtest/d
-L
/opt/vattrtest/l
],
[])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([formatting name humansi, humaniec])
AT_KEYWORDS([query, humansi, humaniec])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  --queryformat '%{SIZE:humansi} %{SIZE:humaniec}\n' \
  -qp /data/RPMS/hello-1.0-1.i386.rpm
runroot rpm \
  --queryformat '%{SIZE:humansi} %{SIZE:humaniec}\n' \
  -qp /data/RPMS/foo-1.0-1.noarch.rpm
runroot rpm \
  --queryformat '%{SIZE:humansi} %{SIZE:humaniec}\n' \
  -qp /data/SRPMS/foo-1.0-1.src.rpm
],
[0],
[2.9K 2.8K
0 0
355 355
],
[])
RPMTEST_CLEANUP

# ------------------------------
AT_SETUP([incomplete escape sequence for format query])
AT_KEYWORDS([query])
RPMTEST_CHECK([
RPMDB_INIT
runroot rpm \
  --queryformat='%{NAME}\n\' \
  -qp /data/RPMS/foo-1.0-1.noarch.rpm
],
[0],
[],
[error: incorrect format: escaped char expected after \
],
)
RPMTEST_CLEANUP

AT_SETUP([query format iteration])
AT_KEYWORDS([query])
RPMDB_INIT

RPMTEST_CHECK([
runroot rpmspec -q --qf "[[%{*:tagnum}\n]]" --srpm /data/SPECS/mini.spec
],
[0],
[100
1000
1001
1002
1004
1005
1014
1016
1021
1022
1106
],
[])

RPMTEST_CHECK([
runroot rpmspec -q --qf "[[%{*:tagname}\n]]" --srpm /data/SPECS/mini.spec
],
[0],
[Headeri18ntable
Name
Version
Release
Summary
Description
License
Group
Os
Arch
Sourcepackage
],
[])
RPMTEST_CLEANUP
