File: regconf.cpp

package info (click to toggle)
wxpython4.0 4.2.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 221,752 kB
  • sloc: cpp: 962,555; python: 230,573; ansic: 170,731; makefile: 51,756; sh: 9,342; perl: 1,564; javascript: 584; php: 326; xml: 200
file content (92 lines) | stat: -rw-r--r-- 3,018 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
///////////////////////////////////////////////////////////////////////////////
// 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"

#include "wx/scopedptr.h"

// ----------------------------------------------------------------------------
// test class
// ----------------------------------------------------------------------------

TEST_CASE("wxRegConfig::ReadWrite", "[regconfig][config][registry]")
{
    wxString app = "wxRegConfigTestCase";
    wxString vendor = "wxWidgets";

    // NOTE: we use wxCONFIG_USE_LOCAL_FILE explicitly to test wxRegConfig
    //       with something different from the default value wxCONFIG_USE_GLOBAL_FILE
    wxScopedPtr<wxConfigBase> config(new wxRegConfig(app, vendor, "", "",
                                                     wxCONFIG_USE_LOCAL_FILE));

    // test writing
    config->SetPath("/group1");
    CHECK( config->Write("entry1", "foo") );
    config->SetPath("/group2");
    CHECK( config->Write("entry1", "bar") );

    CHECK( config->Write("int32", 1234567) );

    // 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) );

    // test reading
    wxString str;
    long dummy;

    config->SetPath("/");
    CHECK( config->GetFirstGroup(str, dummy) );
    CHECK( str == "group1" );
    CHECK( config->Read("group1/entry1", "INVALID DEFAULT") == "foo" );
    CHECK( config->GetNextGroup(str, dummy) );
    CHECK( str == "group2" );
    CHECK( config->Read("group2/entry1", "INVALID DEFAULT") == "bar" );

    CHECK( config->ReadLong("group2/int32", 0) == 1234567 );
    CHECK( config->ReadLongLong("group2/int64", 0) == val64 );

    config->DeleteAll();
}

TEST_CASE("wxRegKey::DeleteFromRedirectedView", "[registry][64bits]")
{
    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);

    REQUIRE( key.Create() );
    CHECK( key.DeleteSelf() );
    CHECK( !key.Exists() );
}

#endif // wxUSE_CONFIG && wxUSE_REGKEY