ipc/ipdl/test/cxx/genIPDLUnitTests.py

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 # This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 4
michael@0 5 import string, sys
michael@0 6
michael@0 7 def usage():
michael@0 8 print >>sys.stderr, """
michael@0 9 %s template_file -t unit_tests... -e extra_protocols...
michael@0 10
michael@0 11 TEMPLATE_FILE is used to generate to generate the unit-tester .cpp
michael@0 12 UNIT_TESTS are the top-level protocols defining unit tests
michael@0 13 EXTRA_PROTOCOLS are top-level protocols for subprocesses that can be
michael@0 14 spawned in tests but are not unit tests in and of
michael@0 15 themselves
michael@0 16 """% (sys.argv[0])
michael@0 17 sys.exit(1)
michael@0 18
michael@0 19 def main(argv):
michael@0 20 template = argv[1]
michael@0 21
michael@0 22 if argv[2] != '-t': usage()
michael@0 23 i = 3
michael@0 24 unittests = []
michael@0 25 while argv[i] != '-e':
michael@0 26 unittests.append(argv[i])
michael@0 27 i += 1
michael@0 28
michael@0 29 extras = argv[(i+1):]
michael@0 30
michael@0 31 includes = '\n'.join([
michael@0 32 '#include "%s.h"'% (t) for t in unittests ])
michael@0 33
michael@0 34
michael@0 35 enum_values = '\n'.join([
michael@0 36 ' %s,'% (t) for t in unittests+extras ])
michael@0 37 last_enum = unittests[-1]
michael@0 38
michael@0 39
michael@0 40 string_to_enums = '\n'.join([
michael@0 41 ''' else if (!strcmp(aString, "%s"))
michael@0 42 return %s;'''% (t, t) for t in unittests+extras ])
michael@0 43
michael@0 44 enum_to_strings = '\n'.join([
michael@0 45 ''' case %s:
michael@0 46 return "%s";'''%(t, t) for t in unittests+extras ])
michael@0 47
michael@0 48 parent_delete_cases = '\n'.join([
michael@0 49 ''' case %s: {
michael@0 50 delete reinterpret_cast<%sParent*>(gParentActor);
michael@0 51 return;
michael@0 52 }
michael@0 53 '''% (t, t) for t in unittests ])
michael@0 54
michael@0 55 parent_enabled_cases_proc = '\n'.join([
michael@0 56 ''' case %s: {
michael@0 57 if (!%sParent::RunTestInProcesses()) {
michael@0 58 passed("N/A to proc");
michael@0 59 DeferredParentShutdown();
michael@0 60 return;
michael@0 61 }
michael@0 62 break;
michael@0 63 }
michael@0 64 ''' % (t, t) for t in unittests ])
michael@0 65
michael@0 66 parent_main_cases_proc = '\n'.join([
michael@0 67 ''' case %s: {
michael@0 68 %sParent** parent =
michael@0 69 reinterpret_cast<%sParent**>(&gParentActor);
michael@0 70 *parent = new %sParent();
michael@0 71 (*parent)->Open(transport, child);
michael@0 72 return (*parent)->Main();
michael@0 73 }
michael@0 74 '''% (t, t, t, t) for t in unittests ])
michael@0 75
michael@0 76 parent_enabled_cases_thread = '\n'.join([
michael@0 77 ''' case %s: {
michael@0 78 if (!%sParent::RunTestInThreads()) {
michael@0 79 passed("N/A to threads");
michael@0 80 DeferredParentShutdown();
michael@0 81 return;
michael@0 82 }
michael@0 83 break;
michael@0 84 }
michael@0 85 ''' % (t, t) for t in unittests ])
michael@0 86
michael@0 87 parent_main_cases_thread = '\n'.join([
michael@0 88 ''' case %s: {
michael@0 89 %sParent** parent =
michael@0 90 reinterpret_cast<%sParent**>(&gParentActor);
michael@0 91 *parent = new %sParent();
michael@0 92
michael@0 93 %sChild** child =
michael@0 94 reinterpret_cast<%sChild**>(&gChildActor);
michael@0 95 *child = new %sChild();
michael@0 96
michael@0 97 ::mozilla::ipc::MessageChannel *childChannel = (*child)->GetIPCChannel();
michael@0 98 ::mozilla::ipc::Side parentSide =
michael@0 99 ::mozilla::ipc::ParentSide;
michael@0 100
michael@0 101 (*parent)->Open(childChannel, childMessageLoop, parentSide);
michael@0 102 return (*parent)->Main();
michael@0 103 }
michael@0 104 '''% (t, t, t, t, t, t, t) for t in unittests ])
michael@0 105
michael@0 106 child_delete_cases = '\n'.join([
michael@0 107 ''' case %s: {
michael@0 108 delete reinterpret_cast<%sChild*>(gChildActor);
michael@0 109 return;
michael@0 110 }
michael@0 111 '''% (t, t) for t in unittests+extras ])
michael@0 112
michael@0 113
michael@0 114 child_init_cases = '\n'.join([
michael@0 115 ''' case %s: {
michael@0 116 %sChild** child =
michael@0 117 reinterpret_cast<%sChild**>(&gChildActor);
michael@0 118 *child = new %sChild();
michael@0 119 (*child)->Open(transport, parent, worker);
michael@0 120 return;
michael@0 121 }
michael@0 122 '''% (t, t, t, t) for t in unittests+extras ])
michael@0 123
michael@0 124 templatefile = open(template, 'r')
michael@0 125 sys.stdout.write(
michael@0 126 string.Template(templatefile.read()).substitute(
michael@0 127 INCLUDES=includes,
michael@0 128 ENUM_VALUES=enum_values, LAST_ENUM=last_enum,
michael@0 129 STRING_TO_ENUMS=string_to_enums,
michael@0 130 ENUM_TO_STRINGS=enum_to_strings,
michael@0 131 PARENT_DELETE_CASES=parent_delete_cases,
michael@0 132 PARENT_ENABLED_CASES_PROC=parent_enabled_cases_proc,
michael@0 133 PARENT_MAIN_CASES_PROC=parent_main_cases_proc,
michael@0 134 PARENT_ENABLED_CASES_THREAD=parent_enabled_cases_thread,
michael@0 135 PARENT_MAIN_CASES_THREAD=parent_main_cases_thread,
michael@0 136 CHILD_DELETE_CASES=child_delete_cases,
michael@0 137 CHILD_INIT_CASES=child_init_cases))
michael@0 138 templatefile.close()
michael@0 139
michael@0 140 if __name__ == '__main__':
michael@0 141 main(sys.argv)

mercurial