Skip to content

Mocking accessor returning C++ objects pointer fails when using libc++ #96

Closed
@sdefresne

Description

When testing Chrome on iOS, we found that mocked properties returning a C++ object (in our case a GURL) by pointer failed when building using libc++ and clang. It appears that the type descriptions returned by @encode(typeof(expr)) (from OCMOCK_VALUE) and -[[NSInvocation methodSignature] methodReturnType] have their properties recursively expanded, but with different depth, causing the strcmp to fail.

The code looks like:
@interface SomeClass
@Property (nonatomic, assign) const GURL* origin;
@EnD

const GURL kFakeOrigin = ....;
const GURL* fake_origin_ptr = &kFakeOrigin;
[[[mock_class stub] andReturnValue:OCMOCK_VALUE(fake_origin_ptr)] origin];

And the type descriptions in OCMBoxedReturnValueProvider.m are:
(lldb) p returnType
(const char _) $0 = 0x149e901d "r^{GURL={basic_string<char, std::__1::char_traits, std::__1::allocator >={__compressed_pair<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >::__rep, std::__1::allocator >={__rep}}}B{Parsed={Component=ii}{Component=ii}{Component=ii}{Component=ii}{Component=ii}{Component=ii}{Component=ii}{Component=ii}^{Parsed}}{scoped_ptr<GURL, base::DefaultDeleter >={scoped_ptr_impl<GURL, base::DefaultDeleter >={Data=^{GURL}}}}}"
(lldb) p valueType
(const char *) $1 = 0x149e5808 "r^{GURL={basic_string<char, std::__1::char_traits, std::__1::allocator >={__compressed_pair<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >::__rep, std::__1::allocator >={__rep=(?={_long=II}{__short=(?=Cc)[11c]}{__raw=[3L]})}}}B{Parsed={Component=ii}{Component=ii}{Component=ii}{Component=ii}{Component=ii}{Component=ii}{Component=ii}{Component=ii}^{Parsed}}{scoped_ptr<GURL, base::DefaultDeleter >={scoped_ptr_impl<GURL, base::DefaultDeleter >={Data=^{GURL}}}}}"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions