Merge branch 'cpp-tests' into cpp-fix-1753

This commit is contained in:
Jakob Lykke Andersen 2015-03-02 21:05:31 +01:00
commit 9e83537e90

View File

@ -27,7 +27,7 @@ def parse(name, string):
raise DefinitionError("") raise DefinitionError("")
return res return res
def check(name, input, output=None): def check(name, input, idv1output=None, idv2output=None, output=None):
# first a simple check of the AST # first a simple check of the AST
if output is None: if output is None:
output = input output = input
@ -42,127 +42,193 @@ def check(name, input, output=None):
# Artificially set the prefixedName, otherwise the get_id fails. # Artificially set the prefixedName, otherwise the get_id fails.
# It would usually have been set in handle_signarue. # It would usually have been set in handle_signarue.
ast.prefixedName = ast.name ast.prefixedName = ast.name
ast.get_id_v1()
ast.get_id_v2() if idv2output:
idv2output = "_CPPv2" + idv2output
idv1 = ast.get_id_v1()
idv2 = ast.get_id_v2()
if idv1 != idv1output or idv2 != idv2output:
print(" %s %s" % ("Id v1".rjust(20), "Id v2".rjust(20)))
print("result: %s %s" % (str(idv1).rjust(20), str(idv2).rjust(20)))
print("expected: %s %s" % (str(idv1output).rjust(20), str(idv2output).rjust(20)))
raise DefinitionError("")
ids.append(ast.get_id_v2()) ids.append(ast.get_id_v2())
#print ".. %s:: %s" % (name, input) #print ".. %s:: %s" % (name, input)
def test_type_definitions(): def test_type_definitions():
check("type", "public bool b", "bool b") check("type", "public bool b", "b", "1b", "bool b")
check("type", "bool A::b") check("type", "bool A::b", "A::b", "N1A1bE")
check("type", "bool *b") check("type", "bool *b", "b", "1b")
check("type", "bool *const b") check("type", "bool *const b", "b", "1b")
check("type", "bool *volatile const b") check("type", "bool *volatile const b", "b", "1b")
check("type", "bool *volatile const b") check("type", "bool *volatile const b", "b", "1b")
check("type", "bool *volatile const *b") check("type", "bool *volatile const *b", "b", "1b")
check("type", "bool &b") check("type", "bool &b", "b", "1b")
check("type", "bool b[]") check("type", "bool b[]", "b", "1b")
check("type", "std::pair<int, int> coord") check("type", "std::pair<int, int> coord", "coord", "5coord")
check("type", "long long int foo") check("type", "long long int foo", "foo", "3foo")
check("type", 'std::vector<std::pair<std::string, long long>> module::blah') check("type", 'std::vector<std::pair<std::string, long long>> module::blah',
check("type", "std::function<void()> F") "module::blah", "N6module4blahE")
check("type", "std::function<R(A1, A2, A3)> F") check("type", "std::function<void()> F", "F", "1F")
check("type", "std::function<R(A1, A2, A3, As...)> F") check("type", "std::function<R(A1, A2, A3)> F", "F", "1F")
check("type", "MyContainer::const_iterator") check("type", "std::function<R(A1, A2, A3, As...)> F", "F", "1F")
check("type", "MyContainer::const_iterator",
"MyContainer::const_iterator","N11MyContainer14const_iteratorE")
check("type", check("type",
"public MyContainer::const_iterator", "public MyContainer::const_iterator",
"MyContainer::const_iterator") "MyContainer::const_iterator", "N11MyContainer14const_iteratorE",
output="MyContainer::const_iterator")
# test decl specs on right # test decl specs on right
check("type", "bool const b") check("type", "bool const b", "b", "1b")
check('member', check('member', ' const std::string & name = 42',
' const std::string & name = 42', "name__ssCR", "4name", output='const std::string &name = 42')
'const std::string &name = 42') check('member', ' const std::string & name', "name__ssCR", "4name",
check('member', ' const std::string & name', 'const std::string &name') output='const std::string &name')
check('member', check('member', ' const std::string & name [ n ]',
' const std::string & name [ n ]', "name__ssCRA", "4name", output='const std::string &name[n]')
'const std::string &name[n]') check('member', 'const std::vector< unsigned int, long> &name',
check('member', "name__std::vector:unsigned-i.l:CR",
'const std::vector< unsigned int, long> &name', "4name", output='const std::vector<unsigned int, long> &name')
'const std::vector<unsigned int, long> &name') check('member', 'module::myclass foo[n]', "foo__module::myclassA", "3foo")
check('member', 'module::myclass foo[n]')
check('function', 'operator bool() const') check('function', 'operator bool() const', "castto-b-operatorC", "NKcvbEv")
check('function', 'A::operator bool() const') check('function', 'A::operator bool() const',
check('function', 'A::operator bool() volatile const &') "A::castto-b-operatorC", "NK1AcvbEv")
check('function', 'A::operator bool() volatile const &&') check('function', 'A::operator bool() volatile const &',
check('function', 'bool namespaced::theclass::method(arg1, arg2)') "A::castto-b-operatorVCR", "NVKR1AcvbEv")
check('function', 'A::operator bool() volatile const &&',
"A::castto-b-operatorVCO", "NVKO1AcvbEv")
check('function', 'bool namespaced::theclass::method(arg1, arg2)',
"namespaced::theclass::method__arg1.arg2",
"N10namespaced8theclass6methodE4arg14arg2")
x = 'std::vector<std::pair<std::string, int>> &module::test(register ' \ x = 'std::vector<std::pair<std::string, int>> &module::test(register ' \
'foo, bar, std::string baz = "foobar, blah, bleh") const = 0' 'foo, bar, std::string baz = "foobar, blah, bleh") const = 0'
check('function', x) check('function', x, "module::test__register.bar.ssC",
check('function', 'void f(std::pair<A, B>)') "NK6module4testE8register3barNSt6stringE")
check('function', 'explicit module::myclass::foo::foo()') check('function', 'void f(std::pair<A, B>)',
check('function', 'module::myclass::foo::~foo()') "f__std::pair:A.B:", "1fNSt4pairI1A1BEE")
check('function', 'int printf(const char *fmt, ...)') check('function', 'explicit module::myclass::foo::foo()',
check('function', 'int foo(const unsigned int j)') "module::myclass::foo::foo", "N6module7myclass3foo3fooEv")
check('function', 'int foo(const int *const ptr)') check('function', 'module::myclass::foo::~foo()',
check('function', 'module::myclass::operator std::vector<std::string>()') "module::myclass::foo::~foo", "N6module7myclass3fooD0Ev")
check('function', 'int printf(const char *fmt, ...)',
"printf__cCP.z", "6printfPKcz")
check('function', 'int foo(const unsigned int j)',
"foo__unsigned-iC", "3fooKj")
check('function', 'int foo(const int *const ptr)',
"foo__iCPC", "3fooPCKi")
check('function', 'module::myclass::operator std::vector<std::string>()',
"module::myclass::castto-std::vector:ss:-operator",
"N6module7myclasscvNSt6vectorINSt6stringEEEEv")
check('function', check('function',
'void operator()(const boost::array<VertexID, 2> &v) const') 'void operator()(const boost::array<VertexID, 2> &v) const',
"call-operator__boost::array:VertexID.2:CRC",
"NKclERKN5boost5arrayI8VertexIDX2EEE")
check('function', check('function',
'void operator()(const boost::array<VertexID, 2, "foo, bar"> &v) const') 'void operator()(const boost::array<VertexID, 2, "foo, bar"> &v) const',
check('function', 'MyClass::MyClass(MyClass::MyClass&&)') 'call-operator__boost::array:VertexID.2."foo,--bar":CRC',
check('function', 'constexpr int get_value()') 'NKclERKN5boost5arrayI8VertexIDX2EX"foo, bar"EEE')
check('function', 'static constexpr int get_value()') check('function', 'MyClass::MyClass(MyClass::MyClass&&)',
check('function', 'int get_value() const noexcept') "MyClass::MyClass__MyClass::MyClassRR",
check('function', 'int get_value() const noexcept = delete') "N7MyClass7MyClassERRN7MyClass7MyClassE")
check('function', 'int get_value() volatile const') check('function', 'constexpr int get_value()', "get_valueCE", "9get_valuev")
check('function', 'MyClass::MyClass(MyClass::MyClass&&) = default') check('function', 'static constexpr int get_value()',
check('function', 'virtual MyClass::a_virtual_function() const override') "get_valueCE", "9get_valuev")
check('function', 'A B() override') check('function', 'int get_value() const noexcept',
check('function', 'A B() final') "get_valueC", "NK9get_valueEv")
check('function', 'A B() final override') check('function', 'int get_value() const noexcept = delete',
check('function', 'A B() override final', 'A B() final override') "get_valueC", "NK9get_valueEv")
check('function', 'MyClass::a_member_function() volatile') check('function', 'int get_value() volatile const',
check('function', 'MyClass::a_member_function() volatile const') "get_valueVC", "NVK9get_valueEv")
check('function', 'MyClass::a_member_function() &&') check('function', 'MyClass::MyClass(MyClass::MyClass&&) = default',
check('function', 'MyClass::a_member_function() &') "MyClass::MyClass__MyClass::MyClassRR",
check('function', 'MyClass::a_member_function() const &') "N7MyClass7MyClassERRN7MyClass7MyClassE")
check('function', 'int main(int argc, char *argv[])') check('function', 'virtual MyClass::a_virtual_function() const override',
check('function', 'MyClass &MyClass::operator++()') "MyClass::a_virtual_functionC", "NK7MyClass18a_virtual_functionEv")
check('function', 'MyClass::pointer MyClass::operator->()') check('function', 'A B() override', "B", "1Bv")
check('function', 'A B() final', "B", "1Bv")
check('function', 'A B() final override', "B", "1Bv")
check('function', 'A B() override final', "B", "1Bv",
output='A B() final override')
check('function', 'MyClass::a_member_function() volatile',
"MyClass::a_member_functionV", "NV7MyClass17a_member_functionEv")
check('function', 'MyClass::a_member_function() volatile const',
"MyClass::a_member_functionVC", "NVK7MyClass17a_member_functionEv")
check('function', 'MyClass::a_member_function() &&',
"MyClass::a_member_functionO", "NO7MyClass17a_member_functionEv")
check('function', 'MyClass::a_member_function() &',
"MyClass::a_member_functionR", "NR7MyClass17a_member_functionEv")
check('function', 'MyClass::a_member_function() const &',
"MyClass::a_member_functionCR", "NKR7MyClass17a_member_functionEv")
check('function', 'int main(int argc, char *argv[])',
"main__i.cPA", "4mainiPA_c")
check('function', 'MyClass &MyClass::operator++()',
"MyClass::inc-operator", "N7MyClassppEv")
check('function', 'MyClass::pointer MyClass::operator->()',
"MyClass::pointer-operator", "N7MyClassptEv")
x = 'std::vector<std::pair<std::string, int>> &module::test(register ' \ x = 'std::vector<std::pair<std::string, int>> &module::test(register ' \
'foo, bar[n], std::string baz = "foobar, blah, bleh") const = 0' 'foo, bar[n], std::string baz = "foobar, blah, bleh") const = 0'
check('function', x) check('function', x, "module::test__register.barA.ssC",
"NK6module4testE8registerAn_3barNSt6stringE")
check('function', check('function',
'int foo(Foo f = Foo(double(), std::make_pair(int(2), double(3.4))))') 'int foo(Foo f = Foo(double(), std::make_pair(int(2), double(3.4))))',
check('function', 'int foo(A a = x(a))') "foo__Foo", "3foo3Foo")
check('function', 'int foo(A a = x(a))', "foo__A", "3foo1A")
raises(DefinitionError, parse, 'function', 'int foo(B b=x(a)') raises(DefinitionError, parse, 'function', 'int foo(B b=x(a)')
raises(DefinitionError, parse, 'function', 'int foo)C c=x(a))') raises(DefinitionError, parse, 'function', 'int foo)C c=x(a))')
raises(DefinitionError, parse, 'function', 'int foo(D d=x(a') raises(DefinitionError, parse, 'function', 'int foo(D d=x(a')
check('function', 'int foo(const A&... a)') check('function', 'int foo(const A&... a)', "foo__ACRDp", "3fooRDpK1A")
check('function', 'virtual void f()') check('function', 'virtual void f()', "f", "1fv")
# test for ::nestedName, from issue 1738 # test for ::nestedName, from issue 1738
check("function", "result(int val, ::std::error_category const &cat)") check("function", "result(int val, ::std::error_category const &cat)",
"result__i.std::error_categoryCR", "6resultiRNSt14error_categoryE")
check('class', 'public A', 'A') check('class', 'public A', "A", "1A", output='A')
check('class', 'private A') check('class', 'private A', "A", "1A")
check('enum', 'A') check('enum', 'A', None, "1A")
check('enum', 'A : std::underlying_type<B>::type') check('enum', 'A : std::underlying_type<B>::type', None, "1A")
check('enum', 'A : unsigned int') check('enum', 'A : unsigned int', None, "1A")
check('enum', 'public A', 'A') check('enum', 'public A', None, "1A", output='A')
check('enum', 'private A') check('enum', 'private A', None, "1A")
check('enumerator', 'A') check('enumerator', 'A', None, "1A")
check('enumerator', 'A = std::numeric_limits<unsigned long>::max()') check('enumerator', 'A = std::numeric_limits<unsigned long>::max()',
None, "1A")
def test_bases(): def test_bases():
check('class', 'A') check('class', 'A', "A", "1A")
check('class', 'A::B::C') check('class', 'A::B::C', "A::B::C", "N1A1B1CE")
check('class', 'A : B') check('class', 'A : B', "A", "1A")
check('class', 'A : private B', 'A : B') check('class', 'A : private B', "A", "1A", output='A : B')
check('class', 'A : public B') check('class', 'A : public B', "A", "1A")
check('class', 'A : B, C') check('class', 'A : B, C', "A", "1A")
check('class', 'A : B, protected C, D') check('class', 'A : B, protected C, D', "A", "1A")
def test_operators(): def test_operators():
check('function', 'void operator new [ ] ()', 'void operator new[]()') check('function', 'void operator new [ ] ()',
check('function', 'void operator delete ()', 'void operator delete()') "new-array-operator", "nav", output='void operator new[]()')
check('function', 'void operator bool() const', 'void operator bool() const') check('function', 'void operator delete ()',
for op in '*-+=/%!': "delete-operator", "dlv", output='void operator delete()')
check('function', 'void operator %s ()' % op, 'void operator%s()' % op) check('function', 'void operator bool() const',
"castto-b-operatorC", "NKcvbEv", output='void operator bool() const')
check('function', 'void operator * ()',
"mul-operator", "mlv", output='void operator*()')
check('function', 'void operator - ()',
"sub-operator", "miv", output='void operator-()')
check('function', 'void operator + ()',
"add-operator", "plv", output='void operator+()')
check('function', 'void operator = ()',
"assign-operator", "aSv", output='void operator=()')
check('function', 'void operator / ()',
"div-operator", "dvv", output='void operator/()')
check('function', 'void operator % ()',
"mod-operator", "rmv", output='void operator%()')
check('function', 'void operator ! ()',
"not-operator", "ntv", output='void operator!()')
#def test_print(): #def test_print():
# # used for getting all the ids out for checking # # used for getting all the ids out for checking