File: 1.13.0a/server/base/nats.tests.inc.php (View as Code)

1: 2: /* ------------------------------------------------------------- 3: This file is part of FreeNATS 4: 5: FreeNATS is (C) Copyright 2008 PurplePixie Systems 6: 7: FreeNATS is free software: you can redistribute it and/or modify 8: it under the terms of the GNU General Public License as published by 9: the Free Software Foundation, either version 3 of the License, or 10: (at your option) any later version. 11: 12: FreeNATS is distributed in the hope that it will be useful, 13: but WITHOUT ANY WARRANTY; without even the implied warranty of 14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15: GNU General Public License for more details. 16: 17: You should have received a copy of the GNU General Public License 18: along with FreeNATS. If not, see www.gnu.org/licenses 19: 20: For more information see www.purplepixie.org/freenats 21: -------------------------------------------------------------- */ 22: 23: class TNATS_Test 24: { 25: var $type=""; 26: var $instance=false; 27: var $class=""; 28: var $name=""; 29: var $revision=-1; 30: var $additional=""; 31: var $parameters=false; 32: 33: function TNATS_Test($type,$class,$parameters=false,$name="",$revision=0,$additional="") 34: { 35: $this->type=$type; 36: $this->class=$class; 37: if ($name=="") $this->name=$type; 38: else $this->name=$name; 39: $this->revision=$revision; 40: $this->additional=$additional; 41: if ($parameters===false) $this->parameters=array(); 42: else $this->parameters=$parameters; 43: } 44: 45: function Create() 46: { 47: if ($this->instance===false) // doesn't exist 48: { 49: $this->instance=new $this->class(); 50: } 51: return $this->instance; 52: } 53: } 54: 55: class TNATS_Tests 56: { 57: var $count=0; 58: var $Tests=array(); 59: var $QuickList=array(); // quick list to save doing it dynamically each time 60: var $UnitList=array(); // Unit list for easy reference 61: 62: function Register($type,$class,$parameters=false,$name="",$revision=0,$additional="") 63: { 64: if ($name=="") $name=$type; 65: $this->Tests[$type]=new TNATS_Test($type,$class,$parameters,$name,$revision,$additional); 66: $this->QuickList[$type]=$name; 67: $this->count++; 68: } 69: 70: function Get($type) 71: { 72: if (isset($this->Tests[$type])) return $this->Tests[$type]; 73: return -1; 74: } 75: 76: function QuickList() 77: { 78: return $this->QuickList; 79: } 80: 81: function Exists($type) 82: { 83: if (isset($this->Tests[$type])) return true; 84: return false; 85: } 86: 87: function SetUnits($type,$long,$short="") 88: { 89: if (!isset($this->UnitList[$type])) 90: $this->UnitList[$type]=array(); 91: 92: $this->UnitList[$type]['long']=$long; 93: $this->UnitList[$type]['short']=$short; 94: } 95: 96: function Units($type,$long=true) 97: { 98: if (!isset($this->UnitList[$type])) return ""; 99: if ($long) return $this->UnitList[$type]['long']; 100: else return $this->UnitList[$type]['short']; 101: } 102: 103: 104: } 105: ?>