| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | |||
| 2 | /*************************************** | ||
| 3 | Auteur : Pierre Aubert | ||
| 4 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 5 | Licence : LGPL-3.0-only | ||
| 6 | ****************************************/ | ||
| 7 | |||
| 8 | #include "type_utils.h" | ||
| 9 | #include "CppTraitCopy.h" | ||
| 10 | |||
| 11 | |||
| 12 | ///Create the class check | ||
| 13 | /** @param fs : file to be completed | ||
| 14 | * @param classConfig : class configuration to be used | ||
| 15 | * @param isConst : true if the generated check has to use const classes | ||
| 16 | */ | ||
| 17 | 12 | void class_createCheckClassEquality(std::ofstream & fs, const PClassConfig & classConfig, bool isConst){ | |
| 18 |
3/3✓ Branch 0 (2→3) taken 12 times.
✓ Branch 2 (3→4) taken 12 times.
✓ Branch 4 (4→5) taken 12 times.
|
12 | PString name(classConfig.getName()), strConst(""); |
| 19 |
2/2✓ Branch 0 (5→6) taken 6 times.
✓ Branch 1 (5→7) taken 6 times.
|
12 | if(isConst){ |
| 20 |
1/1✓ Branch 0 (6→7) taken 6 times.
|
6 | strConst = "const "; |
| 21 | } | ||
| 22 |
3/3✓ Branch 0 (7→8) taken 12 times.
✓ Branch 2 (8→9) taken 12 times.
✓ Branch 4 (9→10) taken 12 times.
|
12 | fs << "///Check the equality between two "+name+" classes\n"; |
| 23 |
1/1✓ Branch 0 (12→13) taken 12 times.
|
12 | fs << "/**\t@param var : variable to be checked\n"; |
| 24 |
1/1✓ Branch 0 (13→14) taken 12 times.
|
12 | fs << " * \t@param reference : reference\n"; |
| 25 |
1/1✓ Branch 0 (14→15) taken 12 times.
|
12 | fs << " * \t@return true on success, false otherwise\n"; |
| 26 |
1/1✓ Branch 0 (15→16) taken 12 times.
|
12 | fs << "*/\n"; |
| 27 |
3/3✓ Branch 0 (16→17) taken 12 times.
✓ Branch 2 (17→18) taken 12 times.
✓ Branch 4 (18→19) taken 12 times.
|
12 | fs << "bool check"+name+"Equality"; |
| 28 |
2/2✓ Branch 0 (21→22) taken 6 times.
✓ Branch 1 (21→23) taken 6 times.
|
12 | if(isConst){ |
| 29 |
1/1✓ Branch 0 (22→23) taken 6 times.
|
6 | fs << "Const"; |
| 30 | } | ||
| 31 |
7/7✓ Branch 0 (23→24) taken 12 times.
✓ Branch 2 (24→25) taken 12 times.
✓ Branch 4 (25→26) taken 12 times.
✓ Branch 6 (26→27) taken 12 times.
✓ Branch 8 (27→28) taken 12 times.
✓ Branch 10 (28→29) taken 12 times.
✓ Branch 12 (29→30) taken 12 times.
|
12 | fs << "(" + strConst + name + " & var, " + strConst + name + " & reference){\n"; |
| 32 |
1/1✓ Branch 0 (36→37) taken 12 times.
|
12 | fs << "\tbool b(true);\n"; |
| 33 |
1/1✓ Branch 0 (37→38) taken 12 times.
|
12 | const PVecClassAttribute & listAttr = classConfig.getListAttribute(); |
| 34 |
2/2✓ Branch 0 (81→39) taken 34 times.
✓ Branch 1 (81→82) taken 12 times.
|
92 | for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){ |
| 35 |
2/2✓ Branch 0 (41→42) taken 34 times.
✓ Branch 2 (42→43) taken 34 times.
|
68 | PString attrName(it->getName().firstToUpper()); |
| 36 |
2/2✓ Branch 0 (45→46) taken 34 times.
✓ Branch 2 (46→47) taken 34 times.
|
34 | bool isSimpleType = getIsSimpleType(it->getType()); |
| 37 | // std::cout << "createCheckClassEquality : attrName = '"<<attrName<<"', isSimpleType = " << isSimpleType << ", it->getIsPointer() = " << it->getIsPointer() << ", it->getIsReference() = " << it->getIsReference() << std::endl; | ||
| 38 |
9/11✓ Branch 0 (47→48) taken 20 times.
✓ Branch 1 (47→57) taken 14 times.
✓ Branch 2 (50→51) taken 20 times.
✓ Branch 4 (51→52) taken 20 times.
✗ Branch 5 (51→57) not taken.
✓ Branch 6 (54→55) taken 20 times.
✓ Branch 8 (55→56) taken 20 times.
✗ Branch 10 (56→57) not taken.
✓ Branch 11 (56→58) taken 20 times.
✓ Branch 12 (59→60) taken 14 times.
✓ Branch 13 (59→70) taken 20 times.
|
74 | if(isSimpleType || it->getIsPointer() || it->getType() == "PString"){ |
| 39 |
5/5✓ Branch 0 (60→61) taken 14 times.
✓ Branch 2 (61→62) taken 14 times.
✓ Branch 4 (62→63) taken 14 times.
✓ Branch 6 (63→64) taken 14 times.
✓ Branch 8 (64→65) taken 14 times.
|
14 | fs << "\tb &= var.get"+attrName+"() == reference.get"+attrName+"();\n"; |
| 40 | } | ||
| 41 | 34 | } | |
| 42 |
1/1✓ Branch 0 (82→83) taken 12 times.
|
12 | fs << "\treturn b;\n"; |
| 43 |
1/1✓ Branch 0 (83→84) taken 12 times.
|
12 | fs << "}\n\n"; |
| 44 | 12 | } | |
| 45 | |||
| 46 | ///Check if the given class owns at least one pointer attribute | ||
| 47 | /** @param classConfig : PClassConfig to be checked | ||
| 48 | * @return true if the class has a pointer attribute, false otherwise | ||
| 49 | */ | ||
| 50 | 12 | bool copy_hasPointerAttribute(const PClassConfig & classConfig){ | |
| 51 | 12 | const PVecClassAttribute & listAttr(classConfig.getListAttribute()); | |
| 52 |
2/2✓ Branch 0 (20→4) taken 34 times.
✓ Branch 1 (20→21) taken 10 times.
|
88 | for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){ |
| 53 |
4/4✓ Branch 0 (6→7) taken 34 times.
✓ Branch 2 (7→8) taken 34 times.
✓ Branch 4 (8→9) taken 2 times.
✓ Branch 5 (8→10) taken 32 times.
|
34 | if(getIsPointerType(it->getType())){return true;} |
| 54 | } | ||
| 55 | 10 | return false; | |
| 56 | } | ||
| 57 | |||
| 58 | ///Create the class check | ||
| 59 | /** @param fs : file to be completed | ||
| 60 | * @param classConfig : class configuration to be used | ||
| 61 | * @param mode : all modes of the generator (data/check/type/config stream) | ||
| 62 | */ | ||
| 63 | 5 | void class_createTestClassCopy(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode){ | |
| 64 |
2/2✓ Branch 0 (2→3) taken 5 times.
✓ Branch 2 (3→4) taken 5 times.
|
5 | PString name(classConfig.getName()); |
| 65 |
3/3✓ Branch 0 (4→5) taken 5 times.
✓ Branch 2 (5→6) taken 5 times.
✓ Branch 4 (6→7) taken 5 times.
|
5 | fs << "///Check copy of class "+name+"\n"; |
| 66 |
3/3✓ Branch 0 (9→10) taken 5 times.
✓ Branch 2 (10→11) taken 5 times.
✓ Branch 4 (11→12) taken 5 times.
|
5 | fs << "void check"+name+"Copy(){\n"; |
| 67 |
3/3✓ Branch 0 (14→15) taken 5 times.
✓ Branch 2 (15→16) taken 5 times.
✓ Branch 4 (16→17) taken 5 times.
|
5 | fs << "\t"+name+" reference;\n"; |
| 68 |
1/1✓ Branch 0 (19→20) taken 5 times.
|
5 | fs << "\t//Let's use the setters\n"; |
| 69 |
1/1✓ Branch 0 (20→21) taken 5 times.
|
5 | const PVecClassAttribute & listAttr = classConfig.getListAttribute(); |
| 70 |
2/2✓ Branch 0 (54→22) taken 14 times.
✓ Branch 1 (54→55) taken 5 times.
|
38 | for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){ |
| 71 |
4/4✓ Branch 0 (24→25) taken 14 times.
✓ Branch 2 (25→26) taken 14 times.
✓ Branch 4 (28→29) taken 14 times.
✓ Branch 6 (29→30) taken 14 times.
|
42 | PString defaultValue(getTestDefaultValueTypeInCpp(it->getType())), attrName(it->getName().firstToUpper());; |
| 72 |
3/3✓ Branch 0 (30→31) taken 14 times.
✓ Branch 2 (31→32) taken 12 times.
✓ Branch 3 (31→42) taken 2 times.
|
14 | if(defaultValue != ""){ |
| 73 |
5/5✓ Branch 0 (32→33) taken 12 times.
✓ Branch 2 (33→34) taken 12 times.
✓ Branch 4 (34→35) taken 12 times.
✓ Branch 6 (35→36) taken 12 times.
✓ Branch 8 (36→37) taken 12 times.
|
12 | fs << "\treference.set"+attrName+"("+defaultValue+");\n"; |
| 74 | } | ||
| 75 | 14 | } | |
| 76 |
3/3✓ Branch 0 (55→56) taken 5 times.
✓ Branch 2 (56→57) taken 5 times.
✓ Branch 4 (57→58) taken 5 times.
|
5 | fs << "\t"+name+" varCopy(reference);\n"; |
| 77 |
3/3✓ Branch 0 (60→61) taken 5 times.
✓ Branch 2 (61→62) taken 5 times.
✓ Branch 4 (62→63) taken 5 times.
|
5 | fs << "\t"+name+" varEqual;\n"; |
| 78 |
1/1✓ Branch 0 (65→66) taken 5 times.
|
5 | fs << "\tvarEqual = reference;\n"; |
| 79 |
5/5✓ Branch 0 (66→67) taken 5 times.
✓ Branch 2 (67→68) taken 5 times.
✓ Branch 4 (68→69) taken 5 times.
✓ Branch 6 (69→70) taken 5 times.
✓ Branch 8 (70→71) taken 5 times.
|
5 | fs << "\t"<<mode.assertCall<<"(check"+name+"Equality(varCopy, reference));\n"; |
| 80 |
5/5✓ Branch 0 (73→74) taken 5 times.
✓ Branch 2 (74→75) taken 5 times.
✓ Branch 4 (75→76) taken 5 times.
✓ Branch 6 (76→77) taken 5 times.
✓ Branch 8 (77→78) taken 5 times.
|
5 | fs << "\t"<<mode.assertCall<<"(check"+name+"EqualityConst(varCopy, reference));\n"; |
| 81 |
5/5✓ Branch 0 (80→81) taken 5 times.
✓ Branch 2 (81→82) taken 5 times.
✓ Branch 4 (82→83) taken 5 times.
✓ Branch 6 (83→84) taken 5 times.
✓ Branch 8 (84→85) taken 5 times.
|
5 | fs << "\t"<<mode.assertCall<<"(check"+name+"Equality(varEqual, reference));\n"; |
| 82 |
5/5✓ Branch 0 (87→88) taken 5 times.
✓ Branch 2 (88→89) taken 5 times.
✓ Branch 4 (89→90) taken 5 times.
✓ Branch 6 (90→91) taken 5 times.
✓ Branch 8 (91→92) taken 5 times.
|
5 | fs << "\t"<<mode.assertCall<<"(check"+name+"EqualityConst(varEqual, reference));\n"; |
| 83 |
1/1✓ Branch 0 (94→95) taken 5 times.
|
5 | fs << "}\n\n"; |
| 84 | 5 | } | |
| 85 | |||
| 86 | ///Consctructor of CppTraitCopy | ||
| 87 | 5 | CppTraitCopy::CppTraitCopy() | |
| 88 | 5 | :PAbstractTraitBackend() | |
| 89 | 5 | {} | |
| 90 | |||
| 91 | ///Desctructor of CppTraitCopy | ||
| 92 | 10 | CppTraitCopy::~CppTraitCopy(){} | |
| 93 | |||
| 94 | ///Declaration of public methods | ||
| 95 | /** @param[out] fs : file to be completed | ||
| 96 | * @param classConfig : PClassConfig to be used | ||
| 97 | * @param mode : mode of the generator | ||
| 98 | */ | ||
| 99 | 8 | void CppTraitCopy::publicMethodDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{ | |
| 100 | //Rule of zero : no hand-written copy constructor / operator= anymore, let the compiler generate them (or delete them, for classes owning a unique_ptr attribute) | ||
| 101 | 8 | } | |
| 102 | |||
| 103 | ///Implementation of public methods | ||
| 104 | /** @param[out] fs : file to be completed | ||
| 105 | * @param classConfig : PClassConfig to be used | ||
| 106 | * @param mode : mode of the generator | ||
| 107 | */ | ||
| 108 | 11 | void CppTraitCopy::publicMethodImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{ | |
| 109 | //Rule of zero : no hand-written copy constructor / operator= anymore, let the compiler generate them (or delete them, for classes owning a unique_ptr attribute) | ||
| 110 | 11 | } | |
| 111 | |||
| 112 | ///Declaration of protected methods | ||
| 113 | /** @param[out] fs : file to be completed | ||
| 114 | * @param classConfig : PClassConfig to be used | ||
| 115 | * @param mode : mode of the generator | ||
| 116 | */ | ||
| 117 | 8 | void CppTraitCopy::protectedMethodDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{ | |
| 118 | //Rule of zero : no hand-written copy<Name>() helper anymore | ||
| 119 | 8 | } | |
| 120 | |||
| 121 | ///Implementation of protected methods | ||
| 122 | /** @param[out] fs : file to be completed | ||
| 123 | * @param classConfig : PClassConfig to be used | ||
| 124 | * @param mode : mode of the generator | ||
| 125 | */ | ||
| 126 | 11 | void CppTraitCopy::protectedMethodImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{ | |
| 127 | //Rule of zero : no hand-written copy<Name>() helper anymore | ||
| 128 | 11 | } | |
| 129 | |||
| 130 | |||
| 131 | ///Implementation of test function | ||
| 132 | /** @param[out] fs : file to be completed | ||
| 133 | * @param classConfig : PClassConfig to be used | ||
| 134 | * @param mode : mode of the generator | ||
| 135 | */ | ||
| 136 | 9 | void CppTraitCopy::testFunction(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{ | |
| 137 |
6/8✓ Branch 0 (2→3) taken 9 times.
✗ Branch 1 (2→6) not taken.
✓ Branch 2 (3→4) taken 9 times.
✗ Branch 3 (3→6) not taken.
✓ Branch 4 (5→6) taken 3 times.
✓ Branch 5 (5→7) taken 6 times.
✓ Branch 6 (8→9) taken 3 times.
✓ Branch 7 (8→10) taken 6 times.
|
9 | if(!mode.enableCopy || !mode.enableGetter || classConfig.getIsEnum()){return;} |
| 138 | 6 | class_createCheckClassEquality(fs, classConfig, false); | |
| 139 | 6 | class_createCheckClassEquality(fs, classConfig, true); | |
| 140 | //A class owning a pointer attribute (std::unique_ptr storage) is no longer copyable under rule of zero, so no copy test can be generated for it | ||
| 141 |
2/2✓ Branch 0 (13→14) taken 5 times.
✓ Branch 1 (13→15) taken 1 times.
|
6 | if(!copy_hasPointerAttribute(classConfig)){ |
| 142 | 5 | class_createTestClassCopy(fs, classConfig, mode); | |
| 143 | } | ||
| 144 | } | ||
| 145 | |||
| 146 | ///Call of the test function | ||
| 147 | /** @param[out] fs : file to be completed | ||
| 148 | * @param classConfig : PClassConfig to be used | ||
| 149 | * @param mode : mode of the generator | ||
| 150 | */ | ||
| 151 | 9 | void CppTraitCopy::testCallFunction(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{ | |
| 152 |
6/7✓ Branch 0 (2→3) taken 9 times.
✗ Branch 1 (2→5) not taken.
✓ Branch 2 (3→4) taken 9 times.
✓ Branch 4 (4→5) taken 3 times.
✓ Branch 5 (4→6) taken 6 times.
✓ Branch 6 (7→8) taken 3 times.
✓ Branch 7 (7→9) taken 6 times.
|
10 | if(!mode.enableCopy || classConfig.getIsEnum()){return;} |
| 153 |
2/2✓ Branch 0 (9→10) taken 6 times.
✓ Branch 2 (10→11) taken 6 times.
|
6 | PString name(classConfig.getName()); |
| 154 |
1/2✗ Branch 0 (11→12) not taken.
✓ Branch 1 (11→19) taken 6 times.
|
6 | if(!mode.enableGetter){ |
| 155 | ✗ | fs << "\t//Cannot create check"+name+"Copy() because there is no getter enabled" << std::endl; | |
| 156 | ✗ | return; | |
| 157 | } | ||
| 158 |
3/3✓ Branch 0 (19→20) taken 6 times.
✓ Branch 2 (20→21) taken 1 times.
✓ Branch 3 (20→32) taken 5 times.
|
6 | if(copy_hasPointerAttribute(classConfig)){ |
| 159 |
6/6✓ Branch 0 (21→22) taken 1 times.
✓ Branch 2 (22→23) taken 1 times.
✓ Branch 4 (23→24) taken 1 times.
✓ Branch 6 (24→25) taken 1 times.
✓ Branch 8 (25→26) taken 1 times.
✓ Branch 10 (26→27) taken 1 times.
|
1 | fs << "\t//Cannot create check"+name+"Copy() because "+name+" owns a pointer attribute and is not copyable anymore" << std::endl; |
| 160 | 1 | return; | |
| 161 | } | ||
| 162 |
3/3✓ Branch 0 (32→33) taken 5 times.
✓ Branch 2 (33→34) taken 5 times.
✓ Branch 4 (34→35) taken 5 times.
|
5 | fs << "\tcheck"+name+"Copy();\n"; |
| 163 |
2/2✓ Branch 0 (39→40) taken 5 times.
✓ Branch 1 (39→42) taken 1 times.
|
6 | } |
| 164 | |||
| 165 | |||
| 166 | |||
| 167 | |||
| 168 |