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 = new simgear::ColorInterpolator;
45 interp->reset(color_arg);
47 interp->update(color_node, 0.5); // with no color it should immediately set to the target
48 VERIFY_NODE_STR(color_node, "rgb(0,0,0)");
50 color_arg.setStringValue("rgba(255,0,0,0.5)");
51 interp->reset(color_arg);
53 interp->update(color_node, 0.5);
54 VERIFY_NODE_STR(color_node, "rgba(127,0,0,0.75)");
56 interp->update(color_node, 0.5);
57 VERIFY_NODE_STR(color_node, "rgba(255,0,0,0.5)");
59 // Animation has already completed and therefore should be reset and start a
60 // new animation starting with the current value of the animation. As this
61 // is already the same as the target value, nothing should change.
62 interp->update(color_node, 0.5);
63 VERIFY_NODE_STR(color_node, "rgba(255,0,0,0.5)");
65 color_arg.setStringValue("#00ff00");
66 interp->reset(color_arg);
67 interp->update(color_node, 1.0);
68 VERIFY_NODE_STR(color_node, "rgb(0,255,0)");
70 std::cout << "all tests passed successfully!" << std::endl;