Exemple #1
0
	bool GetLangNamesAutoC(int /*cat*/, StdStringVector &set)
	{
		for(int i = 0; i < GetLangCount(); ++i)
			set.push_back(std::_tstring(GetLangName(i)) + _T("?2"));
		return true;
	}
Exemple #2
0
int string_test()
{
    typedef std::allocator<CharType>  StdAllocatorChar;
    typedef std::basic_string<CharType, std::char_traits<CharType>, StdAllocatorChar> StdString;
    typedef std::allocator<StdString> StdStringAllocator;
    typedef vector<StdString, StdStringAllocator> StdStringVector;
    typedef AllocatorType<CharType, managed_shared_memory::segment_manager> ShmemAllocatorChar;
    typedef basic_string<CharType, std::char_traits<CharType>, ShmemAllocatorChar> ShmString;
    typedef AllocatorType<ShmString, managed_shared_memory::segment_manager> ShmemStringAllocator;
    typedef vector<ShmString, ShmemStringAllocator> ShmStringVector;

    const int MaxSize = 100;

    std::string process_name;
    test::get_process_id_name(process_name);

    //Create shared memory
    shared_memory_object::remove(process_name.c_str());
    {
        managed_shared_memory segment
        (create_only,
         process_name.c_str(),//segment name
         65536);              //segment size in bytes

        ShmemAllocatorChar shmallocator (segment.get_segment_manager());

        //Initialize vector with a range or iterators and allocator
        ShmStringVector *shmStringVect =
            segment.construct<ShmStringVector>
            (anonymous_instance, std::nothrow)  //object name
            (shmallocator);

        StdStringVector *stdStringVect = new StdStringVector;

        ShmString auxShmString (segment.get_segment_manager());
        StdString auxStdString(StdString(auxShmString.begin(), auxShmString.end() ));

        CharType buffer [20];

        //First, push back
        for(int i = 0; i < MaxSize; ++i) {
            auxShmString = "String";
            auxStdString = "String";
            std::sprintf(buffer, "%i", i);
            auxShmString += buffer;
            auxStdString += buffer;
            shmStringVect->push_back(auxShmString);
            stdStringVect->push_back(auxStdString);
        }

        if(!CheckEqualStringVector(shmStringVect, stdStringVect)) {
            return 1;
        }

        //Now push back moving
        for(int i = 0; i < MaxSize; ++i) {
            auxShmString = "String";
            auxStdString = "String";
            std::sprintf(buffer, "%i", i);
            auxShmString += buffer;
            auxStdString += buffer;
            shmStringVect->push_back(boost::interprocess::move(auxShmString));
            stdStringVect->push_back(auxStdString);
        }

        if(!CheckEqualStringVector(shmStringVect, stdStringVect)) {
            return 1;
        }

        //push front
        for(int i = 0; i < MaxSize; ++i) {
            auxShmString = "String";
            auxStdString = "String";
            std::sprintf(buffer, "%i", i);
            auxShmString += buffer;
            auxStdString += buffer;
            shmStringVect->insert(shmStringVect->begin(), auxShmString);
            stdStringVect->insert(stdStringVect->begin(), auxStdString);
        }

        if(!CheckEqualStringVector(shmStringVect, stdStringVect)) {
            return 1;
        }

        //Now push front moving
        for(int i = 0; i < MaxSize; ++i) {
            auxShmString = "String";
            auxStdString = "String";
            std::sprintf(buffer, "%i", i);
            auxShmString += buffer;
            auxStdString += buffer;
            shmStringVect->insert(shmStringVect->begin(), boost::interprocess::move(auxShmString));
            stdStringVect->insert(stdStringVect->begin(), auxStdString);
        }

        if(!CheckEqualStringVector(shmStringVect, stdStringVect)) {
            return 1;
        }

        //Now test long and short representation swapping
        auxShmString = "String";
        auxStdString = "String";
        ShmString shm_swapper(segment.get_segment_manager());
        StdString std_swapper;
        shm_swapper.swap(auxShmString);
        std_swapper.swap(auxStdString);
        if(!StringEqual()(auxShmString, auxStdString))
            return 1;
        if(!StringEqual()(shm_swapper, std_swapper))
            return 1;

        shm_swapper.swap(auxShmString);
        std_swapper.swap(auxStdString);
        if(!StringEqual()(auxShmString, auxStdString))
            return 1;
        if(!StringEqual()(shm_swapper, std_swapper))
            return 1;

        auxShmString = "LongLongLongLongLongLongLongLongLongLongLongLongLongString";
        auxStdString = "LongLongLongLongLongLongLongLongLongLongLongLongLongString";
        shm_swapper = ShmString (segment.get_segment_manager());
        std_swapper = StdString ();
        shm_swapper.swap(auxShmString);
        std_swapper.swap(auxStdString);
        if(!StringEqual()(auxShmString, auxStdString))
            return 1;
        if(!StringEqual()(shm_swapper, std_swapper))
            return 1;

        shm_swapper.swap(auxShmString);
        std_swapper.swap(auxStdString);
        if(!StringEqual()(auxShmString, auxStdString))
            return 1;
        if(!StringEqual()(shm_swapper, std_swapper))
            return 1;

        //No sort
        std::sort(shmStringVect->begin(), shmStringVect->end());
        std::sort(stdStringVect->begin(), stdStringVect->end());
        if(!CheckEqualStringVector(shmStringVect, stdStringVect)) return 1;

        const CharType prefix []    = "Prefix";
        const int  prefix_size  = sizeof(prefix)/sizeof(prefix[0])-1;
        const CharType sufix []     = "Suffix";

        for(int i = 0; i < MaxSize; ++i) {
            (*shmStringVect)[i].append(sufix);
            (*stdStringVect)[i].append(sufix);
            (*shmStringVect)[i].insert((*shmStringVect)[i].begin(),
                                       prefix, prefix + prefix_size);
            (*stdStringVect)[i].insert((*stdStringVect)[i].begin(),
                                       prefix, prefix + prefix_size);
        }

        if(!CheckEqualStringVector(shmStringVect, stdStringVect)) return 1;

        for(int i = 0; i < MaxSize; ++i) {
            std::reverse((*shmStringVect)[i].begin(), (*shmStringVect)[i].end());
            std::reverse((*stdStringVect)[i].begin(), (*stdStringVect)[i].end());
        }

        if(!CheckEqualStringVector(shmStringVect, stdStringVect)) return 1;

        for(int i = 0; i < MaxSize; ++i) {
            std::reverse((*shmStringVect)[i].begin(), (*shmStringVect)[i].end());
            std::reverse((*stdStringVect)[i].begin(), (*stdStringVect)[i].end());
        }

        if(!CheckEqualStringVector(shmStringVect, stdStringVect)) return 1;

        for(int i = 0; i < MaxSize; ++i) {
            std::sort(shmStringVect->begin(), shmStringVect->end());
            std::sort(stdStringVect->begin(), stdStringVect->end());
        }

        if(!CheckEqualStringVector(shmStringVect, stdStringVect)) return 1;

        for(int i = 0; i < MaxSize; ++i) {
            (*shmStringVect)[i].replace((*shmStringVect)[i].begin(),
                                        (*shmStringVect)[i].end(),
                                        "String");
            (*stdStringVect)[i].replace((*stdStringVect)[i].begin(),
                                        (*stdStringVect)[i].end(),
                                        "String");
        }

        if(!CheckEqualStringVector(shmStringVect, stdStringVect)) return 1;

        shmStringVect->erase(std::unique(shmStringVect->begin(), shmStringVect->end()),
                             shmStringVect->end());
        stdStringVect->erase(std::unique(stdStringVect->begin(), stdStringVect->end()),
                             stdStringVect->end());
        if(!CheckEqualStringVector(shmStringVect, stdStringVect)) return 1;

        //When done, delete vector
        segment.destroy_ptr(shmStringVect);
        delete stdStringVect;
    }
    shared_memory_object::remove(process_name.c_str());
    return 0;
}
Exemple #3
0
int string_test()
{
   typedef std::basic_string<CharType> StdString;
   typedef vector<StdString>  StdStringVector;
   typedef basic_string<CharType> BoostString;
   typedef vector<BoostString> BoostStringVector;

   const int MaxSize = 100;

   {
      BoostStringVector *boostStringVect = new BoostStringVector;
      StdStringVector *stdStringVect = new StdStringVector;
      BoostString auxBoostString;
      StdString auxStdString(StdString(auxBoostString.begin(), auxBoostString.end() ));

      CharType buffer [20];

      //First, push back
      for(int i = 0; i < MaxSize; ++i){
         auxBoostString = string_literals<CharType>::String();
         auxStdString = string_literals<CharType>::String();
         string_literals<CharType>::sprintf_number(buffer, i);
         auxBoostString += buffer;
         auxStdString += buffer;
         boostStringVect->push_back(auxBoostString);
         stdStringVect->push_back(auxStdString);
      }

      if(!CheckEqualStringVector(boostStringVect, stdStringVect)){
         return 1;
      }

      //Now push back moving
      for(int i = 0; i < MaxSize; ++i){
         auxBoostString = string_literals<CharType>::String();
         auxStdString = string_literals<CharType>::String();
         string_literals<CharType>::sprintf_number(buffer, i);
         auxBoostString += buffer;
         auxStdString += buffer;
         boostStringVect->push_back(boost::move(auxBoostString));
         stdStringVect->push_back(auxStdString);
      }

      if(!CheckEqualStringVector(boostStringVect, stdStringVect)){
         return 1;
      }

      //push front
      for(int i = 0; i < MaxSize; ++i){
         auxBoostString = string_literals<CharType>::String();
         auxStdString = string_literals<CharType>::String();
         string_literals<CharType>::sprintf_number(buffer, i);
         auxBoostString += buffer;
         auxStdString += buffer;
         boostStringVect->insert(boostStringVect->begin(), auxBoostString);
         stdStringVect->insert(stdStringVect->begin(), auxStdString);
      }

      if(!CheckEqualStringVector(boostStringVect, stdStringVect)){
         return 1;
      }

      //Now push front moving
      for(int i = 0; i < MaxSize; ++i){
         auxBoostString = string_literals<CharType>::String();
         auxStdString = string_literals<CharType>::String();
         string_literals<CharType>::sprintf_number(buffer, i);
         auxBoostString += buffer;
         auxStdString += buffer;
         boostStringVect->insert(boostStringVect->begin(), boost::move(auxBoostString));
         stdStringVect->insert(stdStringVect->begin(), auxStdString);
      }

      if(!CheckEqualStringVector(boostStringVect, stdStringVect)){
         return 1;
      }

      //Now test long and short representation swapping

      //Short first
      auxBoostString = string_literals<CharType>::String();
      auxStdString = string_literals<CharType>::String();
      BoostString boost_swapper;
      StdString std_swapper;
      boost_swapper.swap(auxBoostString);
      std_swapper.swap(auxStdString);
      if(!StringEqual()(auxBoostString, auxStdString))
         return 1;  
      if(!StringEqual()(boost_swapper, std_swapper))
         return 1;  
      boost_swapper.swap(auxBoostString);
      std_swapper.swap(auxStdString);
      if(!StringEqual()(auxBoostString, auxStdString))
         return 1;  
      if(!StringEqual()(boost_swapper, std_swapper))
         return 1;  

      //Shrink_to_fit
      auxBoostString.shrink_to_fit();
      StdString(auxStdString).swap(auxStdString);
      if(!StringEqual()(auxBoostString, auxStdString))
         return 1;

      //Reserve + shrink_to_fit
      auxBoostString.reserve(boost_swapper.size()*2+1);
      auxStdString.reserve(std_swapper.size()*2+1);
      if(!StringEqual()(auxBoostString, auxStdString))
         return 1;

      auxBoostString.shrink_to_fit();
      StdString(auxStdString).swap(auxStdString);
      if(!StringEqual()(auxBoostString, auxStdString))
         return 1;

      //Long string
      auxBoostString = string_literals<CharType>::LongString();
      auxStdString   = string_literals<CharType>::LongString();
      boost_swapper = BoostString();
      std_swapper = StdString();
      boost_swapper.swap(auxBoostString);
      std_swapper.swap(auxStdString);
      if(!StringEqual()(auxBoostString, auxStdString))
         return 1;  
      if(!StringEqual()(boost_swapper, std_swapper))
         return 1;
      boost_swapper.swap(auxBoostString);
      std_swapper.swap(auxStdString);

      //Shrink_to_fit
      auxBoostString.shrink_to_fit();
      StdString(auxStdString).swap(auxStdString);
      if(!StringEqual()(auxBoostString, auxStdString))
         return 1;

      auxBoostString.clear();
      auxStdString.clear();
      auxBoostString.shrink_to_fit();
      StdString(auxStdString).swap(auxStdString);
      if(!StringEqual()(auxBoostString, auxStdString))
         return 1;

      //No sort
      std::sort(boostStringVect->begin(), boostStringVect->end());
      std::sort(stdStringVect->begin(), stdStringVect->end());
      if(!CheckEqualStringVector(boostStringVect, stdStringVect)) return 1;

      const CharType *prefix    = string_literals<CharType>::Prefix();
      const int  prefix_size    = std::char_traits<CharType>::length(prefix);
      const CharType *sufix      = string_literals<CharType>::Suffix();

      for(int i = 0; i < MaxSize; ++i){
         (*boostStringVect)[i].append(sufix);
         (*stdStringVect)[i].append(sufix);
         (*boostStringVect)[i].insert((*boostStringVect)[i].begin(),
                                    prefix, prefix + prefix_size);
         (*stdStringVect)[i].insert((*stdStringVect)[i].begin(),
                                    prefix, prefix + prefix_size);
      }

      if(!CheckEqualStringVector(boostStringVect, stdStringVect)) return 1;

      for(int i = 0; i < MaxSize; ++i){
         std::reverse((*boostStringVect)[i].begin(), (*boostStringVect)[i].end());
         std::reverse((*stdStringVect)[i].begin(), (*stdStringVect)[i].end());
      }

      if(!CheckEqualStringVector(boostStringVect, stdStringVect)) return 1;

      for(int i = 0; i < MaxSize; ++i){
         std::reverse((*boostStringVect)[i].begin(), (*boostStringVect)[i].end());
         std::reverse((*stdStringVect)[i].begin(), (*stdStringVect)[i].end());
      }

      if(!CheckEqualStringVector(boostStringVect, stdStringVect)) return 1;

      for(int i = 0; i < MaxSize; ++i){
         std::sort(boostStringVect->begin(), boostStringVect->end());
         std::sort(stdStringVect->begin(), stdStringVect->end());
      }

      if(!CheckEqualStringVector(boostStringVect, stdStringVect)) return 1;

      for(int i = 0; i < MaxSize; ++i){
         (*boostStringVect)[i].replace((*boostStringVect)[i].begin(),
                                    (*boostStringVect)[i].end(),
                                    string_literals<CharType>::String());
         (*stdStringVect)[i].replace((*stdStringVect)[i].begin(),
                                    (*stdStringVect)[i].end(),
                                    string_literals<CharType>::String());
      }

      if(!CheckEqualStringVector(boostStringVect, stdStringVect)) return 1;

      boostStringVect->erase(std::unique(boostStringVect->begin(), boostStringVect->end()),
                           boostStringVect->end());
      stdStringVect->erase(std::unique(stdStringVect->begin(), stdStringVect->end()),
                           stdStringVect->end());
      if(!CheckEqualStringVector(boostStringVect, stdStringVect)) return 1;

      //Check addition
      {
         BoostString bs2 = string_literals<CharType>::String();
         StdString   ss2 = string_literals<CharType>::String();
         BoostString bs3 = string_literals<CharType>::Suffix();
         StdString   ss3 = string_literals<CharType>::Suffix();
         BoostString bs4 = bs2 + bs3;
         StdString   ss4 = ss2 + ss3;
         if(!StringEqual()(bs4, ss4)){
            return 1;
         }

         bs4 = bs2 + BoostString();
         ss4 = ss2 + StdString();
         if(!StringEqual()(bs4, ss4)){
            return 1;
         }

         bs4 = BoostString() + bs2;
         ss4 = StdString() + ss2;
         if(!StringEqual()(bs4, ss4)){
            return 1;
         }

         bs4 = BoostString() + boost::move(bs2);
         ss4 = StdString() + boost::move(ss2);
         if(!StringEqual()(bs4, ss4)){
            return 1;
         }

         bs2 = string_literals<CharType>::String();
         ss2 = string_literals<CharType>::String();
         bs4 = boost::move(bs2) + BoostString();
         ss4 = boost::move(ss2) + StdString();
         if(!StringEqual()(bs4, ss4)){
            return 1;
         }

         bs2 = string_literals<CharType>::String();
         ss2 = string_literals<CharType>::String();
         bs4 = string_literals<CharType>::Prefix() + boost::move(bs2);
         ss4 = string_literals<CharType>::Prefix() + boost::move(ss2);
         if(!StringEqual()(bs4, ss4)){
            return 1;
         }

         bs2 = string_literals<CharType>::String();
         ss2 = string_literals<CharType>::String();
         bs4 = boost::move(bs2) + string_literals<CharType>::Suffix();
         ss4 = boost::move(ss2) + string_literals<CharType>::Suffix();
         if(!StringEqual()(bs4, ss4)){
            return 1;
         }

         bs2 = string_literals<CharType>::String();
         ss2 = string_literals<CharType>::String();
         bs4 = string_literals<CharType>::Prefix() + bs2;
         ss4 = string_literals<CharType>::Prefix() + ss2;
         if(!StringEqual()(bs4, ss4)){
            return 1;
         }

         bs2 = string_literals<CharType>::String();
         ss2 = string_literals<CharType>::String();
         bs4 = bs2 + string_literals<CharType>::Suffix();
         ss4 = ss2 + string_literals<CharType>::Suffix();
         if(!StringEqual()(bs4, ss4)){
            return 1;
         }

         bs2 = string_literals<CharType>::String();
         ss2 = string_literals<CharType>::String();
         bs4 = string_literals<CharType>::Char() + bs2;
         ss4 = string_literals<CharType>::Char() + ss2;
         if(!StringEqual()(bs4, ss4)){
            return 1;
         }

         bs2 = string_literals<CharType>::String();
         ss2 = string_literals<CharType>::String();
         bs4 = bs2 + string_literals<CharType>::Char();
         ss4 = ss2 + string_literals<CharType>::Char();
         if(!StringEqual()(bs4, ss4)){
            return 1;
         }
      }

      //When done, delete vector
      delete boostStringVect;
      delete stdStringVect;
   }
   return 0;
}