Exemplo n.º 1
0
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 );
}
Exemplo n.º 2
0
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 );
}
Exemplo n.º 3
0
    void Load()
    {
        std::vector<wxXmlDocument*> userLexers;
        wxArrayString files;

        //---------------------------------------------
        // Load user lexers (new format only)
        //---------------------------------------------
        files.Clear();
        wxFileName userLexersPath(clStandardPaths::Get().GetUserDataDir(), "");
        userLexersPath.AppendDir("lexers");

        CL_DEBUG("Loading users lexers");
        wxDir::GetAllFiles(userLexersPath.GetPath(), &files, "lexer_*.xml");
        // Each XMl represents a single lexer
        for(size_t i = 0; i < files.GetCount(); ++i) {
            wxString content;
            wxFFile xmlFile(files.Item(i), "rb");
            if(!xmlFile.IsOpened()) continue;
            if(xmlFile.ReadAll(&content, wxConvUTF8)) {
                wxXmlDocument* doc = new wxXmlDocument();
                wxStringInputStream sis(content);
                if(doc->Load(sis)) {
                    userLexers.push_back(doc);
                } else {
                    wxDELETE(doc);
                }
            }
            xmlFile.Close();
            wxRemoveFile(files.Item(i));
        }
        CL_DEBUG("Loading users lexers...done");
        m_manager->OnLexerFilesLoaded(userLexers);
    }
Exemplo n.º 4
0
void readOSMXML( XercesInitWrapper &x, const std::string &fileName, OSMFragment &frag )
{
    std::cout << "Reading XML file: " << fileName << std::endl;

    xercesc::SAX2XMLReaderImpl &parser = x.getParser();

    boost::shared_ptr<XMLNodeData> startNdData( new XMLNodeData() );

    startNdData->registerMembers()( "osm", boost::bind( &OSMFragment::build, &frag, _1 ) );

    XMLReader handler( startNdData );

    parser.setContentHandler( &handler );
    parser.setErrorHandler( &handler );

    std::ifstream is( fileName.c_str(), std::ios_base::in | std::ios_base::binary );
    boost::iostreams::filtering_istream in;
    in.push( boost::iostreams::bzip2_decompressor() );
    in.push( is );

    StreamIS sis( in );
    parser.parse( sis );

    std::cout << "Done..." << std::endl;
}
Exemplo n.º 5
0
void rpcudp::_package_process(const udpaddr& addr,
	int len, shared_memory memory, size_t memory_size)
{
	/*
		要最先发送ack
		*/
	const_memory_block blk(memory);
	blk.size = memory_size;
	packages_analysis sis(blk);
	rpcudp_detail::__slice_head_attacher attacher(sis);


	complete_result job;

	job.user_key = get_slice;
	job.key = 0;

	auto* arg = new _complete_argument(addr, memory);
	job.argument = arg;

	auto wlock = ISU_AUTO_LOCK(_spinlock);
	arg->client = &_get_client(addr);
	wlock.unlock();

	if (attacher.udp_ex != nullptr)
	{
		arg->client->_send_ack(
			addr, attacher.udp_ex->group_id,
			attacher.udp_ex->slice_id);
	}

	_process_port.post(job);
}
Exemplo n.º 6
0
void FileConfigTestCase::ReadEmpty()
{
    static const char *confTest = "";

    wxStringInputStream sis(confTest);
    wxFileConfig fc(sis);
}
Exemplo n.º 7
0
 int64_t SegmentInfos::readCurrentVersion(DirectoryPtr directory)
 {
     // Fully read the segments file: this ensures that it's completely written so that if IndexWriter.prepareCommit has been called 
     // (but not yet commit), then the reader will still see itself as current.
     SegmentInfosPtr sis(newLucene<SegmentInfos>());
     sis->read(directory);
     return sis->getVersion();
 }
Exemplo n.º 8
0
void FileConfigTestCase::DeleteAll()
{
    wxStringInputStream sis(testconfig);
    wxFileConfig fc(sis);

    CPPUNIT_ASSERT( fc.DeleteAll() );
    CPPUNIT_ASSERT( Dump(fc).empty() );
}
Exemplo n.º 9
0
void POP3ClientSession::retrieveMessage(int id, std::ostream& ostr)
{
	std::string response;
	sendCommand("RETR", NumberFormatter::format(id), response);
	if (!isPositive(response)) throw POP3Exception("Cannot get message list", response);
	DialogInputStream sis(_socket);
	MailInputStream mis(sis);
	StreamCopier::copyStream(mis, ostr);
}
Exemplo n.º 10
0
void FileConfigTestCase::GetGroups()
{
    wxStringInputStream sis(testconfig);
    wxFileConfig fc(sis);

    CheckGroupSubgroups(fc, wxT(""), 1, wxT("root"));
    CheckGroupSubgroups(fc, wxT("/root"), 2, wxT("group1"), wxT("group2"));
    CheckGroupSubgroups(fc, wxT("/root/group1"), 1, wxT("subgroup"));
    CheckGroupSubgroups(fc, wxT("/root/group2"), 0);
}
Exemplo n.º 11
0
void POP3ClientSession::retrieveMessage(int id, MailMessage& message, PartHandler& handler)
{
	std::string response;
	sendCommand("RETR", NumberFormatter::format(id), response);
	if (!isPositive(response)) throw POP3Exception("Cannot get message list", response);
	DialogInputStream sis(_socket);
	MailInputStream mis(sis);
	message.read(mis, handler);
	while (mis.good()) mis.get(); // read any remaining junk
}
Exemplo n.º 12
0
GitEntry::GitProperties GitEntry::ReadGitProperties(const wxString& localRepoPath)
{
    GitEntry::GitProperties props;
    // Read the global name/email
    // ~/.gitconfig | %USERPROFILE%\.gitconfig
    {
        wxFileName globalConfig(::wxGetHomeDir(), ".gitconfig");
        if(globalConfig.Exists()) {
            wxFFile fp(globalConfig.GetFullPath(), "rb");
            if(fp.IsOpened()) {
                wxString content;
                fp.ReadAll(&content, wxConvUTF8);
                wxStringInputStream sis(content);

                wxFileConfig conf(sis);
                conf.Read("user/email", &props.global_email);
                conf.Read("user/name", &props.global_username);

                fp.Close();
            }
        }
    }

    // Read the repo config file
    if(!localRepoPath.IsEmpty()) {
        wxFileName localConfig(localRepoPath, "config");
        localConfig.AppendDir(".git");
        wxFFile fp(localConfig.GetFullPath(), "rb");
        if(fp.IsOpened()) {
            wxString content;
            fp.ReadAll(&content, wxConvUTF8);
            wxStringInputStream sis(content);

            wxFileConfig conf(sis);
            conf.Read("user/email", &props.local_email);
            conf.Read("user/name", &props.local_username);

            fp.Close();
        }
    }
    return props;
}
Exemplo n.º 13
0
void FileConfigTestCase::GetEntries()
{
    wxStringInputStream sis(testconfig);
    wxFileConfig fc(sis);

    CheckGroupEntries(fc, wxT(""), 0);
    CheckGroupEntries(fc, wxT("/root"), 1, wxT("entry"));
    CheckGroupEntries(fc, wxT("/root/group1"), 0);
    CheckGroupEntries(fc, wxT("/root/group1/subgroup"),
                        2, wxT("subentry"), wxT("subentry2"));
}
Exemplo n.º 14
0
void FileConfigTestCase::Path()
{
    wxStringInputStream sis(testconfig);
    wxFileConfig fc(sis);

    CPPUNIT_ASSERT( ChangePath(fc, wxT("")) == wxT("") );
    CPPUNIT_ASSERT( ChangePath(fc, wxT("/")) == wxT("") );
    CPPUNIT_ASSERT( ChangePath(fc, wxT("root")) == wxT("/root") );
    CPPUNIT_ASSERT( ChangePath(fc, wxT("/root")) == wxT("/root") );
    CPPUNIT_ASSERT( ChangePath(fc, wxT("/root/group1/subgroup")) == wxT("/root/group1/subgroup") );
    CPPUNIT_ASSERT( ChangePath(fc, wxT("/root/group2")) == wxT("/root/group2") );
}
Exemplo n.º 15
0
void POP3ClientSession::retrieveHeader(int id, MessageHeader& header)
{
	std::string response;
	sendCommand("TOP", NumberFormatter::format(id), "0", response);
	if (!isPositive(response)) throw POP3Exception("Cannot get message list", response);
	DialogInputStream sis(_socket);
	MailInputStream mis(sis);
	header.read(mis);
	// skip stuff following header
	mis.get(); // \r
	mis.get(); // \n
}
Exemplo n.º 16
0
void FileConfigTestCase::HasEntry()
{
    wxStringInputStream sis(testconfig);
    wxFileConfig fc(sis);

    CPPUNIT_ASSERT( !fc.HasEntry(_T("root")) );
    CPPUNIT_ASSERT( fc.HasEntry(_T("root/entry")) );
    CPPUNIT_ASSERT( fc.HasEntry(_T("/root/entry")) );
    CPPUNIT_ASSERT( fc.HasEntry(_T("root/group1/subgroup/subentry")) );
    CPPUNIT_ASSERT( !fc.HasEntry(_T("")) );
    CPPUNIT_ASSERT( !fc.HasEntry(_T("root/group1")) );
    CPPUNIT_ASSERT( !fc.HasEntry(_T("subgroup/subentry")) );
}
Exemplo n.º 17
0
void FileConfigTestCase::RenameGroup()
{
    wxStringInputStream sis(testconfig);
    wxFileConfig fc(sis);

    CPPUNIT_ASSERT( fc.RenameGroup(_T("root"), _T("foot")) );
    CPPUNIT_ASSERT( Dump(fc) == _T("[foot]\n")
                                _T("entry=value\n")
                                _T("[foot/group1]\n")
                                _T("[foot/group1/subgroup]\n")
                                _T("subentry=subvalue\n")
                                _T("subentry2=subvalue2\n")
                                _T("[foot/group2]\n") );
}
Exemplo n.º 18
0
void FileConfigTestCase::HasGroup()
{
    wxStringInputStream sis(testconfig);
    wxFileConfig fc(sis);

    CPPUNIT_ASSERT( fc.HasGroup(wxT("root")) );
    CPPUNIT_ASSERT( fc.HasGroup(wxT("root/group1")) );
    CPPUNIT_ASSERT( fc.HasGroup(wxT("root/group1/subgroup")) );
    CPPUNIT_ASSERT( fc.HasGroup(wxT("root/group2")) );
    CPPUNIT_ASSERT( !fc.HasGroup(wxT("")) );
    CPPUNIT_ASSERT( !fc.HasGroup(wxT("root/group")) );
    CPPUNIT_ASSERT( !fc.HasGroup(wxT("root//subgroup")) );
    CPPUNIT_ASSERT( !fc.HasGroup(wxT("foot/subgroup")) );
    CPPUNIT_ASSERT( !fc.HasGroup(wxT("foot")) );
}
Exemplo n.º 19
0
ColoursAndFontsManager::ColoursAndFontsManager()
    : m_initialized(false)
{
    // Create a "go to lexer" when all is broken
    wxStringInputStream sis(LexerTextDefaultXML);
    wxXmlDocument doc;
    if(doc.Load(sis)) {
        m_defaultLexer.Reset(new LexerConf());
        m_defaultLexer->FromXml(doc.GetRoot());
    }

    m_globalBgColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
    m_globalFgColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
    m_lexersVersion = clConfig::Get().Read(LEXERS_VERSION_STRING, LEXERS_UPGRADE_LINENUM_DEFAULT_COLOURS);
}
Exemplo n.º 20
0
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
    );
}
Exemplo n.º 21
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 );
}
Exemplo n.º 22
0
void FileConfigTestCase::ReadFloat()
{
    static const char *confTest =
        "x=1.234\n"
        "y=-9876.5432\n"
        "z=2e+308\n"
    ;

    wxStringInputStream sis(confTest);
    wxFileConfig fc(sis);

    float f;
    CPPUNIT_ASSERT( fc.Read("x", &f) );
    CPPUNIT_ASSERT_EQUAL( 1.234f, f );

    CPPUNIT_ASSERT( fc.Read("y", &f) );
    CPPUNIT_ASSERT_EQUAL( -9876.5432f, f );
}
Exemplo n.º 23
0
void FileConfigTestCase::ReadNonExistent()
{
    static const char *confTest =
        "community=censored\n"
        "[City1]\n"
        "URL=www.fake1.na\n"
        "[City1/A1]\n"
        "[City1/A1/1]\n"
        "IP=192.168.1.66\n"
        "URL=www.fake2.na\n"
    ;

    wxStringInputStream sis(confTest);
    wxFileConfig fc(sis);

    wxString url;
    CPPUNIT_ASSERT( !fc.Read("URL", &url) );
}
Exemplo n.º 24
0
void FileConfigTestCase::DeleteGroup()
{
    wxStringInputStream sis(testconfig);
    wxFileConfig fc(sis);

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

    CPPUNIT_ASSERT( fc.DeleteGroup(_T("root/group1")) );
    CPPUNIT_ASSERT( Dump(fc) == _T("[root]\n")
                                _T("entry=value\n")
                                _T("[root/group2]\n") );

    CPPUNIT_ASSERT( fc.DeleteGroup(_T("root/group2")) );
    CPPUNIT_ASSERT( Dump(fc) == _T("[root]\n")
                                _T("entry=value\n") );

    CPPUNIT_ASSERT( fc.DeleteGroup(_T("root")) );
    CPPUNIT_ASSERT( Dump(fc).empty() );
}
TEST(StrInStream, Simple)
{
    const char* TestStr = "ABC\nDEF\n\nGHI";

    DataRefInStream is(TestStr);
    StrInStream sis(is);

    {
        StrBuf<12> str;

        ASSERT_TRUE(sis.readLine(str));
        ASSERT_EQ(str, "ABC");
    }

    {
        StrBuf<12> str;

        ASSERT_TRUE(sis.readLine(str));
        ASSERT_EQ(str, "DEF");
    }
    
    {
        StrBuf<12> str;

        ASSERT_TRUE(sis.readLine(str));
        ASSERT_EQ(str, "");
    }

    {
        StrBuf<12> str;

        ASSERT_TRUE(sis.readLine(str));
        ASSERT_EQ(str, "GHI");
    }

    {
        StrBuf<12> str;

        ASSERT_FALSE(sis.readLine(str));
    }
}
Exemplo n.º 26
0
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 );
}
Exemplo n.º 27
0
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() );
}
Exemplo n.º 28
0
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 );
}
Exemplo n.º 29
0
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
    );
}
Exemplo n.º 30
0
bool XDebugManager::ProcessDebuggerMessage(const wxString& buffer )
{
    if ( buffer.IsEmpty() )
        return false;
    
    CL_DEBUG( "XDebug <<< " + buffer );
    
    wxXmlDocument doc;
    wxStringInputStream sis(buffer);
    if ( !doc.Load( sis ) ) {
        // failed to parse XML
        CL_DEBUG( "CodeLite >>> invalid XML!");
        return false;
    }
    
    wxXmlNode *root = doc.GetRoot();
    
    if ( root->GetName() == "init" ) {
        
        // Parse the content and notify codelite to open the main file
        xInitStruct initData = ParseInitXML( root );
        
        // Negotiate features with the IDE
        DoNegotiateFeatures();
        
        // this is a startup message from the debugger
        DoApplyBreakpoints();
        
        // Issue a "Continue" command
        DoContinue();
        
    } else if ( root->GetName() == "response" ) {
        // Handle response
        DoHandleResponse(root);
    }
    return true;
}