Skip to content

Commit e666266

Browse files
nglevinluispadron
authored andcommitted
Add tests for plisttool's XML and binary output.
Cherry-pick: a0ad31d
1 parent 8b1f9c3 commit e666266

1 file changed

Lines changed: 45 additions & 4 deletions

File tree

tools/plisttool/plisttool_unittest.py

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,47 @@ def test_main_invocation(self):
8686
plist = _xml_plist('<key>Foo</key><string>abc</string>')
8787
plist_fp.write(plist.getvalue())
8888

89+
json_fp = tempfile.NamedTemporaryFile(mode='wt', delete=False)
90+
self.addCleanup(lambda: os.unlink(json_fp.name))
91+
with json_fp:
92+
outfile = tempfile.NamedTemporaryFile(delete=False)
93+
self.addCleanup(lambda: os.unlink(outfile.name))
94+
outfile.close()
95+
control = {
96+
'plists': [plist_fp.name],
97+
'target': '//test:target',
98+
'output': outfile.name,
99+
}
100+
json.dump(control, json_fp)
101+
102+
# A None/zero return code means success.
103+
self.assertFalse(
104+
plisttool._main(json_fp.name), 'plisttool did not successfully run'
105+
)
106+
107+
with open(outfile.name, 'rb') as fp:
108+
self.assertIn(
109+
member=(
110+
b'<?xml version="1.0" encoding="UTF-8"?>\n'
111+
b'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" '
112+
b'"http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n'
113+
b'<plist version="1.0">\n'
114+
b'<dict>\n'
115+
b'\t<key>Foo</key>\n'
116+
b'\t<string>abc</string>\n'
117+
b'</dict>\n'
118+
b'</plist>\n'
119+
),
120+
container=fp.read(),
121+
)
122+
123+
def test_main_binary_invocation(self):
124+
plist_fp = tempfile.NamedTemporaryFile(delete=False)
125+
self.addCleanup(lambda: os.unlink(plist_fp.name))
126+
with plist_fp:
127+
plist = _xml_plist('<key>Foo</key><string>abc</string>')
128+
plist_fp.write(plist.getvalue())
129+
89130
json_fp = tempfile.NamedTemporaryFile(mode='wt', delete=False)
90131
self.addCleanup(lambda: os.unlink(json_fp.name))
91132
with json_fp:
@@ -94,17 +135,17 @@ def test_main_invocation(self):
94135
outfile.close()
95136
control = {'plists': [plist_fp.name],
96137
'target': '//test:target',
97-
'output': outfile.name}
138+
'output': outfile.name,
139+
'binary': True}
98140
json.dump(control, json_fp)
99141

100142
# A None/zero return code means success.
101143
self.assertFalse(plisttool._main(json_fp.name),
102144
'plisttool did not successfully run')
103145

104-
# TODO(b/111687215): Test that the written output is correct.
105146
with open(outfile.name, 'rb') as fp:
106-
self.assertIn(b'<?xml', fp.read())
107-
147+
# Check that the output is a binary plist based on the header.
148+
self.assertIn(b'bplist', fp.read())
108149

109150
class PlistToolVariableReferenceTest(unittest.TestCase):
110151

0 commit comments

Comments
 (0)