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 "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"
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
>());
51 g_application
.m_ServiceManager
.reset(new CServiceManager());
53 if (!CXBMCTestUtils::Instance().SetReferenceFileBasePath())
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
62 std::string frameworksPath
= CUtil::GetFrameworksPath();
63 CSpecialProtocol::SetXBMCFrameworksPath(frameworksPath
);
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
75 m_tempPath
= fs::create_temp_directory(ec
);
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
))
99 const CProfile
profile("special://temp");
100 CServiceBroker::GetSettingsComponent()->GetProfileManager()->AddProfile(profile
);
101 CServiceBroker::GetSettingsComponent()->GetProfileManager()->CreateProfileFolders();
103 if (!g_application
.m_ServiceManager
->InitForTesting())
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");