Ninjaとの通信、XMLをパースするクラスの追加

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@834 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
N2614 2015-03-18 04:25:14 +00:00
parent 00f7e2105c
commit 8eb4e2e212
11 changed files with 911 additions and 0 deletions

View File

@ -0,0 +1,160 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: NinjaCommunicator.cpp
Copyright 2009-2011 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 "NinjaCommunicator.h"
#include "Util.h"
#include "CommonLogger.h"
#include <nn/ac.h>
#include <nn/http.h>
#include <nn/http/http_Connection.h>
#include <nn/ssl.h>
#include <nn/fnd.h>
namespace ConsoleRestore
{
namespace
{
static unsigned char s_Buffer[4096] NN_ATTRIBUTE_ALIGN(4096);
}
NinjaCommunicator::NinjaCommunicator()
{
}
NinjaCommunicator::~NinjaCommunicator()
{
// TODO Auto-generated destructor stub
}
nn::Result NinjaCommunicator::GetNsUid(const char* baseUrl, nn::ProgramId programId)
{
if(!nn::ac::IsConnected())
{
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(
common::InitializeNetwork());
}
std::string url(baseUrl);
GenerateUrlForNsUid(url, programId);
return HttpCommunicationCore(url);
}
nn::Result NinjaCommunicator::GetExternalKeyInfo(const char* baseUrl, const char* nsUid, const char* countryCode)
{
if(!nn::ac::IsConnected())
{
COMMON_LOGGER_RESULT_IF_FAILED(
common::InitializeNetwork());
}
std::string url(baseUrl);
GenerateUrlForGetExternalKeyInfo(url, nsUid, countryCode);
return HttpCommunicationCore(url);
}
nn::Result NinjaCommunicator::HttpCommunicationCore(std::string url)
{
/* ------------------------------------------------------------------------
(HTTPライブラリ使用前に)
------------------------------------------------------------------------ */
COMMON_LOGGER_RESULT_IF_FAILED(
nn::http::Initialize(reinterpret_cast<uptr>(s_Buffer), sizeof(s_Buffer)));
/* ------------------------------------------------------------------------
------------------------------------------------------------------------ */
//通信先の設定
//<<HTTPS特有コード>>URLの先頭文字はhttpsとなります
COMMON_LOGGER_RESULT_IF_FAILED(
m_HttpCon.Initialize(url.c_str()));
/* ------------------------------------------------------------------------
<<HTTPS特有コード>>SSL処理用設定
------------------------------------------------------------------------ */
//ルート証明書の設定
COMMON_LOGGER_RESULT_IF_FAILED(
m_HttpCon.SetRootCa(NNSSL_CACERT_PUBLIC_CA_1));
COMMON_LOGGER_RESULT_IF_FAILED(
m_HttpCon.SetRootCa(NNSSL_CACERT_PUBLIC_CA_2));
COMMON_LOGGER_RESULT_IF_FAILED(
m_HttpCon.SetRootCa(NNSSL_CACERT_PUBLIC_CA_3));
COMMON_LOGGER_RESULT_IF_FAILED(
m_HttpCon.SetRootCa(NNSSL_CACERT_PUBLIC_CA_4));
#ifndef USE_PROD_KEY
// 開発用サーバは自己署名証明書なので検証項目を減らす
COMMON_LOGGER_RESULT_IF_FAILED(
m_HttpCon.DisableVerifyOptionForDebug(
nn::ssl::VERIFY_COMMON_NAME | nn::ssl::VERIFY_SUBJECT_ALT_NAME | nn::ssl::VERIFY_ROOT_CA));
#endif
/* ------------------------------------------------------------------------
------------------------------------------------------------------------ */
//通信の開始
COMMON_LOGGER_RESULT_IF_FAILED(
m_HttpCon.Connect()); //リクエストの送信を開始する。機器が同時実行可能な最大個数のHTTP通信がすでに実行中の場合は、空きができるまでブロック
return nn::ResultSuccess();
}
void NinjaCommunicator::GenerateUrlForNsUid(std::string& url, nn::ProgramId programId)
{
url.append("titles/id_pair?title_id%5B%5D=");
char programIdStr[32];
std::snprintf(programIdStr, sizeof(programIdStr), "%016llX", programId);
url.append(programIdStr);
NN_LOG("URL=%s\n", url.c_str());
}
void NinjaCommunicator::GenerateUrlForGetExternalKeyInfo(std::string& url, const char* nsUid, const char* countryCode)
{
url.append(countryCode);
url.append("/title/");
url.append(nsUid);
url.append("/ec_info?countryCode=");
url.append(countryCode);
NN_LOG("URL=%s\n", url.c_str());
}
nn::Result NinjaCommunicator::GetBody(u8 *buf, size_t size)
{
//HTTPレスポンスの取得
nn::fnd::TimeSpan timeOut = nn::fnd::TimeSpan::FromSeconds(90);
std::memset(buf, 0, size);
//読み取りが完了するまでブロック。Bodyの最後までの読み込みが成功した場合は、Successを表すResultが返る。バッファサイズが足りない場合は、エラー(Description==ER_RES_BODYBUF_SHORTAGEのResult)が返る*/
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(
m_HttpCon.Read(buf, size, timeOut));
return nn::ResultSuccess();
}
nn::Result NinjaCommunicator::Finalize()
{
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(
m_HttpCon.Finalize());
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(
nn::http::Finalize());
return nn::ResultSuccess();
}
} /* namespace ConsoleRestore */

View File

@ -0,0 +1,55 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: NinjaCommunicator.h
Copyright 2009-2011 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$
*---------------------------------------------------------------------------*/
#ifndef BGSCOMMUNICATOR_H_
#define BGSCOMMUNICATOR_H_
#include <nn.h>
#include <nn/http.h>
#include <string>
namespace ConsoleRestore
{
class NinjaCommunicator
{
public:
NinjaCommunicator();
virtual ~NinjaCommunicator();
//! @Ninjaと通信してns_uidを取得します
//! @param[in] url 接続先URL
nn::Result GetNsUid(const char* baseUrl, nn::ProgramId programId);
//! @Ninjaと通信して外部鍵情報を取得します
nn::Result GetExternalKeyInfo(const char* baseUrl, const char* nsUid, const char* countryCode);
//! @brief 通信結果をバッファに書き込みます。
//! @param[out] buf 通信結果を書き込むバッファ
//! @param[in] size バッファサイズ
nn::Result GetBody(u8* buf, size_t size);
nn::Result Finalize();
private:
nn::Result HttpCommunicationCore(std::string url);
void GenerateUrlForNsUid(std::string& url, nn::ProgramId programId);
void GenerateUrlForGetExternalKeyInfo(std::string& url, const char* nsUid, const char* countryCode);
//Connectionインスタンス
nn::http::Connection m_HttpCon;
};
} /* namespace ConsoleRestore */
#endif /* BGSCOMMUNICATOR_H_ */

View File

@ -35,6 +35,10 @@ SOURCES[] =
PreinstallImporter.cpp
ActCompleter.cpp
AgeChecker.cpp
NinjaCommunicator.cpp
SimpleXmlPreprocessor.cpp
PreorderTitleRestorer.cpp
NinjaXmlReader.cpp
../common/Util.cpp
../common/DrawSystemState.cpp
../common/FileTransfer.cpp
@ -68,6 +72,8 @@ SHADER_PATH = $(ROMFS_ROOT)/$(SHADER_BIN)
ROMFS_DEPENDENCIES = $(SHADER_PATH)
EXCLUDE_LIBS += libnn_olv
LIBS += libnn_cfg \
libnn_crypto \
libnn_mcu \

View File

@ -0,0 +1,180 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: SimpleXmlPreprocessor.cpp
Copyright 2009-2011 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 "SimpleXmlPreprocessor.h"
#if defined(__ARMCC_VERSION)
#include <nn.h>
#else
#include "test_common.h"
#endif
namespace ConsoleRestore
{
bool SimpleXmlPreprocessor::Canonicalize(std::string& str)
{
if(!EraseXmlDeclaration(str))
{
NN_LOG("invalid xml!\n");
return false;
}
if(!EraseEmptyTag(str))
{
NN_LOG("can't erase empty tag");
return false;
}
if(!EraseAttribute(str))
{
NN_LOG("can't erase attribute\n");
return false;
}
if(!EraseNsTagEnd(str))
{
NN_LOG("can't erase ns end\n");
return false;
}
if(!EraseNsTagStart(str))
{
NN_LOG("can't erase ns start\n");
return false;
}
return true;
}
bool SimpleXmlPreprocessor::EraseXmlDeclaration(std::string& str)
{
std::string::size_type start = str.find("<?xml");
if (start == std::string::npos)
{
return false;
}
std::string::size_type end = str.find(">");
if (end == std::string::npos)
{
return false;
}
str.erase(start, end + 1 - start);
return true;
}
bool SimpleXmlPreprocessor::EraseEmptyTag(std::string& str)
{
// XMLとしては正しい前提
std::string::size_type end = str.find("/>");
if (end == std::string::npos)
{
return true;
}
std::string::size_type start = str.rfind("<", end);
if (start == std::string::npos)
{
return false;
}
str.erase(start, end + 2 - start);
return true;
}
bool SimpleXmlPreprocessor::EraseNsTagEnd(std::string& str)
{
std::string::size_type start = str.rfind("</");
while (start != std::string::npos)
{
std::string::size_type end = str.find(">", start);
if (end == std::string::npos)
{
// 不正なXML
return false;
}
std::string::size_type colon = str.substr(start, end - start).find(":");
if (colon == std::string::npos)
{
// 名前空間無し
start = str.rfind("</", start - 1);
continue;
}
str.erase(start + 2, colon - 1);
start = str.rfind("</", start - 1);
}
return true;
}
bool SimpleXmlPreprocessor::EraseNsTagStart(std::string& str)
{
std::string::size_type start = str.find("<");
while (start != std::string::npos)
{
std::string::size_type end = str.find(">", start);
if (end == std::string::npos)
{
// 不正なXML
return false;
}
std::string::size_type colon = str.substr(start, end - start).find(":");
if (colon == std::string::npos)
{
// 名前空間無し
start = str.find("<", end);
continue;
}
str.erase(start + 1, colon);
start = str.find("<", end - colon);
}
return true;
}
bool SimpleXmlPreprocessor::EraseAttribute(std::string& str)
{
std::string::size_type start = str.find("<");
while (start != std::string::npos)
{
std::string::size_type end = str.find(">", start);
if (end == std::string::npos)
{
// 不正なXML
return false;
}
std::string::size_type space = str.substr(start, end - start).find(" ");
if (space == std::string::npos)
{
// 属性なし
start = str.find("<", end);
continue;
}
str.erase(start + space, end - (start + space));
start = str.find("<", start + space);
}
return true;
}
} /* namespace ConsoleRestore */

View File

@ -0,0 +1,52 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: SimpleXmlPreprocessor.h
Copyright 2009-2011 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$
*---------------------------------------------------------------------------*/
#ifndef SIMPLEXMLPREPROCESSOR_H_
#define SIMPLEXMLPREPROCESSOR_H_
#include <string>
namespace ConsoleRestore
{
class SimpleXmlPreprocessor
{
public:
SimpleXmlPreprocessor() {};
~SimpleXmlPreprocessor() {};
// SimpleXmlParserで読めるように変換します
static bool Canonicalize(std::string& str);
private:
// <?xml*>の除去
static bool EraseXmlDeclaration(std::string& str);
// 空タグの除去
static bool EraseEmptyTag(std::string& str);
// 属性の削除
static bool EraseAttribute(std::string& str);
// 終了タグの名前空間の削除
static bool EraseNsTagEnd(std::string& str);
// 開始タグの名前空間の削除
static bool EraseNsTagStart(std::string& str);
};
} /* namespace ConsoleRestore */
#endif /* SIMPLEXMLPREPROCESSOR_H_ */

View File

@ -19,6 +19,7 @@ namespace common
{
nn::fnd::ThreadSafeExpHeap s_AppHeap;
nn::fnd::ThreadSafeExpHeap::Allocator s_Allocator(s_AppHeap);
HeapManager::HeapManager(size_t byteSize, s32 alignment, bit8 groupId, nn::fnd::ExpHeapBase::AllocationMode mode, bool reuse)
@ -61,4 +62,10 @@ void ForceFree(void* ptr)
}
}
// アロケータを渡す場合
nn::fnd::ThreadSafeExpHeap::Allocator* GetAllocator()
{
return &s_Allocator;
}
}

View File

@ -46,6 +46,9 @@ void* ForceAllocate(size_t byteSize, s32 alignment = nn::fnd::ExpHeapBase::DEFAU
// HeapManagerを使わず解放する場合のみ
void ForceFree(void* ptr);
// アロケータを渡す場合
nn::fnd::ThreadSafeExpHeap::Allocator* GetAllocator();
} // namespace common
#endif /* HEAPMANAGER_H_ */

View File

@ -0,0 +1,69 @@
#!/usr/bin/env omake
#----------------------------------------------------------------------------
# Project: Horizon
# File: OMakefile
#
# Copyright (C)2009 Nintendo Co., Ltd. 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$
#----------------------------------------------------------------------------
SUPPORTED_TARGETS = CTR-*.Process.MPCore.*
include $(makePlatformDefsPath tests)
SAMPLED_DEMOS_COMMON_INCLUDE_DIR = $(dir $(HORIZON_ROOT)/../CTR/SampleDemos/common/include)
INCLUDES += $(SAMPLED_DEMOS_COMMON_INCLUDE_DIR) \
../../../common \
../../../ConsoleRestore \
TEST_COMMON_SOURCES[] =
../../../ConsoleRestore/TitleDownloader.cpp
../../../ConsoleRestore/Shop.cpp
../../../ConsoleRestore/PreinstallImporter.cpp
../../../ConsoleRestore/NinjaCommunicator.cpp
../../../common/Util.cpp
../../../common/HeapManager.cpp
../../../common/SdLogger.cpp
../../../common/LogConsole.cpp
../../../common/CommonLogger.cpp
../../../common/SdMountManager.cpp
../../../common/VersionDetect.cpp
../../../common/HardwareStateManager.cpp
../../../common/FileTransfer.cpp
../../../common/SdReaderWriter.cpp
CCFLAGS += -DCOMMON_LOGGER_DETAIL_ENABLE
include $(ROOT)/common/BuildSwitch.om
SOURCES_TEST[] = test_NinjaCommunicator.cpp
ROMFS_ROOT = ../../../common/romfiles
TEST_ENVIRONMENT_PROCESSLIST = true
TEST_ENVIRONMENT_EMUMEM = true
LIBS += libnn_test \
libnn_mcu \
libnn_ps \
libnn_am \
lib_demo \
libnn_nim \
libnn_xml_simple \
ROM_SPEC_FILE = ../../../ConsoleRestore/ConsoleRestore.rsf
DESCRIPTOR = $(HORIZON_ROOT)/resources/specfiles/tools/RepairTool.desc
include $(makePlatformDefsPath build.tests)
tests: $(TEST_TARGETS)

View File

@ -0,0 +1,151 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: test_NinjaCommunicator.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_ApiInit.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 <nn/am.h>
#include "demo.h"
#include "common_Types.h"
#include "CommonLogger.h"
#include "HeapManager.h"
#include "NinjaCommunicator.h"
using namespace nn::test;
class TestNinjaCommunicator : public Suite {
public:
virtual bool InitializeSuite();
virtual void FinalizeSuite();
TestNinjaCommunicator() {
SUITE_NAME("Test");
TEST_ADD(TestNinjaCommunicator::GetNsUid);
TEST_ADD(TestNinjaCommunicator::GetExternalKeyInfo);
}
private:
void GetNsUid();
void GetExternalKeyInfo();
};
namespace
{
const size_t s_GxHeapSize = 0x800000;
}
//------------------------------------------------------------------
// Initialize/Finalize
//------------------------------------------------------------------
bool TestNinjaCommunicator::InitializeSuite()
{
// os の初期化
nn::fs::Initialize();
nn::cfg::CTR::init::Initialize();
nn::cfg::CTR::system::Initialize();
// amの初期化
nn::am::InitializeForLocalImporter();
// ヒープの確保
common::InitializeHeap();
common::HeapManager gxHeap(s_GxHeapSize);
// RenderSystem の準備
uptr heapForGx = reinterpret_cast<uptr>(gxHeap.GetAddr());
demo::RenderSystemDrawing renderSystem;
renderSystem.Initialize(heapForGx, s_GxHeapSize);
// ログ描画の初期化
common::Logger::GetLoggerInstance()->Initialize(common::CONSOLE_WIDTH, common::CONSOLE_HEIGHT,
common::CONSOLE_MAX_LINE, &renderSystem);
return true;
}
void TestNinjaCommunicator::FinalizeSuite()
{
}
//------------------------------------------------------------------
// Test Util
//------------------------------------------------------------------
//------------------------------------------------------------------
// Test Functions
//------------------------------------------------------------------
void TestNinjaCommunicator::GetNsUid()
{
NN_LOG("GetNsUid\n");
ConsoleRestore::NinjaCommunicator ninja;
NN_TEST_ASSERT(
ninja.GetNsUid("https://10.12.6.122/ninja/ws/", 0x000400000FECD000).IsSuccess());
size_t bufSize = 1024 * 1024; // 1MB
common::HeapManager heap(bufSize);
NN_TEST_ASSERT(
heap.GetAddr());
void* buf = heap.GetAddr();
NN_TEST_ASSERT(
ninja.GetBody(reinterpret_cast<u8*>(buf), bufSize).IsSuccess());
NN_LOG("%s\n", buf);
NN_TEST_ASSERT(
ninja.Finalize().IsSuccess());
}
void TestNinjaCommunicator::GetExternalKeyInfo()
{
NN_LOG("GetExternalKeyInfo\n");
ConsoleRestore::NinjaCommunicator ninja;
NN_TEST_ASSERT(
ninja.GetExternalKeyInfo("https://10.12.6.122/ninja/ws/", "50010000041101", "JP").IsSuccess());
size_t bufSize = 1024 * 1024; // 1MB
common::HeapManager heap(bufSize);
NN_TEST_ASSERT(
heap.GetAddr());
void* buf = heap.GetAddr();
NN_TEST_ASSERT(
ninja.GetBody(reinterpret_cast<u8*>(buf), bufSize).IsSuccess());
NN_LOG("%s\n", buf);
NN_TEST_ASSERT(
ninja.Finalize().IsSuccess());
}
NN_TEST_DEFINE_MAIN(TestNinjaCommunicator)
/*---------------------------------------------------------------------------*
End of file
*---------------------------------------------------------------------------*/

View File

@ -0,0 +1,71 @@
#!/usr/bin/env omake
#----------------------------------------------------------------------------
# Project: Horizon
# File: OMakefile
#
# Copyright (C)2009 Nintendo Co., Ltd. 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$
#----------------------------------------------------------------------------
SUPPORTED_TARGETS = CTR-*.Process.MPCore.*
include $(makePlatformDefsPath tests)
SAMPLED_DEMOS_COMMON_INCLUDE_DIR = $(dir $(HORIZON_ROOT)/../CTR/SampleDemos/common/include)
INCLUDES += $(SAMPLED_DEMOS_COMMON_INCLUDE_DIR) \
../../../common \
../../../ConsoleRestore \
TEST_COMMON_SOURCES[] =
../../../ConsoleRestore/TitleDownloader.cpp
../../../ConsoleRestore/Shop.cpp
../../../ConsoleRestore/PreinstallImporter.cpp
../../../ConsoleRestore/SimpleXmlPreprocessor.cpp
../../../ConsoleRestore/NinjaXmlReader.cpp
../../../common/Util.cpp
../../../common/HeapManager.cpp
../../../common/SdLogger.cpp
../../../common/LogConsole.cpp
../../../common/CommonLogger.cpp
../../../common/SdMountManager.cpp
../../../common/VersionDetect.cpp
../../../common/HardwareStateManager.cpp
../../../common/FileTransfer.cpp
../../../common/SdReaderWriter.cpp
CCFLAGS += -DCOMMON_LOGGER_DETAIL_ENABLE
include $(ROOT)/common/BuildSwitch.om
SOURCES_TEST[] = test_NinjaXmlReader.cpp
ROMFS_ROOT = ../../../common/romfiles
TEST_ENVIRONMENT_PROCESSLIST = true
TEST_ENVIRONMENT_EMUMEM = true
EXCLUDE_LIBS += libnn_olv
LIBS += libnn_test \
libnn_mcu \
libnn_ps \
libnn_am \
lib_demo \
libnn_xml_simple \
ROM_SPEC_FILE = ../../../ConsoleRestore/ConsoleRestore.rsf
DESCRIPTOR = $(HORIZON_ROOT)/resources/specfiles/tools/RepairTool.desc
include $(makePlatformDefsPath build.tests)
tests: $(TEST_TARGETS)

View File

@ -0,0 +1,157 @@
/*---------------------------------------------------------------------------*
Project: Horizon
File: test_NinjaCommunicator.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_ApiInit.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 <nn/am.h>
#include "demo.h"
#include "common_Types.h"
#include "CommonLogger.h"
#include "HeapManager.h"
#include "NinjaXmlReader.h"
using namespace nn::test;
class TestNinjaXmlReader : public Suite {
public:
virtual bool InitializeSuite();
virtual void FinalizeSuite();
TestNinjaXmlReader() {
SUITE_NAME("Test");
TEST_ADD(TestNinjaXmlReader::GetNsUid);
TEST_ADD(TestNinjaXmlReader::HasContentLock);
TEST_ADD(TestNinjaXmlReader::GetPlayableDate);
TEST_ADD(TestNinjaXmlReader::HasExternalSeed);
}
private:
void GetNsUid();
void HasContentLock();
void GetPlayableDate();
void HasExternalSeed();
};
namespace
{
const size_t s_GxHeapSize = 0x800000;
}
//------------------------------------------------------------------
// Initialize/Finalize
//------------------------------------------------------------------
bool TestNinjaXmlReader::InitializeSuite()
{
nn::fs::Initialize();
nn::cfg::CTR::init::Initialize();
nn::cfg::CTR::system::Initialize();
// ヒープの確保
common::InitializeHeap();
common::HeapManager gxHeap(s_GxHeapSize);
return true;
}
void TestNinjaXmlReader::FinalizeSuite()
{
}
//------------------------------------------------------------------
// Test Util
//------------------------------------------------------------------
//------------------------------------------------------------------
// Test Functions
//------------------------------------------------------------------
void TestNinjaXmlReader::GetNsUid()
{
char nsUid[32];
ConsoleRestore::NinjaXmlReader reader;
std::string xml("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><eshop><title_id_pairs><title_id_pair><ns_uid>50010000041101</ns_uid><title_id>000400000FECD000</title_id><type>T</type></title_id_pair></title_id_pairs></eshop>");
reader.GetNsUid(nsUid, sizeof(nsUid) / sizeof(nsUid[0]), xml);
NN_TEST_ASSERT(
!std::strcmp(nsUid, "50010000041101"));
NN_LOG("ns_uid = %s\n", nsUid);
}
void TestNinjaXmlReader::HasContentLock()
{
{
ConsoleRestore::NinjaXmlReader reader;
std::string xml("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><eshop><title_ec_info><title_id>000400000FECD000</title_id><content_size>400228</content_size><title_version>1024</title_version><disable_download>false</disable_download><pre_order>true</pre_order><content_lock><seed_published>false</seed_published><playable_date>2024-02-02</playable_date></content_lock></title_ec_info></eshop>");
NN_TEST_ASSERT(
reader.HasContentLock(xml));
}
{
ConsoleRestore::NinjaXmlReader reader;
std::string xml("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><eshop><title_ec_info><title_id>0004000001800A00</title_id><content_size>348980</content_size><title_version>0</title_version><disable_download>false</disable_download></title_ec_info></eshop>");
NN_TEST_ASSERT(
!reader.HasContentLock(xml));
}
}
void TestNinjaXmlReader::GetPlayableDate()
{
{
ConsoleRestore::NinjaXmlReader reader;
std::string xml("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><eshop><title_ec_info><title_id>000400000FECD000</title_id><content_size>400228</content_size><title_version>1024</title_version><disable_download>false</disable_download><pre_order>true</pre_order><content_lock><seed_published>false</seed_published><playable_date>2024-02-02</playable_date></content_lock></title_ec_info></eshop>");
nn::fnd::DateTime date = nn::fnd::DateTime::FromParameters(2024, 2, 2);
NN_TEST_ASSERT_EQUAL(date, reader.GetPlayableDate(xml));
}
{
ConsoleRestore::NinjaXmlReader reader;
std::string xml("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><eshop><title_ec_info><title_id>000400000FECD000</title_id><content_size>400228</content_size><title_version>1024</title_version><disable_download>false</disable_download><pre_order>true</pre_order><content_lock><seed_published>false</seed_published><playable_date>2015-12-31</playable_date></content_lock></title_ec_info></eshop>");
nn::fnd::DateTime date = nn::fnd::DateTime::FromParameters(2015, 12, 31);
NN_TEST_ASSERT_EQUAL(date, reader.GetPlayableDate(xml));
}
}
void TestNinjaXmlReader::HasExternalSeed()
{
{
ConsoleRestore::NinjaXmlReader reader;
std::string xml("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><eshop><title_ec_info><title_id>000400000FECAF00</title_id><content_size>350516</content_size><title_version>0</title_version><disable_download>false</disable_download><content_lock><seed_published>true</seed_published><external_seed>ab9d62312e43836bd73048c8b61e89e1</external_seed></content_lock></title_ec_info></eshop>");
NN_TEST_ASSERT(
reader.HasExternalSeed(xml));
}
{
ConsoleRestore::NinjaXmlReader reader;
std::string xml("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><eshop><title_ec_info><title_id>000400000FECD000</title_id><content_size>400228</content_size><title_version>1024</title_version><disable_download>false</disable_download><pre_order>true</pre_order><content_lock><seed_published>false</seed_published><playable_date>2015-12-31</playable_date></content_lock></title_ec_info></eshop>");
NN_TEST_ASSERT(
!reader.HasExternalSeed(xml));
}
}
NN_TEST_DEFINE_MAIN(TestNinjaXmlReader)
/*---------------------------------------------------------------------------*
End of file
*---------------------------------------------------------------------------*/