#include <framework/mlt_property.h>
#include <framework/mlt_animation.h>
}
+#include <cfloat>
class TestProperties: public QObject
{
Q_OBJECT
+ locale_t locale;
public:
- TestProperties() {}
+ TestProperties() {
+#if defined(__linux__) || defined(__DARWIN__)
+ locale = newlocale( LC_NUMERIC_MASK, "POSIX", NULL );
+#endif
+ }
private Q_SLOTS:
void InstantiationIsAReference()
void DoubleAnimation()
{
- locale_t locale;
-#if defined(__linux__) || defined(__DARWIN__)
- locale = newlocale( LC_NUMERIC_MASK, "POSIX", NULL );
-#endif
double fps = 25.0;
mlt_animation a = mlt_animation_new();
struct mlt_animation_item_s item;
void IntAnimation()
{
- locale_t locale;
-#if defined(__linux__) || defined(__DARWIN__)
- locale = newlocale( LC_NUMERIC_MASK, "POSIX", NULL );
-#endif
double fps = 25.0;
mlt_animation a = mlt_animation_new();
struct mlt_animation_item_s item;
void AnimationWithTimeValueKeyframes()
{
- locale_t locale;
-#if defined(__linux__) || defined(__DARWIN__)
- locale = newlocale( LC_NUMERIC_MASK, "POSIX", NULL );
-#endif
double fps = 25.0;
mlt_animation a = mlt_animation_new();
struct mlt_animation_item_s item;
void DiscreteIntAnimation()
{
- locale_t locale;
-#if defined(__linux__) || defined(__DARWIN__)
- locale = newlocale( LC_NUMERIC_MASK, "POSIX", NULL );
-#endif
double fps = 25.0;
mlt_animation a = mlt_animation_new();
struct mlt_animation_item_s item;
void StringAnimation()
{
- locale_t locale;
-#if defined(__linux__) || defined(__DARWIN__)
- locale = newlocale( LC_NUMERIC_MASK, "POSIX", NULL );
-#endif
double fps = 25.0;
mlt_animation a = mlt_animation_new();
struct mlt_animation_item_s item;
mlt_property_close(item.property);
mlt_animation_close(a);
}
+
+ void test_property_get_double_pos()
+ {
+ double fps = 25.0;
+ mlt_property p = mlt_property_init();
+ mlt_property_set_string(p, "10=100; 20=200");
+ QCOMPARE(mlt_property_get_double(p, fps, locale), 10.0);
+ QCOMPARE(mlt_property_get_double_pos(p, fps, locale, 0, 100), 100.0);
+ QCOMPARE(mlt_property_get_double_pos(p, fps, locale, 15, 100), 150.0);
+ QCOMPARE(mlt_property_get_double_pos(p, fps, locale, 20, 100), 200.0);
+
+ mlt_property_set_string(p, "1.5");
+ QCOMPARE(mlt_property_get_double(p, fps, locale), 1.5);
+ QCOMPARE(mlt_property_get_double_pos(p, fps, locale, 10, 100), 1.5);
+
+ mlt_property_close(p);
+ }
+
+ void test_property_get_int_pos()
+ {
+ double fps = 25.0;
+ mlt_property p = mlt_property_init();
+ mlt_property_set_string(p, "10=100; 20=200");
+ QCOMPARE(mlt_property_get_int(p, fps, locale), 10);
+ QCOMPARE(mlt_property_get_int_pos(p, fps, locale, 0, 100), 100);
+ QCOMPARE(mlt_property_get_int_pos(p, fps, locale, 15, 100), 150);
+ QCOMPARE(mlt_property_get_int_pos(p, fps, locale, 20, 100), 200);
+
+ mlt_property_set_string(p, "1.5");
+ QCOMPARE(mlt_property_get_int(p, fps, locale), 1);
+ QCOMPARE(mlt_property_get_int_pos(p, fps, locale, 10, 100), 1);
+
+ mlt_property_close(p);
+ }
+
+ void SmoothIntAnimation()
+ {
+ double fps = 25.0;
+ mlt_animation a = mlt_animation_new();
+ struct mlt_animation_item_s item;
+
+ mlt_animation_parse(a, "0=80;10~=80; 20~=30; 30~=40; 40~=28; 50=90; 60=0; 70=60; 80=20", 100, fps, locale);
+ item.property = mlt_property_init();
+ char *a_serialized = mlt_animation_serialize(a);
+ QCOMPARE(a_serialized, "0=80;10~=80;20~=30;30~=40;40~=28;50=90;60=0;70=60;80=20");
+ if (a_serialized) free(a_serialized);
+
+ mlt_animation_get_item(a, &item, 10);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 80);
+ QCOMPARE(item.is_key, 1);
+
+ mlt_animation_get_item(a, &item, 50);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 90);
+ QCOMPARE(item.is_key, 1);
+
+ mlt_animation_get_item(a, &item, 55);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 45);
+ QCOMPARE(item.is_key, 0);
+
+ mlt_animation_get_item(a, &item, 60);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 0);
+ QCOMPARE(item.is_key, 1);
+
+ mlt_animation_get_item(a, &item, 75);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 40);
+ QCOMPARE(item.is_key, 0);
+
+ mlt_animation_get_item(a, &item, 100);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 20);
+ QCOMPARE(item.is_key, 0);
+
+ mlt_animation_get_item(a, &item, 110);
+ QCOMPARE(mlt_property_get_int(item.property, fps, locale), 20);
+ QCOMPARE(item.is_key, 0);
+
+ mlt_property_close(item.property);
+ mlt_animation_close(a);
+ }
+
+ void test_property_set_double_pos()
+ {
+ double fps = 25.0;
+ mlt_property p = mlt_property_init();
+ mlt_property_set_string(p, "10=100; 20=200");
+ mlt_property_set_double_pos(p, 1.5, fps, locale, mlt_keyframe_linear, 30, 100);
+ QCOMPARE(mlt_property_get_double(p, fps, locale), 10.0);
+ QCOMPARE(mlt_property_get_double_pos(p, fps, locale, 0, 100), 100.0);
+ QCOMPARE(mlt_property_get_double_pos(p, fps, locale, 15, 100), 150.0);
+ QCOMPARE(mlt_property_get_double_pos(p, fps, locale, 20, 100), 200.0);
+ QCOMPARE(mlt_property_get_double_pos(p, fps, locale, 25, 100), 100.75);
+ QCOMPARE(mlt_property_get_double_pos(p, fps, locale, 30, 100), 1.5);
+ mlt_property_close(p);
+ }
+
+ void test_property_set_int_pos()
+ {
+ double fps = 25.0;
+ mlt_property p = mlt_property_init();
+ mlt_property_set_string(p, "10=100; 20=200");
+ mlt_property_set_int_pos(p, 300, fps, locale, mlt_keyframe_linear, 30, 100);
+ QCOMPARE(mlt_property_get_int(p, fps, locale), 10);
+ QCOMPARE(mlt_property_get_int_pos(p, fps, locale, 0, 100), 100);
+ QCOMPARE(mlt_property_get_int_pos(p, fps, locale, 15, 100), 150);
+ QCOMPARE(mlt_property_get_int_pos(p, fps, locale, 20, 100), 200);
+ QCOMPARE(mlt_property_get_int_pos(p, fps, locale, 25, 100), 250);
+ QCOMPARE(mlt_property_get_int_pos(p, fps, locale, 30, 100), 300);
+ mlt_property_close(p);
+ }
+
+ void PercentAsRatio()
+ {
+ Properties p;
+ p.set("foo", "12.3%");
+ QCOMPARE(p.get_double("foo"), 0.123);
+ p.set("foo", "456 %");
+ QCOMPARE(p.get_double("foo"), 456.0);
+ }
+
+ void PropertiesAnimInt()
+ {
+ int len = 50;
+ Properties p;
+ p.set_lcnumeric("POSIX");
+
+ // Construct animation from scratch
+ p.set("foo", 0, 0, len);
+ p.set("foo", 100, 50, len, mlt_keyframe_smooth);
+ QCOMPARE(p.get_int("foo", 0, len), 0);
+ QCOMPARE(p.get_int("foo", 25, len), 50);
+ QCOMPARE(p.get_int("foo", 50, len), 100);
+ QCOMPARE(p.get("foo"), "0=0;50~=100");
+
+ // Animation from string value
+ p.set("foo", "10=100;20=200");
+ QCOMPARE(p.get_int("foo", 0, len), 100);
+ QCOMPARE(p.get_int("foo", 15, len), 150);
+ QCOMPARE(p.get_int("foo", 20, len), 200);
+
+ // Animation from string using time clock values
+ // Need to set a profile so fps can be used to convert time to frames.
+ Profile profile("dv_pal");
+ p.set("_profile", profile.get_profile(), 0);
+ p.set("foo", ":0.0=100; :2.0=200");
+ QCOMPARE(p.get_int("foo", 0, len), 100);
+ QCOMPARE(p.get_int("foo", 25, len), 150);
+ QCOMPARE(p.get_int("foo", 50, len), 200);
+ }
+
+ void test_mlt_rect()
+ {
+ mlt_property p = mlt_property_init();
+ mlt_rect r = { 1, 2, 3, 4, 5 };
+
+ mlt_property_set_rect( p, r );
+ QCOMPARE(mlt_property_get_string(p), "1 2 3 4 5");
+ r.o = DBL_MIN;
+ mlt_property_set_rect( p, r );
+ QCOMPARE(mlt_property_get_string(p), "1 2 3 4");
+ r.w = DBL_MIN;
+ r.h = DBL_MIN;
+ mlt_property_set_rect( p, r );
+ QCOMPARE(mlt_property_get_string(p), "1 2");
+
+ mlt_property_set_string(p, "1.1/2.2:3.3x4.4:5.5");
+ r = mlt_property_get_rect(p, locale);
+ QCOMPARE(r.x, 1.1);
+ QCOMPARE(r.y, 2.2);
+ QCOMPARE(r.w, 3.3);
+ QCOMPARE(r.h, 4.4);
+ QCOMPARE(r.o, 5.5);
+
+ mlt_property_set_string(p, "1.1 2.2");
+ r = mlt_property_get_rect(p, locale);
+ QCOMPARE(r.x, 1.1);
+ QCOMPARE(r.y, 2.2);
+ QCOMPARE(r.w, DBL_MIN);
+
+ mlt_property_set_int64(p, UINT_MAX);
+ r = mlt_property_get_rect(p, locale);
+ QCOMPARE(r.x, double(UINT_MAX));
+
+ mlt_property_close(p);
+ }
+
+ void SetAndGetRect()
+ {
+ Properties p;
+ mlt_rect r;
+ r.x = 1.1;
+ r.y = 2.2;
+ r.w = 3.3;
+ r.h = 4.4;
+ r.o = 5.5;
+ p.set("key", r);
+ mlt_rect q = p.get_rect("key");
+ QCOMPARE(q.x, 1.1);
+ QCOMPARE(q.y, 2.2);
+ QCOMPARE(q.w, 3.3);
+ QCOMPARE(q.h, 4.4);
+ QCOMPARE(q.o, 5.5);
+ p.set("key", 10, 20, 30, 40);
+ q = p.get_rect("key");
+ QCOMPARE(q.x, 10.0);
+ QCOMPARE(q.y, 20.0);
+ QCOMPARE(q.w, 30.0);
+ QCOMPARE(q.h, 40.0);
+ }
+
+ void RectFromString()
+ {
+ Properties p;
+ p.set_lcnumeric("POSIX");
+ const char *s = "1.1 2.2 3.3 4.4 5.5";
+ mlt_rect r = { 1.1, 2.2, 3.3, 4.4, 5.5 };
+ p.set("key", r);
+ QCOMPARE(p.get("key"), s);
+ p.set("key", s);
+ r = p.get_rect("key");
+ QCOMPARE(r.x, 1.1);
+ QCOMPARE(r.y, 2.2);
+ QCOMPARE(r.w, 3.3);
+ QCOMPARE(r.h, 4.4);
+ QCOMPARE(r.o, 5.5);
+ }
};
QTEST_APPLESS_MAIN(TestProperties)