]> git.sesse.net Git - mlt/blob - src/tests/test_properties/test_properties.cpp
4fbe62907b0b8f95cb622684954450008c5aa90f
[mlt] / src / tests / test_properties / test_properties.cpp
1 /*
2  * Copyright (C) 2013 Dan Dennedy <dan@dennedy.org>
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include <QString>
20 #include <QtTest>
21
22 #include <mlt++/Mlt.h>
23 using namespace Mlt;
24
25 class TestProperties: public QObject
26 {
27     Q_OBJECT
28
29 public:
30     TestProperties() {}
31
32 private Q_SLOTS:
33     void InstantiationIsAReference()
34     {
35         Properties p;
36         QCOMPARE(p.ref_count(), 1);
37     }
38
39     void CopyAddsReference()
40     {
41         Properties p;
42         Properties q = p;
43         QCOMPARE(p.ref_count(), 2);
44     }
45
46     void DestructionRemovesReference()
47     {
48         Properties p;
49         Properties* q = new Properties(p);
50         QCOMPARE(p.ref_count(), 2);
51         delete q;
52         QCOMPARE(p.ref_count(), 1);
53     }
54
55     void SetAndGetString()
56     {
57         Properties p;
58         p.set("key", "value");
59         QVERIFY(p.get("key"));
60         QVERIFY(QString(p.get("key")) != QString(""));
61         QCOMPARE(p.get("key"), "value");
62     }
63
64     void SetAndGetInt()
65     {
66         Properties p;
67         int i = 1;
68         p.set("key", i);
69         QCOMPARE(p.get_int("key"), i);
70     }
71
72     void SetAndGetDouble()
73     {
74         Properties p;
75         double d = 1.0;
76         p.set("key", d);
77         QCOMPARE(p.get_double("key"), d);
78     }
79
80     void SetAndGetInt64()
81     {
82         Properties p;
83         qint64 i = 1LL << 32;
84         p.set("key", i);
85         QCOMPARE(p.get_int64("key"), i);
86     }
87
88     void SetAndGetData()
89     {
90         Properties p;
91         const char *value = "value";
92         char* const s = strdup(value);
93         p.set("key", s, strlen(s), free);
94         int size = 0;
95         QCOMPARE((char*) p.get_data("key", size), value);
96         QCOMPARE(size, int(strlen(value)));
97     }
98
99     void IntFromString()
100     {
101         Properties p;
102         const char *s = "-1";
103         int i = -1;
104         p.set("key", i);
105         QCOMPARE(p.get("key"), s);
106         p.set("key", s);
107         QCOMPARE(p.get_int("key"), i);
108     }
109
110     void Int64FromString()
111     {
112         Properties p;
113         const char *s = "-1";
114         qint64 i = -1;
115         p.set("key", i);
116         QCOMPARE(p.get("key"), s);
117         p.set("key", s);
118         QCOMPARE(p.get_int64("key"), i);
119     }
120
121     void DoubleFromString()
122     {
123         Properties p;
124         const char *s = "-1.234567";
125         double d = -1.234567;
126         p.set("key", d);
127         QCOMPARE(p.get("key"), s);
128         p.set("key", s);
129         QCOMPARE(p.get_double("key"), d);
130     }
131
132     void SetNullRemovesProperty()
133     {
134         Properties p;
135         const char *s = NULL;
136         p.set("key", "value");
137         p.set("key", s);
138         QCOMPARE(p.get("key"), s);
139     }
140
141     void SetAndGetHexColor()
142     {
143         Properties p;
144         const char *hexColorString = "0xaabbccdd";
145         int hexColorInt = 0xaabbccdd;
146         p.set("key", hexColorString);
147         QCOMPARE(p.get_int("key"), hexColorInt);
148     }
149
150     void SetAndGetCssColor()
151     {
152         Properties p;
153         const char *cssColorString = "#aabbcc";
154         int cssColorInt = 0xaabbccff;
155         p.set("key", cssColorString);
156         QCOMPARE(p.get_int("key"), cssColorInt);
157
158         const char *cssColorAlphaString = "#00aabbcc";
159         int cssColorAlphaInt = 0xaabbcc00;
160         p.set("key", cssColorAlphaString);
161         QCOMPARE(p.get_int("key"), cssColorAlphaInt);
162     }
163
164     void SetAndGetTimeCode()
165     {
166         Profile profile;
167         Properties p;
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);
174     }
175
176     void SetAndGetTimeClock()
177     {
178         Profile profile;
179         Properties p;
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);
186     }
187
188     void SetSimpleMathExpression()
189     {
190         Properties p;
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);
194     }
195 };
196
197 QTEST_APPLESS_MAIN(TestProperties)
198
199 #include "test_properties.moc"