From 5e0ff113cc45e03ab8f9e1bd1a4eaccfa4fe8d11 Mon Sep 17 00:00:00 2001 From: Honza Horak Date: Mon, 23 Nov 2020 19:30:50 +0100 Subject: [PATCH] Add a test for libecpg library --- Sanity/libecpg/main.fmf | 27 +++++++++ Sanity/libecpg/runtest.sh | 90 ++++++++++++++++++++++++++++ Sanity/libecpg/testecpg-decimal.pgc | 44 ++++++++++++++ Sanity/libecpg/testecpg-interval.pgc | 24 ++++++++ 4 files changed, 185 insertions(+) create mode 100644 Sanity/libecpg/main.fmf create mode 100755 Sanity/libecpg/runtest.sh create mode 100644 Sanity/libecpg/testecpg-decimal.pgc create mode 100644 Sanity/libecpg/testecpg-interval.pgc diff --git a/Sanity/libecpg/main.fmf b/Sanity/libecpg/main.fmf new file mode 100644 index 0000000..79825db --- /dev/null +++ b/Sanity/libecpg/main.fmf @@ -0,0 +1,27 @@ +summary: Sanity test for libecpg library +description: '' +contact: Honza Horak +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 diff --git a/Sanity/libecpg/runtest.sh b/Sanity/libecpg/runtest.sh new file mode 100755 index 0000000..c7ff309 --- /dev/null +++ b/Sanity/libecpg/runtest.sh @@ -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 +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# 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 diff --git a/Sanity/libecpg/testecpg-decimal.pgc b/Sanity/libecpg/testecpg-decimal.pgc new file mode 100644 index 0000000..d22a77c --- /dev/null +++ b/Sanity/libecpg/testecpg-decimal.pgc @@ -0,0 +1,44 @@ +// Taken from https://www.postgresql.org/docs/13/ecpg-variables.html + +#include +#include +#include + +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; +} diff --git a/Sanity/libecpg/testecpg-interval.pgc b/Sanity/libecpg/testecpg-interval.pgc new file mode 100644 index 0000000..d065911 --- /dev/null +++ b/Sanity/libecpg/testecpg-interval.pgc @@ -0,0 +1,24 @@ +// Taken from https://www.postgresql.org/docs/13/ecpg-variables.html + +#include +#include +#include + +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; +}