Пример #1
0
// The test checks that message formatting work
BOOST_AUTO_TEST_CASE_TEMPLATE(message_formatting, CharT, char_types)
{
    typedef logging::attribute_set attr_set;
    typedef std::basic_string< CharT > string;
    typedef logging::basic_formatting_ostream< CharT > osstream;
    typedef logging::record_view record_view;
    typedef logging::basic_formatter< CharT > formatter;
    typedef message_test_data< CharT > data;

    attrs::constant< int > attr1(10);
    attrs::constant< double > attr2(5.5);

    attr_set set1;
    set1[data::attr1()] = attr1;
    set1[data::attr2()] = attr2;
    set1[data::message().get_name()] = attrs::constant< string >(data::some_test_string());

    record_view rec = make_record_view(set1);

    {
        string str1, str2;
        osstream strm1(str1), strm2(str2);
        formatter f = expr::stream << data::message();
        f(rec, strm1);
        strm2 << data::some_test_string();
        BOOST_CHECK(equal_strings(strm1.str(), strm2.str()));
    }
}
Пример #2
0
BOOST_AUTO_TEST_CASE_TEMPLATE(decorator_formatting, CharT, char_types)
{
    typedef logging::record_view record_view;
    typedef logging::attribute_set attr_set;
    typedef std::basic_string< CharT > string;
    typedef logging::basic_formatting_ostream< CharT > osstream;
    typedef logging::basic_formatter< CharT > formatter;
    typedef test_strings< CharT > data;

    attrs::constant< string > attr1(data::printable_chars());

    attr_set set1;
    set1[data::attr1()] = attr1;

    record_view rec = make_record_view(set1);

    {
        string str1, str2;
        osstream strm1(str1), strm2(str2);
        formatter f = expr::stream << expr::make_xml_decor< CharT >()[ expr::stream << expr::attr< string >(data::attr1()) ];
        f(rec, strm1);
        strm2 << data::escaped_chars();
        BOOST_CHECK(equal_strings(strm1.str(), strm2.str()));
    }
}
Пример #3
0
// The test checks that Boost.Format formatting works
BOOST_AUTO_TEST_CASE_TEMPLATE(formatting, CharT, char_types)
{
    typedef logging::attribute_set attr_set;
    typedef std::basic_string< CharT > string;
    typedef logging::basic_formatting_ostream< CharT > osstream;
    typedef logging::record_view record_view;
    typedef logging::basic_formatter< CharT > formatter;
    typedef format_test_data< CharT > data;

    attrs::constant< int > attr1(10);
    attrs::constant< double > attr2(5.5);

    attr_set set1;
    set1[data::attr1()] = attr1;
    set1[data::attr2()] = attr2;

    record_view rec = make_record_view(set1);

    {
        string str1, str2;
        osstream strm1(str1), strm2(str2);
        formatter f = expr::format(data::format1()) % expr::attr< int >(data::attr1()) % expr::attr< double >(data::attr2());
        f(rec, strm1);
        strm2 << 10 << ", " << 5.5;
        BOOST_CHECK(equal_strings(strm1.str(), strm2.str()));
    }
}
Пример #4
0
// The test checks that time_duration formatting work
BOOST_AUTO_TEST_CASE_TEMPLATE(time_duration, CharT, char_types)
{
    typedef logging::attribute_set attr_set;
    typedef std::basic_string< CharT > string;
    typedef logging::basic_formatting_ostream< CharT > osstream;
    typedef logging::record_view record_view;
    typedef logging::basic_formatter< CharT > formatter;
    typedef test_data< CharT > data;
    typedef date_time_formats< CharT > formats;
    typedef boost::date_time::time_facet< ptime, CharT > facet;

    duration t1(14, 40, 15);
    attrs::constant< duration > attr1(t1);

    attr_set set1;
    set1[data::attr1()] = attr1;

    record_view rec = make_record_view(set1);

    // Check for various formats specification
    {
        string str1, str2;
        osstream strm1(str1), strm2(str2);
        formatter f = expr::stream << expr::format_date_time< duration >(data::attr1(), formats::default_time_duration_format().c_str());
        f(rec, strm1);
        facet* fac = new facet();
        fac->time_duration_format(formats::default_time_duration_format().c_str());
        strm2.imbue(std::locale(strm2.getloc(), fac));
        strm2 << t1;
        BOOST_CHECK(equal_strings(strm1.str(), strm2.str()));
    }
    {
        string str1, str2;
        osstream strm1(str1), strm2(str2);
        formatter f = expr::stream << expr::format_date_time< duration >(data::attr1(), formats::time_duration_format().c_str());
        f(rec, strm1);
        facet* fac = new facet();
        fac->time_duration_format(formats::time_duration_format().c_str());
        strm2.imbue(std::locale(strm2.getloc(), fac));
        strm2 << t1;
        BOOST_CHECK(equal_strings(strm1.str(), strm2.str()));
    }
}
Пример #5
0
/**
@SYMTestCaseID			PDS-STORE-UT-4055
@SYMTestCaseDesc		Test for DEF141471 - STORE, new stream performance tests.
						PREQ2505 Insturmentation of PDS.
						RMemWriteStream & RMemReadStream performance tests.
@SYMTestPriority		High
@SYMTestActions			Test for DEF141471 - STORE, new stream performance tests.
@SYMTestExpectedResults Test must not fail
@SYMDEF					DEF141471
*/
void MemStreamTestL()
	{
	HBufC8* buf = HBufC8::NewLC(KBufSize);
	TPtr8 bufPtr = buf->Des();

	//RMemWriteStream::Open()	
	RMemWriteStream strm1;
	TUint32 fc = User::FastCounter();
	strm1.Open(const_cast <TUint8*> (bufPtr.Ptr()), KBufSize);
	TUint32 openFc = CalcTickDiff(fc, User::FastCounter());
	PrintFcDiffAsUs(_L("###  RMemWriteStream::Open(), Time=%d us\r\n"), openFc);
	strm1.Close();
	
	//RMemWriteStream::RMemWriteStream(TAny*,...)	
	fc = User::FastCounter();
	RMemWriteStream strm2(const_cast <TUint8*> (bufPtr.Ptr()), KBufSize);
	TUint32 constrFc = CalcTickDiff(fc, User::FastCounter());
	PrintFcDiffAsUs(_L("###  RMemWriteStream::RMemWriteStream(TAny*,...), Time=%d us\r\n"), constrFc);
	CleanupClosePushL(strm2);
	DoStreamWriteTestL(strm2);
	CleanupStack::PopAndDestroy(&strm2);
	
	//RMemReadStream::Open()
	RMemReadStream strm3;
	fc = User::FastCounter();
	strm3.Open(bufPtr.Ptr(), KBufSize);
	openFc = CalcTickDiff(fc, User::FastCounter());
	PrintFcDiffAsUs(_L("###  RMemReadStream::Open(), Time=%d us\r\n"), openFc);
	strm3.Close();

	//RMemReadStream::RMemReadStream(TAny*,...)	
	fc = User::FastCounter();
	RMemReadStream strm4(bufPtr.Ptr(), KBufSize);
	constrFc = CalcTickDiff(fc, User::FastCounter());
	PrintFcDiffAsUs(_L("###  RMemReadStream::RMemReadStream(TAny*,...), Time=%d us\r\n"), openFc);
	CleanupClosePushL(strm4);
	DoStreamReadTestL(strm4);
	CleanupStack::PopAndDestroy(&strm4);
	
	CleanupStack::PopAndDestroy(buf);
	}
Пример #6
0
// The test checks that default formatting work
BOOST_AUTO_TEST_CASE_TEMPLATE(default_formatting, CharT, char_types)
{
    typedef logging::record_view record_view;
    typedef logging::attribute_set attr_set;
    typedef std::basic_string< CharT > string;
    typedef logging::basic_formatting_ostream< CharT > osstream;
    typedef logging::basic_formatter< CharT > formatter;
    typedef test_data< CharT > data;

    attrs::constant< int > attr1(10);
    attrs::constant< double > attr2(5.5);
    attrs::constant< my_class > attr3(my_class(77));

    attr_set set1;
    set1[data::attr1()] = attr1;
    set1[data::attr2()] = attr2;
    set1[data::attr3()] = attr3;

    record_view rec = make_record_view(set1);

    // Check for various modes of attribute value type specification
    {
        string str1, str2;
        osstream strm1(str1), strm2(str2);
        formatter f = expr::stream << expr::attr< int >(data::attr1()) << expr::attr< double >(data::attr2());
        f(rec, strm1);
        strm2 << 10 << 5.5;
        BOOST_CHECK(equal_strings(strm1.str(), strm2.str()));
    }
    {
        string str1, str2;
        osstream strm1(str1), strm2(str2);
        formatter f = expr::stream << expr::attr< logging::numeric_types >(data::attr1()) << expr::attr< logging::numeric_types >(data::attr2());
        f(rec, strm1);
        strm2 << 10 << 5.5;
        BOOST_CHECK(equal_strings(strm1.str(), strm2.str()));
    }
    // Check that custom types as attribute values are also supported
    {
        string str1, str2;
        osstream strm1(str1), strm2(str2);
        formatter f = expr::stream << expr::attr< my_class >(data::attr3());
        f(rec, strm1);
        strm2 << my_class(77);
        BOOST_CHECK(equal_strings(strm1.str(), strm2.str()));
    }
    // Check how missing attribute values are handled
    {
        string str1;
        osstream strm1(str1);
        formatter f = expr::stream
            << expr::attr< int >(data::attr1())
            << expr::attr< int >(data::attr4()).or_throw()
            << expr::attr< double >(data::attr2());
        BOOST_CHECK_THROW(f(rec, strm1), logging::runtime_error);
    }
    {
        string str1, str2;
        osstream strm1(str1), strm2(str2);
        formatter f = expr::stream
            << expr::attr< int >(data::attr1())
            << expr::attr< int >(data::attr4())
            << expr::attr< double >(data::attr2());
        f(rec, strm1);
        strm2 << 10 << 5.5;
        BOOST_CHECK(equal_strings(strm1.str(), strm2.str()));
    }
}
Пример #7
0
int main(int argc, char** argv) {
  std::cout << "This program computes the difference between two belief files."
            << std::endl;

  if(argc != 3) {
    std::cout << "Usage example: " << std::endl
              << " %> " << argv[0] << " bp_beliefs.csv gibbs_beliefs.csv "
              << std::endl;
  }


  std::ifstream fin1(argv[1]);
  if(!fin1.good()) {
    std::cout << "Unable to open: " << argv[1] << std::endl;
    exit(EXIT_FAILURE);
  }
  std::ifstream fin2(argv[2]);
  if(!fin2.good()) {
    std::cout << "Unable to open: " << argv[2] << std::endl;
    exit(EXIT_FAILURE);
  }

  double L1_L1_error    = 0;
  double L1_L_inf_error  = 0;
  double L_inf_L1_error    = 0;
  size_t disagree = 0;
  size_t vertices = 0;
  while(fin1.good() && fin2.good()) {
    // Read the line for both files
    std::string line1;
    std::getline(fin1, line1);
    std::string line2;
    std::getline(fin2, line2);
    line1 = trim(line1);
    line2 = trim(line2);
    if(line1.size() == 0 || line2.size() == 0) continue;


    // Trim the varialble name
    size_t index1 = line1.find_first_of('/');
    assert(index1 != std::string::npos);
    size_t index2 = line2.find_first_of('/');
    assert(index2 != std::string::npos);

    std::string var1 = trim(line1.substr(0, index1));
    std::string var2 = trim(line1.substr(0, index2));
    assert(var1 == var2);

    line1 = line1.substr(index1);
    line2 = line2.substr(index2);
    

    //  compute the rest of the string
    std::stringstream strm1(line1), strm2(line2);
    
    size_t index = 0;
    double sum = 0, max = 0;
    size_t mapInd1 = 0;
    double mapVal1 = -1;
    size_t mapInd2 = 0;
    double mapVal2 = -1;

    while(strm1.good() && strm2.good()) {
      
      double value1=-1, value2=-1;      
      strm1 >> value1;
      strm2 >> value2;
      strm1.ignore(1); strm2.ignore(1);
      
      assert(value1 >= 0 && value1 <= 1);
      assert(value2 >= 0 && value2 <= 1);
      // Compute the map for each line
      if(value1 > mapVal1) {
        mapVal1 = value1;
        mapInd1 = index;
      }
      if(value2 > mapVal2) {
        mapVal2 = value2;
        mapInd2 = index;
      }
      // Compute the difference in the probabilities 
      double diff = std::abs(value1 - value2);
      sum += diff;
      max = std::max(max, diff);
      // Increment index
      ++index;
    }

    // Assert both lines end at the same state
    assert(!strm1.good() && !strm2.good());

    // update the global counters
    double l1_error = sum / index;
    L1_L1_error += l1_error;
    L1_L_inf_error += max;
    L_inf_L1_error = std::max(L_inf_L1_error, l1_error);
    disagree += (mapInd1 != mapInd2? 1 : 0);
    ++vertices;
  } // end of while loop
  assert(!fin1.good() && !fin2.good());
  fin1.close(); fin2.close();

  std::cout << "Read " << vertices << " beliefs."
            << std::endl
            << "L1 L1 error:       " << L1_L1_error / vertices << std::endl
            << "L1 Linf error:     " << L1_L_inf_error / vertices << std::endl
            << "Linf L1 error:     " << L_inf_L1_error << std::endl
            << "%Map Disagree:      " << double(disagree) / vertices << std::endl;  
  return EXIT_SUCCESS;
}
Пример #8
0
// The test checks that conditional formatting work
BOOST_AUTO_TEST_CASE_TEMPLATE(conditional_formatting, CharT, char_types)
{
    typedef logging::attribute_set attr_set;
    typedef std::basic_string< CharT > string;
    typedef logging::basic_formatting_ostream< CharT > osstream;
    typedef logging::record_view record_view;
    typedef logging::basic_formatter< CharT > formatter;
    typedef test_data< CharT > data;

    attrs::constant< int > attr1(10);
    attrs::constant< double > attr2(5.5);

    attr_set set1;
    set1[data::attr1()] = attr1;
    set1[data::attr2()] = attr2;

    record_view rec = make_record_view(set1);

    // Check for various modes of attribute value type specification
    {
        string str1, str2;
        osstream strm1(str1), strm2(str2);
        formatter f = expr::stream <<
            expr::if_(expr::has_attr< int >(data::attr1()))
            [
                expr::stream << expr::attr< int >(data::attr1())
            ];
        f(rec, strm1);
        strm2 << 10;
        BOOST_CHECK(equal_strings(strm1.str(), strm2.str()));
    }
    {
        string str1;
        osstream strm1(str1);
        formatter f = expr::stream <<
            expr::if_(expr::has_attr< int >(data::attr2()))
            [
                expr::stream << expr::attr< int >(data::attr2())
            ];
        f(rec, strm1);
        BOOST_CHECK(equal_strings(strm1.str(), string()));
    }
    {
        string str1, str2;
        osstream strm1(str1), strm2(str2);
        formatter f = expr::stream <<
            expr::if_(expr::has_attr< int >(data::attr1()))
            [
                expr::stream << expr::attr< int >(data::attr1())
            ]
            .else_
            [
                expr::stream << expr::attr< double >(data::attr2())
            ];
        f(rec, strm1);
        strm2 << 10;
        BOOST_CHECK(equal_strings(strm1.str(), strm2.str()));
    }
    {
        string str1, str2;
        osstream strm1(str1), strm2(str2);
        formatter f = expr::stream <<
            expr::if_(expr::has_attr< int >(data::attr2()))
            [
                expr::stream << expr::attr< int >(data::attr1())
            ]
            .else_
            [
                expr::stream << expr::attr< double >(data::attr2())
            ];
        f(rec, strm1);
        strm2 << 5.5;
        BOOST_CHECK(equal_strings(strm1.str(), strm2.str()));
    }
}