1 #include <simgear/compiler.h>
3 #include "parse_color.hxx"
4 #include "ColorInterpolator.hxx"
5 #include <simgear/props/props.hxx>
9 #define COMPARE(a, b) \
12 std::cerr << "line " << __LINE__ << ": failed: "\
13 << #a << " != " << #b << std::endl; \
20 std::cerr << "line " << __LINE__ << ": failed: "\
25 #define VERIFY_COLOR(str, r, g, b, a) \
26 VERIFY(simgear::parseColor(str, color)) \
27 COMPARE(color, osg::Vec4(r, g, b, a))
29 #define VERIFY_NODE_STR(node, str) \
30 COMPARE(node.getStringValue(), std::string(str))
32 int main (int ac, char ** av)
35 VERIFY_COLOR("#ff0000", 1,0,0,1);
36 VERIFY_COLOR("#00ff00", 0,1,0,1);
37 VERIFY_COLOR("#0000ff", 0,0,1,1);
38 VERIFY_COLOR("rgb( 255,\t127.5,0)", 1, 0.5, 0, 1);
39 VERIFY_COLOR("rgba(255, 127.5,0, 0.5)", 1, 0.5, 0, 0.5);
41 SGPropertyNode color_node, color_arg;
42 color_arg.setStringValue("#000000");
44 simgear::PropertyInterpolator* interp =
45 simgear::PropertyInterpolator
46 ::create<simgear::ColorInterpolator>(&color_arg);
48 interp->update(&color_node, 0.5); // with no color it should immediately set to the target
49 VERIFY_NODE_STR(color_node, "rgb(0,0,0)");
51 color_arg.setStringValue("rgba(255,0,0,0.5)");
52 interp->reset(&color_arg);
54 interp->update(&color_node, 0.5);
55 VERIFY_NODE_STR(color_node, "rgba(127,0,0,0.75)");
57 interp->update(&color_node, 0.5);
58 VERIFY_NODE_STR(color_node, "rgba(255,0,0,0.5)");
60 // Animation has already completed and therefore should be reset and start a
61 // new animation starting with the current value of the animation. As this
62 // is already the same as the target value, nothing should change.
63 interp->update(&color_node, 0.5);
64 VERIFY_NODE_STR(color_node, "rgba(255,0,0,0.5)");
66 color_arg.setStringValue("#00ff00");
67 interp->reset(&color_arg);
68 interp->update(&color_node, 1.0);
69 VERIFY_NODE_STR(color_node, "rgb(0,255,0)");
71 std::cout << "all tests passed successfully!" << std::endl;