Add a test for libecpg library

This commit is contained in:
Honza Horak 2020-11-23 19:30:50 +01:00
commit 9b6c413512
4 changed files with 185 additions and 0 deletions

27
Sanity/libecpg/main.fmf Normal file
View file

@ -0,0 +1,27 @@
summary: Sanity test for libecpg library
description: ''
contact: Honza Horak <hhorak@redhat.com>
component:
- libecpg
test: ./runtest.sh
path: /Sanity/libecpg
framework: beakerlib
require:
- url: https://github.com/beakerlib/database.git
name: /postgresql
ref: master
recommend:
- postgresql-server
- libecpg-devel
- gcc-c++
duration: 5m
enabled: true
tag:
- NoRHEL4
- NoRHEL5
- NoRHEL6
- TIPfail
- TIPfail_Apps
- Tier1
tier: '1'
extra-task: /CoreOS/postgresql/Sanity/libecpg

90
Sanity/libecpg/runtest.sh Executable file
View file

@ -0,0 +1,90 @@
#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/postgresql/Sanity/libecpg
# Description: Sanity test for libecpg library
# Author: Honza Horak <hhorak@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2015 Red Hat, Inc.
#
# 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, see http://www.gnu.org/licenses/.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="postgresql"
PACKAGE_LIBECPG_DEVEL="libecpg-devel"
rlJournalStart
rlPhaseStart FAIL "Setup"
rlRun "rlImport database/postgresql"
PGDATA="$(postgresqlDataDir)";
PACKAGES="$PACKAGES ${postgresqlPackagePrefix}${PACKAGE_LIBECPG_DEVEL} \
${postgresqlPackagePrefix}${PACKAGE} \
${postgresqlPackagePrefix}${PACKAGE}-server";
for PACKAGE in $PACKAGES; do
rlAssertRpm $PACKAGE
done
rlRun "TestDir=$PWD"
rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
rlRun "pushd $TmpDir"
rlPhaseEnd
rlPhaseStartSetup "Database setup"
varDump postgresqlDataDir;
[[ -d $postgresqlDataDir ]] && rlFileBackup $postgresqlDataDir;
postgresqlCleanup;
postgresqlInitDB;
rlRun "postgresqlChangeAuth trust" 0 "Allow 'trust' authentication"
#rlRun "sed -i -e 's/ident/trust/' ${postgresqlDataDir}/pg_hba.conf" 0 "Allow 'trust' authentication"
cat /var/lib/pgsql/data/pg_hba.conf
postgresqlStart;
rlPhaseEnd
rlPhaseStartTest
postgresqlExec "createdb testdb" "postgres"
rlRun "cp $TestDir/testecpg-decimal.pgc ."
rlRun "ecpg testecpg-decimal.pgc"
rlRun "cc -o testecpg-decimal testecpg-decimal.c -lecpg -lpgtypes"
rlRun "chown postgres:postgres *"
rlRun -s "./testecpg-decimal"
rlAssertGrep "numeric = 12" $rlRun_LOG
rlAssertGrep "numeric = 12.4" $rlRun_LOG
rlAssertGrep "numeric = 12.35" $rlRun_LOG
rlAssertGrep "decimal = 23" $rlRun_LOG
rlAssertGrep "decimal = 23.5" $rlRun_LOG
rlAssertGrep "decimal = 23.46" $rlRun_LOG
rlRun "cp $TestDir/testecpg-interval.pgc ."
rlRun "ecpg testecpg-interval.pgc"
rlRun "cc -o testecpg-interval testecpg-interval.c -lecpg -lpgtypes"
rlRun -s "./testecpg-interval"
rlAssertGrep "interval = @ 1 min" $rlRun_LOG
rlPhaseEnd
rlPhaseStart WARN "Cleanup";
rlRun "popd"
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
rm -f $rlRun_LOG;
rlRun "postgresqlCleanup";
rlFileRestore;
rlPhaseEnd
rlJournalPrintText
rlJournalEnd

View file

@ -0,0 +1,44 @@
// Taken from https://www.postgresql.org/docs/13/ecpg-variables.html
#include <stdio.h>
#include <stdlib.h>
#include <pgtypes_numeric.h>
EXEC SQL WHENEVER SQLERROR STOP;
int
main(void)
{
EXEC SQL BEGIN DECLARE SECTION;
numeric *num;
numeric *num2;
decimal *dec;
EXEC SQL END DECLARE SECTION;
EXEC SQL CONNECT TO testdb USER postgres;
num = PGTYPESnumeric_new();
dec = PGTYPESdecimal_new();
EXEC SQL SELECT 12.345::numeric(4,2), 23.456::decimal(4,2) INTO :num, :dec;
printf("numeric = %s\n", PGTYPESnumeric_to_asc(num, 0));
printf("numeric = %s\n", PGTYPESnumeric_to_asc(num, 1));
printf("numeric = %s\n", PGTYPESnumeric_to_asc(num, 2));
/* Convert decimal to numeric to show a decimal value. */
num2 = PGTYPESnumeric_new();
PGTYPESnumeric_from_decimal(dec, num2);
printf("decimal = %s\n", PGTYPESnumeric_to_asc(num2, 0));
printf("decimal = %s\n", PGTYPESnumeric_to_asc(num2, 1));
printf("decimal = %s\n", PGTYPESnumeric_to_asc(num2, 2));
PGTYPESnumeric_free(num2);
PGTYPESdecimal_free(dec);
PGTYPESnumeric_free(num);
EXEC SQL COMMIT;
EXEC SQL DISCONNECT ALL;
return 0;
}

View file

@ -0,0 +1,24 @@
// Taken from https://www.postgresql.org/docs/13/ecpg-variables.html
#include <stdio.h>
#include <stdlib.h>
#include <pgtypes_interval.h>
int
main(void)
{
EXEC SQL BEGIN DECLARE SECTION;
interval *in;
EXEC SQL END DECLARE SECTION;
EXEC SQL CONNECT TO testdb USER postgres;
in = PGTYPESinterval_new();
EXEC SQL SELECT '1 min'::interval INTO :in;
printf("interval = %s\n", PGTYPESinterval_to_asc(in));
PGTYPESinterval_free(in);
EXEC SQL COMMIT;
EXEC SQL DISCONNECT ALL;
return 0;
}