#include "stdafx.h" #include "SiaDriveConfig.h" #include using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace Sia::Api; 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(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(f.GetLength())); f.Read(&s[0], s.length()); f.Close(); json j = json::parse(s.begin(), s.end()); Assert::AreEqual(static_cast(0), j["UI_Main_TabIndex"].get ()); std::string tempFolder; tempFolder.resize(MAX_PATH + 1); ::GetTempPathA(MAX_PATH, &tempFolder[0]); Assert::AreEqual(tempFolder, j["TempFolder"].get ()); Assert::AreEqual(std::string("./Config/renter_upload.db3"), j["Renter_UploadDbFilePath"].get ()); 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()); DeleteFile(cfg.GetFilePath().c_str()); } }; }