-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit tests: Fix One Definition Rule violation caused by overlinking
The libdnf5 library unit tests use the private methods of the tested libdnf5 library. The `BaseTestCase` class used as a parent of many test scenarios, not only libdnf5 but also libdnf5-cli and other unit tests, provides the `add_system_pkg` method, which also uses private methods of the libdnf5 library. Because the private methods have hidden symbols, they are not exported by the libdnf5 shared library. To access the symbols of the private methods, unit tests link libdnf5 statically instead of using the libdnf5 shared library. This is fine for unit tests of the libdnf5 library. The problem is with unit tests of other components (e.g. libdnf-cli) that link the shared libdnf5 library. Due to this, in these tests the libdnf5 library was linked statically because of used class `BaseTestCase` and at the same time the shared libdnf5 library was linked. The problem was solved by moving the `add_system_pkg` method from the `BaseTestCase` class to the newly created inherited `LibdnfPrivateTestCase` class, which is only used in the libdnf5 library unit tests. Thus, only in these tests must libdnf5 be linked statically. The tests of the other components still use the `BaseTestClass` class, which now uses only public (API) functions from the libdnf5 library. These tests now only link the shared version of the libdnf5 library.
- Loading branch information
Showing
8 changed files
with
102 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
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 "libdnf_private_test_case.hpp" | ||
|
||
#include "../shared/private_accessor.hpp" | ||
#include "base/base_impl.hpp" | ||
#include "utils/string.hpp" | ||
|
||
#include <libdnf5/rpm/nevra.hpp> | ||
|
||
|
||
namespace { | ||
|
||
// Accessor of private Base::p_impl, see private_accessor.hpp | ||
create_private_getter_template; | ||
create_getter(priv_impl, &libdnf5::Base::p_impl); | ||
create_getter(add_rpm_package, &libdnf5::repo::Repo::add_rpm_package); | ||
|
||
} // namespace | ||
|
||
libdnf5::rpm::Package LibdnfPrivateTestCase::add_system_pkg( | ||
const std::string & relative_path, libdnf5::transaction::TransactionItemReason reason) { | ||
// parse out the NA from the package path to set the reason for the installed package | ||
auto filename_toks = libdnf5::utils::string::split(relative_path, "/"); | ||
auto basename_toks = libdnf5::utils::string::rsplit(filename_toks.back(), ".", 2); | ||
auto nevras = libdnf5::rpm::Nevra::parse(basename_toks.front()); | ||
CPPUNIT_ASSERT_MESSAGE("Couldn't parse NEVRA from package path: \"" + relative_path + "\"", !nevras.empty()); | ||
auto na = nevras[0].get_name() + "." + nevras[0].get_arch(); | ||
|
||
(base.*get(priv_impl()))->get_system_state().set_package_reason(na, reason); | ||
|
||
return (*(repo_sack->get_system_repo()).*get(add_rpm_package{}))( | ||
PROJECT_BINARY_DIR "/test/data/" + relative_path, false); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 TEST_LIBDNF5_LIBDNF_PRIVATE_TEST_CASE_HPP | ||
#define TEST_LIBDNF5_LIBDNF_PRIVATE_TEST_CASE_HPP | ||
|
||
#include "../shared/base_test_case.hpp" | ||
|
||
#include <libdnf5/rpm/package.hpp> | ||
#include <libdnf5/transaction/transaction_item_reason.hpp> | ||
|
||
#include <string> | ||
|
||
class LibdnfPrivateTestCase : public BaseTestCase { | ||
public: | ||
libdnf5::rpm::Package add_system_pkg( | ||
const std::string & relative_path, libdnf5::transaction::TransactionItemReason reason); | ||
}; | ||
|
||
#endif // TEST_LIBDNF5_LIBDNF_PRIVATE_TEST_CASE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters