60 lines
1.8 KiB
C++
60 lines
1.8 KiB
C++
#include "stdafx.h"
|
|
#include "CppUnitTest.h"
|
|
#include "SiaDriveConfig.h"
|
|
#include <Shlobj.h>
|
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
|
|
|
namespace UnitTests
|
|
{
|
|
TEST_CLASS(SiaDriveConfig)
|
|
{
|
|
private:
|
|
const wchar_t* TEST_CONFIG_FILE = L".\\test_config.json";
|
|
|
|
public:
|
|
TEST_METHOD(DefaultFileCreation)
|
|
{
|
|
DeleteFile(TEST_CONFIG_FILE);
|
|
Assert::IsFalse(PathFileExists(TEST_CONFIG_FILE) ? true : false);
|
|
|
|
Sia::Api::CSiaDriveConfig cfg(TEST_CONFIG_FILE);
|
|
Assert::AreEqual(static_cast<uint8_t>(0), cfg.GetUI_Main_TabIndex());
|
|
Assert::IsTrue(PathFileExists(TEST_CONFIG_FILE) ? true : false);
|
|
Assert::AreEqual(TEST_CONFIG_FILE, cfg.GetFilePath().c_str());
|
|
|
|
CFile f;
|
|
Assert::IsTrue(f.Open(cfg.GetFilePath().c_str(), CFile::modeRead) ? true : false);
|
|
|
|
std::string s;
|
|
s.resize(static_cast<std::size_t>(f.GetLength()));
|
|
|
|
f.Read(&s[0], s.length());
|
|
|
|
f.Close();
|
|
|
|
json j = json::parse(s.begin(), s.end());
|
|
Assert::AreEqual(static_cast<std::uint8_t>(0), j["UI_Main_TabIndex"].get <std::uint8_t>());
|
|
|
|
std::string tempFolder;
|
|
tempFolder.resize(MAX_PATH + 1);
|
|
::GetTempPathA(MAX_PATH, &tempFolder[0]);
|
|
Assert::AreEqual(tempFolder, j["TempFolder"].get <std::string>());
|
|
|
|
Assert::AreEqual(std::string("./Config/renter_upload.db3"), j["Renter_UploadDbFilePath"].get <std::string>());
|
|
|
|
PWSTR localAppData = nullptr;
|
|
SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, &localAppData);
|
|
|
|
Sia::Api::String sdFolder;
|
|
sdFolder.resize(MAX_PATH + 1);
|
|
::PathCombine(&sdFolder[0], localAppData, L"SiaDrive");
|
|
|
|
Sia::Api::String cacheFolder;
|
|
cacheFolder.resize(MAX_PATH + 1);
|
|
::PathCombine(&cacheFolder[0], &sdFolder[0], L"Cache");
|
|
Assert::AreEqual(std::string(CW2A(cacheFolder.c_str()).m_psz), j["CacheFolder"].get<std::string>());
|
|
|
|
DeleteFile(cfg.GetFilePath().c_str());
|
|
}
|
|
};
|
|
} |