[gparted/filesystem-tests: 4/4] Add ext2 reading tests: usage, label and UUID (!49)



commit cbb0de18fe88512e3f2f9265dfaaf4f8164f8a09
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Fri Jul 26 16:18:58 2019 +0100

    Add ext2 reading tests: usage, label and UUID (!49)
    
    The file system reading methods report errors into Partition messages
    because they are used as part of the GParted refresh, rather than
    reporting errors into OperationDetails used when applying operations.
    Therefore test for no messages for success and print the messages on
    failure.
    
    For example, temporarily breaking the read label test code by setting
    the wrong file system image name produces this:
    
        $ ./test_ext2 --gtest_filter='ext2Test.CreateAndReadLabel'
        Running main() from test_ext2.cc
        Note: Google Test filter = ext2Test.CreateAndReadLabel
        [==========] Running 1 test from 1 test case.
        [----------] Global test environment set-up.
        [----------] 1 test from ext2Test
        [ RUN      ] ext2Test.CreateAndReadLabel
        test_ext2.cc:311: Failure
        Value of: m_partition.get_messages().empty()
          Actual: false
        Expected: true
        Partition messages:
        e2label: No such file or directory while trying to open /does_not_exist/test_ext2.img
        Couldn't find valid filesystem superblock.
    
        [  FAILED  ] ext2Test.CreateAndReadLabel (77 ms)
        [----------] 1 test from ext2Test (77 ms total)
    
        [----------] Global test environment tear-down
        [==========] 1 test from 1 test case ran. (85 ms total)
        [  PASSED  ] 0 tests.
        [  FAILED  ] 1 test, listed below:
        [  FAILED  ] ext2Test.CreateAndReadLabel
    
         1 FAILED TEST
        $ echo $?
        1
    
    Closes !49 - Add file system interface tests

 tests/test_ext2.cc | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
---
diff --git a/tests/test_ext2.cc b/tests/test_ext2.cc
index 8ab84d0f..e4168929 100644
--- a/tests/test_ext2.cc
+++ b/tests/test_ext2.cc
@@ -43,6 +43,7 @@
 
 #include <iostream>
 #include <fstream>
+#include <vector>
 #include <stdlib.h>
 #include <stddef.h>
 #include <stdio.h>
@@ -116,6 +117,17 @@ Glib::ustring strip_markup(const Glib::ustring& str)
 }
 
 
+// Print method for the messages in a Partition object.
+std::ostream& operator<<(std::ostream& out, const Partition& partition)
+{
+       const std::vector<Glib::ustring> messages = partition.get_messages();
+       out << "Partition messages:\n";
+       for (unsigned int i = 0; i < messages.size(); i++)
+               out << messages[i];
+       return out;
+}
+
+
 // Print method for OperationDetailStatus.
 std::ostream& operator<<(std::ostream& out, const OperationDetailStatus od_status)
 {
@@ -255,6 +267,68 @@ TEST_F(ext2Test, Create)
 }
 
 
+TEST_F(ext2Test, CreateAndReadUsage)
+{
+       SKIP_IF_FS_DOESNT_SUPPORT(create);
+       SKIP_IF_FS_DOESNT_SUPPORT(read);
+
+       extra_setup();
+       ASSERT_TRUE(s_ext2_obj->create(m_partition, m_operation_detail)) << m_operation_detail;
+
+       s_ext2_obj->set_used_sectors(m_partition);
+       // Test file system usage is reported correctly.
+       // Used is between 0 and length.
+       EXPECT_LE(0, m_partition.sectors_used);
+       EXPECT_LE(m_partition.sectors_used, m_partition.get_sector_length());
+       // Unused is between 0 and length.
+       EXPECT_LE(0, m_partition.sectors_unused);
+       EXPECT_LE(m_partition.sectors_unused, m_partition.get_sector_length());
+       // Unallocated is 0.
+       EXPECT_EQ(m_partition.sectors_unallocated, 0);
+       // Used + unused = length.
+       EXPECT_EQ(m_partition.sectors_used + m_partition.sectors_unused, m_partition.get_sector_length());
+
+       // Test messages from read operation are empty or print them.
+       EXPECT_TRUE(m_partition.get_messages().empty()) << m_partition;
+}
+
+
+TEST_F(ext2Test, CreateAndReadLabel)
+{
+       SKIP_IF_FS_DOESNT_SUPPORT(create);
+       SKIP_IF_FS_DOESNT_SUPPORT(read_label);
+
+       const char* fs_label = "TEST_LABEL";
+       extra_setup();
+       m_partition.set_filesystem_label(fs_label);
+       ASSERT_TRUE(s_ext2_obj->create(m_partition, m_operation_detail)) << m_operation_detail;
+
+       // Test reading the label is successful.
+       s_ext2_obj->read_label(m_partition);
+       EXPECT_STREQ(fs_label, m_partition.get_filesystem_label().c_str());
+
+       // Test messages from read operation are empty or print them.
+       EXPECT_TRUE(m_partition.get_messages().empty()) << m_partition;
+}
+
+
+TEST_F(ext2Test, CreateAndReadUUID)
+{
+       SKIP_IF_FS_DOESNT_SUPPORT(create);
+       SKIP_IF_FS_DOESNT_SUPPORT(read_uuid);
+
+       extra_setup();
+       ASSERT_TRUE(s_ext2_obj->create(m_partition, m_operation_detail)) << m_operation_detail;
+
+       // Test reading the UUID is successful.
+       s_ext2_obj->read_uuid(m_partition);
+       EXPECT_EQ(m_partition.uuid.size(), 36U);
+
+       // Test messages from read operation are empty or print them.
+       EXPECT_TRUE(m_partition.get_messages().empty()) << m_partition;
+}
+
+
 }  // namespace GParted
 
 


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