-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow copy and move for service container
- Loading branch information
1 parent
4986e7b
commit 7d68b97
Showing
8 changed files
with
55 additions
and
25 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
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,37 @@ | ||
#include <mioc/mioc.h> | ||
#include "Test.h" | ||
#include "doctest.h" | ||
|
||
TEST_CASE("Assignment") | ||
{ | ||
mioc::ServiceContainerPtr containerA = mioc::ServiceContainer::New(); | ||
mioc::ServiceContainerPtr containerB = mioc::ServiceContainer::New(); | ||
|
||
// Register interfaces and implementations. | ||
containerA->AddSingleton<IA, A>(); | ||
containerA->AddSingleton<IB, B, IA>(); | ||
|
||
// Copy container. | ||
*containerB = *containerA; | ||
|
||
auto a1 = containerA->Resolve<IA>(); | ||
auto a2 = containerB->Resolve<IA>(); | ||
CHECK_EQ(a1->ToString(), a2->ToString()); | ||
|
||
const auto b1 = containerA->Resolve<IB>(); | ||
const auto b2 = containerB->Resolve<IB>(); | ||
CHECK_EQ(b1->ToString(), b2->ToString()); | ||
|
||
// Register new instance. | ||
const std::shared_ptr<IC> c = std::make_shared<C>(b1); | ||
containerA->AddSingleton(c); | ||
CHECK_NE(containerA->Resolve<IC>(), nullptr); | ||
CHECK_EQ(containerB->Resolve<IC>(), nullptr); | ||
|
||
// Move container. | ||
mioc::ServiceContainerPtr containerC = mioc::ServiceContainer::New(); | ||
*containerC = std::move(*containerA); | ||
CHECK_EQ(containerC->Resolve<IA>()->ToString(), a1->ToString()); | ||
CHECK_EQ(containerC->Resolve<IB>()->ToString(), b1->ToString()); | ||
CHECK_EQ(containerC->Resolve<IC>(), nullptr); | ||
} |
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
aux_source_directory(. TEST_FILES) | ||
add_executable(tests ${TEST_FILES}) | ||
set(LIBRARIES mioc) | ||
set(MIOC_TESTS SingletonTest TransientTest AssignmentTest) | ||
|
||
target_include_directories(tests PRIVATE .) | ||
|
||
target_link_libraries(tests mioc) | ||
|
||
add_test(NAME TestAll COMMAND tests) | ||
foreach(test ${MIOC_TESTS}) | ||
add_executable(${test} doctest.cpp ${test}.cpp) | ||
target_include_directories(${test} PRIVATE .) | ||
target_link_libraries(${test} ${LIBRARIES}) | ||
add_test(NAME ${test} COMMAND ${test}) | ||
endforeach(test ${MIOC_TESTS}) |
File renamed without changes.