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

📄 configstoretest.cpp

📁 一个小巧的嵌入式图形系统wGUI, 可以用VC编译
💻 CPP
字号:
// ConfigStoreTest.cpp//// test application for the wGui CConfigStore class////// Copyright (c) 2002 Rob Wiskow// rob-dev@boxedchaos.com//// This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public// License as published by the Free Software Foundation; either// version 2.1 of the License, or (at your option) any later version.//// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public// License along with this library; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA//#ifndef DEBUG	// Fixes the warnings from xtree in Release builds	#pragma warning (disable : 4702)#endif  // DEBUG#include "wgui.h"#include <iostream>using namespace std;using namespace wGui;class CTestView : public CView{public:	CTestView(void);	void DoTest(void);	virtual bool HandleMessage(CMessage* pMessage);protected:	CButton* m_pRunTestButton;	CButton* m_pExitButton;	CLabel* m_pResultLabel;};class CTestApp : public CApplication{public:	CTestApp(int argc, char **argv) : CApplication(argc, argv) { m_pTestView = 0; }	~CTestApp(void) { delete m_pTestView; }	virtual void Init(void)	{		CApplication::Init();		m_pTestView = new CTestView();	}protected:	CTestView* m_pTestView;};CTestView::CTestView(void) :	CView(CRect(0, 0, 300, 100), "Config Store Test", true){	SetWindowText(std::string("Config Store Test - wGui version ") + CwgStringResourceHandle(WGRES_VERSION_STRING).String());	m_pRunTestButton = new CButton(ClientToScreen(CRect(20, 20, 140, 40)), this, "Run Test");	m_pExitButton = new CButton(ClientToScreen(CRect(160, 20, 280, 40)), this, "Exit");	m_pResultLabel = new CLabel(ClientToScreen(CRect(20, 50, 280, 70)), this, "Ready to test.");	CMessageServer::Instance().RegisterMessageClient(this, CMessage::CTRL_LCLICK);}void CTestView::DoTest(void){	int iFailCount = 0;	m_pResultLabel->SetWindowText("Running tests...");	CConfigStore TestStore;	TestStore.ReadFromFile("ConfigStoreTest.conf");	if (! TestStore.EntryExists("TESTSTRING"))	{		iFailCount++;		Trace("Failed #1 EntryExists(TESTSTRING)");	}	if (TestStore.EntryExists("I DO NOT EXIST"))	{		iFailCount++;		Trace("Failed #2 EntryExists(I DO NOT EXIST)");	}	if (! TestStore.GetStringEntry("TESTSTRING").first)	{		iFailCount++;		Trace("Failed #3 GetStringEntry()");	}	if (TestStore.GetStringEntry("I DO NOT EXIST").first)	{		iFailCount++;		Trace("Failed #4 GetStringEntry()");	}	if (TestStore.GetStringEntry("TESTSTRING").second != "I am not the droid you are looking for.")	{		iFailCount++;		Trace("Failed #5 GetStringEntry()");	}	if (TestStore.GetStringEntry("TestString").second != "I AM the droid you are looking for!")	{		iFailCount++;		Trace("Failed #6 GetStringEntry()");	}	if (TestStore.GetLongIntEntry("TESTINT").second != 42)	{		iFailCount++;		Trace("Failed #7 GetLongIntEntry()");	}	if (TestStore.GetDoubleEntry("TESTDOUBLE").second != 3.14159)	{		iFailCount++;		Trace("Failed #8 GetDoubleEntry()");	}	if (TestStore.GetStringEntry("TESTNUL").second != "")	{		iFailCount++;		Trace("Failed #9 GetStringEntry()");	}	if (TestStore.GetLongIntEntry("TESTNUL").second != 0)	{		iFailCount++;		Trace("Failed #10 GetLongIntEntry()");	}	if (TestStore.GetDoubleEntry("TESTNUL").second != 0.0)	{		iFailCount++;		Trace("Failed #11 GetDoubleEntry()");	}	if (TestStore.GetStringEntry("SPACINGTEST1").second != "There is no space.")	{		iFailCount++;		Trace("Failed #12 GetStringEntry()");	}	if (TestStore.GetStringEntry("SPACINGTEST2").second != "There is too much space here.")	{		iFailCount++;		Trace("Failed #13 GetStringEntry()");	}	if (TestStore.GetLongIntEntry("Complex Name").second != 21)	{		iFailCount++;		Trace("Failed #14 GetLongIntEntry()");	}	if (TestStore.GetStringEntry("Complex Name").second != "21")	{		iFailCount++;		Trace("Failed #15 GetStringEntry()");	}	if (TestStore.GetStringEntry("Name with !s").second != "yes")	{		iFailCount++;		Trace("Failed #16 GetStringEntry()");	}	TestStore.Clear();	if (TestStore.EntryExists("TESTSTRING"))	{		iFailCount++;		Trace("Failed #17 EntryExists()");	}	TestStore.SetStringEntry("TESTSTRING", "Value 1");	TestStore.SetLongIntEntry("TESTINT", 2003);	TestStore.SetDoubleEntry("TESTDOUBLE", 3.022);	TestStore.StoreToFile("test.conf");	TestStore.Clear();	if (TestStore.EntryExists("TESTSTRING"))	{		iFailCount++;		Trace("Failed #18 EntryExists()");	}	TestStore.ReadFromFile("test.conf");	if (TestStore.GetStringEntry("TESTSTRING").second != "Value 1")	{		iFailCount++;		Trace("Failed #19 GetStringEntry");	}	if (TestStore.GetLongIntEntry("TESTINT").second != 2003)	{		iFailCount++;		Trace("Failed #20 GetLongIntEntry");	}	if (TestStore.GetDoubleEntry("TESTDOUBLE").second != 3.022)	{		iFailCount++;		Trace("Failed #21 GetDoubleEntry");	}	Trace("Tests finished. " + stdex::itoa(iFailCount) + " tests failed.");	if (iFailCount > 0)	{		m_pResultLabel->SetWindowText("Tests finished.  " + stdex::itoa(iFailCount) + " tests failed.");	}	else	{		m_pResultLabel->SetWindowText("Tests finished.  All tests passed.");	}}bool CTestView::HandleMessage(CMessage* pMessage){	bool bHandled = false;	if (pMessage)	{		switch (pMessage->MessageType())		{		case CMessage::CTRL_LCLICK:		{			if (pMessage->Destination() == this)			{				if (pMessage->Source() == m_pRunTestButton)				{				  DoTest();					bHandled = true;				}				else if (pMessage->Source() == m_pExitButton)				{					CMessageServer::Instance().QueueMessage(new CMessage(CMessage::APP_EXIT, 0, this));					bHandled = true;				}			}		}		default:			bHandled = CView::HandleMessage(pMessage);			break;		}	}	return bHandled;}int main(int argc, char **argv){	int iExitCode = EXIT_FAILURE;	try	{		CTestApp TestApp(argc, argv);		TestApp.Init();		TestApp.Exec();		iExitCode = TestApp.ExitCode();	}	catch (Wg_Ex_Base& e)	{		cerr << "Unhandled wGui exception : " << e.std_what() << endl;		exit(EXIT_FAILURE);	}	catch (exception& e)	{		cerr << "Unhandled std exception : " << e.what() << endl;		exit(EXIT_FAILURE);	}	catch (...)	{		cerr << "Unhandled exception." << endl;		exit(EXIT_FAILURE);	}	exit(iExitCode);}

⌨️ 快捷键说明

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