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.
9 #include "TestBasicEnvironment.h"
12 #include "FileItemList.h"
13 #include "ServiceBroker.h"
14 #include "ServiceManager.h"
15 #include "TestUtils.h"
16 #include "application/AppEnvironment.h"
17 #include "application/AppParams.h"
18 #include "application/Application.h"
19 #include "filesystem/Directory.h"
20 #include "filesystem/File.h"
21 #include "filesystem/SpecialProtocol.h"
22 #include "messaging/ApplicationMessenger.h"
23 #include "platform/Filesystem.h"
24 #include "profiles/ProfileManager.h"
25 #include "settings/SettingsComponent.h"
26 #include "windowing/WinSystem.h"
35 #include <system_error>
37 namespace fs
= KODI::PLATFORM::FILESYSTEM
;
39 TestBasicEnvironment::TestBasicEnvironment() = default;
41 void TestBasicEnvironment::SetUp()
43 const auto params
= std::make_shared
<CAppParams
>();
44 params
->SetPlatformDirectories(false);
46 CAppEnvironment::SetUp(params
);
48 CServiceBroker::RegisterAppMessenger(std::make_shared
<KODI::MESSAGING::CApplicationMessenger
>());
52 g_application
.m_ServiceManager
.reset(new CServiceManager());
54 if (!CXBMCTestUtils::Instance().SetReferenceFileBasePath())
56 CXBMCTestUtils::Instance().setTestFileFactoryWriteInputFile(
57 XBMC_REF_FILE_PATH("xbmc/filesystem/test/reffile.txt")
60 //for darwin set framework path - else we get assert
61 //in guisettings init below
63 std::string frameworksPath
= CUtil::GetFrameworksPath();
64 CSpecialProtocol::SetXBMCFrameworksPath(frameworksPath
);
67 * @todo Something should be done about all the asserts in GUISettings so
68 * that the initialization of these components won't be needed.
71 /* Create a temporary directory and set it to be used throughout the
76 m_tempPath
= fs::create_temp_directory(ec
);
83 CSpecialProtocol::SetTempPath(m_tempPath
);
84 CSpecialProtocol::SetProfilePath(m_tempPath
);
86 /* Create and delete a tempfile to initialize the VFS (really to initialize
87 * CLibcdio). This is done so that the initialization of the VFS does not
88 * affect the performance results of the test cases.
90 /** @todo Make the initialization of the VFS here optional so it can be
91 * testable in a test case.
93 f
= XBMC_CREATETEMPFILE("");
94 if (!f
|| !XBMC_DELETETEMPFILE(f
))
100 const CProfile
profile("special://temp");
101 CServiceBroker::GetSettingsComponent()->GetProfileManager()->AddProfile(profile
);
102 CServiceBroker::GetSettingsComponent()->GetProfileManager()->CreateProfileFolders();
104 if (!g_application
.m_ServiceManager
->InitForTesting())
108 void TestBasicEnvironment::TearDown()
110 XFILE::CDirectory::RemoveRecursive(m_tempPath
);
112 g_application
.m_ServiceManager
->DeinitTesting();
114 CServiceBroker::UnregisterAppMessenger();
116 CAppEnvironment::TearDown();
119 void TestBasicEnvironment::SetUpError()
121 fprintf(stderr
, "Setup of basic environment failed.\n");