out << "\n};\n";
}
+
CIMObjectPath CIMInstanceRep::buildPath(
const CIMConstClass& cimClass) const
{
cimClass.getKeyNames(keyNames);
if (keyNames.size() == 0)
- return CIMObjectPath();
+ return CIMObjectPath("", CIMNamespaceName(), className);
//--------------------------------------------------------------------------
// Get type and value for each key (building up key bindings):
if (keyName.equal(tmp.getName()))
{
- const CIMValue& value = tmp.getValue();
-
- // ATTN-A: for now just assert:
- if (value.isArray())
- PEGASUS_ASSERT(false);
-
- CIMType type = value.getType();
- String valueStr;
-
- CIMKeyBinding::Type kbType = CIMKeyBinding::STRING;
-
- switch (type)
- {
- case CIMTYPE_BOOLEAN:
- kbType = CIMKeyBinding::BOOLEAN;
- valueStr = value.toString();
- break;
-
- case CIMTYPE_UINT8:
- case CIMTYPE_SINT8:
- case CIMTYPE_UINT16:
- case CIMTYPE_SINT16:
- case CIMTYPE_UINT32:
- case CIMTYPE_SINT32:
- case CIMTYPE_UINT64:
- case CIMTYPE_SINT64:
- case CIMTYPE_CHAR16:
- kbType = CIMKeyBinding::NUMERIC;
- valueStr = value.toString();
- break;
-
- case CIMTYPE_STRING:
- case CIMTYPE_DATETIME:
- kbType = CIMKeyBinding::STRING;
- valueStr = value.toString();
- break;
-
- case CIMTYPE_REFERENCE:
- kbType = CIMKeyBinding::REFERENCE;
- valueStr = value.toString();
- break;
-
- case CIMTYPE_REAL32:
- case CIMTYPE_REAL64:
- PEGASUS_ASSERT(false);
- }
-
- keyBindings.append(CIMKeyBinding(keyName, valueStr, kbType));
+ keyBindings.append(CIMKeyBinding(keyName, tmp.getValue()));
}
}
_rep = new CIMKeyBindingRep(name, value, type);
}
-#ifdef PEGASUS_FUTURE
CIMKeyBinding::CIMKeyBinding(const CIMName& name, const CIMValue& value)
{
+ // ATTN-RK-20020920: Verify that real numbers cannot be keys
+ if (value.isArray() ||
+ (value.getType() == CIMTYPE_REAL32) ||
+ (value.getType() == CIMTYPE_REAL64))
+ {
+ throw TypeMismatchException();
+ }
+
String kbValue = value.toString();
Type kbType;
_rep = new CIMKeyBindingRep(name, kbValue, kbType);
}
-#endif
CIMKeyBinding::~CIMKeyBinding()
{
_rep->_type = type;
}
-#ifdef PEGASUS_FUTURE
Boolean CIMKeyBinding::equal(CIMValue value)
{
+ // ATTN-RK-20020920: Verify that real numbers cannot be keys
+ if (value.isArray() ||
+ (value.getType() == CIMTYPE_REAL32) ||
+ (value.getType() == CIMTYPE_REAL64))
+ {
+ return false;
+ }
+
CIMValue kbValue;
try
switch (value.getType())
{
case CIMTYPE_CHAR16:
+ if (getType() != STRING) return false;
kbValue.set(getValue()[0]);
break;
case CIMTYPE_DATETIME:
+ if (getType() != STRING) return false;
kbValue.set(CIMDateTime(getValue()));
break;
case CIMTYPE_STRING:
+ if (getType() != STRING) return false;
kbValue.set(getValue());
break;
case CIMTYPE_REFERENCE:
+ if (getType() != REFERENCE) return false;
kbValue.set(CIMObjectPath(getValue()));
break;
- default: // Boolean and numerics
+ case CIMTYPE_BOOLEAN:
+ if (getType() != BOOLEAN) return false;
+ kbValue = XmlReader::stringToValue(0, getValue().getCString(),
+ value.getType());
+ break;
+ default: // Numerics
+ if (getType() != NUMERIC) return false;
kbValue = XmlReader::stringToValue(0, getValue().getCString(),
value.getType());
break;
return value.equal(kbValue);
}
-#endif
Boolean operator==(const CIMKeyBinding& x, const CIMKeyBinding& y)
{
*/
CIMKeyBinding(const CIMName& name, const String& value, Type type);
-#ifdef PEGASUS_FUTURE
/** Construct a CIMKeyBinding with a name and CIMValue, mapping from
CIMValue types to CIMKeyBinding types.
@param name CIMName for the key for this binding object.
@param value CIMValue from which to extract the value for this key.
+ @exception TypeMismatchException if the type of the value is not valid
+ for a key property.
*/
CIMKeyBinding(const CIMName& name, const CIMValue& value);
-#endif
/** Destructor */
~CIMKeyBinding();
/** Modifier */
void setType(Type type);
-#ifdef PEGASUS_FUTURE
Boolean equal(CIMValue value);
-#endif
private:
assert(errorDetected);
}
+// Test CIMKeyBinding constructor (CIMValue variety) and equal(CIMValue) method
+void test03()
+{
+ Boolean exceptionFlag = false;
+ try
+ {
+ CIMKeyBinding kb0("test0", Real32(3.14159));
+ }
+ catch (TypeMismatchException&)
+ {
+ exceptionFlag = true;
+ }
+ assert(exceptionFlag);
+
+ CIMKeyBinding kb1("test1", String("3.14159"), CIMKeyBinding::NUMERIC);
+ assert(!kb1.equal(Real32(3.14159)));
+
+ CIMKeyBinding kb2("test2", Uint32(1000));
+ assert(kb2.equal(Uint32(1000)));
+ assert(!kb2.equal(Uint32(1001)));
+ assert(kb2.getValue() == "1000");
+
+ CIMKeyBinding kb3("test3", Char16('X'));
+ assert(kb3.equal(Char16('X')));
+ assert(!kb3.equal(Char16('Y')));
+ assert(kb3.getValue() == "X");
+
+ CIMKeyBinding kb4("test4", CIMDateTime("19991224120000.000000+360"));
+ assert(kb4.equal(CIMDateTime("19991224120000.000000+360")));
+ assert(!kb4.equal(CIMDateTime("19991225120000.000000+360")));
+ assert(kb4.getValue() == "19991224120000.000000+360");
+ kb4.setValue("0");
+ assert(!kb4.equal(CIMDateTime("19991224120000.000000+360")));
+
+ CIMKeyBinding kb5("test5", String("StringTest"));
+ assert(kb5.equal(String("StringTest")));
+ assert(!kb5.equal(String("StringTest1")));
+ assert(kb5.getValue() == "StringTest");
+
+ CIMKeyBinding kb6("test6", Boolean(true));
+ assert(kb6.equal(Boolean(true)));
+ assert(!kb6.equal(Boolean(false)));
+ assert(kb6.getValue() == "TRUE");
+ kb6.setValue("true1");
+ assert(!kb6.equal(Boolean(true)));
+
+ CIMKeyBinding kb7("test7", CIMObjectPath("//atp:77/root/cimv25:TennisPlayer.last=\"Rafter\",first=\"Patrick\""));
+ assert(kb7.equal(CIMObjectPath("//atp:77/root/cimv25:TennisPlayer.last=\"Rafter\",first=\"Patrick\"")));
+ assert(kb7.equal(CIMObjectPath("//atp:77/root/cimv25:TennisPlayer.FIRST=\"Patrick\",LAST=\"Rafter\"")));
+ assert(!kb7.equal(CIMObjectPath("//atp:77/root/cimv25:TennisPlayer.last=\"Rafter\"")));
+
+ exceptionFlag = false;
+ try
+ {
+ CIMKeyBinding kb8("test8", Array<Uint32>());
+ }
+ catch (TypeMismatchException&)
+ {
+ exceptionFlag = true;
+ }
+ assert(exceptionFlag);
+
+ CIMKeyBinding kb9("test9", String("1000"), CIMKeyBinding::STRING);
+ assert(!kb9.equal(Uint32(1000)));
+
+ CIMKeyBinding kb10("test10", String("100"), CIMKeyBinding::NUMERIC);
+ assert(kb10.equal(Uint64(100)));
+ assert(kb10.equal(Uint32(100)));
+ assert(kb10.equal(Uint16(100)));
+ assert(kb10.equal(Uint8(100)));
+ assert(kb10.equal(Sint64(100)));
+ assert(kb10.equal(Sint32(100)));
+ assert(kb10.equal(Sint16(100)));
+ assert(kb10.equal(Sint8(100)));
+ assert(!kb10.equal(String("100")));
+
+ CIMKeyBinding kb11("test11", String("+100"), CIMKeyBinding::NUMERIC);
+ assert(kb11.equal(Sint64(100)));
+ assert(kb11.equal(Sint32(100)));
+ assert(kb11.equal(Sint16(100)));
+ assert(kb11.equal(Sint8(100)));
+ assert(!kb11.equal(String("100")));
+}
int main(int argc, char** argv)
{
{
test01();
test02();
+ test03();
cout << argv[0] << " +++++ passed all tests" << endl;
}