00001 //------------------------------------------------------------------------------ 00002 // Lamp : Open source game middleware 00003 // Copyright (C) 2004 Junpei Ohtani ( Email : junpee@users.sourceforge.jp ) 00004 // 00005 // This library is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU Lesser General Public 00007 // License as published by the Free Software Foundation; either 00008 // version 2.1 of the License, or (at your option) any later version. 00009 // 00010 // This library is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public 00016 // License along with this library; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 //------------------------------------------------------------------------------ 00019 00020 /** @file 00021 * デバッグ出力リスナ実装 00022 * @author Junpee 00023 */ 00024 00025 #include <LampBasic.h> 00026 #include "Core/System/StringMethod.h" 00027 #include "LampUnit/TestStringListener.h" 00028 #include "LampUnit/TestFailure.h" 00029 #include "Core/Debug/Logger.h" 00030 00031 namespace LampUnit{ 00032 00033 //------------------------------------------------------------------------------ 00034 // コンストラクタ 00035 TestStringListener::TestStringListener(const char* fileName){ 00036 testCount_ = 0; 00037 if(fileName != NULL){ logger_ = new Lamp::Logger(fileName); } 00038 else{ logger_ = NULL; } 00039 00040 } 00041 //------------------------------------------------------------------------------ 00042 // デストラクタ 00043 TestStringListener::~TestStringListener(){ 00044 SafeDelete(logger_); 00045 } 00046 //------------------------------------------------------------------------------ 00047 // テスト開始 00048 void TestStringListener::startTest(Test* test){ 00049 print("."); 00050 testCount_++; 00051 if((testCount_ % 80) == 0){ print("\n"); } 00052 } 00053 //------------------------------------------------------------------------------ 00054 // 失敗の追加 00055 void TestStringListener::addFailure(const TestFailure& failure){ 00056 print("\n"); 00057 printFormat("%s\n", failure.toString()); 00058 } 00059 //------------------------------------------------------------------------------ 00060 // テスト終了 00061 void TestStringListener::endTest(Test* test){ 00062 } 00063 //------------------------------------------------------------------------------ 00064 // 出力 00065 void TestStringListener::print(const char* string){ 00066 StdOutputDebugString(string); 00067 StdPrintf(string); 00068 // 最高優先度でロガーへ出力 00069 if(logger_ != NULL){ 00070 logger_->output(Lamp::Logger::fewLevel, string); 00071 } 00072 } 00073 //------------------------------------------------------------------------------ 00074 // フォーマット出力 00075 void TestStringListener::printFormat(const char* format, ...){ 00076 va_list args; 00077 va_start(args, format); 00078 char stringBuffer[maxStringLength_]; 00079 int size = StdVsnprintf(stringBuffer, 00080 sizeof(stringBuffer) - 1, format, args); 00081 if(size < 0){ 00082 ErrorOut("デバッグ出力のフォーマットに失敗しました。"); 00083 } 00084 stringBuffer[size] = '\0'; 00085 print(stringBuffer); 00086 va_end(args); 00087 } 00088 //------------------------------------------------------------------------------ 00089 } // End of namespace LampUnit 00090 //------------------------------------------------------------------------------