Cycling74 / min-devkit

Tools, documentation, and reference implementation of a Max Package built using the Min-API.
MIT License
163 stars 31 forks source link

Testing initialisation with arguments #106

Open DanBennettDev opened 6 years ago

DanBennettDev commented 6 years ago

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_newwith nullptrfor 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 commented 6 years ago

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 commented 6 years ago

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

leico commented 4 years ago

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 commented 4 years ago

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

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

tap commented 4 years ago

Hi @leico ,

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

Thanks, Tim