Reporting C++/CLR value classes
Reporting C++/CLR value classes
I have a Visual Studio managed C++ project, which contains reference and value classes. When I run NConver with my unit tests, the report only covers the reference classes. Is it possible to get coverage of value classes as well?
If there is currently no support for C++/CLR value classes, I'd like to request this feature for one of the next versions.
Kind regards, Kris.
RE: Reporting C++/CLR value classes
Kris,
According to our testing value classes are profiled correctly unless the compiler decides to compile them to native code. You could also be inadvertently excluding them with one of the regex exclusions. Are you looking at the coverage file in NCoverExplorer?
This is one of our C++/CLI tests; run it and see if the value class is excluded
// CPPValueClassTest.cpp : main project file.
include "stdafx.h"
using namespace System;
ref class ReferenceClass { public : ReferenceClass() { myVariable1 = 1; myVariable2 = 1; }
System::String^ PrintVariables()
{
return L"_myVariable1: " + _myVariable1.ToString() + L" _myVariable2: " + _myVariable2.ToString();
}
private: int myVariable1; int myVariable2; };
value class ValueClass { public:
System::String^ PrintVariables()
{
return L"_myVariable1: " + _myVariable1.ToString() + L" _myVariable2: " + _myVariable2.ToString();
}
int _myVariable1;
int _myVariable2;
};
int main(array<System::String ^> ^args) { Console::WriteLine(L"Testing C++ Value and Reference Class Profiling");
ReferenceClass ^ test1 = gcnew ReferenceClass();
ValueClass ^ test2 = gcnew ValueClass();
ValueClass test3;
Console::WriteLine(L"Reference class:");
Console::WriteLine(test1 ->PrintVariables());
Console::WriteLine(L"Value class declared w/ gcnew:");
Console::WriteLine(test2 ->PrintVariables());
Console::WriteLine(L"Value class declared on the stack");
Console::WriteLine(test3.PrintVariables());
Console::WriteLine(L"Value class variable access");
Console::WriteLine(test3._myVariable1.ToString());
Console::WriteLine(test3._myVariable2.ToString());
return 0;
}
RE: Reporting C++/CLR value classes
Indeed, when I declare my value class with the new C++/CLR syntax its coverage will be shown. The problem was that I was looking at a very large module in which both formats are used: old managed C++ syntax and the new CLR style.
For reference classes it seems to be irrelevant whether they are declared __gc class or ref class. The coverage for these classes will be reported anyway.
But for value classes only value class gives the desired result. All __nogc class declared classes are left out from the report. I don't know whether the compiler decided to compile all of them to native.
So, it seems, I have to re-write my code, which I was planning to do anyway.