Alternate e697dbe9c5997e35395fe158628dd8c5209481da
for Visual Studio 2022 and Windows 11.
読み取り中…
検索中…
一致する文字列を見つけられません
LogTest.cpp
[詳解]
1
5
6#include "pch.h"
7#include "Log.h"
8#include "Thread.h"
9
10using namespace Microsoft::VisualStudio::CppUnitTestFramework;
11
12namespace WindowsLibraryTest
13{
15
16 auto loopAction = [](int index, int loopMax)
17 {
18 alt::TString message;
19 for (int i = 0; i < loopMax; i++)
20 {
21 message << _T ("ThreadFunction_") << index << _T ("_") << i << _T ("_★★★★★★★★★★★★★★★★★★★");
22 __threadLogFile.Info (message.Ctr ());
23 Sleep (0);
24 message = _T ("");
25 }
26
27 return 0;
28 };
29
30 DWORD ThreadFunction1 (LPVOID lpvParam)
31 {
32 loopAction (1, 1000);
33 return 0;
34 }
35
36 DWORD ThreadFunction2 (LPVOID lpvParam)
37 {
38 loopAction (2, 1000);
39 return 0;
40 }
41
42 DWORD ThreadFunction3 (LPVOID lpvParam)
43 {
44 loopAction (3, 1000);
45 return 0;
46 }
47
48 DWORD ThreadFunction4 (LPVOID lpvParam)
49 {
50 loopAction (4, 1000);
51 return 0;
52 }
53
54 DWORD ThreadFunction5 (LPVOID lpvParam)
55 {
56 loopAction (5, 1000);
57 return 0;
58 }
59
60 DWORD ThreadFunction6 (LPVOID lpvParam)
61 {
62 loopAction (6, 1000);
63 return 0;
64 }
65
66 DWORD ThreadFunction7 (LPVOID lpvParam)
67 {
68 loopAction (7, 1000);
69 return 0;
70 }
71
72 DWORD ThreadFunction8 (LPVOID lpvParam)
73 {
74 loopAction (8, 1000);
75 return 0;
76 }
77
78 TEST_CLASS (LogTest)
79 {
80 public:
81 TEST_CLASS_INITIALIZE (ClassInitialize)
82 {
83 Logger::WriteMessage ("LogTest class initialize.\n");
84 auto response = alt::FileUtility::Find (_T(".\\"), _T ("TestLog*"));
85 for (int i = 0; i < response.Size (); i++)
86 {
87 alt::TString target;
88 target.Format (_T ("%s\\%s"),
89 response[i]->GetFolderName().Ctr(),
90 response[i]->GetFileName().Ctr());
91 alt::FileUtility::Delete (target.Ctr ());
92 }
93 }
94
95 TEST_CLASS_CLEANUP (ClassCleanup)
96 {
97 Logger::WriteMessage ("LogTest class cleanup.\n");
98 }
99
100 TEST_METHOD_INITIALIZE (MethodInitialize)
101 {
102 Logger::WriteMessage ("LogTest method initialize.\n");
103 }
104
105 TEST_METHOD_CLEANUP (MethodCleanup)
106 {
107 Logger::WriteMessage ("LogTest method cleanup.\n");
108 }
109
110 TEST_METHOD (LogFileTest1)
111 {
112 alt::Log logger (alt::LogLevel::Trace, _T (".\\TestLogA"), 10, 1024 * 1024);
113
114 for (int i = 0; i < 900; i++)
115 {
116 logger.Debug (_T ("DebugLog -------------------------------------------"));
117 logger.Trace (_T ("TraceLog -------------------------------------------"));
118 logger.Info (_T ("InfoLog --------------------------------------------"));
119 logger.Warn (_T ("WarnLog --------------------------------------------"));
120 logger.Error (_T ("ErrorLog -------------------------------------------"));
121 logger.Fatal (_T ("FatalLog -------------------------------------------"));
122 }
123 }
124
125 TEST_METHOD (LogFileTest2)
126 {
127 alt::Log logger (alt::LogLevel::Debug, _T (".\\TestLogB"), 10, 1024 * 1024);
128
129 for (int i = 0; i < 1000; i++)
130 {
131 logger.Debug (_T ("DebugLog --------------------------------------------------------------------"));
132 logger.Trace (_T ("TraceLog --------------------------------------------------------------------"));
133 logger.Info (_T ("InfoLog ---------------------------------------------------------------------"));
134 logger.Warn (_T ("WarnLog ---------------------------------------------------------------------"));
135 logger.Error (_T ("ErrorLog --------------------------------------------------------------------"));
136 logger.Fatal (_T ("FatalLog --------------------------------------------------------------------"));
137 }
138 }
139
140 TEST_METHOD (LogFileTest3)
141 {
142 alt::Log logger (alt::LogLevel::Info, _T (".\\TestLogC"), 10, 1024 * 1024);
143
144 for (int i = 0; i < 1000; i++)
145 {
146 logger.Debug (_T ("DebugLog --------------------------------------------------------------------"));
147 logger.Trace (_T ("TraceLog --------------------------------------------------------------------"));
148 logger.Info (_T ("InfoLog ---------------------------------------------------------------------"));
149 logger.Warn (_T ("WarnLog ---------------------------------------------------------------------"));
150 logger.Error (_T ("ErrorLog --------------------------------------------------------------------"));
151 logger.Fatal (_T ("FatalLog --------------------------------------------------------------------"));
152 }
153 }
154
155 TEST_METHOD (LogFileTest4)
156 {
157 alt::Log logger (alt::LogLevel::Warn, _T (".\\TestLogD"), 10, 1024 * 1024);
158
159 for (int i = 0; i < 1000; i++)
160 {
161 logger.Debug (_T ("DebugLog --------------------------------------------------------------------"));
162 logger.Trace (_T ("TraceLog --------------------------------------------------------------------"));
163 logger.Info (_T ("InfoLog ---------------------------------------------------------------------"));
164 logger.Warn (_T ("WarnLog ---------------------------------------------------------------------"));
165 logger.Error (_T ("ErrorLog --------------------------------------------------------------------"));
166 logger.Fatal (_T ("FatalLog --------------------------------------------------------------------"));
167 }
168 }
169
170 TEST_METHOD (LogFileTest5)
171 {
172 alt::Log logger (alt::LogLevel::Error, _T (".\\TestLogE"), 10, 1024 * 1024);
173
174 for (int i = 0; i < 1000; i++)
175 {
176 logger.Debug (_T ("DebugLog --------------------------------------------------------------------"));
177 logger.Trace (_T ("TraceLog --------------------------------------------------------------------"));
178 logger.Info (_T ("InfoLog ---------------------------------------------------------------------"));
179 logger.Warn (_T ("WarnLog ---------------------------------------------------------------------"));
180 logger.Error (_T ("ErrorLog --------------------------------------------------------------------"));
181 logger.Fatal (_T ("FatalLog --------------------------------------------------------------------"));
182 }
183 }
184
185 TEST_METHOD (LogFileTest6)
186 {
187 alt::Log logger (alt::LogLevel::Fatal, _T (".\\TestLogF"), 10, 1024 * 1024);
188
189 for (int i = 0; i < 1000; i++)
190 {
191 logger.Debug (_T ("DebugLog --------------------------------------------------------------------"));
192 logger.Trace (_T ("TraceLog --------------------------------------------------------------------"));
193 logger.Info (_T ("InfoLog ---------------------------------------------------------------------"));
194 logger.Warn (_T ("WarnLog ---------------------------------------------------------------------"));
195 logger.Error (_T ("ErrorLog --------------------------------------------------------------------"));
196 logger.Fatal (_T ("FatalLog --------------------------------------------------------------------"));
197 }
198 }
199
200 TEST_METHOD (LogFileThreadTest)
201 {
202 __threadLogFile.Init (alt::LogLevel::Trace, _T (".\\TestLog"), 10, 1024 * 1024 * 1);
203
204 alt::Thread thread1;
205 alt::Thread thread2;
206 alt::Thread thread3;
207 alt::Thread thread4;
208 alt::Thread thread5;
209 alt::Thread thread6;
210 alt::Thread thread7;
211 alt::Thread thread8;
212
213 thread1.Create (ThreadFunction1);
214 thread2.Create (ThreadFunction2);
215 thread3.Create (ThreadFunction3);
216 thread4.Create (ThreadFunction4);
217 thread5.Create (ThreadFunction5);
218 thread6.Create (ThreadFunction6);
219 thread7.Create (ThreadFunction7);
220 thread8.Create (ThreadFunction8);
221
222 thread1.Wait ();
223 thread2.Wait ();
224 thread3.Wait ();
225 thread4.Wait ();
226 thread5.Wait ();
227 thread6.Wait ();
228 thread7.Wait ();
229 thread8.Wait ();
230 }
231 };
232}
Fileをベースとしたログに関する機能を集約したクラス
スレッドに関するWindowsAPIを集約したクラス
プリコンパイル済みヘッダー ファイルです。
static skeleton::Array< FileInfo1 > APIENTRY Find(LPCTSTR target, LPCTSTR name, BOOL bRecurse=FALSE)
ファイルの検索
static BOOL APIENTRY Delete(LPCTSTR name)
ファイルの削除
Definition: FileUtility.cpp:57
Fileをベースとしたログに関する機能を集約したクラス
Definition: Log.h:37
VOID APIENTRY Trace(LPCTSTR message, DWORD dwThreadID=GetCurrentThreadId())
トレースログの出力
Definition: Log.cpp:221
BOOL APIENTRY Init(LogLevel logLevel, LPCTSTR fileName, SHORT sRotation, DWORD dwFileSize)
初期化
Definition: Log.cpp:32
VOID APIENTRY Info(LPCTSTR message, DWORD dwThreadID=GetCurrentThreadId())
情報ログの出力
Definition: Log.cpp:209
VOID APIENTRY Warn(LPCTSTR message, DWORD dwThreadID=GetCurrentThreadId())
警告ログの出力
Definition: Log.cpp:203
VOID APIENTRY Error(LPCTSTR message, DWORD dwThreadID=GetCurrentThreadId())
エラーログの出力
Definition: Log.cpp:197
VOID APIENTRY Fatal(LPCTSTR message, DWORD dwThreadID=GetCurrentThreadId())
致命的エラーログの出力
Definition: Log.cpp:191
VOID APIENTRY Debug(LPCTSTR message, DWORD dwThreadID=GetCurrentThreadId())
デバッグログの出力
Definition: Log.cpp:215
文字列に関するWindowsAPIを集約したクラス
Definition: TString.h:17
TString &APIENTRY Format(LPCTSTR format,...)
フォーマットに従ってパラメータを文字列化します。
Definition: TString.cpp:333
LPCTSTR APIENTRY Ctr() const
内部で確保している文字列ポインタを取得します。
Definition: TString.h:46
スレッドに関するWindowsAPIを集約したクラス
Definition: Thread.h:43
BOOL APIENTRY Create(PTHREAD_START_ROUTINE function=NULL, LPVOID lpvParam=NULL, DWORD dwCreationFlag=0)
スレッドを作成します。
Definition: Thread.cpp:24
DWORD APIENTRY Wait(DWORD dwWaitTime=INFINITE) const
シグナル状態になるとブロックを解除します。
DWORD ThreadFunction2(LPVOID lpvParam)
Definition: LogTest.cpp:36
TEST_CLASS(ArrayTest)
Definition: ArrayTest.cpp:19
DWORD ThreadFunction4(LPVOID lpvParam)
Definition: LogTest.cpp:48
DWORD ThreadFunction8(LPVOID lpvParam)
Definition: LogTest.cpp:72
DWORD ThreadFunction1(LPVOID lpvParam)
Definition: LogTest.cpp:30
DWORD ThreadFunction5(LPVOID lpvParam)
Definition: LogTest.cpp:54
DWORD ThreadFunction7(LPVOID lpvParam)
Definition: LogTest.cpp:66
DWORD ThreadFunction6(LPVOID lpvParam)
Definition: LogTest.cpp:60
DWORD ThreadFunction3(LPVOID lpvParam)
Definition: LogTest.cpp:42
alt::Log __threadLogFile
Definition: LogTest.cpp:14
@ Info
(3)情報
@ Warn
(2)警告
@ Fatal
(0)異常終了レベル
@ Error
(1)エラー
@ Debug
(4)デバッグ
@ Trace
(5)トレース