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