-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PluginManager, Utility: add tests for global state shared across libr…
…aries. In particular, it becomes duplicated when Corrade is built statically and linked to more than one shared library (or separately to a shared library and an executable). Fixes following.
- Loading branch information
Showing
9 changed files
with
351 additions
and
0 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
49 changes: 49 additions & 0 deletions
49
src/Corrade/PluginManager/Test/GlobalStateAcrossLibrariesLibrary.cpp
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,49 @@ | ||
/* | ||
This file is part of Corrade. | ||
Copyright © 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, | ||
2017, 2018, 2019 Vladimír Vondruš <mosra@centrum.cz> | ||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included | ||
in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#include "GlobalStateAcrossLibrariesLibrary.h" | ||
|
||
#include <vector> | ||
#include <string> | ||
|
||
#include "Corrade/PluginManager/Manager.h" | ||
|
||
#include "AbstractAnimal.h" | ||
|
||
static void initialize() { | ||
CORRADE_PLUGIN_IMPORT(Canary) | ||
} | ||
|
||
namespace Corrade { namespace PluginManager { namespace Test { | ||
|
||
std::vector<std::string> staticPluginsLoadedInALibrary() { | ||
initialize(); | ||
|
||
/* Avoid accidentally loading the dynamic plugins as well */ | ||
Manager<AbstractAnimal> manager{"nonexistent"}; | ||
return manager.pluginList(); | ||
} | ||
|
||
}}} |
45 changes: 45 additions & 0 deletions
45
src/Corrade/PluginManager/Test/GlobalStateAcrossLibrariesLibrary.h
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,45 @@ | ||
#ifndef Corrade_PluginManager_Test_GlobalStateAcrossLibrariesLibrary_h | ||
#define Corrade_PluginManager_Test_GlobalStateAcrossLibrariesLibrary_h | ||
/* | ||
This file is part of Magnum. | ||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 | ||
Vladimír Vondruš <mosra@centrum.cz> | ||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included | ||
in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#include "Corrade/PluginManager/Manager.h" | ||
#include "Corrade/Utility/StlForwardString.h" | ||
#include "Corrade/Utility/StlForwardVector.h" | ||
#include "Corrade/Utility/VisibilityMacros.h" | ||
|
||
#ifdef PluginManagerGlobalStateAcrossLibrariesLibrary_EXPORTS | ||
#define CORRADE_GLOBALSTATEACROSSLIBRARIESLIBRARY_EXPORT CORRADE_VISIBILITY_EXPORT | ||
#else | ||
#define CORRADE_GLOBALSTATEACROSSLIBRARIESLIBRARY_EXPORT CORRADE_VISIBILITY_IMPORT | ||
#endif | ||
|
||
namespace Corrade { namespace PluginManager { namespace Test { | ||
|
||
CORRADE_GLOBALSTATEACROSSLIBRARIESLIBRARY_EXPORT std::vector<std::string> staticPluginsLoadedInALibrary(); | ||
|
||
}}} | ||
|
||
#endif |
59 changes: 59 additions & 0 deletions
59
src/Corrade/PluginManager/Test/GlobalStateAcrossLibrariesTest.cpp
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,59 @@ | ||
/* | ||
This file is part of Corrade. | ||
Copyright © 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, | ||
2017, 2018, 2019 Vladimír Vondruš <mosra@centrum.cz> | ||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included | ||
in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#include <vector> | ||
#include <string> | ||
|
||
#include "Corrade/PluginManager/Manager.h" | ||
#include "Corrade/TestSuite/Tester.h" | ||
#include "Corrade/Utility/DebugStl.h" | ||
|
||
#include "AbstractAnimal.h" | ||
#include "GlobalStateAcrossLibrariesLibrary.h" | ||
|
||
namespace Corrade { namespace PluginManager { namespace Test { namespace { | ||
|
||
struct GlobalStateAcrossLibrariesTest: TestSuite::Tester { | ||
explicit GlobalStateAcrossLibrariesTest(); | ||
|
||
void test(); | ||
}; | ||
|
||
GlobalStateAcrossLibrariesTest::GlobalStateAcrossLibrariesTest() { | ||
addTests({&GlobalStateAcrossLibrariesTest::test}); | ||
} | ||
|
||
void GlobalStateAcrossLibrariesTest::test() { | ||
/* Canary is linked to the library, but the executable should see it too */ | ||
CORRADE_COMPARE(staticPluginsLoadedInALibrary(), std::vector<std::string>{"Canary"}); | ||
|
||
/* Avoid accidentally loading the dynamic plugins as well */ | ||
PluginManager::Manager<AbstractAnimal> manager{"nonexistent"}; | ||
CORRADE_COMPARE(manager.pluginList(), std::vector<std::string>{"Canary"}); | ||
} | ||
|
||
}}}} | ||
|
||
CORRADE_TEST_MAIN(Corrade::PluginManager::Test::GlobalStateAcrossLibrariesTest) |
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
39 changes: 39 additions & 0 deletions
39
src/Corrade/Utility/Test/GlobalStateAcrossLibrariesLibrary.cpp
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,39 @@ | ||
/* | ||
This file is part of Corrade. | ||
Copyright © 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, | ||
2017, 2018, 2019 Vladimír Vondruš <mosra@centrum.cz> | ||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included | ||
in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#include <string> | ||
|
||
#include "GlobalStateAcrossLibrariesLibrary.h" | ||
|
||
#include "Corrade/Utility/Debug.h" | ||
#include "Corrade/Utility/Resource.h" | ||
|
||
namespace Corrade { namespace Utility { namespace Test { | ||
|
||
std::ostream* debugOutputFromALibrary() { return Debug::output(); } | ||
|
||
bool libraryHasATestResourceGroup(){ return Resource::hasGroup("test"); } | ||
|
||
}}} |
46 changes: 46 additions & 0 deletions
46
src/Corrade/Utility/Test/GlobalStateAcrossLibrariesLibrary.h
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,46 @@ | ||
#ifndef Corrade_Utility_Test_GlobalStateAcrossLibrariesLibrary_h | ||
#define Corrade_Utility_Test_GlobalStateAcrossLibrariesLibrary_h | ||
/* | ||
This file is part of Magnum. | ||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 | ||
Vladimír Vondruš <mosra@centrum.cz> | ||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included | ||
in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#include <iosfwd> | ||
|
||
#include <Corrade/Utility/VisibilityMacros.h> | ||
|
||
#ifdef UtilityGlobalStateAcrossLibrariesLibrary_EXPORTS | ||
#define CORRADE_GLOBALSTATEACROSSLIBRARIESLIBRARY_EXPORT CORRADE_VISIBILITY_EXPORT | ||
#else | ||
#define CORRADE_GLOBALSTATEACROSSLIBRARIESLIBRARY_EXPORT CORRADE_VISIBILITY_IMPORT | ||
#endif | ||
|
||
namespace Corrade { namespace Utility { namespace Test { | ||
|
||
CORRADE_GLOBALSTATEACROSSLIBRARIESLIBRARY_EXPORT std::ostream* debugOutputFromALibrary(); | ||
|
||
CORRADE_GLOBALSTATEACROSSLIBRARIESLIBRARY_EXPORT bool libraryHasATestResourceGroup(); | ||
|
||
}}} | ||
|
||
#endif |
71 changes: 71 additions & 0 deletions
71
src/Corrade/Utility/Test/GlobalStateAcrossLibrariesTest.cpp
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,71 @@ | ||
/* | ||
This file is part of Corrade. | ||
Copyright © 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, | ||
2017, 2018, 2019 Vladimír Vondruš <mosra@centrum.cz> | ||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included | ||
in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#include <sstream> | ||
|
||
#include "Corrade/TestSuite/Tester.h" | ||
#include "Corrade/Utility/Resource.h" | ||
|
||
#include "GlobalStateAcrossLibrariesLibrary.h" | ||
|
||
namespace Corrade { namespace Utility { namespace Test { namespace { | ||
|
||
struct GlobalStateAcrossLibrariesTest: TestSuite::Tester { | ||
explicit GlobalStateAcrossLibrariesTest(); | ||
|
||
void debug(); | ||
void resource(); | ||
}; | ||
|
||
GlobalStateAcrossLibrariesTest::GlobalStateAcrossLibrariesTest() { | ||
addTests({&GlobalStateAcrossLibrariesTest::debug, | ||
&GlobalStateAcrossLibrariesTest::resource}); | ||
} | ||
|
||
void GlobalStateAcrossLibrariesTest::debug() { | ||
std::ostringstream out; | ||
|
||
std::ostream* current = Debug::output(); | ||
CORRADE_COMPARE(debugOutputFromALibrary(), current); | ||
|
||
{ | ||
Debug redirectOutput{&out}; | ||
CORRADE_COMPARE(debugOutputFromALibrary(), &out); | ||
} | ||
|
||
CORRADE_COMPARE(debugOutputFromALibrary(), current); | ||
} | ||
|
||
void GlobalStateAcrossLibrariesTest::resource() { | ||
/* The resource is complied into the the library, but the executable should | ||
see it too */ | ||
CORRADE_VERIFY(libraryHasATestResourceGroup()); | ||
|
||
CORRADE_VERIFY(Utility::Resource::hasGroup("test")); | ||
} | ||
|
||
}}}} | ||
|
||
CORRADE_TEST_MAIN(Corrade::Utility::Test::GlobalStateAcrossLibrariesTest) |