TEST(CompizString,PrintfTest)
{
    CompString s1;
    CompString s2;
    std::map<CompString, compiz::string::printf_test::Value::Ptr> formatValues;
    std::map<CompString, CompString> formatStrings;

    s1 = "foo";

    const char *other_foo = "foo";
    s2 = compPrintf ("%s", other_foo);

    ASSERT_EQ(s1, s2);

    s1 = "3";
    s2 = compPrintf ("%i", 3, NULL);

    ASSERT_EQ(s1, s2);

    s1 = "3.012600";
    s2 = compPrintf ("%f", 3.0126, NULL);

    ASSERT_EQ(s1, s2);

    s1 = "0x4f567";
    s2 = compPrintf ("0x%x", 0x4f567, NULL);

    ASSERT_EQ(s1, s2);

    formatValues["%i"] = boost::shared_static_cast <compiz::string::printf_test::Value> (compiz::string::printf_test::Value::Ptr (new compiz::string::printf_test::TValue<int> (6)));
    formatStrings["%i"] = CompString ("6");
    formatValues["%f"] = boost::shared_static_cast <compiz::string::printf_test::Value> (compiz::string::printf_test::Value::Ptr (new compiz::string::printf_test::TValue<float> (6.532)));
    formatStrings["%f"] = CompString ("6.532000");
    formatValues["%x"] = boost::shared_static_cast <compiz::string::printf_test::Value> (compiz::string::printf_test::Value::Ptr (new compiz::string::printf_test::TValue<int> (0x34fe5aa)));
    formatStrings["%x"] = CompString ("34fe5aa");
    formatValues["%d"] = boost::shared_static_cast <compiz::string::printf_test::Value> (compiz::string::printf_test::Value::Ptr (new compiz::string::printf_test::TValue<int> (2)));
    formatStrings["%d"] = CompString ("2");

    for (std::map <CompString, CompString>::iterator it = formatStrings.begin ();
	    it != formatStrings.end (); it++)
    {
	CompString str = compiz::string::printf_test::get_format (it->first, formatValues[it->first]);
	ASSERT_EQ(str, it->second);
    }
}
CompString get_format (const CompString &fmt, Value::Ptr v)
{
    if (fmt == "%i" || fmt == "%d")
	return compPrintf(fmt.c_str(),
		(boost::shared_static_cast<TValue<int> >(v))->value());
    if (fmt == "%f")
	return compPrintf(fmt.c_str(),
		(boost::shared_static_cast<TValue<float> >(v))->value());
    if (fmt == "%s")
	return compPrintf(
		fmt.c_str(),
		(boost::shared_static_cast<TValue<std::string> >(v))->value().c_str());
    if (fmt == "%x")
	return compPrintf(fmt.c_str(),
		(boost::shared_static_cast<TValue<int> >(v))->value());

    return "not_reached";
}
예제 #3
0
CompString compPrintf (const char *format, ...)
{
    va_list    ap;
    CompString rv;

    va_start (ap, format);
    rv = compPrintf (format, ap);
    va_end (ap);

    return rv;
}
예제 #4
0
bool
CompText::renderWindowTitle (Window               window,
		             bool                 withViewportNumber,
		             const CompText::Attrib &attrib)
{
    CompString text;

    TEXT_SCREEN (screen);

    if (!ts)
	return false;

    if (withViewportNumber)
    {
	CompString title;
    	CompPoint  winViewport;
	CompSize   viewportSize;

	title = ts->getWindowName (window);
	if (!title.empty ())
	{
	    CompWindow *w;

	    w = screen->findWindow (window);
	    if (w)
	    {
		int viewport;

		winViewport  = w->defaultViewport ();
		viewportSize = screen->vpSize ();
		viewport = winViewport.y () * viewportSize.width () +
		           winViewport.x () + 1;
		text = compPrintf ("%s -[%d]-", title.c_str (), viewport);
	    }
	    else
	    {
		text = title;
	    }
	}
    }
    else
    {
	text = ts->getWindowName (window);
    }

    if (text.empty ())
	return false;

    return renderText (text, attrib);
}
예제 #5
0
CompString
CompOption::colorToString (unsigned short *rgba)
{
    return compPrintf ("#%.2x%.2x%.2x%.2x", rgba[0] / 256, rgba[1] / 256,
					    rgba[2] / 256, rgba[3] / 256);
}