GCC Code Coverage Report


Directory: ./
File: src/TraitBackEnd/Nanobind/NanobindTraitProperty/NanobindTraitProperty.cpp
Date: 2026-01-30 16:30:53
Exec Total Coverage
Lines: 35 38 92.1%
Functions: 7 8 87.5%
Branches: 99 115 86.1%

Line Branch Exec Source
1 /***************************************
2 Auteur : Thibaut Oprinsen
3 Mail : thibaut.oprinsen@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7 #include "NanobindTraitProperty.h"
8
9 ///Constructor of NanobindTraitProperty
10 1 NanobindTraitProperty::NanobindTraitProperty()
11 1 : PAbstractNanobindTraitBackend()
12 1 {}
13
14 ///Destructor of NanobindTraitProperty
15 2 NanobindTraitProperty::~NanobindTraitProperty(){}
16
17 ///Creates a getter method name
18 /** @param varName : name of the var to get
19 * @return getter method name
20 */
21 5 PString createGetterMethodName(const PString & varName){
22
3/3
✓ Branch 0 (2→3) taken 5 times.
✓ Branch 2 (3→4) taken 5 times.
✓ Branch 4 (4→5) taken 5 times.
5 return "get" + varName.firstToUpper();
23 }
24
25 ///Creates a setter method name
26 /** @param varName : name of the var to set
27 * @return setter method name
28 */
29 5 PString createSetterMethodName(const PString & varName){
30
3/3
✓ Branch 0 (2→3) taken 5 times.
✓ Branch 2 (3→4) taken 5 times.
✓ Branch 4 (4→5) taken 5 times.
5 return "set" + varName.firstToUpper();
31 }
32
33 ///Registration of property
34 /// @param fs stream to write to
35 /// @param classConfig config of the class
36 /// @param mode generator mode
37 2 void NanobindTraitProperty::registerProperty(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
38
4/8
✓ Branch 0 (2→3) taken 2 times.
✗ Branch 1 (2→6) not taken.
✓ Branch 2 (3→4) taken 2 times.
✗ Branch 3 (3→6) not taken.
✗ Branch 4 (5→6) not taken.
✓ Branch 5 (5→7) taken 2 times.
✗ Branch 6 (8→9) not taken.
✓ Branch 7 (8→10) taken 2 times.
2 if(!mode.enableSetter || !mode.enableGetter || classConfig.getIsEnum()){return;}
39
40 2 const PVecClassAttribute & listAttr(classConfig.getListAttribute());
41
2/2
✓ Branch 0 (75→12) taken 5 times.
✓ Branch 1 (75→76) taken 2 times.
14 for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
42
4/4
✓ Branch 0 (12→13) taken 5 times.
✓ Branch 2 (15→16) taken 5 times.
✓ Branch 4 (16→17) taken 5 times.
✓ Branch 6 (17→18) taken 5 times.
10 fs << "\t\t.def_prop_rw(\"" << it->getName() << "\",";
43
9/9
✓ Branch 0 (18→19) taken 5 times.
✓ Branch 2 (19→20) taken 5 times.
✓ Branch 4 (20→21) taken 5 times.
✓ Branch 6 (21→22) taken 5 times.
✓ Branch 8 (22→23) taken 5 times.
✓ Branch 10 (25→26) taken 5 times.
✓ Branch 12 (26→27) taken 5 times.
✓ Branch 14 (27→28) taken 5 times.
✓ Branch 16 (28→29) taken 5 times.
10 fs << std::endl << "\t\t\t[]( " << classConfig.getName() << " &c) { return c." << createGetterMethodName(it->getName()) << "(); },";
44
14/14
✓ Branch 0 (30→31) taken 5 times.
✓ Branch 2 (31→32) taken 5 times.
✓ Branch 4 (32→33) taken 5 times.
✓ Branch 6 (33→34) taken 5 times.
✓ Branch 8 (34→35) taken 5 times.
✓ Branch 10 (37→38) taken 5 times.
✓ Branch 12 (40→41) taken 5 times.
✓ Branch 14 (41→42) taken 5 times.
✓ Branch 16 (42→43) taken 5 times.
✓ Branch 18 (43→44) taken 5 times.
✓ Branch 20 (46→47) taken 5 times.
✓ Branch 22 (47→48) taken 5 times.
✓ Branch 24 (48→49) taken 5 times.
✓ Branch 26 (49→50) taken 5 times.
20 fs << std::endl << "\t\t\t[]( " << classConfig.getName() << " &c, " << makeVarType(it->getType(), true, false, false, it->getIsPointer()) << " value) { c." << createSetterMethodName(it->getName()) << "(value); })";
45
2/2
✓ Branch 0 (63→64) taken 3 times.
✓ Branch 1 (63→65) taken 2 times.
15 if(it != listAttr.end() - 1){
46
1/1
✓ Branch 0 (64→65) taken 3 times.
3 fs << std::endl;
47 }
48 }
49 }
50
51 ///Generate test function for property
52 /// @param fs stream to write to
53 /// @param classConfig config of the class
54 /// @param mode generator mode
55 /// @param baseFileName : base name of the configuration
56 2 void NanobindTraitProperty::testFunction(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode, const PString & baseFileName) const{
57
5/9
✓ Branch 0 (2→3) taken 2 times.
✗ Branch 1 (2→6) not taken.
✓ Branch 2 (3→4) taken 2 times.
✗ Branch 3 (3→6) not taken.
✓ Branch 4 (4→5) taken 2 times.
✗ Branch 6 (5→6) not taken.
✓ Branch 7 (5→7) taken 2 times.
✗ Branch 8 (8→9) not taken.
✓ Branch 9 (8→10) taken 2 times.
2 if(!mode.enableSetter || !mode.enableSetter || classConfig.getIsEnum()){return;}
58
3/3
✓ Branch 0 (10→11) taken 2 times.
✓ Branch 2 (11→12) taken 2 times.
✓ Branch 4 (12→13) taken 2 times.
2 PString moduleName = baseFileName.toLower() + "_module";
59
2/2
✓ Branch 0 (15→16) taken 2 times.
✓ Branch 2 (16→17) taken 2 times.
2 PString className = classConfig.getName().toLower();
60
5/5
✓ Branch 0 (17→18) taken 2 times.
✓ Branch 2 (18→19) taken 2 times.
✓ Branch 4 (19→20) taken 2 times.
✓ Branch 6 (20→21) taken 2 times.
✓ Branch 8 (21→22) taken 2 times.
2 fs << "#Test getters and setters of the " << classConfig.getName() << " property trait" << std::endl;
61
2/2
✓ Branch 0 (22→23) taken 2 times.
✓ Branch 2 (23→24) taken 2 times.
2 fs << "def test_attributes_setters_getters():" << std::endl;
62
2/2
✓ Branch 0 (24→25) taken 2 times.
✓ Branch 2 (25→26) taken 2 times.
2 fs << "\t\"\"\"Test setters and getters of attributes generated by Nanobind\"\"\"" << std::endl;
63
3/3
✓ Branch 0 (26→27) taken 2 times.
✓ Branch 2 (27→28) taken 2 times.
✓ Branch 4 (28→29) taken 2 times.
2 fs << "\t" << "# Test default constructor" << std::endl;
64
9/9
✓ Branch 0 (29→30) taken 2 times.
✓ Branch 2 (30→31) taken 2 times.
✓ Branch 4 (31→32) taken 2 times.
✓ Branch 6 (32→33) taken 2 times.
✓ Branch 8 (33→34) taken 2 times.
✓ Branch 10 (34→35) taken 2 times.
✓ Branch 12 (35→36) taken 2 times.
✓ Branch 14 (36→37) taken 2 times.
✓ Branch 16 (37→38) taken 2 times.
2 fs << "\t" << className << " = " << moduleName << "." << classConfig.getName() << "()" << std::endl;
65
3/3
✓ Branch 0 (38→39) taken 2 times.
✓ Branch 2 (39→40) taken 2 times.
✓ Branch 4 (40→41) taken 2 times.
2 fs << "\t" << "# Test properties" << std::endl;
66
1/1
✓ Branch 0 (41→42) taken 2 times.
2 const PVecClassAttribute & listAttr(classConfig.getListAttribute());
67
2/2
✓ Branch 0 (79→43) taken 5 times.
✓ Branch 1 (79→80) taken 2 times.
14 for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
68
2/2
✓ Branch 0 (45→46) taken 5 times.
✓ Branch 2 (46→47) taken 5 times.
5 PString defaultValue = getTestDefaultValueTypeInPython(it->getType());
69
8/8
✓ Branch 0 (47→48) taken 5 times.
✓ Branch 2 (48→49) taken 5 times.
✓ Branch 4 (49→50) taken 5 times.
✓ Branch 6 (52→53) taken 5 times.
✓ Branch 8 (53→54) taken 5 times.
✓ Branch 10 (54→55) taken 5 times.
✓ Branch 12 (55→56) taken 5 times.
✓ Branch 14 (56→57) taken 5 times.
10 fs << "\t" << className << "." << it->getName() << " = " << defaultValue << std::endl;
70
9/9
✓ Branch 0 (57→58) taken 5 times.
✓ Branch 2 (58→59) taken 5 times.
✓ Branch 4 (59→60) taken 5 times.
✓ Branch 6 (60→61) taken 5 times.
✓ Branch 8 (63→64) taken 5 times.
✓ Branch 10 (64→65) taken 5 times.
✓ Branch 12 (65→66) taken 5 times.
✓ Branch 14 (66→67) taken 5 times.
✓ Branch 16 (67→68) taken 5 times.
10 fs << "\t" << "assert " << className << "." << it->getName() << " == " << defaultValue << std::endl;
71 5 }
72
1/1
✓ Branch 0 (80→81) taken 2 times.
2 fs << std::endl;
73 2 }
74
75 ///Call of the test function
76 /// @param fs stream to write to
77 /// @param classConfig config of the class
78 /// @param mode generator mode
79 void NanobindTraitProperty::testCallFunction(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
80 if(!mode.enableSetter || !mode.enableSetter || classConfig.getIsEnum()){return;}
81
82 fs << "\ttest_attributes_setters_getters()" << std::endl;
83 }
84