2010-06-02 10:12:07 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: tests/config/regconf.cpp
|
|
|
|
// Purpose: wxRegConfig unit test
|
|
|
|
// Author: Francesco Montorsi (extracted from console sample)
|
|
|
|
// Created: 2010-06-02
|
|
|
|
// Copyright: (c) 2010 wxWidgets team
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "testprec.h"
|
|
|
|
|
|
|
|
|
|
|
|
#if wxUSE_CONFIG && wxUSE_REGKEY
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#endif // WX_PRECOMP
|
|
|
|
|
|
|
|
#include "wx/msw/regconf.h"
|
|
|
|
|
2021-03-09 11:00:23 -05:00
|
|
|
#include "wx/scopedptr.h"
|
|
|
|
|
2010-06-02 10:12:07 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// test class
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2021-03-09 10:34:21 -05:00
|
|
|
TEST_CASE("wxRegConfig::ReadWrite", "[regconfig][config][registry]")
|
2010-06-02 10:12:07 -04:00
|
|
|
{
|
2021-03-09 11:02:12 -05:00
|
|
|
wxString app = "wxRegConfigTestCase";
|
|
|
|
wxString vendor = "wxWidgets";
|
2010-06-02 10:12:07 -04:00
|
|
|
|
|
|
|
// NOTE: we use wxCONFIG_USE_LOCAL_FILE explicitly to test wxRegConfig
|
|
|
|
// with something different from the default value wxCONFIG_USE_GLOBAL_FILE
|
2021-03-09 11:02:12 -05:00
|
|
|
wxScopedPtr<wxConfigBase> config(new wxRegConfig(app, vendor, "", "",
|
2021-03-09 11:00:23 -05:00
|
|
|
wxCONFIG_USE_LOCAL_FILE));
|
2010-06-02 10:12:07 -04:00
|
|
|
|
|
|
|
// test writing
|
2021-03-09 11:02:12 -05:00
|
|
|
config->SetPath("/group1");
|
|
|
|
CHECK( config->Write("entry1", "foo") );
|
|
|
|
config->SetPath("/group2");
|
|
|
|
CHECK( config->Write("entry1", "bar") );
|
2010-06-02 10:12:07 -04:00
|
|
|
|
2021-03-09 12:53:46 -05:00
|
|
|
CHECK( config->Write("int32", 1234567) );
|
|
|
|
|
2021-03-09 15:17:26 -05:00
|
|
|
// Note that type of wxLL(0x8000000000000008) literal is somehow unsigned
|
|
|
|
// long long with MinGW, not sure if it's a bug or not, but work around it
|
|
|
|
// by specifying the type explicitly.
|
|
|
|
const wxLongLong_t val64 = wxLL(0x8000000000000008);
|
|
|
|
CHECK( config->Write("int64", val64) );
|
|
|
|
|
2010-06-02 10:12:07 -04:00
|
|
|
// test reading
|
|
|
|
wxString str;
|
|
|
|
long dummy;
|
|
|
|
|
2021-03-09 11:02:12 -05:00
|
|
|
config->SetPath("/");
|
2021-03-09 10:34:21 -05:00
|
|
|
CHECK( config->GetFirstGroup(str, dummy) );
|
|
|
|
CHECK( str == "group1" );
|
2021-03-09 11:02:12 -05:00
|
|
|
CHECK( config->Read("group1/entry1", "INVALID DEFAULT") == "foo" );
|
2021-03-09 10:34:21 -05:00
|
|
|
CHECK( config->GetNextGroup(str, dummy) );
|
|
|
|
CHECK( str == "group2" );
|
2021-03-09 11:02:12 -05:00
|
|
|
CHECK( config->Read("group2/entry1", "INVALID DEFAULT") == "bar" );
|
2010-06-02 10:12:07 -04:00
|
|
|
|
2021-03-09 12:53:46 -05:00
|
|
|
CHECK( config->ReadLong("group2/int32", 0) == 1234567 );
|
2021-03-09 15:17:26 -05:00
|
|
|
CHECK( config->ReadLongLong("group2/int64", 0) == val64 );
|
2021-03-09 12:53:46 -05:00
|
|
|
|
2010-06-02 10:12:07 -04:00
|
|
|
config->DeleteAll();
|
|
|
|
}
|
|
|
|
|
2021-03-09 10:34:21 -05:00
|
|
|
TEST_CASE("wxRegKey::DeleteFromRedirectedView", "[registry][64bits]")
|
2017-05-05 11:28:15 -04:00
|
|
|
{
|
|
|
|
if ( !wxIsPlatform64Bit() )
|
|
|
|
{
|
|
|
|
// Test needs WoW64.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test inside a key that's known to be redirected and is in HKCU so that
|
|
|
|
// admin rights are not required (unlike with HKLM).
|
|
|
|
wxRegKey key(wxRegKey::HKCU, "SOFTWARE\\Classes\\CLSID\\wxWidgetsTestKey",
|
|
|
|
sizeof(void *) == 4
|
|
|
|
? wxRegKey::WOW64ViewMode_64
|
|
|
|
: wxRegKey::WOW64ViewMode_32);
|
|
|
|
|
2021-03-09 10:34:21 -05:00
|
|
|
REQUIRE( key.Create() );
|
|
|
|
CHECK( key.DeleteSelf() );
|
|
|
|
CHECK( !key.Exists() );
|
2017-05-05 11:28:15 -04:00
|
|
|
}
|
|
|
|
|
2010-06-02 10:12:07 -04:00
|
|
|
#endif // wxUSE_CONFIG && wxUSE_REGKEY
|
|
|
|
|