Url: Add tests schemeIsLocal,Remote,Volatile,Downloading and scheme snfs4
authorMichael Andres <ma@suse.de>
Thu, 10 Sep 2009 17:10:44 +0000 (19:10 +0200)
committerMichael Andres <ma@suse.de>
Thu, 10 Sep 2009 17:10:44 +0000 (19:10 +0200)
zypp/Url.cc
zypp/Url.h

index 9c6b42f..7ca3c61 100644 (file)
@@ -205,6 +205,7 @@ namespace zypp
         ref.reset( new UrlBase());
         ref->config("require_host",     "m");   // host is mandatory
         addUrlByScheme("nfs",    ref);
+        addUrlByScheme("nfs4",   ref);
         addUrlByScheme("smb",    ref);
         addUrlByScheme("cifs",   ref);
         addUrlByScheme("http",   ref);
@@ -438,6 +439,42 @@ namespace zypp
   }
 
 
+  ///////////////////////////////////////////////////////////////////
+  namespace
+  {
+    inline bool isInList( const char ** begin_r, const char ** end_r, const std::string & scheme_r )
+    {
+      for ( ; begin_r != end_r; ++begin_r )
+        if ( scheme_r == *begin_r )
+          return true;
+      return false;
+    }
+  }
+  bool Url::schemeIsLocal( const std::string & scheme_r )
+  {
+    static const char * val[] = { "cd", "dvd", "dir", "hd", "iso", "file" };
+    return isInList( arrayBegin(val), arrayEnd(val), scheme_r );
+  }
+
+  bool Url::schemeIsRemote( const std::string & scheme_r )
+  {
+    static const char * val[] = { "http", "https", "nfs", "nfs4", "smb", "cifs", "ftp", "sftp" };
+    return isInList( arrayBegin(val), arrayEnd(val), scheme_r );
+  }
+
+  bool Url::schemeIsVolatile( const std::string & scheme_r )
+  {
+    static const char * val[] = { "cd", "dvd" };
+    return isInList( arrayBegin(val), arrayEnd(val), scheme_r );
+  }
+
+  bool Url::schemeIsDownloading( const std::string & scheme_r )
+  {
+    static const char * val[] = { "http", "https", "ftp", "sftp" };
+    return isInList( arrayBegin(val), arrayEnd(val), scheme_r );
+  }
+  ///////////////////////////////////////////////////////////////////
+
   // -----------------------------------------------------------------
   bool
   Url::isValid() const
index d3f0cec..e56bb17 100644 (file)
@@ -247,6 +247,26 @@ namespace zypp
     isValidScheme(const std::string &scheme) const;
 
 
+    /** hd cd dvd dir file iso */
+    static bool schemeIsLocal( const std::string & scheme_r );
+    /** \overload nonstatic version */
+    bool schemeIsLocal() const { return schemeIsLocal( getScheme() ); }
+
+    /** nfs nfs4 smb cifs http https ftp sftp */
+    static bool schemeIsRemote( const std::string & scheme_r );
+    /** \overload nonstatic version */
+    bool schemeIsRemote() const { return schemeIsRemote( getScheme() ); }
+
+    /** cd dvd */
+    static bool schemeIsVolatile( const std::string & scheme_r );
+    /** \overload nonstatic version */
+    bool schemeIsVolatile() const { return schemeIsVolatile( getScheme() ); }
+
+    /** http https ftp sftp */
+    static bool schemeIsDownloading( const std::string & scheme_r );
+    /** \overload nonstatic version */
+    bool schemeIsDownloading() const { return schemeIsDownloading( getScheme() ); }
+
     /**
      * \brief Verifies the Url.
      *