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