I am working on a segment of code that is highly sensitive to copies based on the size of the variable, thus I want to ensure that the code I am writing is not copying data but only transferring ownership (or moving) from one class to another. Preferably I would like to be able to ensure this is happening via a unit test.
In particular, I am using a protocol buffer, but the example can be done generically with unique_ptr
.
Here is an example of code I am trying to do:
TEST(notcopy){
auto verify_not_copied = std::make_unique<type>();
auto test_class = std::make_unique<TestClass>();
auto result = testclass.run(verify_not_copied);
if (result == verify_not_copied){ //part I dont know how to check
return "Test success";
}else{
return "Test had copy";
}
}