Dialog Based ์์์ ํ ์คํธ ¶
Dialog Based ์ ๊ฒฝ์ฐ Modal Dialog ๋ฅผ ์ด์ฉํ๊ฒ ๋๋ค. ์ด ๊ฒฝ์ฐ Dialog ๋ด์์๋ง ๋ฉ์ธ์ง๋ฃจํ๊ฐ ์๋ํ๊ฒ ๋๋ฏ๋ก, DoModal ํจ์๋ก ๋ค์ด์ผ๋ก๊ทธ๋ฅผ ๋์ด ์ดํ์ ์ฝ๋๋ ํด๋น Dialog ๊ฐ ๋ซํ๊ธฐ ์ ๊น์ง๋ ์คํ๋์ง ์๋๋ค. ๊ณ ๋ก, CppUnit ์์์ fixture ๋ฅผ ๋ฏธ๋ฆฌ ๊ตฌ์ฑํ์ฌ ์ธ ์ ์๋ค.
๊ทธ๋์, ํ
์คํธ๋ฅผ ์๋ํ ๋ Modaless Dialog ๋ก ๋ง๋ค๊ณ ์คํ์ ํ์๋ค.
์ํ๋ ์๋ ๋ชจ์ต์ ์ด๋ ๋ค.
- Editbox ์ ์๋ฌด ๊ธ์ ๋ฃ๊ณ
- Add ๋ฒํผ์ ๋๋ฅด๋ฉด
- List box ์ Editbox ์ ์ด ๊ธ์ด ์์๋๋ก ์ฒ์๋ถํฐ ์ฑ์์ง๊ณ
- List box ์์์ ์ปค์๋ ์ฑ์์ง ๊ธ์ ์์นํ๋ค.
- List box ์ ๊ฐ์ด ์ฑ์์ง๊ณ ๋ ๋ค, Editbox ์ ๊ธ์ ์ง์์ง๋ค.
1. GUI Runner Setting ¶
์ด๋ App ํด๋์ค์ InitInstance ํจ์์์ ํด์ค๋ค.
~cpp #include "stdafx.h" #include "GuiTestingOne.h" #include "GuiTestingOneDlg.h" #include "cppunit\ui\mfc\TestRunner.h" #include "GuiTestCase.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif BEGIN_MESSAGE_MAP(CGuiTestingOneApp, CWinApp) //{{AFX_MSG_MAP(CGuiTestingOneApp) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG ON_COMMAND(ID_HELP, CWinApp::OnHelp) END_MESSAGE_MAP() CGuiTestingOneApp::CGuiTestingOneApp() { } CGuiTestingOneApp theApp; BOOL CGuiTestingOneApp::InitInstance() { AfxEnableControlContainer(); CppUnit::MfcUi::TestRunner runner; runner.addTest (GuiTestCase::suite()); runner.run(); /* --- Test Runner ๋ง ์คํ๋๋๋ก, ๋ค์ด์ผ๋ก๊ทธ ๋์ฐ๋ ๋ถ๋ถ์ ์ผ๋จ ๋ง์๋๋ค. ๋ง์ง๋ง์ ์คํํ ๋ ์ด ๋ถ๋ถ์ ์ฃผ์์ฒ๋ฆฌ ๋ ๋ถ๋ถ์ ํ์ด์ฃผ๋ฉด ๋๋ค. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif CGuiTestingOneDlg dlg; m_pMainWnd = &dlg; int nResponse = dlg.DoModal(); if (nResponse == IDOK) { } else if (nResponse == IDCANCEL) { } */ return FALSE; }
2. Test Case ์ ์์ฑ ¶
1. ์ฐ์ต ¶
์ผ๋จ, ์ ๋๋ก ์๋ํ๋์ง ์์๋ณด๊ธฐ ์ํด ์ฐ์ต๊ฒธ m_bFlag ๋ณ์๋ฅผ ๋ง๋ค์ด์ ํ
์คํธ๋ฅผ ํ๋ค.
ํ ์คํธ | ํต๊ณผ์ ์์๋๋ ๊ฒฐ๊ณผ |
test1One | ์ฐ์ต๊ฒธ Assert Equals. 10 == 10 |
test2GuiOne | ๋ฒํผ์ด ๋๋ฌ์ก์ ๊ฒฝ์ฐ์ CGuiTestingOneDlg::m_bFlag ๊ฐ true ์ํ๊ฐ ๋๋ค. |
~cpp #include <cppunit/TestCase.h> #include <cppunit/Extensions/HelperMacros.h> #include "stdafx.h" // resource, mfc ๋ฅผ ์ด์ฉํ ์ ์๋ค. #include "GuiTestingOneDlg.h" // import GuiTestingOneDlg class GuiTestCase : public CppUnit::TestCase { CPPUNIT_TEST_SUITE(GuiTestCase); CPPUNIT_TEST ( test1One ); CPPUNIT_TEST ( test2GuiOne ); CPPUNIT_TEST ( test3ListAdd ); CPPUNIT_TEST_SUITE_END(); public: CGuiTestingOneDlg* pDlg; void setUp () { pDlg = new CGuiTestingOneDlg(); pDlg->Create(IDD_GUITESTINGONE_DIALOG); } void tearDown () { delete pDlg; } public: void test1One () { CPPUNIT_ASSERT_EQUAL (10, 10); } void test2GuiOne () { pDlg->OnButtonadd(); CPPUNIT_ASSERT_EQUAL (true, pDlg->m_bFlag); } };
์ฝ๋ ์ถ๊ฐ
~cpp void CGuiTestingOneDlg::OnButtonadd() { // TODO: Add your control notification handler code here m_bFlag = true; }
2. ํ ์คํธ ์ถ๊ฐ ¶
ํ ์คํธ | ํต๊ณผ์ ์์๋๋ ๊ฒฐ๊ณผ |
test1One | ์ฐ์ต๊ฒธ Assert Equals. 10 == 10 |
test2GuiOne | ๋ฒํผ์ด ๋๋ฌ์ก์ ๊ฒฝ์ฐ์ CGuiTestingOneDlg::m_bFlag ๊ฐ true ์ํ๊ฐ ๋๋ค. |
test3ListAdd | Editbox ์ "Testing..." ์ ์ ํ . ๋ฒํผ์ ๋๋ ์ ๋ Listbox ์ item ๊ฐฏ์๊ฐ 1๊ฐ์์ ํ์ธ |
. | Listbox ์ ์ฒซ๋ฒ์งธ item ์ ์คํธ๋ง์ด "Testing..." ์์ ํ์ธ |
~cpp void test3ListAdd () { pDlg->m_ctlEdit.SetWindowText("Testing..."); pDlg->OnButtonadd(); CPPUNIT_ASSERT_EQUAL (1, pDlg->m_ctlList.GetCount()); CString str; pDlg->m_ctlList.GetText(0, str); CPPUNIT_ASSERT ( isSameString(str, "Testing...")); } bool isSameString (CString& str1, PSTR str2) { return str1.Compare(str2) == 0; } };
์ฝ๋ ์ถ๊ฐ
~cpp void CGuiTestingOneDlg::OnButtonadd() { // TODO: Add your control notification handler code here m_bFlag = true; CString str; m_ctlEdit.GetWindowText(str); m_ctlList.AddString(str); }
3. more... ¶
ํ ์คํธ | ํต๊ณผ์ ์์๋๋ ๊ฒฐ๊ณผ |
test1One | ์ฐ์ต๊ฒธ Assert Equals. 10 == 10 |
test2GuiOne | ๋ฒํผ์ด ๋๋ฌ์ก์ ๊ฒฝ์ฐ์ CGuiTestingOneDlg::m_bFlag ๊ฐ true ์ํ๊ฐ ๋๋ค. |
test3ListAdd | Editbox ์ "Testing..." ์ ์ ํ . ๋ฒํผ์ ๋๋ ์ ๋ Listbox ์ item ๊ฐฏ์๊ฐ 1๊ฐ์์ ํ์ธ |
. | Listbox ์ ์ฒซ๋ฒ์งธ item ์ ๋ฌธ์์ด์ด "Testing..." ์์ ํ์ธ |
test4ListAddMore | test3 ์ ์ถ๊ฐ๋ ํํ. Editbox ์ ๋ค์ "Testing2..." ๋ฅผ ์ ํ ํ๊ณ , ๋ฒํผ์ ๋๋ ์ ๋ Listbox ์ item ๊ฐฏ์๊ฐ 2๊ฐ์์ ํ์ธ |
. | Listbox ์ ๋๋ฒ์งธ item ์ ๋ฌธ์์ด์ด "Testing2..." ์์ ํ์ธ |
~cpp void test4ListAddMore () { test3ListAdd(); CString str; pDlg->m_ctlEdit.SetWindowText("Testing2..."); pDlg->OnButtonadd(); CPPUNIT_ASSERT_EQUAL (2, pDlg->m_ctlList.GetCount()); pDlg->m_ctlList.GetText(1, str); CPPUNIT_ASSERT ( isSameString(str, "Testing2...")); }
4. 'List box ์์์ ์ปค์๋ ์ฑ์์ง ๊ธ์ ์์นํ๋ค' ์ ๋ํ ํ ์คํธ ¶
ํ ์คํธ | ํต๊ณผ์ ์์๋๋ ๊ฒฐ๊ณผ |
test1One | ์ฐ์ต๊ฒธ Assert Equals. 10 == 10 |
test2GuiOne | ๋ฒํผ์ด ๋๋ฌ์ก์ ๊ฒฝ์ฐ์ CGuiTestingOneDlg::m_bFlag ๊ฐ true ์ํ๊ฐ ๋๋ค. |
test3ListAdd | Editbox ์ "Testing..." ์ ์ ํ . ๋ฒํผ์ ๋๋ ์ ๋ Listbox ์ item ๊ฐฏ์๊ฐ 1๊ฐ์์ ํ์ธ |
. | Listbox ์ ์ฒซ๋ฒ์งธ item ์ ๋ฌธ์์ด์ด "Testing..." ์์ ํ์ธ |
test4ListAddMore | test3 ์ ์ถ๊ฐ๋ ํํ. Editbox ์ ๋ค์ "Testing2..." ๋ฅผ ์ ํ ํ๊ณ , ๋ฒํผ์ ๋๋ ์ ๋ Listbox ์ item ๊ฐฏ์๊ฐ 2๊ฐ์์ ํ์ธ |
. | Listbox ์ ๋๋ฒ์งธ item ์ ๋ฌธ์์ด์ด "Testing2..." ์์ ํ์ธ |
test5ListCursorOne | test3 ์งํ์ ์ ํ๋ Item ์ด 0 ๋ฒ์งธ ์์ ํ์ธ |
test6ListCursorTwo | test4 ์งํ์ ์ ํ๋ Item ์ด 1 ๋ฒ์งธ ์์ ํ์ธ |
~cpp void test5ListCursorOne () { test3ListAdd(); CPPUNIT_ASSERT_EQUAL(0, pDlg->m_ctlList.GetCurSel()); } void test6ListCursorTwo () { test4ListAddMore(); CPPUNIT_ASSERT_EQUAL(1, pDlg->m_ctlList.GetCurSel()); }
์ฝ๋ ์ถ๊ฐ
~cpp void CGuiTestingOneDlg::OnButtonadd() { // TODO: Add your control notification handler code here CString str; m_ctlEdit.GetWindowText(str); m_ctlList.AddString(str); m_ctlList.SetCurSel(m_ctlList.GetCount()-1); m_bFlag = true; }
5. edit box ์ ๋ด์ฉ์ด ๋ฐ์ดํฐ ์ถ๊ฐํ ์ด๊ธฐํ ๋๋์ง ํ์ธ ¶
ํ ์คํธ | ํต๊ณผ์ ์์๋๋ ๊ฒฐ๊ณผ |
test1One | ์ฐ์ต๊ฒธ Assert Equals. 10 == 10 |
test2GuiOne | ๋ฒํผ์ด ๋๋ฌ์ก์ ๊ฒฝ์ฐ์ CGuiTestingOneDlg::m_bFlag ๊ฐ true ์ํ๊ฐ ๋๋ค. |
test3ListAdd | Editbox ์ "Testing..." ์ ์ ํ . ๋ฒํผ์ ๋๋ ์ ๋ Listbox ์ item ๊ฐฏ์๊ฐ 1๊ฐ์์ ํ์ธ |
. | Listbox ์ ์ฒซ๋ฒ์งธ item ์ ๋ฌธ์์ด์ด "Testing..." ์์ ํ์ธ |
test4ListAddMore | test3 ์ ์ถ๊ฐ๋ ํํ. Editbox ์ ๋ค์ "Testing2..." ๋ฅผ ์ ํ ํ๊ณ , ๋ฒํผ์ ๋๋ ์ ๋ Listbox ์ item ๊ฐฏ์๊ฐ 2๊ฐ์์ ํ์ธ |
. | Listbox ์ ๋๋ฒ์งธ item ์ ๋ฌธ์์ด์ด "Testing2..." ์์ ํ์ธ |
test5ListCursorOne | test3 ์งํ์ ์ ํ๋ Item ์ด 0 ๋ฒ์งธ ์์ ํ์ธ |
test6ListCursorTwo | test4 ์งํ์ ์ ํ๋ Item ์ด 1 ๋ฒ์งธ ์์ ํ์ธ |
test7EmptyEditbox | test3 ์งํ์ Editbox ์ ์คํธ๋ง์ด ๋น์๋์ง ํ์ธ |
~cpp void test7EmptyEditbox () { test3ListAdd(); CString str; pDlg->m_ctlEdit.GetWindowText(str); CPPUNIT_ASSERT (str.IsEmpty()); }
์ฝ๋ ์ถ๊ฐ
~cpp void CGuiTestingOneDlg::OnButtonadd() { // TODO: Add your control notification handler code here CString str; m_ctlEdit.GetWindowText(str); m_ctlList.AddString(str); m_ctlList.SetCurSel(m_ctlList.GetCount()-1); m_ctlEdit.SetWindowText(""); m_bFlag = true; }
์ฌ๊ธฐ๊น์ง๋ก ์๊ฐํด๋์ ํ
์คํธ๋ค์ด ์ ๋ถ ์๋ฃ. ์์ InitInstance ์ ์จ ๋ฃ์ ์ฃผ์์ ํ๊ณ , ์ค์ ๋ก ์คํํด๋ณด์.
~cpp BOOL CGuiTestingOneApp::InitInstance() { AfxEnableControlContainer(); CppUnit::MfcUi::TestRunner runner; runner.addTest (GuiTestCase::suite()); runner.run(); #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif CGuiTestingOneDlg dlg; m_pMainWnd = &dlg; int nResponse = dlg.DoModal(); if (nResponse == IDOK) { } else if (nResponse == IDCANCEL) { } return FALSE; }