From 8ea1eac371ee705d92fe9e65a28e7336dfb47520 Mon Sep 17 00:00:00 2001 From: Dan Dennedy Date: Thu, 2 May 2013 22:34:29 -0700 Subject: [PATCH] Add more unit tests for mlt_property. --- src/tests/test_properties/test_properties.cpp | 141 ++++++++++++++++++ src/tests/test_properties/test_properties.pro | 1 - 2 files changed, 141 insertions(+), 1 deletion(-) diff --git a/src/tests/test_properties/test_properties.cpp b/src/tests/test_properties/test_properties.cpp index 06dd8f24..4fbe6290 100644 --- a/src/tests/test_properties/test_properties.cpp +++ b/src/tests/test_properties/test_properties.cpp @@ -51,6 +51,147 @@ private Q_SLOTS: delete q; QCOMPARE(p.ref_count(), 1); } + + void SetAndGetString() + { + Properties p; + p.set("key", "value"); + QVERIFY(p.get("key")); + QVERIFY(QString(p.get("key")) != QString("")); + QCOMPARE(p.get("key"), "value"); + } + + void SetAndGetInt() + { + Properties p; + int i = 1; + p.set("key", i); + QCOMPARE(p.get_int("key"), i); + } + + void SetAndGetDouble() + { + Properties p; + double d = 1.0; + p.set("key", d); + QCOMPARE(p.get_double("key"), d); + } + + void SetAndGetInt64() + { + Properties p; + qint64 i = 1LL << 32; + p.set("key", i); + QCOMPARE(p.get_int64("key"), i); + } + + void SetAndGetData() + { + Properties p; + const char *value = "value"; + char* const s = strdup(value); + p.set("key", s, strlen(s), free); + int size = 0; + QCOMPARE((char*) p.get_data("key", size), value); + QCOMPARE(size, int(strlen(value))); + } + + void IntFromString() + { + Properties p; + const char *s = "-1"; + int i = -1; + p.set("key", i); + QCOMPARE(p.get("key"), s); + p.set("key", s); + QCOMPARE(p.get_int("key"), i); + } + + void Int64FromString() + { + Properties p; + const char *s = "-1"; + qint64 i = -1; + p.set("key", i); + QCOMPARE(p.get("key"), s); + p.set("key", s); + QCOMPARE(p.get_int64("key"), i); + } + + void DoubleFromString() + { + Properties p; + const char *s = "-1.234567"; + double d = -1.234567; + p.set("key", d); + QCOMPARE(p.get("key"), s); + p.set("key", s); + QCOMPARE(p.get_double("key"), d); + } + + void SetNullRemovesProperty() + { + Properties p; + const char *s = NULL; + p.set("key", "value"); + p.set("key", s); + QCOMPARE(p.get("key"), s); + } + + void SetAndGetHexColor() + { + Properties p; + const char *hexColorString = "0xaabbccdd"; + int hexColorInt = 0xaabbccdd; + p.set("key", hexColorString); + QCOMPARE(p.get_int("key"), hexColorInt); + } + + void SetAndGetCssColor() + { + Properties p; + const char *cssColorString = "#aabbcc"; + int cssColorInt = 0xaabbccff; + p.set("key", cssColorString); + QCOMPARE(p.get_int("key"), cssColorInt); + + const char *cssColorAlphaString = "#00aabbcc"; + int cssColorAlphaInt = 0xaabbcc00; + p.set("key", cssColorAlphaString); + QCOMPARE(p.get_int("key"), cssColorAlphaInt); + } + + void SetAndGetTimeCode() + { + Profile profile; + Properties p; + p.set("_profile", profile.get_profile(), 0); + const char *timeString = "11:22:33:04"; + p.set("key", timeString); + QCOMPARE(p.get_int("key"), 1023829); + p.set("key", 1023829); + QCOMPARE(p.get_time("key", mlt_time_smpte), timeString); + } + + void SetAndGetTimeClock() + { + Profile profile; + Properties p; + p.set("_profile", profile.get_profile(), 0); + const char *timeString = "11:22:33.400"; + p.set("key", timeString); + QCOMPARE(p.get_int("key"), 1023835); + p.set("key", 1023835); + QCOMPARE(p.get_time("key", mlt_time_clock), timeString); + } + + void SetSimpleMathExpression() + { + Properties p; + p.set("key", "@16.0/9.0 *2 +3 -1"); + QCOMPARE(p.get_int("key"), 5); + QCOMPARE(p.get_double("key"), 16.0/9.0 *2 +3 -1); + } }; QTEST_APPLESS_MAIN(TestProperties) diff --git a/src/tests/test_properties/test_properties.pro b/src/tests/test_properties/test_properties.pro index 0846b085..cc3eb11a 100644 --- a/src/tests/test_properties/test_properties.pro +++ b/src/tests/test_properties/test_properties.pro @@ -1,4 +1,3 @@ include (../common.pri) TARGET = test_properties SOURCES = test_properties.cpp -DEFINES += SRCDIR=\\\"$$PWD/\\\" -- 2.39.2