/*******************************************************************************
 * _TestImplMetadata.js:
 *		Component of the JSUnit-based test suite for the OpenAjax Hub.
 *
 *		This is the unit test for the required metadata that each implementation must provide.
 *		.
 * Copyright 2006-2007 OpenAjax Alliance
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 
 * use this file except in compliance with the License. You may obtain a copy 
 * of the License at http://www.apache.org/licenses/LICENSE-2.0 . Unless 
 * required by applicable law or agreed to in writing, software distributed 
 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 
 * specific language governing permissions and limitations under the License.
 *
 ******************************************************************************/

var _TestImplMetadata_tests = [
  "m1_1"
];

/************************************************************************
 * JSUnit scaffolding used by _TestImplMetadata_jsunit_*.html files.
 * Not used for standalone (i.e., non-JSUnit) testing harness.
 ***********************************************************************/
function exposeTestFunctionNames(){
	 return ["test_ImplMetadata"];
}
function test_ImplMetadata() {
	for (var i = 0; i < _TestImplMetadata_tests.length; i++) {
		OpenAjax.hub.reinit();
		var test = window[_TestImplMetadata_tests[i]];
		test.run();
		assertTrue(test.details, test.pass);
	}
}
/********************** End of JSUnit scaffolding. **********************/


/*************************************************************************
 * Standalone testing scaffolding used by _TestPubSub_standalone.html
 ************************************************************************/
function runTests() {
	var result = '<?xml version "1.0" encoding "UTF-8"?>\n\r<tests>';
	result += t1_1_1.run(); result += "<br/>";
	result += t1_1_2.run(); result += "<br/>";
	result += t1_1_3.run(); result += "<br/>";
	result += t1_1_4.run(); result += "<br/>";
	result += t1_2_1.run(); result += "<br/>";
	result += t1_3_1.run(); result += "<br/>";
	result += t2_1.run(); result += "<br/>";
	result += t2_2.run(); result += "<br/>";
	result += t2_3.run(); result += "<br/>";
	result += t3_3.run(); result += "<br/>";
	result += t3_4.run(); result += "<br/>";
	result += '</tests>';
	return result;
}
function ShowValue(val)
{
        var testFrame = document.getElementById("myFrame");
        var doc = testFrame.contentDocument;
        if (doc == undefined || doc == null) 
            doc = testFrame.contentWindow.document;

        doc.open();
        doc.write(val);
        doc.close();
    
}
/************* End of standalone testing scaffolding.********************/


/************************************************************************
 * Unit tests.
 ***********************************************************************/

var m1_1 = {
	name: "1.1", 
	description: "Publish unit tests",
	result: "",
	expectedResult: "1.1: start, OK: OpenAjax.hub.implementer passes tests, " +
					"OK: OpenAjax.hub.implVersion passes tests, " +
					"OK: OpenAjax.hub.implVersion has right format, "+
					"OK: OpenAjax.hub.specVersion passes tests, " +
					"OK: OpenAjax.hub.specVersion has right format, "
}
m1_1.check_OpenAjax_Not_MissingNullEmpty = function(ref /*string*/) {
	var val = OpenAjax.hub[ref];
	if (val == undefined || val == null || val == "") {
		return false;
	} else {
		return true;
	}
}
m1_1.check_OpenAjax_Not_MissingNullEmpty = function(ref /*string*/) {
	var val = OpenAjax.hub[ref];
	if (val == undefined || val == null || val == "") {
		return false;
	} else {
		return true;
	}
}
m1_1.check_VersionString = function(ref /*string*/) {
	var val = OpenAjax.hub[ref];
	var pattern = /^\d+(\.\d+)*$/;
	if (pattern.test(val)) {
		return true;
	} else {
		return false;
	}
}
m1_1.run = function() {
	this.result = "1.1: start, ";
	if (this.check_OpenAjax_Not_MissingNullEmpty("implementer")) {
		this.result += "OK: OpenAjax.hub.implementer passes tests, ";
	} else {	
		this.result += "FAIL: Missing, null, or empty string value for OpenAjax.hub.implementer, ";
	}
	if (this.check_OpenAjax_Not_MissingNullEmpty("implVersion")) {
		this.result += "OK: OpenAjax.hub.implVersion passes tests, ";
	} else {	
		this.result += "FAIL: Missing, null, or empty string value for OpenAjax.hub.implVersion, ";
	}
	if (this.check_VersionString("implVersion")) {
		this.result += "OK: OpenAjax.hub.implVersion has right format, ";
	} else {	
		this.result += "FAIL: implVersion does not match required form #, #.#, #.#.#, ..., ";
	}
	if (this.check_OpenAjax_Not_MissingNullEmpty("specVersion")) {
		this.result += "OK: OpenAjax.hub.specVersion passes tests, ";
	} else {	
		this.result += "FAIL: Missing, null, or empty string value for OpenAjax.hub.specVersion, ";
	}
	if (this.check_VersionString("specVersion")) {
		this.result += "OK: OpenAjax.hub.specVersion has right format, ";
	} else {	
		this.result += "FAIL: specVersion does not match required form #, #.#, #.#.#, ..., ";
	}
	if (this.result == this.expectedResult) {
		this.pass = true;
		this.details = "<test><name>" + this.name + "</name><result>PASSED</result></test>";
	} else {
		this.pass = false;
		this.details = "<test><name>" + this.name + "</name><result>FAILED</result><details>" + this.result + "</details><expected>" + this.expectedResult + "</expected></test>";
	}
}

	
