2009/dap/contacts/tests/test-cases common.js,1.1,1.2

Update of /sources/public/2009/dap/contacts/tests/test-cases
In directory hutz:/tmp/cvs-serv11570

Modified Files:
	common.js 
Log Message:
more thorough comparison of contacts


Index: common.js
===================================================================
RCS file: /sources/public/2009/dap/contacts/tests/test-cases/common.js,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- common.js	23 May 2011 14:02:13 -0000	1.1
+++ common.js	23 May 2011 15:08:23 -0000	1.2
@@ -1,4 +1,41 @@
-var _contact_properties = {"id": "string", "displayName": "string", "name": "contactname", "nickname": "string", "phoneNumbers": "contactfields", "emails": "contactfields", "addresses": "contactaddresses", "ims": "contactfields", "organizations": "contactorganizations", "revision": "date", "birthday": "date", "gender": "string", "note": "string", "photos": "contactfields", "categories": "strings", "urls": "contactfields", "timezone": "string"};
+var _contact_fields = [{"type": "string",
+					     "value": "string",
+					     "pref": "boolean"
+					    }
+			   ];
+var _contact_properties = {"id": "opaquestring",
+			   "displayName": "string",
+			   "name": {"formatted": "string",
+				    "familyName": "string",
+				    "givenName": "string",
+				    "middleName": "string",
+				    "honorificPrefix": "string",
+				    "honorificSuffix": "string"},
+			   "nickname": "string",
+			   "phoneNumbers": _contact_fields,
+			   "emails": _contact_fields,
+			   "addresses": [{
+					     "formatted": "string",
+					     "streetAddress": "string",
+					     "locality": "string",
+					     "postalCode": "string",
+					     "region": "string",
+					     "streetAddress": "string"
+					 }], 
+			   "ims": _contact_fields,
+			   "organizations": [{
+						 "name": "string",
+						 "department": "string",
+						 "title": "string"
+					     }],
+			   "revision": "date",
+			   "birthday": "date",
+			   "gender": "string",
+			   "note": "string",
+			   "photos": _contact_fields,
+			   "categories": ["string"],
+			   "urls": _contact_fields,
+			   "timezone": "string"};
 
 function assert_is_contact(contact) {
     for (i in _contact_properties) {
@@ -8,10 +45,30 @@
 
 function assert_contact_same_as(contact, refContact) {
     for (field in _contact_properties) {
-	if (_contact_properties[field] == "string") {
-	    assert_equals(contact[field], refContact[field]);
-	} else {
-	    // @@@ deal with composed properties
+	_compare_field(contact[field], refContact[field], field, _contact_properties[field]);
+    }
+}
+
+function _compare_field(actual, expected, fieldname, datatype) {
+    if (expected == null) {
+	assert_equals(actual, expected, "Comparing values of " + fieldname);	
+    } else if (datatype == "string" || datatype == "date" || datatype=="opaquestring") {
+	if (expected == null || datatype != "opaquestring") {
+	    assert_equals(actual, expected, "Comparing values of " + fieldname);
+	}
+    } else if (datatype instanceof Array) {
+        for (i in expected) {
+	    _compare_field(actual[i], expected[i], fieldname, datatype[0]);
 	}
+    } else if (typeof(datatype)=='object') {
+        for (var i in  actual) {
+	    assert_own_property(expected, i, "Unexpected property " + i + " in " + fieldname);
+            _compare_field(actual[i], expected[i], fieldname + "." + i, "string");
+        }
+	for (var i in expected) {
+	    assert_own_property(actual, i, "Missing property " + i + " in " + fieldname);
+	}
+    } else {
+	assert_unreached( "Unknown datatype to compare:" + datatype);		
     }
-}
\ No newline at end of file
+}

Received on Monday, 23 May 2011 15:08:27 UTC