Move wxRegConfig tests from console sample to a new wxRegConfigTestCase class.

Remove wxRegKey tests from console sample: on newer Windows they only work when run with admin privileges; also we can expect wx[Reg]ConfigTestCase to already check a good number of wxRegKey features.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64466 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Francesco Montorsi
2010-06-02 14:12:07 +00:00
parent df693ed65c
commit 7b8ccf3321
14 changed files with 142 additions and 191 deletions

View File

@@ -120,9 +120,7 @@
#define TEST_MODULE
#define TEST_PATHLIST
#define TEST_PRINTF
#define TEST_REGCONF
#define TEST_REGEX
#define TEST_REGISTRY
#else // #if TEST_ALL
#define TEST_DATETIME
#define TEST_VOLUME
@@ -1927,155 +1925,6 @@ rfg2 (void)
#endif // TEST_PRINTF
// ----------------------------------------------------------------------------
// registry and related stuff
// ----------------------------------------------------------------------------
// this is for MSW only
#ifndef __WXMSW__
#undef TEST_REGCONF
#undef TEST_REGISTRY
#endif
#ifdef TEST_REGCONF
#include "wx/confbase.h"
#include "wx/msw/regconf.h"
#if 0
static void TestRegConfWrite()
{
wxConfig *config = new wxConfig(wxT("myapp"));
config->SetPath(wxT("/group1"));
config->Write(wxT("entry1"), wxT("foo"));
config->SetPath(wxT("/group2"));
config->Write(wxT("entry1"), wxT("bar"));
}
#endif
static void TestRegConfRead()
{
wxRegConfig *config = new wxRegConfig(wxT("myapp"));
wxString str;
long dummy;
config->SetPath(wxT("/"));
wxPuts(wxT("Enumerating / subgroups:"));
bool bCont = config->GetFirstGroup(str, dummy);
while(bCont)
{
wxPuts(str);
bCont = config->GetNextGroup(str, dummy);
}
}
#endif // TEST_REGCONF
#ifdef TEST_REGISTRY
#include "wx/msw/registry.h"
// I chose this one because I liked its name, but it probably only exists under
// NT
static const wxChar *TESTKEY =
wxT("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
static void TestRegistryRead()
{
wxPuts(wxT("*** testing registry reading ***"));
wxRegKey key(TESTKEY);
wxPrintf(wxT("The test key name is '%s'.\n"), key.GetName().c_str());
if ( !key.Open() )
{
wxPuts(wxT("ERROR: test key can't be opened, aborting test."));
return;
}
size_t nSubKeys, nValues;
if ( key.GetKeyInfo(&nSubKeys, NULL, &nValues, NULL) )
{
wxPrintf(wxT("It has %u subkeys and %u values.\n"), nSubKeys, nValues);
}
wxPrintf(wxT("Enumerating values:\n"));
long dummy;
wxString value;
bool cont = key.GetFirstValue(value, dummy);
while ( cont )
{
wxPrintf(wxT("Value '%s': type "), value.c_str());
switch ( key.GetValueType(value) )
{
case wxRegKey::Type_None: wxPrintf(wxT("ERROR (none)")); break;
case wxRegKey::Type_String: wxPrintf(wxT("SZ")); break;
case wxRegKey::Type_Expand_String: wxPrintf(wxT("EXPAND_SZ")); break;
case wxRegKey::Type_Binary: wxPrintf(wxT("BINARY")); break;
case wxRegKey::Type_Dword: wxPrintf(wxT("DWORD")); break;
case wxRegKey::Type_Multi_String: wxPrintf(wxT("MULTI_SZ")); break;
default: wxPrintf(wxT("other (unknown)")); break;
}
wxPrintf(wxT(", value = "));
if ( key.IsNumericValue(value) )
{
long val;
key.QueryValue(value, &val);
wxPrintf(wxT("%ld"), val);
}
else // string
{
wxString val;
key.QueryValue(value, val);
wxPrintf(wxT("'%s'"), val.c_str());
key.QueryRawValue(value, val);
wxPrintf(wxT(" (raw value '%s')"), val.c_str());
}
wxPutchar('\n');
cont = key.GetNextValue(value, dummy);
}
}
static void TestRegistryAssociation()
{
/*
The second call to deleteself genertaes an error message, with a
messagebox saying .flo is crucial to system operation, while the .ddf
call also fails, but with no error message
*/
wxRegKey key;
key.SetName(wxT("HKEY_CLASSES_ROOT\\.ddf") );
key.Create();
key = wxT("ddxf_auto_file") ;
key.SetName(wxT("HKEY_CLASSES_ROOT\\.flo") );
key.Create();
key = wxT("ddxf_auto_file") ;
key.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
key.Create();
key = wxT("program,0") ;
key.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
key.Create();
key = wxT("program \"%1\"") ;
key.SetName(wxT("HKEY_CLASSES_ROOT\\.ddf") );
key.DeleteSelf();
key.SetName(wxT("HKEY_CLASSES_ROOT\\.flo") );
key.DeleteSelf();
key.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
key.DeleteSelf();
key.SetName(wxT("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
key.DeleteSelf();
}
#endif // TEST_REGISTRY
// ----------------------------------------------------------------------------
// FTP
// ----------------------------------------------------------------------------
@@ -2621,22 +2470,10 @@ int main(int argc, char **argv)
TestPrintf();
#endif // TEST_PRINTF
#ifdef TEST_REGCONF
#if 0
TestRegConfWrite();
#endif
TestRegConfRead();
#endif // TEST_REGCONF
#if defined TEST_REGEX && TEST_INTERACTIVE
TestRegExInteractive();
#endif // defined TEST_REGEX && TEST_INTERACTIVE
#ifdef TEST_REGISTRY
TestRegistryRead();
TestRegistryAssociation();
#endif // TEST_REGISTRY
#ifdef TEST_DATETIME
#if TEST_INTERACTIVE
TestDateTimeInteractive();

View File

@@ -62,6 +62,7 @@ TEST_OBJECTS = \
test_base64.o \
test_cmdlinetest.o \
test_fileconf.o \
test_regconf.o \
test_datetimetest.o \
test_evthandler.o \
test_evtsource.o \
@@ -382,6 +383,9 @@ test_cmdlinetest.o: $(srcdir)/cmdline/cmdlinetest.cpp $(TEST_ODEP)
test_fileconf.o: $(srcdir)/config/fileconf.cpp $(TEST_ODEP)
$(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/config/fileconf.cpp
test_regconf.o: $(srcdir)/config/regconf.cpp $(TEST_ODEP)
$(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/config/regconf.cpp
test_datetimetest.o: $(srcdir)/datetime/datetimetest.cpp $(TEST_ODEP)
$(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/datetime/datetimetest.cpp

View File

@@ -7,7 +7,10 @@
// Copyright: (c) 2007 Marcin Wojdyr
///////////////////////////////////////////////////////////////////////////////
// see also tests/fileconf/fileconftest.cpp for wxFileConfig specific tests
// NOTE: this test is compiled in test_gui because it uses wxColour for
// its testing purpose.
// See also tests/config/fileconf.cpp for wxFileConfig specific tests and
// tests/config/regconf.cpp for wxRegConfig specific tests.
// ----------------------------------------------------------------------------
// headers

85
tests/config/regconf.cpp Normal file
View File

@@ -0,0 +1,85 @@
///////////////////////////////////////////////////////////////////////////////
// Name: tests/config/regconf.cpp
// Purpose: wxRegConfig unit test
// Author: Francesco Montorsi (extracted from console sample)
// Created: 2010-06-02
// RCS-ID: $Id$
// Copyright: (c) 2010 wxWidgets team
///////////////////////////////////////////////////////////////////////////////
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#include "testprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_CONFIG && wxUSE_REGKEY
#ifndef WX_PRECOMP
#endif // WX_PRECOMP
#include "wx/msw/regconf.h"
// ----------------------------------------------------------------------------
// test class
// ----------------------------------------------------------------------------
class RegConfigTestCase : public CppUnit::TestCase
{
public:
RegConfigTestCase() { }
private:
CPPUNIT_TEST_SUITE( RegConfigTestCase );
CPPUNIT_TEST( ReadWrite );
CPPUNIT_TEST_SUITE_END();
void ReadWrite();
DECLARE_NO_COPY_CLASS(RegConfigTestCase)
};
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( RegConfigTestCase );
// also include in it's own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RegConfigTestCase, "RegConfigTestCase" );
void RegConfigTestCase::ReadWrite()
{
wxString app = wxT("wxRegConfigTestCase");
wxString vendor = wxT("wxWidgets");
// NOTE: we use wxCONFIG_USE_LOCAL_FILE explicitly to test wxRegConfig
// with something different from the default value wxCONFIG_USE_GLOBAL_FILE
wxConfigBase *config = new wxRegConfig(app, vendor, wxT(""), wxT(""),
wxCONFIG_USE_LOCAL_FILE);
// test writing
config->SetPath(wxT("/group1"));
CPPUNIT_ASSERT( config->Write(wxT("entry1"), wxT("foo")) );
config->SetPath(wxT("/group2"));
CPPUNIT_ASSERT( config->Write(wxT("entry1"), wxT("bar")) );
// test reading
wxString str;
long dummy;
config->SetPath(wxT("/"));
CPPUNIT_ASSERT( config->GetFirstGroup(str, dummy) );
CPPUNIT_ASSERT( str == "group1" );
CPPUNIT_ASSERT( config->Read(wxT("group1/entry1"), wxT("INVALID DEFAULT")) == "foo" );
CPPUNIT_ASSERT( config->GetNextGroup(str, dummy) );
CPPUNIT_ASSERT( str == "group2" );
CPPUNIT_ASSERT( config->Read(wxT("group2/entry1"), wxT("INVALID DEFAULT")) == "bar" );
config->DeleteAll();
delete config;
}
#endif // wxUSE_CONFIG && wxUSE_REGKEY

View File

@@ -46,6 +46,7 @@ TEST_OBJECTS = \
$(OBJS)\test_base64.obj \
$(OBJS)\test_cmdlinetest.obj \
$(OBJS)\test_fileconf.obj \
$(OBJS)\test_regconf.obj \
$(OBJS)\test_datetimetest.obj \
$(OBJS)\test_evthandler.obj \
$(OBJS)\test_evtsource.obj \
@@ -424,6 +425,9 @@ $(OBJS)\test_cmdlinetest.obj: .\cmdline\cmdlinetest.cpp
$(OBJS)\test_fileconf.obj: .\config\fileconf.cpp
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\config\fileconf.cpp
$(OBJS)\test_regconf.obj: .\config\regconf.cpp
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\config\regconf.cpp
$(OBJS)\test_datetimetest.obj: .\datetime\datetimetest.cpp
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\datetime\datetimetest.cpp

View File

@@ -38,6 +38,7 @@ TEST_OBJECTS = \
$(OBJS)\test_base64.o \
$(OBJS)\test_cmdlinetest.o \
$(OBJS)\test_fileconf.o \
$(OBJS)\test_regconf.o \
$(OBJS)\test_datetimetest.o \
$(OBJS)\test_evthandler.o \
$(OBJS)\test_evtsource.o \
@@ -405,6 +406,9 @@ $(OBJS)\test_cmdlinetest.o: ./cmdline/cmdlinetest.cpp
$(OBJS)\test_fileconf.o: ./config/fileconf.cpp
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\test_regconf.o: ./config/regconf.cpp
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\test_datetimetest.o: ./datetime/datetimetest.cpp
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<

View File

@@ -40,6 +40,7 @@ TEST_OBJECTS = \
$(OBJS)\test_base64.obj \
$(OBJS)\test_cmdlinetest.obj \
$(OBJS)\test_fileconf.obj \
$(OBJS)\test_regconf.obj \
$(OBJS)\test_datetimetest.obj \
$(OBJS)\test_evthandler.obj \
$(OBJS)\test_evtsource.obj \
@@ -550,6 +551,9 @@ $(OBJS)\test_cmdlinetest.obj: .\cmdline\cmdlinetest.cpp
$(OBJS)\test_fileconf.obj: .\config\fileconf.cpp
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\config\fileconf.cpp
$(OBJS)\test_regconf.obj: .\config\regconf.cpp
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\config\regconf.cpp
$(OBJS)\test_datetimetest.obj: .\datetime\datetimetest.cpp
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\datetime\datetimetest.cpp

View File

@@ -276,6 +276,7 @@ TEST_OBJECTS = &
$(OBJS)\test_base64.obj &
$(OBJS)\test_cmdlinetest.obj &
$(OBJS)\test_fileconf.obj &
$(OBJS)\test_regconf.obj &
$(OBJS)\test_datetimetest.obj &
$(OBJS)\test_evthandler.obj &
$(OBJS)\test_evtsource.obj &
@@ -462,6 +463,9 @@ $(OBJS)\test_cmdlinetest.obj : .AUTODEPEND .\cmdline\cmdlinetest.cpp
$(OBJS)\test_fileconf.obj : .AUTODEPEND .\config\fileconf.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
$(OBJS)\test_regconf.obj : .AUTODEPEND .\config\regconf.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
$(OBJS)\test_datetimetest.obj : .AUTODEPEND .\datetime\datetimetest.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<

View File

@@ -37,6 +37,7 @@
base64/base64.cpp
cmdline/cmdlinetest.cpp
config/fileconf.cpp
config/regconf.cpp
datetime/datetimetest.cpp
events/evthandler.cpp
events/evtsource.cpp

View File

@@ -405,6 +405,10 @@ SOURCE=.\thread\queue.cpp
# End Source File
# Begin Source File
SOURCE=.\config\regconf.cpp
# End Source File
# Begin Source File
SOURCE=.\regex\regextest.cpp
# End Source File
# Begin Source File

View File

@@ -739,6 +739,9 @@
<File
RelativePath=".\thread\queue.cpp">
</File>
<File
RelativePath=".\config\regconf.cpp">
</File>
<File
RelativePath=".\regex\regextest.cpp">
</File>

View File

@@ -1059,6 +1059,10 @@
RelativePath=".\thread\queue.cpp"
>
</File>
<File
RelativePath=".\config\regconf.cpp"
>
</File>
<File
RelativePath=".\regex\regextest.cpp"
>

View File

@@ -44,7 +44,7 @@
Name="VCCLCompilerTool"
AdditionalOptions="/MP"
Optimization="0"
AdditionalIncludeDirectories=".\..\lib\vc_lib\mswud;.\..\include;F:\cppunit\include;."
AdditionalIncludeDirectories=".\..\lib\vc_lib\mswud;.\..\include;.;F:\cppunit\include"
PreprocessorDefinitions="WIN32;_DEBUG;__WXMSW__;_UNICODE;_CONSOLE;wxUSE_GUI=0"
ExceptionHandling="1"
BasicRuntimeChecks="3"
@@ -1023,6 +1023,10 @@
RelativePath=".\thread\queue.cpp"
>
</File>
<File
RelativePath=".\config\regconf.cpp"
>
</File>
<File
RelativePath=".\regex\regextest.cpp"
>

View File

@@ -1,16 +1,10 @@
<?xml version="1.0" encoding="Windows-1252"?>
<!--
This project was generated by
Bakefile 0.2.8 (http://www.bakefile.org)
Do not modify, all changes will be overwritten!
-->
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Version="9,00"
Name="test_gui"
ProjectGUID="{9BB295D9-A6AA-510D-AA0D-9375B5D91025}"
TargetFrameworkVersion="0"
>
<Platforms>
<Platform
@@ -18,7 +12,6 @@
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
@@ -51,7 +44,7 @@
Name="VCCLCompilerTool"
AdditionalOptions="/MP"
Optimization="0"
AdditionalIncludeDirectories=".\..\lib\vc_lib\mswud;.\..\include;.;.\..\samples"
AdditionalIncludeDirectories=".\..\lib\vc_lib\mswud;.\..\include;.;.\..\samples;f:\cppunit\include"
PreprocessorDefinitions="WIN32;_DEBUG;__WXMSW__;_UNICODE;NOPCH;_CONSOLE"
ExceptionHandling="1"
BasicRuntimeChecks="3"
@@ -86,7 +79,7 @@
OutputFile="vc_mswud\test_gui.exe"
LinkIncremental="2"
SuppressStartupBanner="true"
AdditionalLibraryDirectories=".\..\lib\vc_lib"
AdditionalLibraryDirectories=".\..\lib\vc_lib;f:\cppunit\lib"
GenerateManifest="true"
GenerateDebugInformation="true"
ProgramDatabaseFile="vc_mswud\test_gui.pdb"
@@ -104,8 +97,8 @@
/>
<Tool
Name="VCBscMakeTool"
OutputFile="vc_mswud\test_vc9_test_gui.bsc"
SuppressStartupBanner="true"
OutputFile="vc_mswud\test_vc9_test_gui.bsc"
/>
<Tool
Name="VCFxCopTool"
@@ -185,9 +178,9 @@
GenerateDebugInformation="true"
ProgramDatabaseFile="vc_mswu\test_gui.pdb"
SubSystem="1"
TargetMachine="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
@@ -200,8 +193,8 @@
/>
<Tool
Name="VCBscMakeTool"
OutputFile="vc_mswu\test_vc9_test_gui.bsc"
SuppressStartupBanner="true"
OutputFile="vc_mswu\test_vc9_test_gui.bsc"
/>
<Tool
Name="VCFxCopTool"
@@ -296,8 +289,8 @@
/>
<Tool
Name="VCBscMakeTool"
OutputFile="vc_mswunivud\test_vc9_test_gui.bsc"
SuppressStartupBanner="true"
OutputFile="vc_mswunivud\test_vc9_test_gui.bsc"
/>
<Tool
Name="VCFxCopTool"
@@ -377,9 +370,9 @@
GenerateDebugInformation="true"
ProgramDatabaseFile="vc_mswunivu\test_gui.pdb"
SubSystem="1"
TargetMachine="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
@@ -392,8 +385,8 @@
/>
<Tool
Name="VCBscMakeTool"
OutputFile="vc_mswunivu\test_vc9_test_gui.bsc"
SuppressStartupBanner="true"
OutputFile="vc_mswunivu\test_vc9_test_gui.bsc"
/>
<Tool
Name="VCFxCopTool"
@@ -488,8 +481,8 @@
/>
<Tool
Name="VCBscMakeTool"
OutputFile="vc_mswuddll\test_vc9_test_gui.bsc"
SuppressStartupBanner="true"
OutputFile="vc_mswuddll\test_vc9_test_gui.bsc"
/>
<Tool
Name="VCFxCopTool"
@@ -569,9 +562,9 @@
GenerateDebugInformation="true"
ProgramDatabaseFile="vc_mswudll\test_gui.pdb"
SubSystem="1"
TargetMachine="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
@@ -584,8 +577,8 @@
/>
<Tool
Name="VCBscMakeTool"
OutputFile="vc_mswudll\test_vc9_test_gui.bsc"
SuppressStartupBanner="true"
OutputFile="vc_mswudll\test_vc9_test_gui.bsc"
/>
<Tool
Name="VCFxCopTool"
@@ -680,8 +673,8 @@
/>
<Tool
Name="VCBscMakeTool"
OutputFile="vc_mswunivuddll\test_vc9_test_gui.bsc"
SuppressStartupBanner="true"
OutputFile="vc_mswunivuddll\test_vc9_test_gui.bsc"
/>
<Tool
Name="VCFxCopTool"
@@ -761,9 +754,9 @@
GenerateDebugInformation="true"
ProgramDatabaseFile="vc_mswunivudll\test_gui.pdb"
SubSystem="1"
TargetMachine="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
@@ -776,8 +769,8 @@
/>
<Tool
Name="VCBscMakeTool"
OutputFile="vc_mswunivudll\test_vc9_test_gui.bsc"
SuppressStartupBanner="true"
OutputFile="vc_mswunivudll\test_vc9_test_gui.bsc"
/>
<Tool
Name="VCFxCopTool"
@@ -791,7 +784,6 @@
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
@@ -1000,7 +992,5 @@
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>