From 7721b7453349a071720adeb51ef0e322c8bf2550 Mon Sep 17 00:00:00 2001 From: N2614 Date: Thu, 19 Jan 2012 05:46:36 +0000 Subject: [PATCH] =?UTF-8?q?http=E3=82=B3=E3=83=8D=E3=82=AF=E3=82=B7?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E3=82=92=E3=83=A1=E3=83=B3=E3=83=90=E5=A4=89?= =?UTF-8?q?=E6=95=B0=E3=81=A7=E6=8C=81=E3=81=A4=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=20SimpleXmlParser=E3=80=81BgsCommunicator=E3=81=AE=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@575 385bec56-5757-e545-9c3a-d8741f4650f1 --- .../ConsoleRestore/BgsCommunicator.cpp | 116 ++++++------ .../sources/ConsoleRestore/BgsCommunicator.h | 18 +- .../ConsoleRestore/BgsCommunicator/OMakefile | 71 ++++++++ .../BgsCommunicator/test_BgsCommunicator.cpp | 171 ++++++++++++++++++ .../sources/tests/ConsoleRestore/OMakefile | 2 +- .../ConsoleRestore/SimpleXmlParser/OMakefile | 48 +++++ .../SimpleXmlParser/test_SimpleXmlParser.cpp | 165 +++++++++++++++++ 7 files changed, 527 insertions(+), 64 deletions(-) create mode 100644 trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/BgsCommunicator/OMakefile create mode 100644 trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/BgsCommunicator/test_BgsCommunicator.cpp create mode 100644 trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/SimpleXmlParser/OMakefile create mode 100644 trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/SimpleXmlParser/test_SimpleXmlParser.cpp diff --git a/trunk/ConsoleDataMigration/sources/ConsoleRestore/BgsCommunicator.cpp b/trunk/ConsoleDataMigration/sources/ConsoleRestore/BgsCommunicator.cpp index ce6db31..d7eecff 100644 --- a/trunk/ConsoleDataMigration/sources/ConsoleRestore/BgsCommunicator.cpp +++ b/trunk/ConsoleDataMigration/sources/ConsoleRestore/BgsCommunicator.cpp @@ -187,7 +187,7 @@ u8 USER_ORIGIN_PRIVATE_KEY[] = } -BgsCommunicator::BgsCommunicator() +BgsCommunicator::BgsCommunicator() : m_Result(nn::ResultSuccess()) { // TODO 自動生成されたコンストラクター・スタブ } @@ -199,122 +199,116 @@ BgsCommunicator::~BgsCommunicator() bool BgsCommunicator::Execute(const void* buf, size_t size) { - nn::Result result; - - result = common::InitializeNetwork(); - COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); + m_Result = common::InitializeNetwork(); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result); /* ------------------------------------------------------------------------ ライブラリの初期化(HTTPライブラリ使用前に、各プロセスで一度だけ実行する。) ------------------------------------------------------------------------ */ - result = nn::http::Initialize(reinterpret_cast(s_PostBuffer), sizeof(s_PostBuffer)); - COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); + m_Result = nn::http::Initialize(reinterpret_cast(s_PostBuffer), sizeof(s_PostBuffer)); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result); /* ------------------------------------------------------------------------ 通信準備 ------------------------------------------------------------------------ */ - //Connectionインスタンスの生成 - nn::http::Connection httpCon; //通信先の設定 //<>URLの先頭文字はhttpsとなります - result = httpCon.Initialize("https://10.12.3.73/bgs/services/BusinessGatewaySOAP", nn::http::REQUEST_METHOD_POST); - COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); + m_Result = m_HttpCon.Initialize("https://10.12.3.73/bgs/services/BusinessGatewaySOAP", nn::http::REQUEST_METHOD_POST); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result); - result = httpCon.AddHeaderField("Accept-Encoding", "identity"); - COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); + m_Result = m_HttpCon.AddHeaderField("Accept-Encoding", "identity"); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result); - result = httpCon.AddHeaderField("SOAPAction", "urn:bgs.wsapi.broadon.com/GetPreInstalledInfo"); - COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); + m_Result = m_HttpCon.AddHeaderField("SOAPAction", "urn:bgs.wsapi.broadon.com/GetPreInstalledInfo"); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result); - result = httpCon.AddHeaderField("Content-Type", "text/xml; charset=utf-8"); - COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); + m_Result = m_HttpCon.AddHeaderField("Content-Type", "text/xml; charset=utf-8"); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result); // POSTデータの設定 - result = httpCon.AddPostDataRaw(buf, size); - COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); + m_Result = m_HttpCon.AddPostDataRaw(buf, size); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result); /* ------------------------------------------------------------------------ <>SSL処理用設定 ------------------------------------------------------------------------ */ //ルート証明書の設定 - COMMON_LOGGER_RETURN_FALSE_IF_FAILED( httpCon.SetRootCa( NNSSL_CACERT_PUBLIC_CA_1 )); - COMMON_LOGGER_RETURN_FALSE_IF_FAILED( httpCon.SetRootCa( NNSSL_CACERT_PUBLIC_CA_2 )); - COMMON_LOGGER_RETURN_FALSE_IF_FAILED( httpCon.SetRootCa( NNSSL_CACERT_PUBLIC_CA_3 )); - COMMON_LOGGER_RETURN_FALSE_IF_FAILED( httpCon.SetRootCa( NNSSL_CACERT_PUBLIC_CA_4 )); - COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED( m_HttpCon.SetRootCa( NNSSL_CACERT_PUBLIC_CA_1 )); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED( m_HttpCon.SetRootCa( NNSSL_CACERT_PUBLIC_CA_2 )); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED( m_HttpCon.SetRootCa( NNSSL_CACERT_PUBLIC_CA_3 )); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED( m_HttpCon.SetRootCa( NNSSL_CACERT_PUBLIC_CA_4 )); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result); s32 sslError; - httpCon.GetSslError(&sslError); + m_HttpCon.GetSslError(&sslError); NN_LOG("sslerror = %x\n", sslError); - result = httpCon.SetClientCert(USER_ORIGIN_CLIENT_CERT_DATA, sizeof(USER_ORIGIN_CLIENT_CERT_DATA), + m_Result = m_HttpCon.SetClientCert(USER_ORIGIN_CLIENT_CERT_DATA, sizeof(USER_ORIGIN_CLIENT_CERT_DATA), USER_ORIGIN_PRIVATE_KEY, sizeof(USER_ORIGIN_PRIVATE_KEY)); //クライアント証明書を設定する。 - COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result); // 証明書が適当?なので検証項目を減らす - result = httpCon.DisableVerifyOptionForDebug( + m_Result = m_HttpCon.DisableVerifyOptionForDebug( nn::ssl::VERIFY_COMMON_NAME | nn::ssl::VERIFY_SUBJECT_ALT_NAME | nn::ssl::VERIFY_ROOT_CA); - COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result); /* ------------------------------------------------------------------------ 通信実行 ------------------------------------------------------------------------ */ //通信の開始 - result = httpCon.Connect(); //リクエストの送信を開始する。機器が同時実行可能な最大個数のHTTP通信がすでに実行中の場合は、空きができるまでブロック - COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); + m_Result = m_HttpCon.Connect(); //リクエストの送信を開始する。機器が同時実行可能な最大個数のHTTP通信がすでに実行中の場合は、空きができるまでブロック + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result); - httpCon.GetSslError(&sslError); + nn::http::ResultCode resultCode; + m_Result = m_HttpCon.GetError(&resultCode); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result); + NN_LOG("resultCode = %x\n", resultCode); + + m_Result = m_HttpCon.GetSslError(&sslError); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result); NN_LOG("sslerror = %x\n", sslError); - //HTTPレスポンスの取得 - u8 bodyBuf[4096]; - memset(bodyBuf, 0, sizeof(bodyBuf)); - result = httpCon.Read(bodyBuf, sizeof(bodyBuf)); //読み取りが完了するまでブロック。Bodyの最後までの読み込みが成功した場合は、Successを表すResultが返る。バッファサイズが足りない場合は、エラー(Description==ER_RES_BODYBUF_SHORTAGEのResult)が返る*/ - COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); - httpCon.GetSslError(&sslError); - NN_LOG("sslerror = %x\n", sslError); - - //必要に応じて、通信エラーを確認 - //nn::http::ResultCode resultCode; - //result = httpCon.GetError(&resultCode); - - //<>必要に応じて、SSL通信エラーを確認 - //nn::ssl::ResultCode sslResultCode; - //result = httpCon.GetSslError(&sslResultCode); + return true; +} +size_t BgsCommunicator::GetBodySize() +{ /* ------------------------------------------------------------------------ HTTPレスポンスに対するアプリ側の処理。(この部分はアプリ毎に任意の処理を行う。本デモでは例として、メッセージヘッダの一部とメッセージボディ全体をダンプする処理を実装する。) ------------------------------------------------------------------------ */ //HTTPヘッダの情報読み出し s32 statusCode = 0; - result = httpCon.GetStatusCode(&statusCode); //Statusコードの取得 - COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); + m_Result = m_HttpCon.GetStatusCode(&statusCode); //Statusコードの取得 + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result); NN_LOG("---HTTP ResultCode = %d---\n", statusCode); char headerFields[1024]; memset(headerFields, 0, sizeof(headerFields)); u32 fieldLen = sizeof(headerFields); - result = httpCon.GetHeaderField("Content-Length", headerFields, fieldLen, &fieldLen); //特定のヘッダフィールドをラベルから取得 - //result = httpCon.GetHeaderAll(headerFields, fieldLen, &fieldLen);//全ヘッダフィールドを一括取得 - COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); - u32 contentLength = std::atoi(headerFields); - NN_LOG("---HTTP Content-Length = %d---\n", contentLength); + m_Result = m_HttpCon.GetHeaderField("Content-Length", headerFields, fieldLen, &fieldLen); //特定のヘッダフィールドをラベルから取得 + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result); + m_BodySize = std::strtol(headerFields, NULL, 10); + NN_LOG("---HTTP Content-Length = %d---\n", m_BodySize); - result = common::FinalizeNetwork(); - COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); - return false; + return m_BodySize; } -size_t BgsCommunicator::GetBodySize() +bool BgsCommunicator::GetBody(u8 *buf, size_t size) { - return 0; + //HTTPレスポンスの取得 + memset(buf, 0, size); + m_Result = m_HttpCon.Read(buf, size); //読み取りが完了するまでブロック。Bodyの最後までの読み込みが成功した場合は、Successを表すResultが返る。バッファサイズが足りない場合は、エラー(Description==ER_RES_BODYBUF_SHORTAGEのResult)が返る*/ + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result); + return true; } -void BgsCommunicator::GetBody(void *buf) +bool BgsCommunicator::Finalize() { - NN_UNUSED_VAR(buf); + m_Result = common::FinalizeNetwork(); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(m_Result); + return true; } } /* namespace ConsoleRestore */ diff --git a/trunk/ConsoleDataMigration/sources/ConsoleRestore/BgsCommunicator.h b/trunk/ConsoleDataMigration/sources/ConsoleRestore/BgsCommunicator.h index a53bd77..40bcc9d 100644 --- a/trunk/ConsoleDataMigration/sources/ConsoleRestore/BgsCommunicator.h +++ b/trunk/ConsoleDataMigration/sources/ConsoleRestore/BgsCommunicator.h @@ -17,6 +17,7 @@ #define BGSCOMMUNICATOR_H_ #include +#include namespace ConsoleRestore { @@ -34,10 +35,23 @@ public: //! @brief 通信結果のサイズを取得します size_t GetBodySize(); - //! @brief 通信結果を取得します + //! @brief 通信結果をバッファに書き込みます。正しく結果を取得するには GetBodySizeで取得したサイズのバッファが必要です。 //! @param[out] buf 通信結果を書き込むバッファ - void GetBody(void* buf); + //! @param[in] size バッファサイズ + bool GetBody(u8* buf, size_t size); + bool Finalize(); + + nn::Result GetLastResult(); + +private: + nn::Result m_Result; + + //! @brief HTTPレスポンスのサイズ + size_t m_BodySize; + + //Connectionインスタンス + nn::http::Connection m_HttpCon; }; } /* namespace ConsoleRestore */ diff --git a/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/BgsCommunicator/OMakefile b/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/BgsCommunicator/OMakefile new file mode 100644 index 0000000..1f5a065 --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/BgsCommunicator/OMakefile @@ -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/Shop.cpp + ../../../ConsoleRestore/XmlCreator.cpp + ../../../ConsoleRestore/SimpleXmlPreprocessor.cpp + ../../../ConsoleRestore/BgsCommunicator.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 + +SOURCES_TEST[] = test_BgsCommunicator.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/private/RepairTool.desc + + +DEPEND_PROCESSES[] = + test_BgsCommunicator>$(GetProcessCdiPathList http) + + +include $(makePlatformDefsPath build.tests) + + +tests: $(TEST_TARGETS) diff --git a/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/BgsCommunicator/test_BgsCommunicator.cpp b/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/BgsCommunicator/test_BgsCommunicator.cpp new file mode 100644 index 0000000..77463c3 --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/BgsCommunicator/test_BgsCommunicator.cpp @@ -0,0 +1,171 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: test_BgsCommunicator.cpp + + Copyright (C)2012 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$ + *---------------------------------------------------------------------------*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "demo.h" + +#include "common_Types.h" +#include "CommonLogger.h" +#include "HeapManager.h" +#include "XmlCreator.h" +#include "BgsCommunicator.h" +#include "SimpleXmlPreprocessor.h" + +using namespace nn::test; + +class BgsCommunicatorTest : public Suite { +public: + virtual bool InitializeSuite(); + virtual void FinalizeSuite(); + + BgsCommunicatorTest() { + TEST_ADD(BgsCommunicatorTest::Exec); + } +private: + void Exec(); +}; + +namespace +{ +void PutString(std::string str) +{ + if (str.size() > 254) + { + for (size_t pos = 0; pos < str.size(); pos += 254) + { + NN_LOG("%s", str.substr(pos, nn::math::Min(static_cast(254), str.size() - pos)).c_str()); + } + } + else + { + NN_LOG("%s\n", str.c_str()); + } +} + +#if 0 +void DumpHttpBody(u8* pBodyBuf, size_t contentLength) +{ +#ifndef NN_SWITCH_DISABLE_DEBUG_PRINT + NN_LOG("---HTTP Body Dump(Content-Length=%d)---\n", contentLength); + int hexCheckCount = 0; + for (int i = 0; i < contentLength; ++i) + { + NN_LOG("%02x ", pBodyBuf[i]); + ++hexCheckCount; + if (hexCheckCount == 16) + { + NN_LOG("\n"); + hexCheckCount = 0; + } + } + + NN_LOG("\n---HTTP Body Dump END---------------------------------\n"); +#else + NN_UNUSED_VAR(pBodyBuf); + NN_UNUSED_VAR(contentLength); + NN_UNUSED_VAR(statusCode); +#endif +} +#endif + +const size_t s_GxHeapSize = 0x800000; + +} + +//------------------------------------------------------------------ +// Initialize/Finalize +//------------------------------------------------------------------ + +bool BgsCommunicatorTest::InitializeSuite() +{ + // os の初期化 + nn::os::Initialize(); + + nn::fs::Initialize(); + + // amの初期化 + nn::am::InitializeForLocalImporter(); + + // cfgの初期化 + nn::cfg::init::Initialize(); + nn::cfg::system::Initialize(); + + // ヒープの確保 + common::InitializeHeap(); + common::HeapManager gxHeap(s_GxHeapSize); + + // RenderSystem の準備 + uptr heapForGx = reinterpret_cast(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 BgsCommunicatorTest::FinalizeSuite() +{ +} + +//------------------------------------------------------------------ +// Test Util +//------------------------------------------------------------------ + + +//------------------------------------------------------------------ +// Test Functions +//------------------------------------------------------------------ + +void BgsCommunicatorTest::Exec() +{ + NN_LOG("BgsCommunicator Exec\n"); + ConsoleRestore::BgsCommunicator comm; + + ConsoleRestore::XmlCreator xml; + xml.Exec(17179924184, reinterpret_cast(const_cast("EJA20305940"))); + + comm.Execute(xml.GetData().c_str(), xml.GetData().size()); + size_t bufSize = comm.GetBodySize(); + common::HeapManager heap(bufSize); + void* buf = heap.GetAddr(); + comm.GetBody(reinterpret_cast(buf), bufSize); + comm.Finalize(); + + // simpleXMLに変換します + ConsoleRestore::SimpleXmlPreprocessor pp; + std::string xmlData(reinterpret_cast(buf)); + pp.Canonicalize(xmlData); + + PutString(xmlData); +} + +NN_TEST_DEFINE_MAIN(BgsCommunicatorTest) + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/OMakefile b/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/OMakefile index c0ed910..bc75c14 100644 --- a/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/OMakefile +++ b/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/OMakefile @@ -15,6 +15,6 @@ #---------------------------------------------------------------------------- if $(IsTestBuild) - .SUBDIRS: TitleDownloader BgsCommunicator + .SUBDIRS: $(glob D, *) DefineDefaultRules() diff --git a/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/SimpleXmlParser/OMakefile b/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/SimpleXmlParser/OMakefile new file mode 100644 index 0000000..b91f912 --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/SimpleXmlParser/OMakefile @@ -0,0 +1,48 @@ +#!/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/SimpleXmlPreprocessor.cpp + +CCFLAGS += -DCOMMON_LOGGER_DETAIL_ENABLE + +SOURCES_TEST[] = test_SimpleXmlParser.cpp + +ROMFS_ROOT = ../../../common/romfiles + +TEST_ENVIRONMENT_PROCESSLIST = true +TEST_ENVIRONMENT_EMUMEM = true + +LIBS += libnn_test \ + libnn_xml_simple \ + +ROM_SPEC_FILE = ../../../ConsoleRestore/ConsoleRestore.rsf +DESCRIPTOR = $(HORIZON_ROOT)/resources/specfiles/private/RepairTool.desc + +include $(makePlatformDefsPath build.tests) + + +tests: $(TEST_TARGETS) diff --git a/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/SimpleXmlParser/test_SimpleXmlParser.cpp b/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/SimpleXmlParser/test_SimpleXmlParser.cpp new file mode 100644 index 0000000..4c3d146 --- /dev/null +++ b/trunk/ConsoleDataMigration/sources/tests/ConsoleRestore/SimpleXmlParser/test_SimpleXmlParser.cpp @@ -0,0 +1,165 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: test_SimpleXmlParser.cpp + + Copyright (C)2011 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$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "demo.h" + +#include "common_Types.h" +#include "CommonLogger.h" +#include "HeapManager.h" +#include "XmlCreator.h" +#include "SimpleXmlPreprocessor.h" + +using namespace nn::test; + +class SimpleXmlParserTest : public Suite { +public: + SimpleXmlParserTest() { + TEST_ADD(SimpleXmlParserTest::Find); + } +private: + void Find(); +}; + +namespace +{ + +class SimpleXmlParserGetter +{ +public: + static const char* GetName(const nn::xml::simple::SimpleXmlParser::Node* pNode); + static const char* GetContent(const nn::xml::simple::SimpleXmlParser::Node* pNode); + + static const size_t BUF_SIZE = 1024; + +private: + static char m_Buf[BUF_SIZE]; + +}; + +const char* SimpleXmlParserGetter::GetName(const nn::xml::simple::SimpleXmlParser::Node* pNode) +{ + if(!pNode) + { + return NULL; + } + std::memset(m_Buf, 0, sizeof(m_Buf)); + std::memcpy(m_Buf, pNode->name, pNode->nameSize); + return m_Buf; +} + +const char* SimpleXmlParserGetter::GetContent(const nn::xml::simple::SimpleXmlParser::Node* pNode) +{ + if(!pNode) + { + return NULL; + } + std::memset(m_Buf, 0, sizeof(m_Buf)); + std::memcpy(m_Buf, pNode->content, pNode->contentSize); + return m_Buf; +} + +char SimpleXmlParserGetter::m_Buf[SimpleXmlParserGetter::BUF_SIZE]; + +} + +//------------------------------------------------------------------ +// Test Functions +//------------------------------------------------------------------ + +void SimpleXmlParserTest::Find() +{ +const char testText[] = "\ +\ +\ +\ +\ +\ +\ +1326939225587\ +0\ +1\ +\ +17179924184\ +EJA20305940\ +JPN\ +1324339327000\ +000400000FEEB400,000400000FEEB000\ +\ +\ +\ +\ +\ +"; + + nn::fnd::IAllocator* pAllocator = nn::init::GetAllocator(); + nn::xml::simple::SimpleXmlParser simpleXmlParser(pAllocator); + simpleXmlParser.parse(reinterpret_cast(const_cast(testText)), sizeof(testText) - 1); + + + NN_TEST_ASSERT(!simpleXmlParser.isError()); + const nn::xml::simple::SimpleXmlParser::Node* pRootNode = simpleXmlParser.getRootNode(); + const nn::xml::simple::SimpleXmlParser::Node* pTargetNode = pRootNode->firstChild; + // 欲しい情報がある場所まで階層を掘り下げる + const nn::xml::simple::SimpleXmlParser::Node* pPriorityNode = nn::xml::simple::SimpleXmlParser::FindNextNode( + pTargetNode, "Body"); + pPriorityNode = nn::xml::simple::SimpleXmlParser::FindNextNode(pPriorityNode->firstChild, + "GetPreInstalledInfoResponse"); + pPriorityNode = nn::xml::simple::SimpleXmlParser::FindNextNode(pPriorityNode->firstChild, + "GetPreInstalledInfoResponse"); + pPriorityNode = nn::xml::simple::SimpleXmlParser::FindNextNode(pPriorityNode->firstChild, "PreinstalledInfo"); + + { + const nn::xml::simple::SimpleXmlParser::Node* pTaskIdNode = nn::xml::simple::SimpleXmlParser::FindNextNode( + pPriorityNode->firstChild, "DeviceId"); + NN_TEST_ASSERT(pTaskIdNode); + NN_TEST_ASSERT_EQUAL(std::strcmp("DeviceId", SimpleXmlParserGetter::GetName(pTaskIdNode)), 0); + NN_TEST_ASSERT_EQUAL(std::strcmp("17179924184", SimpleXmlParserGetter::GetContent(pTaskIdNode)), 0); + } + + { + const nn::xml::simple::SimpleXmlParser::Node* pTaskIdNode = nn::xml::simple::SimpleXmlParser::FindNextNode( + pPriorityNode->firstChild, "SerialNo"); + NN_TEST_ASSERT(pTaskIdNode); + NN_TEST_ASSERT_EQUAL(std::strcmp("SerialNo", SimpleXmlParserGetter::GetName(pTaskIdNode)), 0); + NN_TEST_ASSERT_EQUAL(std::strcmp("EJA20305940", SimpleXmlParserGetter::GetContent(pTaskIdNode)), 0); + } + + { + const nn::xml::simple::SimpleXmlParser::Node* pTaskIdNode = nn::xml::simple::SimpleXmlParser::FindNextNode( + pPriorityNode->firstChild, "TitleIds"); + NN_TEST_ASSERT(pTaskIdNode); + NN_TEST_ASSERT_EQUAL(std::strcmp("TitleIds", SimpleXmlParserGetter::GetName(pTaskIdNode)), 0); + NN_TEST_ASSERT_EQUAL(std::strcmp("000400000FEEB400,000400000FEEB000", SimpleXmlParserGetter::GetContent(pTaskIdNode)), 0); + } + +} + +NN_TEST_DEFINE_MAIN(SimpleXmlParserTest) + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/