Quickly test a feature that is part of a large DLL project

I use VS2010 for development in C ++, and I often finish work on some dll project, and after everything compiles beautifully, I would like to try to run dummy data on some classes, but because it is a DLL, and not exe with main does this, which is not. So, is there an easy way to do what I want, or have I cursed forever to c / p parts of a large project into a small testing one? Ofc changing the type of project also works, but I would like to have some almost like iteractive shell way of testing functions.

+4
source share
5 answers

I know this is not a library or anything else, but if you want to run the dll on windows, just without creating it in anything, or writing a script, you can use rundll32.exe in windows. It allows you to run any of the exported functions in the dll. The syntax should look like:

rundll32.exe PathAndNameofDll,exportedFunctionName [ArgsToTheExportedFunction]

http://best-windows.vlaurie.com/rundll32.html is a nice simple, still up-to-date tutorial on how to use this binary. It has some interesting tricks that may surprise you.

If you are interested in the 64-bit version, it has the same name (seriously microsoft?), Check here: rundll32.exe equivalent for 64-bit DLLs

In addition, if you want to go low, theoretically you can use OllyDbg , which comes with a DLL loader to run the DLL you want to debug (in the assembly), in which you can use the same type of material (call exported functions and pass arguments), but the debugger is more suitable for reverse engineering than code debugging.

+5
source

I think you have basically two options.

First, you need to use some unit tests for the function. For C ++, you can find many implementations to take a look at CppUnit

The second option is to open the DLL, get the function through Win32API and call it that way (it will still qualify as unit testing at some level). You can generalize this approach a little by creating an executable file that makes the above parameterization necessary information (for example, path to dll, function name) to achieve the "interactive shell" that you mentioned - if you decide to go this way, you can check this CodeProject article on loading DLLs from C ++

+3
source

Besides using the unit tests provided by CppUnit, you can still write your own small testing framework. This way you can set up your Dll projects as needed, download it, link it up whatever you want and prove with some simple data as you like.

This value if you have many DLLs that are dependent on each other to do a specific job. (legacy C ++ Dlls projects are generally unlikely to be tested in my experience).

Having made some frame application, you can also check the possibilities that CppUnit will give you and combine it with your test frame.

This way you get a good set of automated tests that still have graded unit tests. It is somewhat difficult to start unit tests if the project already has a certain size. Having your own structure will allow you to write tests whenever you make some changes to the dll. Just paste it into your framework, check what you expect from it, and improve your frame more and more.

The basic idea is to separate the test, testrunner, testdata and statements to be made.

+2
source

Im using python + ctypes to create quick test routines for my dll applications.

If you use the extended attribute syntax, it will be easy for you.

Google for the Python + ctypes + test module, and you will find some examples.

+1
source

I would recommend Window Powershell command commands.

If you look at the article here - http://msdn.microsoft.com/en-us/magazine/cc163430.aspx , you can see how easy it is to set it up. Of course, this article is mainly about testing C # code, but you can see how they talk about how you can load any COM-enabled DLL in the same way.

Here you can see how to download the COM assembly - http://blogs.technet.com/b/heyscriptingguy/archive/2009/01/26/how-do-i-use-windows-powershell-to-work-with- junk-e-mail-in-office-outlook.aspx

EDIT: I know a very successful storage virtualization software company that uses Powershell extensively to test both managed and unmanaged (drivers) code.

+1
source

Source: https://habr.com/ru/post/1416631/


All Articles