Get rid of CppUnit boilerplate in wxConfig unit tests
No real changes.
This commit is contained in:
@@ -28,36 +28,10 @@
|
||||
#include "wx/colour.h"
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// test class
|
||||
// the tests
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
class ConfigTestCase : public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
ConfigTestCase() {}
|
||||
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( ConfigTestCase );
|
||||
CPPUNIT_TEST( ReadWriteLocalTest );
|
||||
CPPUNIT_TEST( RecordingDefaultsTest );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void ReadWriteLocalTest();
|
||||
void RecordingDefaultsTest();
|
||||
|
||||
// return the number of values we (attempted to) read
|
||||
size_t ReadValues(wxConfig *config, bool has_values);
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(ConfigTestCase);
|
||||
};
|
||||
|
||||
// register in the unnamed registry so that these tests are run by default
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( ConfigTestCase );
|
||||
|
||||
// also include in its own registry so that these tests can be run alone
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ConfigTestCase, "ConfigTestCase" );
|
||||
|
||||
void ConfigTestCase::ReadWriteLocalTest()
|
||||
TEST_CASE("wxConfig::ReadWriteLocal", "[config]")
|
||||
{
|
||||
wxString app = wxT("wxConfigTestCase");
|
||||
wxString vendor = wxT("wxWidgets");
|
||||
@@ -79,60 +53,62 @@ void ConfigTestCase::ReadWriteLocalTest()
|
||||
config = new wxConfig(app, vendor, wxT(""), wxT(""),
|
||||
wxCONFIG_USE_LOCAL_FILE);
|
||||
wxString string1 = config->Read(wxT("string1"));
|
||||
CPPUNIT_ASSERT_EQUAL( "abc", string1 );
|
||||
CHECK( string1 == "abc" );
|
||||
string1 = config->Read(wxT("string1"), wxT("defaultvalue"));
|
||||
CPPUNIT_ASSERT_EQUAL( "abc", string1 );
|
||||
CHECK( string1 == "abc" );
|
||||
|
||||
wxString string2;
|
||||
bool r = config->Read(wxT("string2"), &string2);
|
||||
CPPUNIT_ASSERT( r );
|
||||
CPPUNIT_ASSERT_EQUAL( "def", string2 );
|
||||
CHECK( r );
|
||||
CHECK( string2 == "def" );
|
||||
|
||||
r = config->Read(wxT("string2"), &string2, wxT("defaultvalue"));
|
||||
CPPUNIT_ASSERT( r );
|
||||
CPPUNIT_ASSERT_EQUAL( "def", string2 );
|
||||
CHECK( r );
|
||||
CHECK( string2 == "def" );
|
||||
|
||||
int int1 = config->Read(wxT("int1"), 5);
|
||||
CPPUNIT_ASSERT_EQUAL( 123, int1 );
|
||||
CHECK( int1 == 123 );
|
||||
|
||||
long long1;
|
||||
r = config->Read(wxT("long1"), &long1);
|
||||
CPPUNIT_ASSERT( r );
|
||||
CPPUNIT_ASSERT_EQUAL( 234L, long1 );
|
||||
CHECK( r );
|
||||
CHECK( long1 == 234L );
|
||||
|
||||
CPPUNIT_ASSERT( config->ReadLong(wxT("long1"), 0) == 234 );
|
||||
CHECK( config->ReadLong(wxT("long1"), 0) == 234 );
|
||||
|
||||
double double1;
|
||||
r = config->Read(wxT("double1"), &double1);
|
||||
CPPUNIT_ASSERT( r );
|
||||
CPPUNIT_ASSERT_EQUAL( 345.67, double1 );
|
||||
CHECK( r );
|
||||
CHECK( double1 == 345.67 );
|
||||
|
||||
CPPUNIT_ASSERT( config->ReadDouble(wxT("double1"), 0) == double1 );
|
||||
CHECK( config->ReadDouble(wxT("double1"), 0) == double1 );
|
||||
|
||||
bool bool1;
|
||||
r = config->Read(wxT("foo"), &bool1); // there is no "foo" key
|
||||
CPPUNIT_ASSERT( !r );
|
||||
CHECK( !r );
|
||||
|
||||
r = config->Read(wxT("bool1"), &bool1);
|
||||
CPPUNIT_ASSERT( r );
|
||||
CPPUNIT_ASSERT_EQUAL( true, bool1 );
|
||||
CHECK( r );
|
||||
CHECK( bool1 == true );
|
||||
|
||||
CPPUNIT_ASSERT( config->ReadBool(wxT("bool1"), false) == bool1 );
|
||||
CHECK( config->ReadBool(wxT("bool1"), false) == bool1 );
|
||||
|
||||
#ifdef wxHAS_CONFIG_TEMPLATE_RW
|
||||
wxColour color1;
|
||||
r = config->Read(wxT("color1"), &color1);
|
||||
CPPUNIT_ASSERT( r );
|
||||
CPPUNIT_ASSERT( color1 == wxColour(11,22,33,44) );
|
||||
CHECK( r );
|
||||
CHECK( color1 == wxColour(11,22,33,44) );
|
||||
|
||||
CPPUNIT_ASSERT( config->ReadObject(wxT("color1"), wxNullColour) == color1 );
|
||||
CHECK( config->ReadObject(wxT("color1"), wxNullColour) == color1 );
|
||||
#endif // wxHAS_CONFIG_TEMPLATE_RW
|
||||
|
||||
config->DeleteAll();
|
||||
delete config;
|
||||
}
|
||||
|
||||
size_t ConfigTestCase::ReadValues(wxConfig *config, bool has_values)
|
||||
// Helper of RecordingDefaultsTest() test.
|
||||
static
|
||||
size_t ReadValues(wxConfig *config, bool has_values)
|
||||
{
|
||||
size_t read = 0;
|
||||
bool r;
|
||||
@@ -145,42 +121,42 @@ size_t ConfigTestCase::ReadValues(wxConfig *config, bool has_values)
|
||||
|
||||
wxString string3;
|
||||
r = config->Read(wxT("string3"), &string3, wxT("abc"));
|
||||
CPPUNIT_ASSERT_EQUAL( has_values, r );
|
||||
CHECK( r == has_values );
|
||||
read++;
|
||||
|
||||
wxString string4;
|
||||
r = config->Read(wxT("string4"), &string4, wxString(wxT("def")));
|
||||
CPPUNIT_ASSERT_EQUAL( has_values, r );
|
||||
CHECK( r == has_values );
|
||||
read++;
|
||||
|
||||
int int1;
|
||||
r = config->Read(wxT("int1"), &int1, 123);
|
||||
CPPUNIT_ASSERT_EQUAL( has_values, r );
|
||||
CHECK( r == has_values );
|
||||
read++;
|
||||
|
||||
int int2 = config->Read(wxT("int2"), 1234);
|
||||
CPPUNIT_ASSERT_EQUAL( int2, 1234 );
|
||||
CHECK( 1234 == int2 );
|
||||
read++;
|
||||
|
||||
long long1;
|
||||
r = config->Read(wxString(wxT("long1")), &long1, 234L);
|
||||
CPPUNIT_ASSERT_EQUAL( has_values, r );
|
||||
CHECK( r == has_values );
|
||||
read++;
|
||||
|
||||
double double1;
|
||||
r = config->Read(wxT("double1"), &double1, 345.67);
|
||||
CPPUNIT_ASSERT_EQUAL( has_values, r );
|
||||
CHECK( r == has_values );
|
||||
read++;
|
||||
|
||||
bool bool1;
|
||||
r = config->Read(wxT("bool1"), &bool1, true);
|
||||
CPPUNIT_ASSERT_EQUAL( has_values, r );
|
||||
CHECK( r == has_values );
|
||||
read++;
|
||||
|
||||
#ifdef wxHAS_CONFIG_TEMPLATE_RW
|
||||
wxColour color1;
|
||||
r = config->Read(wxT("color1"), &color1, wxColour(11,22,33,44));
|
||||
CPPUNIT_ASSERT_EQUAL( has_values, r );
|
||||
CHECK( r == has_values );
|
||||
read++;
|
||||
#endif // wxHAS_CONFIG_TEMPLATE_RW
|
||||
|
||||
@@ -188,7 +164,7 @@ size_t ConfigTestCase::ReadValues(wxConfig *config, bool has_values)
|
||||
}
|
||||
|
||||
|
||||
void ConfigTestCase::RecordingDefaultsTest()
|
||||
TEST_CASE("wxConfig::RecordingDefaults", "[config]")
|
||||
{
|
||||
wxString app = wxT("wxConfigTestCaseRD");
|
||||
wxString vendor = wxT("wxWidgets");
|
||||
@@ -197,10 +173,10 @@ void ConfigTestCase::RecordingDefaultsTest()
|
||||
config->DeleteAll();
|
||||
config->SetRecordDefaults(false); // by default it is false
|
||||
ReadValues(config, false);
|
||||
CPPUNIT_ASSERT_EQUAL( 0, config->GetNumberOfEntries() );
|
||||
CHECK( config->GetNumberOfEntries() == 0 );
|
||||
config->SetRecordDefaults(true);
|
||||
size_t read = ReadValues(config, false);
|
||||
CPPUNIT_ASSERT_EQUAL( read, config->GetNumberOfEntries() );
|
||||
CHECK( config->GetNumberOfEntries() == read );
|
||||
ReadValues(config, true);
|
||||
config->DeleteAll();
|
||||
delete config;
|
||||
|
||||
Reference in New Issue
Block a user