2 * Copyright (C) 2013 Dan Dennedy <dan@dennedy.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with consumer library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <mlt++/Mlt.h>
25 class TestProperties: public QObject
33 void InstantiationIsAReference()
36 QCOMPARE(p.ref_count(), 1);
39 void CopyAddsReference()
43 QCOMPARE(p.ref_count(), 2);
46 void DestructionRemovesReference()
49 Properties* q = new Properties(p);
50 QCOMPARE(p.ref_count(), 2);
52 QCOMPARE(p.ref_count(), 1);
55 void SetAndGetString()
58 p.set("key", "value");
59 QVERIFY(p.get("key"));
60 QVERIFY(QString(p.get("key")) != QString(""));
61 QCOMPARE(p.get("key"), "value");
69 QCOMPARE(p.get_int("key"), i);
72 void SetAndGetDouble()
77 QCOMPARE(p.get_double("key"), d);
84 p.set("key", (int64_t)i);
85 QCOMPARE((qint64)p.get_int64("key"), i);
91 const char *value = "value";
92 char* const s = strdup(value);
93 p.set("key", s, strlen(s), free);
95 QCOMPARE((char*) p.get_data("key", size), value);
96 QCOMPARE(size, int(strlen(value)));
102 const char *s = "-1";
105 QCOMPARE(p.get("key"), s);
107 QCOMPARE(p.get_int("key"), i);
110 void Int64FromString()
113 const char *s = "-1";
115 p.set("key", (int64_t)i);
116 QCOMPARE(p.get("key"), s);
118 QCOMPARE((qint64)p.get_int64("key"), i);
121 void DoubleFromString()
124 const char *s = "-1.234567";
125 double d = -1.234567;
127 QCOMPARE(p.get("key"), s);
129 QCOMPARE(p.get_double("key"), d);
132 void SetNullRemovesProperty()
135 const char *s = NULL;
136 p.set("key", "value");
138 QCOMPARE(p.get("key"), s);
141 void SetAndGetHexColor()
144 const char *hexColorString = "0xaabbccdd";
145 int hexColorInt = 0xaabbccdd;
146 p.set("key", hexColorString);
147 QCOMPARE(p.get_int("key"), hexColorInt);
150 void SetAndGetCssColor()
153 const char *cssColorString = "#aabbcc";
154 int cssColorInt = 0xaabbccff;
155 p.set("key", cssColorString);
156 QCOMPARE(p.get_int("key"), cssColorInt);
158 const char *cssColorAlphaString = "#00aabbcc";
159 int cssColorAlphaInt = 0xaabbcc00;
160 p.set("key", cssColorAlphaString);
161 QCOMPARE(p.get_int("key"), cssColorAlphaInt);
164 void SetAndGetTimeCode()
168 p.set("_profile", profile.get_profile(), 0);
169 const char *timeString = "11:22:33:04";
170 p.set("key", timeString);
171 QCOMPARE(p.get_int("key"), 1023829);
172 p.set("key", 1023829);
173 QCOMPARE(p.get_time("key", mlt_time_smpte), timeString);
176 void SetAndGetTimeClock()
180 p.set("_profile", profile.get_profile(), 0);
181 const char *timeString = "11:22:33.400";
182 p.set("key", timeString);
183 QCOMPARE(p.get_int("key"), 1023835);
184 p.set("key", 1023835);
185 QCOMPARE(p.get_time("key", mlt_time_clock), timeString);
188 void SetSimpleMathExpression()
191 p.set("key", "@16.0/9.0 *2 +3 -1");
192 QCOMPARE(p.get_int("key"), 5);
193 QCOMPARE(p.get_double("key"), 16.0/9.0 *2 +3 -1);
196 void PassOneProperty()
199 const char *s = "value";
201 QCOMPARE(p[1].get("key"), (void*) 0);
202 p[1].pass_property(p[0], "key");
203 QCOMPARE(p[1].get("key"), s);
206 void PassMultipleByPrefix()
209 const char *s = "value";
210 p[0].set("key.one", s);
211 p[0].set("key.two", s);
212 QCOMPARE(p[1].get("key.one"), (void*) 0);
213 QCOMPARE(p[1].get("key.two"), (void*) 0);
214 p[1].pass_values(p[0], "key.");
215 QCOMPARE(p[1].get("one"), s);
216 QCOMPARE(p[1].get("two"), s);
219 void PassMultipleByList()
222 const char *s = "value";
223 p[0].set("key.one", s);
224 p[0].set("key.two", s);
225 QCOMPARE(p[1].get("key.one"), (void*) 0);
226 QCOMPARE(p[1].get("key.two"), (void*) 0);
227 p[1].pass_list(p[0], "key.one key.two");
228 QCOMPARE(p[1].get("key.one"), s);
229 QCOMPARE(p[1].get("key.two"), s);
232 void MirrorProperties()
236 p[0].set("key", "value");
237 QCOMPARE(p[1].get("key"), "value");
240 void InheritProperties()
243 p[0].set("key", "value");
244 QVERIFY(p[1].get("key") == 0);
246 QCOMPARE(p[1].get("key"), "value");
252 QCOMPARE(p.get("key"), (void*) 0);
253 p.parse("key=value");
254 QCOMPARE(p.get("key"), "value");
255 p.parse("key=\"new value\"");
256 QCOMPARE(p.get("key"), "new value");
259 void RenameProperty()
262 p.set("key", "value");
263 QVERIFY(p.get("new key") == 0);
264 p.rename("key", "new key");
265 QCOMPARE(p.get("new key"), "value");
268 void SequenceDetected()
274 QVERIFY(p.is_sequence());
276 QVERIFY(!p.is_sequence());
279 void SerializesToYamlTiny()
282 p[0].set("key1", "value1");
283 p[0].set("key2", "value2");
284 p[1].set("1", "value3");
285 p[1].set("2", "value4");
286 p[0].set("seq", p[1].get_properties(), 0);
287 QCOMPARE(p[0].serialise_yaml(),
297 void RadixRespondsToLocale()
300 p.set_lcnumeric("en_US");
301 p.set("key", "0.125");
302 QCOMPARE(p.get_double("key"), double(1) / double(8));
303 p.set_lcnumeric("de_DE");
304 p.set("key", "0,125");
305 QCOMPARE(p.get_double("key"), double(1) / double(8));
309 QTEST_APPLESS_MAIN(TestProperties)
311 #include "test_properties.moc"