Пример #1
0
TEST(CompOption,Value)
{

    check_type_value<bool> (CompOption::TypeBool, true);
    check_type_value<bool> (CompOption::TypeBool, false);

    check_type_value<int> (CompOption::TypeInt, 1);
    check_type_value<float> (CompOption::TypeFloat, 1.f);
    check_type_value<CompString> (CompOption::TypeString, CompString ("Check"));
    check_type_value<CompString> (CompOption::TypeString, "core");
    
    check_type_value<CompAction> (CompOption::TypeAction, CompAction());
    check_type_value<CompMatch> (CompOption::TypeMatch, CompMatch());

    check_type_value<unsigned short[4]> (CompOption::TypeColor, testColor);
	
    check_type_value<CompOption::Value::Vector> (CompOption::TypeList, CompOption::Value::Vector(5));

    CompOption::Value v1, v2;
    ASSERT_EQ (v1,v2);
    v1.set (CompString("SomeString"));
    ASSERT_TRUE(v1 != v2);

    CompOption::Value::Vector vec;
    CompOption::Value v;

    v.set (true);
    vec.push_back (v);
    vec.push_back (v);

    check_list_type<bool> (CompOption::TypeBool, vec);

    vec.clear ();
    v.set (CompString ("foo"));
    vec.push_back (v);
    vec.push_back (v);

    check_list_type<CompString> (CompOption::TypeString, vec);
}
Пример #2
0
void
PrivateAnimScreen::updateOptionSet (OptionSet  *os,
				    const char *optNamesValuesOrig)
{
    unsigned int len             = strlen (optNamesValuesOrig);
    char         *optNamesValues = (char *)calloc (len + 1, 1);

    // Find the first substring with no spaces in it
    sscanf (optNamesValuesOrig, " %s ", optNamesValues);

    if (!strlen (optNamesValues))
    {
	free (optNamesValues);
	return;
    }
    // Backup original, since strtok is destructive
    strcpy (optNamesValues, optNamesValuesOrig);

    char         *nameTrimmed   = (char *)calloc (len + 1, 1);
    char         *valueStr      = 0;
    const char   *betweenPairs  = ",";
    const char   *betweenOptVal = "=";

    // Count number of pairs
    char         *pairToken     = (char *)optNamesValuesOrig; // TODO do with CompString
    unsigned int nPairs         = 1;

    while ((pairToken = strchr (pairToken, betweenPairs[0])))
    {
	++pairToken; // skip delimiter
	++nPairs;
    }

    os->pairs.clear ();
    os->pairs.reserve (nPairs);

    // Tokenize pairs
    char *name = strtok (optNamesValues, betweenOptVal);

    int errorNo = -1;
    unsigned int i;

    for (i = 0; name && i < nPairs; ++i)
    {
	errorNo = 0;

	if (strchr (name, betweenPairs[0])) // handle "a, b=4" case
	{
	    errorNo = 1;
	    break;
	}

	sscanf (name, " %s ", nameTrimmed);

	if (!strlen (nameTrimmed))
	{
	    errorNo = 2;
	    break;
	}

	valueStr = strtok (0, betweenPairs);

	if (!valueStr)
	{
	    errorNo = 3;
	    break;
	}

	// TODO: Fix: Convert to "pluginname:option_name" format
	// Warning: Assumes that option names in different extension plugins
	// will be different.
	bool         matched                                    = false;
	const        ExtensionPluginInfo *chosenExtensionPlugin = NULL;
	CompOption   *o                                         = 0;
	int          optId                                      = -1;
	unsigned int nOptions;

	foreach (ExtensionPluginInfo *extensionPlugin, mExtensionPlugins)
	{
	    nOptions = extensionPlugin->effectOptions->size ();

	    for (optId = (int)extensionPlugin->firstEffectOptionIndex;
		 optId < (int)nOptions; ++optId)
	    {
		o = &(*extensionPlugin->effectOptions)[(unsigned)optId];

		if (strcasecmp (nameTrimmed, o->name ().c_str ()) == 0)
		{
		    matched = true;
		    chosenExtensionPlugin = extensionPlugin;
		    break;
		}
	    }

	    if (matched)
		break;
	}

	if (!matched)
	{
	    errorNo = 4;
	    break;
	}

	CompOption::Value v;

	os->pairs.push_back (IdValuePair ());
	IdValuePair *pair = &os->pairs[i];

	pair->pluginInfo = chosenExtensionPlugin;
	pair->optionId = optId;
	int valueRead = -1;

	switch (o->type ())
	{
	    case CompOption::TypeBool:
		int vb;
		valueRead = sscanf (valueStr, " %d ", &vb);

		if (valueRead)
		    pair->value.set ((bool)vb);

		break;

	    case CompOption::TypeInt:
	    {
		int vi;
		valueRead = sscanf (valueStr, " %d ", &vi);

		if (valueRead > 0)
		{
		    if (o->rest ().inRange (vi))
		    {
			v.set (vi);
			pair->value = v;
		    }
		    else
			errorNo = 7;
		}

		break;
	    }
	    case CompOption::TypeFloat:
	    {
		float vf;
		valueRead = sscanf (valueStr, " %f ", &vf);

		if (valueRead > 0)
		{
		    if (o->rest ().inRange (vf))
		    {
			v.set (vf);
			pair->value = v;
		    }
		    else
			errorNo = 7;
		}

		break;
	    }
	    case CompOption::TypeString:
	    {
		v.set (CompString (valueStr));
		valueRead = 1;
		break;
	    }

	    case CompOption::TypeColor:
	    {
		unsigned short vc[4];
		valueRead = sscanf (valueStr, " #%2hx%2hx%2hx%2hx ",
				    &vc[0], &vc[1], &vc[2], &vc[3]);

		if (valueRead == 4)
		{
		    CompOption::Value *pairVal = &pair->value;
		    for (int j = 0; j < 4; ++j)
			vc[j] = vc[j] << 8 | vc[j];
		    pairVal->set (vc);
		}
		else
		    errorNo = 6;

		break;
	    }

	    default:
		break;
	}

	if (valueRead == 0)
	    errorNo = 6;

	if (errorNo > 0)
	    break;
	// If valueRead is -1 here, then it must be a
	// non-(int/float/string) option, which is not supported yet.
	// Such an option doesn't currently exist anyway.

	errorNo = -1;
	name = strtok (0, betweenOptVal);
    }
Пример #3
0
TEST(CompOption,Color)
{

    CompOption::Value value(testColor);

    unsigned short * color = value.c();
    ASSERT_NE((void*)0, color);
    for (int i = 0; i != 4; ++i) ASSERT_EQ(testColor[i], color[i]);

    color = value.get<unsigned short*>();
    ASSERT_NE((void*)0, color);
    for (int i = 0; i != 4; ++i) ASSERT_EQ(testColor[i], color[i]);

    value.set(testColor2);

    color = value.c();
    ASSERT_NE((void*)0, color);
    for (int i = 0; i != 4; ++i) ASSERT_EQ(testColor2[i], color[i]);

    color = value.get<unsigned short*>();
    ASSERT_NE((void*)0, color);
    for (int i = 0; i != 4; ++i) ASSERT_EQ(testColor2[i], color[i]);

    CompOption::Value v;

    v.set (testColor);

    color = v.c();
    ASSERT_NE((void*)0, color);
    for (int i = 0; i != 4; ++i) ASSERT_EQ(testColor[i], color[i]);

    color = v.get<unsigned short*>();
    ASSERT_NE((void*)0, color);
    for (int i = 0; i != 4; ++i) ASSERT_EQ(testColor[i], color[i]);

    v.set(testColor2);

    color = v.c();
    ASSERT_NE((void*)0, color);
    for (int i = 0; i != 4; ++i) ASSERT_EQ(testColor2[i], color[i]);

    color = v.get<unsigned short*>();
    ASSERT_NE((void*)0, color);
    for (int i = 0; i != 4; ++i) ASSERT_EQ(testColor2[i], color[i]);

    v.set (static_cast <short unsigned int *> (testColor));

    color = v.c();
    ASSERT_NE((void*)0, color);
    for (int i = 0; i != 4; ++i) ASSERT_EQ(testColor[i], color[i]);

    color = v.get<unsigned short*>();
    ASSERT_NE((void*)0, color);
    for (int i = 0; i != 4; ++i) ASSERT_EQ(testColor[i], color[i]);

    v.set(testColor2);

    color = v.c();
    ASSERT_NE((void*)0, color);
    for (int i = 0; i != 4; ++i) ASSERT_EQ(testColor2[i], color[i]);

    color = v.get<unsigned short*>();
    ASSERT_NE((void*)0, color);
    for (int i = 0; i != 4; ++i) ASSERT_EQ(testColor2[i], color[i]);
}