2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "TestBasicEnvironment.h"
22 #include "TestUtils.h"
23 #include "filesystem/Directory.h"
24 #include "filesystem/File.h"
25 #include "filesystem/SpecialProtocol.h"
26 #include "powermanagement/PowerManager.h"
27 #include "settings/AdvancedSettings.h"
28 #include "settings/Settings.h"
35 void TestBasicEnvironment::SetUp()
38 CStdString xbmcTempPath;
41 /* NOTE: The below is done to fix memleak warning about unitialized variable
42 * in xbmcutil::GlobalsSingleton<CAdvancedSettings>::getInstance().
44 g_advancedSettings.Initialize();
46 if (!CXBMCTestUtils::Instance().SetReferenceFileBasePath())
48 CXBMCTestUtils::Instance().setTestFileFactoryWriteInputFile(
49 XBMC_REF_FILE_PATH("xbmc/filesystem/test/reffile.txt")
52 //for darwin set framework path - else we get assert
53 //in guisettings init below
55 CStdString frameworksPath = CUtil::GetFrameworksPath();
56 CSpecialProtocol::SetXBMCFrameworksPath(frameworksPath);
58 /* TODO: Something should be done about all the asserts in GUISettings so
59 * that the initialization of these components won't be needed.
61 g_powerManager.Initialize();
62 CSettings::Get().Initialize();
64 /* Create a temporary directory and set it to be used throughout the
68 TCHAR lpTempPathBuffer[MAX_PATH];
69 if (!GetTempPath(MAX_PATH, lpTempPathBuffer))
71 xbmcTempPath = lpTempPathBuffer;
72 if (!GetTempFileName(xbmcTempPath.c_str(), "xbmctempdir", 0, lpTempPathBuffer))
74 DeleteFile(lpTempPathBuffer);
75 if (!CreateDirectory(lpTempPathBuffer, NULL))
77 CSpecialProtocol::SetTempPath(lpTempPathBuffer);
81 strcpy(buf, "/tmp/xbmctempdirXXXXXX");
82 if ((tmp = mkdtemp(buf)) == NULL)
84 CSpecialProtocol::SetTempPath(tmp);
87 /* Create and delete a tempfile to initialize the VFS (really to initialize
88 * CLibcdio). This is done so that the initialization of the VFS does not
89 * affect the performance results of the test cases.
91 /* TODO: Make the initialization of the VFS here optional so it can be
92 * testable in a test case.
94 f = XBMC_CREATETEMPFILE("");
95 if (!f || !XBMC_DELETETEMPFILE(f))
102 void TestBasicEnvironment::TearDown()
104 CStdString xbmcTempPath = CSpecialProtocol::TranslatePath("special://temp/");
105 XFILE::CDirectory::Remove(xbmcTempPath);
108 void TestBasicEnvironment::SetUpError()
110 fprintf(stderr, "Setup of basic environment failed.\n");