return type;
}
+cr_CompressionType
+cr_compression_type(const char *name)
+{
+ if (!name)
+ return CR_CW_UNKNOWN_COMPRESSION;
+
+ gchar *name_lower = g_strdup(name);
+ for (gchar *c = name_lower; *c; c++)
+ *c = tolower(*c);
+
+ if (!g_strcmp0(name_lower, "gz") || !g_strcmp0(name_lower, "gzip"))
+ return CR_CW_GZ_COMPRESSION;
+ if (!g_strcmp0(name_lower, "bz2") || !g_strcmp0(name_lower, "bzip2"))
+ return CR_CW_BZ2_COMPRESSION;
+ if (!g_strcmp0(name_lower, "xz"))
+ return CR_CW_XZ_COMPRESSION;
+
+ return CR_CW_UNKNOWN_COMPRESSION;
+}
const char *
cr_compression_suffix(cr_CompressionType comtype)
g_assert_cmpstr(suffix, ==, ".xz");
}
+static void
+test_cr_compression_type(void)
+{
+ cr_CompressionType type;
+
+ type = cr_compression_type(NULL);
+ g_assert_cmpint(type, ==, CR_CW_UNKNOWN_COMPRESSION);
+
+ type = cr_compression_type("");
+ g_assert_cmpint(type, ==, CR_CW_UNKNOWN_COMPRESSION);
+
+ type = cr_compression_type("foo");
+ g_assert_cmpint(type, ==, CR_CW_UNKNOWN_COMPRESSION);
+
+ type = cr_compression_type("gz");
+ g_assert_cmpint(type, ==, CR_CW_GZ_COMPRESSION);
+
+ type = cr_compression_type("gzip");
+ g_assert_cmpint(type, ==, CR_CW_GZ_COMPRESSION);
+
+ type = cr_compression_type("GZ");
+ g_assert_cmpint(type, ==, CR_CW_GZ_COMPRESSION);
+
+ type = cr_compression_type("Gz");
+ g_assert_cmpint(type, ==, CR_CW_GZ_COMPRESSION);
+
+ type = cr_compression_type("bz2");
+ g_assert_cmpint(type, ==, CR_CW_BZ2_COMPRESSION);
+
+ type = cr_compression_type("bzip2");
+ g_assert_cmpint(type, ==, CR_CW_BZ2_COMPRESSION);
+
+ type = cr_compression_type("xz");
+ g_assert_cmpint(type, ==, CR_CW_XZ_COMPRESSION);
+}
+
static void
test_cr_detect_compression(void)
{
test_cr_compression_suffix);
g_test_add_func("/compression_wrapper/test_cr_detect_compression",
test_cr_detect_compression);
+ g_test_add_func("/compression_wrapper/test_cr_compression_type",
+ test_cr_compression_type);
g_test_add_func("/compression_wrapper/test_cr_detect_compression_bad_suffix",
test_cr_detect_compression_bad_suffix);
g_test_add_func("/compression_wrapper/test_cr_read_with_autodetection",