Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing initialisation with arguments #106

Open
DanBennettDev opened this issue Apr 3, 2018 · 5 comments
Open

Testing initialisation with arguments #106

DanBennettDev opened this issue Apr 3, 2018 · 5 comments

Comments

@DanBennettDev
Copy link

So far as I can tell the test wrapper provided doesn't support initialising your objects with arguments - test_wrapper constructor is calling the constructor for wrapper_new with nullptr for the argument array. This makes it a difficult to test externals with substantial initialisation processes.

It's possible I'm being dumb here and there's an easy way around this. I tried adding a constructor (as below) that takes args to the test_wrapper, but when I follow execution in the debugger this still seems to result in my external's class constructor being called with 0 arguments - so there's obviously a fair bit I'm missing here.

test_wrapper(atoms& args = {}) {
    m_minwrap_obj = wrapper_new<min_class_type>(symbol("dummy"), args.size(), &args[0]);
}
@tap
Copy link
Contributor

tap commented Apr 3, 2018

Thanks @DanBennettDev -- The plumbing for the unit testing is the largest area with room for growth and improvement.

One thing that might be confusing in the debugger is that 2 instances of your object will be created. The first one is a "dummy" construction where an instance is created, information from it is harvested to create the Max class, and then it is destroyed. This only happens once. Then the real instance to be used gets created.

That's a great point about us having no examples of unit tests where args are being passed.

@DanBennettDev
Copy link
Author

ok thanks - I'll go back and dig into the test code a bit more deeply.

@leico
Copy link
Contributor

leico commented Mar 12, 2020

I find this issue, now I would like to test arguments.
So, in my environment, this code looks works fine.

in c74_min_unittest.h

        test_wrapper() {
            m_minwrap_obj = wrapper_new<min_class_type>(symbol("dummy"), 0, nullptr);
        }
      
        // constructor overload
        test_wrapper(const atoms& vec_args){
          max::t_atom args[ vec_args.size() ];
          for( std :: size_t i = 0, end = vec_args.size() ; i < end ; ++ i)
            args[i] = vec_args[i];
          m_minwrap_obj = wrapper_new<min_class_type>(symbol("dummy"), vec_args.size(), args); // Would "dummy" needs to become other name?
        }

in *_test.cpp

test_wrapper<Test.args_object> an_instance({"aaa", 10, 2.5});

If it looks good, I can send a pull request.

@leico
Copy link
Contributor

leico commented Mar 12, 2020

Ah...yes, I found a dummy class.... on c74_min_object_wrapper.hpp

スクリーンショット 2020-03-12 16 49 23

@tap
Copy link
Contributor

tap commented Mar 17, 2020

Hi @leico ,

If you would like to submit a Pull Request I'd be happy to review it!

Thanks,
Tim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants