mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@313 385bec56-5757-e545-9c3a-d8741f4650f1
175 lines
5.0 KiB
C++
175 lines
5.0 KiB
C++
/*---------------------------------------------------------------------------*
|
|
Project: Horizon
|
|
File: test_Util.cpp
|
|
|
|
Copyright 2009 Nintendo. All rights reserved.
|
|
|
|
These coded instructions, statements, and computer programs contain
|
|
proprietary information of Nintendo of America Inc. and/or Nintendo
|
|
Company Ltd., and are protected by Federal copyright law. They may
|
|
not be disclosed to third parties or copied or duplicated in any form,
|
|
in whole or in part, without the prior written consent of Nintendo.
|
|
|
|
$Rev$
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
#include <nn.h>
|
|
#include <nn/test/test_Test.h>
|
|
#include <nn/cfg/CTR/cfg_ApiSys.h>
|
|
#include <nn/fs.h>
|
|
#include <nn/fs/CTR/fs_ArchiveTypesForSystem.h>
|
|
#include <nn/fs/CTR/MPCore/fs_FileSystemBasePrivate.h>
|
|
#include <nn/fs/fs_ApiSysSaveData.h>
|
|
|
|
#include "Util.h"
|
|
|
|
using namespace nn::test;
|
|
|
|
class UtilTest : public Suite {
|
|
public:
|
|
virtual bool InitializeSuite();
|
|
virtual void FinalizeSuite();
|
|
|
|
UtilTest() {
|
|
SUITE_NAME("TestUtil");
|
|
TEST_ADD(UtilTest::AddCheckDigit);
|
|
TEST_ADD(UtilTest::GetSaveDataDirectoryRoot);
|
|
}
|
|
private:
|
|
void AddCheckDigit();
|
|
void GetSaveDataDirectoryRoot();
|
|
};
|
|
|
|
//------------------------------------------------------------------
|
|
// Initialize/Finalize
|
|
//------------------------------------------------------------------
|
|
|
|
bool UtilTest::InitializeSuite()
|
|
{
|
|
nn::fs::Initialize();
|
|
|
|
return true;
|
|
}
|
|
|
|
void UtilTest::FinalizeSuite()
|
|
{
|
|
}
|
|
|
|
//------------------------------------------------------------------
|
|
// Test Util
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
// Test Functions
|
|
//------------------------------------------------------------------
|
|
|
|
void UtilTest::AddCheckDigit()
|
|
{
|
|
|
|
// 通常チェックデジット
|
|
{
|
|
const char serialBase[] = "EJF10000445";
|
|
const char serialWithCheckDigit[] = "EJF100004458";
|
|
char serial[nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN];
|
|
std::memcpy(serial, serialBase, sizeof(serialBase));
|
|
common::Util::AddCheckDigit(serial);
|
|
|
|
NN_TEST_ASSERT_EQUAL(std::strcmp(serial, serialWithCheckDigit), 0);
|
|
}
|
|
|
|
// チェックデジットが0になる場合
|
|
{
|
|
const char serialBase[] = "CJF10004638";
|
|
const char serialWithCheckDigit[] = "CJF100046380";
|
|
char serial[nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN];
|
|
std::memcpy(serial, serialBase, sizeof(serialBase));
|
|
common::Util::AddCheckDigit(serial);
|
|
|
|
NN_TEST_ASSERT_EQUAL(std::strcmp(serial, serialWithCheckDigit), 0);
|
|
}
|
|
}
|
|
|
|
void UtilTest::GetSaveDataDirectoryRoot()
|
|
{
|
|
bit8 ivs[512];
|
|
s64 ivsSize;
|
|
// 完全性検証SEEDの取得
|
|
nn::Result result = nn::fs::MountSpecialArchive("nand:", nn::fs::CTR::ARCHIVE_TYPE_CTR_NAND);
|
|
if (result.IsSuccess())
|
|
{
|
|
nn::fs::FileInputStream fis;
|
|
|
|
result = fis.TryInitialize(L"nand:/private/movable.sed");
|
|
if (result.IsSuccess())
|
|
{
|
|
ivsSize = fis.GetSize();
|
|
s32 readSize;
|
|
result = fis.TryRead(&readSize, ivs, ivsSize);
|
|
if (result.IsFailure())
|
|
{
|
|
NN_DBG_PRINT_RESULT(result);
|
|
NN_TEST_FAIL("Can't Read IVS");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
NN_TEST_FAIL("Can't Initialize File");
|
|
}
|
|
fis.Finalize();
|
|
}
|
|
else
|
|
{
|
|
NN_TEST_FAIL("Can't Mount nand:");
|
|
}
|
|
|
|
wchar_t saveDataRootWStr[nn::fs::MAX_FILE_PATH_LENGTH];
|
|
nn::fs::Directory dir;
|
|
result = dir.TryInitialize("nand:/data/");
|
|
if(result.IsSuccess())
|
|
{
|
|
nn::fs::DirectoryEntry entry;
|
|
s32 num;
|
|
result = dir.TryRead(&num, &entry, 1);
|
|
if(result.IsSuccess())
|
|
{
|
|
if(num == 1)
|
|
{
|
|
std::memset(saveDataRootWStr, 0, sizeof(saveDataRootWStr));
|
|
std::wcscpy(saveDataRootWStr, entry.entryName);
|
|
}
|
|
else
|
|
{
|
|
NN_TEST_FAIL("Unknown Directory exists");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
NN_TEST_FAIL("Can't Read nand:/data/");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
NN_TEST_FAIL("Can't Initialize nand:/data/");
|
|
}
|
|
|
|
// 一旦アンマウントしておく
|
|
nn::fs::Unmount("nand:");
|
|
|
|
std::wstring tmp(saveDataRootWStr);
|
|
char saveDataRootStr[nn::fs::MAX_FILE_PATH_LENGTH];
|
|
std::wcstombs(saveDataRootStr, tmp.c_str(), tmp.size());
|
|
|
|
std::string sysSaveRoot;
|
|
common::Util::GetSaveDataDirectoryRoot(sysSaveRoot, &ivs, ivsSize);
|
|
|
|
NN_TEST_ASSERT_EQUAL(std::strcmp(sysSaveRoot.c_str(), saveDataRootStr), 0);
|
|
}
|
|
|
|
|
|
NN_TEST_DEFINE_MAIN(UtilTest)
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
End of file
|
|
*---------------------------------------------------------------------------*/
|