summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid King <amigadave@amigadave.com>2011-12-13 22:04:14 +0100
committerDavid King <amigadave@amigadave.com>2011-12-13 23:16:00 +0100
commitc8252e3b957810cd7759064ca6ac440dcd06b943 (patch)
tree89a7db4073e5ed0aa84e73293f8d6500f13ccf35 /tests
parent4f1af6e070ed9d6b06b2f9f2bc6ef78ffac84ed8 (diff)
Improve tests for CheeseFileUtil
Add burst_reset test. Add photo and video path tests. Improve existing burst test.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-libcheese.c88
1 files changed, 79 insertions, 9 deletions
diff --git a/tests/test-libcheese.c b/tests/test-libcheese.c
index e704ff9..592bc7c 100644
--- a/tests/test-libcheese.c
+++ b/tests/test-libcheese.c
@@ -23,17 +23,18 @@
#include "cheese-fileutil.h"
/* Test CheeseFileUtil */
-static void test_file_utils ()
+static void
+fileutil_burst (void)
{
- CheeseFileUtil *file_util;
+ CheeseFileUtil *fileutil;
gchar *first_path, *second_path, *third_path, *stub;
gchar *real_second, *real_third;
gchar **split;
- file_util = cheese_fileutil_new ();
- g_assert (file_util != NULL);
+ fileutil = cheese_fileutil_new ();
+ g_assert (fileutil != NULL);
- first_path = cheese_fileutil_get_new_media_filename (file_util,
+ first_path = cheese_fileutil_get_new_media_filename (fileutil,
CHEESE_MEDIA_MODE_BURST);
split = g_strsplit (first_path, "_1.jpg", -1);
stub = g_strdup (split[0]);
@@ -41,9 +42,12 @@ static void test_file_utils ()
second_path = g_strdup_printf ("%s_2.jpg", stub);
third_path = g_strdup_printf ("%s_3.jpg", stub);
- real_second = cheese_fileutil_get_new_media_filename (file_util,
+ real_second = cheese_fileutil_get_new_media_filename (fileutil,
CHEESE_MEDIA_MODE_BURST);
- real_third = cheese_fileutil_get_new_media_filename (file_util,
+ /* Sleep for two seconds, and check to ensure that the original burst time
+ * remains constant. */
+ g_usleep (2000000);
+ real_third = cheese_fileutil_get_new_media_filename (fileutil,
CHEESE_MEDIA_MODE_BURST);
g_assert_cmpstr (real_second, ==, second_path);
@@ -55,7 +59,67 @@ static void test_file_utils ()
g_free (second_path);
g_free (third_path);
g_free (stub);
- g_object_unref (file_util);
+ g_object_unref (fileutil);
+}
+
+static void
+fileutil_reset_burst (void)
+{
+ CheeseFileUtil *fileutil;
+ gchar *first_path, *second_path;
+
+ fileutil = cheese_fileutil_new ();
+ g_assert (fileutil != NULL);
+
+ first_path = cheese_fileutil_get_new_media_filename (fileutil,
+ CHEESE_MEDIA_MODE_BURST);
+ cheese_fileutil_reset_burst (fileutil);
+ /* Sleep for two seconds to ensure a different burst time. */
+ g_usleep (2000000);
+ second_path = cheese_fileutil_get_new_media_filename (fileutil,
+ CHEESE_MEDIA_MODE_BURST);
+
+ g_assert (g_str_has_suffix (first_path, "_1.jpg"));
+ g_assert (g_str_has_suffix (second_path, "_1.jpg"));
+ g_assert_cmpstr (first_path, !=, second_path);
+
+ g_free (first_path);
+ g_free (second_path);
+ g_object_unref (fileutil);
+}
+
+static void
+fileutil_photo_path (void)
+{
+ CheeseFileUtil *fileutil;
+ const gchar *path;
+
+ fileutil = cheese_fileutil_new ();
+ g_assert (fileutil != NULL);
+
+ path = cheese_fileutil_get_photo_path (fileutil);
+ g_assert (path != NULL);
+ g_assert (g_file_test (path, G_FILE_TEST_EXISTS));
+ g_assert (g_file_test (path, G_FILE_TEST_IS_DIR));
+
+ g_object_unref (fileutil);
+}
+
+static void
+fileutil_video_path (void)
+{
+ CheeseFileUtil *fileutil;
+ const gchar *path;
+
+ fileutil = cheese_fileutil_new ();
+ g_assert (fileutil != NULL);
+
+ path = cheese_fileutil_get_video_path (fileutil);
+ g_assert (path != NULL);
+ g_assert (g_file_test (path, G_FILE_TEST_EXISTS));
+ g_assert (g_file_test (path, G_FILE_TEST_IS_DIR));
+
+ g_object_unref (fileutil);
}
int main (int argc, gchar *argv[])
@@ -65,7 +129,13 @@ int main (int argc, gchar *argv[])
g_test_init (&argc, &argv, NULL);
- g_test_add_func ("/libcheese/file_util", test_file_utils);
+ if (g_test_slow ())
+ {
+ g_test_add_func ("/libcheese/fileutil/burst", fileutil_burst);
+ g_test_add_func ("/libcheese/fileutil/reset_burst", fileutil_reset_burst);
+ }
+ g_test_add_func ("/libcheese/fileutil/photo_path", fileutil_photo_path);
+ g_test_add_func ("/libcheese/fileutil/video_path", fileutil_video_path);
return g_test_run ();
}