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