Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[swig] Bindings and tests for libdnf5::utils::[is_glob_pattern | is_file_pattern] #1738

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ endif()


# list of all modules that will be included in libdnf5 bindings
list(APPEND SWIG_LIBDNF5_MODULES advisory base common comps conf logger repo rpm transaction plugin)
list(APPEND SWIG_LIBDNF5_MODULES advisory base common comps conf logger repo rpm transaction plugin utils)


# list of all modules that will be included in libdnf5-cli bindings
Expand Down
19 changes: 19 additions & 0 deletions bindings/libdnf5/utils.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#if defined(SWIGPYTHON)
%module(package="libdnf5") utils
#elif defined(SWIGPERL)
%module "libdnf5::utils"
#elif defined(SWIGRUBY)
%module "libdnf5/utils"
#endif

%include <std_string.i>

%include <shared.i>

%{
#include "libdnf5/utils/patterns.hpp"
%}

#define CV __perl_CV

%include "libdnf5/utils/patterns.hpp"
44 changes: 44 additions & 0 deletions test/libdnf5/utils/test_patterns.cpp
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

#include "test_patterns.hpp"

#include <libdnf5/utils/patterns.hpp>

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"));
}
37 changes: 37 additions & 0 deletions test/libdnf5/utils/test_patterns.hpp
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

#ifndef LIBDNF5_TEST_UTILS_PATTERNS_HPP
#define LIBDNF5_TEST_UTILS_PATTERNS_HPP

#include <cppunit/TestCase.h>
#include <cppunit/extensions/HelperMacros.h>

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
41 changes: 41 additions & 0 deletions test/perl5/libdnf5/utils/test_patterns.t
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

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()
Empty file.
36 changes: 36 additions & 0 deletions test/python3/libdnf5/utils/test_patterns.py
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

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'))
39 changes: 39 additions & 0 deletions test/ruby/libdnf5/utils/test_patterns.rb
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

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
Loading