⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainfrm.cpp

📁 分别用贪心算法和启发式算法对测试用例集进行了最小化。
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "RWXML8.h"

#include "MainFrm.h"
#include "FirstDlg.h"
#include "SecondDlg.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMainFrame
//CString csSN;
//CString st;
//CString *cspTemp1,*cspTemp2,*cspTemp3,*cspTemp4,*cspTemp5,*cspTemp6;




//TestCaseNode* TestSuite=new TestCaseNode;


IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_COMMAND(ID_TEST_DLG2, OnTestDlg2)
	ON_COMMAND(ID_TEST_DLG1, OnTestDlg1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here
	
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}

	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);

	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers


//DEL void CMainFrame::OnTestDlg() 
//DEL {
//DEL 	// TODO: Add your command handler code here
//DEL 	CFirstDlg *pDlg=new CFirstDlg;
//DEL 	pDlg->Create(IDD_DIALOG1);
//DEL 	pDlg->ShowWindow(SW_NORMAL);
//DEL 
//DEL }

void CMainFrame::OnTestDlg1() 
{
	// TODO: Add your command handler code here
	CFirstDlg *pDlg1=new CFirstDlg;
//	pDlg1->SetDlgItemInt(IDC_STATIC1,1223,TRUE);
//	pDlg1->OnShowStatic(cspTemp1);
	pDlg1->Create(IDD_DIALOG1);
	pDlg1->ShowWindow(SW_NORMAL);
}

void CMainFrame::OnTestDlg2() 
{
	// TODO: Add your command handler code here
	CSecondDlg *pDlg2=new CSecondDlg;
	pDlg2->Create(IDD_DIALOG2);
	pDlg2->ShowWindow(SW_NORMAL);

}


//DEL void CMainFrame::OnFileOpen() 
//DEL {
//DEL 	// TODO: Add your command handler code here
//DEL 	CString FilePathName ; 
//DEL 	CFile m_File; 
//DEL 	CFileDialog m_Dlg(true); 
//DEL 	if(m_Dlg.DoModal() == IDOK) 
//DEL 		FilePathName = m_Dlg.GetPathName();
//DEL 	CString xmlText;
//DEL 	if(!ReadFile(FilePathName, xmlText)) return;
//DEL 
//DEL //	m_File.Open(FilePathName,CFile::modeRead);
//DEL 	CMarkup Xml;
//DEL 	Xml.SetDoc(xmlText);
//DEL 	Xml.ResetPos();
//DEL 	for(int i=1;i<=Xml);
//DEL 	Xml.FindElem("TS");
//DEL 	int TestCaseCount=Xml.GetAttrib(TCCount);
//DEL 	
//DEL 
//DEL }


//DEL BOOL CMainFrame::ReadFile(const CString& xmlFile, CString& xmlText)
//DEL {
//DEL     // This code derived from Ben Bryant's MarkupDlg.cpp file.
//DEL 
//DEL     // Open file.
//DEL     CFile file;
//DEL     if ( !file.Open(xmlFile, CFile::modeRead) )
//DEL     {
//DEL         return FALSE;
//DEL     }
//DEL     int nFileLen = (int)file.GetLength();
//DEL 
//DEL     // Allocate buffer for binary file data.
//DEL     unsigned char* pBuffer = new unsigned char[nFileLen + 2];
//DEL     nFileLen = file.Read( pBuffer, nFileLen );
//DEL     file.Close();
//DEL     pBuffer[nFileLen] = '\0';
//DEL     pBuffer[nFileLen+1] = '\0'; // in case 2-byte encoded
//DEL 
//DEL     // Windows Unicode file is detected if starts with FEFF.
//DEL     if ( pBuffer[0] == 0xff && pBuffer[1] == 0xfe )
//DEL     {
//DEL         // Contains byte order mark, so assume wide char content.
//DEL         // Non _UNICODE builds should perform UCS-2 (wide char) to UTF-8 conversion here.
//DEL         xmlText = (LPCWSTR)(&pBuffer[2]);
//DEL     }
//DEL     else
//DEL     {
//DEL         // _UNICODE builds should perform UTF-8 to UCS-2 (wide char) conversion here.
//DEL         xmlText = (LPCSTR)pBuffer;
//DEL     }
//DEL     delete [] pBuffer;
//DEL 
//DEL     // If it is too short, assume it got truncated due to non-text content.
//DEL     if ( xmlText.GetLength() < nFileLen / 2 - 20 )
//DEL     {
//DEL         return FALSE;
//DEL     }
//DEL 
//DEL     return TRUE;
//DEL }



//////////////////////////////////////////////////////////////////////////////////////
//////函数OnMinBegain()主要用来实现最小化操作:读入xml文件,将测试用例与段、点的对应情况
//////分析储存到二维数组,用GRE启发式算法来最小化测试用例
//////作者:张美玲 2008-11-26
/*
struct Point_Node{
int data;
Point_Node* next;
};

struct TestCaseNode{
int TC_ID;
int TC_Seg_Count;
int TC_Point_Count;
Point_Node *PointList;
Point_Node *SegmentList;
int Time;
}TestCase;
TestCaseNode* TestSuite;
*/
//////////////////////////////////////////////////////////////////////////////////////

//DEL void CMainFrame::OnMinBegain() 
//DEL {
//DEL 	// TODO: Add your command handler code here
//DEL 	int TCID;
//DEL 	CString csTCID;
//DEL 	int TCCount;
//DEL 	CString csTCCount;
//DEL //	int TCTime;
//DEL 
//DEL 	int PointCount;
//DEL 	CString csPointCount;
//DEL 	int SegCount;
//DEL 	CString csSegmentCount;
//DEL 
//DEL 	CMarkup xml;
//DEL 
//DEL 	xml.Load("TestSuite.xml");
//DEL 	xml.FindElem("TS");
//DEL 	csTCCount = xml.GetAttrib("TestCaseCount");
//DEL 	TCCount=atoi(xml.GetAttrib("TestCaseCount"));
//DEL 	xml.FindChildElem("TC");
//DEL 
//DEL //依次取出每个测试用例的每个域值放在链表TestSuite
//DEL 	for(int i=0;i<TCCount;i++)
//DEL 	{
//DEL 		xml.IntoElem();
//DEL 
//DEL 
//DEL //测试用例编号
//DEL 		cspTemp1 = &xml.GetAttrib("ID");
//DEL 		cspTemp1++;
//DEL 		TCID=atoi(xml.GetAttrib("ID"));
//DEL 		TestSuite[i].TC_ID=TCID;
//DEL 		
//DEL 
//DEL 
//DEL //测试用例执行完所用时间
//DEL 		cspTemp2=&xml.GetAttrib("Time");
//DEL 		cspTemp2++;
//DEL //		TCTime=atoi(xml.GetAttrib("Time"));
//DEL 		TestSuite[i].Time=atoi(xml.GetAttrib("Time"));
//DEL 
//DEL 
//DEL //测试用例对应的各个点
//DEL 		xml.FindChildElem("Point");
//DEL 	
//DEL 		csPointCount=xml.GetAttrib("PointCount");
//DEL 		cspTemp3=&xml.GetAttrib("PointCount");
//DEL 		cspTemp3++;
//DEL 		PointCount=atoi(xml.GetAttrib("PointCount"));
//DEL 		TestSuite[i].TC_Point_Count=atoi(xml.GetAttrib("PointCount"));
//DEL 
//DEL 		xml.IntoElem();
//DEL 		xml.FindChildElem("PElement");
//DEL 		for(int j=0;j<PointCount;j++)
//DEL 		{
//DEL 			cspTemp4=&xml.GetData();
//DEL 			cspTemp4++;
//DEL 			TestSuite[i].PointList[j]=atoi(xml.GetElemContent());
//DEL //			TestSuite->PointList=TestSuite->PointList->next;
//DEL 
//DEL 		}//每个测试用例中的点循环
//DEL 		xml.OutOfElem();
//DEL 	
//DEL 
//DEL 		
//DEL 		
//DEL 
//DEL //测试用例对应的各个段
//DEL 		xml.FindChildElem("Segment");
//DEL 	
//DEL 		csSegmentCount=xml.GetAttrib("SegCount");
//DEL 		cspTemp5=&xml.GetAttrib("SegCount");
//DEL 		cspTemp5++;
//DEL 		SegCount=atoi(xml.GetAttrib("SegCount"));
//DEL 		TestSuite[i].TC_Seg_Count=atoi(xml.GetAttrib("SegCount"));
//DEL 
//DEL 		xml.IntoElem();
//DEL 		xml.FindElem("SElement");
//DEL 		for(int k=0;k<SegCount;k++)
//DEL 		{
//DEL 			cspTemp6=&xml.GetElemContent();
//DEL 			cspTemp6++;
//DEL 			TestSuite[i].SegmentList[k]=atoi(xml.GetElemContent());			
//DEL //			TestSuite->SegmentList=TestSuite->SegmentList->next;
//DEL 
//DEL 		}//每个测试用例中的段循环
//DEL 		xml.OutOfElem();
//DEL 
//DEL 		
//DEL 
//DEL 		xml.OutOfElem();
//DEL 		xml.FindElem("TC");		
//DEL /*
//DEL //////////////////////////////////////////////////////////////////////////////////
//DEL //下面两句话显示一个提示框来验证是否获得了xml文件中的数据
//DEL 	int nChoice = MessageBox(csTime,"Number1",MB_YESNOCANCEL|MB_ICONQUESTION );
//DEL 	if(nChoice==IDYES){}
//DEL //////////////////////////////////////////////////////////////////////////////////
//DEL */
//DEL 	}//整个测试用例集的循环      
//DEL 
//DEL /*
//DEL 	for(int m=0;m<TestSuite.size();m++)
//DEL 	{
//DEL 		char* ch=cspTemp1->GetBuffer(TestSuite[i].TC_ID);
//DEL 		int nChoice = MessageBox(ch,"Number1",MB_YESNOCANCEL|MB_ICONQUESTION );
//DEL 		cspTemp1++;
//DEL 		if(nChoice==IDYES){}
//DEL 
//DEL 	}
//DEL 
//DEL   */
//DEL }


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -