/usr/share/phoronix-test-suite/pts-core/objects/pts_test_option.php is in phoronix-test-suite 4.8.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | <?php
/*
Phoronix Test Suite
URLs: http://www.phoronix.com, http://www.phoronix-test-suite.com/
Copyright (C) 2008 - 2011, Phoronix Media
Copyright (C) 2008 - 2011, Michael Larabel
pts_test_option: An object used for storing a test option and its possible values
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class pts_test_option
{
private $identifier = null;
private $option_name = null;
private $prefix = null;
private $postfix = null;
private $default_entry = -1;
private $options = array();
public function __construct($identifier, $option)
{
$this->identifier = $identifier;
$this->option_name = $option;
}
public function set_option_prefix($prefix)
{
$this->prefix = $prefix;
}
public function set_option_postfix($postfix)
{
$this->postfix = $postfix;
}
public function set_option_default($default_node)
{
$default_node--;
if(isset($this->options[$default_node]))
{
$this->default_entry = $default_node;
}
}
public function get_identifier()
{
return $this->identifier;
}
public function get_name()
{
return $this->option_name;
}
public function get_option_prefix()
{
return $this->prefix;
}
public function get_option_postfix()
{
return $this->postfix;
}
public function get_option_default_raw()
{
return $this->default_entry == -1 ? 0 : $this->default_entry;
}
public function get_option_default()
{
return $this->default_entry == -1 ? $this->option_count() - 1 : $this->default_entry;
}
public function add_option($name, $value, $message)
{
array_push($this->options, array($name, $value, $message));
}
public function get_options_array()
{
return $this->options;
}
public function get_all_option_names()
{
$names = array();
for($i = 0; $i < $this->option_count(); $i++)
{
array_push($names, $this->get_option_name($i));
}
return $names;
}
public function get_all_option_names_with_messages()
{
$names = array();
for($i = 0; $i < $this->option_count(); $i++)
{
$user_msg = $this->get_option_message($i);
array_push($names, $this->get_option_name($i) . (!empty($user_msg) ? ' [' . $user_msg . ']' : null));
}
return $names;
}
public function get_option_name($index)
{
return isset($this->options[$index][0]) ? $this->options[$index][0] : null;
}
public function get_option_value($index)
{
return isset($this->options[$index][1]) ? $this->options[$index][1] : null;
}
public function get_option_message($index)
{
return isset($this->options[$index][2]) ? $this->options[$index][2] : null;
}
public function option_count()
{
return count($this->options);
}
public function format_option_value_from_input($input)
{
return $this->get_option_prefix() . $input . $this->get_option_postfix();
}
public function format_option_display_from_input($input)
{
$name = $this->get_name();
return $name != null && $input != null ? $name . ': ' . $input : null;
}
public function format_option_value_from_select($select_pos)
{
$input = $this->get_option_value($select_pos);
return $this->format_option_value_from_input($input);
}
public function format_option_display_from_select($select_pos)
{
$display_name = $this->get_option_name($select_pos);
if(($cut_point = strpos($display_name, '(')) > 1 && strpos($display_name, ')') > $cut_point)
{
$display_name = trim(substr($display_name, 0, $cut_point));
}
return $this->format_option_display_from_input($display_name);
}
public function is_valid_select_choice($select_pos)
{
$valid = false;
if(is_numeric($select_pos) && $select_pos >= 0 && $select_pos < $this->option_count())
{
$valid = $select_pos;
}
else if(in_array($select_pos, $this->get_all_option_names()))
{
$match_made = false;
for($i = 0; $i < $this->option_count() && !$match_made; $i++)
{
if($this->get_option_name($i) == $select_pos)
{
$valid = $i;
$match_made = true;
}
}
}
return $valid;
}
public function parse_selection_choice_input($input, $use_default_on_empty = true)
{
$return_keys = array();
if($input === '0')
{
array_push($return_keys, 0);
}
else
{
foreach(pts_strings::comma_explode($input) as $input_choice)
{
if($input_choice == $this->option_count() || $input_choice == 'Test All Options')
{
// Add all options
foreach(array_keys($this->options) as $i)
{
array_push($return_keys, $i);
}
break;
}
else if(($c = $this->is_valid_select_choice($input_choice)) !== false)
{
array_push($return_keys, $c);
}
}
}
$return_keys = array_unique($return_keys);
sort($return_keys);
if($use_default_on_empty && count($return_keys) == 0)
{
// Use the default as no valid options were presented
array_push($return_keys, $this->get_option_default());
}
return $return_keys;
}
}
?>
|