C++ Logo

std-proposals

Advanced search

Friend namespace

From: chibane nadir <organicoman_at_[hidden]>
Date: Sun, 6 Dec 2020 01:56:49 +0000 (UTC)
Hello Team,for the purpose of TDD, there is a problem with testing private data members and member functions. some call it black box testing and others do the nasty "#define private public" just to shortcut the visibility of private and protected members to test the classes.I suggest to add the feature of "friend namespace" like the following:
namespace XYZ{ // define here your functions and classes void test_object_private_data_member_D(object* self,...);
}
class object{ // private data members, and member functions 'sometype' D;
    // public data members, and member functions
// for the purpose of testing this class let's include the members of namespace XYZ as friends so we can access private and protected// members of the current classprivate:
    using friend namespace XYZ; // <---- (A)
};
(A): at this point all the functions and classes defined in the namespace XYZ above will be inserted in the class "object" as friend functions and classes, likewise we will write test cases based on these friend functions and classes since they have access to all"object" class no matter what is their visibility (private, protected or public), and avoiding the need to use the nasty macro hack'#define private public'

i can show a sample of how i use friend functions to create test cases, for interested people.







Received on 2020-12-05 19:56:57