示例#1
0
文件: fileconf.cpp 项目: beanhome/dev
void FileConfigTestCase::RenameEntry()
{
    wxStringInputStream sis(testconfig);
    wxFileConfig fc(sis);

    fc.SetPath(wxT("root"));
    CPPUNIT_ASSERT( fc.RenameEntry(wxT("entry"), wxT("newname")) );
    wxVERIFY_FILECONFIG( wxT("[root]\n")
                         wxT("newname=value\n")
                         wxT("[root/group1]\n")
                         wxT("[root/group1/subgroup]\n")
                         wxT("subentry=subvalue\n")
                         wxT("subentry2=subvalue2\n")
                         wxT("[root/group2]\n"),
                         fc );

    fc.SetPath(wxT("group1/subgroup"));
    CPPUNIT_ASSERT( !fc.RenameEntry(wxT("entry"), wxT("newname")) );
    CPPUNIT_ASSERT( !fc.RenameEntry(wxT("subentry"), wxT("subentry2")) );

    CPPUNIT_ASSERT( fc.RenameEntry(wxT("subentry"), wxT("subentry1")) );
    wxVERIFY_FILECONFIG( wxT("[root]\n")
                         wxT("newname=value\n")
                         wxT("[root/group1]\n")
                         wxT("[root/group1/subgroup]\n")
                         wxT("subentry2=subvalue2\n")
                         wxT("subentry1=subvalue\n")
                         wxT("[root/group2]\n"),
                         fc );
}
示例#2
0
文件: fileconf.cpp 项目: beanhome/dev
void FileConfigTestCase::DeleteEntry()
{
    wxStringInputStream sis(testconfig);
    wxFileConfig fc(sis);

    CPPUNIT_ASSERT( !fc.DeleteEntry(wxT("foo")) );

    CPPUNIT_ASSERT( fc.DeleteEntry(wxT("root/group1/subgroup/subentry")) );
    wxVERIFY_FILECONFIG( wxT("[root]\n")
                         wxT("entry=value\n")
                         wxT("[root/group1]\n")
                         wxT("[root/group1/subgroup]\n")
                         wxT("subentry2=subvalue2\n")
                         wxT("[root/group2]\n"),
                         fc );

    // group should be deleted now as well as it became empty
    wxConfigPathChanger change(&fc, wxT("root/group1/subgroup/subentry2"));
    CPPUNIT_ASSERT( fc.DeleteEntry(wxT("subentry2")) );
    wxVERIFY_FILECONFIG( wxT("[root]\n")
                         wxT("entry=value\n")
                         wxT("[root/group1]\n")
                         wxT("[root/group2]\n"),
                         fc );
}
示例#3
0
void FileConfigTestCase::DeleteLastRootEntry()
{
    // This tests for the bug which occurred when the last entry of the root
    // group was deleted: this corrupted internal state and resulted in a crash
    // after trying to write the just deleted entry again.
    wxStringInputStream sis("");
    wxFileConfig fc(sis);

    fc.Write("key", "value");
    wxVERIFY_FILECONFIG( "key=value\n", fc );

    fc.DeleteEntry("key");
    wxVERIFY_FILECONFIG( "", fc );

    fc.Write("key", "value");
    wxVERIFY_FILECONFIG( "key=value\n", fc );
}
示例#4
0
文件: fileconf.cpp 项目: beanhome/dev
void FileConfigTestCase::CreateSubgroupAndEntries()
{
    wxFileConfig fc;
    fc.Write(wxT("sub/sub_first"), wxT("sub_one"));
    fc.Write(wxT("first"), wxT("one"));

    wxVERIFY_FILECONFIG( wxT("first=one\n")
                         wxT("[sub]\n")
                         wxT("sub_first=sub_one\n"),
                         fc );
}
示例#5
0
文件: fileconf.cpp 项目: beanhome/dev
void FileConfigTestCase::DeleteAndWriteEntry()
{
    wxStringInputStream sis(
            "[root/group1]\n"
            "subentry=subvalue\n"
            "subentry2=subvalue2\n"
            "subentry3=subvalue3\n"
    );

    wxFileConfig fc(sis);

    fc.DeleteEntry("/root/group1/subentry2");
    fc.Write("/root/group1/subentry2", "testvalue");
    fc.DeleteEntry("/root/group2/subentry2");
    fc.Write("/root/group2/subentry2", "testvalue2");
    fc.DeleteEntry("/root/group1/subentry2");
    fc.Write("/root/group1/subentry2", "testvalue");
    fc.DeleteEntry("/root/group2/subentry2");
    fc.Write("/root/group2/subentry2", "testvalue2");

    wxVERIFY_FILECONFIG( "[root/group1]\n"
                         "subentry=subvalue\n"
                         "subentry3=subvalue3\n"
                         "subentry2=testvalue\n"
                         "[root/group2]\n"
                         "subentry2=testvalue2\n",
                         fc );

    fc.DeleteEntry("/root/group2/subentry2");
    wxVERIFY_FILECONFIG( "[root/group1]\n"
                         "subentry=subvalue\n"
                         "subentry3=subvalue3\n"
                         "subentry2=testvalue\n",
                         fc );

    fc.DeleteEntry("/root/group1/subentry2");
    fc.DeleteEntry("/root/group1/subentry");
    fc.DeleteEntry("/root/group1/subentry3");
    wxVERIFY_FILECONFIG( "", fc );
}
示例#6
0
文件: fileconf.cpp 项目: beanhome/dev
void FileConfigTestCase::DeleteGroup()
{
    wxStringInputStream sis(testconfig);
    wxFileConfig fc(sis);

    CPPUNIT_ASSERT( !fc.DeleteGroup(wxT("foo")) );

    CPPUNIT_ASSERT( fc.DeleteGroup(wxT("root/group1")) );
    wxVERIFY_FILECONFIG( wxT("[root]\n")
                         wxT("entry=value\n")
                         wxT("[root/group2]\n"),
                         fc );

    // notice trailing slash: it should be ignored
    CPPUNIT_ASSERT( fc.DeleteGroup(wxT("root/group2/")) );
    wxVERIFY_FILECONFIG( wxT("[root]\n")
                         wxT("entry=value\n"),
                         fc );

    CPPUNIT_ASSERT( fc.DeleteGroup(wxT("root")) );
    CPPUNIT_ASSERT( Dump(fc).empty() );
}
示例#7
0
文件: fileconf.cpp 项目: beanhome/dev
void FileConfigTestCase::DeleteAndRecreateGroup()
{
    static const wxChar *confInitial =
        wxT("[First]\n")
        wxT("Value1=Foo\n")
        wxT("[Second]\n")
        wxT("Value2=Bar\n");

    wxStringInputStream sis(confInitial);
    wxFileConfig fc(sis);

    fc.DeleteGroup(wxT("Second"));
    wxVERIFY_FILECONFIG( wxT("[First]\n")
                         wxT("Value1=Foo\n"),
                         fc );

    fc.Write(wxT("Second/Value2"), wxT("New"));
    wxVERIFY_FILECONFIG( wxT("[First]\n")
                         wxT("Value1=Foo\n")
                         wxT("[Second]\n")
                         wxT("Value2=New\n"),
                         fc );
}
示例#8
0
文件: fileconf.cpp 项目: beanhome/dev
void FileConfigTestCase::AddToExistingRoot()
{
    static const wxChar *confInitial =
        wxT("[Group]\n")
        wxT("value1=foo\n");

    wxStringInputStream sis(confInitial);
    wxFileConfig fc(sis);

    fc.Write(wxT("/value1"), wxT("bar"));
    wxVERIFY_FILECONFIG(
        wxT("value1=bar\n")
        wxT("[Group]\n")
        wxT("value1=foo\n"),
        fc
    );
}
示例#9
0
文件: fileconf.cpp 项目: beanhome/dev
void FileConfigTestCase::Binary()
{
    wxStringInputStream sis(
        "[root]\n"
        "binary=Zm9vCg==\n"
    );
    wxFileConfig fc(sis);

    wxMemoryBuffer buf;
    fc.Read("/root/binary", &buf);

    CPPUNIT_ASSERT( memcmp("foo\n", buf.GetData(), buf.GetDataLen()) == 0 );

    buf.SetDataLen(0);
    buf.AppendData("\0\1\2", 3);
    fc.Write("/root/012", buf);
    wxVERIFY_FILECONFIG(
        "[root]\n"
        "binary=Zm9vCg==\n"
        "012=AAEC\n",
        fc
    );
}
示例#10
0
文件: fileconf.cpp 项目: beanhome/dev
void FileConfigTestCase::AddEntries()
{
    wxFileConfig fc;

    wxVERIFY_FILECONFIG( wxT(""), fc  );

    fc.Write(wxT("/Foo"), wxT("foo"));
    wxVERIFY_FILECONFIG( wxT("Foo=foo\n"), fc  );

    fc.Write(wxT("/Bar/Baz"), wxT("baz"));
    wxVERIFY_FILECONFIG( wxT("Foo=foo\n[Bar]\nBaz=baz\n"), fc  );

    fc.DeleteAll();
    wxVERIFY_FILECONFIG( wxT(""), fc  );

    fc.Write(wxT("/Bar/Baz"), wxT("baz"));
    wxVERIFY_FILECONFIG( wxT("[Bar]\nBaz=baz\n"), fc  );

    fc.Write(wxT("/Foo"), wxT("foo"));
    wxVERIFY_FILECONFIG( wxT("Foo=foo\n[Bar]\nBaz=baz\n"), fc  );
}
示例#11
0
文件: fileconf.cpp 项目: beanhome/dev
void FileConfigTestCase::RenameGroup()
{
    wxStringInputStream sis(testconfig);
    wxFileConfig fc(sis);

    CPPUNIT_ASSERT( fc.RenameGroup(wxT("root"), wxT("foot")) );
    wxVERIFY_FILECONFIG( wxT("[foot]\n")
                         wxT("entry=value\n")
                         wxT("[foot/group1]\n")
                         wxT("[foot/group1/subgroup]\n")
                         wxT("subentry=subvalue\n")
                         wxT("subentry2=subvalue2\n")
                         wxT("[foot/group2]\n"),
                         fc );

    // renaming a path doesn't work, it must be the immediate group
    CPPUNIT_ASSERT( !fc.RenameGroup(wxT("foot/group1"), wxT("group2")) );


    fc.SetPath(wxT("foot"));

    // renaming to a name of existing group doesn't work
    CPPUNIT_ASSERT( !fc.RenameGroup(wxT("group1"), wxT("group2")) );

    // try exchanging the groups names and then restore them back
    CPPUNIT_ASSERT( fc.RenameGroup(wxT("group1"), wxT("groupTmp")) );
    wxVERIFY_FILECONFIG( wxT("[foot]\n")
                         wxT("entry=value\n")
                         wxT("[foot/groupTmp]\n")
                         wxT("[foot/groupTmp/subgroup]\n")
                         wxT("subentry=subvalue\n")
                         wxT("subentry2=subvalue2\n")
                         wxT("[foot/group2]\n"),
                         fc );

    CPPUNIT_ASSERT( fc.RenameGroup(wxT("group2"), wxT("group1")) );
    wxVERIFY_FILECONFIG( wxT("[foot]\n")
                         wxT("entry=value\n")
                         wxT("[foot/groupTmp]\n")
                         wxT("[foot/groupTmp/subgroup]\n")
                         wxT("subentry=subvalue\n")
                         wxT("subentry2=subvalue2\n")
                         wxT("[foot/group1]\n"),
                         fc );

    CPPUNIT_ASSERT( fc.RenameGroup(wxT("groupTmp"), wxT("group2")) );
    wxVERIFY_FILECONFIG( wxT("[foot]\n")
                         wxT("entry=value\n")
                         wxT("[foot/group2]\n")
                         wxT("[foot/group2/subgroup]\n")
                         wxT("subentry=subvalue\n")
                         wxT("subentry2=subvalue2\n")
                         wxT("[foot/group1]\n"),
                         fc );

    CPPUNIT_ASSERT( fc.RenameGroup(wxT("group1"), wxT("groupTmp")) );
    wxVERIFY_FILECONFIG( wxT("[foot]\n")
                         wxT("entry=value\n")
                         wxT("[foot/group2]\n")
                         wxT("[foot/group2/subgroup]\n")
                         wxT("subentry=subvalue\n")
                         wxT("subentry2=subvalue2\n")
                         wxT("[foot/groupTmp]\n"),
                         fc );

    CPPUNIT_ASSERT( fc.RenameGroup(wxT("group2"), wxT("group1")) );
    wxVERIFY_FILECONFIG( wxT("[foot]\n")
                         wxT("entry=value\n")
                         wxT("[foot/group1]\n")
                         wxT("[foot/group1/subgroup]\n")
                         wxT("subentry=subvalue\n")
                         wxT("subentry2=subvalue2\n")
                         wxT("[foot/groupTmp]\n"),
                         fc );

    CPPUNIT_ASSERT( fc.RenameGroup(wxT("groupTmp"), wxT("group2")) );
    wxVERIFY_FILECONFIG( wxT("[foot]\n")
                         wxT("entry=value\n")
                         wxT("[foot/group1]\n")
                         wxT("[foot/group1/subgroup]\n")
                         wxT("subentry=subvalue\n")
                         wxT("subentry2=subvalue2\n")
                         wxT("[foot/group2]\n"),
                         fc );
}
示例#12
0
文件: fileconf.cpp 项目: beanhome/dev
void FileConfigTestCase::Save()
{
    wxStringInputStream sis(testconfig);
    wxFileConfig fc(sis);
    wxVERIFY_FILECONFIG( testconfig, fc );
}