diff options
Diffstat (limited to 'testing/generate_gmock_mutant.py')
-rwxr-xr-x | testing/generate_gmock_mutant.py | 57 |
1 files changed, 23 insertions, 34 deletions
diff --git a/testing/generate_gmock_mutant.py b/testing/generate_gmock_mutant.py index 6d814f0..a6ee4c3 100755 --- a/testing/generate_gmock_mutant.py +++ b/testing/generate_gmock_mutant.py @@ -56,8 +56,8 @@ HEADER = """\ // } // // void QuitMessageLoop(int seconds) { -// MessageLoop* loop = MessageLoop::current(); -// loop->PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), +// base::MessageLoop* loop = base::MessageLoop::current(); +// loop->PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), // 1000 * seconds); // } // }; @@ -202,7 +202,7 @@ struct MutantFunctor { } inline R operator()() { - return impl_->RunWithParams(Tuple0()); + return impl_->RunWithParams(Tuple<>()); } template <typename Arg1> @@ -241,8 +241,8 @@ FOOTER = """\ # Templates for DispatchToMethod/DispatchToFunction functions. # template_params - typename P1, typename P2.. typename C1.. -# prebound - TupleN<P1, .. PN> -# calltime - TupleN<C1, .. CN> +# prebound - Tuple<P1, .. PN> +# calltime - Tuple<C1, .. CN> # args - p.a, p.b.., c.a, c.b.. DISPATCH_TO_METHOD_TEMPLATE = """\ template <typename R, typename T, typename Method, %(template_params)s> @@ -264,8 +264,8 @@ inline R DispatchToFunction(Function function, # Templates for CreateFunctor functions. # template_params - typename P1, typename P2.. typename C1.. typename X1.. -# prebound - TupleN<P1, .. PN> -# calltime - TupleN<A1, .. AN> +# prebound - Tuple<P1, .. PN> +# calltime - Tuple<A1, .. AN> # params - X1,.. , A1, .. # args - const P1& p1 .. # call_args - p1, p2, p3.. @@ -305,7 +305,7 @@ def SplitLine(line, width): return (line[:n], line[n + 1:]) -def Wrap(s, width, subsequent_offset=4): +def Wrap(s, width, subsequent_offset): """Wraps a single line |s| at commas so every line is at most |width| characters long. """ @@ -324,10 +324,8 @@ def Clean(s): Our simple string formatting/concatenation may introduce extra commas. """ - s = s.replace("<>", "") s = s.replace(", >", ">") s = s.replace(", )", ")") - s = s.replace(">>", "> >") return s @@ -339,23 +337,13 @@ def ExpandPattern(pattern, it): return [pattern.replace("%", x) for x in it] -def Gen(pattern, n): - """Expands pattern replacing '%' with sequential integers. +def Gen(pattern, n, start): + """Expands pattern replacing '%' with sequential integers starting with start. Expanded patterns will be joined with comma separator. - GenAlphs("X%", 3) will return "X1, X2, X3". + Gen("X%", 3, 1) will return "X1, X2, X3". """ - it = string.hexdigits[1:n + 1] - return ", ".join(ExpandPattern(pattern, it)) - - -def GenAlpha(pattern, n): - """Expands pattern replacing '%' with sequential small ASCII letters. - - Expanded patterns will be joined with comma separator. - GenAlphs("X%", 3) will return "Xa, Xb, Xc". - """ - it = string.ascii_lowercase[0:n] + it = string.hexdigits[start:n + start] return ", ".join(ExpandPattern(pattern, it)) @@ -364,7 +352,7 @@ def Merge(a): def GenTuple(pattern, n): - return Clean("Tuple%d<%s>" % (n, Gen(pattern, n))) + return Clean("Tuple<%s>" % (Gen(pattern, n, 1))) def FixCode(s): @@ -378,11 +366,12 @@ def FixCode(s): def GenerateDispatch(prebound, calltime): print "\n// %d - %d" % (prebound, calltime) args = { - "template_params": Merge([Gen("typename P%", prebound), - Gen("typename C%", calltime)]), + "template_params": Merge([Gen("typename P%", prebound, 1), + Gen("typename C%", calltime, 1)]), "prebound": GenTuple("P%", prebound), "calltime": GenTuple("C%", calltime), - "args": Merge([GenAlpha("p.%", prebound), GenAlpha("c.%", calltime)]), + "args": Merge([Gen("get<%>(p)", prebound, 0), + Gen("get<%>(c)", calltime, 0)]), } print FixCode(DISPATCH_TO_METHOD_TEMPLATE % args) @@ -394,12 +383,12 @@ def GenerateCreateFunctor(prebound, calltime): args = { "calltime": GenTuple("A%", calltime), "prebound": GenTuple("P%", prebound), - "params": Merge([Gen("X%", prebound), Gen("A%", calltime)]), - "args": Gen("const P%& p%", prebound), - "call_args": Gen("p%", prebound), - "template_params": Merge([Gen("typename P%", prebound), - Gen("typename A%", calltime), - Gen("typename X%", prebound)]) + "params": Merge([Gen("X%", prebound, 1), Gen("A%", calltime, 1)]), + "args": Gen("const P%& p%", prebound, 1), + "call_args": Gen("p%", prebound, 1), + "template_params": Merge([Gen("typename P%", prebound, 1), + Gen("typename A%", calltime, 1), + Gen("typename X%", prebound, 1)]) } mutant = FixCode(CREATE_METHOD_FUNCTOR_TEMPLATE % args) |