| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2017 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 import logging |
| 7 import sys |
| 8 import unittest |
| 9 |
| 10 import function_signature |
| 11 |
| 12 |
| 13 class AnalyzeTest(unittest.TestCase): |
| 14 |
| 15 def testParseFunctionSignature(self): |
| 16 def check(ret_part, name_part, params_part, after_part=''): |
| 17 signature = ''.join((name_part, params_part, after_part)) |
| 18 got_full, got_name = function_signature.Parse(signature) |
| 19 self.assertEqual(name_part + after_part, got_name) |
| 20 self.assertEqual(name_part + params_part + after_part, got_full) |
| 21 if ret_part: |
| 22 signature = ''.join((ret_part, name_part, params_part, after_part)) |
| 23 got_full, got_name = function_signature.Parse(signature) |
| 24 self.assertEqual(name_part + after_part, got_name) |
| 25 self.assertEqual(name_part + params_part + after_part, got_full) |
| 26 |
| 27 check('bool ', |
| 28 'foo::Bar<unsigned int, int>::Do<unsigned int>', |
| 29 '(unsigned int)') |
| 30 check('base::internal::CheckedNumeric<int>& ', |
| 31 'base::internal::CheckedNumeric<int>::operator+=<int>', |
| 32 '(int)') |
| 33 check('base::internal::CheckedNumeric<int>& ', |
| 34 'b::i::CheckedNumeric<int>::MathOp<b::i::CheckedAddOp, int>', |
| 35 '(int)') |
| 36 check('', '(anonymous namespace)::GetBridge', '(long long)') |
| 37 check('', 'operator delete', '(void*)') |
| 38 check('', 'b::i::DstRangeRelationToSrcRangeImpl<long long, long long, ' |
| 39 'std::__ndk1::numeric_limits, (b::i::Integer)1>::Check', |
| 40 '(long long)') |
| 41 check('', 'cc::LayerIterator::operator cc::LayerIteratorPosition const', |
| 42 '()', |
| 43 ' const') |
| 44 check('decltype ({parm#1}((SkRecords::NoOp)())) ', |
| 45 'SkRecord::Record::visit<SkRecords::Draw&>', |
| 46 '(SkRecords::Draw&)', |
| 47 ' const') |
| 48 check('', 'base::internal::BindStateBase::BindStateBase', |
| 49 '(void (*)(), void (*)(base::internal::BindStateBase const*))') |
| 50 check('int ', 'std::__ndk1::__c11_atomic_load<int>', |
| 51 '(std::__ndk1::<int> volatile*, std::__ndk1::memory_order)') |
| 52 check('std::basic_ostream<char, std::char_traits<char> >& ', |
| 53 'std::operator<< <std::char_traits<char> >', |
| 54 '(std::basic_ostream<char, std::char_traits<char> >&, char)') |
| 55 check('v8::internal::SlotCallbackResult ', |
| 56 'v8::internal::UpdateTypedSlotHelper::UpdateCodeTarget' |
| 57 '<v8::PointerUpdateJobTraits<(v8::Direction)1>::Foo(v8::Heap*, ' |
| 58 'v8::MemoryChunk*)::{lambda(v8::SlotType, unsigned char*)#2}::' |
| 59 'operator()(v8::SlotType, unsigned char*, unsigned char*) ' |
| 60 'const::{lambda(v8::Object**)#1}>', |
| 61 '(v8::RelocInfo, v8::Foo<(v8::PointerDirection)1>::Bar(v8::Heap*)::' |
| 62 '{lambda(v8::SlotType)#2}::operator()(v8::SlotType) const::' |
| 63 '{lambda(v8::Object**)#1})') |
| 64 check('', |
| 65 'WTF::StringAppend<WTF::String, WTF::String>::operator WTF::String', |
| 66 '()', |
| 67 ' const') |
| 68 # Make sure []s are not removed from the name part. |
| 69 check('', 'Foo', '()', ' [virtual thunk]') |
| 70 |
| 71 # SkArithmeticImageFilter.cpp has class within function body. e.g.: |
| 72 # ArithmeticFP::onCreateGLSLInstance() looks like: |
| 73 # class ArithmeticFP { |
| 74 # GrGLSLFragmentProcessor* onCreateGLSLInstance() const { |
| 75 # class GLSLFP { |
| 76 # void emitCode(EmitArgs& args) { ... } |
| 77 # }; |
| 78 # ... |
| 79 # } |
| 80 # }; |
| 81 SIG = '(anonymous namespace)::Foo::Baz() const::GLSLFP::onData(Foo, Bar)' |
| 82 got_full, got_name = function_signature.Parse(SIG) |
| 83 self.assertEqual('(anonymous namespace)::Foo::Baz', got_name) |
| 84 self.assertEqual(SIG, got_full) |
| 85 |
| 86 |
| 87 if __name__ == '__main__': |
| 88 logging.basicConfig(level=logging.DEBUG, |
| 89 format='%(levelname).1s %(relativeCreated)6d %(message)s') |
| 90 unittest.main() |
| OLD | NEW |