LCOV - code coverage report
Current view: top level - tests/harness - backendmanager.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 954b5873a738 Lines: 3 3 100.0 %
Date: 2019-06-30 05:20:33 Functions: 2 2 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /** @file backendmanager.h
       2                 :            :  * @brief Base class for backend handling in test harness
       3                 :            :  */
       4                 :            : /* Copyright 1999,2000,2001 BrightStation PLC
       5                 :            :  * Copyright 2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2017,2018 Olly Betts
       6                 :            :  *
       7                 :            :  * This program is free software; you can redistribute it and/or
       8                 :            :  * modify it under the terms of the GNU General Public License as
       9                 :            :  * published by the Free Software Foundation; either version 2 of the
      10                 :            :  * License, or (at your option) any later version.
      11                 :            :  *
      12                 :            :  * This program is distributed in the hope that it will be useful,
      13                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :            :  * GNU General Public License for more details.
      16                 :            :  *
      17                 :            :  * You should have received a copy of the GNU General Public License
      18                 :            :  * along with this program; if not, write to the Free Software
      19                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
      20                 :            :  * USA
      21                 :            :  */
      22                 :            : 
      23                 :            : #ifndef XAPIAN_INCLUDED_BACKENDMANAGER_H
      24                 :            : #define XAPIAN_INCLUDED_BACKENDMANAGER_H
      25                 :            : 
      26                 :            : #include <xapian.h>
      27                 :            : #include <vector>
      28                 :            : 
      29                 :            : // Paths to xapian-tcpsrv and xapian-progsrv.
      30                 :            : #ifdef __WIN32__
      31                 :            : // Under __WIN32__ we want \ path separators since we pass this path to
      32                 :            : // CreateProcess().
      33                 :            : # define XAPIAN_BIN_PATH "..\\bin\\"
      34                 :            : # define EXE_SUFFIX ".exe"
      35                 :            : #else
      36                 :            : # define XAPIAN_BIN_PATH "../bin/"
      37                 :            : # define EXE_SUFFIX
      38                 :            : #endif
      39                 :            : #define XAPIAN_TCPSRV XAPIAN_BIN_PATH "xapian-tcpsrv" EXE_SUFFIX
      40                 :            : #define XAPIAN_PROGSRV XAPIAN_BIN_PATH "xapian-progsrv" EXE_SUFFIX
      41                 :            : 
      42                 :            : class BackendManager {
      43                 :            :     /// The current data directory
      44                 :            :     std::string datadir;
      45                 :            : 
      46                 :            :   protected:
      47                 :            :     /// Index data from zero or more text files into a database.
      48                 :            :     void index_files_to_database(Xapian::WritableDatabase & database,
      49                 :            :                                  const std::vector<std::string> & files);
      50                 :            : 
      51                 :            :     bool create_dir_if_needed(const std::string &dirname);
      52                 :            : 
      53                 :            :     /** Virtual method implementing get_database().
      54                 :            :      *
      55                 :            :      *  If we just called this get_database() then each subclass which
      56                 :            :      *  defined it would also need to un-hide the non-virtual overloaded method
      57                 :            :      *  with "using get_database(const std::string&);" or similar.
      58                 :            :      */
      59                 :            :     virtual Xapian::Database do_get_database(const std::vector<std::string> &files);
      60                 :            : 
      61                 :            :     /** Virtual method implementing get_database_path().
      62                 :            :      *
      63                 :            :      *  If we just called this get_database_path() then each subclass which
      64                 :            :      *  defined it would also need to un-hide the non-virtual overloaded method
      65                 :            :      *  with "using get_database_path(const std::string&);" or similar.
      66                 :            :      */
      67                 :            :     virtual std::string do_get_database_path(const std::vector<std::string> &files);
      68                 :            : 
      69                 :            :   public:
      70                 :            :     /// Constructor.
      71                 :            :     explicit
      72                 :         20 :     BackendManager(const std::string& datadir_)
      73                 :         20 :         : datadir(datadir_) {}
      74                 :            : 
      75                 :            :     /** We have virtual methods and want to be able to delete derived classes
      76                 :            :      *  using a pointer to the base class, so we need a virtual destructor.
      77                 :            :      */
      78                 :            :     virtual ~BackendManager();
      79                 :            : 
      80                 :            :     /** Get the database type currently in use.
      81                 :            :      */
      82                 :            :     virtual std::string get_dbtype() const;
      83                 :            : 
      84                 :            :     /** Get the directory to store data in.
      85                 :            :      */
      86                 :        860 :     const std::string & get_datadir() const { return datadir; }
      87                 :            : 
      88                 :            :     /// Get a database instance of the current type.
      89                 :            :     Xapian::Database get_database(const std::vector<std::string> &files);
      90                 :            : 
      91                 :            :     /// Get a database instance of the current type, single file case.
      92                 :            :     Xapian::Database get_database(const std::string &file);
      93                 :            : 
      94                 :            :     /** Get a database instance of the current type, generated case.
      95                 :            :      *
      96                 :            :      * @param dbname    The name of the database (base on your testcase name).
      97                 :            :      * @param gen       Generator function - should index data to the empty
      98                 :            :      *                  WritableDatabase provided.
      99                 :            :      * @param arg       String argument to pass to @a gen - it's up to you how
     100                 :            :      *                  to make use of this (or just ignore it if you don't need
     101                 :            :      *                  it).
     102                 :            :      */
     103                 :            :     Xapian::Database get_database(const std::string &dbname,
     104                 :            :                                   void (*gen)(Xapian::WritableDatabase&,
     105                 :            :                                               const std::string &),
     106                 :            :                                   const std::string &arg);
     107                 :            : 
     108                 :            :     /// Get a database instance by path
     109                 :            :     virtual Xapian::Database get_database_by_path(const std::string& path);
     110                 :            : 
     111                 :            :     /// Get the path of a database instance, if such a thing exists.
     112                 :            :     std::string get_database_path(const std::vector<std::string> &files);
     113                 :            : 
     114                 :            :     /// Get the path of a database instance, if such a thing exists (single file case).
     115                 :            :     std::string get_database_path(const std::string &file);
     116                 :            : 
     117                 :            :     /// Get the path of a generated database instance.
     118                 :            :     std::string get_database_path(const std::string &dbname,
     119                 :            :                                   void (*gen)(Xapian::WritableDatabase&,
     120                 :            :                                               const std::string &),
     121                 :            :                                   const std::string &arg);
     122                 :            : 
     123                 :            :     /// Get a writable database instance.
     124                 :            :     virtual Xapian::WritableDatabase get_writable_database(const std::string & name, const std::string & file);
     125                 :            : 
     126                 :            :     /// Get the path of a writable database instance, if such a thing exists.
     127                 :            :     virtual std::string get_writable_database_path(const std::string & name);
     128                 :            : 
     129                 :            :     /// Get a generated writable database instance
     130                 :            :     virtual Xapian::WritableDatabase
     131                 :            :     get_generated_database(const std::string& name);
     132                 :            : 
     133                 :            :     /// Get the path to use for generating a database, if supported.
     134                 :            :     virtual std::string get_generated_database_path(const std::string & name);
     135                 :            : 
     136                 :            :     /// Finalise the generated database
     137                 :            :     virtual void finalise_generated_database(const std::string& name);
     138                 :            : 
     139                 :            :     /// Get a remote database instance with the specified timeout.
     140                 :            :     virtual Xapian::Database get_remote_database(const std::vector<std::string> & files, unsigned int timeout);
     141                 :            : 
     142                 :            :     /// Create a Database object for the last opened WritableDatabase.
     143                 :            :     virtual Xapian::Database get_writable_database_as_database();
     144                 :            : 
     145                 :            :     /// Create a WritableDatabase object for the last opened WritableDatabase.
     146                 :            :     virtual Xapian::WritableDatabase get_writable_database_again();
     147                 :            : 
     148                 :            :     /// Get the path of the last opened WritableDatabase.
     149                 :            :     virtual std::string get_writable_database_path_again();
     150                 :            : 
     151                 :            :     /// Get a path to compact a database to.
     152                 :            :     virtual std::string get_compaction_output_path(const std::string& name);
     153                 :            : 
     154                 :            :     /** Called after each test, to perform any necessary cleanup.
     155                 :            :      *
     156                 :            :      *  May be called more than once for a given test in some cases.
     157                 :            :      */
     158                 :            :     virtual void clean_up();
     159                 :            : 
     160                 :            :     /// Get the command line required to run xapian-progsrv.
     161                 :            :     static const char * get_xapian_progsrv_command();
     162                 :            : };
     163                 :            : 
     164                 :            : #endif /* XAPIAN_INCLUDED_BACKENDMANAGER_H */

Generated by: LCOV version 1.11