Skip to content

Commit d823b75

Browse files
committed
Generate tests for all lua settable options
1 parent 2f78e0f commit d823b75

2 files changed

Lines changed: 392 additions & 33 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
generate_test = """ WHEN("The script \\"v = sfoav.getOption(\\"meshes\\");\\"")
2+
{
3+
console.runString("v = sfoav.getOption(\\"meshes\\");");
4+
THEN("v is DEFAULT")
5+
{
6+
REQUIRE(console.getGlobal<TYPE>("v").MEMBER == DEFAULT);
7+
}
8+
WHEN("The script \\"sfoav.setOption(\\"meshes\\", SET); v = sfoav.getOption(\\"meshes\\");\\"")
9+
{
10+
console.runString("sfoav.setOption(\\"meshes\\", SET); v = sfoav.getOption(\\"meshes\\");");
11+
THEN("v is SET")
12+
{
13+
CONDITION
14+
}
15+
}
16+
}
17+
"""
18+
19+
tests = """/*
20+
Tests are generated by tests/generate_lua_options_interop_tests.py
21+
*/
22+
SCENARIO("Lua options interop")
23+
{
24+
jLog::Log l;
25+
GIVEN(\"A Lua console with default CommandLine values\")
26+
{
27+
Console console(l, &vs, &options, &camera);
28+
29+
"""
30+
31+
for option in ["meshes", "hideAtoms", "showAxes", "showCell",
32+
"hideInfoText", "play", "noCentering", "darkTheme",
33+
"noTransparencySorting", "sizeByMass"]:
34+
test = generate_test
35+
for (k, v) in [("meshes", option), ("DEFAULT", "false"),
36+
("SET", "true"), ("TYPE", "LuaBool"),
37+
("MEMBER", "bit"),
38+
("CONDITION", "REQUIRE(console.getGlobal<LuaBool>(\"v\").bit == true);")]:
39+
test = test.replace(k, v)
40+
tests += test+"\n"
41+
42+
for (option, default) in [("levelOfDetail", 0), ("msaa", 0),
43+
("speed", 60), ("bondCutOff", 0),
44+
("bondSize", 1), ("atomSize", 1),
45+
("globalAtomAlpha", 1), ("globalBondAlpha", 1),
46+
("deemphasisAlpha", 0.25)]:
47+
test = generate_test
48+
for (k, v) in [("meshes", option), ("DEFAULT", str(default)),
49+
("SET", "31"), ("TYPE", "LuaNumber"),
50+
("MEMBER", "n"),
51+
("CONDITION", "REQUIRE_THAT(console.getGlobal<LuaNumber>(\"v\").n, WithinAbs(31, tol));")]:
52+
test = test.replace(k, v)
53+
tests += test+"\n"
54+
55+
tests += " #ifdef WITH_FFMPEG\n"
56+
for (option, default) in [("preset", "slow"), ("codec", "libx264"),
57+
("profile", "main")]:
58+
test = generate_test
59+
for (k, v) in [("meshes", option), ("DEFAULT", str(default)),
60+
("SET", "TEST"), ("TYPE", "LuaString"),
61+
("MEMBER", "characters"),
62+
("CONDITION", "REQUIRE(\"TEST\" == console.getGlobal<LuaString>(\"v\").characters);")]:
63+
test = test.replace(k, v)
64+
tests += test
65+
tests += " #endif\n"
66+
tests += """ }
67+
}"""
68+
print(tests)

0 commit comments

Comments
 (0)