Don't needlessly use wxScopedPtr in wxConfig unit test

Just use objects directly instead of pointers.
This commit is contained in:
Vadim Zeitlin 2023-03-06 23:20:38 +01:00
parent 0f158ac6d2
commit 29a97bb52d
2 changed files with 65 additions and 66 deletions

View file

@ -26,7 +26,6 @@
#endif // WX_PRECOMP
#include "wx/config.h"
#include "wx/scopedptr.h"
// Tests using wxColour can only be done when using GUI library and they
// require template functions that are not supported by some ancient compilers.
@ -46,95 +45,97 @@ TEST_CASE("wxConfig::ReadWriteLocal", "[config]")
{
wxString app = "wxConfigTestCase";
wxString vendor = "wxWidgets";
wxScopedPtr<wxConfig> config(new wxConfig(app, vendor, "", "",
wxCONFIG_USE_LOCAL_FILE));
config->DeleteAll();
config->Write("string1", "abc");
config->Write("string2", wxString("def"));
config->Write("int1", 123);
config->Write(wxString("long1"), 234L);
config->Write("double1", 345.67);
config->Write("bool1", true);
// See comment in regconf.cpp.
const wxLongLong_t val64 = wxLL(0x8000000000000008);
config->Write("ll", val64);
const wxULongLong_t uval64 = wxULL(0x9000000000000009);
config->Write("ull", uval64);
config->Write("size", size_t(UINT_MAX));
{
wxConfig config(app, vendor, "", "", wxCONFIG_USE_LOCAL_FILE);
config.DeleteAll();
config.Write("string1", "abc");
config.Write("string2", wxString("def"));
config.Write("int1", 123);
config.Write(wxString("long1"), 234L);
config.Write("double1", 345.67);
config.Write("bool1", true);
config.Write("ll", val64);
config.Write("ull", uval64);
config.Write("size", size_t(UINT_MAX));
#ifdef TEST_WXCOLOUR
config->Write("color1", wxColour(11,22,33,44));
config.Write("color1", wxColour(11,22,33,44));
#endif // TEST_WXCOLOUR
config->Flush();
config.Flush();
}
config.reset(new wxConfig(app, vendor, "", "",
wxCONFIG_USE_LOCAL_FILE));
wxString string1 = config->Read("string1");
wxConfig config(app, vendor, "", "", wxCONFIG_USE_LOCAL_FILE);
wxString string1 = config.Read("string1");
CHECK( string1 == "abc" );
string1 = config->Read("string1", "defaultvalue");
string1 = config.Read("string1", "defaultvalue");
CHECK( string1 == "abc" );
wxString string2;
bool r = config->Read("string2", &string2);
bool r = config.Read("string2", &string2);
CHECK( r );
CHECK( string2 == "def" );
r = config->Read("string2", &string2, "defaultvalue");
r = config.Read("string2", &string2, "defaultvalue");
CHECK( r );
CHECK( string2 == "def" );
int int1 = config->Read("int1", 5);
int int1 = config.Read("int1", 5);
CHECK( int1 == 123 );
long long1;
r = config->Read("long1", &long1);
r = config.Read("long1", &long1);
CHECK( r );
CHECK( long1 == 234L );
CHECK( config->ReadLong("long1", 0) == 234 );
CHECK( config.ReadLong("long1", 0) == 234 );
double double1;
r = config->Read("double1", &double1);
r = config.Read("double1", &double1);
CHECK( r );
CHECK( double1 == 345.67 );
CHECK( config->ReadDouble("double1", 0) == double1 );
CHECK( config.ReadDouble("double1", 0) == double1 );
bool bool1;
r = config->Read("foo", &bool1); // there is no "foo" key
r = config.Read("foo", &bool1); // there is no "foo" key
CHECK( !r );
r = config->Read("bool1", &bool1);
r = config.Read("bool1", &bool1);
CHECK( r );
CHECK( bool1 == true );
CHECK( config->ReadBool("bool1", false) == bool1 );
CHECK( config.ReadBool("bool1", false) == bool1 );
wxLongLong_t ll;
CHECK( config->Read("ll", &ll) );
CHECK( config.Read("ll", &ll) );
CHECK( ll == val64 );
CHECK( config->ReadLongLong("ll", 0) == val64 );
CHECK( config.ReadLongLong("ll", 0) == val64 );
CHECK( config->Read("ull", &ll) );
CHECK( config.Read("ull", &ll) );
CHECK( ll == static_cast<wxLongLong_t>(uval64) );
CHECK( config->ReadLongLong("ull", 0) == static_cast<wxLongLong_t>(uval64) );
CHECK( config.ReadLongLong("ull", 0) == static_cast<wxLongLong_t>(uval64) );
size_t size;
CHECK( config->Read("size", &size) );
CHECK( config.Read("size", &size) );
CHECK( size == UINT_MAX );
#ifdef TEST_WXCOLOUR
wxColour color1;
r = config->Read("color1", &color1);
r = config.Read("color1", &color1);
CHECK( r );
CHECK( color1 == wxColour(11,22,33,44) );
CHECK( config->ReadObject("color1", wxNullColour) == color1 );
CHECK( config.ReadObject("color1", wxNullColour) == color1 );
#endif // TEST_WXCOLOUR
config->DeleteAll();
config.DeleteAll();
}
// Helper of RecordingDefaultsTest() test.
@ -199,17 +200,16 @@ TEST_CASE("wxConfig::RecordingDefaults", "[config]")
{
wxString app = "wxConfigTestCaseRD";
wxString vendor = "wxWidgets";
wxScopedPtr<wxConfig> config(new wxConfig(app, vendor, "", "",
wxCONFIG_USE_LOCAL_FILE));
config->DeleteAll();
config->SetRecordDefaults(false); // by default it is false
ReadValues(*config, false);
CHECK( config->GetNumberOfEntries() == 0 );
config->SetRecordDefaults(true);
size_t read = ReadValues(*config, false);
CHECK( config->GetNumberOfEntries() == read );
ReadValues(*config, true);
config->DeleteAll();
wxConfig config(app, vendor, "", "", wxCONFIG_USE_LOCAL_FILE);
config.DeleteAll();
config.SetRecordDefaults(false); // by default it is false
ReadValues(config, false);
CHECK( config.GetNumberOfEntries() == 0 );
config.SetRecordDefaults(true);
size_t read = ReadValues(config, false);
CHECK( config.GetNumberOfEntries() == read );
ReadValues(config, true);
config.DeleteAll();
}
#endif //wxUSE_CONFIG

View file

@ -20,7 +20,7 @@
#include "wx/msw/regconf.h"
#include "wx/scopedptr.h"
#include <memory>
// ----------------------------------------------------------------------------
// test class
@ -33,39 +33,38 @@ TEST_CASE("wxRegConfig::ReadWrite", "[regconfig][config][registry]")
// 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));
wxRegConfig config(app, vendor, "", "", wxCONFIG_USE_LOCAL_FILE);
// test writing
config->SetPath("/group1");
CHECK( config->Write("entry1", "foo") );
config->SetPath("/group2");
CHECK( config->Write("entry1", "bar") );
config.SetPath("/group1");
CHECK( config.Write("entry1", "foo") );
config.SetPath("/group2");
CHECK( config.Write("entry1", "bar") );
CHECK( config->Write("int32", 1234567) );
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) );
CHECK( config.Write("int64", val64) );
// test reading
wxString str;
long dummy;
config->SetPath("/");
CHECK( config->GetFirstGroup(str, 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( 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.Read("group2/entry1", "INVALID DEFAULT") == "bar" );
CHECK( config->ReadLong("group2/int32", 0) == 1234567 );
CHECK( config->ReadLongLong("group2/int64", 0) == val64 );
CHECK( config.ReadLong("group2/int32", 0) == 1234567 );
CHECK( config.ReadLongLong("group2/int64", 0) == val64 );
config->DeleteAll();
config.DeleteAll();
}
TEST_CASE("wxRegKey::DeleteFromRedirectedView", "[registry][64bits]")