| 172 | self.writer.writeln('}') |
| 173 | |
| 174 | def create_emitter_tests(out): |
| 175 | out = Writer(out) |
| 176 | |
| 177 | includes = [ |
| 178 | 'handler_test.h', |
| 179 | 'yaml-cpp/yaml.h', |
| 180 | 'gmock/gmock.h', |
| 181 | 'gtest/gtest.h', |
| 182 | ] |
| 183 | for include in includes: |
| 184 | out.writeln('#include "%s"' % include) |
| 185 | out.writeln('') |
| 186 | |
| 187 | usings = [ |
| 188 | '::testing::_', |
| 189 | ] |
| 190 | for using in usings: |
| 191 | out.writeln('using %s;' % using) |
| 192 | out.writeln('') |
| 193 | |
| 194 | with Scope(out, 'namespace YAML', 0) as _: |
| 195 | with Scope(out, 'namespace', 0) as _: |
| 196 | out.writeln('') |
| 197 | out.writeln('typedef HandlerTest GenEmitterTest;') |
| 198 | out.writeln('') |
| 199 | tests = list(gen_tests()) |
| 200 | |
| 201 | for test in tests: |
| 202 | with Scope(out, 'TEST_F(%s, %s)' % ('GenEmitterTest', test['name']), 2) as _: |
| 203 | out.writeln('Emitter out;') |
| 204 | for event in test['events']: |
| 205 | emit = event['emit'] |
| 206 | if isinstance(emit, list): |
| 207 | for e in emit: |
| 208 | out.writeln('out << %s;' % e) |
| 209 | elif emit: |
| 210 | out.writeln('out << %s;' % emit) |
| 211 | out.writeln('') |
| 212 | for event in test['events']: |
| 213 | handle = event['handle'] |
| 214 | if isinstance(handle, list): |
| 215 | for e in handle: |
| 216 | out.writeln('EXPECT_CALL(handler, %s);' % e) |
| 217 | elif handle: |
| 218 | out.writeln('EXPECT_CALL(handler, %s);' % handle) |
| 219 | out.writeln('Parse(out.c_str());') |
| 220 | out.writeln('') |
| 221 | |
| 222 | if __name__ == '__main__': |
| 223 | create_emitter_tests(sys.stdout) |