Linking Visual Studio 2012 C++ Unit Testing project against an exe causes access violations -


i'm starting existing, monolithic, .exe native visual studio 2012 project. want add native unit test project alongside, according http://msdn.microsoft.com/en-us/library/hh419385.aspx#objectref, suggests supported:

the code under test built .exe file: add separate test project. link output object file.

i dllexport'ed methods needed test, linked test project exe project's .lib library , things seemed work simple test functions. however, tried more interesting started getting access violations one:

first-chance exception @ 0x04fa4aac (testapplication.exe) in vstest.executionengine.x86.exe: 0xc0000005: access violation reading location 0x011bf0e0.

so created new solution simplest .exe , unity test project pair muster , able reproduce exceptions caller (unit test project) , callee (.exe project):

callee (.exe project) header.h:

#include <string> __declspec( dllexport ) std::string __cdecl strtest( std::string j ); 

callee (.exe project) header.cpp:

#include "header.h"  std::string strtest( std::string j ) {     std::string output;      output += j;     output += "haha";      return output; } 

caller (unit test project) unittest1.cpp:

#include "cppunittest.h" #include "../testapplication/header.h"  using namespace microsoft::visualstudio::cppunittestframework;  namespace unittest {         test_class(unittest1) {     public:         test_method(testmethod1) {             std::string test = strtest( "bla " );         }     }; } 

the access violation happens inside std::string constructor being called std::string output; line in strtest().

i made sure 2 projects have identical settings (especially calling convention, optimization/debug settings, bit-ness, , character set). disabled , removed pre-compiled headers both projects.

i tried creating second exe project functions above , have main exe project link against second exe project. worked perfectly. when tried have unit test project link against second exe project, in same way had main exe project working, got same access violations again.

the thing worked converting exe project dll project (litterally changing configuration type of exe project application (.exe) dynamic library (.dll)).

so question is, can somehow exe project unit-testable using visual studio 2012's unit testing or should start splitting dlls already?

edit:

i submitted issue on microsoft connect on , told indeed bug: https://connect.microsoft.com/visualstudio/feedback/details/804696/linking-visual-studio-2012-c-unit-testing-project-against-an-exe-causes-access-violations

i've done more tests using same solution attached on fresh installs of windows 7 pro x64 sp1 , windows 8.1 pro preview x64 on vmware workstation 9 virtual machines. nothing windows updates , specific visual studio installed each test. reverted clean snapshot between tests. ran visual studios all-default settings.

on windows 7, tried gave me same access violation. tried solution with:

  1. visual studio express 2012 windows desktop w/ update 2
  2. visual studio express 2012 windows desktop w/ update 3
  3. visual studio 2012 ultimate w/ update 3
  4. visual studio 2013 rc professional

on windows 8.1, visual studio express 2012 windows desktop w/ update 3 unit tests ran fine. i'm assuming other combinations tried on windows 7 work fine on 8.1.

back on windows 7, when switched x86 x64 platform , setting default processor architecture test settings x64 same test passed. no longer got access violations.

so (windows 7/x86 platform)-specific problem.

also, regarding access violation, it's not graceful. "vstest.executionengine.x86.exe has stopped working" dialog box these problem details:

problem signature: problem event name:    bex application name:    vstest.executionengine.x86.exe application version:    12.0.20827.3 application timestamp:    521cc637 fault module name:    stackhash_9321 fault module version:    0.0.0.0 fault module timestamp:    00000000 exception offset:    00ae9998 exception code:    c0000005 exception data:    00000008 os version:    6.1.7601.2.1.0.256.1 locale id:    1033 additional information 1:    9321 additional information 2:    9321642ea520dd869526c054c7161ae9 additional information 3:    bfae additional information 4:    bfaed60192419c1d7d34eac41dbe71a8 


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -