/* Copyright 2009 Palm, Inc.  All rights reserved. */

function CallerDetailsTests() {
}

CallerDetailsTests.prototype.before = function before(beforeCallback) {
	this.detailsTable = new CallerDetailsTable();
	beforeCallback();
};

CallerDetailsTests.prototype.testAdd = function testAdd () {
	this.detailsTable.set("5551212", {name: "Rob"});
	var details = this.detailsTable.get("5551212");
	Mojo.requireDefined(details, "Details must be found");
	Mojo.requireEqual("Rob", details.name);
	return Mojo.Test.passed;
};

CallerDetailsTests.prototype.testUnset = function testUnset () {
	this.detailsTable.set("5551212", {name: "Rob"});
	this.detailsTable.unset("5551212");
	var details = this.detailsTable.get("5551212");
	Mojo.requireFalse(details, "Details must not be found");
	return Mojo.Test.passed;
};

// ensures that purging the oldest entry happens when kMaxDetailsCount entries
// have been added 
CallerDetailsTests.prototype.testExpire = function testExpire() {
	this.detailsTable.set("42424242", {name:"Kilgore Trout"});
	for (var i = 0; i < this.detailsTable.kMaxDetailsCount; i++ ) {
		this.detailsTable.set("12456"+i, {name:"ice9 user" + i });
	} 
	var details = this.detailsTable.get("42424242");
	Mojo.requireFalse(details, "Details must not be found");
	return Mojo.Test.passed;
}

// ensures that all kMaxDetailsCount entries are stored
CallerDetailsTests.prototype.testFull = function testFull() {
	for (var i = 0; i < this.detailsTable.kMaxDetailsCount; i++) {
		this.detailsTable.set("8675309"+i, {name: "ice9 user"+i})
	}
	for (var i = 0; i < this.detailsTable.kMaxDetailsCount; i++) {
		var details = this.detailsTable.get("8675309"+i);
		Mojo.requireDefined(details, "Details must be found");
		Mojo.requireEqual("ice9 user"+i, details.name);
	}
	return Mojo.Test.passed;
}

// after adding kMaxDetailsCount entries, deleting one, and adding another
// ensures that oldest entry has not been purged
CallerDetailsTests.prototype.testFullDelete = function testFullDelete() {
	for (var i = 0; i < this.detailsTable.kMaxDetailsCount; i++) {
		this.detailsTable.set("8675309"+i, {name: "ice9 user"+i})
	}

	this.detailsTable.unset("86753091");
	this.detailsTable.set("42424242", {"name":"Zooey Glass"});

	var details = this.detailsTable.get("86753090");
	Mojo.requireDefined(details, "Details must be defined");
	Mojo.requireEqual("ice9 user0", details.name);

	return Mojo.Test.passed;
}
