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

View file

@ -20,7 +20,7 @@
#include "wx/msw/regconf.h" #include "wx/msw/regconf.h"
#include "wx/scopedptr.h" #include <memory>
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// test class // test class
@ -33,39 +33,38 @@ TEST_CASE("wxRegConfig::ReadWrite", "[regconfig][config][registry]")
// NOTE: we use wxCONFIG_USE_LOCAL_FILE explicitly to test wxRegConfig // NOTE: we use wxCONFIG_USE_LOCAL_FILE explicitly to test wxRegConfig
// with something different from the default value wxCONFIG_USE_GLOBAL_FILE // with something different from the default value wxCONFIG_USE_GLOBAL_FILE
wxScopedPtr<wxConfigBase> config(new wxRegConfig(app, vendor, "", "", wxRegConfig config(app, vendor, "", "", wxCONFIG_USE_LOCAL_FILE);
wxCONFIG_USE_LOCAL_FILE));
// test writing // test writing
config->SetPath("/group1"); config.SetPath("/group1");
CHECK( config->Write("entry1", "foo") ); CHECK( config.Write("entry1", "foo") );
config->SetPath("/group2"); config.SetPath("/group2");
CHECK( config->Write("entry1", "bar") ); 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 // 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 // long long with MinGW, not sure if it's a bug or not, but work around it
// by specifying the type explicitly. // by specifying the type explicitly.
const wxLongLong_t val64 = wxLL(0x8000000000000008); const wxLongLong_t val64 = wxLL(0x8000000000000008);
CHECK( config->Write("int64", val64) ); CHECK( config.Write("int64", val64) );
// test reading // test reading
wxString str; wxString str;
long dummy; long dummy;
config->SetPath("/"); config.SetPath("/");
CHECK( config->GetFirstGroup(str, dummy) ); CHECK( config.GetFirstGroup(str, dummy) );
CHECK( str == "group1" ); CHECK( str == "group1" );
CHECK( config->Read("group1/entry1", "INVALID DEFAULT") == "foo" ); CHECK( config.Read("group1/entry1", "INVALID DEFAULT") == "foo" );
CHECK( config->GetNextGroup(str, dummy) ); CHECK( config.GetNextGroup(str, dummy) );
CHECK( str == "group2" ); 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.ReadLong("group2/int32", 0) == 1234567 );
CHECK( config->ReadLongLong("group2/int64", 0) == val64 ); CHECK( config.ReadLongLong("group2/int64", 0) == val64 );
config->DeleteAll(); config.DeleteAll();
} }
TEST_CASE("wxRegKey::DeleteFromRedirectedView", "[registry][64bits]") TEST_CASE("wxRegKey::DeleteFromRedirectedView", "[registry][64bits]")