Tweaks to track changes in property manager.

This commit is contained in:
curt 2001-06-28 21:54:02 +00:00
parent e7b9e55599
commit b481ccd749

View File

@ -50,13 +50,13 @@ static double getNum (int index) { return 1.0 / index; }
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
static void static void
show_values (const SGValue * value) show_values (const SGPropertyNode * node)
{ {
cout << "Bool: " << value->getBoolValue() << endl; cout << "Bool: " << node->getBoolValue() << endl;
cout << "Int: " << value->getIntValue() << endl; cout << "Int: " << node->getIntValue() << endl;
cout << "Float: " << value->getFloatValue() << endl; cout << "Float: " << node->getFloatValue() << endl;
cout << "Double: " << value->getDoubleValue() << endl; cout << "Double: " << node->getDoubleValue() << endl;
cout << "String: " << value->getStringValue() << endl; cout << "String: " << node->getStringValue() << endl;
} }
@ -68,7 +68,7 @@ show_values (const SGValue * value)
static void static void
test_value () test_value ()
{ {
SGValue * value; SGPropertyNode * node;
cout << endl << "Value" << endl << endl; cout << endl << "Value" << endl << endl;
@ -77,81 +77,81 @@ test_value ()
// //
cout << "Testing coercion from bool (expect true)" << endl; cout << "Testing coercion from bool (expect true)" << endl;
value = new SGValue; node = new SGPropertyNode;
value->setBoolValue(true); node->setBoolValue(true);
show_values(value); show_values(node);
delete value; delete node;
cout << endl; cout << endl;
cout << "Testing coercion from int (expect 128)" << endl; cout << "Testing coercion from int (expect 128)" << endl;
value = new SGValue; node = new SGPropertyNode;
value->setIntValue(128); node->setIntValue(128);
show_values(value); show_values(node);
delete value; delete node;
cout << endl; cout << endl;
cout << "Testing coercion from float (expect 1.0/3.0)" << endl; cout << "Testing coercion from float (expect 1.0/3.0)" << endl;
value = new SGValue; node = new SGPropertyNode;
value->setFloatValue(1.0/3.0); node->setFloatValue(1.0/3.0);
show_values(value); show_values(node);
delete value; delete node;
cout << endl; cout << endl;
cout << "Testing coercion from double (expect 1.0/3.0)" << endl; cout << "Testing coercion from double (expect 1.0/3.0)" << endl;
value = new SGValue; node = new SGPropertyNode;
value->setDoubleValue(1.0/3.0); node->setDoubleValue(1.0/3.0);
show_values(value); show_values(node);
delete value; delete node;
cout << endl; cout << endl;
cout << "Testing coercion from string (expect 10e4)" << endl; cout << "Testing coercion from string (expect 10e4)" << endl;
value = new SGValue; node = new SGPropertyNode;
value->setStringValue("10e4"); node->setStringValue("10e4");
show_values(value); show_values(node);
delete value; delete node;
cout << endl; cout << endl;
cout << "Testing coercion from unknown (expect -10e-4)" << endl; cout << "Testing coercion from unspecified (expect -10e-4)" << endl;
value = new SGValue; node = new SGPropertyNode;
value->setUnknownValue("-10e-4"); node->setUnspecifiedValue("-10e-4");
show_values(value); show_values(node);
delete value; delete node;
cout << endl; cout << endl;
// //
// Test coercion for setters. // Test coercion for setters.
// //
value = new SGValue; node = new SGPropertyNode;
cout << "Testing coercion to bool from bool (expect false)" << endl; cout << "Testing coercion to bool from bool (expect false)" << endl;
value->setBoolValue(false); node->setBoolValue(false);
show_values(value); show_values(node);
cout << endl; cout << endl;
cout << "Testing coercion to bool from int (expect 1)" << endl; cout << "Testing coercion to bool from int (expect 1)" << endl;
value->setIntValue(1); node->setIntValue(1);
show_values(value); show_values(node);
cout << endl; cout << endl;
cout << "Testing coercion to bool from float (expect 1.1)" << endl; cout << "Testing coercion to bool from float (expect 1.1)" << endl;
value->setFloatValue(1.1); node->setFloatValue(1.1);
show_values(value); show_values(node);
cout << endl; cout << endl;
cout << "Testing coercion to bool from double (expect 1.1)" << endl; cout << "Testing coercion to bool from double (expect 1.1)" << endl;
value->setDoubleValue(1.1); node->setDoubleValue(1.1);
show_values(value); show_values(node);
cout << endl; cout << endl;
cout << "Testing coercion to bool from string (expect 1e10)" << endl; cout << "Testing coercion to bool from string (expect 1e10)" << endl;
value->setStringValue("1e10"); node->setStringValue("1e10");
show_values(value); show_values(node);
cout << endl; cout << endl;
cout << "Testing coercion to bool from unknown (expect 1e10)" << endl; cout << "Testing coercion to bool from unspecified (expect 1e10)" << endl;
value->setUnknownValue("1e10"); node->setUnspecifiedValue("1e10");
show_values(value); show_values(node);
cout << endl; cout << endl;
// Test tying to a pointer. // Test tying to a pointer.
@ -159,67 +159,67 @@ test_value ()
static int myValue = 10; static int myValue = 10;
cout << "Testing tying to a pointer (expect 10)" << endl; cout << "Testing tying to a pointer (expect 10)" << endl;
if (!value->tie(SGRawValuePointer<int>(&myValue))) if (!node->tie(SGRawValuePointer<int>(&myValue), false))
cout << "*** FAILED TO TIE VALUE!!!" << endl; cout << "*** FAILED TO TIE VALUE!!!" << endl;
show_values(value); show_values(node);
cout << endl; cout << endl;
cout << "Changing base variable (expect -5)" << endl; cout << "Changing base variable (expect -5)" << endl;
myValue = -5; myValue = -5;
show_values(value); show_values(node);
if (!value->untie()) if (!node->untie())
cout << "*** FAIELD TO UNTIE VALUE!!!" << endl; cout << "*** FAILED TO UNTIE VALUE!!!" << endl;
cout << endl; cout << endl;
// Test tying to static functions. // Test tying to static functions.
cout << "Create a new int value (expect 10)" << endl; cout << "Create a new int value (expect 10)" << endl;
value->setIntValue(10); node->setIntValue(10);
show_values(value); show_values(node);
cout << endl; cout << endl;
cout << "Testing tying to static getter (expect 100)" << endl; cout << "Testing tying to static getter (expect 100)" << endl;
if (!value->tie(SGRawValueFunctions<int>(get100))) if (!node->tie(SGRawValueFunctions<int>(get100)))
cout << "*** FAILED TO TIE VALUE!!!" << endl; cout << "*** FAILED TO TIE VALUE!!!" << endl;
show_values(value); show_values(node);
cout << endl; cout << endl;
cout << "Try changing value with no setter (expect 100)" << endl; cout << "Try changing value with no setter (expect 100)" << endl;
if (value->setIntValue(200)) if (node->setIntValue(200))
cout << "*** setIntValue did not return false!!!" << endl; cout << "*** setIntValue did not return false!!!" << endl;
show_values(value); show_values(node);
cout << endl; cout << endl;
cout << "Untie value (expect 100)" << endl; cout << "Untie value (expect 100)" << endl;
if (!value->untie()) if (!node->untie())
cout << "*** FAILED TO UNTIE VALUE!!!" << endl; cout << "*** FAILED TO UNTIE VALUE!!!" << endl;
show_values(value); show_values(node);
cout << endl; cout << endl;
cout << "Try changing value (expect 200)" << endl; cout << "Try changing value (expect 200)" << endl;
if (!value->setIntValue(200)) if (!node->setIntValue(200))
cout << "*** setIntValue RETURNED FALSE!!!" << endl; cout << "*** setIntValue RETURNED FALSE!!!" << endl;
show_values(value); show_values(node);
cout << endl; cout << endl;
// Test tying to indexed static functions. // Test tying to indexed static functions.
cout << "Create a new int value (expect 10)" << endl; cout << "Create a new int value (expect 10)" << endl;
value->setIntValue(10); node->setIntValue(10);
show_values(value); show_values(node);
cout << endl; cout << endl;
cout << "Testing tying to indexed static getter (0.3333...)" << endl; cout << "Testing tying to indexed static getter (0.3333...)" << endl;
if (!value->tie(SGRawValueFunctionsIndexed<double>(3, getNum))) if (!node->tie(SGRawValueFunctionsIndexed<double>(3, getNum)))
cout << "*** FAILED TO TIE VALUE!!!" << endl; cout << "*** FAILED TO TIE VALUE!!!" << endl;
show_values(value); show_values(node);
cout << endl; cout << endl;
cout << "Untie value (expect 0.3333...)" << endl; cout << "Untie value (expect 0.3333...)" << endl;
if (!value->untie()) if (!node->untie())
cout << "*** FAILED TO UNTIE VALUE!!!" << endl; cout << "*** FAILED TO UNTIE VALUE!!!" << endl;
show_values(value); show_values(node);
cout << endl; cout << endl;
@ -230,39 +230,39 @@ test_value ()
SGRawValueMethods<class Stuff,float> tiedstuff(stuff, SGRawValueMethods<class Stuff,float> tiedstuff(stuff,
&Stuff::getStuff, &Stuff::getStuff,
&Stuff::setStuff); &Stuff::setStuff);
if (!value->tie(tiedstuff, false)) if (!node->tie(tiedstuff, false))
cout << "*** FAILED TO TIE VALUE!!!" << endl; cout << "*** FAILED TO TIE VALUE!!!" << endl;
show_values(value); show_values(node);
cout << endl; cout << endl;
cout << "Try untying from object (expect 199)" << endl; cout << "Try untying from object (expect 199)" << endl;
if (!value->untie()) if (!node->untie())
cout << "*** FAILED TO UNTIE VALUE!!!" << endl; cout << "*** FAILED TO UNTIE VALUE!!!" << endl;
show_values(value); show_values(node);
cout << endl; cout << endl;
cout << "Try tying to an indexed method (expect 199)" << endl; cout << "Try tying to an indexed method (expect 199)" << endl;
if (!value->tie(SGRawValueMethodsIndexed<class Stuff, float> if (!node->tie(SGRawValueMethodsIndexed<class Stuff, float>
(stuff, 2, &Stuff::getStuff, &Stuff::setStuff))) (stuff, 2, &Stuff::getStuff, &Stuff::setStuff)))
cout << "*** FAILED TO TIE VALUE!!!" << endl; cout << "*** FAILED TO TIE VALUE!!!" << endl;
show_values(value); show_values(node);
cout << endl; cout << endl;
value->untie(); node->untie();
cout << "Change value (expect 50)" << endl; cout << "Change value (expect 50)" << endl;
if (!value->setIntValue(50)) if (!node->setIntValue(50))
cout << "*** FAILED TO SET VALUE!!!" << endl; cout << "*** FAILED TO SET VALUE!!!" << endl;
show_values(value); show_values(node);
cout << endl; cout << endl;
cout << "Try tying to an object with defaults (expect 50)" << endl; cout << "Try tying to an object with defaults (expect 50)" << endl;
if (!value->tie(tiedstuff, true)) if (!node->tie(tiedstuff, true))
cout << "*** FAILED TO TIE VALUE!!!" << endl; cout << "*** FAILED TO TIE VALUE!!!" << endl;
show_values(value); show_values(node);
cout << endl; cout << endl;
delete value; delete node;
} }