[gnome-autoar/wip/oholy/various-fixes: 8/23] tests: Add test for the output-is-dest property




commit 17297019602dde3f7dc158a99f3254378352b8aa
Author: Ondrej Holy <oholy redhat com>
Date:   Thu Mar 4 13:40:11 2021 +0100

    tests: Add test for the output-is-dest property
    
    A test for the `output-is-dest` property is missing currently. Let's add
    one to be sure that extra directory is not created for an archive with
    a file with a different name.

 .../input/arextract.zip                            | Bin 0 -> 208 bytes
 .../reference/arextractdifferent.txt               |   1 +
 tests/test-extract-unit.c                          |  45 +++++++++++++++++++++
 3 files changed, 46 insertions(+)
---
diff --git a/tests/files/extract/test-one-file-different-name-output-is-dest/input/arextract.zip 
b/tests/files/extract/test-one-file-different-name-output-is-dest/input/arextract.zip
new file mode 100644
index 0000000..1c24bdc
Binary files /dev/null and 
b/tests/files/extract/test-one-file-different-name-output-is-dest/input/arextract.zip differ
diff --git a/tests/files/extract/test-one-file-different-name-output-is-dest/reference/arextractdifferent.txt 
b/tests/files/extract/test-one-file-different-name-output-is-dest/reference/arextractdifferent.txt
new file mode 100644
index 0000000..12466e2
--- /dev/null
+++ b/tests/files/extract/test-one-file-different-name-output-is-dest/reference/arextractdifferent.txt
@@ -0,0 +1 @@
+AutoarExtract
diff --git a/tests/test-extract-unit.c b/tests/test-extract-unit.c
index 23977b3..b025470 100644
--- a/tests/test-extract-unit.c
+++ b/tests/test-extract-unit.c
@@ -556,6 +556,49 @@ test_one_file_different_name (void)
   assert_reference_and_output_match (extract_test);
 }
 
+/* Be sure that extra folder is not created in case of output-is-dest. */
+static void
+test_one_file_different_name_output_is_dest (void)
+{
+  /* arextract.zip
+   * └── arextractdifferent.txt
+   *
+   * 0 directories, 1 file
+   *
+   *
+   * ref
+   * └── arextractdifferent.txt
+   *
+   * 0 directory, 1 file
+   */
+
+  g_autoptr (ExtractTest) extract_test = NULL;
+  g_autoptr (ExtractTestData) data = NULL;
+  g_autoptr (GFile) archive = NULL;
+  g_autoptr (AutoarExtractor) extractor = NULL;
+
+  extract_test = extract_test_new ("test-one-file-different-name-output-is-dest");
+
+  if (!extract_test) {
+    g_assert_nonnull (extract_test);
+    return;
+  }
+
+  archive = g_file_get_child (extract_test->input, "arextract.zip");
+
+  extractor = autoar_extractor_new (archive, extract_test->output);
+  autoar_extractor_set_output_is_dest (extractor, TRUE);
+
+  data = extract_test_data_new_for_extract (extractor);
+
+  autoar_extractor_start (extractor, data->cancellable);
+
+  g_assert_cmpuint (data->number_of_files, ==, 1);
+  g_assert_no_error (data->error);
+  g_assert_true (data->completed_signalled);
+  assert_reference_and_output_match (extract_test);
+}
+
 static void
 test_multiple_files_same_name (void)
 {
@@ -941,6 +984,8 @@ setup_test_suite (void)
                    test_one_file_same_name);
   g_test_add_func ("/autoar-extract/test-one-file-different-name",
                    test_one_file_different_name);
+  g_test_add_func ("/autoar-extract/test-one-file-different-name-output-is-dest",
+                   test_one_file_different_name_output_is_dest);
   g_test_add_func ("/autoar-extract/test-multiple-files-same-name",
                    test_multiple_files_same_name);
   g_test_add_func ("/autoar-extract/test-multiple-files-different-name",


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]