• R/O
  • SSH
  • HTTPS

iris-fmw: Commit


Commit MetaInfo

Revision263 (tree)
Time2012-01-18 18:45:16
Authorshirayanagi

Log Message

iutest v0.15.0.0

型アサーションに対応

RGBA フォーマットクラス修正
関数フッククラス修正

Change Summary

Incremental Difference

--- trunk/framework/src/platform/windows/win/debug/dbghelp/WXProcHook.cpp (revision 262)
+++ trunk/framework/src/platform/windows/win/debug/dbghelp/WXProcHook.cpp (revision 263)
@@ -37,7 +37,7 @@
3737 CProcHook::CProcHook(void)
3838 : m_pfnOrigin(nullptr)
3939 , m_pfnCurrent(nullptr)
40-, m_pThunk(nullptr)
40+, m_ppAddress(nullptr)
4141 , m_pfnPrev(nullptr)
4242 {
4343 }
@@ -86,7 +86,7 @@
8686 PROC* ppfn = pointer_cast<PROC*>(&pitd->u1.Function);
8787 if( *ppfn == pfnTarget )
8888 {
89- m_pThunk = pitd;
89+ m_ppAddress = ppfn;
9090 m_pfnOrigin = *ppfn;
9191 return true;
9292 }
@@ -93,7 +93,6 @@
9393 ++pitd;
9494 }
9595 return false;
96-
9796 }
9897 /// CProcHook::Open 参照
9998 template<>
@@ -109,6 +108,69 @@
109108
110109 /**********************************************************************//**
111110 *
111+ * ターゲットのオープン
112+ *
113+ * @note モジュール全検索をする
114+ *
115+ -----------------------------------------------------------------------
116+ * @param [in] pfnTarget = ターゲット関数ポインタ
117+ * @param [in] hModule = ターゲットモジュール
118+ * @return 成否
119+*//***********************************************************************/
120+bool CProcHook::Open(PROC pfnTarget, HMODULE hModule)
121+{
122+ Close();
123+
124+ do
125+ {
126+ CImageDirectoryEntry<IMAGE_DIRECTORY_ENTRY_IMPORT> pidesc((PVOID)hModule, TRUE);
127+ if( pidesc == nullptr ) break;
128+
129+ while( pidesc->Name )
130+ {
131+#if 1 // デバッグ、最適化用
132+ LPCSTR lpName = pointer_cast<LPCSTR>((PBYTE)hModule + pidesc->Name);
133+ IRIS_UNUSED_VAR(lpName);
134+#endif
135+ PIMAGE_THUNK_DATA pitd = pointer_cast<PIMAGE_THUNK_DATA>((PBYTE)hModule + pidesc->FirstThunk);
136+
137+ while( pitd->u1.Function )
138+ {
139+ PROC* ppfn = pointer_cast<PROC*>(&pitd->u1.Function);
140+ if( *ppfn == pfnTarget )
141+ {
142+ m_ppAddress = ppfn;
143+ m_pfnOrigin = *ppfn;
144+ return true;
145+ }
146+ ++pitd;
147+ }
148+ ++pidesc;
149+ }
150+ } while(0);
151+
152+ // IAT から探す
153+ do
154+ {
155+ CImageDirectoryEntry<IMAGE_DIRECTORY_ENTRY_IAT> pidesc((PVOID)hModule, TRUE);
156+ if( pidesc == nullptr ) break;
157+
158+ for( ULONG i=0, count=pidesc.GetCount(); i < count; ++i, ++pidesc )
159+ {
160+ PROC* ppfn = pointer_cast<PROC*>(pidesc);
161+ if( *ppfn == pfnTarget )
162+ {
163+ m_ppAddress = ppfn;
164+ m_pfnOrigin = *ppfn;
165+ return true;
166+ }
167+ }
168+ } while(0);
169+ return false;
170+}
171+
172+/**********************************************************************//**
173+ *
112174 * オープン済みかどうか
113175 *
114176 -----------------------------------------------------------------------
@@ -116,7 +178,7 @@
116178 *//***********************************************************************/
117179 bool CProcHook::IsOpen(void)
118180 {
119- return m_pThunk != nullptr;
181+ return m_ppAddress != nullptr;
120182 }
121183
122184 /**********************************************************************//**
@@ -127,7 +189,7 @@
127189 void CProcHook::Close(void)
128190 {
129191 Reset();
130- m_pThunk = nullptr;
192+ m_ppAddress = nullptr;
131193 m_pfnOrigin = nullptr;
132194 m_pfnCurrent = nullptr;
133195 }
@@ -144,7 +206,7 @@
144206 {
145207 if( !IsOpen() ) return false;
146208 DWORD dwOldProtect;
147- PROC* ppfn = pointer_cast<PROC*>(&m_pThunk->u1.Function);
209+ PROC* ppfn = m_ppAddress;
148210 m_pfnPrev = *ppfn;
149211 VirtualProtect(ppfn, sizeof(ppfn), PAGE_EXECUTE_READWRITE, &dwOldProtect);
150212 WriteProcessMemory(GetCurrentProcess(), ppfn, &pfnNew, sizeof(pfnNew), nullptr);
@@ -163,7 +225,7 @@
163225 bool CProcHook::Revert(void)
164226 {
165227 if( !IsOpen() ) return true;
166- if( m_pThunk != nullptr && m_pfnPrev != nullptr )
228+ if( m_pfnPrev != nullptr )
167229 {
168230 if( !Replace(m_pfnPrev) ) return false;
169231 }
@@ -180,7 +242,7 @@
180242 bool CProcHook::Reset(void)
181243 {
182244 if( !IsOpen() ) return true;
183- if( m_pThunk != nullptr && m_pfnOrigin != nullptr )
245+ if( m_pfnOrigin != nullptr )
184246 {
185247 if( !Replace(m_pfnOrigin) ) return false;
186248 }
@@ -225,4 +287,21 @@
225287 }
226288 }
227289
290+TEST(ProcHookTest, SearchAll)
291+{
292+ {
293+ ::iris::wx::dbg::CProcHook phook;
294+ ASSERT_TRUE( phook.Open((PROC)MessageBoxA, ::GetModuleHandle(nullptr)) );
295+ ASSERT_TRUE( phook.Replace((PROC)_User_MessageBoxA) );
296+
297+ int ret = MessageBoxA(nullptr, "ProcHookTest", "test", 0);
298+ ASSERT_TRUE( ret == -1 );
299+ }
300+
301+ {
302+ ::iris::wx::dbg::CProcHook phook;
303+ ASSERT_TRUE( phook.Open("user32.dll", "MessageBoxA", ::GetModuleHandle(nullptr)) );
304+ }
305+}
306+
228307 #endif
--- trunk/framework/src/platform/windows/win/debug/dbghelp/WXProcHook.h (revision 262)
+++ trunk/framework/src/platform/windows/win/debug/dbghelp/WXProcHook.h (revision 263)
@@ -36,10 +36,10 @@
3636 /// 関数フッククラス
3737 class CProcHook : public IIrisObject
3838 {
39- PROC m_pfnOrigin; //!< 本来の関数ポインタ
40- PROC m_pfnPrev; //!< 以前の関数ポインタ
41- PROC m_pfnCurrent; //!< 現在の関数ポインタ
42- PIMAGE_THUNK_DATA m_pThunk; //!< イメージ情報
39+ PROC m_pfnOrigin; //!< 本来の関数ポインタ
40+ PROC m_pfnPrev; //!< 以前の関数ポインタ
41+ PROC m_pfnCurrent; //!< 現在の関数ポインタ
42+ PROC* m_ppAddress; //!< 関数ポインタ格納アドレス
4343 public:
4444 // コンストラクタ
4545 CProcHook(void);
@@ -57,6 +57,8 @@
5757 PROC pfnTarget = mdl.GetProcAddress(pszFuncName);
5858 return Open(pszModuleName, pfnTarget, hModule);
5959 }
60+ bool Open(PROC pfnTarget, HMODULE hModule);
61+
6062 // オープン済みかどうか
6163 bool IsOpen(void);
6264
@@ -80,6 +82,9 @@
8082 PROC GetNewProc(void) { return m_pfnCurrent; }
8183 /// オリジナルの関数を取得
8284 PROC GetOriginProc(void) { return m_pfnOrigin; }
85+ /// オリジナルの関数を取得
86+ template<typename F>
87+ F GetOriginProc(F) { return (F)m_pfnOrigin; }
8388 };
8489
8590 } // end of namespace dbg
--- trunk/framework/src/platform/windows/win/debug/dbghelp/WXImageDirectoryEntry.h (revision 262)
+++ trunk/framework/src/platform/windows/win/debug/dbghelp/WXImageDirectoryEntry.h (revision 263)
@@ -36,9 +36,9 @@
3636 class CImageDirectoryEntry : public IIrisObject
3737 {
3838 typedef CImageDirectoryEntry<ENTRY> _Myt;
39- template<USHORT DE>struct type_impl { typedef VOID value_type; };
40- template<>struct type_impl<IMAGE_DIRECTORY_ENTRY_IMPORT> { typedef IMAGE_IMPORT_DESCRIPTOR value_type; };
41- template<>struct type_impl<IMAGE_DIRECTORY_ENTRY_EXPORT> { typedef IMAGE_EXPORT_DIRECTORY value_type; };
39+ template<USHORT DE>struct type_impl { typedef DWORD value_type; };
40+ template<>struct type_impl<IMAGE_DIRECTORY_ENTRY_IMPORT> { typedef IMAGE_IMPORT_DESCRIPTOR value_type; };
41+ template<>struct type_impl<IMAGE_DIRECTORY_ENTRY_EXPORT> { typedef IMAGE_EXPORT_DIRECTORY value_type; };
4242
4343 public:
4444 typedef typename type_impl<ENTRY>::value_type value_type;
@@ -76,6 +76,12 @@
7676 _Myt operator ++ (int) { _Myt tmp(*this); ++m_pEntry; return tmp; }
7777
7878 public:
79+ /// サイズ取得
80+ ULONG GetSize(void) const { return m_nSize; }
81+ /// 要素数の取得
82+ ULONG GetCount(void) const { return m_nSize / sizeof(value_type); }
83+
84+public:
7985 /// データ取得
8086 static value_ptr ToData(PVOID pBase, BOOLEAN bMappedAsImage, PULONG pSize)
8187 {
--- trunk/framework/src/platform/windows/win/debug/dbghelp/WXSymbol.cpp (revision 262)
+++ trunk/framework/src/platform/windows/win/debug/dbghelp/WXSymbol.cpp (revision 263)
@@ -8,7 +8,7 @@
88 * @version 1.0
99 *
1010 * @par copyright
11- * Copyright (C) 2010-2011 Takazumi Shirayanagi\n
11+ * Copyright (C) 2010-2012 Takazumi Shirayanagi\n
1212 * The new BSD License is applied to this software.
1313 * see iris_LICENSE.txt
1414 */
@@ -98,6 +98,7 @@
9898 *//***********************************************************************/
9999 BOOL CSymbol::Cleanup(void)
100100 {
101+ if( !IsValid() ) return TRUE;
101102 return CDbgHelpModule::SymCleanup(Detach());
102103 }
103104
--- trunk/framework/src/fnd/container/FndSingleton.h (revision 262)
+++ trunk/framework/src/fnd/container/FndSingleton.h (revision 263)
@@ -40,7 +40,7 @@
4040
4141 public:
4242 static const u32 NUM_INST = NUM_INST_;
43-private:
43+public:
4444 typedef TN_ value_type;
4545 typedef TN_ *value_ptr;
4646 typedef TN_ &value_ref;
@@ -72,6 +72,8 @@
7272 }
7373
7474 private:
75+#if 0
76+ // ローカル static 版
7577 static volatile value_ptr& ptr(s32 idx)
7678 {
7779 IRIS_MSC_PRAGMA_WARNING_BEGIN()
@@ -82,8 +84,19 @@
8284 IRIS_ASSERT( idx < NUM_INST );
8385 return s_instance[idx];
8486 }
87+#else
88+ static volatile value_ptr& ptr(s32 idx)
89+ {
90+ IRIS_ASSERT( idx < NUM_INST );
91+ return s_instance[idx];
92+ }
93+ static value_ptr s_instance[NUM_INST];
94+#endif
8595 };
8696
97+template<typename TN_, u32 NUM_INST_>
98+TN_* CSingleton<TN_, NUM_INST_>::s_instance[NUM_INST] = { nullptr };
99+
87100 /**
88101 * @brief シングルトンベースクラス
89102 * @tparam TN_ = 対象型
@@ -96,7 +109,7 @@
96109 public:
97110 static const u32 NUM_INST = NUM_INST_;
98111
99-private:
112+public:
100113 typedef TN_ value_type;
101114 typedef TN_ *value_ptr;
102115 typedef TN_ &value_ref;
@@ -103,10 +116,10 @@
103116
104117 public:
105118 /// インスタンスの取得
106- static value_ref GetInstance(s32 idx=0) { return value_type::_GetInstance(idx); }
119+ static value_ref GetInstance(s32 idx=0) { return value_type::GetInstance_(idx); }
107120
108121 protected:
109- static value_ref _GetInstance(s32 idx=0) { static value_type instance[NUM_INST]; return instance[idx]; }
122+ static value_ref GetInstance_(s32 idx=0) { static value_type instance[NUM_INST]; return instance[idx]; }
110123 };
111124
112125 } // end of namespace fnd
--- trunk/framework/src/fnd/image/FndColor.h (revision 262)
+++ trunk/framework/src/fnd/image/FndColor.h (revision 263)
@@ -112,6 +112,9 @@
112112 // IRIS_STATIC_ASSERT( sizeof(value_type)*8 >= BSZ_ALL );
113113
114114 public:
115+ static bool HasAplha(void) { return BSZ_A != 0; }
116+
117+public:
115118 /**
116119 * @name コンストラクタ
117120 * @{
@@ -227,7 +230,7 @@
227230 template<typename U, int BITS_>
228231 U b(void) const { return convert<BITS_, BSZ_B, U>::shift(b()); }
229232 template<typename U, int BITS_>
230- U a(void) const { return convert<BITS_, BSZ_A, U>::shift(a()); }
233+ U a(void) const { return convert_alpha<BITS_, BSZ_A, U>::shift(a()); }
231234
232235 template<typename U>
233236 U r(void) const { return convert<sizeof(U)*8, BSZ_R, U>::shift(r()); }
@@ -236,7 +239,7 @@
236239 template<typename U>
237240 U b(void) const { return convert<sizeof(U)*8, BSZ_B, U>::shift(b()); }
238241 template<typename U>
239- U a(void) const { return convert<sizeof(U)*8, BSZ_A, U>::shift(a()); }
242+ U a(void) const { return convert_alpha<sizeof(U)*8, BSZ_A, U>::shift(a()); }
240243 /**
241244 * @}
242245 */
@@ -401,6 +404,32 @@
401404 }
402405 };
403406
407+ template<int BTO, int BFROM, typename TO>
408+ class convert_alpha
409+ {
410+ template<int BTO_, int BFROM_, typename FROM>
411+ struct impl
412+ {
413+ static inline TO shift(FROM value)
414+ {
415+ return convert<BTO, BFROM, TO>::shift(value);
416+ }
417+ };
418+ // src が 0 bit の場合は、最大値
419+ template<int B, typename FROM>
420+ struct impl<B, 0, FROM>
421+ {
422+ static inline TO shift(FROM /*value*/) { return (1<<B)-1; }
423+ };
424+ public:
425+ template<typename FROM>
426+ static inline TO shift(FROM value)
427+ {
428+ return impl<BTO, BFROM, FROM>::shift(value);
429+ }
430+ };
431+
432+
404433 template<int SIZE>
405434 void a_(value_type_a v) { value_type max = (value_type)max_a(); m_col &= ~(max << SFT_A); m_col |= ((v > max ? max : (value_type)v)) << SFT_A; }
406435 template<>
--- trunk/framework/src/fnd/io/FndIStream.h (nonexistent)
+++ trunk/framework/src/fnd/io/FndIStream.h (revision 263)
@@ -0,0 +1,72 @@
1+//======================================================================
2+//-----------------------------------------------------------------------
3+/**
4+ * @file FndIStream.h
5+ * @brief stream インターフェイス ファイル
6+ *
7+ * @author t.sirayanagi
8+ * @version 1.0
9+ *
10+ * @par copyright
11+ * Copyright (C) 2012 Takazumi Shirayanagi\n
12+ * The new BSD License is applied to this software.
13+ * see iris_LICENSE.txt
14+*/
15+//-----------------------------------------------------------------------
16+//======================================================================
17+#ifndef INCG_IRIS_FndIStream_H_
18+#define INCG_IRIS_FndIStream_H_
19+
20+//======================================================================
21+// include
22+#include "../../iris_object.h"
23+
24+namespace iris {
25+namespace fnd
26+{
27+
28+//======================================================================
29+// class
30+//! Stream インターフェイス
31+class IStream : private INonCopyable<IStream>
32+{
33+public:
34+ // コンストラクタ
35+ IStream(void) {}
36+ // デストラクタ
37+ virtual ~IStream(void) {}
38+public:
39+ /**
40+ * seek
41+ * @param [in] offset = オフセット
42+ * @param [in] origin = 計算方法
43+ * @return 成否
44+ */
45+ virtual bool Seek(long offset, int origin) = 0;
46+ /**
47+ * tell
48+ * @return 現在の位置
49+ */
50+ virtual s32 Tell(void) const = 0;
51+
52+ /**
53+ * 読み込み
54+ * @param [out] buf = 出力バッファ
55+ * @param [in] size = 出力バッファサイズ
56+ * @return 読み込みサイズ
57+ */
58+ virtual u32 Read(void* buf, u32 size) = 0;
59+ /**
60+ * 書き込み
61+ * @param [in] buf = 入力バッファ
62+ * @param [in] size = 入力バッファサイズ
63+ * @return 書き込みサイズ
64+ */
65+ virtual u32 Write(const void* buf, u32 size) = 0;
66+};
67+
68+
69+} // end of namespace fnd
70+} // end of namespace iris
71+
72+#endif
--- trunk/framework/src/fnd/io/FndIFile.h (revision 262)
+++ trunk/framework/src/fnd/io/FndIFile.h (revision 263)
@@ -8,7 +8,7 @@
88 * @version 1.0
99 *
1010 * @par copyright
11- * Copyright (C) 2010-2011 Takazumi Shirayanagi\n
11+ * Copyright (C) 2010-2012 Takazumi Shirayanagi\n
1212 * The new BSD License is applied to this software.
1313 * see iris_LICENSE.txt
1414 */
@@ -19,7 +19,7 @@
1919
2020 //======================================================================
2121 // include
22-#include "../../iris_object.h"
22+#include "FndIStream.h"
2323 #include "../../c++0x/cpp0x_enable_if.hpp"
2424 #include "../../c++0x/cpp0x_type_traits.hpp"
2525
@@ -58,7 +58,7 @@
5858 //======================================================================
5959 // class
6060 //! FILEクラス インターフェイス
61-class IFile : private INonCopyable<IFile>
61+class IFile : private IStream
6262 {
6363 public:
6464 // コンストラクタ
--- trunk/framework/testsuite/iutest/include/iutest_ver.h (revision 262)
+++ trunk/framework/testsuite/iutest/include/iutest_ver.h (revision 263)
@@ -22,16 +22,22 @@
2222
2323 //======================================================================
2424 // define
25-#define IUTEST_VER 0x00140002 //!< iutest version 0.14.0.2
25+#define IUTEST_VER 0x00150000 //!< iutest version 0.15.0.0
2626 #define IUTEST_MAJORVER 0x00
27-#define IUTEST_MINORVER 0x14
27+#define IUTEST_MINORVER 0x15
2828 #define IUTEST_BUILD 0x00
29-#define IUTEST_REVISION 0x02
29+#define IUTEST_REVISION 0x00
3030
3131 /**
3232 * @file iutest_ver.h
3333 * @par release note
3434 <ul>
35+ <li>v0.15.0.0
36+ <ul>
37+ <li>型アサーション 対応</li>
38+ <li>TestCase の DISABLED がカウントされていないバグを修正</li>
39+ </ul>
40+ </li>
3541 <li>v0.14.0.1
3642 <ul>
3743 <li>RecoredProperty 対応</li>
--- trunk/framework/testsuite/iutest/include/gtest/iutest_switch.h (revision 262)
+++ trunk/framework/testsuite/iutest/include/gtest/iutest_switch.h (revision 263)
@@ -328,6 +328,9 @@
328328
329329 #ifdef INCG_IRIS_iutest_H_
330330 # define GTEST_USE_OWN_TR1_TUPLE 0
331+# ifdef StaticAssertTypeEq
332+# undef StaticAssertTypeEq
333+# endif
331334 #endif
332335
333336 //======================================================================
--- trunk/framework/testsuite/iutest/include/iutest_case.h (revision 262)
+++ trunk/framework/testsuite/iutest/include/iutest_case.h (revision 263)
@@ -69,7 +69,11 @@
6969 bool Run(void)
7070 {
7171 if( !should_run() ) return true;
72- if( m_disable ) return true;
72+ if( m_disable )
73+ {
74+ m_disable_num = m_should_run_num;
75+ return true;
76+ }
7377
7478 if( TestFlag::IsEnableFlag(TestFlag::SHUFFLE_TESTS) )
7579 {
--- trunk/framework/testsuite/iutest/include/iutest_static_assertion.h (nonexistent)
+++ trunk/framework/testsuite/iutest/include/iutest_static_assertion.h (revision 263)
@@ -0,0 +1,59 @@
1+//======================================================================
2+//-----------------------------------------------------------------------
3+/**
4+ * @file iutest_static_assertion.h
5+ * @brief iris unit test static assertion 定義 ファイル
6+ *
7+ * @author t.sirayanagi
8+ * @version 1.0
9+ *
10+ * @par copyright
11+ * Copyright (C) 2012 Takazumi Shirayanagi\n
12+ * The new BSD License is applied to this software.
13+ * see LICENSE
14+*/
15+//-----------------------------------------------------------------------
16+//======================================================================
17+#ifndef INCG_IRIS_iutest_static_assertion_H_53842FD6_9E5D_40a6_905D_EC6DEBE5ED6A_
18+#define INCG_IRIS_iutest_static_assertion_H_53842FD6_9E5D_40a6_905D_EC6DEBE5ED6A_
19+
20+//======================================================================
21+// include
22+
23+namespace iutest
24+{
25+
26+namespace detail
27+{
28+
29+template<typename T1, typename T2>
30+struct StaticAssertTypeEqHelper;
31+
32+template<typename T>
33+struct StaticAssertTypeEqHelper<T, T>
34+{
35+ operator bool (void) const { return true; }
36+};
37+
38+}
39+
40+//======================================================================
41+// function
42+#if 0
43+template<typename T1, typename T2>
44+static bool StaticAssertTypeEq(void)
45+{
46+ (void)detail::StaticAssertTypeEqHelper<T1, T2>();
47+ return true;
48+}
49+#else
50+
51+// マクロバージョン
52+// エラーが呼び出し位置に出る
53+#define StaticAssertTypeEq detail::StaticAssertTypeEqHelper
54+
55+#endif
56+
57+} // end of namespace iutest
58+
59+#endif
--- trunk/framework/testsuite/iutest/include/iutest.h (revision 262)
+++ trunk/framework/testsuite/iutest/include/iutest.h (revision 263)
@@ -51,6 +51,7 @@
5151 #include "iutest_ver.h"
5252 #include "iutest_param_tests.h"
5353 #include "iutest_typed_tests.h"
54+#include "iutest_static_assertion.h"
5455 #include "listener/iutest_default_printer.h"
5556 #include "listener/iutest_default_xml_generator.h"
5657 #include "iutest_util.h"
--- trunk/framework/testsuite/iutest/samples/sub.cpp (revision 262)
+++ trunk/framework/testsuite/iutest/samples/sub.cpp (revision 263)
@@ -8,6 +8,7 @@
88 * include testing framework
99 */
1010 #include "../include/iutest.h"
11+#include "../include/gtest/iutest_switch.h"
1112
1213 #if 1 // Success Tests
1314
@@ -68,6 +69,12 @@
6869 IUTEST_ASSERT_EQ(2, x);
6970 }
7071
72+IUTEST(StaticTest, Eq)
73+{
74+ IUTEST_ASSERT_TRUE( (iutest::StaticAssertTypeEq<int, int>()) );
75+ //iutest::StaticAssertTypeEq<bool, int>();
76+}
77+
7178 #if IUTEST_HAS_PARAM_TEST
7279 // パラメータテスト
7380
Show on old repository browser