From 463742d981b4e03505c2f14a108d3523ff7367d4 Mon Sep 17 00:00:00 2001 From: Jaroslav Rohel Date: Tue, 1 Oct 2024 10:27:20 +0200 Subject: [PATCH] Unit tests for libdnf5::utils::[is_glob_pattern | is_file_pattern] Includes C++, Perl, Python and Ruby tests. --- test/libdnf5/utils/test_patterns.cpp | 44 +++++++++++++++++++++ test/libdnf5/utils/test_patterns.hpp | 37 +++++++++++++++++ test/perl5/libdnf5/utils/test_patterns.t | 41 +++++++++++++++++++ test/python3/libdnf5/utils/__init__.py | 0 test/python3/libdnf5/utils/test_patterns.py | 36 +++++++++++++++++ test/ruby/libdnf5/utils/test_patterns.rb | 39 ++++++++++++++++++ 6 files changed, 197 insertions(+) create mode 100644 test/libdnf5/utils/test_patterns.cpp create mode 100644 test/libdnf5/utils/test_patterns.hpp create mode 100644 test/perl5/libdnf5/utils/test_patterns.t create mode 100644 test/python3/libdnf5/utils/__init__.py create mode 100644 test/python3/libdnf5/utils/test_patterns.py create mode 100644 test/ruby/libdnf5/utils/test_patterns.rb diff --git a/test/libdnf5/utils/test_patterns.cpp b/test/libdnf5/utils/test_patterns.cpp new file mode 100644 index 000000000..ccb58f7ab --- /dev/null +++ b/test/libdnf5/utils/test_patterns.cpp @@ -0,0 +1,44 @@ +/* +Copyright Contributors to the libdnf project. + +This file is part of libdnf: https://github.com/rpm-software-management/libdnf/ + +Libdnf 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. + +Libdnf 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 libdnf. If not, see . +*/ + +#include "test_patterns.hpp" + +#include + +using namespace libdnf5::utils; + +CPPUNIT_TEST_SUITE_REGISTRATION(UtilsPatternsTest); + + +void UtilsPatternsTest::test_is_file_pattern() { + CPPUNIT_ASSERT(!is_file_pattern("")); + CPPUNIT_ASSERT(!is_file_pattern("no_file_pattern")); + CPPUNIT_ASSERT(!is_file_pattern("no_file/pattern")); + CPPUNIT_ASSERT(is_file_pattern("/pattern")); + CPPUNIT_ASSERT(is_file_pattern("*/pattern")); +} + + +void UtilsPatternsTest::test_is_glob_pattern() { + CPPUNIT_ASSERT(!is_glob_pattern("")); + CPPUNIT_ASSERT(!is_glob_pattern("no_glob_pattern")); + CPPUNIT_ASSERT(is_glob_pattern("glob*_pattern")); + CPPUNIT_ASSERT(is_glob_pattern("glob[sdf]_pattern")); + CPPUNIT_ASSERT(is_glob_pattern("glob?_pattern")); +} diff --git a/test/libdnf5/utils/test_patterns.hpp b/test/libdnf5/utils/test_patterns.hpp new file mode 100644 index 000000000..f35e1be95 --- /dev/null +++ b/test/libdnf5/utils/test_patterns.hpp @@ -0,0 +1,37 @@ +/* +Copyright Contributors to the libdnf project. + +This file is part of libdnf: https://github.com/rpm-software-management/libdnf/ + +Libdnf 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. + +Libdnf 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 libdnf. If not, see . +*/ + +#ifndef LIBDNF5_TEST_UTILS_PATTERNS_HPP +#define LIBDNF5_TEST_UTILS_PATTERNS_HPP + +#include +#include + +class UtilsPatternsTest : public CppUnit::TestCase { + CPPUNIT_TEST_SUITE(UtilsPatternsTest); + CPPUNIT_TEST(test_is_file_pattern); + CPPUNIT_TEST(test_is_glob_pattern); + CPPUNIT_TEST_SUITE_END(); + +public: + void test_is_file_pattern(); + void test_is_glob_pattern(); +}; + +#endif // LIBDNF5_TEST_UTILS_PATTERNS_HPP diff --git a/test/perl5/libdnf5/utils/test_patterns.t b/test/perl5/libdnf5/utils/test_patterns.t new file mode 100644 index 000000000..24cff3be8 --- /dev/null +++ b/test/perl5/libdnf5/utils/test_patterns.t @@ -0,0 +1,41 @@ +# Copyright Contributors to the libdnf project. +# +# This file is part of libdnf: https://github.com/rpm-software-management/libdnf/ +# +# Libdnf 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. +# +# Libdnf 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 libdnf. If not, see . + +use strict; +use warnings; + +use Test::More; + +use libdnf5::utils; + +{ + ok(!libdnf5::utils::is_file_pattern(''), 'is_file_pattern ""'); + ok(!libdnf5::utils::is_file_pattern('no_file_pattern'), 'is_file_pattern "no_file_pattern"'); + ok(!libdnf5::utils::is_file_pattern('no_file/pattern'), 'is_file_pattern "no_file/pattern"'); + ok(libdnf5::utils::is_file_pattern('/pattern') == 1, 'is_file_pattern "/pattern"'); + ok(libdnf5::utils::is_file_pattern('*/pattern') == 1, 'is_file_pattern "*/pattern"'); +} + +{ + ok(!libdnf5::utils::is_glob_pattern(''), 'is_glob_pattern ""'); + ok(!libdnf5::utils::is_glob_pattern('no_glob_pattern'), 'is_glob_pattern "no_glob_pattern"'); + ok(libdnf5::utils::is_glob_pattern('glob*_pattern'), 'is_glob_pattern "glob*_pattern"'); + ok(libdnf5::utils::is_glob_pattern('glob[sdf]_pattern') == 1, 'is_glob_pattern "glob[sdf]_pattern"'); + ok(libdnf5::utils::is_glob_pattern('glob?_pattern') == 1, 'is_glob_pattern "glob?_pattern"'); +} + +done_testing() diff --git a/test/python3/libdnf5/utils/__init__.py b/test/python3/libdnf5/utils/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/test/python3/libdnf5/utils/test_patterns.py b/test/python3/libdnf5/utils/test_patterns.py new file mode 100644 index 000000000..10d68483f --- /dev/null +++ b/test/python3/libdnf5/utils/test_patterns.py @@ -0,0 +1,36 @@ +# Copyright Contributors to the libdnf project. +# +# This file is part of libdnf: https://github.com/rpm-software-management/libdnf/ +# +# Libdnf 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. +# +# Libdnf 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 libdnf. If not, see . + +import unittest + +import libdnf5.utils + + +class TestIsXPattern(unittest.TestCase): + def test_is_file_pattern(self): + self.assertFalse(libdnf5.utils.is_file_pattern('')) + self.assertFalse(libdnf5.utils.is_file_pattern('no_file_pattern')) + self.assertFalse(libdnf5.utils.is_file_pattern('no_file/pattern')) + self.assertTrue(libdnf5.utils.is_file_pattern('/pattern')) + self.assertTrue(libdnf5.utils.is_file_pattern('*/pattern')) + + def test_is_glob_pattern(self): + self.assertFalse(libdnf5.utils.is_glob_pattern('')) + self.assertFalse(libdnf5.utils.is_glob_pattern('no_glob_pattern')) + self.assertTrue(libdnf5.utils.is_glob_pattern('glob*_pattern')) + self.assertTrue(libdnf5.utils.is_glob_pattern('glob[sdf]_pattern')) + self.assertTrue(libdnf5.utils.is_glob_pattern('glob?_pattern')) diff --git a/test/ruby/libdnf5/utils/test_patterns.rb b/test/ruby/libdnf5/utils/test_patterns.rb new file mode 100644 index 000000000..f810ee00d --- /dev/null +++ b/test/ruby/libdnf5/utils/test_patterns.rb @@ -0,0 +1,39 @@ +# Copyright Contributors to the libdnf project. +# +# This file is part of libdnf: https://github.com/rpm-software-management/libdnf/ +# +# Libdnf 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. +# +# Libdnf 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 libdnf. If not, see . + +require 'test/unit' +include Test::Unit::Assertions + +require 'libdnf5/utils' + +class TestIsXPattern < Test::Unit::TestCase + def test_is_file_pattern() + assert(!Utils::is_file_pattern('')) + assert(!Utils::is_file_pattern('no_file_pattern')) + assert(!Utils::is_file_pattern('no_file/pattern')) + assert(Utils::is_file_pattern('/pattern')) + assert(Utils::is_file_pattern('*/pattern')) + end + + def test_is_glob_pattern() + assert(!Utils::is_glob_pattern('')) + assert(!Utils::is_glob_pattern('no_glob_pattern')) + assert(Utils::is_glob_pattern('glob*_pattern')) + assert(Utils::is_glob_pattern('glob[sdf]_pattern')) + assert(Utils::is_glob_pattern('glob?_pattern')) + end +end