This file is indexed.

/usr/share/octave/packages/struct-1.0.10/test_struct.m is in octave-struct 1.0.10-1build1.

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
## Copyright (C) 2000 Etienne Grossmann <etienne@egdn.net>
##
## 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/>.

##       errors = test_struct
##
## Test whether struct functions behave, and returns the number of errors.
##   
## Sets the global variables test_struct_errors (number of errors)
##                     and   test_struct_cnt    (number of tests) 
##
## If a workspace variable 'verbose' is set to -1 the output is verbose. 
## If it is set to 1, output is minimal (error and test counts).
## Otherwise, each error is reported with a short message and the error and ...
## test counts are displayed at the end of the script (if it is reached).
##

1 ;
global test_struct_errors  ;
global test_struct_cnt  ;
test_struct_verbose = test_struct_errors = test_struct_cnt = 0 ;

if ! exist ("verbose"), verbose = 0; end
if exist ("verbose") && ! isglobal ("verbose")
  tmp = verbose;
  global verbose = tmp;
end

function mytest( val, tag )	# My test function ###################

global test_struct_cnt ;
global test_struct_errors  ;
global verbose ;

% if ! exist("test_struct_verbose"), test_struct_verbose = 0 ; end

if val ,
  if verbose
    printf("OK %i\n",test_struct_cnt) ; 
  end
else
  if verbose 
    printf("NOT OK %-4i : %s\n",test_struct_cnt,tag) ;
  end
  test_struct_errors++ ;
end
test_struct_cnt++ ;
endfunction			# EOF my test function ###############




s.hello = 1 ;
s.world = 2 ;
mytest( isstruct(s)                   , "isstruct" ) ;
mytest( s.hello == getfields(s,"hello"), "getfields 1" ) ;
mytest( s.world == getfields(s,"world"), "getfields 2" ) ; 

t = struct ("hello",1,"world",2) ;
mytest( t.hello == s.hello            , "struct 1" ) ;
mytest( t.world == s.world            , "struct 2" ) ;

s.foo = "bar" ;
s.bye = "ciao" ;
t = setfields (t,"foo","bar","bye","ciao") ;
mytest( t.foo == s.foo                , "setfields 1" ) ;
mytest( t.bye == s.bye                , "setfields 2" ) ;

% s = struct() ;
% t = rmfield (t,"foo","bye","hello") ; % no longer works with octave func
t = rmfield( t, "foo");
t = rmfield( t, "bye");
t = rmfield( t, "hello");
mytest( ! isfield(t,"foo")    , "rmfield 1" ) ;
mytest( ! isfield(t,"bye")    , "rmfield 2" ) ;
mytest( ! isfield(t,"hello")  , "rmfield 3" ) ;
mytest( t.world ==  s.world           , "rmfield 4" ) ;


				# Test tars, getfield
x = 2 ; y = 3 ; z = "foo" ;
s = tars (x,y,z);

mytest( x == s.x                          , "tars 1" );
mytest( y == s.y                          , "tars 2" );
mytest( z == s.z                          , "tars 3" );

a = "x" ; b = "y" ; 
[xx,yy,zz] = getfields (s,a,b,"z") ;

mytest( x == xx                           , "getfields 1" );
mytest( y == yy                           , "getfields 2" );
mytest( z == zz                           , "getfields 3" );

[x3,z3,z4] = getfields (s,"x","z","z") ;
mytest( x == x3                           , "getfields 4" );
mytest( z == z3                           , "getfields 5" );
mytest( z == z4                           , "getfields 6" );

## Broken
##oo(1,1).f0= 1;
##oo= setfield(oo,{1,2},'fd',{3},'b', 6);
##mytest( getfield(oo,{1,2},'fd',{3},'b') == 6, "getfield 6" );

try				# Should not return inexistent fields
  [nothing] = getfields (s,"foo");
  found_nothing = 0;
catch
  found_nothing = 1;
end
mytest( found_nothing                     , "getfields 4" );


ok = test_struct_errors == 0;
if verbose
  if ok
    printf ("All %d tests ok\n", test_struct_cnt);
  else
    printf("There were %d errors in of %d tests\n",...
	   test_struct_errors,test_struct_cnt) ;
  end
end