1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
#include <string.h>
#include <math.h>
#include <CUnit/CUnit.h>
#include <CUnit/Basic.h>
#include "../src/utils.h"
#include "../src/connectors/common.h"
void
test_common_slot_get_id_from_path ()
{
guint id;
gint err;
printf ("\n");
err = common_slot_get_id_from_path ("", &id);
CU_ASSERT_TRUE (err == -EINVAL);
err = common_slot_get_id_from_path ("/", &id);
CU_ASSERT_TRUE (err == -EINVAL);
err = common_slot_get_id_from_path ("/1", &id);
CU_ASSERT_TRUE (err == 0);
CU_ASSERT_TRUE (id == 1);
err = common_slot_get_id_from_path ("/p/1", &id);
CU_ASSERT_TRUE (err == 0);
CU_ASSERT_TRUE (id == 1);
}
void
test_common_get_sanitized_name ()
{
gchar *str;
printf ("\n");
str = common_get_sanitized_name ("asdf", NULL, '?');
CU_ASSERT_STRING_EQUAL (str, "asdf");
g_free (str);
str = common_get_sanitized_name ("ásdf", NULL, '?');
CU_ASSERT_STRING_EQUAL (str, "asdf");
g_free (str);
str = common_get_sanitized_name ("asdf", "asd", '?');
CU_ASSERT_STRING_EQUAL (str, "asd?");
g_free (str);
str = common_get_sanitized_name ("ásdf", "asd", '?');
CU_ASSERT_STRING_EQUAL (str, "asd?");
g_free (str);
str = common_get_sanitized_name ("ásdf", "asd", 0);
CU_ASSERT_STRING_EQUAL (str, "asd");
g_free (str);
}
void
test_common_to_os_sanitized_name ()
{
gchar *str = strdup ("\\^/");
printf ("\n");
common_to_os_sanitized_name (str);
CU_ASSERT_STRING_EQUAL (str, "?^?");
g_free (str);
}
static const gchar *EXTS[] = { "ext", NULL };
static const gchar **
get_exts ()
{
return EXTS;
}
void
test_common_slot_get_download_path ()
{
struct backend backend;
struct fs_operations ops;
gchar *path;
struct idata idata;
snprintf (backend.name, LABEL_MAX, "Dev Name");
ops.name = "fsname";
ops.get_exts = get_exts;
idata_init (&idata, NULL, strdup ("name"), NULL);
path = common_slot_get_download_path_n (&backend, &ops, "/dst_dir", "/1",
&idata);
CU_ASSERT_STRING_EQUAL ("/dst_dir/Dev Name fsname 1 - name.ext", path);
g_free (path);
path = common_slot_get_download_path_nn (&backend, &ops, "/dst_dir", "/1",
&idata);
CU_ASSERT_STRING_EQUAL ("/dst_dir/Dev Name fsname 01 - name.ext", path);
g_free (path);
path = common_slot_get_download_path_nnn (&backend, &ops, "/dst_dir", "/1",
&idata);
CU_ASSERT_STRING_EQUAL ("/dst_dir/Dev Name fsname 001 - name.ext", path);
g_free (path);
path = common_slot_get_download_path (&backend, &ops, "/dst_dir", "/1",
&idata, 0);
printf ("%s\n", path);
CU_ASSERT_STRING_EQUAL ("/dst_dir/Dev Name fsname - name.ext", path);
g_free (path);
idata_free (&idata);
idata_init (&idata, NULL, NULL, NULL);
path = common_slot_get_download_path_n (&backend, &ops, "/dst_dir", "/1",
&idata);
CU_ASSERT_STRING_EQUAL ("/dst_dir/Dev Name fsname 1.ext", path);
g_free (path);
idata_free (&idata);
}
gint
main (gint argc, gchar *argv[])
{
gint err = 0;
debug_level = 5;
if (CU_initialize_registry () != CUE_SUCCESS)
{
goto cleanup;
}
CU_pSuite suite = CU_add_suite ("Elektroid common connector tests", 0, 0);
if (!suite)
{
goto cleanup;
}
if (!CU_add_test (suite, "common_slot_get_id_from_path",
test_common_slot_get_id_from_path))
{
goto cleanup;
}
if (!CU_add_test (suite, "common_get_sanitized_name",
test_common_get_sanitized_name))
{
goto cleanup;
}
if (!CU_add_test (suite, "test_common_to_os_sanitized_name",
test_common_to_os_sanitized_name))
{
goto cleanup;
}
if (!CU_add_test (suite, "common_slot_get_download_path",
test_common_slot_get_download_path))
{
goto cleanup;
}
CU_basic_set_mode (CU_BRM_VERBOSE);
CU_basic_run_tests ();
err = CU_get_number_of_tests_failed ();
cleanup:
CU_cleanup_registry ();
return err || CU_get_error ();
}
|