Merge remote-tracking branch 'origin/0.10'
[platform/upstream/gstreamer.git] / tests / check / libs / profile.c
1 /* GStreamer unit test for gstprofile
2  *
3  * Copyright (C) <2009> Edward Hervey <edward.hervey@collabora.co.uk>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 /* #include <fcntl.h> */
26 #include <unistd.h>
27 #include <glib.h>
28 #include <glib/gstdio.h>
29 #include <gst/check/gstcheck.h>
30
31 #include <gst/pbutils/encoding-profile.h>
32 #include <gst/pbutils/encoding-target.h>
33
34 static inline gboolean
35 gst_caps_is_equal_unref (GstCaps * caps1, GstCaps * caps2)
36 {
37   gboolean ret;
38
39   ret = gst_caps_is_equal (caps1, caps2);
40   gst_caps_unref (caps1);
41
42   return ret;
43 }
44
45 #define CHECK_PROFILE(profile, name, description, format, preset, presence, restriction) \
46   {                                                                     \
47   fail_if(profile == NULL);                                             \
48   fail_unless_equals_string (gst_encoding_profile_get_name (profile), name); \
49   fail_unless_equals_string (gst_encoding_profile_get_description (profile), description); \
50   fail_unless (gst_caps_is_equal_unref (gst_encoding_profile_get_format (profile), format)); \
51   fail_unless_equals_string (gst_encoding_profile_get_preset (profile), preset); \
52   fail_unless_equals_int (gst_encoding_profile_get_presence (profile), presence); \
53   if (restriction) \
54     fail_unless (gst_caps_is_equal_unref (gst_encoding_profile_get_restriction (profile), restriction)); \
55   }
56
57 GST_START_TEST (test_profile_creation)
58 {
59   GstEncodingProfile *encprof;
60   GstEncodingAudioProfile *audioprof;
61   GstEncodingVideoProfile *videoprof;
62   GstCaps *ogg, *vorbis, *theora;
63   GstCaps *test1, *test2;
64
65   ogg = gst_caps_new_empty_simple ("application/ogg");
66   vorbis = gst_caps_new_empty_simple ("audio/x-vorbis");
67   theora = gst_caps_new_empty_simple ("video/x-theora");
68
69   encprof = (GstEncodingProfile *) gst_encoding_container_profile_new ((gchar *)
70       "ogg-theora-vorbis", "dumb-profile", ogg, (gchar *) "dumb-preset");
71   CHECK_PROFILE (encprof, "ogg-theora-vorbis", "dumb-profile", ogg,
72       "dumb-preset", 0, NULL);
73
74   audioprof = gst_encoding_audio_profile_new (vorbis, (gchar *) "HQ", NULL, 0);
75   CHECK_PROFILE ((GstEncodingProfile *) audioprof, NULL, NULL, vorbis, "HQ", 0,
76       NULL);
77
78   videoprof = gst_encoding_video_profile_new (theora, (gchar *) "HQ", NULL, 0);
79   CHECK_PROFILE ((GstEncodingProfile *) videoprof, NULL, NULL, theora, "HQ",
80       0, NULL);
81
82   fail_unless (gst_encoding_container_profile_add_profile (
83           (GstEncodingContainerProfile *) encprof,
84           (GstEncodingProfile *) audioprof));
85   fail_unless (gst_encoding_container_profile_add_profile (
86           (GstEncodingContainerProfile *) encprof,
87           (GstEncodingProfile *) videoprof));
88
89   /* Test caps */
90   test1 = gst_caps_from_string ("video/x-theora; audio/x-vorbis");
91   test2 = gst_encoding_profile_get_input_caps (encprof);
92   fail_unless (gst_caps_is_equal (test1, test2));
93   gst_caps_unref (test1);
94   gst_caps_unref (test2);
95
96   gst_encoding_profile_unref (encprof);
97   gst_caps_unref (ogg);
98   gst_caps_unref (theora);
99   gst_caps_unref (vorbis);
100 }
101
102 GST_END_TEST;
103
104
105 GST_START_TEST (test_profile_input_caps)
106 {
107   GstEncodingProfile *sprof;
108   GstCaps *vorbis;
109   GstCaps *out, *restriction, *test1;
110
111   vorbis = gst_caps_new_empty_simple ("audio/x-vorbis");
112
113   /* Simple case, no restriction */
114   sprof = (GstEncodingProfile *)
115       gst_encoding_audio_profile_new (vorbis, NULL, NULL, 0);
116   fail_if (sprof == NULL);
117
118   out = gst_encoding_profile_get_input_caps (sprof);
119   fail_if (out == NULL);
120   fail_unless (gst_caps_is_equal (out, vorbis));
121   gst_caps_unref (out);
122   gst_encoding_profile_unref (sprof);
123
124   /* One simple restriction */
125   restriction = gst_caps_from_string ("audio/x-raw,channels=2,rate=44100");
126   test1 = gst_caps_from_string ("audio/x-vorbis,channels=2,rate=44100");
127   fail_if (restriction == NULL);
128
129   sprof = (GstEncodingProfile *)
130       gst_encoding_audio_profile_new (vorbis, NULL, restriction, 0);
131   fail_if (sprof == NULL);
132
133   out = gst_encoding_profile_get_input_caps (sprof);
134   fail_if (out == NULL);
135   GST_DEBUG ("got caps %" GST_PTR_FORMAT, out);
136   fail_unless (gst_caps_is_equal (out, test1));
137   gst_caps_unref (out);
138   gst_caps_unref (restriction);
139   gst_caps_unref (test1);
140   gst_encoding_profile_unref (sprof);
141
142   gst_caps_unref (vorbis);
143 }
144
145 GST_END_TEST;
146
147
148 GST_START_TEST (test_target_naming)
149 {
150   GstEncodingTarget *target;
151
152   gst_debug_set_threshold_for_name ("default", GST_LEVEL_NONE);
153
154   /* NULL values */
155   ASSERT_CRITICAL (target = gst_encoding_target_new (NULL, NULL, NULL, NULL));
156   fail_if (target != NULL);
157   ASSERT_CRITICAL (target =
158       gst_encoding_target_new ("donkey", NULL, NULL, NULL));
159   fail_if (target != NULL);
160   ASSERT_CRITICAL (target =
161       gst_encoding_target_new (NULL, "donkey", NULL, NULL));
162   fail_if (target != NULL);
163   ASSERT_CRITICAL (target =
164       gst_encoding_target_new (NULL, NULL, "donkey", NULL));
165   fail_if (target != NULL);
166
167   /* Name and Category validation */
168
169   /* empty non-NULL strings */
170   fail_if (gst_encoding_target_new ("", "valid", "description", NULL) != NULL);
171   fail_if (gst_encoding_target_new ("valid", "", "description", NULL) != NULL);
172
173   /* don't start with a lower case ASCII character */
174   fail_if (gst_encoding_target_new ("A", "valid", "description", NULL) != NULL);
175   fail_if (gst_encoding_target_new ("3", "valid", "description", NULL) != NULL);
176   fail_if (gst_encoding_target_new ("-", "valid", "description", NULL) != NULL);
177   fail_if (gst_encoding_target_new ("!", "valid", "description", NULL) != NULL);
178   fail_if (gst_encoding_target_new (" ", "valid", "description", NULL) != NULL);
179   fail_if (gst_encoding_target_new ("valid", "A", "description", NULL) != NULL);
180   fail_if (gst_encoding_target_new ("valid", "3", "description", NULL) != NULL);
181   fail_if (gst_encoding_target_new ("valid", "-", "description", NULL) != NULL);
182   fail_if (gst_encoding_target_new ("valid", "!", "description", NULL) != NULL);
183   fail_if (gst_encoding_target_new ("valid", " ", "description", NULL) != NULL);
184
185   /* Starting with anything else is valid */
186   target = gst_encoding_target_new ("a", "valid", "description", NULL);
187   fail_if (target == NULL);
188   gst_encoding_target_unref (target);
189   target = gst_encoding_target_new ("z", "valid", "description", NULL);
190   fail_if (target == NULL);
191   gst_encoding_target_unref (target);
192   target = gst_encoding_target_new ("valid", "a", "description", NULL);
193   fail_if (target == NULL);
194   gst_encoding_target_unref (target);
195   target = gst_encoding_target_new ("valid", "z", "description", NULL);
196   fail_if (target == NULL);
197   gst_encoding_target_unref (target);
198
199   /* only inner valid characters are lower-case ASCII letters *OR* digits *OR* hyphens */
200   fail_if (gst_encoding_target_new ("aA", "valid", "description",
201           NULL) != NULL);
202   fail_if (gst_encoding_target_new ("a!", "valid", "description",
203           NULL) != NULL);
204   fail_if (gst_encoding_target_new ("space donkeys", "valid", "description",
205           NULL) != NULL);
206   fail_if (gst_encoding_target_new ("howaboutùnicode", "valid", "description",
207           NULL) != NULL);
208   fail_if (gst_encoding_target_new ("valid", "aA", "description",
209           NULL) != NULL);
210   fail_if (gst_encoding_target_new ("valid", "a!", "description",
211           NULL) != NULL);
212
213   target =
214       gst_encoding_target_new ("donkey-4-ever", "valid", "description", NULL);
215   fail_if (target == NULL);
216   gst_encoding_target_unref (target);
217   target =
218       gst_encoding_target_new ("valid", "donkey-4-ever", "description", NULL);
219   fail_if (target == NULL);
220   gst_encoding_target_unref (target);
221
222 }
223
224 GST_END_TEST;
225
226 static GstEncodingTarget *
227 create_saveload_target (const gchar * targetname)
228 {
229   GstEncodingTarget *target;
230   GstEncodingProfile *profile, *sprof;
231   GstCaps *caps, *caps2;
232
233   GST_DEBUG ("Creating target");
234
235   target = gst_encoding_target_new (targetname, "herding",
236       "Plenty of pony glitter profiles", NULL);
237   caps = gst_caps_from_string ("animal/x-pony");
238   profile =
239       (GstEncodingProfile *) gst_encoding_container_profile_new ("pony",
240       "I don't want a description !", caps, NULL);
241   gst_caps_unref (caps);
242   gst_encoding_target_add_profile (target, profile);
243
244   caps = gst_caps_from_string ("audio/x-pony-song,pretty=True");
245   caps2 = gst_caps_from_string ("audio/x-raw,channels=1,rate=44100");
246   sprof =
247       (GstEncodingProfile *) gst_encoding_audio_profile_new (caps, NULL, caps2,
248       1);
249   gst_encoding_container_profile_add_profile ((GstEncodingContainerProfile *)
250       profile, sprof);
251   gst_caps_unref (caps);
252   gst_caps_unref (caps2);
253
254   caps = gst_caps_from_string ("video/x-glitter,sparkling=True");
255   caps2 =
256       gst_caps_from_string ("video/x-raw,width=640,height=480,framerate=15/1");
257   sprof = (GstEncodingProfile *)
258       gst_encoding_video_profile_new (caps, "seriously glittery", caps2, 0);
259   gst_encoding_video_profile_set_variableframerate ((GstEncodingVideoProfile *)
260       sprof, TRUE);
261   gst_encoding_container_profile_add_profile ((GstEncodingContainerProfile *)
262       profile, sprof);
263   gst_caps_unref (caps);
264   gst_caps_unref (caps2);
265
266   return target;
267 }
268
269 GST_START_TEST (test_target_profile)
270 {
271   GstEncodingTarget *target;
272   GstEncodingProfile *prof;
273
274   target = create_saveload_target ("myponytarget");
275
276   /* NULL isn't a valid profile name */
277   ASSERT_CRITICAL (gst_encoding_target_get_profile (target, NULL));
278
279   /* try finding a profile that doesn't exist */
280   fail_if (gst_encoding_target_get_profile (target,
281           "no-really-does-not-exist"));
282
283   /* try finding a profile that exists */
284   prof = gst_encoding_target_get_profile (target, "pony");
285   fail_if (prof == NULL);
286
287   gst_encoding_profile_unref (prof);
288   gst_encoding_target_unref (target);
289 }
290
291 GST_END_TEST;
292
293 GST_START_TEST (test_saving_profile)
294 {
295   GstEncodingTarget *orig, *loaded = NULL;
296   GstEncodingProfile *proforig, *profloaded;
297   gchar *profile_file_name;
298
299   /* Create and store a target */
300   orig = create_saveload_target ("myponytarget2");
301   GST_DEBUG ("Saving target 'myponytarget2'");
302   fail_unless (gst_encoding_target_save (orig, NULL));
303
304   /* Check we can load it */
305   profile_file_name =
306       g_build_filename (g_get_user_data_dir (), "gstreamer-1.0",
307       "encoding-profiles", "herding", "myponytarget2.gep", NULL);
308   GST_DEBUG ("Loading target from '%s'", profile_file_name);
309   loaded = gst_encoding_target_load_from_file (profile_file_name, NULL);
310   fail_unless (loaded != NULL);
311   g_free (profile_file_name);
312
313   GST_DEBUG ("Checking targets are equal");
314   /* Check targets are identical */
315   /* 1. at the target level */
316   fail_unless_equals_string (gst_encoding_target_get_name (orig),
317       gst_encoding_target_get_name (loaded));
318   fail_unless_equals_string (gst_encoding_target_get_category (orig),
319       gst_encoding_target_get_category (loaded));
320   fail_unless_equals_string (gst_encoding_target_get_description (orig),
321       gst_encoding_target_get_description (loaded));
322   fail_unless_equals_int (g_list_length ((GList *)
323           gst_encoding_target_get_profiles (loaded)), 1);
324
325   /* 2. at the profile level */
326   profloaded =
327       (GstEncodingProfile *) gst_encoding_target_get_profiles (loaded)->data;
328   proforig =
329       (GstEncodingProfile *) gst_encoding_target_get_profiles (orig)->data;
330
331   fail_unless_equals_int (G_TYPE_FROM_INSTANCE (profloaded),
332       G_TYPE_FROM_INSTANCE (proforig));
333   GST_DEBUG ("Comparing loaded:%p to original:%p", profloaded, proforig);
334   fail_unless (gst_encoding_profile_is_equal (profloaded, proforig));
335
336   gst_encoding_target_unref (orig);
337   gst_encoding_target_unref (loaded);
338 }
339
340 GST_END_TEST;
341
342 static void
343 test_individual_target (GstEncodingTarget * target)
344 {
345   GstEncodingProfile *prof;
346   GstCaps *tmpcaps, *tmpcaps2;
347   GstEncodingProfile *sprof1, *sprof2;
348
349   GST_DEBUG ("Checking the target properties");
350   /* Check the target  */
351   fail_unless_equals_string (gst_encoding_target_get_name (target),
352       "myponytarget");
353   fail_unless_equals_string (gst_encoding_target_get_category (target),
354       "herding");
355   fail_unless_equals_string (gst_encoding_target_get_description (target),
356       "Plenty of pony glitter profiles");
357
358   GST_DEBUG ("Checking the number of profiles the target contains");
359   fail_unless_equals_int (g_list_length ((GList *)
360           gst_encoding_target_get_profiles (target)), 1);
361
362
363   GST_DEBUG ("Checking the container profile");
364   /* Check the profile */
365   prof = (GstEncodingProfile *) gst_encoding_target_get_profiles (target)->data;
366   tmpcaps = gst_caps_from_string ("animal/x-pony");
367   CHECK_PROFILE (prof, "pony", "I don't want a description !", tmpcaps, NULL, 0,
368       0);
369   gst_caps_unref (tmpcaps);
370
371   GST_DEBUG ("Checking the container profile has 2 stream profiles");
372   /* Check the stream profiles */
373   fail_unless_equals_int (g_list_length ((GList *)
374           gst_encoding_container_profile_get_profiles (
375               (GstEncodingContainerProfile *) prof)), 2);
376
377   GST_DEBUG ("Checking the container profile has the audio/x-pony-song stream");
378   tmpcaps = gst_caps_from_string ("audio/x-pony-song,pretty=True");
379   tmpcaps2 = gst_caps_from_string ("audio/x-raw,channels=1,rate=44100");
380   sprof1 =
381       (GstEncodingProfile *) gst_encoding_audio_profile_new (tmpcaps, NULL,
382       tmpcaps2, 1);
383   fail_unless (gst_encoding_container_profile_contains_profile (
384           (GstEncodingContainerProfile *) prof, sprof1));
385   gst_encoding_profile_unref (sprof1);
386   gst_caps_unref (tmpcaps);
387   gst_caps_unref (tmpcaps2);
388
389   GST_DEBUG ("Checking the container profile has the video//x-glitter stream");
390   tmpcaps = gst_caps_from_string ("video/x-glitter,sparkling=True");
391   tmpcaps2 =
392       gst_caps_from_string ("video/x-raw,width=640,height=480,framerate=15/1");
393   sprof2 = (GstEncodingProfile *)
394       gst_encoding_video_profile_new (tmpcaps, "seriously glittery", tmpcaps2,
395       0);
396   gst_encoding_video_profile_set_variableframerate ((GstEncodingVideoProfile *)
397       sprof2, TRUE);
398   fail_unless (gst_encoding_container_profile_contains_profile (
399           (GstEncodingContainerProfile *) prof, sprof2));
400   gst_encoding_profile_unref (sprof2);
401   gst_caps_unref (tmpcaps);
402   gst_caps_unref (tmpcaps2);
403 }
404
405 GST_START_TEST (test_loading_profile)
406 {
407   GstEncodingTarget *target;
408   gchar *profile_file_name;
409   GstEncodingProfile *profile;
410   GstCaps *tmpcaps;
411   GValue strvalue = { 0, };
412   GValue objectvalue = { 0, };
413
414   gst_debug_set_threshold_for_name ("default", GST_LEVEL_NONE);
415
416   /* Test loading using short method and all arguments */
417   target = gst_encoding_target_load ("myponytarget", "herding", NULL);
418   fail_unless (target != NULL);
419   test_individual_target (target);
420   gst_encoding_target_unref (target);
421
422   /* Test loading using short method and no category */
423   target = gst_encoding_target_load ("myponytarget", NULL, NULL);
424   fail_unless (target != NULL);
425   test_individual_target (target);
426   gst_encoding_target_unref (target);
427
428   /* Test loading using fully specified path */
429   profile_file_name =
430       g_build_filename (g_get_user_data_dir (), "gstreamer-1.0",
431       "encoding-profiles", "herding", "myponytarget.gep", NULL);
432
433   GST_DEBUG ("Loading target from '%s'", profile_file_name);
434   target = gst_encoding_target_load_from_file (profile_file_name, NULL);
435   g_free (profile_file_name);
436   fail_unless (target != NULL);
437   test_individual_target (target);
438   gst_encoding_target_unref (target);
439
440   /* Test getting the profiles directly
441    * First without category */
442   profile = gst_encoding_profile_find ("myponytarget", "pony", NULL);
443   fail_unless (profile != NULL);
444   tmpcaps = gst_caps_from_string ("animal/x-pony");
445   CHECK_PROFILE (profile, "pony", "I don't want a description !", tmpcaps, NULL,
446       0, 0);
447   gst_caps_unref (tmpcaps);
448   gst_encoding_profile_unref (profile);
449
450   /* Then with a specific category */
451   profile = gst_encoding_profile_find ("myponytarget", "pony", "herding");
452   fail_unless (profile != NULL);
453   tmpcaps = gst_caps_from_string ("animal/x-pony");
454   CHECK_PROFILE (profile, "pony", "I don't want a description !", tmpcaps, NULL,
455       0, 0);
456   gst_caps_unref (tmpcaps);
457   gst_encoding_profile_unref (profile);
458
459   /* For my next trick, I will need the assistance of a GValue */
460   g_value_init (&strvalue, G_TYPE_STRING);
461   g_value_init (&objectvalue, GST_TYPE_ENCODING_PROFILE);
462   g_value_set_static_string (&strvalue, "myponytarget/pony");
463   fail_unless (g_value_transform (&strvalue, &objectvalue));
464   profile = (GstEncodingProfile *) g_value_dup_object (&objectvalue);
465   fail_if (profile == NULL);
466   g_value_unset (&strvalue);
467   g_value_unset (&objectvalue);
468   tmpcaps = gst_caps_from_string ("animal/x-pony");
469   CHECK_PROFILE (profile, "pony", "I don't want a description !", tmpcaps, NULL,
470       0, 0);
471   gst_caps_unref (tmpcaps);
472   gst_encoding_profile_unref (profile);
473
474   /* Let's go crazy for error detection */
475   fail_if (gst_encoding_profile_find ("myponytarget", "whales", NULL));
476   fail_if (gst_encoding_profile_find ("myponytarget", "whales", "herding"));
477   fail_if (gst_encoding_profile_find ("myponytarget", "", NULL));
478   fail_if (gst_encoding_profile_find ("", "pony", NULL));
479 }
480
481 GST_END_TEST;
482
483 GST_START_TEST (test_target_list)
484 {
485   GList *categories;
486   GList *targets;
487   GList *tmp;
488
489   /* Make sure we get our test category in the available categories */
490   categories = gst_encoding_list_available_categories ();
491   fail_if (categories == NULL);
492   fail_if (g_list_find_custom (categories, "herding",
493           (GCompareFunc) g_strcmp0) == NULL);
494   g_list_foreach (categories, (GFunc) g_free, NULL);
495   g_list_free (categories);
496
497   /* Try getting all available targets with a specified category */
498   targets = gst_encoding_list_all_targets ("herding");
499   fail_if (targets == NULL);
500   for (tmp = targets; tmp; tmp = tmp->next) {
501     GstEncodingTarget *target = (GstEncodingTarget *) tmp->data;
502     if (!g_strcmp0 (gst_encoding_target_get_name (target), "myponytarget"))
503       break;
504   }
505   /* If tmp is NULL, it means we iterated the whole list without finding
506    * our target */
507   fail_if (tmp == NULL);
508   g_list_foreach (targets, (GFunc) g_object_unref, NULL);
509   g_list_free (targets);
510
511   /* Try getting all available targets without a specified category */
512   targets = gst_encoding_list_all_targets (NULL);
513   fail_if (targets == NULL);
514   for (tmp = targets; tmp; tmp = tmp->next) {
515     GstEncodingTarget *target = (GstEncodingTarget *) tmp->data;
516     if (!g_strcmp0 (gst_encoding_target_get_name (target), "myponytarget"))
517       break;
518   }
519   /* If tmp is NULL, it means we iterated the whole list without finding
520    * our target */
521   fail_if (tmp == NULL);
522   g_list_foreach (targets, (GFunc) g_object_unref, NULL);
523   g_list_free (targets);
524 }
525
526 GST_END_TEST;
527
528
529 static const gchar *profile_string = "\
530 [GStreamer Encoding Target]\n\
531 name=myponytarget\n\
532 category=herding\n\
533 description=Plenty of pony glitter profiles\n\
534 \n\
535 [profile-pony1]\n\
536 name=pony\n\
537 type=container\n\
538 description=I don't want a description !\n\
539 format=animal/x-pony\n\
540 \n\
541 [streamprofile-pony11]\n\
542 parent=pony\n\
543 type=audio\n\
544 format=audio/x-pony-song,pretty=True\n\
545 restriction=audio/x-raw,channels=1,rate=44100\n\
546 presence=1\n\
547 \n\
548 [streamprofile-pony12]\n\
549 parent=pony\n\
550 type=video\n\
551 preset=seriously glittery\n\
552 format=video/x-glitter,sparkling=True\n\
553 restriction=video/x-raw,width=640,height=480,framerate=15/1\n\
554 presence=0\n\
555 variableframerate=true\n\
556 ";
557
558 static void
559 remove_profile_file (void)
560 {
561   gchar *profile_file_name;
562
563   profile_file_name =
564       g_build_filename (g_get_user_data_dir (), "gstreamer-1.0",
565       "encoding-profiles", "herding", "myponytarget.gep", NULL);
566   g_unlink (profile_file_name);
567   g_free (profile_file_name);
568   profile_file_name =
569       g_build_filename (g_get_user_data_dir (), "gstreamer-1.0",
570       "encoding-profiles", "herding", "myponytarget2.gep", NULL);
571   g_unlink (profile_file_name);
572   g_free (profile_file_name);
573 }
574
575 static void
576 create_profile_file (void)
577 {
578   gchar *profile_file_name;
579   gchar *profile_dir;
580   GError *error = NULL;
581
582   profile_dir =
583       g_build_filename (g_get_user_data_dir (), "gstreamer-1.0",
584       "encoding-profiles", "herding", NULL);
585   profile_file_name =
586       g_build_filename (g_get_user_data_dir (), "gstreamer-1.0",
587       "encoding-profiles", "herding", "myponytarget.gep", NULL);
588   g_mkdir_with_parents (profile_dir, S_IRUSR | S_IWUSR | S_IXUSR);
589   if (!g_file_set_contents (profile_file_name, profile_string,
590           strlen (profile_string), &error))
591     GST_WARNING ("Couldn't write contents to file : %s", error->message);
592   g_free (profile_dir);
593   g_free (profile_file_name);
594 }
595
596 static void
597 test_setup (void)
598 {
599   create_profile_file ();
600 }
601
602 static void
603 test_teardown (void)
604 {
605   remove_profile_file ();
606 }
607
608
609 static Suite *
610 profile_suite (void)
611 {
612   Suite *s = suite_create ("profile support library");
613   TCase *tc_chain = tcase_create ("general");
614   gboolean can_write;
615   gchar *gst_dir;
616
617   /* cehck if we can create profiles */
618   gst_dir = g_build_filename (g_get_user_data_dir (), "gstreamer-1.0", NULL);
619   can_write = (g_access (gst_dir, R_OK | W_OK | X_OK) == 0);
620   g_free (gst_dir);
621
622   suite_add_tcase (s, tc_chain);
623
624   tcase_add_test (tc_chain, test_profile_creation);
625   tcase_add_test (tc_chain, test_profile_input_caps);
626   tcase_add_test (tc_chain, test_target_naming);
627   tcase_add_test (tc_chain, test_target_profile);
628   if (can_write) {
629     tcase_add_test (tc_chain, test_loading_profile);
630     tcase_add_test (tc_chain, test_saving_profile);
631     tcase_add_test (tc_chain, test_target_list);
632   }
633
634   tcase_add_unchecked_fixture (tc_chain, test_setup, test_teardown);
635
636   return s;
637 }
638
639 GST_CHECK_MAIN (profile);