示例#1
0
  void MemStreamTest::RunTests() 
  {
  
    // -------------------------------------------------------
    // Test input stream
    // -------------------------------------------------------
    {
      std::string test("hi there");  
    
      IMemStream ms((char*)(test.data()), test.size());
      std::stringstream ss(test);
    
      for (int i=0; i<5; i++)
      {
        std::string s1, s2;
        ms >> s1;
        ss >> s2;
        TESTEQUAL2("in", s2, s1);
        TESTEQUAL2("in fail", ss.fail(), ms.fail());
        TESTEQUAL2("in eof", ss.eof(), ms.eof());
      }      


      // Test changing the buffer 
      std::string test2("bye now");  
      ms.str((char*)(test2.data()), test2.size());
      ms.seekg(0);
      ms.clear();
      std::stringstream ss2(test2);
    
      for (int i=0; i<5; i++)
      {
        std::string s1, s2;
        ms >> s1;
        ss2 >> s2;
        TESTEQUAL2("in2", s2, s1);
        TESTEQUAL2("in2 fail", ss2.fail(), ms.fail());
        TESTEQUAL2("in2 eof", ss2.eof(), ms.eof());
      }      
    }


    // -------------------------------------------------------
    // Test setting the buffer on a default input stream
    // -------------------------------------------------------
    {
      std::string test("third test");  
    
      IMemStream ms;
      ms.str((char*)(test.data()), test.size());
      std::stringstream ss(test);
    
      for (int i=0; i<5; i++)
      {
        std::string s1, s2;
        ms >> s1;
        ss >> s2;
        TESTEQUAL2("in2", s2, s1);
        TESTEQUAL2("in2 fail", ss.fail(), ms.fail());
        TESTEQUAL2("in2 eof", ss.eof(), ms.eof());
      }      
    }
  
  
    // -------------------------------------------------------
    // Test output stream
    // -------------------------------------------------------
    {
      OMemStream ms;
      std::stringstream ss;
    
      for (int i=0; i<500; i++)
      {
        ms << i << " ";
        ss << i << " ";
      }
        
      const char* dataP = ms.str();
      size_t size = ms.pcount();
      std::string msStr(dataP, size);
      std::string ssStr = ss.str();
      TESTEQUAL2("out data", msStr, ssStr);
      TESTEQUAL2("out eof", ms.eof(), ss.eof());
      TESTEQUAL2("out fail", ms.fail(), ss.fail());
    }
  
    // -------------------------------------------------------
    // Test memory limits
    // -------------------------------------------------------
    // Set max at 0x10000000 for day to day testing so that test doesn't take too long.
    // To determine the actual memory limits, change this max to something very large and
    // see where we break. 
  
    size_t max = 0x10000000L;
    size_t sizeLimit = memLimitsTest(max);
    TESTEQUAL2("maximum stream size", sizeLimit >= max, true);  
  }
示例#2
0
 void show()
 {
     if (!stopped) 
         stop();
     std::cout << msStr() << "\n";
 }