AT_BANNER([Rpm development])

AT_SETUP([rpm API user])
AT_KEYWORDS([devel])

cat << EOF > CMakeLists.txt
cmake_minimum_required(VERSION 3.18)
project(trpm VERSION 1.0 DESCRIPTION "test rpm API" LANGUAGES C)

find_package(rpm REQUIRED)
add_executable(trpm trpm.c)
target_link_libraries(trpm PRIVATE rpm::librpm)
EOF

cat << EOF > trpm.c
#include <stdio.h>
#include <rpm/rpmlib.h>

int main(int argc, char *argv[])
{
	int rc = rpmReadConfigFiles(NULL, NULL);
	printf("%s: %d\n", RPMVERSION, rc);
	rpmFreeRpmrc();
	return rc;
}
EOF

cmake . && make

RPMTEST_CHECK([[
LD_PRELOAD=${ASANLIB} ./trpm
]],
[0],
[AT_PACKAGE_VERSION: 0]
)
RPMTEST_CLEANUP

AT_SETUP([rpm plugin development])
AT_KEYWORDS([devel])
RPMDB_INIT

runroot rpmbuild --quiet -bb \
	/data/SPECS/simple.spec \
	/data/SPECS/fakeshell.spec

runroot rpm -U /build/RPMS/noarch/fakeshell-1.0-1.noarch.rpm

cmake /data/debugplugin && make && make install DESTDIR=${RPMTEST}

RPMTEST_CHECK([
runroot rpm -U /build/RPMS/noarch/simple-1.0-1.noarch.rpm
],
[0],
[],
[debug_init
debug_tsm_pre
debug_psm_pre: simple-1.0-1.noarch
debug_fsm_file_pre:  /opt/bin 40755 80000001
debug_fsm_file_prepare:  1 /opt/bin /opt/bin 40755 80000001
debug_fsm_file_post:  /opt/bin 40755 80000001: 0
debug_fsm_file_pre: /opt/bin/simple /opt/bin/simple; 100755 1
debug_fsm_file_prepare: /opt/bin/simple 1 /opt/bin/simple; /opt/bin/simple 100755 1
debug_fsm_file_post: /opt/bin/simple /opt/bin/simple 100755 1: 0
debug_scriptlet_pre: %post(simple-1.0-1.noarch) 3
debug_scriptlet_fork_post: /bin/sh 3
debug_scriptlet_post: %post(simple-1.0-1.noarch) 3: 0
debug_psm_post: simple-1.0-1.noarch:0
debug_psm_pre: simple-1.0-1.noarch
debug_psm_post: simple-1.0-1.noarch:0
debug_tsm_post: 0
debug_cleanup
])
RPMTEST_CLEANUP

