I use VS2010 for C++ development, and I often end up doing work in some dll project and after everything compiles nicely I would like to try to run dummy data on some classes, but ofc the fact that it is a dll and not an exe with main makes that a no go. So is there a simple way to do what I want, or Im cursed till eternity to c/p parts of a big project into small testing one? Ofc changing the type of the project also works, but I would like to have some almost like iteractive shell way of testing functions.
-
Have you looked at Unit Tests? – Brad Semrad Jun 13 '12 at 21:38
-
afaik VS2010 in prof version doesnt have any UT capabilities. I could be wrong, like I said afaik. – NoSenseEtAl Jun 13 '12 at 21:44
-
1Will then you could use the free open source version NUnit (http://nunit.org/). Also VS 2010 Pro does (http://www.microsoft.com/visualstudio/en-us/products/2010-editions/product-comparison) – Brad Semrad Jun 13 '12 at 21:47
-
Isnt NUnit just for .net, I use both native and .net(CLI) C++. Also check this out: http://msdn.microsoft.com/en-us/library/ms182532.aspx It says perm or ultim – NoSenseEtAl Jun 14 '12 at 07:41
-
Well you do get Unit Test also according to Wikipedia (http://en.wikipedia.org/wiki/Visual_Studio#Editions). You should have access under the Test in creating new project both native and manage version (at least in VS 2012). Sorry I also assumed that you were using some .NET features but the Native version should work. However http://msdn.microsoft.com/en-US/library/ms243171(v=vs.100).aspx states differently...........GAHHHHH – Brad Semrad Jun 14 '12 at 13:16
5 Answers
I know this isn't a library or anything, but if you want to run the dll on windows simply without framing it into anything, or writing a script, you can use rundll32.exe within windows. It allows you to run any of the exported functions in the dll. The syntax should be similiar to:
rundll32.exe PathAndNameofDll,exportedFunctionName [ArgsToTheExportedFunction]
http://best-windows.vlaurie.com/rundll32.html -- is a good simple still relevant tutorial on how to use this binary. Its got some cool tricks in there that may surprise you.
If you are wondering about a 64-bit version, it has the same name (seriously microsoft?) check it out here: rundll32.exe equivalent for 64-bit DLLs
Furthermore, if you wanted to go low level, you could in theory utilize OllyDbg which comes with a DLL loader for running DLL's you want to debug (in assembly), which you can do the same type of stuff in (call exported functions and pass args) but the debugger is more for reverse engineering than code debugging.
I think you have basically two options.
First, is to use some sort of unit tests on the function. For C++ you can find a variety of implementations, for one take a look at CppUnit
The second option is to open the DLL, get the function via the Win32API and call it that way (this would still qualify as unit testing on some level). You could generalize this approach somewhat by creating an executable that does the above parametrized with the required information (e.g. dll path, function name) to achieve the "interactive shell" you mentioned -- if you decide to take this path, you can check out this CodeProject article on loading DLLs from C++

- 28,265
- 3
- 46
- 55
Besides using unit tests as provided by CppUnit, you can still write your own small testing framework. That way you can setup your Dll projects as needed, load it, link it, whatever you want and prove it with some simple data as you like.
This is valueable if you have many Dlls that depend on each other to do a certain job. (legacy Dlls projects in C++ tend to be hardly testable in my experience).
Having done some frame application, you can also inspect the possibilities that CppUnit will give you and combine it with your test frame.
That way you will end up with a good set of automated test, which still are valueable unit tests. It is somewhat hard starting to make unit tests if a project already has a certain size. Having your own framework will let you write tests whenever you make some change to a dll. Just insert it into your framework, test what you expect it to do and enhance your frame more and more.
The basic idea is to separate the test, the testrunner, the testdata and the asserts to be made.

- 8,024
- 8
- 64
- 113
I’m using python + ctypes to build quick testing routines for my DLL applications.
If you are using the extended attribute syntax, will be easy for you.
Google for Python + ctypes + test unit and you will find several examples.

- 11
- 2
I would recommend Window Powershell commandlets.
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 up. Of course this article is mostly about testing C# code, but you can see how they talk about also being able to load any COM enabled DLL in the same way.
Here you can see how to load a 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 it's managaged and unmanaged (drivers) code.

- 6,831
- 2
- 33
- 62