diff options
author | Marco Poletti <poletti.marco@gmail.com> | 2017-07-23 21:13:34 +0100 |
---|---|---|
committer | Marco Poletti <poletti.marco@gmail.com> | 2017-07-23 21:13:34 +0100 |
commit | b95efcce188e5d56e7e58670cca6b22e09f714da (patch) | |
tree | a88279bea30db33f7524ed9ac89b607a91d59bc8 /tests/test_multibindings_bind_interface.py | |
parent | 91ce401846af8ffa83240dfdfaafe972f40c9ee0 (diff) | |
download | google-fruit-b95efcce188e5d56e7e58670cca6b22e09f714da.tar.gz |
Report better errors when attempting to bind/inject a type that can't be bound/injected. Also add more thorough tests for these cases, in preparation for supporting const bindings.
Diffstat (limited to 'tests/test_multibindings_bind_interface.py')
-rwxr-xr-x | tests/test_multibindings_bind_interface.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/test_multibindings_bind_interface.py b/tests/test_multibindings_bind_interface.py index f6a721f..b53a763 100755 --- a/tests/test_multibindings_bind_interface.py +++ b/tests/test_multibindings_bind_interface.py @@ -26,6 +26,44 @@ COMMON_DEFINITIONS = ''' struct Annotation2 {}; ''' +@pytest.mark.parametrize('XAnnot,XImplAnnot', [ + ('X', 'XImpl'), + ('X', 'fruit::Annotated<Annotation2, XImpl>'), + ('fruit::Annotated<Annotation1, X>', 'XImpl'), + ('fruit::Annotated<Annotation1, X>', 'fruit::Annotated<Annotation2, XImpl>'), +]) +def test_add_interface_multibinding_success(XAnnot, XImplAnnot): + source = ''' + struct X { + virtual int foo() = 0; + }; + + struct XImpl : public X { + INJECT(XImpl()) = default; + + int foo() override { + return 5; + } + }; + + fruit::Component<> getComponent() { + return fruit::createComponent() + .addMultibinding<XAnnot, XImplAnnot>(); + } + + int main() { + fruit::Injector<> injector(getComponent()); + + std::vector<X*> multibindings = injector.getMultibindings<XAnnot>(); + Assert(multibindings.size() == 1); + Assert(multibindings[0]->foo() == 5); + } + ''' + expect_success( + COMMON_DEFINITIONS, + source, + locals()) + @pytest.mark.parametrize('XAnnot,intAnnot', [ ('X', 'int'), ('fruit::Annotated<Annotation1, X>', 'fruit::Annotated<Annotation2, int>'), |