Skip to content

Commit 58dedeb

Browse files
author
roman_yakovenko
committed
adding problematic use case, contributed by Zbigniew Mandziejewicz
1 parent 43dabe4 commit 58dedeb

File tree

6 files changed

+109
-5
lines changed

6 files changed

+109
-5
lines changed

pygccxml/declarations/decl_printer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__( self, level=0, print_details=True, recursive=True, writer=None, ve
2929
self.__verbose = verbose
3030
self.__writer = writer
3131
if not self.__writer:
32-
self.__writer = lambda x: sys.stdout.write( x + os.linesep )
32+
self.__writer = lambda x: sys.stdout.write( x )
3333

3434
def clone(self, increment_level=True):
3535
level = self.__level
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef __all_h_10062009__
2+
#define __all_h_10062009__ 1
3+
4+
#include "data.h"
5+
#include "base.h"
6+
#include "derived.h"
7+
8+
#endif//__all_h_10062009__
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef __base_h_10062009__
2+
#define __base_h_10062009__ 1
3+
4+
#include "data.h"
5+
6+
namespace buggy{
7+
8+
struct base_t{
9+
virtual ~base_t() {};
10+
virtual data_t* get_data() const = 0;
11+
};
12+
13+
}
14+
15+
#endif//__base_h_10062009__
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef __data_h_10062009__
2+
#define __data_h_10062009__ 1
3+
4+
namespace std{
5+
6+
template<class T1, class T2>
7+
struct pair{
8+
typedef pair<T1, T2> _Myt;
9+
typedef T1 first_type;
10+
typedef T2 second_type;
11+
12+
pair(): first(T1()), second(T2())
13+
{}
14+
15+
pair(const T1& t1, const T2& t2)
16+
: first(t1), second(t2)
17+
{}
18+
19+
T1 first; // the first stored value
20+
T2 second; // the second stored value
21+
};
22+
}
23+
24+
namespace buggy{
25+
26+
struct data_t{
27+
typedef std::pair<data_t*, data_t*> pair_t;
28+
};
29+
30+
}
31+
32+
#endif//__data_h_10062009__
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef __derived_h_10062009__
2+
#define __derived_h_10062009__ 1
3+
4+
#include "base.h"
5+
6+
namespace buggy{
7+
8+
class derived_t: public base_t{
9+
public:
10+
11+
virtual ~derived_t() {};
12+
virtual data_t* get_data() const;
13+
14+
private:
15+
data_t::pair_t data_pair;
16+
};
17+
18+
}
19+
20+
#endif//__derived_h_10062009__

unittests/project_reader_correctness_tester.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import pygccxml
1111
from pygccxml import utils
1212
from pygccxml import parser
13-
from pygccxml import declarations
13+
from pygccxml import declarations
1414

1515
class tester_t( parser_test_case.parser_test_case_t ):
1616
def __init__(self, *args):
@@ -50,10 +50,39 @@ def __test_correctness_impl(self, file_name ):
5050
def test_correctness(self):
5151
for src in self.__files:
5252
self.__test_correctness_impl( src )
53-
53+
54+
55+
class tester2_t( parser_test_case.parser_test_case_t ):
56+
def __init__(self, *args):
57+
parser_test_case.parser_test_case_t.__init__(self, *args)
58+
self.__files = [
59+
'separate_compilation/data.h'
60+
, 'separate_compilation/base.h'
61+
, 'separate_compilation/derived.h'
62+
]
63+
64+
def test(self):
65+
prj_reader = parser.project_reader_t( self.config )
66+
prj_decls = prj_reader.read_files( self.__files
67+
, compilation_mode=parser.COMPILATION_MODE.FILE_BY_FILE )
68+
src_reader = parser.source_reader_t( self.config )
69+
src_decls = src_reader.read_file( 'separate_compilation/all.h' )
70+
if src_decls != prj_decls:
71+
s = src_decls[0]
72+
p = prj_decls[0]
73+
sr = file( os.path.join( autoconfig.build_directory , 'separate_compilation.sr.txt'),'w+b' )
74+
pr = file( os.path.join( autoconfig.build_directory , 'separate_compilation.pr.txt'), 'w+b' )
75+
declarations.print_declarations( s, writer=lambda l: sr.write( l ) )
76+
declarations.print_declarations( p, writer=lambda l: pr.write( l ) )
77+
sr.close()
78+
pr.close()
79+
self.fail( "Expected - There is a difference between declarations" )
80+
81+
5482
def create_suite():
55-
suite = unittest.TestSuite()
56-
suite.addTest( unittest.makeSuite(tester_t))
83+
suite = unittest.TestSuite()
84+
suite.addTest( unittest.makeSuite(tester_t))
85+
suite.addTest( unittest.makeSuite(tester2_t))
5786
return suite
5887

5988
def run_suite():

0 commit comments

Comments
 (0)