Alternate e697dbe9c5997e35395fe158628dd8c5209481da
for Visual Studio 2022 and Windows 11.
読み取り中…
検索中…
一致する文字列を見つけられません
WorkerTemplateTest.cpp
[詳解]
1/*
2 https://docs.microsoft.com/ja-jp/visualstudio/test/microsoft-visualstudio-testtools-cppunittestframework-api-reference?view=vs-2019#general_asserts
3 Microsoft.VisualStudio.TestTools.CppUnitTestFramework API リファレンス
4 */
5#include "pch.h"
6#include "WorkerTemplate.hpp"
7
8using namespace Microsoft::VisualStudio::CppUnitTestFramework;
9using namespace alt;
10
11namespace alt
12{
14 {
15 public:
17 {
18 _message = nullptr;
19 _dwSize = 0;
20 _data = nullptr;
21 };
22
23 virtual ~WorkerFunction ()
24 {
25 delete _message;
26 delete _data;
27 };
28
29 std::function<bool ()> init = [&]()
30 {
31 _message = new Message ();
32 _message->SetFrom (0);
33 _message->SetTo (1);
34 _message->SetCommand (-1);
35
36 _data = new Data (64);
37 _data->SetByte ((LPBYTE)"THIS IS A SAMPLE STRING.", 24);
38
39 return true;
40 };
41
42 std::function<bool ()> start = [&]()
43 {
44 return true;
45 };
46
47 std::function<bool (Message message)> command = [&](Message message)
48 {
49 return true;
50 };
51
52 std::function<Data (Data data)> process = [&](Data data) -> Data
53 {
54 return data;
55 };
56
57 std::function<bool ()> stop = [&]()
58 {
59 return true;
60 };
61
62 std::function<bool ()> exit = [&]()
63 {
64 return true;
65 };
66
67 private:
70 DWORD _dwSize;
71 };
72}
73
74namespace MiddleLibraryTest
75{
76 TEST_CLASS (WorkerTemplateTest)
77 {
78 public:
79 TEST_CLASS_INITIALIZE (ClassInitialize)
80 {
81 Logger::WriteMessage ("class initialize.\n");
82 }
83
84 TEST_CLASS_CLEANUP (ClassCleanup)
85 {
86 Logger::WriteMessage ("class cleanup.\n");
87 }
88
89 TEST_METHOD_INITIALIZE (MethodInitialize)
90 {
91 Logger::WriteMessage ("method initialize.\n");
92 }
93
94 TEST_METHOD_CLEANUP (MethodCleanup)
95 {
96 Logger::WriteMessage ("method cleanup.\n");
97 }
98
99 TEST_METHOD (SequencialCall)
100 {
103 WorkerTemplate workerTemplate;
104 WorkerFunction workerFunction;
105 Data data (128);
106 data.SetByte ((LPBYTE)"1234567890", 10);
107 Message message;
108
110 {
111 bool ret = t.Init (f.init);
112 Assert::AreEqual<bool> (true, ret);
113
114 }(workerTemplate, workerFunction);
115
117 {
118 bool ret = t.Start (f.start);
119 Assert::AreEqual<bool> (true, ret);
120
121 }(workerTemplate, workerFunction);
122
123 [] (WorkerTemplate& t, WorkerFunction& f, Message& msg)
124 {
125 bool ret = t.Command (f.command, msg);
126 Assert::AreEqual<bool> (true, ret);
127
128 }(workerTemplate, workerFunction, message);
129
130 [] (WorkerTemplate& t, WorkerFunction& f, Data& d)
131 {
132 Data ret = t.Process (f.process, d);
133 Assert::AreEqual (0, lstrcmpA ("1234567890", (LPSTR)ret.GetByte ()));
134
135 }(workerTemplate, workerFunction, data);
136
138 {
139 bool ret = t.Stop (f.stop);
140 Assert::AreEqual<bool> (true, ret);
141
142 }(workerTemplate, workerFunction);
143
145 {
146 bool ret = t.Exit (f.exit);
147 Assert::AreEqual<bool> (true, ret);
148
149 }(workerTemplate, workerFunction);
150 }
151 };
152}
プリコンパイル済みヘッダー ファイルです。
LPBYTE GetByte()
void SetByte(LPBYTE pbyData, DWORD dwSize)
void SetTo(int to)
void SetFrom(int from)
void SetCommand(int command)
std::function< bool()> init
std::function< bool()> stop
std::function< bool(Message message)> command
std::function< bool()> exit
std::function< bool()> start
std::function< Data(Data data)> process
bool Stop(Function function)
終了処理
bool Start(Function function)
開始処理
bool Exit(Function function)
退出処理
bool Init(Function function)
初期化処理
bool Command(Function function, Message message)
コマンド処理
Data Process(Function function, Data data)
プロセス処理
TEST_CLASS(DesignPatternTest)
Definition: DBLibrary.h:12