Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: testing/generate_gmock_mutant.py

Issue 1159553007: Move Tuple to base namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « storage/browser/fileapi/sandbox_file_stream_writer.cc ('k') | testing/gmock_mutant.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import string 6 import string
7 import sys 7 import sys
8 8
9 HEADER = """\ 9 HEADER = """\
10 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 10 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 // EXPECT_CALL(mock, DemiurgeCreated(_)).Times(1) 106 // EXPECT_CALL(mock, DemiurgeCreated(_)).Times(1)
107 // .WillOnce(Invoke(CreateFunctor(&mock, &Mock::StoreDemiurge))); 107 // .WillOnce(Invoke(CreateFunctor(&mock, &Mock::StoreDemiurge)));
108 // 108 //
109 // EXPECT_CALL(mock, OnRequest(_, StrEq("Moby Dick"))) 109 // EXPECT_CALL(mock, OnRequest(_, StrEq("Moby Dick")))
110 // .Times(AnyNumber()) 110 // .Times(AnyNumber())
111 // .WillAlways(WithArgs<0>(Invoke( 111 // .WillAlways(WithArgs<0>(Invoke(
112 // CreateFunctor(&mock->demiurge_, &Demiurge::DecreaseMonsters)))); 112 // CreateFunctor(&mock->demiurge_, &Demiurge::DecreaseMonsters))));
113 // 113 //
114 114
115 #include "base/memory/linked_ptr.h" 115 #include "base/memory/linked_ptr.h"
116 #include "base/tuple.h" // for Tuple 116 #include "base/tuple.h"
117 117
118 namespace testing {""" 118 namespace testing {"""
119 119
120 MUTANT = """\ 120 MUTANT = """\
121 121
122 // Interface that is exposed to the consumer, that does the actual calling 122 // Interface that is exposed to the consumer, that does the actual calling
123 // of the method. 123 // of the method.
124 template <typename R, typename Params> 124 template <typename R, typename Params>
125 class MutantRunner { 125 class MutantRunner {
126 public: 126 public:
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 // Redirects operator() to MutantRunner<Params>::Run() 195 // Redirects operator() to MutantRunner<Params>::Run()
196 template <typename R, typename Params> 196 template <typename R, typename Params>
197 struct MutantFunctor { 197 struct MutantFunctor {
198 explicit MutantFunctor(MutantRunner<R, Params>* cb) : impl_(cb) { 198 explicit MutantFunctor(MutantRunner<R, Params>* cb) : impl_(cb) {
199 } 199 }
200 200
201 ~MutantFunctor() { 201 ~MutantFunctor() {
202 } 202 }
203 203
204 inline R operator()() { 204 inline R operator()() {
205 return impl_->RunWithParams(Tuple<>()); 205 return impl_->RunWithParams(base::Tuple<>());
206 } 206 }
207 207
208 template <typename Arg1> 208 template <typename Arg1>
209 inline R operator()(const Arg1& a) { 209 inline R operator()(const Arg1& a) {
210 return impl_->RunWithParams(Params(a)); 210 return impl_->RunWithParams(Params(a));
211 } 211 }
212 212
213 template <typename Arg1, typename Arg2> 213 template <typename Arg1, typename Arg2>
214 inline R operator()(const Arg1& a, const Arg2& b) { 214 inline R operator()(const Arg1& a, const Arg2& b) {
215 return impl_->RunWithParams(Params(a, b)); 215 return impl_->RunWithParams(Params(a, b));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 # params - X1,.. , A1, .. 269 # params - X1,.. , A1, ..
270 # args - const P1& p1 .. 270 # args - const P1& p1 ..
271 # call_args - p1, p2, p3.. 271 # call_args - p1, p2, p3..
272 CREATE_METHOD_FUNCTOR_TEMPLATE = """\ 272 CREATE_METHOD_FUNCTOR_TEMPLATE = """\
273 template <typename R, typename T, typename U, %(template_params)s> 273 template <typename R, typename T, typename U, %(template_params)s>
274 inline MutantFunctor<R, %(calltime)s> 274 inline MutantFunctor<R, %(calltime)s>
275 CreateFunctor(T* obj, R (U::*method)(%(params)s), %(args)s) { 275 CreateFunctor(T* obj, R (U::*method)(%(params)s), %(args)s) {
276 MutantRunner<R, %(calltime)s>* t = 276 MutantRunner<R, %(calltime)s>* t =
277 new Mutant<R, T, R (U::*)(%(params)s), 277 new Mutant<R, T, R (U::*)(%(params)s),
278 %(prebound)s, %(calltime)s> 278 %(prebound)s, %(calltime)s>
279 (obj, method, MakeTuple(%(call_args)s)); 279 (obj, method, base::MakeTuple(%(call_args)s));
280 return MutantFunctor<R, %(calltime)s>(t); 280 return MutantFunctor<R, %(calltime)s>(t);
281 } 281 }
282 """ 282 """
283 283
284 CREATE_FUNCTION_FUNCTOR_TEMPLATE = """\ 284 CREATE_FUNCTION_FUNCTOR_TEMPLATE = """\
285 template <typename R, %(template_params)s> 285 template <typename R, %(template_params)s>
286 inline MutantFunctor<R, %(calltime)s> 286 inline MutantFunctor<R, %(calltime)s>
287 CreateFunctor(R (*function)(%(params)s), %(args)s) { 287 CreateFunctor(R (*function)(%(params)s), %(args)s) {
288 MutantRunner<R, %(calltime)s>* t = 288 MutantRunner<R, %(calltime)s>* t =
289 new MutantFunction<R, R (*)(%(params)s), 289 new MutantFunction<R, R (*)(%(params)s),
290 %(prebound)s, %(calltime)s> 290 %(prebound)s, %(calltime)s>
291 (function, MakeTuple(%(call_args)s)); 291 (function, base::MakeTuple(%(call_args)s));
292 return MutantFunctor<R, %(calltime)s>(t); 292 return MutantFunctor<R, %(calltime)s>(t);
293 } 293 }
294 """ 294 """
295 295
296 def SplitLine(line, width): 296 def SplitLine(line, width):
297 """Splits a single line at comma, at most |width| characters long.""" 297 """Splits a single line at comma, at most |width| characters long."""
298 if len(line) < width: 298 if len(line) <= width:
299 return (line, None) 299 return (line, None)
300 n = 1 + line[:width].rfind(",") 300 n = 1 + line[:width].rfind(",")
301 if n == 0: # If comma cannot be found give up and return the entire line. 301 if n == 0: # If comma cannot be found give up and return the entire line.
302 return (line, None) 302 return (line, None)
303 # Assume there is a space after the comma 303 # Assume there is a space after the comma
304 assert line[n] == " " 304 assert line[n] == " "
305 return (line[:n], line[n + 1:]) 305 return (line[:n], line[n + 1:])
306 306
307 307
308 def Wrap(s, width, subsequent_offset): 308 def Wrap(s, width, subsequent_offset):
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 """ 345 """
346 it = string.hexdigits[start:n + start] 346 it = string.hexdigits[start:n + start]
347 return ", ".join(ExpandPattern(pattern, it)) 347 return ", ".join(ExpandPattern(pattern, it))
348 348
349 349
350 def Merge(a): 350 def Merge(a):
351 return ", ".join(filter(len, a)) 351 return ", ".join(filter(len, a))
352 352
353 353
354 def GenTuple(pattern, n): 354 def GenTuple(pattern, n):
355 return Clean("Tuple<%s>" % (Gen(pattern, n, 1))) 355 return Clean("base::Tuple<%s>" % (Gen(pattern, n, 1)))
356 356
357 357
358 def FixCode(s): 358 def FixCode(s):
359 lines = Clean(s).splitlines() 359 lines = Clean(s).splitlines()
360 # Wrap sometimes very long 1st and 3rd line at 80th column. 360 # Wrap sometimes very long 1st line to be inside the "template <"
361 lines[0] = Wrap(lines[0], 80, 10) 361 lines[0] = Wrap(lines[0], 80, 10)
362 lines[2] = Wrap(lines[2], 80, 4) 362
363 # Wrap all subsequent lines to 6 spaces arbitrarily. This is a 2-space line
364 # indent, plus a 4 space continuation indent.
365 for line in xrange(1, len(lines)):
366 lines[line] = Wrap(lines[line], 80, 6)
363 return "\n".join(lines) 367 return "\n".join(lines)
364 368
365 369
366 def GenerateDispatch(prebound, calltime): 370 def GenerateDispatch(prebound, calltime):
367 print "\n// %d - %d" % (prebound, calltime) 371 print "\n// %d - %d" % (prebound, calltime)
368 args = { 372 args = {
369 "template_params": Merge([Gen("typename P%", prebound, 1), 373 "template_params": Merge([Gen("typename P%", prebound, 1),
370 Gen("typename C%", calltime, 1)]), 374 Gen("typename C%", calltime, 1)]),
371 "prebound": GenTuple("P%", prebound), 375 "prebound": GenTuple("P%", prebound),
372 "calltime": GenTuple("C%", calltime), 376 "calltime": GenTuple("C%", calltime),
373 "args": Merge([Gen("get<%>(p)", prebound, 0), 377 "args": Merge([Gen("base::get<%>(p)", prebound, 0),
374 Gen("get<%>(c)", calltime, 0)]), 378 Gen("base::get<%>(c)", calltime, 0)]),
375 } 379 }
376 380
377 print FixCode(DISPATCH_TO_METHOD_TEMPLATE % args) 381 print FixCode(DISPATCH_TO_METHOD_TEMPLATE % args)
378 print FixCode(DISPATCH_TO_FUNCTION_TEMPLATE % args) 382 print FixCode(DISPATCH_TO_FUNCTION_TEMPLATE % args)
379 383
380 384
381 def GenerateCreateFunctor(prebound, calltime): 385 def GenerateCreateFunctor(prebound, calltime):
382 print "// %d - %d" % (prebound, calltime) 386 print "// %d - %d" % (prebound, calltime)
383 args = { 387 args = {
384 "calltime": GenTuple("A%", calltime), 388 "calltime": GenTuple("A%", calltime),
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 print MUTANT 441 print MUTANT
438 for prebound in xrange(0, 6 + 1): 442 for prebound in xrange(0, 6 + 1):
439 for args in xrange(0, 6 + 1): 443 for args in xrange(0, 6 + 1):
440 GenerateCreateFunctor(prebound, args) 444 GenerateCreateFunctor(prebound, args)
441 print FOOTER 445 print FOOTER
442 return 0 446 return 0
443 447
444 448
445 if __name__ == "__main__": 449 if __name__ == "__main__":
446 sys.exit(main()) 450 sys.exit(main())
OLDNEW
« no previous file with comments | « storage/browser/fileapi/sandbox_file_stream_writer.cc ('k') | testing/gmock_mutant.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698