kodi
TestUtils.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include <string>
12 #include <vector>
13 
14 namespace XFILE
15 {
16  class CFile;
17 }
18 
20 {
21 public:
22  static CXBMCTestUtils &Instance();
23 
24  /* ReferenceFilePath() is used to prepend a path with the location to the
25  * xbmc-test binary. It's assumed the test suite program will only be run
26  * with xbmc-test residing in the source tree.
27  */
28  std::string ReferenceFilePath(const std::string& path);
29 
30  /* Function to set the reference file base path. */
31  bool SetReferenceFileBasePath();
32 
33  /* Function used in creating a temporary file. It accepts a parameter
34  * 'suffix' to append to the end of the tempfile path. The temporary
35  * file is return as a XFILE::CFile object.
36  */
37  XFILE::CFile *CreateTempFile(std::string const& suffix);
38 
39  /* Function used to close and delete a temporary file previously created
40  * using CreateTempFile().
41  */
42  bool DeleteTempFile(XFILE::CFile *tempfile);
43 
44  /* Function to get path of a tempfile */
45  std::string TempFilePath(XFILE::CFile const* const tempfile);
46 
47  /* Get the containing directory of a tempfile */
48  std::string TempFileDirectory(XFILE::CFile const* const tempfile);
49 
50  /* Functions to get variables used in the TestFileFactory tests. */
51  std::vector<std::string> &getTestFileFactoryReadUrls();
52 
53  /* Function to get variables used in the TestFileFactory tests. */
54  std::vector<std::string> &getTestFileFactoryWriteUrls();
55 
56  /* Function to get the input file used in the TestFileFactory.Write tests. */
57  std::string &getTestFileFactoryWriteInputFile();
58 
59  /* Function to set the input file used in the TestFileFactory.Write tests */
60  void setTestFileFactoryWriteInputFile(std::string const& file);
61 
62  /* Function to get advanced settings files. */
63  std::vector<std::string> &getAdvancedSettingsFiles();
64 
65  /* Function to get GUI settings files. */
66  std::vector<std::string> &getGUISettingsFiles();
67 
68  /* Function used in creating a corrupted file. The parameters are a URL
69  * to the original file to be corrupted and a suffix to append to the
70  * path of the newly created file. This will return a XFILE::CFile
71  * object which is itself a tempfile object which can be used with the
72  * tempfile functions of this utility class.
73  */
74  XFILE::CFile *CreateCorruptedFile(std::string const& strFileName,
75  std::string const& suffix);
76 
77  /* Function to parse command line options */
78  void ParseArgs(int argc, char **argv);
79 
80  /* Function to return the newline characters for this platform */
81  std::string getNewLineCharacters() const;
82 private:
84  CXBMCTestUtils(CXBMCTestUtils const&) = delete;
85  CXBMCTestUtils& operator=(CXBMCTestUtils const&) = delete;
86 
87  std::vector<std::string> TestFileFactoryReadUrls;
88  std::vector<std::string> TestFileFactoryWriteUrls;
89  std::string TestFileFactoryWriteInputFile;
90 
91  std::vector<std::string> AdvancedSettingsFiles;
92  std::vector<std::string> GUISettingsFiles;
93 
94  double probability;
95 };
96 
97 #define XBMC_REF_FILE_PATH(s) CXBMCTestUtils::Instance().ReferenceFilePath(s)
98 #define XBMC_CREATETEMPFILE(a) CXBMCTestUtils::Instance().CreateTempFile(a)
99 #define XBMC_DELETETEMPFILE(a) CXBMCTestUtils::Instance().DeleteTempFile(a)
100 #define XBMC_TEMPFILEPATH(a) CXBMCTestUtils::Instance().TempFilePath(a)
101 #define XBMC_CREATECORRUPTEDFILE(a, b) \
102  CXBMCTestUtils::Instance().CreateCorruptedFile(a, b)
Definition: Scraper.h:41
Definition: File.h:37
Definition: SimpleFS.h:27
Definition: TestUtils.h:19