LCOV - code coverage report
Current view: top level - src/libs/tools/tests - testtool_umount.cpp (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 79 79 100.0 %
Date: 2019-09-12 12:28:41 Functions: 44 84 52.4 %

          Line data    Source code
       1             : /**
       2             :  * @file
       3             :  *
       4             :  * @brief Tests for the umount
       5             :  *
       6             :  * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
       7             :  *
       8             :  */
       9             : 
      10             : 
      11             : #include <backend.hpp>
      12             : #include <backends.hpp>
      13             : #include <keysetio.hpp>
      14             : 
      15             : #include <gtest/gtest.h>
      16             : 
      17          24 : void testUmount (std::string mp)
      18             : {
      19             :         using namespace kdb;
      20             :         using namespace kdb::tools;
      21          48 :         KeySet ks;
      22             : 
      23          48 :         Backend b1;
      24         120 :         b1.setMountpoint (Key (mp, KEY_END), ks);
      25          24 :         b1.serialize (ks);
      26             : 
      27          24 :         Backends::umount (mp, ks);
      28          96 :         EXPECT_EQ (ks.size (), 0) << "size not null, but keyset is:\n" << ks;
      29          24 : }
      30             : 
      31          20 : TEST (Umount, SimpleRoot)
      32             : {
      33           8 :         testUmount ("/");
      34           2 : }
      35          20 : TEST (Umount, SimpleSpec)
      36             : {
      37           8 :         testUmount ("spec/hello");
      38           2 : }
      39          20 : TEST (Umount, SimpleDir)
      40             : {
      41           8 :         testUmount ("dir/hello");
      42           2 : }
      43          20 : TEST (Umount, SimpleUser)
      44             : {
      45           8 :         testUmount ("user/hello");
      46           2 : }
      47          20 : TEST (Umount, SimpleSystem)
      48             : {
      49           8 :         testUmount ("system/hello");
      50           2 : }
      51          20 : TEST (Umount, SimpleCascading)
      52             : {
      53           8 :         testUmount ("/hello");
      54           2 : }
      55             : 
      56          20 : TEST (Umount, InvolvedRoot)
      57             : {
      58           8 :         testUmount ("/is//../a//../complex/..///.");
      59           2 : }
      60             : 
      61          20 : TEST (Umount, InvolvedSpec)
      62             : {
      63           8 :         testUmount ("spec/is///a//./more/complex/../complicated///issue//.");
      64           2 : }
      65          20 : TEST (Umount, InvolvedDir)
      66             : {
      67           8 :         testUmount ("dir/is///a//./more/complex/../complicated///issue//.");
      68           2 : }
      69          20 : TEST (Umount, InvolvedUser)
      70             : {
      71           8 :         testUmount ("user/is///a//./more/complex/../complicated///issue//.");
      72           2 : }
      73          20 : TEST (Umount, InvolvedSystem)
      74             : {
      75           8 :         testUmount ("system/is///a//./more/complex/../complicated///issue//.");
      76           2 : }
      77          20 : TEST (Umount, InvolvedCascading)
      78             : {
      79           8 :         testUmount ("/is///a//./more/complex/../complicated///issue//.");
      80           2 : }
      81             : 
      82             : /**
      83             :  * @brief Test umount with compatibility umount-names
      84             :  *
      85             :  * @param mp the mountpoint to mount
      86             :  * @param ump the mountpoint to umount
      87             :  */
      88          16 : void testOldMount (std::string mp, std::string ump)
      89             : {
      90             :         using namespace kdb;
      91             :         using namespace kdb::tools;
      92          32 :         KeySet ks;
      93             : 
      94             :         // fake mount
      95          32 :         Key x ("system/elektra/mountpoints", KEY_END);
      96          16 :         x.addBaseName (mp);
      97          64 :         ks.append (x.dup ());
      98          64 :         x.addBaseName ("mountpoint");
      99          48 :         x.setString (mp);
     100          16 :         ks.append (x);
     101             : 
     102          16 :         Backends::umount (ump, ks);
     103          64 :         EXPECT_EQ (ks.size (), 0) << "size not null, but keyset is:\n" << ks;
     104          16 : }
     105             : 
     106          20 : TEST (Umount, SameSpec)
     107             : {
     108          14 :         testOldMount ("spec/hello", "spec/hello");
     109           2 : }
     110          20 : TEST (Umount, OldSpec)
     111             : {
     112          14 :         testOldMount ("spec/hello", "spec_hello");
     113           2 : } // actually this is impossible, in 0.8.10 spec mountpoints did not exist ;)
     114          20 : TEST (Umount, SameUser)
     115             : {
     116          14 :         testOldMount ("user/hello", "user_hello");
     117           2 : }
     118          20 : TEST (Umount, SameSystem)
     119             : {
     120          14 :         testOldMount ("system/hello", "system_hello");
     121           2 : }
     122          20 : TEST (Umount, SimilarOldNew)
     123             : {
     124          14 :         testOldMount ("/hello/hello", "/hello_hello");
     125           2 : }
     126          20 : TEST (Umount, SimilarOldNew2)
     127             : {
     128          14 :         testOldMount ("/hello/hello", "_hello_hello");
     129           2 : }
     130          20 : TEST (Umount, SimilarOldNew3)
     131             : {
     132          14 :         testOldMount ("/", "_");
     133           2 : }
     134          20 : TEST (Umount, SimilarOldNew4)
     135             : {
     136          14 :         testOldMount ("/", "/");
     137           8 : }

Generated by: LCOV version 1.13