[PVR][Estuary] Timer settings dialog: Show client name in timer type selection dialog...
[xbmc.git] / xbmc / test / TestBasicEnvironment.cpp
blob7a357765a0a397e6d30c78a71151a0bee196dda9
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "TestBasicEnvironment.h"
11 #include "FileItem.h"
12 #include "ServiceBroker.h"
13 #include "ServiceManager.h"
14 #include "TestUtils.h"
15 #include "application/AppEnvironment.h"
16 #include "application/AppParams.h"
17 #include "application/Application.h"
18 #include "filesystem/Directory.h"
19 #include "filesystem/File.h"
20 #include "filesystem/SpecialProtocol.h"
21 #include "messaging/ApplicationMessenger.h"
22 #include "platform/Filesystem.h"
23 #include "profiles/ProfileManager.h"
24 #include "settings/SettingsComponent.h"
25 #include "windowing/WinSystem.h"
27 #ifdef TARGET_DARWIN
28 #include "Util.h"
29 #endif
31 #include <cstdio>
32 #include <cstdlib>
33 #include <climits>
34 #include <system_error>
36 namespace fs = KODI::PLATFORM::FILESYSTEM;
38 TestBasicEnvironment::TestBasicEnvironment() = default;
40 void TestBasicEnvironment::SetUp()
42 const auto params = std::make_shared<CAppParams>();
43 params->SetPlatformDirectories(false);
45 CAppEnvironment::SetUp(params);
47 CServiceBroker::RegisterAppMessenger(std::make_shared<KODI::MESSAGING::CApplicationMessenger>());
49 XFILE::CFile *f;
51 g_application.m_ServiceManager.reset(new CServiceManager());
53 if (!CXBMCTestUtils::Instance().SetReferenceFileBasePath())
54 SetUpError();
55 CXBMCTestUtils::Instance().setTestFileFactoryWriteInputFile(
56 XBMC_REF_FILE_PATH("xbmc/filesystem/test/reffile.txt")
59 //for darwin set framework path - else we get assert
60 //in guisettings init below
61 #ifdef TARGET_DARWIN
62 std::string frameworksPath = CUtil::GetFrameworksPath();
63 CSpecialProtocol::SetXBMCFrameworksPath(frameworksPath);
64 #endif
65 /**
66 * @todo Something should be done about all the asserts in GUISettings so
67 * that the initialization of these components won't be needed.
70 /* Create a temporary directory and set it to be used throughout the
71 * test suite run.
74 std::error_code ec;
75 m_tempPath = fs::create_temp_directory(ec);
76 if (ec)
78 TearDown();
79 SetUpError();
82 CSpecialProtocol::SetTempPath(m_tempPath);
83 CSpecialProtocol::SetProfilePath(m_tempPath);
85 /* Create and delete a tempfile to initialize the VFS (really to initialize
86 * CLibcdio). This is done so that the initialization of the VFS does not
87 * affect the performance results of the test cases.
89 /** @todo Make the initialization of the VFS here optional so it can be
90 * testable in a test case.
92 f = XBMC_CREATETEMPFILE("");
93 if (!f || !XBMC_DELETETEMPFILE(f))
95 TearDown();
96 SetUpError();
99 const CProfile profile("special://temp");
100 CServiceBroker::GetSettingsComponent()->GetProfileManager()->AddProfile(profile);
101 CServiceBroker::GetSettingsComponent()->GetProfileManager()->CreateProfileFolders();
103 if (!g_application.m_ServiceManager->InitForTesting())
104 exit(1);
107 void TestBasicEnvironment::TearDown()
109 XFILE::CDirectory::RemoveRecursive(m_tempPath);
111 g_application.m_ServiceManager->DeinitTesting();
113 CServiceBroker::UnregisterAppMessenger();
115 CAppEnvironment::TearDown();
118 void TestBasicEnvironment::SetUpError()
120 fprintf(stderr, "Setup of basic environment failed.\n");
121 exit(EXIT_FAILURE);