Skip to content

Commit d505181

Browse files
author
roman_yakovenko
committed
add new test case and bit fields size to the decl_printer
1 parent ed14817 commit d505181

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

pygccxml/declarations/decl_printer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ def visit_variable(self ):
262262
self.writer( ' ' * curr_level * self.INDENT_SIZE + 'type: %s' % self.__inst.type.decl_string + os.linesep)
263263
self.writer( ' ' * curr_level * self.INDENT_SIZE + 'value: %s' % self.__inst.value + os.linesep)
264264
if self.__print_details:
265+
if self.__inst.bits:
266+
bits = 'bits: %d'%(self.__inst.bits)
267+
self.writer( ' ' * curr_level * self.INDENT_SIZE + bits.ljust( self.JUSTIFY ) + os.linesep)
268+
265269
byte_size = 'size: %d'%(self.__inst.type.byte_size)
266270
self.writer( ' ' * curr_level * self.INDENT_SIZE + byte_size.ljust( self.JUSTIFY ) + os.linesep)
267271
try:

unittests/gccxml10184_tester.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright 2004-2008 Roman Yakovenko.
2+
# Distributed under the Boost Software License, Version 1.0. (See
3+
# accompanying file LICENSE_1_0.txt or copy at
4+
# http://www.boost.org/LICENSE_1_0.txt)
5+
6+
import os
7+
import sys
8+
import unittest
9+
import autoconfig
10+
import parser_test_case
11+
12+
from pygccxml import utils
13+
from pygccxml import parser
14+
from pygccxml import declarations
15+
16+
code = \
17+
"""
18+
class A {
19+
public:
20+
virtual ~A() = 0;
21+
unsigned int a : 1;
22+
unsigned int unused : 31;
23+
};
24+
"""
25+
26+
class tester_t( parser_test_case.parser_test_case_t ):
27+
def __init__(self, *args):
28+
parser_test_case.parser_test_case_t.__init__(self, *args)
29+
30+
def test(self):
31+
src_reader = parser.source_reader_t( self.config )
32+
global_ns = declarations.get_global_namespace( src_reader.read_string( code ) )
33+
self.failUnless( global_ns.var( 'a' ).bits == 1 )
34+
self.failUnless( global_ns.var( 'unused' ).bits == 31 )
35+
36+
def create_suite():
37+
suite = unittest.TestSuite()
38+
suite.addTest( unittest.makeSuite(tester_t))
39+
return suite
40+
41+
def run_suite():
42+
unittest.TextTestRunner(verbosity=2).run( create_suite() )
43+
44+
if __name__ == "__main__":
45+
run_suite()

unittests/test_all.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@
5555
import calling_convention_tester
5656
import const_volatile_arg_tester
5757
import array_bug_tester
58-
import gccxml10185_tester
5958
import gccxml10183_tester
59+
import gccxml10184_tester
60+
import gccxml10185_tester
6061

6162
testers = [
6263
decl_string_tester
@@ -108,8 +109,9 @@
108109
, calling_convention_tester
109110
, const_volatile_arg_tester
110111
, array_bug_tester
111-
, gccxml10185_tester
112-
, gccxml10183_tester
112+
, gccxml10183_tester
113+
, gccxml10184_tester
114+
, gccxml10185_tester
113115
]
114116

115117
def create_suite():

0 commit comments

Comments
 (0)