Esempio n. 1
0
bool operator==(const CVariant& v1, const CVariant& v2)
{
    bool less = false;

    if( v1.IsNull() || v2.IsNull() ) {
        less = v1.IsNull() && !v2.IsNull();
    }
    else {
        if( v1.GetType() != v2.GetType() ) {
            NCBI_THROW(CVariantException, eVariant, "Cannot compare different types");
        }

        switch( v1.GetType() ) {
        case eDB_Char:
        case eDB_VarChar:
        case eDB_LongChar:
        case eDB_Binary:
        case eDB_VarBinary:
            less = v1.GetString() == v2.GetString();
            break;
        case eDB_Bit:
            less = v1.GetBit() == v2.GetBit();
            break;
        case eDB_TinyInt:
            less = v1.GetByte() == v2.GetByte();
            break;
        case eDB_SmallInt:
            less = v1.GetInt2() == v2.GetInt2();
            break;
        case eDB_Int:
            less = v1.GetInt4() == v2.GetInt4();
            break;
        case eDB_BigInt:
            less = v1.GetInt8() == v2.GetInt8();
            break;
        case eDB_Float:
            less = v1.GetFloat() == v2.GetFloat();
            break;
        case eDB_Double:
            less = v1.GetDouble() == v2.GetDouble();
            break;
        case eDB_DateTime:
        case eDB_SmallDateTime:
            less = v1.GetCTime() == v2.GetCTime();
            break;
        default:
            NCBI_THROW(CVariantException, eVariant, "Type not supported");
        }
    }
    return less;
}
Esempio n. 2
0
void CTestSuiteVariant::TestString()
{
	CVariant String;
	String.SetString("hello");
	CPPUNIT_ASSERT_EQUAL( 0,strcmp("hello",String.GetString()) );

	String.SetString("olleh");
	CPPUNIT_ASSERT_EQUAL( 0,strcmp("olleh",String.GetString()) );

	CVariant String2;
	String2.SetString("olleh");
	CPPUNIT_ASSERT_EQUAL( 0,strcmp("olleh",String2.GetString()) );

	CVariant String3;
	String3.SetNumber<int32>(1);
	String3.SetString("olleh");
	CPPUNIT_ASSERT_EQUAL( 0,strcmp("olleh",String3.GetString()) );
}
Esempio n. 3
0
void CTestSuiteVariant::TestDoubleException()
{
	CVariant Double;
	Double.SetNumber<double>(1.0);
	Double.GetString();
}
Esempio n. 4
0
void CTestSuiteVariant::TestFloatException()
{
	CVariant Float;
	Float.SetNumber<float>(1.0f);
	Float.GetString();
}