1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
# SPDX-License-Identifier: LGPL-2.1-or-later
import os
from pathlib import Path
from rpcgen.parser import XDRParser
from rpcgen.generator import (
XDRTypeDeclarationGenerator,
XDRTypeImplementationGenerator,
XDRMarshallDeclarationGenerator,
XDRMarshallImplementationGenerator,
)
def test_generate_header():
x = Path(Path(__file__).parent, "demo.x")
h = Path(Path(__file__).parent, "demo.h")
with x.open("r") as fp:
parser = XDRParser(fp)
spec = parser.parse()
got = (
XDRTypeDeclarationGenerator(spec).visit()
+ "\n"
+ XDRMarshallDeclarationGenerator(spec).visit()
)
with h.open("r") as fp:
want = fp.read()
if "VIR_TEST_REGENERATE_OUTPUT" in os.environ:
want = got
with h.open("w") as fp:
fp.write(want)
assert got == want
def test_generate_source():
x = Path(Path(__file__).parent, "demo.x")
h = Path(Path(__file__).parent, "demo.c")
with x.open("r") as fp:
parser = XDRParser(fp)
spec = parser.parse()
got = (
XDRTypeImplementationGenerator(spec).visit()
+ "\n"
+ XDRMarshallImplementationGenerator(spec).visit()
)
with h.open("r") as fp:
want = fp.read()
if "VIR_TEST_REGENERATE_OUTPUT" in os.environ:
want = got
with h.open("w") as fp:
fp.write(want)
assert got == want
|