From a970695ff45f8ba3f235ffdf9e5356c267dcfda7 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 30 Oct 2017 18:59:57 +0200 Subject: [PATCH] Commit tests fort libunistring to new-tests branch --- README.md | 3 + libunistring-tests/Makefile | 63 +++++++++++++++++++ libunistring-tests/libunistring_test.py | 79 ++++++++++++++++++++++++ libunistring-tests/runtest.sh | 54 ++++++++++++++++ libunistring-tests/test | Bin 0 -> 8896 bytes libunistring-tests/test.c | 37 +++++++++++ tests.yml | 23 +++++++ 7 files changed, 259 insertions(+) create mode 100644 README.md create mode 100644 libunistring-tests/Makefile create mode 100644 libunistring-tests/libunistring_test.py create mode 100644 libunistring-tests/runtest.sh create mode 100755 libunistring-tests/test create mode 100644 libunistring-tests/test.c create mode 100644 tests.yml diff --git a/README.md b/README.md new file mode 100644 index 0000000..fd5c17f --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# libunistring + +This project conatains libunistring i18n testcases diff --git a/libunistring-tests/Makefile b/libunistring-tests/Makefile new file mode 100644 index 0000000..b4a5f93 --- /dev/null +++ b/libunistring-tests/Makefile @@ -0,0 +1,63 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/python/libunistring-tests +# Description: Functional tests for libunistring. +# Author: Pooja Yadav +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# 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/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +export TEST=/CoreOS/python/libunistring-tests +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) libunistring_test.py Makefile test runtest.sh + +.PHONY: all install download clean + +run: $(FILES) build + ./runtest.sh + +build: $(BUILT_FILES) + test -x runtest.sh || chmod a+x runtest.sh + +clean: + rm -f *~ $(BUILT_FILES) + +include /usr/share/rhts/lib/rhts-make.include + +$(METADATA): Makefile + @echo "Owner: Pooja Yadav " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Functional test for the gettext module" >> $(METADATA) + @echo "Type: Sanity" >> $(METADATA) + @echo "TestTime: 5m" >> $(METADATA) + @echo "RunFor: python" >> $(METADATA) + @echo "Requires: python" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) + diff --git a/libunistring-tests/libunistring_test.py b/libunistring-tests/libunistring_test.py new file mode 100644 index 0000000..a9c688e --- /dev/null +++ b/libunistring-tests/libunistring_test.py @@ -0,0 +1,79 @@ +# -*- coding: utf-8 -*- + +import os +import subprocess +import logging + +""" +Creating a result.log file for saving logs +""" +logging.basicConfig(level=logging.INFO) + +logging.info("TEST RESULTS FOR FUNCTION\n\n") + +data = [] + +def create_testfile(): + testfile = subprocess.call("./test 'Bonjour le monde'" , shell=True) + with open("./testfile.in") as fh: + lines = fh.readlines() + global data + data = lines + +def test_utf8(): + """ + Check UTF-8 encoding + """ + try: + conv8 = data[0].strip("\n").decode('utf-8') + conv16 = data[0].strip("\n").decode('utf-16') + if conv8 == ("Bonjour le monde") and conv16 != ("Bonjour le monde"): + logging.info("UTF-8 Conversion Test: SUCCESS") + else: + logging.error("UTF-8 Conversion Test: ERROR") + except UnicodeError: + logging.error("UTF-8 Conversion Test: UnicodeError") + +def test_utf_16(): + """ + Check UTF-16 encoding + """ + try: + conv16 = data[1].strip("\n").decode('utf-16') + conv8 = data[1].strip("\n").decode('utf-8') + if conv16 == ("Bonjour le monde") and conv8 != ("Bonjour le monde"): + logging.info("UTF-16 Conversion Test: SUCCESS") + else: + logging.error("UTF-16 Conversion Test: ERROR") + except UnicodeError: + logging.error("UTF-16 Conversion Test: UnicodeError") + +def test_utf_32(): + """ + Check UTF-32 encoding + """ + try: + conv8 = data[2].strip("\n").decode('utf-8') + conv16= data[2].strip("\n").decode('utf-16') + conv32 = data[2].strip("\n").decode('utf-32') + if conv32 == ("Bonjour le monde") and conv8 and conv16 != ("Bonjour le monde"): + logging.info("UTF-32 Conversion Test: SUCCESS") + else: + logging.error("UTF-32 Conversion Test: ERROR") + except UnicodeError: + logging.error("UTF-32 Conversion Test: UnicodeError") + +def del_testfile(): + try: + subprocess.call(['rm', '-rf', './testfile.in']) + except OSError as e: + logging.error("OSError\n") + + +if __name__ == "__main__": + del_testfile() + create_testfile() + test_utf8() + test_utf_16() + test_utf_32() + diff --git a/libunistring-tests/runtest.sh b/libunistring-tests/runtest.sh new file mode 100644 index 0000000..64e85ac --- /dev/null +++ b/libunistring-tests/runtest.sh @@ -0,0 +1,54 @@ +#!/bin/bash +# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/python/libunistring-tests +# Description: Functional tests for libunistring to check i18n features. +# Author: Pooja Yadav +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2010 Red Hat, Inc. All rights reserved. +# +# This copyrighted material is made available to anyone wishing +# to use, modify, copy, or redistribute it subject to the terms +# and conditions of the GNU General Public License version 2. +# +# 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. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/bin/rhts-environment.sh +. /usr/lib/beakerlib/beakerlib.sh + +PACKAGE="libunistring" + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm $PACKAGE + rlRun "TmpDir=\`mktemp -d\`" 0 "Creating tmp directory" + rlRun "cp libunistring_test.py test $TmpDir" + rlRun "pushd $TmpDir" + rlPhaseEnd + + rlPhaseStartTest + rlLog "Run libunistring_test.py" + rlRun "python libunistring_test.py" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "popd" + rlRun "rm -r $TmpDir" 0 "Removing tmp directory" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd + diff --git a/libunistring-tests/test b/libunistring-tests/test new file mode 100755 index 0000000000000000000000000000000000000000..41243b5965254045593f6963a99c44aa3cbd364a GIT binary patch literal 8896 zcmeHMeQaCR6~DHd#Qk#ILbtSKt2NrLg~cSLgaBKylem3hY3b6Gb%OHZ#?HrZ?96^H zErQW0P|XWr)jm+QX;S_e64LksO=y%3wdse_g2ogWXcZeGV(XMp*iy(?1SQ_@+;`8* z^Rtc6Chf0X>%DW&@1Aq+_kH&qKOAY>>UOyVC%4!lh#RR2NyvN)5n3%-g*A$WA|$>j zR*Om?6?j6jgs7QgI;%`G^(r|J=mI>AZWCy9hh&E7H6|>Watn!4ee)@#vL-#d#AKNY z5s(1sQCnx1N*1(JW|+oQJ9-smJz`1E?~~%7o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s7a!GbC&@5Izjof7Bh4l1CNLD7kq*j{PMCiyg?2&&K+EuO3&xdDUU^ z`zXu$HON!C3lI5ptk3uFqpG3o7m_R`=lIMW2sjP3^`$++b{Yqu7sQ-^ZhV+|A7>WIZI;B4 +#include +#include +#include +#include +#include +#include + +int +main (int argc, char **argv) +{ + if (argc < 2) { + printf ("Usage: %s \n", argv[0]); + return 1; + } + + size_t len8, len16, len32; + const char newline = '\n'; + + uint8_t *res8 = u8_conv_from_encoding ("ASCII", iconveh_question_mark, argv[1], strlen (argv[1]), NULL, NULL, &len8); + uint16_t *res16 = u16_conv_from_encoding ("ASCII", iconveh_question_mark, argv[1], strlen (argv[1]), NULL, NULL, &len16); + uint32_t *res32 = u32_conv_from_encoding ("ASCII", iconveh_question_mark, argv[1], strlen (argv[1]), NULL, NULL, &len32); + + int fd = open ("testfile.in", O_WRONLY | O_CREAT, S_IRUSR); + + for (int i = 0; i < len8; i++) + write (fd, &res8[i], sizeof (uint8_t)); + write (fd, &newline, 1); + for (int i = 0; i < len16; i++) + write (fd, &res16[i], sizeof (uint16_t)); + write (fd, &newline, 1); + for (int i = 0; i < len32; i++) + write (fd, &res32[i], sizeof (uint32_t)); + + close (fd); +} + diff --git a/tests.yml b/tests.yml new file mode 100644 index 0000000..1b4c3ec --- /dev/null +++ b/tests.yml @@ -0,0 +1,23 @@ +--- + +# Tests for Atomic +- hosts: localhost + tags: + - atomic + roles: + - role: standard-test-beakerlib + tests: + - libunistring-tests + +# Tests for Classic and Container +- hosts: localhost + tags: + - classic + - container + roles: + - role: standard-test-beakerlib + tests: + - libunistring-tests + required_packages: + - libunistring + - libunistring-devel